diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2012-08-12 04:09:57 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2012-08-12 04:09:57 +0400 |
commit | 44e4c5f8316b34835c7900dc649bf8a1570afc0a (patch) | |
tree | 99027196ffd166c78c336126d36c36bbc1621a29 | |
parent | 8a340981be174cae842d339f0458ba6b558330c3 (diff) | |
parent | 0682c3f1aefe315df5fe64ba8c814adacbd739e5 (diff) |
Merged changes in the trunk up to revision 49797.
649 files changed, 8909 insertions, 20066 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 75cefd0c219..77f934fcc15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -226,9 +226,6 @@ option(WITH_LZMA "Enable best LZMA compression, (used for pointcache)" # Camera/motion tracking option(WITH_LIBMV "Enable libmv structure from motion library" ON) -# Mesh boolean lib -option(WITH_CARVE "Enable Carve library to handle mesh boolean operations" ON) - # Misc option(WITH_INPUT_NDOF "Enable NDOF input devices (SpaceNavigator and friends)" ON) option(WITH_RAYOPTIMIZATION "Enable use of SIMD (SSE) optimizations for the raytracer" ON) @@ -250,7 +247,7 @@ option(WITH_CYCLES "Enable cycles Render Engine" ON) option(WITH_CYCLES_TEST "Build cycles test application" OFF) option(WITH_CYCLES_OSL "Build Cycles with OSL support" OFF) option(WITH_CYCLES_CUDA_BINARIES "Build cycles CUDA binaries" OFF) -set(CYCLES_CUDA_BINARIES_ARCH sm_13 sm_20 sm_21 CACHE STRING "CUDA architectures to build binaries for") +set(CYCLES_CUDA_BINARIES_ARCH sm_13 sm_20 sm_21 sm_30 CACHE STRING "CUDA architectures to build binaries for") mark_as_advanced(CYCLES_CUDA_BINARIES_ARCH) unset(PLATFORM_DEFAULT) @@ -274,7 +271,9 @@ if(APPLE) endif() execute_process(COMMAND uname -r OUTPUT_VARIABLE MAC_SYS) # check for actual system-version - if (${MAC_SYS} MATCHES 11) + if (${MAC_SYS} MATCHES 12) + set(OSX_SYSTEM 10.8) + elseif (${MAC_SYS} MATCHES 11) set(OSX_SYSTEM 10.7) elseif(${MAC_SYS} MATCHES 10) set(OSX_SYSTEM 10.6) @@ -364,8 +363,8 @@ if(WITH_CYCLES) set(WITH_OPENIMAGEIO ON) endif() -# auto enable boost for cycles and carve -if(WITH_CYCLES OR WITH_CARVE) +# auto enable boost for cycles and booleans +if(WITH_CYCLES OR WITH_MOD_BOOLEAN) set(WITH_BOOST ON) endif() @@ -856,7 +855,7 @@ elseif(WIN32) if(WITH_MOD_CLOTH_ELTOPO) set(LAPACK ${LIBDIR}/lapack) # set(LAPACK_INCLUDE_DIR ${LAPACK}/include) - set_lib_path(LAPACK_LIBPATH ${LAPACK}/lib) + set(LAPACK_LIBPATH ${LAPACK}/lib) set(LAPACK_LIBRARIES ${LIBDIR}/lapack/lib/libf2c.lib ${LIBDIR}/lapack/lib/clapack_nowrap.lib @@ -896,6 +895,7 @@ elseif(WIN32) endif() if(WITH_OPENCOLLADA) + set(OPENCOLLADA ${LIBDIR}/opencollada) set(OPENCOLLADA_INCLUDE_DIRS ${LIBDIR}/opencollada/include/COLLADAStreamWriter/include @@ -904,23 +904,22 @@ elseif(WIN32) ${LIBDIR}/opencollada/include/COLLADASaxFrameworkLoader/include ${LIBDIR}/opencollada/include/GeneratedSaxParser/include ) - - set_lib_path(OPENCOLLADA_LIBPATH "opencollada/lib") + set_lib_path(OPENCOLLADA_LIBPATH "opencollada") set(OPENCOLLADA_LIBRARIES - ${OPENCOLLADA_LIBPATH}/OpenCOLLADASaxFrameworkLoader.lib - ${OPENCOLLADA_LIBPATH}/OpenCOLLADAFramework.lib - ${OPENCOLLADA_LIBPATH}/OpenCOLLADABaseUtils.lib - ${OPENCOLLADA_LIBPATH}/OpenCOLLADAStreamWriter.lib - ${OPENCOLLADA_LIBPATH}/MathMLSolver.lib - ${OPENCOLLADA_LIBPATH}/GeneratedSaxParser.lib - ${OPENCOLLADA_LIBPATH}/xml2.lib - ${OPENCOLLADA_LIBPATH}/buffer.lib - ${OPENCOLLADA_LIBPATH}/ftoa.lib - ${OPENCOLLADA_LIBPATH}/UTF.lib + ${OPENCOLLADA_LIBPATH}/lib/OpenCOLLADASaxFrameworkLoader.lib + ${OPENCOLLADA_LIBPATH}/lib/OpenCOLLADAFramework.lib + ${OPENCOLLADA_LIBPATH}/lib/OpenCOLLADABaseUtils.lib + ${OPENCOLLADA_LIBPATH}/lib/OpenCOLLADAStreamWriter.lib + ${OPENCOLLADA_LIBPATH}/lib/MathMLSolver.lib + ${OPENCOLLADA_LIBPATH}/lib/GeneratedSaxParser.lib + ${OPENCOLLADA_LIBPATH}/lib/xml2.lib + ${OPENCOLLADA_LIBPATH}/lib/buffer.lib + ${OPENCOLLADA_LIBPATH}/lib/ftoa.lib + ${OPENCOLLADA_LIBPATH}/lib/UTF.lib ) set(PCRE_LIBRARIES - ${OPENCOLLADA_LIBPATH}/pcre.lib + ${OPENCOLLADA_LIBPATH}/lib/pcre.lib ) unset(OPENCOLLADA_LIBPATH) @@ -943,7 +942,8 @@ elseif(WIN32) if(WITH_IMAGE_OPENEXR) set_lib_path(OPENEXR "openexr") - set_lib_path(OPENEXR_LIBPATH "openexr/lib") + set(OPENEXR_INCLUDE_DIR ${OPENEXR}/include) + set(OPENEXR_LIBPATH ${OPENEXR}/lib) set(OPENEXR_LIBRARIES ${OPENEXR_LIBPATH}/Iex.lib ${OPENEXR_LIBPATH}/Half.lib @@ -951,15 +951,12 @@ elseif(WIN32) ${OPENEXR_LIBPATH}/Imath.lib ${OPENEXR_LIBPATH}/IlmThread.lib ) - set_lib_path(OPENEXR_INCUDE "openexr/include") set(OPENEXR_INCLUDE_DIRS - ${OPENEXR_INCUDE} - ${OPENEXR_INCUDE}/IlmImf - ${OPENEXR_INCUDE}/Iex - ${OPENEXR_INCUDE}/Imath + ${OPENEXR_INCLUDE_DIR} + ${OPENEXR_INCLUDE_DIR}/IlmImf + ${OPENEXR_INCLUDE_DIR}/Iex + ${OPENEXR_INCLUDE_DIR}/Imath ) - unset(OPENEXR_INCUDE) - unset(OPENEXR_LIBPATH) endif() if(WITH_IMAGE_TIFF) @@ -978,8 +975,9 @@ elseif(WIN32) if(WITH_PYTHON) # normally cached but not since we include them with blender set(PYTHON_VERSION 3.2) # CACHE STRING) - set_lib_path(PYTHON_INCLUDE_DIR "python/include/python${PYTHON_VERSION}") - set_lib_path(PYTHON_LIBRARY "python/lib/python32.lib") #CACHE FILEPATH) + set_lib_path(PYTHON "python") + set(PYTHON_INCLUDE_DIR ${PYTHON}/include/python${PYTHON_VERSION}) + set(PYTHON_LIBRARY ${PYTHON}/lib/python32.lib) #CACHE FILEPATH # uncached vars set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}") @@ -1010,7 +1008,7 @@ elseif(WIN32) set(OPENIMAGEIO ${LIBDIR}/openimageio) set(OPENIMAGEIO_INCLUDE_DIRS ${OPENIMAGEIO}/include) set(OPENIMAGEIO_LIBRARIES OpenImageIO) - set_lib_path(OPENIMAGEIO_LIBPATH "openimageio/lib") + set(OPENIMAGEIO_LIBPATH ${OPENIMAGEIO}/lib) set(OPENIMAGEIO_DEFINITIONS) endif() @@ -1485,6 +1483,16 @@ endif() if(MSVC) # for some reason this fails on msvc add_definitions(-D__LITTLE_ENDIAN__) + +# OSX-Note: as we do crosscompiling with specific set architecture, +# endianess-detection and autosetting is counterproductive +# so we just set endianess according CMAKE_OSX_ARCHITECTURES + +elseif(CMAKE_OSX_ARCHITECTURES MATCHES i386 OR CMAKE_OSX_ARCHITECTURES MATCHES x86_64) + add_definitions(-D__LITTLE_ENDIAN__) +elseif(CMAKE_OSX_ARCHITECTURES MATCHES ppc OR CMAKE_OSX_ARCHITECTURES MATCHES ppc64) + add_definitions(-D__BIG_ENDIAN__) + else() include(TestBigEndian) test_big_endian(_SYSTEM_BIG_ENDIAN) @@ -1651,9 +1659,6 @@ endif() # MSVC2010 fails to links C++ libs right if(MSVC10) - if(WITH_IMAGE_OPENEXR) - message(WARNING "MSVC 2010 does not support OpenEXR, disabling WITH_IMAGE_OPENEXR. To enable support use Use MSVC 2008") - endif() if(WITH_OPENCOLLADA) message(WARNING "MSVC 2010 does not support OpenCollada, disabling WITH_OPENCOLLADA. To enable support use Use MSVC 2008") endif() diff --git a/SConstruct b/SConstruct index 681e3964a13..53e1911a3e7 100644 --- a/SConstruct +++ b/SConstruct @@ -92,7 +92,7 @@ if platform=='win32': if not use_color=='1': B.bc.disable() - + #on defaut white Os X terminal, some colors are totally unlegible if platform=='darwin': B.bc.OKGREEN = '\033[34m' @@ -123,7 +123,7 @@ if bitness: B.bitness = bitness else: B.bitness = tempbitness - + # first check cmdline for toolset and we create env to work on quickie = B.arguments.get('BF_QUICK', None) @@ -138,7 +138,7 @@ if quickie: B.quickie=string.split(quickie,',') else: B.quickie=[] - + toolset = B.arguments.get('BF_TOOLSET', None) if toolset: print "Using " + toolset @@ -270,7 +270,7 @@ if 'blenderlite' in B.targets: target_env_defs['WITH_BF_PYTHON'] = False target_env_defs['WITH_BF_3DMOUSE'] = False target_env_defs['WITH_BF_LIBMV'] = False - + # Merge blenderlite, let command line to override for k,v in target_env_defs.iteritems(): if k not in B.arguments: @@ -319,7 +319,7 @@ if env['WITH_BF_OPENMP'] == 1: if env['WITH_GHOST_COCOA'] == True: env.Append(CPPFLAGS=['-DGHOST_COCOA']) - + if env['USE_QTKIT'] == True: env.Append(CPPFLAGS=['-DUSE_QTKIT']) @@ -374,7 +374,7 @@ if not B.root_build_dir[-1]==os.sep: B.root_build_dir += os.sep if not B.doc_build_dir[-1]==os.sep: B.doc_build_dir += os.sep - + # We do a shortcut for clean when no quicklist is given: just delete # builddir without reading in SConscripts do_clean = None @@ -422,16 +422,16 @@ if not quickie and do_clean: # with _any_ library but since we used a fixed python version this tends to # be most problematic. if env['WITH_BF_PYTHON']: - py_h = os.path.join(Dir(env.subst('${BF_PYTHON_INC}')).abspath, "Python.h") + py_h = os.path.join(Dir(env.subst('${BF_PYTHON_INC}')).abspath, "Python.h") - if not os.path.exists(py_h): - print("\nMissing: \"" + env.subst('${BF_PYTHON_INC}') + os.sep + "Python.h\",\n" - " Set 'BF_PYTHON_INC' to point " - "to a valid python include path.\n Containing " - "Python.h for python version \"" + env.subst('${BF_PYTHON_VERSION}') + "\"") + if not os.path.exists(py_h): + print("\nMissing: \"" + env.subst('${BF_PYTHON_INC}') + os.sep + "Python.h\",\n" + " Set 'BF_PYTHON_INC' to point " + "to a valid python include path.\n Containing " + "Python.h for python version \"" + env.subst('${BF_PYTHON_VERSION}') + "\"") - Exit() - del py_h + Exit() + del py_h if not os.path.isdir ( B.root_build_dir): @@ -445,9 +445,53 @@ if not os.path.isdir ( B.root_build_dir): # if not os.path.isdir(B.doc_build_dir) and env['WITH_BF_DOCS']: # os.makedirs ( B.doc_build_dir ) +################################### +# Ensure all data files are valid # +################################### +if not os.path.isdir ( B.root_build_dir + 'data_headers'): + os.makedirs ( B.root_build_dir + 'data_headers' ) +# use for includes +env['DATA_HEADERS'] = os.path.join(os.path.abspath(env['BF_BUILDDIR']), "data_headers") +def ensure_data(FILE_FROM, FILE_TO, VAR_NAME): + if os.sep == "\\": + FILE_FROM = FILE_FROM.replace("/", "\\") + FILE_TO = FILE_TO.replace("/", "\\") + + # first check if we need to bother. + if os.path.exists(FILE_TO): + if os.path.getmtime(FILE_FROM) < os.path.getmtime(FILE_TO): + return + + print(B.bc.HEADER + "Generating: " + B.bc.ENDC + "%r" % os.path.basename(FILE_TO)) + fpin = open(FILE_FROM, "rb") + fpin.seek(0, os.SEEK_END) + size = fpin.tell() + fpin.seek(0) + + fpout = open(FILE_TO, "w") + fpout.write("int %s_size = %d;\n" % (VAR_NAME, size)) + fpout.write("char %s[] = {\n" % VAR_NAME) + + while size > 0: + size -= 1 + if size % 32 == 31: + fpout.write("\n") + + fpout.write("%3d," % ord(fpin.read(1))) + fpout.write("\n 0};\n\n") + + fpin.close() + fpout.close() + +ensure_data("source/blender/compositor/operations/COM_OpenCLKernels.cl", + B.root_build_dir + "data_headers/COM_OpenCLKernels.cl.h", + "clkernelstoh_COM_OpenCLKernels_cl") + +##### END DATAFILES ########## + Help(opts.GenerateHelpText(env)) -# default is new quieter output, but if you need to see the +# default is new quieter output, but if you need to see the # commands, do 'scons BF_QUIET=0' bf_quietoutput = B.arguments.get('BF_QUIET', '1') if env['BF_QUIET']: @@ -534,7 +578,7 @@ if env['OURPLATFORM']!='darwin': for targetdir,srcfile in zip(datafilestargetlist, datafileslist): td, tf = os.path.split(targetdir) dotblenderinstall.append(env.Install(dir=td, source=srcfile)) - + if env['WITH_BF_PYTHON']: #-- local/VERSION/scripts scriptpaths=['release/scripts'] @@ -611,13 +655,13 @@ if env['OURPLATFORM']!='darwin': kernel_build_dir = os.path.join(B.root_build_dir, 'intern/cycles/kernel') cubin_file = os.path.join(kernel_build_dir, "kernel_%s.cubin" % arch) scriptinstall.append(env.Install(dir=dir,source=cubin_file)) - + if env['WITH_BF_INTERNATIONAL']: internationalpaths=['release' + os.sep + 'datafiles'] - + def check_path(path, member): return (member in path.split(os.sep)) - + for intpath in internationalpaths: for dp, dn, df in os.walk(intpath): if '.svn' in dn: @@ -630,7 +674,7 @@ if env['OURPLATFORM']!='darwin': pass else: continue - + dir = os.path.join(env['BF_INSTALLDIR'], VERSION) dir += os.sep + os.path.basename(intpath) + dp[len(intpath):] @@ -738,7 +782,7 @@ if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'win64-vc', 'linuxcross'): # strict: the x86 build fails on x64 Windows. We need to ship # both builds in x86 packages. if bitness == 32: - dllsources.append('${LCGDIR}/thumbhandler/lib/BlendThumb.dll') + dllsources.append('${LCGDIR}/thumbhandler/lib/BlendThumb.dll') dllsources.append('${LCGDIR}/thumbhandler/lib/BlendThumb64.dll') if env['WITH_BF_OIIO'] and env['OURPLATFORM'] != 'win32-mingw': @@ -751,7 +795,7 @@ if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'win64-vc', 'linuxcross'): if env['OURPLATFORM'] == 'win64-mingw': dllsources = [] - + if env['WITH_BF_PYTHON']: if env['BF_DEBUG']: dllsources.append('${BF_PYTHON_LIBPATH}/${BF_PYTHON_DLL}_d.dll') @@ -770,10 +814,10 @@ if env['OURPLATFORM'] == 'win64-mingw': if env['WITH_BF_SDL']: dllsources.append('${LCGDIR}/sdl/lib/SDL.dll') - - if(env['WITH_BF_OPENMP']): - dllsources.append('${LCGDIR}/binaries/libgomp-1.dll') - + + if(env['WITH_BF_OPENMP']): + dllsources.append('${LCGDIR}/binaries/libgomp-1.dll') + dllsources.append('${LCGDIR}/thumbhandler/lib/BlendThumb64.dll') dllsources.append('${LCGDIR}/binaries/libgcc_s_sjlj-1.dll') dllsources.append('${LCGDIR}/binaries/libwinpthread-1.dll') diff --git a/build_files/buildbot/slave_pack.py b/build_files/buildbot/slave_pack.py index 73c633d0c29..654efd72876 100644 --- a/build_files/buildbot/slave_pack.py +++ b/build_files/buildbot/slave_pack.py @@ -55,11 +55,14 @@ if builder.find('scons') != -1: 'WITHOUT_BF_INSTALL=True'] config = None + bits = None if builder.endswith('linux_x86_64_scons'): config = 'user-config-x86_64.py' + bits = 64 elif builder.endswith('linux_i386_scons'): - config = 'user-config-x86_64.py' + config = 'user-config-i686.py' + bits = 32 if config is not None: config_fpath = os.path.join(config_dir, config) @@ -69,7 +72,16 @@ if builder.find('scons') != -1: blenderplayer = os.path.join(install_dir, 'blenderplayer') subprocess.call(['strip', '--strip-all', blender, blenderplayer]) + extra = '/' + os.path.join('home', 'sources', 'release-builder', 'extra') + mesalibs = os.path.join(extra, 'mesalibs' + str(bits) + '.tar.bz2') + software_gl = os.path.join(extra, 'blender-softwaregl') + + os.system('tar -xpf %s -C %s' % (mesalibs, install_dir)) + os.system('cp %s %s' % (software_gl, install_dir)) + os.system('chmod 755 %s' % (os.path.join(install_dir, 'blender-softwaregl'))) + retcode = subprocess.call(['python', 'scons/scons.py'] + scons_options) + sys.exit(retcode) else: if builder.find('win') != -1: diff --git a/build_files/cmake/Modules/FindOpenCOLLADA.cmake b/build_files/cmake/Modules/FindOpenCOLLADA.cmake index 77c8b09c4ac..169d3a82fc7 100644 --- a/build_files/cmake/Modules/FindOpenCOLLADA.cmake +++ b/build_files/cmake/Modules/FindOpenCOLLADA.cmake @@ -81,6 +81,7 @@ FOREACH(COMPONENT ${_opencollada_FIND_INCLUDES}) # Alternative would be to suffix all members of search path # but this is less trouble, just looks strange. include/opencollada/${COMPONENT} + include/${COMPONENT}/include HINTS ${_opencollada_SEARCH_DIRS} ) diff --git a/build_files/cmake/config/blender_lite.cmake b/build_files/cmake/config/blender_lite.cmake index 777fbbf0dba..06a82261795 100644 --- a/build_files/cmake/config/blender_lite.cmake +++ b/build_files/cmake/config/blender_lite.cmake @@ -15,7 +15,6 @@ set(WITH_CODEC_SNDFILE OFF CACHE FORCE BOOL) set(WITH_CYCLES OFF CACHE FORCE BOOL) set(WITH_FFTW3 OFF CACHE FORCE BOOL) set(WITH_LIBMV OFF CACHE FORCE BOOL) -set(WITH_CARVE OFF CACHE FORCE BOOL) set(WITH_GAMEENGINE OFF CACHE FORCE BOOL) set(WITH_COMPOSITOR OFF CACHE FORCE BOOL) set(WITH_GHOST_XDND OFF CACHE FORCE BOOL) diff --git a/build_files/cmake/data_to_c.cmake b/build_files/cmake/data_to_c.cmake new file mode 100644 index 00000000000..b8b18269dc8 --- /dev/null +++ b/build_files/cmake/data_to_c.cmake @@ -0,0 +1,25 @@ +# cmake script, to be called on its own with 3 defined args +# +# - FILE_FROM +# - FILE_TO +# - VAR_NAME + +# not highly optimal, may replace with generated C program like makesdna +file(READ ${FILE_FROM} file_from_string HEX) +string(LENGTH ${file_from_string} _max_index) +math(EXPR size_on_disk ${_max_index}/2) + +file(REMOVE ${FILE_TO}) + +file(APPEND ${FILE_TO} "int ${VAR_NAME}_size = ${size_on_disk};\n") +file(APPEND ${FILE_TO} "char ${VAR_NAME}[] = {") + +set(_index 0) + +while(NOT _index EQUAL _max_index) + string(SUBSTRING "${file_from_string}" ${_index} 2 _pair) + file(APPEND ${FILE_TO} "0x${_pair},") + math(EXPR _index ${_index}+2) +endwhile() +# null terminator not essential but good if we want plane strings encoded +file(APPEND ${FILE_TO} "0x00};\n") diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake index bceeb5acc86..50bbab9eed9 100644 --- a/build_files/cmake/macros.cmake +++ b/build_files/cmake/macros.cmake @@ -719,12 +719,37 @@ macro(set_lib_path lvar lproj) - - if(MSVC10 AND EXISTS ${LIBDIR}/vc2010/${lproj}) - set(${lvar} ${LIBDIR}/vc2010/${lproj}) + if(MSVC10) + set(${lvar} ${LIBDIR}/${lproj}/vc2010) else() set(${lvar} ${LIBDIR}/${lproj}) endif() +endmacro() -endmacro() +# not highly optimal, may replace with generated C program like makesdna +function(data_to_c + file_from file_to var_name) + + file(READ ${file_from} file_from_string HEX) + string(LENGTH ${file_from_string} _max_index) + math(EXPR size_on_disk ${_max_index}/2) + + file(REMOVE ${file_to}) + + file(APPEND ${file_to} "int ${var_name}_size = ${size_on_disk};\n") + file(APPEND ${file_to} "char ${var_name}[] = {") + + set(_index 0) + + while(NOT _index EQUAL _max_index) + string(SUBSTRING "${file_from_string}" ${_index} 2 _pair) + file(APPEND ${file_to} "0x${_pair},") + math(EXPR _index ${_index}+2) + endwhile() + file(APPEND ${file_to} "};\n") +endfunction() + +# eg +# data_to_c("/home/guest/test.txt" "/home/guest/test.txt.h" "this_is_data") + diff --git a/build_files/scons/tools/btools.py b/build_files/scons/tools/btools.py index e08a013d081..034d261e7cd 100644 --- a/build_files/scons/tools/btools.py +++ b/build_files/scons/tools/btools.py @@ -164,7 +164,7 @@ def validate_arguments(args, bc): 'WITH_BF_CYCLES', 'WITH_BF_CYCLES_CUDA_BINARIES', 'BF_CYCLES_CUDA_NVCC', 'BF_CYCLES_CUDA_NVCC', 'WITH_BF_CYCLES_CUDA_THREADED_COMPILE', 'WITH_BF_OIIO', 'WITH_BF_STATICOIIO', 'BF_OIIO', 'BF_OIIO_INC', 'BF_OIIO_LIB', 'BF_OIIO_LIB_STATIC', 'BF_OIIO_LIBPATH', 'WITH_BF_BOOST', 'WITH_BF_STATICBOOST', 'BF_BOOST', 'BF_BOOST_INC', 'BF_BOOST_LIB', 'BF_BOOST_LIB_STATIC', 'BF_BOOST_LIBPATH', - 'WITH_BF_LIBMV', 'WITH_BF_CARVE' + 'WITH_BF_LIBMV' ] # Have options here that scons expects to be lists @@ -530,7 +530,6 @@ def read_opts(env, cfg, args): (BoolVariable('WITH_BF_LZO', 'Enable fast LZO pointcache compression', True)), (BoolVariable('WITH_BF_LZMA', 'Enable best LZMA pointcache compression', True)), - (BoolVariable('WITH_BF_CARVE', 'Enable carve library for mesh boolean operations', True)), (BoolVariable('WITH_BF_LIBMV', 'Enable libmv structure from motion library', True)), diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt index b5f94c06d4c..151df493062 100644 --- a/extern/CMakeLists.txt +++ b/extern/CMakeLists.txt @@ -68,7 +68,7 @@ if(WITH_LIBMV) add_subdirectory(libmv) endif() -if(WITH_CARVE) +if(WITH_MOD_BOOLEAN) add_subdirectory(carve) endif() diff --git a/extern/SConscript b/extern/SConscript index 67b74e9ee91..ce366deb38a 100644 --- a/extern/SConscript +++ b/extern/SConscript @@ -32,7 +32,7 @@ if env['WITH_BF_LZMA']: if env['WITH_BF_LIBMV']: SConscript(['libmv/SConscript']) -if env['WITH_BF_CARVE']: +if env['WITH_BF_BOOLEAN']: SConscript(['carve/SConscript']) if env['WITH_GHOST_XDND']: diff --git a/intern/CMakeLists.txt b/intern/CMakeLists.txt index 71d2ef5e410..2b4a84d6b39 100644 --- a/intern/CMakeLists.txt +++ b/intern/CMakeLists.txt @@ -55,7 +55,6 @@ if(WITH_MOD_DECIMATE) endif() if(WITH_MOD_BOOLEAN) - add_subdirectory(boolop) add_subdirectory(bsp) endif() diff --git a/intern/SConscript b/intern/SConscript index 3bfdc2c4ca7..53fc80b0317 100644 --- a/intern/SConscript +++ b/intern/SConscript @@ -11,7 +11,6 @@ SConscript(['audaspace/SConscript', 'decimation/SConscript', 'iksolver/SConscript', 'itasc/SConscript', - 'boolop/SConscript', 'opennl/SConscript', 'mikktspace/SConscript', 'smoke/SConscript', @@ -26,7 +25,8 @@ if env['WITH_BF_FLUID']: if env['WITH_BF_CYCLES']: SConscript(['cycles/SConscript']) -SConscript(['bsp/SConscript']) +if env['WITH_BF_BOOLEAN']: + SConscript(['bsp/SConscript']) if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'win64-mingw', 'linuxcross', 'win64-vc'): SConscript(['utfconv/SConscript']) diff --git a/intern/boolop/CMakeLists.txt b/intern/boolop/CMakeLists.txt deleted file mode 100644 index d8e9c0c94d7..00000000000 --- a/intern/boolop/CMakeLists.txt +++ /dev/null @@ -1,111 +0,0 @@ -# ***** BEGIN GPL LICENSE BLOCK ***** -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -# The Original Code is Copyright (C) 2006, Blender Foundation -# All rights reserved. -# -# The Original Code is: all of this file. -# -# Contributor(s): Jacques Beaurain. -# -# ***** END GPL LICENSE BLOCK ***** - -remove_strict_flags() - -set(INC - . - extern - intern - ../container - ../guardedalloc - ../memutil - ../moto/include - ../../source/blender/blenlib - ../../source/blender/makesdna -) - -set(INC_SYS - -) - -if(NOT WITH_CARVE) - set(SRC - intern/BOP_BBox.cpp - intern/BOP_BSPNode.cpp - intern/BOP_BSPTree.cpp - intern/BOP_Edge.cpp - intern/BOP_Face.cpp - intern/BOP_Face2Face.cpp - intern/BOP_Interface.cpp - intern/BOP_MathUtils.cpp - intern/BOP_Merge.cpp - intern/BOP_Merge2.cpp - intern/BOP_Mesh.cpp - intern/BOP_Segment.cpp - intern/BOP_Splitter.cpp - intern/BOP_Tag.cpp - intern/BOP_Triangulator.cpp - intern/BOP_Vertex.cpp - - extern/BOP_Interface.h - intern/BOP_BBox.h - intern/BOP_BSPNode.h - intern/BOP_BSPTree.h - intern/BOP_Chrono.h - intern/BOP_Edge.h - intern/BOP_Face.h - intern/BOP_Face2Face.h - intern/BOP_Indexs.h - intern/BOP_MathUtils.h - intern/BOP_Merge.h - intern/BOP_Merge2.h - intern/BOP_Mesh.h - intern/BOP_Misc.h - intern/BOP_Segment.h - intern/BOP_Splitter.h - intern/BOP_Tag.h - intern/BOP_Triangulator.h - intern/BOP_Vertex.h - ) -else() - set(SRC - intern/BOP_CarveInterface.cpp - extern/BOP_Interface.h - ) - - list(APPEND INC - ../../extern/carve/include - ) - - if(WITH_BOOST) - if(NOT MSVC) - # Boost is setting as preferred collections library in the Carve code when using MSVC compiler - add_definitions( - -DHAVE_BOOST_UNORDERED_COLLECTIONS - ) - endif() - - add_definitions( - -DCARVE_SYSTEM_BOOST - ) - - list(APPEND INC - ${BOOST_INCLUDE_DIR} - ) - endif() -endif() - -blender_add_lib(bf_intern_bop "${SRC}" "${INC}" "${INC_SYS}") diff --git a/intern/boolop/SConscript b/intern/boolop/SConscript deleted file mode 100644 index f630d1d58e0..00000000000 --- a/intern/boolop/SConscript +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/python -Import ('env') - -incs = '. intern extern ../moto/include ../container ../memutil' -incs += ' ../../source/blender/makesdna ../../intern/guardedalloc' -incs += ' ../../source/blender/blenlib' - -defs = [] - -if not env['WITH_BF_CARVE']: - import os - sources = env.Glob('intern/*.cpp') - sources.remove('intern' + os.sep + 'BOP_CarveInterface.cpp') -else: - sources = env.Glob('intern/BOP_CarveInterface.cpp') - incs += ' ../../extern/carve/include' - - if env['WITH_BF_BOOST']: - if env['OURPLATFORM'] not in ('win32-vc', 'win64-vc'): - # Boost is setting as preferred collections library in the Carve code when using MSVC compiler - if env['OURPLATFORM'] not in ('win32-mingw', 'win64-mingw'): - defs.append('HAVE_BOOST_UNORDERED_COLLECTIONS') - - defs.append('CARVE_SYSTEM_BOOST') - incs += ' ' + env['BF_BOOST_INC'] - -if (env['OURPLATFORM'] in ('win32-mingw', 'win64-mingw')): - env.BlenderLib ('bf_intern_bop', sources, Split(incs) , [], libtype='intern', priority = 5 ) -else: - env.BlenderLib ('bf_intern_bop', sources, Split(incs) , defs, libtype='intern', priority = 5 ) - diff --git a/intern/boolop/intern/BOP_BBox.cpp b/intern/boolop/intern/BOP_BBox.cpp deleted file mode 100644 index a42c7d936cf..00000000000 --- a/intern/boolop/intern/BOP_BBox.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file boolop/intern/BOP_BBox.cpp - * \ingroup boolopintern - */ - - -#include "BOP_BBox.h" - -#include "MT_Scalar.h" - -/** - * Constructs a nwe bounding box. - */ -BOP_BBox::BOP_BBox() -{ - m_minX = MT_INFINITY; - m_minY = MT_INFINITY; - m_minZ = MT_INFINITY; - m_maxX = -MT_INFINITY; - m_maxY = -MT_INFINITY; - m_maxZ = -MT_INFINITY; -} - -/** - * Constructs a new bounding box using three points. - * @param p1 first point - * @param p2 second point - * @param p3 third point - */ -BOP_BBox::BOP_BBox(const MT_Point3& p1,const MT_Point3& p2,const MT_Point3& p3) -{ - m_minX = BOP_MIN(BOP_MIN(p1[0],p2[0]),p3[0]); - m_minY = BOP_MIN(BOP_MIN(p1[1],p2[1]),p3[1]); - m_minZ = BOP_MIN(BOP_MIN(p1[2],p2[2]),p3[2]); - m_maxX = BOP_MAX(BOP_MAX(p1[0],p2[0]),p3[0]); - m_maxY = BOP_MAX(BOP_MAX(p1[1],p2[1]),p3[1]); - m_maxZ = BOP_MAX(BOP_MAX(p1[2],p2[2]),p3[2]); -} diff --git a/intern/boolop/intern/BOP_BBox.h b/intern/boolop/intern/BOP_BBox.h deleted file mode 100644 index c58bb704fc3..00000000000 --- a/intern/boolop/intern/BOP_BBox.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file boolop/intern/BOP_BBox.h - * \ingroup boolopintern - */ - - -#ifndef __BOP_BBOX_H__ -#define __BOP_BBOX_H__ - -#include "MT_Point3.h" -#include "BOP_MathUtils.h" - -#define BOP_MAX(a, b) ((a > b) ? a : b) -#define BOP_MIN(a, b) ((a < b) ? a : b) -#define BOP_ABS(a) ((a < 0) ? -(a) : a) - -class BOP_BBox -{ -public: - MT_Scalar m_minX; - MT_Scalar m_minY; - MT_Scalar m_minZ; - MT_Scalar m_maxX; - MT_Scalar m_maxY; - MT_Scalar m_maxZ; - MT_Scalar m_centerX; - MT_Scalar m_centerY; - MT_Scalar m_centerZ; - MT_Scalar m_extentX; - MT_Scalar m_extentY; - MT_Scalar m_extentZ; - -public: - BOP_BBox(); - BOP_BBox(const MT_Point3& p1,const MT_Point3& p2,const MT_Point3& p3); - inline void add(const MT_Point3& p) - { - m_minX = BOP_MIN(m_minX,p[0]); - m_minY = BOP_MIN(m_minY,p[1]); - m_minZ = BOP_MIN(m_minZ,p[2]); - m_maxX = BOP_MAX(m_maxX,p[0]); - m_maxY = BOP_MAX(m_maxY,p[1]); - m_maxZ = BOP_MAX(m_maxZ,p[2]); - }; - - inline const MT_Scalar getCenterX() const {return m_centerX;}; - inline const MT_Scalar getCenterY() const {return m_centerY;}; - inline const MT_Scalar getCenterZ() const {return m_centerZ;}; - - inline const MT_Scalar getExtentX() const {return m_extentX;}; - inline const MT_Scalar getExtentY() const {return m_extentY;}; - inline const MT_Scalar getExtentZ() const {return m_extentZ;}; - - inline void compute() { - m_extentX = (m_maxX-m_minX)/2.0f; - m_extentY = (m_maxY-m_minY)/2.0f; - m_extentZ = (m_maxZ-m_minZ)/2.0f; - m_centerX = m_minX+m_extentX; - m_centerY = m_minY+m_extentY; - m_centerZ = m_minZ+m_extentZ; - }; - - inline const bool intersect(const BOP_BBox& b) const { - return (!((BOP_comp(m_maxX,b.m_minX)<0) || (BOP_comp(b.m_maxX,m_minX)<0) || - (BOP_comp(m_maxY,b.m_minY)<0) || (BOP_comp(b.m_maxY,m_minY)<0) || - (BOP_comp(m_maxZ,b.m_minZ)<0) || (BOP_comp(b.m_maxZ,m_minZ)<0))); - }; - - -}; - -#endif diff --git a/intern/boolop/intern/BOP_BSPNode.cpp b/intern/boolop/intern/BOP_BSPNode.cpp deleted file mode 100644 index 3588e80c28e..00000000000 --- a/intern/boolop/intern/BOP_BSPNode.cpp +++ /dev/null @@ -1,718 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file boolop/intern/BOP_BSPNode.cpp - * \ingroup boolopintern - */ - - -#include "BOP_MathUtils.h" -#include "BOP_BSPNode.h" -#include "MT_assert.h" -#include "MT_MinMax.h" -#include <iostream> - -/** - * Constructs a new BSP node. - * @param plane split plane. - */ -BOP_BSPNode::BOP_BSPNode(const MT_Plane3& plane) -{ - m_plane = plane; - m_inChild = NULL; - m_outChild = NULL; - m_deep = 1; -} - -/** - * Destroys a BSP tree. - */ -BOP_BSPNode::~BOP_BSPNode() -{ - if (m_inChild!=NULL) delete m_inChild; - if (m_outChild!=NULL) delete m_outChild; -} - -/** - * Adds a new face to this BSP tree. - * @param pts vector containing face points - * @param plane face plane. - */ - -unsigned int BOP_BSPNode::addFace(const BOP_BSPPoints& pts, - const MT_Plane3& plane ) -{ - unsigned int newDeep = 0; - BOP_TAG tag = ON; - - // find out if any points on the "face" lie in either half-space - BOP_IT_BSPPoints ptsEnd = pts.end(); - for(BOP_IT_BSPPoints itp=pts.begin();itp!=ptsEnd;itp++){ - tag = (BOP_TAG) ((int) tag | (int)testPoint(*itp)); - } - - if (tag == ON) { } // face lies on hyperplane: do nothing - else if ((tag & IN) != 0 && (tag & OUT) == 0) { // face is entirely on inside - if (m_inChild != NULL) - newDeep = m_inChild->addFace(pts, plane) + 1; - else { - m_inChild = new BOP_BSPNode(plane); - newDeep = 2; - } - } else if ((tag & OUT) != 0 && (tag & IN) == 0) { // face is entirely on outside - if (m_outChild != NULL) - newDeep = m_outChild->addFace(pts, plane) + 1; - else { - m_outChild = new BOP_BSPNode(plane); - newDeep = 2; - } - } else { // face lies in both half-spaces: split it - BOP_BSPPoints inside, outside; - MT_Point3 lpoint= pts[pts.size()-1]; - BOP_TAG ltag = testPoint(lpoint); - BOP_TAG tstate = ltag; - - // classify each line segment, looking for endpoints which lie on different - // sides of the hyperplane. - - ptsEnd = pts.end(); - for(BOP_IT_BSPPoints itp=pts.begin();itp!=ptsEnd;itp++){ - MT_Point3 npoint= *itp; - BOP_TAG ntag = testPoint(npoint); - - if(ltag != ON) { // last point not on hyperplane - if(tstate == IN) { - if (m_inChild != NULL) inside.push_back(lpoint); - } else { - if (m_outChild != NULL) outside.push_back(lpoint); - } - if(ntag != ON && ntag != tstate) { // last, self in different half-spaces - MT_Point3 mpoint = BOP_intersectPlane( m_plane, lpoint, npoint ); - if (m_inChild != NULL) inside.push_back(mpoint); - if (m_outChild != NULL) outside.push_back(mpoint); - tstate = ntag; - } - } else { // last point on hyperplane, so we're switching - // half-spaces - // boundary point belong to both faces - if (m_inChild != NULL) inside.push_back(lpoint); - if (m_outChild != NULL) outside.push_back(lpoint); - tstate = ntag; // state changes to new point tag - } - lpoint = npoint; // save point, tag for next iteration - ltag = ntag; - } - - if (m_inChild != NULL) - newDeep = m_inChild->addFace(inside, plane) + 1; - else { - m_inChild = new BOP_BSPNode(plane); - newDeep = 2; - } - if (m_outChild != NULL) - newDeep = MT_max(newDeep, m_outChild->addFace(outside, plane) + 1); - else { - m_outChild = new BOP_BSPNode(plane); - newDeep = MT_max(newDeep,(unsigned int)2); - } - } - - // update the deep attribute - m_deep = MT_max(m_deep,newDeep); - - return m_deep; -} - -/** - * Tests the point situation respect the node plane. - * @param p point to test. - * @return TAG result: IN, OUT or ON. - */ -BOP_TAG BOP_BSPNode::testPoint(const MT_Point3& p) const -{ - return BOP_createTAG(BOP_classify(p,m_plane)); - -} - -/** - * Classifies a face using its coordinates and plane. - * @param p1 first point. - * @param p2 second point. - * @param p3 third point. - * @param plane face plane. - * @return TAG result: IN, OUT or IN&OUT. - */ -BOP_TAG BOP_BSPNode::classifyFace(const MT_Point3& p1, - const MT_Point3& p2, - const MT_Point3& p3, - const MT_Plane3& plane) const -{ - // local variables - MT_Point3 auxp1, auxp2; - BOP_TAG auxtag1, auxtag2, auxtag3; - - switch(BOP_createTAG(testPoint(p1),testPoint(p2),testPoint(p3))) { - // Classify the face on the IN side - case IN_IN_IN : - return classifyFaceIN(p1, p2, p3, plane); - case IN_IN_ON : - case IN_ON_IN : - case ON_IN_IN : - case IN_ON_ON : - case ON_IN_ON : - case ON_ON_IN : - return BOP_addON(classifyFaceIN(p1, p2, p3, plane)); - - // Classify the face on the OUT side - case OUT_OUT_OUT : - return classifyFaceOUT(p1, p2, p3, plane); - case OUT_OUT_ON : - case OUT_ON_OUT : - case ON_OUT_OUT : - case ON_ON_OUT : - case ON_OUT_ON : - case OUT_ON_ON : - return BOP_addON(classifyFaceOUT(p1, p2, p3, plane)); - - // Classify the ON face depending on it plane normal - case ON_ON_ON : - if (hasSameOrientation(plane)) - return BOP_addON(classifyFaceIN(p1, p2, p3, plane)); - else - return BOP_addON(classifyFaceOUT(p1, p2, p3, plane)); - - // Classify the face IN/OUT and one vertex ON - // becouse only one ON, only one way to subdivide the face - case IN_OUT_ON : - auxp1 = BOP_intersectPlane(m_plane, p1, p2); - auxtag1 = classifyFaceIN( p1, auxp1 , p3, plane); - auxtag2 = classifyFaceOUT(auxp1, p2, p3, plane); - return (BOP_compTAG(auxtag1,auxtag2)?BOP_addON(auxtag1):INOUT); - - case OUT_IN_ON : - auxp1 = BOP_intersectPlane(m_plane, p1, p2); - auxtag1 = classifyFaceOUT(p1, auxp1, p3, plane); - auxtag2 = classifyFaceIN( auxp1, p2, p3, plane); - return (BOP_compTAG(auxtag1,auxtag2)?BOP_addON(auxtag1):INOUT); - - case IN_ON_OUT : - auxp1 = BOP_intersectPlane(m_plane, p1, p3); - auxtag1 = classifyFaceIN( p1, p2, auxp1, plane); - auxtag2 = classifyFaceOUT(p2, p3, auxp1, plane); - return (BOP_compTAG(auxtag1,auxtag2)?BOP_addON(auxtag1):INOUT); - - case OUT_ON_IN : - auxp1 = BOP_intersectPlane(m_plane, p1, p3); - auxtag1 = classifyFaceOUT(p1, p2, auxp1, plane); - auxtag2 = classifyFaceIN( p2, p3, auxp1, plane); - return (BOP_compTAG(auxtag1,auxtag2)?BOP_addON(auxtag1):INOUT); - - case ON_IN_OUT : - auxp1 = BOP_intersectPlane(m_plane, p2, p3); - auxtag1 = classifyFaceIN( p1, p2, auxp1, plane); - auxtag2 = classifyFaceOUT(auxp1, p3, p1, plane); - return (BOP_compTAG(auxtag1,auxtag2)?BOP_addON(auxtag1):INOUT); - - case ON_OUT_IN : - auxp1 = BOP_intersectPlane(m_plane, p2, p3); - auxtag1 = classifyFaceOUT(p1, p2, auxp1, plane); - auxtag2 = classifyFaceIN( auxp1, p3, p1, plane); - return (BOP_compTAG(auxtag1,auxtag2)?BOP_addON(auxtag1):INOUT); - - // Classify IN/OUT face without ON vertices. - // Two ways to divide the triangle, - // will chose the least degenerated sub-triangles. - case IN_OUT_OUT : - auxp1 = BOP_intersectPlane(m_plane, p1, p2); - auxp2 = BOP_intersectPlane(m_plane, p1, p3); - - // f1: p1 auxp1 , auxp1 auxp2 - auxtag1 = classifyFaceIN(p1, auxp1, auxp2, plane); - - // f2: auxp1 p2 , p2 auxp2; f3: p2 p3 , p3 auxp2 || - // f2: auxp1 p3, p3 auxp2; f3: p2 p3 , p3 auxp1 - if (BOP_isInsideCircle(p2, p3, auxp1, auxp2)) { - auxtag2 = classifyFaceOUT(auxp1, p2, auxp2, plane); - auxtag3 = classifyFaceOUT(p2, p3, auxp2, plane); - } - else { - auxtag2 = classifyFaceOUT(auxp1, p3, auxp2, plane); - auxtag3 = classifyFaceOUT(p2, p3, auxp1, plane); - } - return (BOP_compTAG(auxtag1,auxtag2)&&BOP_compTAG(auxtag2,auxtag3)?auxtag1:INOUT); - - case OUT_IN_IN : - auxp1 = BOP_intersectPlane(m_plane, p1, p2); - auxp2 = BOP_intersectPlane(m_plane, p1, p3); - - // f1: p1 auxp1 , auxp1 auxp2 - auxtag1 = classifyFaceOUT(p1, auxp1, auxp2, plane); - - // f2: auxp1 p2 , p2 auxp2; f3: p2 p3 , p3 auxp2 || - // f2: auxp1 p3, p3 auxp2; f3: p2 p3 , p3 auxp1 - if (BOP_isInsideCircle(p2, p3, auxp1, auxp2)) { - auxtag2 = classifyFaceIN(auxp1, p2, auxp2, plane); - auxtag3 = classifyFaceIN(p2, p3, auxp2, plane); - } - else { - auxtag2 = classifyFaceIN(auxp1, p3, auxp2, plane); - auxtag3 = classifyFaceIN(p2, p3, auxp1, plane); - } - return (BOP_compTAG(auxtag1,auxtag2)&&BOP_compTAG(auxtag2,auxtag3)?auxtag1:INOUT); - - case OUT_IN_OUT : - auxp1 = BOP_intersectPlane(m_plane, p2, p1); - auxp2 = BOP_intersectPlane(m_plane, p2, p3); - - // f1: auxp1 p2 , p2 auxp2 - auxtag1 = classifyFaceIN(auxp1, p2, auxp2, plane); - - // f2: p1 auxp1 , auxp1 auxp2; f3: p1 auxp2 , auxp2 p3 || - // f2: p3 auxp1, auxp1 auxp2 f3:p1 auxp1, auxp1 p3 - if (BOP_isInsideCircle(p1, p3, auxp1, auxp2)) { - auxtag2 = classifyFaceOUT(p1, auxp1, auxp2, plane); - auxtag3 = classifyFaceOUT(p1, auxp2, p3, plane); - } - else { - auxtag2 = classifyFaceOUT(p3, auxp1, auxp2, plane); - auxtag3 = classifyFaceOUT(p1, auxp1, p3, plane); - } - return (BOP_compTAG(auxtag1,auxtag2)&&BOP_compTAG(auxtag2,auxtag3)?auxtag1:INOUT); - - case IN_OUT_IN : - auxp1 = BOP_intersectPlane(m_plane, p2, p1); - auxp2 = BOP_intersectPlane(m_plane, p2, p3); - - // f1: auxp1 p2 , p2 auxp2 - auxtag1 = classifyFaceOUT(auxp1, p2, auxp2, plane); - - // f2: p1 auxp1 , auxp1 auxp2; f3: p1 auxp2 , auxp2 p3 || - // f2: p3 auxp1, auxp1 auxp2 f3:p1 auxp1, auxp1 p3 - if (BOP_isInsideCircle(p1, p3, auxp1, auxp2)) { - auxtag2 = classifyFaceIN(p1, auxp1, auxp2, plane); - auxtag3 = classifyFaceIN(p1, auxp2, p3, plane); - } - else { - auxtag2 = classifyFaceIN(p3, auxp1, auxp2, plane); - auxtag3 = classifyFaceIN(p1, auxp1, p3, plane); - } - return (BOP_compTAG(auxtag1,auxtag2)&&BOP_compTAG(auxtag2,auxtag3)?auxtag1:INOUT); - - case OUT_OUT_IN : - auxp1 = BOP_intersectPlane(m_plane, p3, p1); - auxp2 = BOP_intersectPlane(m_plane, p3, p2); - - // f1: auxp1 auxp2 , auxp2 p3 - auxtag1 = classifyFaceIN(auxp1, auxp2, p3, plane); - - // f2: p1 p2 , p2 auxp2; f3:p1 auxp2 , auxp2 auxp1 || - // f2: p1 p2, p2 auxp1; f3:p2 auxp2, auxp2 auxp1 - if (BOP_isInsideCircle(p1, p2, auxp1, auxp2)) { - auxtag2 = classifyFaceOUT(p1, p2, auxp2, plane); - auxtag3 = classifyFaceOUT(p1, auxp2, auxp1, plane); - } - else { - auxtag2 = classifyFaceOUT(p1, p2, auxp1, plane); - auxtag3 = classifyFaceOUT(p2, auxp2, auxp1, plane); - } - return (BOP_compTAG(auxtag1,auxtag2)&&BOP_compTAG(auxtag2,auxtag3)?auxtag1:INOUT); - - case IN_IN_OUT : - auxp1 = BOP_intersectPlane(m_plane, p3, p1); - auxp2 = BOP_intersectPlane(m_plane, p3, p2); - - // f1: auxp1 auxp2 , auxp2 p3 - auxtag1 = classifyFaceOUT(auxp1, auxp2, p3, plane); - - // f2: p1 p2 , p2 auxp2; f3:p1 auxp2 , auxp2 auxp1 || - // f2: p1 p2, p2 auxp1; f3:p2 auxp2, auxp2 auxp1 - if (BOP_isInsideCircle(p1, p2, auxp1, auxp2)) { - auxtag2 = classifyFaceIN(p1, p2, auxp2, plane); - auxtag3 = classifyFaceIN(p1, auxp2, auxp1, plane); - } - else { - auxtag2 = classifyFaceIN(p1, p2, auxp1, plane); - auxtag3 = classifyFaceIN(p2, auxp2, auxp1, plane); - } - return (BOP_compTAG(auxtag1,auxtag2)&&BOP_compTAG(auxtag2,auxtag3)?auxtag1:INOUT); - - default: - return UNCLASSIFIED; - } -} - -/** - * Classifies a face through IN subtree. - * @param p1 firts face vertex. - * @param p2 second face vertex. - * @param p3 third face vertex. - * @param plane face plane. - */ -BOP_TAG BOP_BSPNode::classifyFaceIN(const MT_Point3& p1, - const MT_Point3& p2, - const MT_Point3& p3, - const MT_Plane3& plane) const -{ - if (m_inChild != NULL) - return m_inChild->classifyFace(p1, p2, p3, plane); - else - return IN; -} - -/** - * Classifies a face through OUT subtree. - * @param p1 firts face vertex. - * @param p2 second face vertex. - * @param p3 third face vertex. - * @param plane face plane. - */ -BOP_TAG BOP_BSPNode::classifyFaceOUT(const MT_Point3& p1, - const MT_Point3& p2, - const MT_Point3& p3, - const MT_Plane3& plane) const -{ - if (m_outChild != NULL) - return m_outChild->classifyFace(p1, p2, p3, plane); - else - return OUT; -} - -/** - * Simplified classification (optimized but requires that the face is not - * INOUT; only works correctly with faces completely IN or OUT). - * @param p1 firts face vertex. - * @param p2 second face vertex. - * @param p3 third face vertex. - * @param plane face plane. - * @return TAG result: IN or OUT. - */ -BOP_TAG BOP_BSPNode::simplifiedClassifyFace(const MT_Point3& p1, - const MT_Point3& p2, - const MT_Point3& p3, - const MT_Plane3& plane) const -{ - MT_Point3 ret[3]; - - BOP_TAG tag = BOP_createTAG(testPoint(p1),testPoint(p2),testPoint(p3)); - - if ((tag & IN_IN_IN) != 0) { - if ((tag & OUT_OUT_OUT) != 0) { - if (splitTriangle(ret,m_plane,p1,p2,p3,tag)<0) - return simplifiedClassifyFaceIN(ret[0],ret[1],ret[2],plane); - else - return simplifiedClassifyFaceOUT(ret[0],ret[1],ret[2],plane); - } - else { - return simplifiedClassifyFaceIN(p1,p2,p3,plane); - } - } - else { - if ((tag & OUT_OUT_OUT) != 0) { - return simplifiedClassifyFaceOUT(p1,p2,p3,plane); - } - else { - if (hasSameOrientation(plane)) { - return simplifiedClassifyFaceIN(p1,p2,p3,plane); - } - else { - return simplifiedClassifyFaceOUT(p1,p2,p3,plane); - } - } - } - - return IN; -} - -/** - * Simplified classify through IN subtree. - * @param p1 firts face vertex. - * @param p2 second face vertex. - * @param p3 third face vertex. - * @param plane face plane. - */ -BOP_TAG BOP_BSPNode::simplifiedClassifyFaceIN(const MT_Point3& p1, - const MT_Point3& p2, - const MT_Point3& p3, - const MT_Plane3& plane) const -{ - if (m_inChild != NULL) - return m_inChild->simplifiedClassifyFace(p1, p2, p3, plane); - else - return IN; -} - -/** - * Simplified classify through OUT subtree. - * @param p1 firts face vertex. - * @param p2 second face vertex. - * @param p3 third face vertex. - * @param plane face plane. - */ -BOP_TAG BOP_BSPNode::simplifiedClassifyFaceOUT(const MT_Point3& p1, - const MT_Point3& p2, - const MT_Point3& p3, - const MT_Plane3& plane) const -{ - if (m_outChild != NULL) - return m_outChild->simplifiedClassifyFace(p1, p2, p3, plane); - else - return OUT; -} - -/** - * Determine if the input plane have the same orientation of the node plane. - * @param plane plane to test. - * @return TRUE if have the same orientation, FALSE otherwise. - */ -bool BOP_BSPNode::hasSameOrientation(const MT_Plane3& plane) const -{ - return (BOP_orientation(m_plane,plane)>0); -} - -/** - * Comparation between both childrens. - * @return 0 equal deep, 1 inChild more deep than outChild and -1 otherwise. - */ -int BOP_BSPNode::compChildren() const -{ - unsigned int deep1 = (m_inChild == NULL?0:m_inChild->getDeep()); - unsigned int deep2 = (m_outChild == NULL?0:m_outChild->getDeep()); - - if (deep1 == deep2) - return 0; - else if (deep1 < deep2) - return -1; - else - return 1; -} - -/** - * Extract a subtriangle from input triangle, is used for simplified classification. - * The subtriangle is obtained spliting the input triangle by input plane. - * @param res output subtriangle result. - * @param plane spliter plane. - * @param p1 first triangle point. - * @param p2 second triangle point. - * @param p3 third triangle point. - * @param tag triangle orientation respect the plane. - */ -int BOP_BSPNode::splitTriangle(MT_Point3* res, - const MT_Plane3& plane, - const MT_Point3& p1, - const MT_Point3& p2, - const MT_Point3& p3, - const BOP_TAG tag) const -{ - switch (tag) { - case IN_OUT_ON : - if (compChildren()<0) { - // f1: p1 new p3 || new = splitedge(p1,p2) - res[0] = p1; - res[1] = BOP_intersectPlane( plane, p1, p2 ); - res[2] = p3; - return -1; - }else{ - // f1: p2 new p3 || new = splitedge(p1,p2) - res[0] = p2; - res[1] = p3; - res[2] = BOP_intersectPlane( plane, p1, p2 ); - return 1; - } - case OUT_IN_ON : - if (compChildren()<0) { - // f1: p2 new p3 || new = splitedge(p1,p2) - res[0] = p2; - res[1] = p3; - res[2] = BOP_intersectPlane( plane, p1, p2 ); - return -1; - }else{ - // f1: p1 new p3 || new = splitedge(p1,p2) - res[0] = p1; - res[1] = BOP_intersectPlane( plane, p1, p2 ); - res[2] = p3; - return 1; - } - case IN_ON_OUT : - if (compChildren()<0) { - // f1: p1 p2 new || new = splitedge(p1,p3) - res[0] = p1; - res[1] = p2; - res[2] = BOP_intersectPlane( plane, p1, p3 ); - return -1; - }else{ - // f1: p2 p3 new || new = splitedge(p1,p3) - res[0] = p2; - res[1] = p3; - res[2] = BOP_intersectPlane( plane, p1, p3 ); - return 1; - } - case OUT_ON_IN : - if (compChildren()<0) { - // f1: p2 p3 new || new = splitedge(p1,p3) - res[0] = p2; - res[1] = p3; - res[2] = BOP_intersectPlane( plane, p1, p3 ); - return -1; - }else{ - // f1: p1 p2 new || new = splitedge(p1,p3) - res[0] = p1; - res[1] = p2; - res[2] = BOP_intersectPlane( plane, p1, p3 ); - return 1; - } - case ON_IN_OUT : - if (compChildren()<0) { - // f1: p1 p2 new || new = splitedge(p2,p3) - res[0] = p1; - res[1] = p2; - res[2] = BOP_intersectPlane( plane, p2, p3 ); - return -1; - }else{ - // f1: p1 p3 new || new = splitedge(p2,p3) - res[0] = p1; - res[1] = BOP_intersectPlane( plane, p2, p3 ); - res[2] = p3; - return 1; - } - case ON_OUT_IN : - if (compChildren()<0) { - // f1: p1 p2 new || new = splitedge(p2,p3) - res[0] = p1; - res[1] = BOP_intersectPlane( plane, p2, p3 ); - res[2] = p3; - return -1; - }else{ - // f1: p1 p2 new || new = splitedge(p2,p3) - res[0] = p1; - res[1] = p2; - res[2] = BOP_intersectPlane( plane, p2, p3 ); - return 1; - } - case IN_OUT_OUT : - if (compChildren()<=0) { - // f1: p1 new1 new2 || new1 = splitedge(p1,p2) new2 = splitedge(p1,p3) - res[0] = p1; - res[1] = BOP_intersectPlane( plane, p1, p2 ); - res[2] = BOP_intersectPlane( plane, p1, p3 ); - return -1; - }else{ - // f1: p1 new1 new2 || new1 = splitedge(p1,p2) new2 = splitedge(p1,p3) - res[0] = BOP_intersectPlane( plane, p1, p2 ); - res[1] = p2; - res[2] = p3; - return 1; - } - case OUT_IN_IN : - if (compChildren()<0) { - // f1: p1 new1 new2 || new1 = splitedge(p1,p2) new2 = splitedge(p1,p3) - res[0] = BOP_intersectPlane( plane, p1, p2 ); - res[1] = p2; - res[2] = p3; - return -1; - }else { - // f1: p1 new1 new2 || new1 = splitedge(p1,p2) new2 = splitedge(p1,p3) - res[0] = p1; - res[1] = BOP_intersectPlane( plane, p1, p2 ); - res[2] = BOP_intersectPlane( plane, p1, p3 ); - return 1; - } - case OUT_IN_OUT : - if (compChildren()<=0) { - // f1: new1 p2 new2 || new1 = splitedge(p2,p1) new2 = splitedge(p2,p3) - res[0] = BOP_intersectPlane( plane, p2, p1 ); - res[1] = p2; - res[2] = BOP_intersectPlane( plane, p2, p3 ); - return -1; - }else { - // f1: new1 p2 new2 || new1 = splitedge(p2,p1) new2 = splitedge(p2,p3) - res[0] = p1; - res[1] = BOP_intersectPlane( plane, p2, p1 ); - res[2] = BOP_intersectPlane( plane, p2, p3 ); - return 1; - } - case IN_OUT_IN : - if (compChildren()<0) { - // f1: new1 p2 new2 || new1 = splitedge(p2,p1) new2 = splitedge(p2,p3) - res[0] = p1; - res[1] = BOP_intersectPlane( plane, p2, p1 ); - res[2] = BOP_intersectPlane( plane, p2, p3 ); - return -1; - }else{ - // f1: new1 p2 new2 || new1 = splitedge(p2,p1) new2 = splitedge(p2,p3) - res[0] = BOP_intersectPlane( plane, p2, p1 ); - res[1] = p2; - res[2] = BOP_intersectPlane( plane, p2, p3 ); - return 1; - } - case OUT_OUT_IN : - if (compChildren()<=0) { - // f1: new1 new2 p2 || new1 = splitedge(p3,p1) new2 = splitedge(p3,p2) - res[0] = BOP_intersectPlane( plane, p3, p1 ); - res[1] = BOP_intersectPlane( plane, p3, p2 ); - res[2] = p3; - return -1; - }else{ - // f1: new1 new2 p2 || new1 = splitedge(p3,p1) new2 = splitedge(p3,p2) - res[0] = BOP_intersectPlane( plane, p3, p1 ); - res[1] = p1; - res[2] = p2; - return 1; - } - case IN_IN_OUT : - if (compChildren()<0) { - // f1: new1 new2 p2 || new1 = splitedge(p3,p1) new2 = splitedge(p3,p2) - res[0] = BOP_intersectPlane( plane, p3, p1 ); - res[1] = p1; - res[2] = p2; - return -1; - }else{ - // f1: new1 new2 p2 || new1 = splitedge(p3,p1) new2 = splitedge(p3,p2) - res[0] = BOP_intersectPlane( plane, p3, p1 ); - res[1] = BOP_intersectPlane( plane, p3, p2 ); - res[2] = p3; - return 1; - } - default: - return 0; - } -} - -/** - * Debug info. - */ -void BOP_BSPNode::print(unsigned int deep) -{ - std::cout << "(" << deep << "," << m_plane << ")," << std::endl; - if (m_inChild != NULL) - m_inChild->print(deep + 1); - else - std::cout << "(" << deep+1 << ",None)," << std::endl; - if (m_outChild != NULL) - m_outChild->print(deep + 1); - else - std::cout << "(" << deep+1 << ",None)," << std::endl; -} diff --git a/intern/boolop/intern/BOP_BSPNode.h b/intern/boolop/intern/BOP_BSPNode.h deleted file mode 100644 index 6c110416dd7..00000000000 --- a/intern/boolop/intern/BOP_BSPNode.h +++ /dev/null @@ -1,107 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file boolop/intern/BOP_BSPNode.h - * \ingroup boolopintern - */ - - -#ifndef __BOP_BSPNODE_H__ -#define __BOP_BSPNODE_H__ - -#include "MT_Plane3.h" -#include "BOP_Tag.h" -#include "BOP_Face.h" - -typedef std::vector<MT_Point3> BOP_BSPPoints; -typedef std::vector<MT_Point3>::const_iterator BOP_IT_BSPPoints; - -class BOP_BSPNode -{ -protected: - BOP_BSPNode* m_inChild; - BOP_BSPNode* m_outChild; - MT_Plane3 m_plane; - unsigned int m_deep; - -public: - // Construction methods - BOP_BSPNode(const MT_Plane3& plane); - ~BOP_BSPNode(); - unsigned int addFace(const BOP_BSPPoints& pts, - const MT_Plane3& plane); - BOP_TAG classifyFace(const MT_Point3& p1, - const MT_Point3& p2, - const MT_Point3& p3, - const MT_Plane3& plane) const; - BOP_TAG simplifiedClassifyFace(const MT_Point3& p1, - const MT_Point3& p2, - const MT_Point3& p3, - const MT_Plane3& plane) const; - -protected: - BOP_TAG testPoint(const MT_Point3& p) const; - BOP_TAG classifyFaceIN(const MT_Point3& p1, - const MT_Point3& p2, - const MT_Point3& p3, - const MT_Plane3& plane) const; - BOP_TAG classifyFaceOUT(const MT_Point3& p1, - const MT_Point3& p2, - const MT_Point3& p3, - const MT_Plane3& plane) const; - BOP_TAG simplifiedClassifyFaceIN(const MT_Point3& p1, - const MT_Point3& p2, - const MT_Point3& p3, - const MT_Plane3& plane) const; - BOP_TAG simplifiedClassifyFaceOUT(const MT_Point3& p1, - const MT_Point3& p2, - const MT_Point3& p3, - const MT_Plane3& plane) const; - bool hasSameOrientation(const MT_Plane3& plane) const; - int compChildren() const; - int splitTriangle(MT_Point3* res, - const MT_Plane3& plane, - const MT_Point3& p1, - const MT_Point3& p2, - const MT_Point3& p3, - const BOP_TAG tag) const; - -public: - // Inline acces methods - inline void setInChild(BOP_BSPNode* inChild) { m_inChild=inChild; }; - inline void setOutChild(BOP_BSPNode* outChild) { m_outChild=outChild; }; - inline BOP_BSPNode* getInChild() { return m_inChild; }; - inline BOP_BSPNode* getOutChild() { return m_outChild; }; - inline bool isLeaf() const { return !m_inChild && !m_outChild; }; - inline void setPlane(const MT_Plane3& plane) {m_plane=plane;}; - inline MT_Plane3& getPlane() { return m_plane; }; - - inline unsigned int getDeep() const {return m_deep;}; - void print(unsigned int deep); -}; - -#endif diff --git a/intern/boolop/intern/BOP_BSPTree.cpp b/intern/boolop/intern/BOP_BSPTree.cpp deleted file mode 100644 index 7a8ed417be4..00000000000 --- a/intern/boolop/intern/BOP_BSPTree.cpp +++ /dev/null @@ -1,190 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file boolop/intern/BOP_BSPTree.cpp - * \ingroup boolopintern - */ - - -#include "BOP_BSPTree.h" -#include <vector> -#include <iostream> - -/** - * Constructs a new BSP tree. - */ -BOP_BSPTree::BOP_BSPTree() -{ - m_root = NULL; - m_bspBB = NULL; -} - -/** - * Destroys a BSP tree. - */ -BOP_BSPTree::~BOP_BSPTree() -{ - if (m_root!=NULL) delete m_root; - if (m_bspBB!=NULL) delete m_bspBB; -} - -/** - * Adds all mesh faces to BSP tree. - * @param mesh mesh to add. - * @param facesList face list to add. - */ -void BOP_BSPTree::addMesh(BOP_Mesh* mesh, BOP_Faces& facesList) -{ - for (BOP_IT_Faces it = facesList.begin(); it != facesList.end(); ++it) { - addFace( mesh, *it ); - } - -} - -/** - * Adds a new face into bsp tree. - * @param mesh Input data for BSP tree. - * @param face index to mesh face. - */ - -void BOP_BSPTree::addFace(BOP_Mesh* mesh, BOP_Face* face) -{ - addFace(mesh->getVertex(face->getVertex(0))->getPoint(), - mesh->getVertex(face->getVertex(1))->getPoint(), - mesh->getVertex(face->getVertex(2))->getPoint(), - face->getPlane()); -} - -/** - * Adds new facee to the bsp-tree. - * @param p1 first face point. - * @param p2 second face point. - * @param p3 third face point. - * @param plane face plane. - */ -void BOP_BSPTree::addFace(const MT_Point3& p1, - const MT_Point3& p2, - const MT_Point3& p3, - const MT_Plane3& plane) -{ - if (m_root == NULL) - m_root = new BOP_BSPNode(plane); - else { - BOP_BSPPoints pts; - - pts.push_back(p1); - pts.push_back(p2); - pts.push_back(p3); - - m_root->addFace(pts,plane); - } - - // update bounding box - m_bbox.add(p1); - m_bbox.add(p2); - m_bbox.add(p3); -} - -/** - * Tests face vs bsp-tree (returns where is the face respect bsp planes). - * @param p1 first face triangle point. - * @param p2 secons face triangle point. - * @param p3 third face triangle point. - * @param plane face plane. - * @return BSP_IN, BSP_OUT or BSP_IN_OUT - */ -BOP_TAG BOP_BSPTree::classifyFace(const MT_Point3& p1, - const MT_Point3& p2, - const MT_Point3& p3, - const MT_Plane3& plane) const -{ - if ( m_root != NULL ) - return m_root->classifyFace(p1, p2, p3, plane); - else - return OUT; -} - -/** - * Filters a face using the BSP bounding infomation. - * @param p1 first face triangle point. - * @param p2 secons face triangle point. - * @param p3 third face triangle point. - * @param face face to test. - * @return UNCLASSIFIED, BSP_IN, BSP_OUT or BSP_IN_OUT - */ -BOP_TAG BOP_BSPTree::filterFace(const MT_Point3& p1, - const MT_Point3& p2, - const MT_Point3& p3, - BOP_Face* face) -{ - if ( m_bspBB != NULL ) { - return m_bspBB->classifyFace(p1,p2,p3,face->getPlane()); - } - else - return UNCLASSIFIED; -} - -/** - * Tests face vs bsp-tree (returns where is the face respect bsp planes). - * @param p1 first face triangle point. - * @param p2 secons face triangle point. - * @param p3 third face triangle point. - * @param plane face plane. - * @return BSP_IN, BSP_OUT or BSP_IN_OUT - */ -BOP_TAG BOP_BSPTree::simplifiedClassifyFace(const MT_Point3& p1, - const MT_Point3& p2, - const MT_Point3& p3, - const MT_Plane3& plane) const -{ - if ( m_root != NULL ) - return m_root->simplifiedClassifyFace(p1, p2, p3, plane); - else - return OUT; -} - -/** - * Returns the deep of this BSP tree. - * @return tree deep - */ -unsigned int BOP_BSPTree::getDeep() const -{ - if ( m_root != NULL ) - return m_root->getDeep(); - else - return 0; -} - -/** - * Prints debug information. - */ -void BOP_BSPTree::print() -{ - if ( m_root != NULL ) - m_root->print( 0 ); -} - diff --git a/intern/boolop/intern/BOP_BSPTree.h b/intern/boolop/intern/BOP_BSPTree.h deleted file mode 100644 index 5dc55e47175..00000000000 --- a/intern/boolop/intern/BOP_BSPTree.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file boolop/intern/BOP_BSPTree.h - * \ingroup boolopintern - */ - - -#ifndef __BOP_BSPTREE_H__ -#define __BOP_BSPTREE_H__ - -#include "BOP_BSPNode.h" -#include "BOP_Mesh.h" -#include "BOP_Tag.h" -#include "BOP_BBox.h" - -class BOP_BSPTree -{ -protected: - BOP_BSPNode* m_root; - BOP_BSPNode* m_bspBB; - BOP_BBox m_bbox; -public: - // Construction methods - BOP_BSPTree(); - virtual ~BOP_BSPTree(); - void addMesh(BOP_Mesh* mesh, BOP_Faces& facesList); - void addFace(BOP_Mesh* mesh, BOP_Face* face); - virtual void addFace(const MT_Point3& p1, - const MT_Point3& p2, - const MT_Point3& p3, - const MT_Plane3& plane); - BOP_TAG classifyFace(const MT_Point3& p1, - const MT_Point3& p2, - const MT_Point3& p3, - const MT_Plane3& plane) const; - BOP_TAG filterFace(const MT_Point3& p1, - const MT_Point3& p2, - const MT_Point3& p3, - BOP_Face* face); - BOP_TAG simplifiedClassifyFace(const MT_Point3& p1, - const MT_Point3& p2, - const MT_Point3& p3, - const MT_Plane3& plane) const; - unsigned int getDeep() const; - void print(); - inline void setRoot(BOP_BSPNode* root) {m_root=root;}; - inline BOP_BSPNode* getRoot() const {return m_root;}; -}; - -#endif - diff --git a/intern/boolop/intern/BOP_Chrono.h b/intern/boolop/intern/BOP_Chrono.h deleted file mode 100644 index 8f09eeae82e..00000000000 --- a/intern/boolop/intern/BOP_Chrono.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file boolop/intern/BOP_Chrono.h - * \ingroup boolopintern - */ - - -#ifndef __BOP_CHRONO_H__ -#define __BOP_CHRONO_H__ - -#include <time.h> - -class BOP_Chrono -{ -private: - clock_t m_begin; -public: - BOP_Chrono(){}; - void start() {m_begin = clock();}; - float stamp() { - clock_t c = clock(); - clock_t stmp = c - m_begin; - m_begin = c; - float t = ((float) stmp / (float) CLOCKS_PER_SEC)*1000.0f; - return t; - }; -}; - -#endif diff --git a/intern/boolop/intern/BOP_Edge.cpp b/intern/boolop/intern/BOP_Edge.cpp deleted file mode 100644 index fc03dd897d3..00000000000 --- a/intern/boolop/intern/BOP_Edge.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file boolop/intern/BOP_Edge.cpp - * \ingroup boolopintern - */ - - -#include "BOP_Edge.h" - -/** - * Constructs a new edge. - * @param v1 vertex index - * @param v2 vertex index - */ -BOP_Edge::BOP_Edge(BOP_Index v1, BOP_Index v2) -{ - m_vertexs[0] = v1; - m_vertexs[1] = v2; -} - -/** - * Adds a new face index to this edge. - * @param i face index - */ -void BOP_Edge::addFace(BOP_Index i) -{ - if (!containsFace(i)) - m_faces.push_back(i); -} - -/** - * Returns if this edge contains the specified face index. - * @param i face index - * @return true if this edge contains the specified face index, false otherwise - */ -bool BOP_Edge::containsFace(BOP_Index i) -{ - int pos=0; - for(BOP_IT_Indexs it = m_faces.begin();it!=m_faces.end();pos++,it++) { - if ((*it) == i) - return true; - } - - return false; -} - -/** - * Replaces an edge vertex index. - * @param oldIndex old vertex index - * @param newIndex new vertex index - */ -void BOP_Edge::replaceVertexIndex(BOP_Index oldIndex, BOP_Index newIndex) -{ - if (m_vertexs[0] == oldIndex) m_vertexs[0] = newIndex; - else if (m_vertexs[1] == oldIndex) m_vertexs[1] = newIndex; -} - -#ifdef BOP_NEW_MERGE - -/** - * Returns if this edge contains the specified face index. - * @param i face index - * @return true if this edge contains the specified face index, false otherwise - */ -bool BOP_Edge::removeFace(BOP_Index i) -{ - int pos=0; - for(BOP_IT_Indexs it = m_faces.begin();it!=m_faces.end();pos++,it++) { - if ((*it) == i) { - m_faces.erase(it); - return true; - } - } - - return false; -} - -#endif - -#ifdef BOP_DEBUG - -#include <iostream> - -/** - * Implements operator <<. - */ -ostream &operator<<(ostream &stream, BOP_Edge *e) -{ - stream << "Edge[" << e->getVertex1() << "," << e->getVertex2(); -#ifdef BOP_NEW_MERGE - if(e->m_used) - stream << "] (used)"; - else - stream << "] (unused)"; -#endif - return stream; -} -#endif - - diff --git a/intern/boolop/intern/BOP_Edge.h b/intern/boolop/intern/BOP_Edge.h deleted file mode 100644 index fd2f53b1aa4..00000000000 --- a/intern/boolop/intern/BOP_Edge.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file boolop/intern/BOP_Edge.h - * \ingroup boolopintern - */ - - -#ifndef __BOP_EDGE_H__ -#define __BOP_EDGE_H__ - -#include "BOP_Indexs.h" -#include "BOP_Misc.h" - -class BOP_Edge -{ -private: - BOP_Index m_vertexs[2]; - BOP_Indexs m_faces; -#ifdef BOP_NEW_MERGE - bool m_used; -#endif - - bool containsFace(BOP_Index i); - -public: - BOP_Edge(BOP_Index v1, BOP_Index v2); - inline BOP_Index getVertex1() { return m_vertexs[0];}; - inline BOP_Index getVertex2() { return m_vertexs[1];}; - void replaceVertexIndex(BOP_Index oldIndex, BOP_Index newIndex); - inline BOP_Index getFace(unsigned int i){return m_faces[i];}; - inline unsigned int getNumFaces(){return m_faces.size();}; - inline BOP_Indexs &getFaces(){return m_faces;}; - void addFace(BOP_Index face); -#ifdef BOP_NEW_MERGE - bool removeFace(BOP_Index i); - bool getUsed() { return m_used;}; - void setUsed(bool setting) { m_used=setting;}; -#endif -#ifdef BOP_DEBUG - friend ostream &operator<<(ostream &stream, BOP_Edge *e); -#endif - -}; - -#endif diff --git a/intern/boolop/intern/BOP_Face.cpp b/intern/boolop/intern/BOP_Face.cpp deleted file mode 100644 index 651964f4dbd..00000000000 --- a/intern/boolop/intern/BOP_Face.cpp +++ /dev/null @@ -1,430 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file boolop/intern/BOP_Face.cpp - * \ingroup boolopintern - */ - - -#include "BOP_Face.h" - -/******************************************************************************/ -/*** BOP_Face ***/ -/******************************************************************************/ - -/** - * Constructs a new face. - * @param plane face plane - * @param originalFace index of the original face - */ -BOP_Face::BOP_Face(MT_Plane3 plane, BOP_Index originalFace) -{ - m_plane = plane; - m_tag = UNCLASSIFIED; - m_originalFace = originalFace; - m_split = 0; - m_bbox = NULL; -} - -/** - * Inverts this face. - */ -void BOP_Face::invert() -{ - getPlane().Invert(); - BOP_Index aux = m_indexs[0]; - m_indexs[0] = m_indexs[2]; - m_indexs[2] = aux; -} - -/******************************************************************************/ -/*** BOP_Face ***/ -/******************************************************************************/ - -/** - * Constructs a new triangle face. - * @param v1 vertex index - * @param v2 vertex index - * @param v3 vertex index - * @param plane face plane - * @param originalFace index of the original face - */ -BOP_Face3::BOP_Face3(BOP_Index v1, BOP_Index v2, BOP_Index v3, MT_Plane3 plane, BOP_Index originalFace): BOP_Face(plane,originalFace) -{ - m_indexs[0] = v1; - m_indexs[1] = v2; - m_indexs[2] = v3; - m_size = 3; -} - -/** - * Returns the relative edge index (1,2,3) for the specified vertex indexs. - * @param v1 vertex index - * @param v2 vertex index - * @param e relative edge index (1,2,3) - * @return true if (v1,v2) is an edge of this face, false otherwise - */ -bool BOP_Face3::getEdgeIndex(BOP_Index v1, BOP_Index v2, unsigned int &e) -{ - if (m_indexs[0] == v1) { - if (m_indexs[1] == v2) { - e = 1; - } - else if (m_indexs[2] == v2) { - e = 3; - } - else - return false; - } - else if (m_indexs[1] == v1) { - if (m_indexs[0] == v2) { - e = 1; - } - else if (m_indexs[2] == v2) { - e = 2; - } - else - return false; - } - else if (m_indexs[2] == v1) { - if (m_indexs[0] == v2) { - e = 3; - } - else if (m_indexs[1] == v2) { - e = 2; - } - else - return false; - }else { - return false; - } - - return true; -} - -/** - * Returns if this face contains the specified vertex index. - * @param v vertex index - * @return true if this face contains the specified vertex index, false otherwise - */ -bool BOP_Face3::containsVertex(BOP_Index v) -{ - return (m_indexs[0] == v || m_indexs[1] == v || m_indexs[2] == v); -} - -/** - * Returns the neighbours of the specified vertex index. - * @param v vertex index - * @param prev previous vertex index - * @param next next vertex index - * @return true if this face contains the vertex index v, false otherwise - */ -bool BOP_Face3::getNeighbours(BOP_Index v, BOP_Index &prev, BOP_Index &next) -{ - if (m_indexs[0] == v) { - prev = m_indexs[2]; - next = m_indexs[1]; - } - else if (m_indexs[1] == v) { - prev = m_indexs[0]; - next = m_indexs[2]; - } - else if (m_indexs[2] == v) { - prev = m_indexs[1]; - next = m_indexs[0]; - } - else return false; - - return true; -} - -/** - * Returns the previous neighbour of the specified vertex index. - * @param v vertex index - * @param w previous vertex index - * @return true if this face contains the specified vertex index, false otherwise - */ -bool BOP_Face3::getPreviousVertex(BOP_Index v, BOP_Index &w) -{ - if (m_indexs[0] == v) w = m_indexs[2]; - else if (m_indexs[1] == v) w = m_indexs[0]; - else if (m_indexs[2] == v) w = m_indexs[1]; - else return false; - - return true; -} - -/** - * Returns the next neighbour of the specified vertex index. - * @param v vertex index - * @param w vertex index - * @return true if this face contains the specified vertex index, false otherwise - */ -bool BOP_Face3::getNextVertex(BOP_Index v, BOP_Index &w) -{ - if (m_indexs[0] == v) w = m_indexs[1]; - else if (m_indexs[1] == v) w = m_indexs[2]; - else if (m_indexs[2] == v) w = m_indexs[0]; - else return false; - - return true; -} - -/** - * Replaces a face vertex index. - * @param oldIndex old vertex index - * @param newIndex new vertex index - */ -void BOP_Face3::replaceVertexIndex(BOP_Index oldIndex, BOP_Index newIndex) -{ - /* if the old index really exists, and new index also exists already, - * don't create an edge with both vertices == newIndex */ - - if( (m_indexs[0] == oldIndex || m_indexs[1] == oldIndex || m_indexs[2] == oldIndex) && - (m_indexs[0] == newIndex || m_indexs[1] == newIndex || m_indexs[2] == newIndex) ) { - setTAG(BROKEN); - } - - if (m_indexs[0] == oldIndex) m_indexs[0] = newIndex; - else if (m_indexs[1] == oldIndex) m_indexs[1] = newIndex; - else if (m_indexs[2] == oldIndex) m_indexs[2] = newIndex; -} - -/******************************************************************************/ -/*** BOP_Face4 ***/ -/******************************************************************************/ - -/** - * Constructs a new quad face. - * @param v1 vertex index - * @param v2 vertex index - * @param v3 vertex index - * @param v4 vertex index - * @param plane face plane - * @param originalFace index of the original face - */ -BOP_Face4::BOP_Face4(BOP_Index v1, BOP_Index v2, BOP_Index v3, BOP_Index v4, MT_Plane3 plane, - BOP_Index originalFace): - BOP_Face(plane,originalFace) -{ - m_indexs[0] = v1; - m_indexs[1] = v2; - m_indexs[2] = v3; - m_indexs[3] = v4; - - m_size = 4; -} - -/** - * Returns if this face contains the specified vertex index. - * @param v vertex index - * @return true if this face contains the specified vertex index, false otherwise - */ -bool BOP_Face4::containsVertex(BOP_Index v) -{ - return (m_indexs[0] == v || m_indexs[1] == v || m_indexs[2] == v || m_indexs[3]==v); -} - -/** - * Returns the neighbours of the specified vertex index. - * @param v vertex index - * @param prev previous vertex index - * @param next next vertex index - * @param opp opposite vertex index - * @return true if this face contains the vertex index v, false otherwise - */ -bool BOP_Face4::getNeighbours(BOP_Index v, BOP_Index &prev, BOP_Index &next, BOP_Index &opp) -{ - if (m_indexs[0] == v) { - prev = m_indexs[3]; - next = m_indexs[1]; - opp = m_indexs[2]; - } - else if (m_indexs[1] == v) { - prev = m_indexs[0]; - next = m_indexs[2]; - opp = m_indexs[3]; - } - else if (m_indexs[2] == v) { - prev = m_indexs[1]; - next = m_indexs[3]; - opp = m_indexs[0]; - } - else if (m_indexs[3] == v) { - prev = m_indexs[2]; - next = m_indexs[0]; - opp = m_indexs[1]; - } - else return false; - - return true; -} - -/** - * Returns the previous neighbour of the specified vertex index. - * @param v vertex index - * @param w previous vertex index - * @return true if this face contains the specified vertex index, false otherwise - */ -bool BOP_Face4::getPreviousVertex(BOP_Index v, BOP_Index &w) -{ - if (m_indexs[0] == v) w = m_indexs[3]; - else if (m_indexs[1] == v) w = m_indexs[0]; - else if (m_indexs[2] == v) w = m_indexs[1]; - else if (m_indexs[3] == v) w = m_indexs[2]; - else return false; - - return true; -} - -/** - * Returns the next neighbour of the specified vertex index. - * @param v vertex index - * @param w next vertex index - * @return true if this face contains the specified vertex index, false otherwise - */ -bool BOP_Face4::getNextVertex(BOP_Index v, BOP_Index &w) -{ - if (m_indexs[0] == v) w = m_indexs[1]; - else if (m_indexs[1] == v) w = m_indexs[2]; - else if (m_indexs[2] == v) w = m_indexs[3]; - else if (m_indexs[3] == v) w = m_indexs[0]; - else return false; - - return true; -} - -/** - * Returns the opposite neighbour of the specified vertex index. - * @param v vertex index - * @param w opposite vertex index - * @return true if this face contains the specified vertex index, false otherwise - */ -bool BOP_Face4::getOppositeVertex(BOP_Index v, BOP_Index &w) -{ - if (m_indexs[0] == v) - w = m_indexs[2]; - else if (m_indexs[1] == v) - w = m_indexs[3]; - else if (m_indexs[2] == v) - w = m_indexs[0]; - else if (m_indexs[3] == v) - w = m_indexs[1]; - else - return false; - - return true; -} - -/** - * Replaces a face vertex index. - * @param oldIndex old vertex index - * @param newIndex new vertex index - */ -void BOP_Face4::replaceVertexIndex(BOP_Index oldIndex, BOP_Index newIndex) -{ - if (m_indexs[0] == oldIndex) m_indexs[0] = newIndex; - else if (m_indexs[1] == oldIndex) m_indexs[1] = newIndex; - else if (m_indexs[2] == oldIndex) m_indexs[2] = newIndex; - else if (m_indexs[3] == oldIndex) m_indexs[3] = newIndex; -} - -/** - * Returns the relative edge index (1,2,3,4) for the specified vertex indexs. - * @param v1 vertex index - * @param v2 vertex index - * @param e relative edge index (1,2,3,4) - * @return true if (v1,v2) is an edge of this face, false otherwise - */ -bool BOP_Face4::getEdgeIndex(BOP_Index v1, BOP_Index v2, unsigned int &e) -{ - if (m_indexs[0] == v1) { - if (m_indexs[1] == v2) { - e = 1; - } - else if (m_indexs[3] == v2) { - e = 4; - } - else - return false; - } - else if (m_indexs[1] == v1) { - if (m_indexs[0] == v2) { - e = 1; - } - else if (m_indexs[2] == v2) { - e = 2; - } - else - return false; - } - else if (m_indexs[2] == v1) { - if (m_indexs[1] == v2) { - e = 2; - } - else if (m_indexs[3] == v2) { - e = 3; - } - else - return false; - } - else if (m_indexs[3] == v1) { - if (m_indexs[2] == v2) { - e = 3; - } - else if (m_indexs[0] == v2) { - e = 4; - } - else - return false; - } - else return false; - - return true; -} - -#ifdef BOP_DEBUG -/** - * Implements operator <<. - */ -ostream &operator<<(ostream &stream, BOP_Face *f) -{ - char aux[20]; - BOP_stringTAG(f->m_tag,aux); - if (f->size()==3) { - stream << "Face[" << f->getVertex(0) << "," << f->getVertex(1) << ","; - stream << f->getVertex(2) << "] (" << aux << ") <-- " << f->m_originalFace; - } - else { - stream << "Face[" << f->getVertex(0) << "," << f->getVertex(1) << ","; - stream << f->getVertex(2) << "," << f->getVertex(3) << "] (" << aux; - stream << ") <-- " << f->m_originalFace; - } - - return stream; -} -#endif diff --git a/intern/boolop/intern/BOP_Face.h b/intern/boolop/intern/BOP_Face.h deleted file mode 100644 index 4f09618e23a..00000000000 --- a/intern/boolop/intern/BOP_Face.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file boolop/intern/BOP_Face.h - * \ingroup boolopintern - */ - - -#ifndef __BOP_FACE_H__ -#define __BOP_FACE_H__ - -#include "BOP_Tag.h" -#include "MT_Plane3.h" -#include "BOP_Indexs.h" -#include "BOP_BBox.h" -#include "BOP_Misc.h" -#include <iostream> -#include <vector> - -class BOP_Face; - -typedef std::vector<BOP_Face *> BOP_Faces; -typedef std::vector<BOP_Face *>::iterator BOP_IT_Faces; - -class BOP_Face -{ -private: - BOP_TAG m_tag; - MT_Plane3 m_plane; - BOP_Index m_originalFace; - -protected: - BOP_Index m_indexs[4]; - unsigned int m_size; - unsigned int m_split; - BOP_BBox *m_bbox; - -public: - BOP_Face(MT_Plane3 plane, BOP_Index originalFace); - virtual ~BOP_Face(){if (m_bbox) delete m_bbox;}; - inline MT_Plane3 getPlane() const {return m_plane;}; - inline void setPlane(const MT_Plane3 plane) {m_plane = plane;}; - inline BOP_TAG getTAG() const {return m_tag;}; - inline void setTAG(const BOP_TAG t) {m_tag = t;}; - inline BOP_Index getOriginalFace() const {return m_originalFace;}; - inline void setOriginalFace(const BOP_Index originalFace) {m_originalFace=originalFace;}; - inline BOP_Index getVertex(unsigned int i) const {return m_indexs[i];}; - inline void setVertex(const BOP_Index idx, const BOP_Index i) {m_indexs[idx]=i;}; - inline unsigned int getSplit() const {return m_split;}; - inline void setSplit(const unsigned int i) {m_split=i;}; - - void invert(); - inline void setBBox(const MT_Point3& p1,const MT_Point3& p2,const MT_Point3& p3) { - m_bbox = new BOP_BBox(p1, p2, p3);}; - inline BOP_BBox *getBBox() {return m_bbox;}; - inline void freeBBox(){if (m_bbox!=NULL) {delete m_bbox; m_bbox=NULL;} }; - - inline unsigned int size() const {return m_size;}; - - virtual bool getEdgeIndex(BOP_Index v1, BOP_Index v2, unsigned int &e) = 0; - virtual void replaceVertexIndex(BOP_Index oldIndex, BOP_Index newIndex) = 0; - virtual bool containsVertex(BOP_Index v) = 0; - -#ifdef BOP_DEBUG - friend ostream &operator<<(ostream &stream, BOP_Face *f); -#endif -}; - -class BOP_Face3: public BOP_Face -{ -public: - BOP_Face3(BOP_Index i, BOP_Index j, BOP_Index k, MT_Plane3 p, BOP_Index originalFace); - bool getEdgeIndex(BOP_Index v1, BOP_Index v2, unsigned int &e); - void replaceVertexIndex(BOP_Index oldIndex, BOP_Index newIndex); - bool containsVertex(BOP_Index v); - - bool getNeighbours(BOP_Index v, BOP_Index &prev, BOP_Index &next); - bool getPreviousVertex(BOP_Index v, BOP_Index &w); - bool getNextVertex(BOP_Index v, BOP_Index &w); -}; - -class BOP_Face4: public BOP_Face -{ -public: - BOP_Face4(BOP_Index i, BOP_Index j, BOP_Index k, BOP_Index l, MT_Plane3 p, BOP_Index originalFace); - bool getEdgeIndex(BOP_Index v1, BOP_Index v2, unsigned int &e); - void replaceVertexIndex(BOP_Index oldIndex, BOP_Index newIndex); - bool containsVertex(BOP_Index v); - - bool getNeighbours(BOP_Index v, BOP_Index &prev, BOP_Index &next, BOP_Index &opp); - bool getPreviousVertex(BOP_Index v, BOP_Index &w); - bool getNextVertex(BOP_Index v, BOP_Index &w); - bool getOppositeVertex(BOP_Index v, BOP_Index &w); -}; - -#endif diff --git a/intern/boolop/intern/BOP_Face2Face.cpp b/intern/boolop/intern/BOP_Face2Face.cpp deleted file mode 100644 index 905d23fddff..00000000000 --- a/intern/boolop/intern/BOP_Face2Face.cpp +++ /dev/null @@ -1,1250 +0,0 @@ -/* - * - * - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Marc Freixas, Ken Hughes - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file boolop/intern/BOP_Face2Face.cpp - * \ingroup boolopintern - */ - - -#include "BOP_Face2Face.h" -#include "BOP_BBox.h" - -// TAGS for segment classification in x-segment creation -// sA -> point of sA -// sB -> point of sB -// sX -> point of sA and SB -#define sA_sB 12 -#define sB_sA 21 -#define sX_sA 31 -#define sA_sX 13 -#define sX_sB 32 -#define sB_sX 23 -#define sX_sX 33 - -#define sA_sA_sB 112 -#define sB_sB_sA 221 -#define sB_sA_sA 211 -#define sA_sB_sB 122 -#define sA_sB_sA 121 -#define sB_sA_sB 212 -#define sA_sX_sB 132 -#define sB_sX_sA 231 -#define sX_sA_sB 312 -#define sX_sB_sA 321 -#define sA_sB_sX 123 -#define sB_sA_sX 213 - -#define sA_sA_sB_sB 1122 -#define sB_sB_sA_sA 2211 -#define sA_sB_sA_sB 1212 -#define sB_sA_sB_sA 2121 -#define sA_sB_sB_sA 1221 -#define sB_sA_sA_sB 2112 - -void BOP_intersectCoplanarFaces(BOP_Mesh* mesh, - BOP_Faces* facesB, - BOP_Face* faceA, - BOP_Face* faceB, - bool invert); - -void BOP_intersectCoplanarFaces(BOP_Mesh* mesh, - BOP_Faces* facesB, - BOP_Face* faceB, - BOP_Segment sA, - MT_Plane3 planeA, - bool invert); - -void BOP_intersectNonCoplanarFaces(BOP_Mesh* mesh, - BOP_Faces* facesA, - BOP_Faces* facesB, - BOP_Face* faceA, - BOP_Face* faceB); - -void BOP_getPoints(BOP_Mesh* mesh, - BOP_Face* faceA, - BOP_Segment& sA, - MT_Plane3 planeB, - MT_Point3* points, - unsigned int* faces, - unsigned int& size, - unsigned int faceValue); - -void BOP_mergeSort(MT_Point3 *points, unsigned int *face, unsigned int &size, bool &invertA, bool &invertB); - -void BOP_createXS(BOP_Mesh* mesh, - BOP_Face* faceA, - BOP_Face* faceB, - BOP_Segment sA, - BOP_Segment sB, - bool invert, - BOP_Segment* segments); - -void BOP_createXS(BOP_Mesh* mesh, - BOP_Face* faceA, - BOP_Face* faceB, - MT_Plane3 planeA, - MT_Plane3 planeB, - BOP_Segment sA, - BOP_Segment sB, - bool invert, - BOP_Segment* segments); - -BOP_Index BOP_getVertexIndex(BOP_Mesh* mesh, - MT_Point3 point, - unsigned int cfgA, - unsigned int cfgB, - BOP_Index vA, - BOP_Index vB, - bool invert); - -BOP_Index BOP_getVertexIndex(BOP_Mesh *mesh, MT_Point3 point, unsigned int cfg, BOP_Index v); - -void triangulate(BOP_Mesh *mesh, BOP_Faces *faces, BOP_Face *face, BOP_Segment s); - -BOP_Face *BOP_getOppositeFace(BOP_Mesh* mesh, - BOP_Faces* faces, - BOP_Face* face, - BOP_Edge* edge); - -bool BOP_overlap(MT_Vector3 normal, - MT_Point3 p1, - MT_Point3 p2, - MT_Point3 p3, - MT_Point3 q1, - MT_Point3 q2, - MT_Point3 q3); - -void BOP_mergeVertexs(BOP_Mesh *mesh, unsigned int firstFace); - - -/** - * Computes intersections between faces of both lists. - * @param mesh mesh that contains the faces, edges and vertices - * @param facesA set of faces from object A - * @param facesB set of faces from object B - * - * Two optimizations were added here: - * 1) keep the bounding box for a face once it's created; this is - * especially important for B faces, since they were being created and - * recreated over and over - * 2) associate a "split" index in the faceB vector with each A face; when - * an A face is split, we will not need to recheck any B faces have - * already been checked against that original A face - */ - -void BOP_Face2Face(BOP_Mesh *mesh, BOP_Faces *facesA, BOP_Faces *facesB) -{ - for(unsigned int idxFaceA=0;idxFaceA<facesA->size();idxFaceA++) { - BOP_Face *faceA = (*facesA)[idxFaceA]; - MT_Plane3 planeA = faceA->getPlane(); - MT_Point3 p1 = mesh->getVertex(faceA->getVertex(0))->getPoint(); - MT_Point3 p2 = mesh->getVertex(faceA->getVertex(1))->getPoint(); - MT_Point3 p3 = mesh->getVertex(faceA->getVertex(2))->getPoint(); - - /* get (or create) bounding box for face A */ - if( faceA->getBBox() == NULL ) - faceA->setBBox(p1,p2,p3); - BOP_BBox *boxA = faceA->getBBox(); - - /* start checking B faces with the previously stored split index */ - - for(unsigned int idxFaceB=faceA->getSplit(); - idxFaceB<facesB->size() && (faceA->getTAG() != BROKEN) && (faceA->getTAG() != PHANTOM);) { - BOP_Face *faceB = (*facesB)[idxFaceB]; - faceA->setSplit(idxFaceB); - if ((faceB->getTAG() != BROKEN) && (faceB->getTAG() != PHANTOM)) { - - /* get (or create) bounding box for face B */ - if( faceB->getBBox() == NULL ) { - faceB->setBBox(mesh->getVertex(faceB->getVertex(0))->getPoint(), - mesh->getVertex(faceB->getVertex(1))->getPoint(), - mesh->getVertex(faceB->getVertex(2))->getPoint()); - } - BOP_BBox *boxB = faceB->getBBox(); - - if (boxA->intersect(*boxB)) { - MT_Plane3 planeB = faceB->getPlane(); - if (BOP_containsPoint(planeB,p1) && - BOP_containsPoint(planeB,p2) && - BOP_containsPoint(planeB,p3)) - { - if (BOP_orientation(planeB,planeA)>0) { - BOP_intersectCoplanarFaces(mesh,facesB,faceA,faceB,false); - } - } - else { - BOP_intersectNonCoplanarFaces(mesh,facesA,facesB,faceA,faceB); - } - } - } - idxFaceB++; - } - } - - - // Clean broken faces from facesA - BOP_IT_Faces it; - it = facesA->begin(); - while (it != facesA->end()) { - BOP_Face *face = *it; - if (face->getTAG() == BROKEN) it = facesA->erase(it); - else it++; - } - /* - it = facesB->begin(); - while (it != facesB->end()) { - BOP_Face *face = *it; - if (face->getTAG() == BROKEN) it = facesB->erase(it); - else it++; - } - */ -} - -/** - * Computes intesections of coplanars faces from object A with faces from object B. - * @param mesh mesh that contains the faces, edges and vertices - * @param facesA set of faces from object A - * @param facesB set of faces from object B - */ -void BOP_sew(BOP_Mesh *mesh, BOP_Faces *facesA, BOP_Faces *facesB) -{ - for(unsigned int idxFaceB = 0; idxFaceB < facesB->size(); idxFaceB++) { - BOP_Face *faceB = (*facesB)[idxFaceB]; - MT_Plane3 planeB = faceB->getPlane(); - MT_Point3 p1 = mesh->getVertex(faceB->getVertex(0))->getPoint(); - MT_Point3 p2 = mesh->getVertex(faceB->getVertex(1))->getPoint(); - MT_Point3 p3 = mesh->getVertex(faceB->getVertex(2))->getPoint(); - - for(unsigned int idxFaceA = 0; - idxFaceA < facesA->size() && - faceB->getTAG() != BROKEN && - faceB->getTAG() != PHANTOM; - idxFaceA++) { - BOP_Face *faceA = (*facesA)[idxFaceA]; - if ((faceA->getTAG() != BROKEN)&&(faceA->getTAG() != PHANTOM)) { - MT_Plane3 planeA = faceA->getPlane(); - if (BOP_containsPoint(planeA,p1) && - BOP_containsPoint(planeA,p2) && - BOP_containsPoint(planeA,p3)) { - if (BOP_orientation(planeA,planeB) > 0) { - BOP_intersectCoplanarFaces(mesh,facesA,faceB,faceA,true); - } - } - } - } - } -} - -/** - * Triangulates faceB using edges of faceA that both are complanars. - * @param mesh mesh that contains the faces, edges and vertices - * @param facesB set of faces from object B - * @param faceA face from object A - * @param faceB face from object B - * @param invert indicates if faceA has priority over faceB - */ -void BOP_intersectCoplanarFaces(BOP_Mesh* mesh, - BOP_Faces* facesB, - BOP_Face* faceA, - BOP_Face* faceB, - bool invert) -{ - unsigned int oldSize = facesB->size(); - unsigned int originalFaceB = faceB->getOriginalFace(); - - MT_Point3 p1 = mesh->getVertex(faceA->getVertex(0))->getPoint(); - MT_Point3 p2 = mesh->getVertex(faceA->getVertex(1))->getPoint(); - MT_Point3 p3 = mesh->getVertex(faceA->getVertex(2))->getPoint(); - - MT_Vector3 normal(faceA->getPlane().x(),faceA->getPlane().y(),faceA->getPlane().z()); - - MT_Vector3 p1p2 = p2-p1; - - MT_Plane3 plane1((p1p2.cross(normal).normalized()),p1); - - BOP_Segment sA; - sA.m_cfg1 = BOP_Segment::createVertexCfg(1); - sA.m_v1 = faceA->getVertex(0); - sA.m_cfg2 = BOP_Segment::createVertexCfg(2); - sA.m_v2 = faceA->getVertex(1); - - BOP_intersectCoplanarFaces(mesh,facesB,faceB,sA,plane1,invert); - - MT_Vector3 p2p3 = p3-p2; - MT_Plane3 plane2((p2p3.cross(normal).normalized()),p2); - - sA.m_cfg1 = BOP_Segment::createVertexCfg(2); - sA.m_v1 = faceA->getVertex(1); - sA.m_cfg2 = BOP_Segment::createVertexCfg(3); - sA.m_v2 = faceA->getVertex(2); - - if (faceB->getTAG() == BROKEN) { - for(unsigned int idxFace = oldSize; idxFace < facesB->size(); idxFace++) { - BOP_Face *face = (*facesB)[idxFace]; - if (face->getTAG() != BROKEN && originalFaceB == face->getOriginalFace()) - BOP_intersectCoplanarFaces(mesh,facesB,face,sA,plane2,invert); - } - } - else { - BOP_intersectCoplanarFaces(mesh,facesB,faceB,sA,plane2,invert); - } - - MT_Vector3 p3p1 = p1-p3; - MT_Plane3 plane3((p3p1.cross(normal).safe_normalized()),p3); - - sA.m_cfg1 = BOP_Segment::createVertexCfg(3); - sA.m_v1 = faceA->getVertex(2); - sA.m_cfg2 = BOP_Segment::createVertexCfg(1); - sA.m_v2 = faceA->getVertex(0); - - if (faceB->getTAG() == BROKEN) { - for(unsigned int idxFace = oldSize; idxFace < facesB->size(); idxFace++) { - BOP_Face *face = (*facesB)[idxFace]; - if (face->getTAG() != BROKEN && originalFaceB == face->getOriginalFace()) - BOP_intersectCoplanarFaces(mesh,facesB,face,sA,plane3,invert); - } - } - else { - BOP_intersectCoplanarFaces(mesh,facesB,faceB,sA,plane3,invert); - } -} - -/** - * Triangulates faceB using segment sA and planeA. - * @param mesh mesh that contains the faces, edges and vertices - * @param facesB set of faces from object B - * @param faceB face from object B - * @param sA segment to intersect with faceB - * @param planeA plane to intersect with faceB - * @param invert indicates if sA has priority over faceB - */ -void BOP_intersectCoplanarFaces(BOP_Mesh* mesh, - BOP_Faces* facesB, - BOP_Face* faceB, - BOP_Segment sA, - MT_Plane3 planeA, - bool invert) -{ - BOP_Segment sB = BOP_splitFace(planeA,mesh,faceB); - - if (BOP_Segment::isDefined(sB.m_cfg1)) { - BOP_Segment xSegment[2]; - BOP_createXS(mesh,NULL,faceB,planeA,MT_Plane3(),sA,sB,invert,xSegment); - if (BOP_Segment::isDefined(xSegment[1].m_cfg1)) { - unsigned int sizefaces = mesh->getNumFaces(); - triangulate(mesh,facesB,faceB,xSegment[1]); - BOP_mergeVertexs(mesh,sizefaces); - } - } -} - -/** - * Triangulates faceB using edges of faceA that both are not complanars. - * @param mesh mesh that contains the faces, edges and vertices - * @param facesB set of faces from object B - * @param faceA face from object A - * @param faceB face from object B - */ -void BOP_intersectNonCoplanarFaces(BOP_Mesh *mesh, - BOP_Faces *facesA, - BOP_Faces *facesB, - BOP_Face *faceA, - BOP_Face *faceB) -{ - // Obtain segments of faces A and B from the intersection with their planes - BOP_Segment sA = BOP_splitFace(faceB->getPlane(),mesh,faceA); - BOP_Segment sB = BOP_splitFace(faceA->getPlane(),mesh,faceB); - - if (BOP_Segment::isDefined(sA.m_cfg1) && BOP_Segment::isDefined(sB.m_cfg1)) { - // There is an intesection, build the X-segment - BOP_Segment xSegment[2]; - BOP_createXS(mesh,faceA,faceB,sA,sB,false,xSegment); - - unsigned int sizefaces = mesh->getNumFaces(); - triangulate(mesh,facesA,faceA,xSegment[0]); - BOP_mergeVertexs(mesh,sizefaces); - - sizefaces = mesh->getNumFaces(); - triangulate(mesh,facesB,faceB,xSegment[1]); - BOP_mergeVertexs(mesh,sizefaces); - } -} - -/** - * Tests if faces since firstFace have all vertexs non-coincident of colinear, otherwise repairs the mesh. - * @param mesh mesh that contains the faces, edges and vertices - * @param firstFace first face index to be tested - */ -void BOP_mergeVertexs(BOP_Mesh *mesh, unsigned int firstFace) -{ - unsigned int numFaces = mesh->getNumFaces(); - for(unsigned int idxFace = firstFace; idxFace < numFaces; idxFace++) { - BOP_Face *face = mesh->getFace(idxFace); - if ((face->getTAG() != BROKEN) && (face->getTAG() != PHANTOM)) { - MT_Point3 vertex1 = mesh->getVertex(face->getVertex(0))->getPoint(); - MT_Point3 vertex2 = mesh->getVertex(face->getVertex(1))->getPoint(); - MT_Point3 vertex3 = mesh->getVertex(face->getVertex(2))->getPoint(); - if (BOP_collinear(vertex1,vertex2,vertex3)) // collinear triangle - face->setTAG(PHANTOM); - } - } -} - -/** - * Obtains the points of the segment created from the intersection between faceA and planeB. - * @param mesh mesh that contains the faces, edges and vertices - * @param faceA intersected face - * @param sA segment of the intersection between faceA and planeB - * @param planeB intersected plane - * @param points array of points where the new points are saved - * @param faces array of relative face index to the points - * @param size size of arrays points and faces - * @param faceValue relative face index of new points - */ -void BOP_getPoints(BOP_Mesh* mesh, - BOP_Face* faceA, - BOP_Segment& sA, - MT_Plane3 planeB, - MT_Point3* points, - unsigned int* faces, - unsigned int& size, - unsigned int faceValue) -{ - MT_Point3 p1,p2; - - if (BOP_Segment::isDefined(sA.m_cfg1)) { - if (BOP_Segment::isEdge(sA.m_cfg1)) { - // the new point becomes of split faceA edge - p1 = BOP_splitEdge(planeB,mesh,faceA,BOP_Segment::getEdge(sA.m_cfg1)); - } - else if (BOP_Segment::isVertex(sA.m_cfg1)) { - // the new point becomes of vertex faceA - p1 = mesh->getVertex(BOP_Segment::getVertex(sA.m_v1))->getPoint(); - } - - if (BOP_Segment::isDefined(sA.m_cfg2)) { - if (BOP_Segment::isEdge(sA.m_cfg2)) { - p2 = BOP_splitEdge(planeB,mesh,faceA,BOP_Segment::getEdge(sA.m_cfg2)); - } - else if (BOP_Segment::isVertex(sA.m_cfg2)) { - p2 = mesh->getVertex(BOP_Segment::getVertex(sA.m_v2))->getPoint(); - } - points[size] = p1; - points[size+1] = p2; - faces[size] = faceValue; - faces[size+1] = faceValue; - size += 2; - } - - else { - points[size] = p1; - faces[size] = faceValue; - size++; - } - } -} - -/** - * Sorts the colinear points and relative face indices. - * @param points array of points where the new points are saved - * @param faces array of relative face index to the points - * @param size size of arrays points and faces - * @param invertA indicates if points of same relative face had been exchanged - */ -void BOP_mergeSort(MT_Point3 *points, unsigned int *face, unsigned int &size, bool &invertA, bool &invertB) { - MT_Point3 sortedPoints[4]; - unsigned int sortedFaces[4], position[4]; - unsigned int i; - if (size == 2) { - - // Trivial case, only test the merge ... - if (BOP_fuzzyZero(points[0].distance(points[1]))) { - face[0] = 3; - size--; - } - } - else { - // size is 3 or 4 - // Get segment extreme points - MT_Scalar maxDistance = -1; - for(i=0;i<size-1;i++){ - for(unsigned int j=i+1;j<size;j++){ - MT_Scalar distance = points[i].distance(points[j]); - if (distance > maxDistance){ - maxDistance = distance; - position[0] = i; - position[size-1] = j; - } - } - } - - // Get segment inner points - position[1] = position[2] = size; - for(i=0;i<size;i++){ - if ((i != position[0]) && (i != position[size-1])){ - if (position[1] == size) position[1] = i; - else position[2] = i; - } - } - - // Get inner points - if (position[2] < size) { - MT_Scalar d1 = points[position[1]].distance(points[position[0]]); - MT_Scalar d2 = points[position[2]].distance(points[position[0]]); - if (d1 > d2) { - unsigned int aux = position[1]; - position[1] = position[2]; - position[2] = aux; - } - } - - // Sort data - for(i=0;i<size;i++) { - sortedPoints[i] = points[position[i]]; - sortedFaces[i] = face[position[i]]; - } - - invertA = false; - invertB = false; - if (face[1] == 1) { - - // invertA? - for(i=0;i<size;i++) { - if (position[i] == 1) { - invertA = true; - break; - } - else if (position[i] == 0) break; - } - - // invertB? - if (size == 4) { - for(i=0;i<size;i++) { - if (position[i] == 3) { - invertB = true; - break; - } - else if (position[i] == 2) break; - } - } - } - else if (face[1] == 2) { - // invertB? - for(i=0;i<size;i++) { - if (position[i] == 2) { - invertB = true; - break; - } - else if (position[i] == 1) break; - } - } - - - // Merge data - MT_Scalar d1 = sortedPoints[1].distance(sortedPoints[0]); - MT_Scalar d2 = sortedPoints[1].distance(sortedPoints[2]); - if (BOP_fuzzyZero(d1) && sortedFaces[1] != sortedFaces[0]) { - if (BOP_fuzzyZero(d2) && sortedFaces[1] != sortedFaces[2]) { - if (d1 < d2) { - // merge 0 and 1 - sortedFaces[0] = 3; - for(i = 1; i<size-1;i++) { - sortedPoints[i] = sortedPoints[i+1]; - sortedFaces[i] = sortedFaces[i+1]; - } - size--; - if (size == 3) { - // merge 1 and 2 ??? - d1 = sortedPoints[1].distance(sortedPoints[2]); - if (BOP_fuzzyZero(d1) && sortedFaces[1] != sortedFaces[2]) { - // merge! - sortedFaces[1] = 3; - size--; - } - } - } - else { - // merge 1 and 2 - sortedFaces[1] = 3; - for(i = 2; i<size-1;i++) { - sortedPoints[i] = sortedPoints[i+1]; - sortedFaces[i] = sortedFaces[i+1]; - } - size--; - } - } - else { - // merge 0 and 1 - sortedFaces[0] = 3; - for(i = 1; i<size-1;i++) { - sortedPoints[i] = sortedPoints[i+1]; - sortedFaces[i] = sortedFaces[i+1]; - } - size--; - if (size == 3) { - // merge 1 i 2 ??? - d1 = sortedPoints[1].distance(sortedPoints[2]); - if (BOP_fuzzyZero(d1) && sortedFaces[1] != sortedFaces[2]) { - // merge! - sortedFaces[1] = 3; - size--; - } - } - } - } - else { - if (BOP_fuzzyZero(d2) && sortedFaces[1] != sortedFaces[2]) { - // merge 1 and 2 - sortedFaces[1] = 3; - for(i = 2; i<size-1;i++) { - sortedPoints[i] = sortedPoints[i+1]; - sortedFaces[i] = sortedFaces[i+1]; - } - size--; - } - else if (size == 4) { - d1 = sortedPoints[2].distance(sortedPoints[3]); - if (BOP_fuzzyZero(d1) && sortedFaces[2] != sortedFaces[3]) { - // merge 2 and 3 - sortedFaces[2] = 3; - size--; - } - } - } - - // Merge initial points ... - for(i=0;i<size;i++) { - points[i] = sortedPoints[i]; - face[i] = sortedFaces[i]; - } - - } -} - - -/** - * Computes the x-segment of two segments (the shared interval). The segments needs to have sA.m_cfg1 > 0 && sB.m_cfg1 > 0 . - * @param mesh mesh that contains the faces, edges and vertices - * @param faceA face of object A - * @param faceB face of object B - * @param sA segment of intersection between faceA and planeB - * @param sB segment of intersection between faceB and planeA - * @param invert indicates if faceA has priority over faceB - * @param segmemts array of the output x-segments - */ -void BOP_createXS(BOP_Mesh* mesh, - BOP_Face* faceA, - BOP_Face* faceB, - BOP_Segment sA, - BOP_Segment sB, - bool invert, - BOP_Segment* segments) { - BOP_createXS(mesh, faceA, faceB, faceA->getPlane(), faceB->getPlane(), - sA, sB, invert, segments); -} - -/** - * Computes the x-segment of two segments (the shared interval). The segments needs to have sA.m_cfg1 > 0 && sB.m_cfg1 > 0 . - * @param mesh mesh that contains the faces, edges and vertices - * @param faceA face of object A - * @param faceB face of object B - * @param planeA plane of faceA - * @param planeB plane of faceB - * @param sA segment of intersection between faceA and planeB - * @param sB segment of intersection between faceB and planeA - * @param invert indicates if faceA has priority over faceB - * @param segmemts array of the output x-segments - */ -void BOP_createXS(BOP_Mesh* mesh, - BOP_Face* faceA, - BOP_Face* faceB, - MT_Plane3 planeA, - MT_Plane3 planeB, - BOP_Segment sA, - BOP_Segment sB, - bool invert, - BOP_Segment* segments) -{ - MT_Point3 points[4]; // points of the segments - unsigned int face[4]; // relative face indexs (1 => faceA, 2 => faceB) - unsigned int size = 0; // size of points and relative face indexs - - BOP_getPoints(mesh, faceA, sA, planeB, points, face, size, 1); - BOP_getPoints(mesh, faceB, sB, planeA, points, face, size, 2); - - bool invertA = false; - bool invertB = false; - BOP_mergeSort(points,face,size,invertA,invertB); - - if (invertA) sA.invert(); - if (invertB) sB.invert(); - - // Compute the configuration label - unsigned int label = 0; - for(unsigned int i =0; i < size; i++) { - label = face[i]+label*10; - } - - if (size == 1) { - // Two coincident points - segments[0].m_cfg1 = sA.m_cfg1; - segments[1].m_cfg1 = sB.m_cfg1; - - segments[0].m_v1 = BOP_getVertexIndex(mesh, points[0], sA.m_cfg1, sB.m_cfg1, - sA.m_v1, sB.m_v1, invert); - segments[1].m_v1 = segments[0].m_v1; - segments[0].m_cfg2 = segments[1].m_cfg2 = BOP_Segment::createUndefinedCfg(); - } - else if (size == 2) { - switch(label) { - // Two non-coincident points - case sA_sB: - case sB_sA: - segments[0].m_cfg1 = - segments[1].m_cfg1 = - segments[0].m_cfg2 = - segments[1].m_cfg2 = BOP_Segment::createUndefinedCfg(); - break; - - // Two coincident points and one non-coincident of sA - case sA_sX: - segments[0].m_cfg1 = sA.m_cfg2; - segments[1].m_cfg1 = sB.m_cfg1; - segments[0].m_v1 = BOP_getVertexIndex(mesh, points[1], sA.m_cfg2, sB.m_cfg1, - sA.m_v2, sB.m_v1, invert); - segments[1].m_v1 = segments[0].m_v1; - - segments[0].m_cfg2 = BOP_Segment::createUndefinedCfg(); - segments[1].m_cfg2 = BOP_Segment::createUndefinedCfg(); - break; - case sX_sA: - segments[0].m_cfg1 = sA.m_cfg1; - segments[1].m_cfg1 = sB.m_cfg1; - segments[0].m_v1 = BOP_getVertexIndex(mesh, points[0], sA.m_cfg1, sB.m_cfg1, - sA.m_v1, sB.m_v1, invert); - segments[1].m_v1 = segments[0].m_v1; - - segments[0].m_cfg2 = BOP_Segment::createUndefinedCfg(); - segments[1].m_cfg2 = BOP_Segment::createUndefinedCfg(); - break; - - // Two coincident points and one non-coincident of sB - case sB_sX: - segments[0].m_cfg1 = sA.m_cfg1; - segments[1].m_cfg1 = sB.m_cfg2; - segments[0].m_v1 = BOP_getVertexIndex(mesh, points[1], sA.m_cfg1, sB.m_cfg2, - sA.m_v1, sB.m_v2, invert); - segments[1].m_v1 = segments[0].m_v1; - - segments[0].m_cfg2 = BOP_Segment::createUndefinedCfg(); - segments[1].m_cfg2 = BOP_Segment::createUndefinedCfg(); - break; - case sX_sB: - segments[0].m_cfg1 = sA.m_cfg1; - segments[1].m_cfg1 = sB.m_cfg1; - segments[0].m_v1 = BOP_getVertexIndex(mesh, points[0], sA.m_cfg1, sB.m_cfg1, - sA.m_v1, sB.m_v1, invert); - segments[1].m_v1 = segments[0].m_v1; - - segments[0].m_cfg2 = BOP_Segment::createUndefinedCfg(); - segments[1].m_cfg2 = BOP_Segment::createUndefinedCfg(); - break; - - // coincident points 2-2 - case sX_sX: - segments[0].m_cfg1 = sA.m_cfg1; - segments[1].m_cfg1 = sB.m_cfg1; - segments[0].m_v1 = BOP_getVertexIndex(mesh, points[0], sA.m_cfg1, sB.m_cfg1, - sA.m_v1, sB.m_v1, invert); - segments[1].m_v1 = segments[0].m_v1; - - segments[0].m_cfg2 = sA.m_cfg2; - segments[1].m_cfg2 = sB.m_cfg2; - segments[0].m_v2 = BOP_getVertexIndex(mesh, points[1], sA.m_cfg2, sB.m_cfg2, - sA.m_v2, sB.m_v2, invert); - segments[1].m_v2 = segments[0].m_v2; - break; - - default: - break; - } - } - else if (size == 3) { - switch(label) { - case sA_sA_sB: - case sB_sA_sA: - case sA_sB_sB: - case sB_sB_sA: - segments[0].m_cfg1 = - segments[1].m_cfg1 = - segments[0].m_cfg2 = - segments[1].m_cfg2 = BOP_Segment::createUndefinedCfg(); - break; - - case sA_sB_sA: - segments[1].m_v1 = BOP_getVertexIndex(mesh,points[1],sB.m_cfg1,sB.m_v1); - segments[1].m_cfg1 = sB.m_cfg1; - segments[1].m_cfg2 = BOP_Segment::createUndefinedCfg(); - segments[0].m_cfg1 = sA.getConfig(); - segments[0].m_cfg2 = BOP_Segment::createUndefinedCfg(); - segments[0].m_v1 = segments[1].m_v1; - break; - - case sB_sA_sB: - segments[0].m_v1 = BOP_getVertexIndex(mesh,points[1],sA.m_cfg1,sA.m_v1); - segments[0].m_cfg1 = sA.m_cfg1; - segments[0].m_cfg2 = BOP_Segment::createUndefinedCfg(); - segments[1].m_cfg1 = sB.getConfig(); - segments[1].m_cfg2 = BOP_Segment::createUndefinedCfg(); - segments[1].m_v1 = segments[0].m_v1; - break; - - case sA_sX_sB: - segments[0].m_cfg1 = sA.m_cfg2; - segments[1].m_cfg1 = sB.m_cfg1; - segments[0].m_v1 = BOP_getVertexIndex(mesh, points[1], sA.m_cfg2, sB.m_cfg1, - sA.m_v2, sB.m_v1, invert); - segments[1].m_v1 = segments[0].m_v1; - segments[0].m_cfg2 = BOP_Segment::createUndefinedCfg(); - segments[1].m_cfg2 = BOP_Segment::createUndefinedCfg(); - break; - - case sB_sX_sA: - segments[0].m_cfg1 = sA.m_cfg1; - segments[1].m_cfg1 = sB.m_cfg2; - segments[0].m_v1 = BOP_getVertexIndex(mesh, points[1], sA.m_cfg1, sB.m_cfg2, - sA.m_v1, sB.m_v2, invert); - segments[1].m_v1 = segments[0].m_v1; - segments[0].m_cfg2 = BOP_Segment::createUndefinedCfg(); - segments[1].m_cfg2 = BOP_Segment::createUndefinedCfg(); - break; - - case sX_sA_sB: - segments[0].m_cfg1 = sA.m_cfg1; - segments[1].m_cfg1 = sB.m_cfg1; - segments[0].m_v1 = BOP_getVertexIndex(mesh, points[0], sA.m_cfg1, sB.m_cfg1, - sA.m_v1, sB.m_v1, invert); - segments[1].m_v1 = segments[0].m_v1; - - segments[0].m_cfg2 = sA.m_cfg2; - segments[1].m_cfg2 = sB.getConfig(); - segments[0].m_v2 = BOP_getVertexIndex(mesh, points[1], sA.m_cfg2, sA.m_v2); - segments[1].m_v2 = segments[0].m_v2; - break; - - case sX_sB_sA: - segments[0].m_cfg1 = sA.m_cfg1; - segments[1].m_cfg1 = sB.m_cfg1; - segments[0].m_v1 = BOP_getVertexIndex(mesh, points[0], sA.m_cfg1, sB.m_cfg1, - sA.m_v1, sB.m_v1, invert); - segments[1].m_v1 = segments[0].m_v1; - - segments[0].m_cfg2 = sA.getConfig(); - segments[1].m_cfg2 = sB.m_cfg2; - segments[0].m_v2 = BOP_getVertexIndex(mesh,points[1],sB.m_cfg2,sB.m_v2); - segments[1].m_v2 = segments[0].m_v2; - break; - - case sA_sB_sX: - segments[0].m_cfg1 = sA.getConfig(); - segments[1].m_cfg1 = sB.m_cfg1; - segments[0].m_v1 = BOP_getVertexIndex(mesh,points[1],sB.m_cfg1,sB.m_v1); - segments[1].m_v1 = segments[0].m_v1; - - segments[0].m_cfg2 = sA.m_cfg2; - segments[1].m_cfg2 = sB.m_cfg2; - segments[0].m_v2 = BOP_getVertexIndex(mesh, points[2], sA.m_cfg2, sB.m_cfg2, - sA.m_v2, sB.m_v2, invert); - segments[1].m_v2 = segments[0].m_v2; - break; - - case sB_sA_sX: - segments[0].m_cfg1 = sA.m_cfg1; - segments[1].m_cfg1 = sB.getConfig(); - segments[0].m_v1 = BOP_getVertexIndex(mesh,points[1],sA.m_cfg1,sA.m_v1); - segments[1].m_v1 = segments[0].m_v1; - - segments[0].m_cfg2 = sA.m_cfg2; - segments[1].m_cfg2 = sB.m_cfg2; - segments[0].m_v2 = BOP_getVertexIndex(mesh, points[2], sA.m_cfg2, sB.m_cfg2, - sA.m_v2, sB.m_v2, invert); - segments[1].m_v2 = segments[0].m_v2; - break; - - default: - break; - } - } - else { - // 4! - switch(label) { - case sA_sA_sB_sB: - case sB_sB_sA_sA: - segments[0].m_cfg1 = - segments[1].m_cfg1 = - segments[0].m_cfg2 = - segments[1].m_cfg2 = BOP_Segment::createUndefinedCfg(); - break; - - case sA_sB_sA_sB: - segments[0].m_cfg1 = sA.getConfig(); - segments[1].m_cfg1 = sB.m_cfg1; - segments[0].m_v1 = BOP_getVertexIndex(mesh,points[1],sB.m_cfg1,sB.m_v1); - segments[1].m_v1 = segments[0].m_v1; - - segments[0].m_cfg2 = sA.m_cfg2; - segments[1].m_cfg2 = sB.getConfig(); - segments[0].m_v2 = BOP_getVertexIndex(mesh,points[2],sA.m_cfg2,sA.m_v2); - segments[1].m_v2 = segments[0].m_v2; - break; - - case sB_sA_sB_sA: - segments[0].m_cfg1 = sA.m_cfg1; - segments[1].m_cfg1 = sB.getConfig(); - segments[0].m_v1 = BOP_getVertexIndex(mesh,points[1],sA.m_cfg1,sA.m_v1); - segments[1].m_v1 = segments[0].m_v1; - - segments[0].m_cfg2 = sA.getConfig(); - segments[1].m_cfg2 = sB.m_cfg2; - segments[0].m_v2 = BOP_getVertexIndex(mesh,points[2],sB.m_cfg2,sB.m_v2); - segments[1].m_v2 = segments[0].m_v2; - break; - - case sA_sB_sB_sA: - segments[0].m_cfg1 = sA.getConfig(); - segments[1].m_cfg1 = sB.m_cfg1; - segments[0].m_v1 = BOP_getVertexIndex(mesh,points[1],sB.m_cfg1,sB.m_v1); - segments[1].m_v1 = segments[0].m_v1; - - segments[0].m_cfg2 = segments[0].m_cfg1; - segments[1].m_cfg2 = sB.m_cfg2; - segments[0].m_v2 = BOP_getVertexIndex(mesh,points[2],sB.m_cfg2,sB.m_v2); - segments[1].m_v2 = segments[0].m_v2; - break; - - case sB_sA_sA_sB: - segments[0].m_cfg1 = sA.m_cfg1; - segments[1].m_cfg1 = sB.getConfig(); - segments[0].m_v1 = BOP_getVertexIndex(mesh,points[1],sA.m_cfg1,sA.m_v1); - segments[1].m_v1 = segments[0].m_v1; - - segments[0].m_cfg2 = sA.m_cfg2; - segments[1].m_cfg2 = segments[1].m_cfg1; - segments[0].m_v2 = BOP_getVertexIndex(mesh,points[2],sA.m_cfg2,sA.m_v2); - segments[1].m_v2 = segments[0].m_v2; - break; - - default: - break; - } - } - - segments[0].sort(); - segments[1].sort(); -} - -/** - * Computes the vertex index of a point. - * @param mesh mesh that contains the faces, edges and vertices - * @param point input point - * @param cfgA configuration of point on faceA - * @param cfgB configuration of point on faceB - * @param vA vertex index of point on faceA - * @param vB vertex index of point on faceB - * @param invert indicates if vA has priority over vB - * @return final vertex index in the mesh - */ -BOP_Index BOP_getVertexIndex(BOP_Mesh* mesh, - MT_Point3 point, - unsigned int cfgA, - unsigned int cfgB, - BOP_Index vA, - BOP_Index vB, - bool invert) -{ - if (BOP_Segment::isVertex(cfgA)) { // exists vertex index on A - if (BOP_Segment::isVertex(cfgB)) { // exists vertex index on B - // unify vertex indexs - if (invert) - return mesh->replaceVertexIndex(vA,vB); - else - return mesh->replaceVertexIndex(vB,vA); - } - else - return vA; - } - else {// does not exist vertex index on A - if (BOP_Segment::isVertex(cfgB)) // exists vertex index on B - return vB; - else {// does not exist vertex index on B - return mesh->addVertex(point); - } - } -} - -/** - * Computes the vertex index of a point. - * @param mesh mesh that contains the faces, edges and vertices - * @param cfg configuration of point - * @param v vertex index of point - * @return final vertex index in the mesh - */ -BOP_Index BOP_getVertexIndex(BOP_Mesh *mesh, MT_Point3 point, unsigned int cfg, BOP_Index v) -{ - if (BOP_Segment::isVertex(cfg)) // vertex existent - return v; - else { - return mesh->addVertex(point); - } -} - -/******************************************************************************/ -/*** TRIANGULATE ***/ -/******************************************************************************/ - -/** - * Triangulates the input face according to the specified segment. - * @param mesh mesh that contains the faces, edges and vertices - * @param faces set of faces that contains the original face and the new triangulated faces - * @param face face to be triangulated - * @param s segment used to triangulate face - */ -void triangulate(BOP_Mesh *mesh, BOP_Faces *faces, BOP_Face *face, BOP_Segment s) -{ - if (BOP_Segment::isUndefined(s.m_cfg1)) { - // Nothing to do - } - else if (BOP_Segment::isVertex(s.m_cfg1)) { - // VERTEX(v1) + VERTEX(v2) => nothing to do - } - else if (BOP_Segment::isEdge(s.m_cfg1)) { - if (BOP_Segment::isVertex(s.m_cfg2) || BOP_Segment::isUndefined(s.m_cfg2)) { - // EDGE(v1) + VERTEX(v2) - BOP_Edge *edge = mesh->getEdge(face,BOP_Segment::getEdge(s.m_cfg1)); - BOP_triangulateA(mesh,faces,face,s.m_v1,BOP_Segment::getEdge(s.m_cfg1)); - BOP_Face *opposite = BOP_getOppositeFace(mesh,faces,face,edge); - if (opposite != NULL) { - unsigned int e; - opposite->getEdgeIndex(edge->getVertex1(), edge->getVertex2(),e); - BOP_triangulateA(mesh, faces, opposite, s.m_v1, e); - } - } - else { - // EDGE(v1) + EDGE(v2) - if (BOP_Segment::getEdge(s.m_cfg1) == BOP_Segment::getEdge(s.m_cfg2)) { - // EDGE(v1) == EDGE(v2) - BOP_Edge *edge = mesh->getEdge(face,BOP_Segment::getEdge(s.m_cfg1)); - BOP_triangulateD(mesh, faces, face, s.m_v1, s.m_v2, - BOP_Segment::getEdge(s.m_cfg1)); - BOP_Face *opposite = BOP_getOppositeFace(mesh,faces,face,edge); - if (opposite != NULL) { - unsigned int e; - opposite->getEdgeIndex(edge->getVertex1(), edge->getVertex2(),e); - BOP_triangulateD(mesh, faces, opposite, s.m_v1, s.m_v2, e); - } - } - else { // EDGE(v1) != EDGE(v2) - BOP_Edge *edge1 = mesh->getEdge(face,BOP_Segment::getEdge(s.m_cfg1)); - BOP_Edge *edge2 = mesh->getEdge(face,BOP_Segment::getEdge(s.m_cfg2)); - BOP_triangulateE(mesh, faces, face, s.m_v1, s.m_v2, - BOP_Segment::getEdge(s.m_cfg1), - BOP_Segment::getEdge(s.m_cfg2)); - BOP_Face *opposite = BOP_getOppositeFace(mesh,faces,face,edge1); - if (opposite != NULL) { - unsigned int e; - opposite->getEdgeIndex(edge1->getVertex1(), edge1->getVertex2(),e); - BOP_triangulateA(mesh, faces, opposite, s.m_v1, e); - } - opposite = BOP_getOppositeFace(mesh,faces,face,edge2); - if (opposite != NULL) { - unsigned int e; - opposite->getEdgeIndex(edge2->getVertex1(), edge2->getVertex2(),e); - BOP_triangulateA(mesh, faces, opposite, s.m_v2, e); - } - } - } - } - else if (BOP_Segment::isIn(s.m_cfg1)) { - if (BOP_Segment::isVertex(s.m_cfg2) || BOP_Segment::isUndefined(s.m_cfg2)) { - // IN(v1) + VERTEX(v2) - BOP_triangulateB(mesh,faces,face,s.m_v1); - } - else if (BOP_Segment::isEdge(s.m_cfg2)) { - // IN(v1) + EDGE(v2) - BOP_Edge *edge = mesh->getEdge(face,BOP_Segment::getEdge(s.m_cfg2)); - BOP_triangulateF(mesh,faces,face,s.m_v1,s.m_v2,BOP_Segment::getEdge(s.m_cfg2)); - BOP_Face *opposite = BOP_getOppositeFace(mesh,faces,face,edge); - if (opposite != NULL) { - unsigned int e; - opposite->getEdgeIndex(edge->getVertex1(), edge->getVertex2(),e); - BOP_triangulateA(mesh, faces, opposite, s.m_v2, e); - } - } - else // IN(v1) + IN(v2) - BOP_triangulateC(mesh,faces,face,s.m_v1,s.m_v2); - } -} - -/** - * Returns if a face is in the set of faces. - * @param faces set of faces - * @param face face to be searched - * @return if the face is inside faces - */ -bool BOP_containsFace(BOP_Faces *faces, BOP_Face *face) -{ - const BOP_IT_Faces facesEnd = faces->end(); - for(BOP_IT_Faces it=faces->begin();it!=facesEnd;it++) - { - if (*it == face) - return true; - } - - return false; -} - -/** - * Returns the first face of faces that shares the input edge of face. - * @param mesh mesh that contains the faces, edges and vertices - * @param faces set of faces - * @param face input face - * @param edge face's edge - * @return first face that shares the edge of input face - */ -BOP_Face *BOP_getOppositeFace(BOP_Mesh* mesh, - BOP_Faces* faces, - BOP_Face* face, - BOP_Edge* edge) -{ - if (edge == NULL) - return NULL; - - BOP_Indexs auxfaces = edge->getFaces(); - const BOP_IT_Indexs auxfacesEnd = auxfaces.end(); - for(BOP_IT_Indexs it = auxfaces.begin(); it != auxfacesEnd; it++) { - BOP_Face *auxface = mesh->getFace(*it); - if ((auxface != face) && (auxface->getTAG()!=BROKEN) && - BOP_containsFace(faces,auxface)) { - return auxface; - } - } - - return NULL; -} - -/******************************************************************************/ -/*** OVERLAPPING ***/ -/******************************************************************************/ - -/** - * Removes faces from facesB that are overlapped with anyone from facesA. - * @param mesh mesh that contains the faces, edges and vertices - * @param facesA set of faces from object A - * @param facesB set of faces from object B - */ -void BOP_removeOverlappedFaces(BOP_Mesh *mesh, BOP_Faces *facesA, BOP_Faces *facesB) -{ - for(unsigned int i=0;i<facesA->size();i++) { - BOP_Face *faceI = (*facesA)[i]; - if (faceI->getTAG()==BROKEN) continue; - bool overlapped = false; - MT_Point3 p1 = mesh->getVertex(faceI->getVertex(0))->getPoint(); - MT_Point3 p2 = mesh->getVertex(faceI->getVertex(1))->getPoint(); - MT_Point3 p3 = mesh->getVertex(faceI->getVertex(2))->getPoint(); - for(unsigned int j=0;j<facesB->size();) { - BOP_Face *faceJ = (*facesB)[j]; - if (faceJ->getTAG()!=BROKEN) { - MT_Plane3 planeJ = faceJ->getPlane(); - if (BOP_containsPoint(planeJ,p1) && BOP_containsPoint(planeJ,p2) - && BOP_containsPoint(planeJ,p3)) - { - MT_Point3 q1 = mesh->getVertex(faceJ->getVertex(0))->getPoint(); - MT_Point3 q2 = mesh->getVertex(faceJ->getVertex(1))->getPoint(); - MT_Point3 q3 = mesh->getVertex(faceJ->getVertex(2))->getPoint(); - if (BOP_overlap(MT_Vector3(planeJ.x(),planeJ.y(),planeJ.z()), - p1,p2,p3,q1,q2,q3)) - { - facesB->erase(facesB->begin()+j,facesB->begin()+(j+1)); - faceJ->setTAG(BROKEN); - overlapped = true; - } - else j++; - } - else j++; - }else j++; - } - if (overlapped) faceI->setTAG(OVERLAPPED); - } -} - -/** - * Computes if triangle p1,p2,p3 is overlapped with triangle q1,q2,q3. - * @param normal normal of the triangle p1,p2,p3 - * @param p1 point of first triangle - * @param p2 point of first triangle - * @param p3 point of first triangle - * @param q1 point of second triangle - * @param q2 point of second triangle - * @param q3 point of second triangle - * @return if there is overlapping between both triangles - */ -bool BOP_overlap(MT_Vector3 normal, MT_Point3 p1, MT_Point3 p2, MT_Point3 p3, - MT_Point3 q1, MT_Point3 q2, MT_Point3 q3) -{ - MT_Vector3 p1p2 = p2-p1; - MT_Plane3 plane1(p1p2.cross(normal),p1); - - MT_Vector3 p2p3 = p3-p2; - MT_Plane3 plane2(p2p3.cross(normal),p2); - - MT_Vector3 p3p1 = p1-p3; - MT_Plane3 plane3(p3p1.cross(normal),p3); - - BOP_TAG tag1 = BOP_createTAG(BOP_classify(q1,plane1)); - BOP_TAG tag2 = BOP_createTAG(BOP_classify(q1,plane2)); - BOP_TAG tag3 = BOP_createTAG(BOP_classify(q1,plane3)); - BOP_TAG tagQ1 = BOP_createTAG(tag1,tag2,tag3); - if (tagQ1 == IN_IN_IN) return true; - - tag1 = BOP_createTAG(BOP_classify(q2,plane1)); - tag2 = BOP_createTAG(BOP_classify(q2,plane2)); - tag3 = BOP_createTAG(BOP_classify(q2,plane3)); - BOP_TAG tagQ2 = BOP_createTAG(tag1,tag2,tag3); - if (tagQ2 == IN_IN_IN) return true; - - tag1 = BOP_createTAG(BOP_classify(q3,plane1)); - tag2 = BOP_createTAG(BOP_classify(q3,plane2)); - tag3 = BOP_createTAG(BOP_classify(q3,plane3)); - BOP_TAG tagQ3 = BOP_createTAG(tag1,tag2,tag3); - if (tagQ3 == IN_IN_IN) return true; - - if ((tagQ1 & OUT_OUT_OUT) == 0 && (tagQ2 & OUT_OUT_OUT) == 0 && - (tagQ3 & OUT_OUT_OUT) == 0) return true; - else return false; -} diff --git a/intern/boolop/intern/BOP_Face2Face.h b/intern/boolop/intern/BOP_Face2Face.h deleted file mode 100644 index 9809084ce3b..00000000000 --- a/intern/boolop/intern/BOP_Face2Face.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file boolop/intern/BOP_Face2Face.h - * \ingroup boolopintern - */ - - -#ifndef __BOP_FACE2FACE_H__ -#define __BOP_FACE2FACE_H__ - -#include "BOP_Mesh.h" -#include "BOP_Segment.h" -#include "BOP_Triangulator.h" -#include "BOP_Splitter.h" -#include "BOP_BSPTree.h" - -void BOP_Face2Face(BOP_Mesh *mesh, BOP_Faces *facesA, BOP_Faces *facesB); -void BOP_sew(BOP_Mesh *mesh, BOP_Faces *facesA, BOP_Faces *facesB); -void BOP_removeOverlappedFaces(BOP_Mesh *mesh, BOP_Faces *facesA, BOP_Faces *facesB); - -#endif diff --git a/intern/boolop/intern/BOP_Interface.cpp b/intern/boolop/intern/BOP_Interface.cpp deleted file mode 100644 index b18a4334263..00000000000 --- a/intern/boolop/intern/BOP_Interface.cpp +++ /dev/null @@ -1,535 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file boolop/intern/BOP_Interface.cpp - * \ingroup boolopintern - */ - - -#include <iostream> -#include <map> -#include "../extern/BOP_Interface.h" -#include "../../bsp/intern/BSP_CSGMesh_CFIterator.h" -#include "BOP_BSPTree.h" -#include "BOP_Mesh.h" -#include "BOP_Face2Face.h" -#include "BOP_Merge.h" -#include "BOP_Merge2.h" -#include "BOP_Chrono.h" - -#if defined(BOP_ORIG_MERGE) && defined(BOP_NEW_MERGE) -#include "../../../source/blender/blenkernel/BKE_global.h" -#endif - -BoolOpState BOP_intersectionBoolOp(BOP_Mesh* meshC, - BOP_Faces* facesA, - BOP_Faces* facesB, - bool invertMeshA, - bool invertMeshB); -BOP_Face3* BOP_createFace(BOP_Mesh* mesh, - BOP_Index vertex1, - BOP_Index vertex2, - BOP_Index vertex3, - BOP_Index origFace); -void BOP_addMesh(BOP_Mesh* mesh, - BOP_Faces* meshFacesId, - CSG_FaceIteratorDescriptor& face_it, - CSG_VertexIteratorDescriptor& vertex_it, - bool invert); -BSP_CSGMesh* BOP_newEmptyMesh(); -BSP_CSGMesh* BOP_exportMesh(BOP_Mesh* inputMesh, - bool invert); -void BOP_meshFilter(BOP_Mesh* meshC, BOP_Faces* faces, BOP_BSPTree* bsp); -void BOP_simplifiedMeshFilter(BOP_Mesh* meshC, BOP_Faces* faces, BOP_BSPTree* bsp, bool inverted); -void BOP_meshClassify(BOP_Mesh* meshC, BOP_Faces* faces, BOP_BSPTree* bsp); - -/** - * Performs a generic booleam operation, the entry point for external modules. - * @param opType Boolean operation type BOP_INTERSECTION, BOP_UNION, BOP_DIFFERENCE - * @param outputMesh Output mesh, the final result (the object C) - * @param obAFaces Object A faces list - * @param obAVertices Object A vertices list - * @param obBFaces Object B faces list - * @param obBVertices Object B vertices list - * @param interpFunc Interpolating function - * @return operation state: BOP_OK, BOP_NO_SOLID, BOP_ERROR - */ -BoolOpState BOP_performBooleanOperation(BoolOpType opType, - BSP_CSGMesh** outputMesh, - CSG_FaceIteratorDescriptor obAFaces, - CSG_VertexIteratorDescriptor obAVertices, - CSG_FaceIteratorDescriptor obBFaces, - CSG_VertexIteratorDescriptor obBVertices) -{ - #ifdef BOP_DEBUG - std::cout << "BEGIN BOP_performBooleanOperation" << std::endl; - #endif - - // Set invert flags depending on boolean operation type: - // INTERSECTION: A^B = and(A,B) - // UNION: A|B = not(and(not(A),not(B))) - // DIFFERENCE: A-B = and(A,not(B)) - bool invertMeshA = (opType == BOP_UNION); - bool invertMeshB = (opType != BOP_INTERSECTION); - bool invertMeshC = (opType == BOP_UNION); - - // Faces list for both objects, used by boolean op. - BOP_Faces meshAFacesId; - BOP_Faces meshBFacesId; - - // Build C-mesh, the output mesh - BOP_Mesh meshC; - - // Add A-mesh into C-mesh - BOP_addMesh(&meshC, &meshAFacesId, obAFaces, obAVertices, invertMeshA); - - // Add B-mesh into C-mesh - BOP_addMesh(&meshC, &meshBFacesId, obBFaces, obBVertices, invertMeshB); - - // for now, allow operations on non-manifold (non-solid) meshes -#if 0 - if (!meshC.isClosedMesh()) - return BOP_NO_SOLID; -#endif - - // Perform the intersection boolean operation. - BoolOpState result = BOP_intersectionBoolOp(&meshC, &meshAFacesId, &meshBFacesId, - invertMeshA, invertMeshB); - - // Invert the output mesh if is required - *outputMesh = BOP_exportMesh(&meshC, invertMeshC); - - #ifdef BOP_DEBUG - std::cout << "END BOP_performBooleanOperation" << std::endl; - #endif - - return result; -} - -/** - * Computes the intersection boolean operation. Creates a new mesh resulting from - * an intersection of two meshes. - * @param meshC Input & Output mesh - * @param facesA Mesh A faces list - * @param facesB Mesh B faces list - * @param invertMeshA determines if object A is inverted - * @param invertMeshB determines if object B is inverted - * @return operation state: BOP_OK, BOP_NO_SOLID, BOP_ERROR - */ -BoolOpState BOP_intersectionBoolOp(BOP_Mesh* meshC, - BOP_Faces* facesA, - BOP_Faces* facesB, - bool invertMeshA, - bool invertMeshB) -{ - #ifdef BOP_DEBUG - BOP_Chrono chrono; - float t = 0.0f; - float c = 0.0f; - chrono.start(); - std::cout << "---" << std::endl; - #endif - - // Create BSPs trees for mesh A & B - BOP_BSPTree bspA; - bspA.addMesh(meshC, *facesA); - - BOP_BSPTree bspB; - bspB.addMesh(meshC, *facesB); - - #ifdef BOP_DEBUG - c = chrono.stamp(); t += c; - std::cout << "Create BSP " << c << std::endl; - #endif - - unsigned int numVertices = meshC->getNumVertexs(); - - // mesh pre-filter - BOP_simplifiedMeshFilter(meshC, facesA, &bspB, invertMeshB); - if ((0.25*facesA->size()) > bspB.getDeep()) - BOP_meshFilter(meshC, facesA, &bspB); - - BOP_simplifiedMeshFilter(meshC, facesB, &bspA, invertMeshA); - if ((0.25*facesB->size()) > bspA.getDeep()) - BOP_meshFilter(meshC, facesB, &bspA); - - #ifdef BOP_DEBUG - c = chrono.stamp(); t += c; - std::cout << "mesh Filter " << c << std::endl; - #endif - - // Face 2 Face - BOP_Face2Face(meshC,facesA,facesB); - - #ifdef BOP_DEBUG - c = chrono.stamp(); t += c; - std::cout << "Face2Face " << c << std::endl; - #endif - - // BSP classification - BOP_meshClassify(meshC,facesA,&bspB); - BOP_meshClassify(meshC,facesB,&bspA); - - #ifdef BOP_DEBUG - c = chrono.stamp(); t += c; - std::cout << "Classification " << c << std::endl; - #endif - - // Process overlapped faces - BOP_removeOverlappedFaces(meshC,facesA,facesB); - - #ifdef BOP_DEBUG - c = chrono.stamp(); t += c; - std::cout << "Remove overlap " << c << std::endl; - #endif - - // Sew two meshes - BOP_sew(meshC,facesA,facesB); - - #ifdef BOP_DEBUG - c = chrono.stamp(); t += c; - std::cout << "Sew " << c << std::endl; - #endif - - // Merge faces -#ifdef BOP_ORIG_MERGE -#ifndef BOP_NEW_MERGE - BOP_Merge::getInstance().mergeFaces(meshC,numVertices); -#endif -#endif - -#ifdef BOP_NEW_MERGE -#ifndef BOP_ORIG_MERGE - BOP_Merge2::getInstance().mergeFaces(meshC,numVertices); -#else - static int state = -1; - if (G.rt == 100) { - if( state != 1 ) { - std::cout << "Boolean code using old merge technique." << std::endl; - state = 1; - } - BOP_Merge::getInstance().mergeFaces(meshC,numVertices); - } else { - if( state != 0 ) { - std::cout << "Boolean code using new merge technique." << std::endl; - state = 0; - } - BOP_Merge2::getInstance().mergeFaces(meshC,numVertices); - } -#endif -#endif - - #ifdef BOP_DEBUG - c = chrono.stamp(); t += c; - std::cout << "Merge faces " << c << std::endl; - std::cout << "Total " << t << std::endl; - // Test integrity - meshC->testMesh(); - #endif - - return BOP_OK; -} - -/** - * Preprocess to filter no collisioned faces. - * @param meshC Input & Output mesh data - * @param faces Faces list to test - * @param bsp BSP tree used to filter - */ -void BOP_meshFilter(BOP_Mesh* meshC, BOP_Faces* faces, BOP_BSPTree* bsp) -{ - BOP_IT_Faces it; - BOP_TAG tag; - - it = faces->begin(); - while (it!=faces->end()) { - BOP_Face *face = *it; - MT_Point3 p1 = meshC->getVertex(face->getVertex(0))->getPoint(); - MT_Point3 p2 = meshC->getVertex(face->getVertex(1))->getPoint(); - MT_Point3 p3 = meshC->getVertex(face->getVertex(2))->getPoint(); - if ((tag = bsp->classifyFace(p1,p2,p3,face->getPlane()))==OUT||tag==OUTON) { - face->setTAG(BROKEN); - it = faces->erase(it); - } - else if (tag == IN) { - it = faces->erase(it); - }else{ - it++; - } - } -} - -/** - * Pre-process to filter no collisioned faces. - * @param meshC Input & Output mesh data - * @param faces Faces list to test - * @param bsp BSP tree used to filter - * @param inverted determines if the object is inverted - */ -void BOP_simplifiedMeshFilter(BOP_Mesh* meshC, BOP_Faces* faces, BOP_BSPTree* bsp, bool inverted) -{ - BOP_IT_Faces it; - - it = faces->begin(); - while (it!=faces->end()) { - BOP_Face *face = *it; - MT_Point3 p1 = meshC->getVertex(face->getVertex(0))->getPoint(); - MT_Point3 p2 = meshC->getVertex(face->getVertex(1))->getPoint(); - MT_Point3 p3 = meshC->getVertex(face->getVertex(2))->getPoint(); - if (bsp->filterFace(p1,p2,p3,face)==OUT) { - if (!inverted) face->setTAG(BROKEN); - it = faces->erase(it); - } - else { - it++; - } - } -} - -/** - * Process to classify the mesh faces using a bsp tree. - * @param meshC Input & Output mesh data - * @param faces Faces list to classify - * @param bsp BSP tree used to face classify - */ -void BOP_meshClassify(BOP_Mesh* meshC, BOP_Faces* faces, BOP_BSPTree* bsp) -{ - for(BOP_IT_Faces face=faces->begin();face!=faces->end();face++) { - if ((*face)->getTAG()!=BROKEN) { - MT_Point3 p1 = meshC->getVertex((*face)->getVertex(0))->getPoint(); - MT_Point3 p2 = meshC->getVertex((*face)->getVertex(1))->getPoint(); - MT_Point3 p3 = meshC->getVertex((*face)->getVertex(2))->getPoint(); - if (bsp->simplifiedClassifyFace(p1,p2,p3,(*face)->getPlane())!=IN) { - (*face)->setTAG(BROKEN); - } - } - } -} - -/** - * Returns a new mesh triangle. - * @param meshC Input & Output mesh data - * @param vertex1 first vertex of the new face - * @param vertex2 second vertex of the new face - * @param vertex3 third vertex of the new face - * @param origFace identifier of the new face - * @return new the new face - */ -BOP_Face3 *BOP_createFace3(BOP_Mesh* mesh, - BOP_Index vertex1, - BOP_Index vertex2, - BOP_Index vertex3, - BOP_Index origFace) -{ - MT_Point3 p1 = mesh->getVertex(vertex1)->getPoint(); - MT_Point3 p2 = mesh->getVertex(vertex2)->getPoint(); - MT_Point3 p3 = mesh->getVertex(vertex3)->getPoint(); - MT_Plane3 plane(p1,p2,p3); - - return new BOP_Face3(vertex1, vertex2, vertex3, plane, origFace); -} - -/** - * Adds mesh information into destination mesh. - * @param mesh input/output mesh, destination for the new mesh data - * @param meshFacesId output mesh faces, contains an added faces list - * @param face_it faces iterator - * @param vertex_it vertices iterator - * @param inverted if TRUE adding inverted faces, non-inverted otherwise - */ -void BOP_addMesh(BOP_Mesh* mesh, - BOP_Faces* meshFacesId, - CSG_FaceIteratorDescriptor& face_it, - CSG_VertexIteratorDescriptor& vertex_it, - bool invert) -{ - unsigned int vtxIndexOffset = mesh->getNumVertexs(); - - // The size of the vertex data array will be at least the number of faces. - CSG_IVertex vertex; - while (!vertex_it.Done(vertex_it.it)) { - vertex_it.Fill(vertex_it.it,&vertex); - MT_Point3 pos(vertex.position); - mesh->addVertex(pos); - vertex_it.Step(vertex_it.it); - } - - CSG_IFace face; - - // now for the polygons. - // we may need to decalare some memory for user defined face properties. - - BOP_Face3 *newface; - - while (!face_it.Done(face_it.it)) { - face_it.Fill(face_it.it,&face); - - // Let's not rely on quads being coplanar - especially if they - // are coming out of that soup of code from blender... - if (face.vertex_number == 4){ - // QUAD - if (invert) { - newface = BOP_createFace3(mesh, - face.vertex_index[2] + vtxIndexOffset, - face.vertex_index[0] + vtxIndexOffset, - face.vertex_index[3] + vtxIndexOffset, - face.orig_face); - meshFacesId->push_back(newface); - mesh->addFace(newface); - newface = BOP_createFace3(mesh, - face.vertex_index[2] + vtxIndexOffset, - face.vertex_index[1] + vtxIndexOffset, - face.vertex_index[0] + vtxIndexOffset, - face.orig_face); - meshFacesId->push_back(newface); - mesh->addFace(newface); - } - else { - newface = BOP_createFace3(mesh, - face.vertex_index[0] + vtxIndexOffset, - face.vertex_index[2] + vtxIndexOffset, - face.vertex_index[3] + vtxIndexOffset, - face.orig_face); - meshFacesId->push_back(newface); - mesh->addFace(newface); - newface = BOP_createFace3(mesh, - face.vertex_index[0] + vtxIndexOffset, - face.vertex_index[1] + vtxIndexOffset, - face.vertex_index[2] + vtxIndexOffset, - face.orig_face); - meshFacesId->push_back(newface); - mesh->addFace(newface); - } - } - else { - // TRIANGLES - if (invert) { - newface = BOP_createFace3(mesh, - face.vertex_index[2] + vtxIndexOffset, - face.vertex_index[1] + vtxIndexOffset, - face.vertex_index[0] + vtxIndexOffset, - face.orig_face); - meshFacesId->push_back(newface); - mesh->addFace(newface); - } - else { - newface = BOP_createFace3(mesh, - face.vertex_index[0] + vtxIndexOffset, - face.vertex_index[1] + vtxIndexOffset, - face.vertex_index[2] + vtxIndexOffset, - face.orig_face); - meshFacesId->push_back(newface); - mesh->addFace(newface); - } - } - - face_it.Step(face_it.it); - } -} - -/** - * Returns an empty mesh with the specified properties. - * @return a new empty mesh - */ -BSP_CSGMesh* BOP_newEmptyMesh() -{ - BSP_CSGMesh* mesh = BSP_CSGMesh::New(); - if (mesh == NULL) return mesh; - - std::vector<BSP_MVertex>* vertices = new std::vector<BSP_MVertex>; - - mesh->SetVertices(vertices); - - return mesh; -} - -/** - * Exports a BOP_Mesh to a BSP_CSGMesh. - * @param mesh Input mesh - * @param invert if TRUE export with inverted faces, no inverted otherwise - * @return the corresponding new BSP_CSGMesh - */ -BSP_CSGMesh* BOP_exportMesh(BOP_Mesh* mesh, - bool invert) -{ - BSP_CSGMesh* outputMesh = BOP_newEmptyMesh(); - - if (outputMesh == NULL) return NULL; - - // vtx index dictionary, to translate indeces from input to output. - std::map<int,unsigned int> dic; - std::map<int,unsigned int>::iterator itDic; - - unsigned int count = 0; - - // Add a new face for each face in the input list - BOP_Faces faces = mesh->getFaces(); - BOP_Vertexs vertexs = mesh->getVertexs(); - - for (BOP_IT_Faces face = faces.begin(); face != faces.end(); face++) { - if ((*face)->getTAG()!=BROKEN){ - // Add output face - outputMesh->FaceSet().push_back(BSP_MFace()); - BSP_MFace& outFace = outputMesh->FaceSet().back(); - - // Copy face - outFace.m_verts.clear(); - outFace.m_plane = (*face)->getPlane(); - outFace.m_orig_face = (*face)->getOriginalFace(); - - // invert face if is required - if (invert) (*face)->invert(); - - // Add the face vertex if not added yet - for (unsigned int pos=0;pos<(*face)->size();pos++) { - BSP_VertexInd outVtxId; - BOP_Index idVertex = (*face)->getVertex(pos); - itDic = dic.find(idVertex); - if (itDic == dic.end()) { - // The vertex isn't added yet - outVtxId = BSP_VertexInd(outputMesh->VertexSet().size()); - BSP_MVertex outVtx((mesh->getVertex(idVertex))->getPoint()); - outVtx.m_edges.clear(); - outputMesh->VertexSet().push_back(outVtx); - dic[idVertex] = outVtxId; - count++; - } - else { - // The vertex is added - outVtxId = BSP_VertexInd(itDic->second); - } - - outFace.m_verts.push_back(outVtxId); - } - } - } - - // Build the mesh edges using topological informtion - outputMesh->BuildEdges(); - - return outputMesh; -} diff --git a/intern/boolop/intern/BOP_MathUtils.cpp b/intern/boolop/intern/BOP_MathUtils.cpp deleted file mode 100644 index 020de2163a3..00000000000 --- a/intern/boolop/intern/BOP_MathUtils.cpp +++ /dev/null @@ -1,471 +0,0 @@ -/* - * - * - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Marc Freixas, Ken Hughes - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file boolop/intern/BOP_MathUtils.cpp - * \ingroup boolopintern - */ - - -#include "BOP_MathUtils.h" -#include <iostream> - -/** - * Compares two scalars with EPSILON accuracy. - * @param A scalar - * @param B scalar - * @return 1 if A > B, -1 if A < B, 0 otherwise - */ -int BOP_comp(const MT_Scalar A, const MT_Scalar B) -{ -#ifndef VAR_EPSILON - if (A >= B + BOP_EPSILON) return 1; - else if (B >= A + BOP_EPSILON) return -1; - else return 0; -#else - int expA, expB; - float mant; - frexp(A, &expA); /* get exponents of each number */ - frexp(B, &expB); - - if(expA < expB) /* find the larger exponent */ - expA = expB; - mant = frexp((A-B), &expB); /* get exponent of the difference */ - /* mantissa will only be zero is (A-B) is really zero; otherwise, also - * also allow a "reasonably" small exponent or "reasonably large" - * difference in exponents to be considers "close to zero" */ - if( mant == 0 || expB < -30 || expA - expB > 31) return 0; - else if( mant > 0) return 1; - else return -1; -#endif -} - -/** - * Compares a scalar with EPSILON accuracy. - * @param A scalar - * @return 1 if A > 0, -1 if A < 0, 0 otherwise - */ -int BOP_comp0(const MT_Scalar A) -{ - if (A >= BOP_EPSILON) return 1; - else if (0 >= A + BOP_EPSILON) return -1; - else return 0; -} - -/** - * Compares two scalar triplets with EPSILON accuracy. - * @param A scalar triplet - * @param B scalar triplet - * @return 1 if A > B, -1 if A < B, 0 otherwise - */ -int BOP_comp(const MT_Tuple3& A, const MT_Tuple3& B) -{ -#ifndef VAR_EPSILON - if (A.x() >= (B.x() + BOP_EPSILON)) return 1; - else if (B.x() >= (A.x() + BOP_EPSILON)) return -1; - else if (A.y() >= (B.y() + BOP_EPSILON)) return 1; - else if (B.y() >= (A.y() + BOP_EPSILON)) return -1; - else if (A.z() >= (B.z() + BOP_EPSILON)) return 1; - else if (B.z() >= (A.z() + BOP_EPSILON)) return -1; - else return 0; -#else - int result = BOP_comp(A.x(), B.x()); - if (result != 0) return result; - result = BOP_comp(A.y(), B.y()); - if (result != 0) return result; - return BOP_comp(A.z(), B.z()); -#endif -} - -/** - * Compares two scalars strictly. - * @param A scalar - * @param B scalar - * @return 1 if A > B, -1 if A < B, 0 otherwise - */ -int BOP_exactComp(const MT_Scalar A, const MT_Scalar B) -{ - if (A > B) return 1; - else if (B > A) return -1; - else return 0; -} -/** - * Compares two scalar strictly. - * @param A scalar triplet - * @param B scalar triplet - * @return 1 if A > B, -1 if A < B, 0 otherwise - */ -int BOP_exactComp(const MT_Tuple3& A, const MT_Tuple3& B) -{ - if (A.x() > B.x()) return 1; - else if (B.x() > A.x()) return -1; - else if (A.y() > B.y()) return 1; - else if (B.y() > A.y()) return -1; - else if (A.z() > B.z()) return 1; - else if (B.z() > A.z()) return -1; - else return 0; -} - -/** - * Returns if p1 is between p2 and p3 and lay on the same line (are collinears). - * @param p1 point - * @param p2 point - * @param p3 point - * @return true if p1 is between p2 and p3 and lay on the same line, false otherwise - */ -bool BOP_between(const MT_Point3& p1, const MT_Point3& p2, const MT_Point3& p3) -{ - MT_Scalar distance = p2.distance(p3); - return (p1.distance(p2) < distance && p1.distance(p3) < distance) && BOP_collinear(p1,p2,p3); -} - -/** - * Returns if three points lay on the same line (are collinears). - * @param p1 point - * @param p2 point - * @param p3 point - * @return true if the three points lay on the same line, false otherwise - */ -bool BOP_collinear(const MT_Point3& p1, const MT_Point3& p2, const MT_Point3& p3) -{ - if( BOP_comp(p1,p2) == 0 || BOP_comp(p2,p3) == 0 ) return true; - - MT_Vector3 v1 = p2 - p1; - MT_Vector3 v2 = p3 - p2; - - /* normalize vectors before taking their cross product, so its length - * has some actual meaning */ - // if(MT_fuzzyZero(v1.length()) || MT_fuzzyZero(v2.length())) return true; - v1.normalize(); - v2.normalize(); - - MT_Vector3 w = v1.cross(v2); - - return (BOP_fuzzyZero(w.x()) && BOP_fuzzyZero(w.y()) && BOP_fuzzyZero(w.z())); -} - -/** - * Returns if a quad (coplanar) is convex. - * @return true if the quad is convex, false otherwise - */ -bool BOP_convex(const MT_Point3& p1, const MT_Point3& p2, const MT_Point3& p3, const MT_Point3& p4) -{ - MT_Vector3 v1 = p3 - p1; - MT_Vector3 v2 = p4 - p2; - MT_Vector3 quadPlane = v1.cross(v2); - // plane1 is the perpendicular plane that contains the quad diagonal (p2,p4) - MT_Plane3 plane1(quadPlane.cross(v2),p2); - // if p1 and p3 are classified in the same region, the quad is not convex - if (BOP_classify(p1,plane1) == BOP_classify(p3,plane1)) return false; - else { - // Test the other quad diagonal (p1,p3) and perpendicular plane - MT_Plane3 plane2(quadPlane.cross(v1),p1); - // if p2 and p4 are classified in the same region, the quad is not convex - return (BOP_classify(p2,plane2) != BOP_classify(p4,plane2)); - } -} - -/** - * Returns if a quad (coplanar) is concave and where is the split edge. - * @return 0 if is convex, 1 if is concave and split edge is p1-p3 and -1 if is - * cancave and split edge is p2-p4. - */ -int BOP_concave(const MT_Point3& p1, const MT_Point3& p2, const MT_Point3& p3, const MT_Point3& p4) -{ - MT_Vector3 v1 = p3 - p1; - MT_Vector3 v2 = p4 - p2; - MT_Vector3 quadPlane = v1.cross(v2); - // plane1 is the perpendicular plane that contains the quad diagonal (p2,p4) - MT_Plane3 plane1(quadPlane.cross(v2),p2); - // if p1 and p3 are classified in the same region, the quad is not convex - if (BOP_classify(p1,plane1) == BOP_classify(p3,plane1)) return 1; - else { - // Test the other quad diagonal (p1,p3) and perpendicular plane - MT_Plane3 plane2(quadPlane.cross(v1),p1); - // if p2 and p4 are classified in the same region, the quad is not convex - if (BOP_classify(p2,plane2) == BOP_classify(p4,plane2)) return -1; - else return 0; - } -} - -/** - * Computes the intersection between two lines (on the same plane). - * @param vL1 first line vector - * @param pL1 first line point - * @param vL2 second line vector - * @param pL2 second line point - * @param intersection intersection point (if exists) - * @return false if lines are parallels, true otherwise - */ -bool BOP_intersect(const MT_Vector3& vL1, const MT_Point3& pL1, const MT_Vector3& vL2, - const MT_Point3& pL2, MT_Point3 &intersection) -{ - // NOTE: - // If the lines aren't on the same plane, the intersection point will not be valid. - // So be careful !! - - MT_Scalar t = -1; - MT_Scalar den = (vL1.y()*vL2.x() - vL1.x() * vL2.y()); - - if (!BOP_fuzzyZero(den)) { - t = (pL2.y()*vL1.x() - vL1.y()*pL2.x() + pL1.x()*vL1.y() - pL1.y()*vL1.x()) / den; - } - else { - den = (vL1.y()*vL2.z() - vL1.z() * vL2.y()); - if (!BOP_fuzzyZero(den)) { - t = (pL2.y()*vL1.z() - vL1.y()*pL2.z() + pL1.z()*vL1.y() - pL1.y()*vL1.z()) / den; - } - else { - den = (vL1.x()*vL2.z() - vL1.z() * vL2.x()); - if (!BOP_fuzzyZero(den)) { - t = (pL2.x()*vL1.z() - vL1.x()*pL2.z() + pL1.z()*vL1.x() - pL1.x()*vL1.z()) / den; - } - else { - return false; - } - } - } - - intersection.setValue(vL2.x()*t + pL2.x(), vL2.y()*t + pL2.y(), vL2.z()*t + pL2.z()); - return true; -} - -/** - * Returns the center of the circle defined by three points. - * @param p1 point - * @param p2 point - * @param p3 point - * @param center circle center - * @return false if points are collinears, true otherwise - */ -bool BOP_getCircleCenter(const MT_Point3& p1, const MT_Point3& p2, const MT_Point3& p3, - MT_Point3& center) -{ - // Compute quad plane - MT_Vector3 p1p2 = p2-p1; - MT_Vector3 p1p3 = p3-p1; - MT_Plane3 plane1(p1,p2,p3); - MT_Vector3 plane = plane1.Normal(); - - // Compute first line vector, perpendicular to plane vector and edge (p1,p2) - MT_Vector3 vL1 = p1p2.cross(plane); - if( MT_fuzzyZero(vL1.length() ) ) - return false; - vL1.normalize(); - - // Compute first line point, middle point of edge (p1,p2) - MT_Point3 pL1 = p1.lerp(p2, 0.5); - - // Compute second line vector, perpendicular to plane vector and edge (p1,p3) - MT_Vector3 vL2 = p1p3.cross(plane); - if( MT_fuzzyZero(vL2.length() ) ) - return false; - vL2.normalize(); - - // Compute second line point, middle point of edge (p1,p3) - MT_Point3 pL2 = p1.lerp(p3, 0.5); - - // Compute intersection (the lines lay on the same plane, so the intersection exists - // only if they are not parallel!!) - return BOP_intersect(vL1,pL1,vL2,pL2,center); -} - -/** - * Returns if points q is inside the circle defined by p1, p2 and p3. - * @param p1 point - * @param p2 point - * @param p3 point - * @param q point - * @return true if p4 or p5 are inside the circle, false otherwise. If - * the circle does not exist (p1, p2 and p3 are collinears) returns true - */ -bool BOP_isInsideCircle(const MT_Point3& p1, const MT_Point3& p2, const MT_Point3& p3, - const MT_Point3& q) -{ - MT_Point3 center; - - // Compute circle center - bool ok = BOP_getCircleCenter(p1,p2,p3,center); - - if (!ok) return true; // p1,p2 and p3 are collinears - - // Check if q is inside the circle - MT_Scalar r = p1.distance(center); - MT_Scalar d = q.distance(center); - return (BOP_comp(d,r) <= 0); -} - -/** - * Returns if points p4 or p5 is inside the circle defined by p1, p2 and p3. - * @param p1 point - * @param p2 point - * @param p3 point - * @param p4 point - * @param p5 point - * @return true if p4 or p5 is inside the circle, false otherwise. If - * the circle does not exist (p1, p2 and p3 are collinears) returns true - */ -bool BOP_isInsideCircle(const MT_Point3& p1, const MT_Point3& p2, const MT_Point3& p3, - const MT_Point3& p4, const MT_Point3& p5) -{ - MT_Point3 center; - bool ok = BOP_getCircleCenter(p1,p2,p3,center); - - if (!ok) return true; // Collinear points! - - // Check if p4 or p5 is inside the circle - MT_Scalar r = p1.distance(center); - MT_Scalar d1 = p4.distance(center); - MT_Scalar d2 = p5.distance(center); - return (BOP_comp(d1,r) <= 0 || BOP_comp(d2,r) <= 0); -} - -/** - * Returns if two planes share the same orientation. - * @return >0 if planes share the same orientation - */ -MT_Scalar BOP_orientation(const MT_Plane3& p1, const MT_Plane3& p2) -{ - // Dot product between plane normals - return (p1.x()*p2.x() + p1.y()*p2.y() + p1.z()*p2.z()); -} - -/** - * Classifies a point according to the specified plane with EPSILON accuracy. - * @param p point - * @param plane plane - * @return >0 if the point is above (OUT), - * =0 if the point is on (ON), - * <0 if the point is below (IN) - */ -int BOP_classify(const MT_Point3& p, const MT_Plane3& plane) -{ - // Compare plane - point distance with zero - return BOP_comp0(plane.signedDistance(p)); -} - -/** - * Intersects a plane with the line that contains the specified points. - * @param plane split plane - * @param p1 first line point - * @param p2 second line point - * @return intersection between plane and line that contains p1 and p2 - */ -MT_Point3 BOP_intersectPlane(const MT_Plane3& plane, const MT_Point3& p1, const MT_Point3& p2) -{ - // Compute intersection between plane and line ... - // - // L: (p2-p1)lambda + p1 - // - // supposes resolve equation ... - // - // coefA*((p2.x - p1.y)*lambda + p1.x) + ... + coefD = 0 - - MT_Point3 intersection = MT_Point3(0,0,0); //never ever return anything undefined! - MT_Scalar den = plane.x()*(p2.x()-p1.x()) + - plane.y()*(p2.y()-p1.y()) + - plane.z()*(p2.z()-p1.z()); - if (den != 0) { - MT_Scalar lambda = (-plane.x()*p1.x()-plane.y()*p1.y()-plane.z()*p1.z()-plane.w()) / den; - intersection.setValue(p1.x() + (p2.x()-p1.x())*lambda, - p1.y() + (p2.y()-p1.y())*lambda, - p1.z() + (p2.z()-p1.z())*lambda); - return intersection; - } - return intersection; -} - -/** - * Returns if a plane contains a point with EPSILON accuracy. - * @param plane plane - * @param point point - * @return true if the point is on the plane, false otherwise - */ -bool BOP_containsPoint(const MT_Plane3& plane, const MT_Point3& point) -{ - return BOP_fuzzyZero(plane.signedDistance(point)); -} - -/** - * Pre: p0, p1 and p2 is a triangle and q is an interior point. - * @param p0 point - * @param p1 point - * @param p2 point - * @param q point - * @return intersection point I - * v - * (p0)-----(I)----->(p1) - * \ ^ / - * \ |w / - * \ | / - * \ (q) / - * \ | / - * \ | / - * \ | / - * (p2) - * - * v = P1-P2 - * w = P3-Q - * r0(t) = v*t+P1 - * r1(t) = w*t+P3 - * I = r0^r1 - */ -MT_Point3 BOP_4PointIntersect(const MT_Point3& p0, const MT_Point3& p1, const MT_Point3& p2, - const MT_Point3& q) -{ - MT_Vector3 v(p0.x()-p1.x(), p0.y()-p1.y(), p0.z()-p1.z()); - MT_Vector3 w(p2.x()-q.x(), p2.y()-q.y(), p2.z()-q.z()); - MT_Point3 I; - - BOP_intersect(v,p0,w,p2,I); - return I; -} - -/** - * Pre: p0, p1 and q are collinears. - * @param p0 point - * @param p1 point - * @param q point - * @return 0 if q == p0, 1 if q == p1, or a value between 0 and 1 otherwise - * - * (p0)-----(q)------------(p1) - * |<-d1-->| | - * |<---------d0---------->| - * - */ -MT_Scalar BOP_EpsilonDistance(const MT_Point3& p0, const MT_Point3& p1, const MT_Point3& q) -{ - MT_Scalar d0 = p0.distance(p1); - MT_Scalar d1 = p0.distance(q); - MT_Scalar d; - - if (BOP_fuzzyZero(d0)) d = 1.0; - else if (BOP_fuzzyZero(d1)) d = 0.0; - else d = d1 / d0; - return d; -} diff --git a/intern/boolop/intern/BOP_MathUtils.h b/intern/boolop/intern/BOP_MathUtils.h deleted file mode 100644 index 38acd98dd3d..00000000000 --- a/intern/boolop/intern/BOP_MathUtils.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * - * - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Marc Freixas, Ken Hughes - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file boolop/intern/BOP_MathUtils.h - * \ingroup boolopintern - */ - - -#ifndef __BOP_MATHUTILS_H__ -#define __BOP_MATHUTILS_H__ - -#include <math.h> -#include <float.h> -#include "MT_Point3.h" -#include "MT_Plane3.h" - -/* define this to give better precision comparisons */ -#define VAR_EPSILON - -#ifndef VAR_EPSILON -const MT_Scalar BOP_EPSILON(1.0e-5); -#else -const MT_Scalar BOP_EPSILON(9.3132257461547852e-10); /* ~= 2**-30 */ -#endif - -inline int BOP_sign(MT_Scalar x) { - return x < 0.0 ? -1 : x > 0.0 ? 1 : 0; -} -inline MT_Scalar BOP_abs(MT_Scalar x) { return fabs(x); } -int BOP_comp(const MT_Scalar A, const MT_Scalar B); -int BOP_comp(const MT_Tuple3& A, const MT_Tuple3& B); -int BOP_comp0(const MT_Scalar A); -inline bool BOP_fuzzyZero(MT_Scalar x) { return BOP_comp0(x) == 0; } -int BOP_exactComp(const MT_Scalar A, const MT_Scalar B); -int BOP_exactComp(const MT_Tuple3& A, const MT_Tuple3& B); -bool BOP_between(const MT_Point3& p1, const MT_Point3& p2, const MT_Point3& p3); -bool BOP_collinear(const MT_Point3& p1, const MT_Point3& p2, const MT_Point3& p3); -bool BOP_convex(const MT_Point3& p1, const MT_Point3& p2, const MT_Point3& p3, - const MT_Point3& p4); -int BOP_concave(const MT_Point3& p1, const MT_Point3& p2, const MT_Point3& p3, const MT_Point3& p4); -bool BOP_intersect(const MT_Vector3& vL1, const MT_Point3& pL1, const MT_Vector3& vL2, - const MT_Point3& pL2, MT_Point3& intersection); -bool BOP_getCircleCenter(const MT_Point3& p1, const MT_Point3& p2, const MT_Point3& p3, - const MT_Point3& center); -bool BOP_isInsideCircle(const MT_Point3& p1, const MT_Point3& p2, const MT_Point3& p3, - const MT_Point3& p4, const MT_Point3& p5); -bool BOP_isInsideCircle(const MT_Point3& p1, const MT_Point3& p2, const MT_Point3& p3, - const MT_Point3& q); -MT_Scalar BOP_orientation(const MT_Plane3& p1, const MT_Plane3& p2); -int BOP_classify(const MT_Point3& p, const MT_Plane3& plane); -MT_Point3 BOP_intersectPlane(const MT_Plane3& plane, const MT_Point3& p1, const MT_Point3& p2); -bool BOP_containsPoint(const MT_Plane3& plane, const MT_Point3& point); -MT_Point3 BOP_4PointIntersect(const MT_Point3& p0, const MT_Point3& p1, const MT_Point3& p2, - const MT_Point3& q); -MT_Scalar BOP_EpsilonDistance(const MT_Point3& p0, const MT_Point3& p1, const MT_Point3& q); - -#endif diff --git a/intern/boolop/intern/BOP_Merge.cpp b/intern/boolop/intern/BOP_Merge.cpp deleted file mode 100644 index 0baa6e7be67..00000000000 --- a/intern/boolop/intern/BOP_Merge.cpp +++ /dev/null @@ -1,811 +0,0 @@ -/* - * - * - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Marc Freixas, Ken Hughes - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file boolop/intern/BOP_Merge.cpp - * \ingroup boolopintern - */ - - -#include "BOP_Merge.h" - -#ifdef BOP_ORIG_MERGE - -#ifdef _MSC_VER -#if _MSC_VER < 1300 -#include <list> -#endif -#endif - -/** - * SINGLETON (use method BOP_Merge.getInstance). - */ -BOP_Merge BOP_Merge::SINGLETON; - -/** - * Simplifies a mesh, merging its faces. - * @param m mesh - * @param v index of the first mergeable vertex (can be removed by merge) - */ -void BOP_Merge::mergeFaces(BOP_Mesh *m, BOP_Index v) -{ - m_mesh = m; - m_firstVertex = v; - - bool cont = false; - - // Merge faces - mergeFaces(); - - do { - // Add quads ... - cont = createQuads(); - if (cont) { - // ... and merge new faces - cont = mergeFaces(); - } - // ... until the merge is not succesful - } while(cont); -} - -/** - * Simplifies a mesh, merging its faces. - */ -bool BOP_Merge::mergeFaces() -{ - BOP_Indexs mergeVertices; - BOP_Vertexs vertices = m_mesh->getVertexs(); - BOP_IT_Vertexs v = vertices.begin(); - const BOP_IT_Vertexs verticesEnd = vertices.end(); - - // Advance to first mergeable vertex - advance(v,m_firstVertex); - BOP_Index pos = m_firstVertex; - - // Add unbroken vertices to the list - while(v!=verticesEnd) { - if ((*v)->getTAG() != BROKEN) mergeVertices.push_back(pos); - v++;pos++; - } - - // Merge faces with that vertices - return mergeFaces(mergeVertices); -} - - -/** - * Simplifies a mesh, merging the faces with the specified vertices. - * @param mergeVertices vertices to test - * @return true if a face merge was performed - */ -bool BOP_Merge::mergeFaces(BOP_Indexs &mergeVertices) -{ - // Check size > 0! - if (mergeVertices.size() == 0) return false; - - // New faces added by merge - BOP_Faces newFaces; - - // Old faces removed by merge - BOP_Faces oldFaces; - - // Get the first vertex index and add it to - // the current pending vertices to merge - BOP_Index v = mergeVertices[0]; - BOP_Indexs pendingVertices; - pendingVertices.push_back(v); - - // Get faces with index v that come from the same original face - BOP_LFaces facesByOriginalFace; - getFaces(facesByOriginalFace,v); - - bool merged = true; - - // Check it has any unbroken face - if (facesByOriginalFace.size()==0) { - // v has not any unbroken face (so it's a new BROKEN vertex) - (m_mesh->getVertex(v))->setTAG(BROKEN); - merged = false; - } - - // Merge vertex faces - const BOP_IT_LFaces facesEnd = facesByOriginalFace.end(); - - for(BOP_IT_LFaces facesByOriginalFaceX = facesByOriginalFace.begin(); - (facesByOriginalFaceX != facesEnd)&&merged; - facesByOriginalFaceX++) { - merged = mergeFaces((*facesByOriginalFaceX),oldFaces,newFaces,pendingVertices,v); - } - - // Check if the are some pendingVertices to merge - if (pendingVertices.size() > 1 && merged) { - // There are pending vertices that we need to merge in order to merge v ... - for(unsigned int i=1;i<pendingVertices.size() && merged;i++) - merged = mergeFaces(oldFaces,newFaces,pendingVertices,pendingVertices[i]); - } - - // If merge was succesful ... - if (merged) { - // Set old faces to BROKEN... - const BOP_IT_Faces oldFacesEnd = oldFaces.end(); - for(BOP_IT_Faces face=oldFaces.begin();face!=oldFacesEnd;face++) - (*face)->setTAG(BROKEN); - - // ... and add merged faces (that are the new merged faces without pending vertices) - const BOP_IT_Faces newFacesEnd = newFaces.end(); - for(BOP_IT_Faces newFace=newFaces.begin();newFace!=newFacesEnd;newFace++) { - m_mesh->addFace(*newFace); - // Also, add new face vertices to the queue of vertices to merge if they weren't - for(BOP_Index i = 0;i<(*newFace)->size();i++) { - BOP_Index vertexIndex = (*newFace)->getVertex(i); - if (vertexIndex >= m_firstVertex && !containsIndex(mergeVertices,vertexIndex)) - mergeVertices.push_back(vertexIndex); - } - } - // Set the merged vertices to BROKEN ... - const BOP_IT_Indexs pendingEnd = pendingVertices.end(); - for(BOP_IT_Indexs pendingVertex = pendingVertices.begin(); pendingVertex != pendingEnd;pendingVertex++) { - BOP_Index pV = *pendingVertex; - m_mesh->getVertex(pV)->setTAG(BROKEN); - // ... and remove them from mergeVertices queue - const BOP_IT_Indexs mergeEnd = mergeVertices.end(); - for(BOP_IT_Indexs mergeVertex = mergeVertices.begin(); mergeVertex != mergeEnd;mergeVertex++) { - BOP_Index mV = *mergeVertex; - if (mV == pV) { - mergeVertices.erase(mergeVertex); - break; - } - } - } - } - else { - // The merge was not succesful, remove the vertex frome merge vertices queue - mergeVertices.erase(mergeVertices.begin()); - - // free the not used newfaces - const BOP_IT_Faces newFacesEnd = newFaces.end(); - for(BOP_IT_Faces newFace=newFaces.begin();newFace!=newFacesEnd;newFace++) { - delete (*newFace); - } - } - - // Invoke mergeFaces and return the merge result - return (mergeFaces(mergeVertices) || merged); -} - - -/** - * Simplifies a mesh, merging the faces with vertex v that come from the same face. - * @param oldFaces sequence of old mesh faces obtained from the merge - * @param newFaces sequence of new mesh faces obtained from the merge - * @param vertices sequence of indexs (v1 ... vi = v ... vn) where : - * v is the current vertex to test, - * vj (j < i) are tested vertices, - * vk (k >= i) are vertices required to test to merge vj - * (so if a vertex vk can't be merged, the merge is not possible). - * @return true if the vertex v was 'merged' (obviously it could require to test - * some new vertices that will be added to the vertices list) - */ -bool BOP_Merge::mergeFaces(BOP_Faces &oldFaces, BOP_Faces &newFaces, BOP_Indexs &vertices, BOP_Index v) { - - bool merged = true; - - // Get faces with v that come from the same original face, (without the already 'merged' from vertices) - BOP_LFaces facesByOriginalFace; - getFaces(facesByOriginalFace,vertices,v); - - if (facesByOriginalFace.size()==0) { - // All the faces with this vertex were already merged!!! - return true; - } - else { - // Merge faces - const BOP_IT_LFaces facesEnd = facesByOriginalFace.end(); - for(BOP_IT_LFaces facesByOriginalFaceX = facesByOriginalFace.begin(); - (facesByOriginalFaceX != facesEnd)&&merged; - facesByOriginalFaceX++) { - merged = mergeFaces((*facesByOriginalFaceX),oldFaces,newFaces,vertices,v); - } - } - return merged; -} - - -/** - * Merge a set of faces removing the vertex index v. - * @param faces set of faces - * @param oldFaces set of old faces obtained from the merge - * @param newFaces set of new faces obtained from the merge - * @param vertices sequence of indexs (v1 ... vi = v ... vn) where : - * v is the current vertex to test, - * vj (j < i) are tested vertices, - * vk (k >= i) are vertices required to test to merge vj - * (so if a vertex vk can't be merged, the merge is not possible). - * @param v vertex index - * @return true if the merge is succesful, false otherwise - */ -bool BOP_Merge::mergeFaces(BOP_Faces &faces, BOP_Faces &oldFaces, BOP_Faces &newFaces, BOP_Indexs &vertices, BOP_Index v) -{ - - bool merged = false; - - if (faces.size() == 2) { - // Merge a pair of faces into a new face without v - BOP_Face *faceI = faces[0]; - BOP_Face *faceJ = faces[1]; - BOP_Face *faceK = mergeFaces(faceI,faceJ,vertices,v); - if (faceK != NULL) { - newFaces.push_back(faceK); - oldFaces.push_back(faceI); - oldFaces.push_back(faceJ); - merged = true; - } - else merged = false; - } - else if (faces.size() == 4) { - // Merge two pair of faces into a new pair without v - // First we try to perform a simplify merge to avoid more pending vertices - // (for example, if we have two triangles and two quads it will be better - // to do 3+4 and 3+4 than 3+3 and 4+4) - BOP_Face *oldFace1 = faces[0]; - BOP_Face *oldFace2, *newFace1; - unsigned int indexJ = 1; - while (indexJ < faces.size() && !merged) { - oldFace2 = faces[indexJ]; - newFace1 = mergeFaces(oldFace1,oldFace2,v); - if (newFace1 != NULL) merged = true; - else indexJ++; - } - if (merged) { - // Merge the other pair of faces - unsigned int indexK, indexL; - if (indexJ == 1) {indexK = 2;indexL = 3;} - else if (indexJ == 2) {indexK = 1;indexL = 3;} - else {indexK = 1;indexL = 2;} - BOP_Face *oldFace3 = faces[indexK]; - BOP_Face *oldFace4 = faces[indexL]; - unsigned int oldSize = vertices.size(); - BOP_Face *newFace2 = mergeFaces(oldFace3,oldFace4,vertices,v); - if (newFace2 != NULL) { - newFaces.push_back(newFace1); - newFaces.push_back(newFace2); - oldFaces.push_back(oldFace1); - oldFaces.push_back(oldFace2); - oldFaces.push_back(oldFace3); - oldFaces.push_back(oldFace4); - merged = true; - } - else { - // Undo all changes - delete newFace1; - merged = false; - unsigned int count = vertices.size() - oldSize; - if (count != 0) - vertices.erase(vertices.end() - count, vertices.end()); - } - } - if (!merged) { - // Try a complete merge - merged = true; - while (faces.size()>0 && merged) { - indexJ = 1; - BOP_Face *faceI = faces[0]; - merged = false; - while (indexJ < faces.size()) { - BOP_Face *faceJ = faces[indexJ]; - BOP_Face *faceK = mergeFaces(faceI,faceJ,vertices,v); - if (faceK != NULL) { - // faceK = faceI + faceJ and it does not include v! - faces.erase(faces.begin()+indexJ,faces.begin()+(indexJ+1)); - faces.erase(faces.begin(),faces.begin()+1); - newFaces.push_back(faceK); - oldFaces.push_back(faceI); - oldFaces.push_back(faceJ); - merged = true; - break; - } - else indexJ++; - } - } - } - } - else merged = false; // there are N=1 or N=3 or N>4 faces! - - // Return merge result - return merged; -} - -/** - * Returns a new quad from the merge of two faces (one quad and one triangle) - * that share the vertex v and come from the same original face. - * @param faceI mesh face (quad or triangle) with index v - * @param faceJ mesh face (quad or triangle) with index v - * @param v vertex index shared by both faces - * @return if the merge is possible, a new quad without v - */ -BOP_Face* BOP_Merge::mergeFaces(BOP_Face *faceI, BOP_Face *faceJ, BOP_Index v) -{ - if (faceI->size() == 3) { - if (faceJ->size() == 4) - return mergeFaces((BOP_Face4*)faceJ,(BOP_Face3*)faceI,v); - } - else if (faceI->size() == 4) { - if (faceJ->size() == 3) - return mergeFaces((BOP_Face4*)faceI,(BOP_Face3*)faceJ,v); - } - return NULL; -} - -/** - * Returns a new face from the merge of two faces (quads or triangles) that - * share te vertex v and come from the same original face. - * @param faceI mesh face (quad or triangle) with index v - * @param faceJ mesh face (quad or triangle) with index v - * @param pending vector with pending vertices (required to merge two quads into - * a new quad or one quad and one triangle into a new triangle; these merges - * suppose to remove two vertexs, v and its neighbour, that will be a pending - * vertex to merge if it wasn't) - * @param v vertex index shared by both faces - * @return if the merge is possible, a new face without v - */ -BOP_Face* BOP_Merge::mergeFaces(BOP_Face *faceI, BOP_Face *faceJ, BOP_Indexs &pending, BOP_Index v) -{ - if (faceI->size() == 3) { - if (faceJ->size() == 3) - return mergeFaces((BOP_Face3*)faceI,(BOP_Face3*)faceJ,v); - else if (faceJ->size() == 4) - return mergeFaces((BOP_Face4*)faceJ,(BOP_Face3*)faceI,pending,v); - } - else if (faceI->size() == 4) { - if (faceJ->size() == 3) - return mergeFaces((BOP_Face4*)faceI,(BOP_Face3*)faceJ,pending,v); - else if (faceJ->size() == 4) - return mergeFaces((BOP_Face4*)faceI,(BOP_Face4*)faceJ,pending,v); - } - return NULL; -} - -/** - * Returns a new triangle from the merge of two triangles that share the vertex - * v and come from the same original face. - * @param faceI mesh triangle - * @param faceJ mesh triangle - * @param v vertex index shared by both triangles - * @return If the merge is possible, a new triangle without v - */ -BOP_Face* BOP_Merge::mergeFaces(BOP_Face3 *faceI, BOP_Face3 *faceJ, BOP_Index v) -{ - BOP_Face *faceK = NULL; - - // Get faces data - BOP_Index prevI, nextI, prevJ, nextJ; - faceI->getNeighbours(v,prevI,nextI); - faceJ->getNeighbours(v,prevJ,nextJ); - MT_Point3 vertex = m_mesh->getVertex(v)->getPoint(); - MT_Point3 vPrevI = m_mesh->getVertex(prevI)->getPoint(); - MT_Point3 vNextI = m_mesh->getVertex(nextI)->getPoint(); - MT_Point3 vPrevJ = m_mesh->getVertex(prevJ)->getPoint(); - MT_Point3 vNextJ = m_mesh->getVertex(nextJ)->getPoint(); - - // Merge test - if (prevI == nextJ) { - // Both faces share the edge (prevI,v) == (v,nextJ) - if (BOP_between(vertex,vNextI,vPrevJ)) { - faceK = new BOP_Face3(prevI,prevJ,nextI,faceI->getPlane(),faceI->getOriginalFace()); - faceK->setTAG(faceI->getTAG()); - } - } - else if (nextI == prevJ) { - // Both faces share the edge (v,nextI) == (prevJ,v) - if (BOP_between(vertex,vPrevI,vNextJ)) { - faceK = new BOP_Face3(prevI,nextJ,nextI,faceI->getPlane(),faceI->getOriginalFace()); - faceK->setTAG(faceI->getTAG()); - } - } - return faceK; -} - -/** - * Returns a new quad from the merge of one quad and one triangle that share - * the vertex v and come from the same original face. - * @param faceI mesh quad - * @param faceJ mesh triangle - * @param v vertex index shared by both faces - * @return If the merge is possible, a new quad without v - */ -BOP_Face* BOP_Merge::mergeFaces(BOP_Face4 *faceI, BOP_Face3 *faceJ, BOP_Index v) -{ - BOP_Face *faceK = NULL; - - // Get faces data - BOP_Index prevI, nextI, opp, prevJ, nextJ; - faceI->getNeighbours(v,prevI,nextI,opp); - faceJ->getNeighbours(v,prevJ,nextJ); - MT_Point3 vertex = m_mesh->getVertex(v)->getPoint(); - MT_Point3 vOpp = m_mesh->getVertex(opp)->getPoint(); - MT_Point3 vPrevI = m_mesh->getVertex(prevI)->getPoint(); - MT_Point3 vNextI = m_mesh->getVertex(nextI)->getPoint(); - MT_Point3 vPrevJ = m_mesh->getVertex(prevJ)->getPoint(); - MT_Point3 vNextJ = m_mesh->getVertex(nextJ)->getPoint(); - - // Merge test - if (prevI == nextJ) { - if (BOP_between(vertex,vNextI,vPrevJ) && !BOP_collinear(vPrevJ,vPrevI,vOpp) - && BOP_convex(vOpp,vPrevI,vPrevJ,vNextI)) { - faceK = new BOP_Face4(opp,prevI,prevJ,nextI,faceI->getPlane(),faceI->getOriginalFace()); - faceK->setTAG(faceI->getTAG()); - } - } - else if (nextI == prevJ) { - if (BOP_between(vertex,vPrevI,vNextJ) && !BOP_collinear(vNextJ,vNextI,vOpp) - && BOP_convex(vOpp,vPrevI,vNextJ,vNextI)) { - faceK = new BOP_Face4(opp,prevI,nextJ,nextI,faceI->getPlane(),faceI->getOriginalFace()); - faceK->setTAG(faceI->getTAG()); - } - } - return faceK; -} - -/** - * Returns a new face (quad or triangle) from the merge of one quad and one - * triangle that share the vertex v and come from the same original face. - * @param faceI mesh quad - * @param faceJ mesh triangle - * @param pending vector with pending vertices (required to merge one quad - * and one triangle into a new triangle; it supposes to remove two vertexs, - * v and its neighbour, that will be a new pending vertex if it wasn't) - * @param v vertex index shared by both faces - * @return If the merge is possible, a new face without v - */ -BOP_Face* BOP_Merge::mergeFaces(BOP_Face4 *faceI, BOP_Face3 *faceJ, BOP_Indexs &pending, BOP_Index v) -{ - BOP_Face *faceK = NULL; - - // Get faces data - BOP_Index prevI, nextI, opp, prevJ, nextJ; - faceI->getNeighbours(v,prevI,nextI,opp); - faceJ->getNeighbours(v,prevJ,nextJ); - MT_Point3 vertex = m_mesh->getVertex(v)->getPoint(); - MT_Point3 vOpp = m_mesh->getVertex(opp)->getPoint(); - MT_Point3 vPrevI = m_mesh->getVertex(prevI)->getPoint(); - MT_Point3 vNextI = m_mesh->getVertex(nextI)->getPoint(); - MT_Point3 vPrevJ = m_mesh->getVertex(prevJ)->getPoint(); - MT_Point3 vNextJ = m_mesh->getVertex(nextJ)->getPoint(); - - // Merge test - if (prevI == nextJ) { - if (BOP_between(vertex,vNextI,vPrevJ)) { - if (!BOP_collinear(vPrevJ,vPrevI,vOpp) && BOP_convex(vOpp,vPrevI,vPrevJ,vNextI)) { - // The result is a new quad - faceK = new BOP_Face4(opp,prevI,prevJ,nextI,faceI->getPlane(),faceI->getOriginalFace()); - faceK->setTAG(faceI->getTAG()); - } - else if (BOP_between(vPrevI,vPrevJ,vOpp)) { - // The result is a triangle (only if prevI can be merged) - if (prevI < m_firstVertex) return NULL; // It can't be merged - faceK = new BOP_Face3(nextI,opp,prevJ,faceI->getPlane(),faceI->getOriginalFace()); - faceK->setTAG(faceI->getTAG()); - if (!containsIndex(pending, prevI)) pending.push_back(prevI); - } - } - } - else if (nextI == prevJ) { - if (BOP_between(vertex,vPrevI,vNextJ)) { - if (!BOP_collinear(vNextJ,vNextI,vOpp) && BOP_convex(vOpp,vPrevI,vNextJ,vNextI)) { - // The result is a new quad - faceK = new BOP_Face4(opp,prevI,nextJ,nextI,faceI->getPlane(),faceI->getOriginalFace()); - faceK->setTAG(faceI->getTAG()); - } - else if (BOP_between(vNextI,vOpp,vNextJ)) { - // The result is a triangle (only if nextI can be merged) - if (nextI < m_firstVertex) return NULL; - faceK = new BOP_Face3(prevI,nextJ,opp,faceI->getPlane(),faceI->getOriginalFace()); - faceK->setTAG(faceI->getTAG()); - if (!containsIndex(pending, nextI)) pending.push_back(nextI); - } - } - } - return faceK; -} - -/** - * Returns a new quad from the merge of two quads that share - * the vertex v and come from the same original face. - * @param faceI mesh quad - * @param faceJ mesh quad - * @param pending vector with pending vertices (required to merge the two - * quads supposes to remove two vertexs, v and its neighbour, - * that will be a new pending vertex if it wasn't) - * @param v vertex index shared by both quads - * @return If the merge is possible, a new quad without v - */ -BOP_Face* BOP_Merge::mergeFaces(BOP_Face4 *faceI, BOP_Face4 *faceJ, BOP_Indexs &pending, BOP_Index v) -{ - BOP_Face *faceK = NULL; - - // Get faces data - BOP_Index prevI, nextI, oppI, prevJ, nextJ, oppJ; - faceI->getNeighbours(v,prevI,nextI,oppI); - faceJ->getNeighbours(v,prevJ,nextJ,oppJ); - MT_Point3 vertex = m_mesh->getVertex(v)->getPoint(); - MT_Point3 vPrevI = m_mesh->getVertex(prevI)->getPoint(); - MT_Point3 vNextI = m_mesh->getVertex(nextI)->getPoint(); - MT_Point3 vOppI = m_mesh->getVertex(oppI)->getPoint(); - MT_Point3 vPrevJ = m_mesh->getVertex(prevJ)->getPoint(); - MT_Point3 vNextJ = m_mesh->getVertex(nextJ)->getPoint(); - MT_Point3 vOppJ = m_mesh->getVertex(oppJ)->getPoint(); - - // Merge test - if (prevI == nextJ) { - // prevI/nextJ will be a new vertex required to merge - if (prevI < m_firstVertex) return NULL; // It can't be merged - if (BOP_between(vertex,vPrevJ,vNextI) && BOP_between(vNextJ,vOppJ,vOppI)) { - faceK = new BOP_Face4(oppJ,prevJ,nextI,oppI,faceI->getPlane(),faceI->getOriginalFace()); - faceK->setTAG(faceI->getTAG()); - // We add prevI to the pending list if it wasn't yet - if (!containsIndex(pending, prevI)) pending.push_back(prevI); - } - } - else if (nextI == prevJ) { - // nextI/prevJ will be a new vertex required to merge - if (nextI < m_firstVertex) return NULL; // It can't be merged - if (BOP_between(vertex,vPrevI,vNextJ) && BOP_between(vNextI,vOppI,vOppJ)) { - faceK = new BOP_Face4(oppI,prevI,nextJ,oppJ,faceI->getPlane(),faceI->getOriginalFace()); - faceK->setTAG(faceI->getTAG()); - // Add nextI to the pending list if it wasn't yet - if (!containsIndex(pending, nextI)) pending.push_back(nextI); - } - } - return faceK; -} - - -/** - * Simplifies the mesh, merging the pairs of triangles that come frome the - * same original face and define a quad. - * @return true if a quad was added, false otherwise - */ -bool BOP_Merge::createQuads() -{ - - BOP_Faces quads; - - // Get mesh faces - BOP_Faces faces = m_mesh->getFaces(); - - - // Merge mesh triangles - const BOP_IT_Faces facesIEnd = (faces.end()-1); - const BOP_IT_Faces facesJEnd = faces.end(); - for(BOP_IT_Faces faceI=faces.begin();faceI!=facesIEnd;faceI++) { - if ((*faceI)->getTAG() == BROKEN || (*faceI)->size() != 3) continue; - for(BOP_IT_Faces faceJ=(faceI+1);faceJ!=facesJEnd;faceJ++) { - if ((*faceJ)->getTAG() == BROKEN || (*faceJ)->size() != 3 || - (*faceJ)->getOriginalFace() != (*faceI)->getOriginalFace()) continue; - - // Test if both triangles share a vertex index - BOP_Index v; - bool found = false; - for(unsigned int i=0;i<3 && !found;i++) { - v = (*faceI)->getVertex(i); - found = (*faceJ)->containsVertex(v); - - } - if (!found) continue; - - BOP_Face *faceK = createQuad((BOP_Face3*)*faceI,(BOP_Face3*)*faceJ,v); - if (faceK != NULL) { - // Set triangles to BROKEN - (*faceI)->setTAG(BROKEN); - (*faceJ)->setTAG(BROKEN); - quads.push_back(faceK); - break; - } - } - } - - // Add quads to mesh - const BOP_IT_Faces quadsEnd = quads.end(); - for(BOP_IT_Faces quad=quads.begin();quad!=quadsEnd;quad++) m_mesh->addFace(*quad); - return (quads.size() > 0); -} - -/** - * Returns a new quad (convex) from the merge of two triangles that share the - * vertex index v. - * @param faceI mesh triangle - * @param faceJ mesh triangle - * @param v vertex index shared by both triangles - * @return a new convex quad if the merge is possible - */ -BOP_Face* BOP_Merge::createQuad(BOP_Face3 *faceI, BOP_Face3 *faceJ, BOP_Index v) -{ - BOP_Face *faceK = NULL; - - // Get faces data - BOP_Index prevI, nextI, prevJ, nextJ; - faceI->getNeighbours(v,prevI,nextI); - faceJ->getNeighbours(v,prevJ,nextJ); - MT_Point3 vertex = m_mesh->getVertex(v)->getPoint(); - MT_Point3 vPrevI = m_mesh->getVertex(prevI)->getPoint(); - MT_Point3 vNextI = m_mesh->getVertex(nextI)->getPoint(); - MT_Point3 vPrevJ = m_mesh->getVertex(prevJ)->getPoint(); - MT_Point3 vNextJ = m_mesh->getVertex(nextJ)->getPoint(); - - // Quad test - if (prevI == nextJ) { - if (!BOP_collinear(vNextI,vertex,vPrevJ) && !BOP_collinear(vNextI,vPrevI,vPrevJ) && - BOP_convex(vertex,vNextI,vPrevI,vPrevJ)) { - faceK = new BOP_Face4(v,nextI,prevI,prevJ,faceI->getPlane(),faceI->getOriginalFace()); - faceK->setTAG(faceI->getTAG()); - } - } - else if (nextI == prevJ) { - if (!BOP_collinear(vPrevI,vertex,vNextJ) && !BOP_collinear(vPrevI,vNextI,vNextJ) && - BOP_convex(vertex,vNextJ,vNextI,vPrevI)) { - faceK = new BOP_Face4(v,nextJ,nextI,prevI,faceI->getPlane(),faceI->getOriginalFace()); - faceK->setTAG(faceI->getTAG()); - } - } - return faceK; -} - -/** - * Returns if a index is inside a set of indexs. - * @param indexs set of indexs - * @param i index - * @return true if the index is inside the set, false otherwise - */ -bool BOP_Merge::containsIndex(BOP_Indexs indexs, BOP_Index i) -{ - const BOP_IT_Indexs indexsEnd = indexs.end(); - for(BOP_IT_Indexs it=indexs.begin();it!=indexsEnd;it++) { - if (*it == i) return true; - } - return false; -} - -/** - * Creates a list of lists L1, L2, ... LN where - * LX = mesh faces with vertex v that come from the same original face - * @param facesByOriginalFace list of faces lists - * @param v vertex index - */ -void BOP_Merge::getFaces(BOP_LFaces &facesByOriginalFace, BOP_Index v) -{ - // Get edges with vertex v - BOP_Indexs edgeIndexs = m_mesh->getVertex(v)->getEdges(); - const BOP_IT_Indexs edgeEnd = edgeIndexs.end(); - for(BOP_IT_Indexs edgeIndex = edgeIndexs.begin();edgeIndex != edgeEnd;edgeIndex++) { - // Foreach edge, add its no broken faces to the output list - BOP_Edge* edge = m_mesh->getEdge(*edgeIndex); - BOP_Indexs faceIndexs = edge->getFaces(); - const BOP_IT_Indexs faceEnd = faceIndexs.end(); - for(BOP_IT_Indexs faceIndex=faceIndexs.begin();faceIndex!=faceEnd;faceIndex++) { - BOP_Face* face = m_mesh->getFace(*faceIndex); - if (face->getTAG() != BROKEN) { - bool found = false; - // Search if we already have created a list for the - // faces that come from the same original face - const BOP_IT_LFaces lfEnd = facesByOriginalFace.end(); - for(BOP_IT_LFaces facesByOriginalFaceX=facesByOriginalFace.begin(); - facesByOriginalFaceX!=lfEnd; facesByOriginalFaceX++) { - if (((*facesByOriginalFaceX)[0])->getOriginalFace() == face->getOriginalFace()) { - // Search that the face has not been added to the list before - for(unsigned int i = 0;i<(*facesByOriginalFaceX).size();i++) { - if ((*facesByOriginalFaceX)[i] == face) { - found = true; - break; - } - } - if (!found) { - // Add the face to the list - if (face->getTAG()==OVERLAPPED) facesByOriginalFaceX->insert(facesByOriginalFaceX->begin(),face); - else facesByOriginalFaceX->push_back(face); - found = true; - } - break; - } - } - if (!found) { - // Create a new list and add the current face - BOP_Faces facesByOriginalFaceX; - facesByOriginalFaceX.push_back(face); - facesByOriginalFace.push_back(facesByOriginalFaceX); - } - } - } - } -} - -/** - * Creates a list of lists L1, L2, ... LN where - * LX = mesh faces with vertex v that come from the same original face - * and without any of the vertices that appear before v in vertices - * @param facesByOriginalFace list of faces lists - * @param vertices vector with vertices indexs that contains v - * @param v vertex index - */ -void BOP_Merge::getFaces(BOP_LFaces &facesByOriginalFace, BOP_Indexs vertices, BOP_Index v) -{ - // Get edges with vertex v - BOP_Indexs edgeIndexs = m_mesh->getVertex(v)->getEdges(); - const BOP_IT_Indexs edgeEnd = edgeIndexs.end(); - for(BOP_IT_Indexs edgeIndex = edgeIndexs.begin();edgeIndex != edgeEnd;edgeIndex++) { - // Foreach edge, add its no broken faces to the output list - BOP_Edge* edge = m_mesh->getEdge(*edgeIndex); - BOP_Indexs faceIndexs = edge->getFaces(); - const BOP_IT_Indexs faceEnd = faceIndexs.end(); - for(BOP_IT_Indexs faceIndex=faceIndexs.begin();faceIndex!=faceEnd;faceIndex++) { - BOP_Face* face = m_mesh->getFace(*faceIndex); - if (face->getTAG() != BROKEN) { - // Search if the face contains any of the forbidden vertices - bool found = false; - for(BOP_IT_Indexs vertex = vertices.begin();*vertex!= v;vertex++) { - if (face->containsVertex(*vertex)) { - // face contains a forbidden vertex! - found = true; - break; - } - } - if (!found) { - // Search if we already have created a list with the - // faces that come from the same original face - const BOP_IT_LFaces lfEnd = facesByOriginalFace.end(); - for(BOP_IT_LFaces facesByOriginalFaceX=facesByOriginalFace.begin(); - facesByOriginalFaceX!=lfEnd; facesByOriginalFaceX++) { - if (((*facesByOriginalFaceX)[0])->getOriginalFace() == face->getOriginalFace()) { - // Search that the face has not been added to the list before - for(unsigned int i = 0;i<(*facesByOriginalFaceX).size();i++) { - if ((*facesByOriginalFaceX)[i] == face) { - found = true; - break; - } - } - if (!found) { - // Add face to the list - if (face->getTAG()==OVERLAPPED) facesByOriginalFaceX->insert(facesByOriginalFaceX->begin(),face); - else facesByOriginalFaceX->push_back(face); - found = true; - } - break; - } - } - if (!found) { - // Create a new list and add the current face - BOP_Faces facesByOriginalFaceX; - facesByOriginalFaceX.push_back(face); - facesByOriginalFace.push_back(facesByOriginalFaceX); - } - } - } - } - } -} - -#endif /* BOP_ORIG_MERGE */ diff --git a/intern/boolop/intern/BOP_Merge.h b/intern/boolop/intern/BOP_Merge.h deleted file mode 100644 index 9d6d7030ba7..00000000000 --- a/intern/boolop/intern/BOP_Merge.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file boolop/intern/BOP_Merge.h - * \ingroup boolopintern - */ - - -#ifndef __BOP_MERGE_H__ -#define __BOP_MERGE_H__ - -#include "BOP_Misc.h" - -#ifdef BOP_ORIG_MERGE -#include "BOP_Mesh.h" -#include "BOP_Tag.h" -#include "BOP_MathUtils.h" -#include "MEM_SmartPtr.h" - -typedef std::vector< BOP_Faces > BOP_LFaces; -typedef std::vector< BOP_Faces >::iterator BOP_IT_LFaces; - -class BOP_Merge { - private: - BOP_Mesh* m_mesh; - BOP_Index m_firstVertex; - static BOP_Merge SINGLETON; - - BOP_Merge() {}; - bool mergeFaces(); - bool mergeFaces(BOP_Indexs &mergeVertices); - bool mergeFaces(BOP_Faces &oldFaces, BOP_Faces &newFaces, BOP_Indexs &vertices, BOP_Index v); - bool mergeFaces(BOP_Faces &faces, BOP_Faces &oldFaces, BOP_Faces &newFaces, BOP_Indexs &vertices, BOP_Index v); - BOP_Face *mergeFaces(BOP_Face *faceI, BOP_Face *faceJ, BOP_Index v); - BOP_Face *mergeFaces(BOP_Face *faceI, BOP_Face *faceJ, BOP_Indexs &pending, BOP_Index v); - BOP_Face *mergeFaces(BOP_Face3 *faceI, BOP_Face3 *faceJ, BOP_Index v); - BOP_Face *mergeFaces(BOP_Face4 *faceI, BOP_Face3 *faceJ, BOP_Index v); - BOP_Face *mergeFaces(BOP_Face4 *faceI, BOP_Face3 *faceJ, BOP_Indexs &pending, BOP_Index v); - BOP_Face *mergeFaces(BOP_Face4 *faceI, BOP_Face4 *faceJ, BOP_Indexs &pending, BOP_Index v); - bool createQuads(); - BOP_Face *createQuad(BOP_Face3 *faceI, BOP_Face3 *faceJ, BOP_Index v); - bool containsIndex(BOP_Indexs indexs, BOP_Index index); - void getFaces(BOP_LFaces &facesByOriginalFace, BOP_Index v); - void getFaces(BOP_LFaces &facesByOriginalFace, BOP_Indexs vertices, BOP_Index v); - - public: - - static BOP_Merge &getInstance() { - return SINGLETON; - } - - void mergeFaces(BOP_Mesh *m, BOP_Index v); -}; - -#endif /* BOP_ORIG_MERGE */ - -#endif diff --git a/intern/boolop/intern/BOP_Merge2.cpp b/intern/boolop/intern/BOP_Merge2.cpp deleted file mode 100644 index 6bec9ba8222..00000000000 --- a/intern/boolop/intern/BOP_Merge2.cpp +++ /dev/null @@ -1,948 +0,0 @@ -/* - * - * - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Marc Freixas, Ken Hughes - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file boolop/intern/BOP_Merge2.cpp - * \ingroup boolopintern - */ - - -#include "BOP_Merge2.h" - -#ifdef BOP_NEW_MERGE - -static void deleteFace(BOP_Mesh *m, BOP_Face *face); - -/** - * SINGLETON (use method BOP_Merge2.getInstance). - */ -BOP_Merge2 BOP_Merge2::SINGLETON; - -#ifdef BOP_DEBUG -void dumpmesh ( BOP_Mesh *m, bool force ) -{ - unsigned int nonmanifold = 0; - { - BOP_Edges edges = m->getEdges(); - int count = 0; - for (BOP_IT_Edges edge = edges.begin(); edge != edges.end(); - ++count, ++edge) { - if (!(*edge)->getUsed() && (*edge)->getFaces().size() == 0 ) continue; - BOP_Vertex * v1 = m->getVertex((*edge)->getVertex1()); - BOP_Vertex * v2 = m->getVertex((*edge)->getVertex2()); - - if(v1->getTAG()!= BROKEN || v2->getTAG()!= BROKEN ) { - int fcount = 0; - BOP_Indexs faces = (*edge)->getFaces(); - for (BOP_IT_Indexs face = faces.begin(); face != faces.end(); face++) { - BOP_Face *f = m->getFace(*face); - if(f->getTAG()== UNCLASSIFIED) ++fcount; - } - - - if(fcount !=0 && fcount !=2 ) { - ++nonmanifold; - } - } - } - if (!force && nonmanifold == 0) return; - } - if( nonmanifold ) - cout << nonmanifold << " edges detected" << endl; -#ifdef BOP_DEBUG - cout << "---------------------------" << endl; - - BOP_Edges edges = m->getEdges(); - int count = 0; - for (BOP_IT_Edges edge = edges.begin(); edge != edges.end(); - ++count, ++edge) { - BOP_Vertex * v1 = m->getVertex((*edge)->getVertex1()); - BOP_Vertex * v2 = m->getVertex((*edge)->getVertex2()); - - if(v1->getTAG()!= BROKEN || v2->getTAG()!= BROKEN ) { - int fcount = 0; - BOP_Indexs faces = (*edge)->getFaces(); - cout << count << ", " << (*edge) << ", " << faces.size() << endl; - for (BOP_IT_Indexs face = faces.begin(); face != faces.end(); face++) { - BOP_Face *f = m->getFace(*face); - if(f->getTAG()== UNCLASSIFIED) ++fcount; - cout << " face " << f << endl; - } - - - if(fcount !=0 && fcount !=2 ) - cout << " NON-MANIFOLD" << endl; - } - } - - BOP_Faces faces = m->getFaces(); - count = 0; - for (BOP_IT_Faces face = faces.begin(); face != faces.end(); face++) { - if( count < 12*2 || (*face)->getTAG() != BROKEN ) { - cout << count << ", " << *face << endl; - } - ++count; - } - - BOP_Vertexs verts = m->getVertexs(); - count = 0; - for (BOP_IT_Vertexs vert = verts.begin(); vert != verts.end(); vert++) { - cout << count++ << ", " << *vert << " " << (*vert)->getNumEdges() << endl; - BOP_Indexs edges = (*vert)->getEdges(); - for( BOP_IT_Indexs it = edges.begin(); it != edges.end(); ++it) { - BOP_Edge *edge = m->getEdge(*it); - cout << " " << edge << endl; - } - } - cout << "===========================" << endl; -#endif -} -#endif - -/** - * Simplifies a mesh, merging its faces. - * @param m mesh - * @param v index of the first mergeable vertex (can be removed by merge) - */ - -void BOP_Merge2::mergeFaces(BOP_Mesh *m, BOP_Index v) -{ - m_mesh = m; - -#ifdef BOP_DEBUG - cout << "##############################" << endl; -#endif - cleanup( ); - - m_firstVertex = v; - bool cont = false; - - // Merge faces - mergeFaces(); - - do { - // Add quads ... - cont = createQuads(); - // ... and merge new faces - if( cont ) cont = mergeFaces(); - -#ifdef BOP_DEBUG - cout << "called mergeFaces " << cont << endl; -#endif - // ... until the merge is not succesful - } while(cont); -} - -void clean_nonmanifold( BOP_Mesh *m ) -{ - return; - - BOP_Edges nme; - BOP_Edges e = m->getEdges(); - for( BOP_IT_Edges it = e.begin(); it != e.end(); ++it ) { - BOP_Indexs faces = (*it)->getFaces(); - if( faces.size() & ~2 ) - nme.push_back(*it); - } - if (nme.size() == 0) return; - for( BOP_IT_Edges it = nme.begin(); it != nme.end(); ++it ) { - if( (*it)->getFaces().size() > 1 ) { - BOP_Indexs faces = (*it)->getFaces(); - for( BOP_IT_Indexs face = faces.begin(); face != faces.end(); ++face ) { - MT_Point3 vertex1 = m->getVertex(m->getFace(*face)->getVertex(0))->getPoint(); - MT_Point3 vertex2 = m->getVertex(m->getFace(*face)->getVertex(1))->getPoint(); - MT_Point3 vertex3 = m->getVertex(m->getFace(*face)->getVertex(2))->getPoint(); - if (BOP_collinear(vertex1,vertex2,vertex3)) // collinear triangle - deleteFace(m,m->getFace(*face)); - } - continue; - } - BOP_Face *oface1 = m->getFace((*it)->getFaces().front()); - BOP_Face *oface2, *tmpface; - BOP_Index first =(*it)->getVertex1(); - BOP_Index next =(*it)->getVertex2(); - BOP_Index last = first; - unsigned short facecount = 0; - bool found = false; - BOP_Indexs vertList; -#ifdef BOP_DEBUG - cout << " first edge is " << (*it) << endl; -#endif - vertList.push_back(first); - BOP_Edge *edge; - while(true) { - BOP_Vertex *vert = m->getVertex(next); - BOP_Indexs edges = vert->getEdges(); - edge = NULL; - for( BOP_IT_Indexs eit = edges.begin(); eit != edges.end(); ++eit) { - edge = m->getEdge(*eit); - if( edge->getFaces().size() > 1) { - edge = NULL; - continue; - } - if( edge->getVertex1() == next && edge->getVertex2() != last ) { - last = next; - next = edge->getVertex2(); - break; - } - if( edge->getVertex2() == next && edge->getVertex1() != last ) { - last = next; - next = edge->getVertex1(); - break; - } - edge = NULL; - } - if( !edge ) break; -#ifdef BOP_DEBUG - cout << " next edge is " << edge << endl; -#endif - tmpface = m->getFace(edge->getFaces().front()); - if( oface1->getOriginalFace() != tmpface->getOriginalFace() ) - oface2 = tmpface; - else - ++facecount; - vertList.push_back(last); - if( vertList.size() > 3 ) break; - if( next == first ) { - found = true; - break; - } - } - if(found) { - edge = *it; -#ifdef BOP_DEBUG - cout << " --> found a loop" << endl; -#endif - if( vertList.size() == 3 ) { - BOP_Face3 *face = (BOP_Face3 *)m->getFace(edge->getFaces().front()); - face->getNeighbours(first,last,next); - } else if( vertList.size() == 4 ) { - BOP_Face4 *face = (BOP_Face4 *)m->getFace(edge->getFaces().front()); - face->getNeighbours(first,last,next,last); - } else { -#ifdef BOP_DEBUG - cout << "loop has " << vertList.size() << "verts"; -#endif - continue; - } - if(facecount == 1) oface1 = oface2; - next = vertList[1]; - last = vertList[2]; - if( edge->getVertex2() == next ) { - BOP_Face3 *f = new BOP_Face3(next,first,last, - oface1->getPlane(),oface1->getOriginalFace()); - m->addFace( f ); -#ifdef BOP_DEBUG - cout << " face is backward: " << f << endl; -#endif - - } else { - BOP_Face3 *f = new BOP_Face3(last,first,next, - oface1->getPlane(),oface1->getOriginalFace()); - m->addFace( f ); -#ifdef BOP_DEBUG - cout << " face is forward: " << f << endl; -#endif - } - } - } -} - -/** - * Runs through mesh and makes sure vert/face/edge data is consistent. Most - * importantly: - * (1) mark edges which are no longer used - * (2) remove broken faces from edges - * (3) remove faces from mesh which have a single edge belonging to no other - * face (non-manifold edges) - */ - -void BOP_Merge2::cleanup( void ) -{ - BOP_Edges edges = m_mesh->getEdges(); - for (BOP_IT_Edges edge = edges.begin(); edge != edges.end(); ++edge) { - BOP_Indexs faces = (*edge)->getFaces(); - for (BOP_IT_Indexs face = faces.begin(); face != faces.end(); ++face) { - BOP_Face *f = m_mesh->getFace(*face); - if (f->getTAG()== UNCLASSIFIED); - else (*edge)->removeFace(*face); - } - if( (*edge)->getFaces().size() == 0) (*edge)->setUsed(false); - } - - BOP_Vertexs v = m_mesh->getVertexs(); - for( BOP_IT_Vertexs it = v.begin(); it != v.end(); ++it ) { - if( (*it)->getTAG() != BROKEN) { - BOP_Indexs iedges = (*it)->getEdges(); - for(BOP_IT_Indexs i = iedges.begin();i!=iedges.end();i++) - if( m_mesh->getEdge((*i))->getUsed( ) == false) (*it)->removeEdge( *i ); - if( (*it)->getEdges().size() == 0 ) (*it)->setTAG(BROKEN); - } - } - // clean_nonmanifold( m_mesh ); -} - -/** - * Simplifies a mesh, merging its faces. - */ -bool BOP_Merge2::mergeFaces() -{ - BOP_Indexs mergeVertices; - BOP_Vertexs vertices = m_mesh->getVertexs(); - BOP_IT_Vertexs v = vertices.begin(); - const BOP_IT_Vertexs verticesEnd = vertices.end(); - - // Advance to first mergeable vertex - advance(v,m_firstVertex); - BOP_Index pos = m_firstVertex; - - // Add unbroken vertices to the list - while(v!=verticesEnd) { - if ((*v)->getTAG() != BROKEN) { - mergeVertices.push_back(pos); - } - - v++; - pos++; - } - - // Merge faces with that vertices - return mergeFaces(mergeVertices); -} - -/** - * remove edges from vertices when the vertex is removed - */ -void BOP_Merge2::freeVerts(BOP_Index v, BOP_Vertex *vert) -{ - BOP_Indexs edges = vert->getEdges(); - BOP_Vertex *other; - - for( BOP_IT_Indexs it = edges.begin(); it != edges.end(); ++it) { - BOP_Edge *edge = m_mesh->getEdge(*it); - BOP_Indexs edges2; - if( edge->getVertex1() != v ) - other = m_mesh->getVertex( edge->getVertex1() ); - else - other = m_mesh->getVertex( edge->getVertex2() ); - other->removeEdge(*it); - vert->removeEdge(*it); - } -} - -/** - * Simplifies a mesh, merging the faces with the specified vertices. - * @param mergeVertices vertices to test - * @return true if a face merge was performed - */ -bool BOP_Merge2::mergeFaces(BOP_Indexs &mergeVertices) -{ - // Check size > 0! - if (mergeVertices.size() == 0) return false; - bool didMerge = false; - - for( BOP_Index i = 0; i < mergeVertices.size(); ++i ) { - BOP_LFaces facesByOriginalFace; - BOP_Index v = mergeVertices[i]; - BOP_Vertex *vert = m_mesh->getVertex(v); -#ifdef BOP_DEBUG - cout << "i = " << i << ", v = " << v << ", vert = " << vert << endl; - if (v==48) - cout << "found vert 48" << endl; -#endif - if ( vert->getTAG() != BROKEN ) { - getFaces(facesByOriginalFace,v); - - switch (facesByOriginalFace.size()) { - case 0: - // v has no unbroken faces (so it's a new BROKEN vertex) - freeVerts( v, vert ); - vert->setTAG(BROKEN); - break; - case 2: { -#ifdef BOP_DEBUG - cout << "size of fBOF = " << facesByOriginalFace.size() << endl; -#endif - BOP_Faces ff = facesByOriginalFace.front(); - BOP_Faces fb = facesByOriginalFace.back(); - BOP_Index eindexs[2]; - int ecount = 0; - - // look for two edges adjacent to v which contain both ofaces - BOP_Indexs edges = vert->getEdges(); -#ifdef BOP_DEBUG - cout << " ff has " << ff.size() << " faces" << endl; - cout << " fb has " << fb.size() << " faces" << endl; - cout << " v has " << edges.size() << " edges" << endl; -#endif - for(BOP_IT_Indexs it = edges.begin(); it != edges.end(); - ++it ) { - BOP_Edge *edge = m_mesh->getEdge(*it); - BOP_Indexs faces = edge->getFaces(); -#ifdef BOP_DEBUG - cout << " " << edge << " has " << edge->getFaces().size() << " faces" << endl; -#endif - if( faces.size() == 2 ) { - BOP_Face *f0 = m_mesh->getFace(faces[0]); - BOP_Face *f1 = m_mesh->getFace(faces[1]); - if( f0->getOriginalFace() != f1->getOriginalFace() ) { -#ifdef BOP_DEBUG - cout << " " << f0 << endl; - cout << " " << f1 << endl; -#endif - eindexs[ecount++] = (*it); - } - } - } - if(ecount == 2) { -#ifdef BOP_DEBUG - cout << " edge indexes are " << eindexs[0]; - cout << " and " << eindexs[1] << endl; -#endif - BOP_Edge *edge = m_mesh->getEdge(eindexs[0]); - BOP_Index N = edge->getVertex1(); - if(N == v) N = edge->getVertex2(); -#ifdef BOP_DEBUG - cout << " ## OK, replace "<<v<<" with "<<N << endl; -#endif - mergeVertex(ff , v, N ); - mergeVertex(fb , v, N ); -// now remove v and its edges - vert->setTAG(BROKEN); - for(BOP_IT_Indexs it = edges.begin(); it != edges.end(); - ++it ) { - BOP_Edge *tedge = m_mesh->getEdge(*it); - tedge->setUsed(false); - } - didMerge = true; - } -#ifdef BOP_DEBUG - else { - cout << " HUH: ecount was " << ecount << endl; - } -#endif - } - break; - default: - break; - } - } - } - - return didMerge; -} - -void BOP_Merge2::mergeVertex(BOP_Faces &faces, BOP_Index v1, BOP_Index v2) -{ - for(BOP_IT_Faces face=faces.begin();face!=faces.end();face++) { - if( (*face)->size() == 3) - mergeVertex((BOP_Face3 *) *face, v1, v2); - else - mergeVertex((BOP_Face4 *) *face, v1, v2); - (*face)->setTAG(BROKEN); -#ifdef BOP_DEBUG - cout << " breaking " << (*face) << endl; -#endif - } -} - -/* - * Remove a face from the mesh and from each edges's face list - */ - -static void deleteFace(BOP_Mesh *m, BOP_Face *face) -{ - BOP_Index l2 = face->getVertex(0); - BOP_Faces faces = m->getFaces(); - for(int i = face->size(); i-- ; ) { - BOP_Indexs edges = m->getVertex(l2)->getEdges(); - BOP_Index l1 = face->getVertex(i); - for(BOP_IT_Indexs it1 = edges.begin(); it1 != edges.end(); ++it1 ) { - BOP_Edge *edge = m->getEdge(*it1); - if( ( edge->getVertex1() == l1 && edge->getVertex2() == l2 ) || - ( edge->getVertex1() == l2 && edge->getVertex2() == l1 ) ) { - BOP_Indexs ef = edge->getFaces(); - for(BOP_IT_Indexs it = ef.begin(); it != ef.end(); ++it ) { - if( m->getFace(*it) == face) { - edge->removeFace(*it); - break; - } - } - break; - } - } - l2 = l1; - } - face->setTAG(BROKEN); -} - -void BOP_Merge2::mergeVertex(BOP_Face3 *face, BOP_Index v1, BOP_Index v2) -{ - BOP_Index next, prev; - face->getNeighbours(v1,prev,next); - - // if new vertex is not already in the tri, make a new tri - if( prev != v2 && next != v2 ) { - m_mesh->addFace( new BOP_Face3(prev,v2,next, - face->getPlane(),face->getOriginalFace()) ); -#ifdef BOP_DEBUG - cout << "mv3: add " << prev << "," << v2 << "," << next << endl; - } else { - cout << "mv3: vertex already in tri: doing nothing" << endl; -#endif - } - deleteFace(m_mesh, face); -} - -void BOP_Merge2::mergeVertex(BOP_Face4 *face, BOP_Index v1, BOP_Index v2) -{ - BOP_Index next, prev, opp; - face->getNeighbours(v1,prev,next,opp); - - // if new vertex is already in the quad, replace quad with new tri - if( prev == v2 || next == v2 ) { - m_mesh->addFace( new BOP_Face3(prev,next,opp, - face->getPlane(),face->getOriginalFace()) ); -#ifdef BOP_DEBUG - cout << "mv4a: add " << prev << "," << next << "," << opp << endl; -#endif - } - // otherwise make a new quad - else { - m_mesh->addFace( new BOP_Face4(prev,v2,next,opp, - face->getPlane(),face->getOriginalFace()) ); -#ifdef BOP_DEBUG - cout << "mv4b: add "<<prev<<","<<v2<<","<<next<<","<<opp<<endl; -#endif - } - deleteFace(m_mesh, face); -} - -// #define OLD_QUAD - -/** - * Simplifies the mesh, merging the pairs of triangles that come frome the - * same original face and define a quad. - * @return true if a quad was added, false otherwise - */ -bool BOP_Merge2::createQuads() -{ - - BOP_Faces quads; - - // Get mesh faces - BOP_Faces faces = m_mesh->getFaces(); - - // Merge mesh triangles - const BOP_IT_Faces facesIEnd = (faces.end()-1); - const BOP_IT_Faces facesJEnd = faces.end(); - for(BOP_IT_Faces faceI=faces.begin();faceI!=facesIEnd;faceI++) { -#ifdef OLD_QUAD - if ((*faceI)->getTAG() == BROKEN || (*faceI)->size() != 3) continue; - for(BOP_IT_Faces faceJ=(faceI+1);faceJ!=facesJEnd;faceJ++) { - if ((*faceJ)->getTAG() == BROKEN || (*faceJ)->size() != 3 || - (*faceJ)->getOriginalFace() != (*faceI)->getOriginalFace()) continue; - - - BOP_Face *faceK = createQuad((BOP_Face3*)*faceI,(BOP_Face3*)*faceJ); - if (faceK != NULL) { - // Set triangles to BROKEN - deleteFace(m_mesh, *faceI); - deleteFace(m_mesh, *faceJ); -#ifdef BOP_DEBUG - cout << "createQuad: del " << *faceI << endl; - cout << "createQuad: del " << *faceJ << endl; - cout << "createQuad: add " << faceK << endl; -#endif - quads.push_back(faceK); - break; - } - } -#else - if ((*faceI)->getTAG() == BROKEN ) continue; - for(BOP_IT_Faces faceJ=(faceI+1);faceJ!=facesJEnd;faceJ++) { - if ((*faceJ)->getTAG() == BROKEN || - (*faceJ)->getOriginalFace() != (*faceI)->getOriginalFace()) continue; - - BOP_Face *faceK = NULL; - if((*faceI)->size() == 3) { - if((*faceJ)->size() == 3) - faceK = createQuad((BOP_Face3*)*faceI,(BOP_Face3*)*faceJ); - else - faceK = createQuad((BOP_Face3*)*faceI,(BOP_Face4*)*faceJ); - } else { - if((*faceJ)->size() == 3) - faceK = createQuad((BOP_Face3*)*faceJ,(BOP_Face4*)*faceI); - else - faceK = createQuad((BOP_Face4*)*faceI,(BOP_Face4*)*faceJ); - } - - if (faceK != NULL) { - // Set triangles to BROKEN - deleteFace(m_mesh, *faceI); - deleteFace(m_mesh, *faceJ); -#ifdef BOP_DEBUG - cout << "createQuad: del " << *faceI << endl; - cout << "createQuad: del " << *faceJ << endl; - cout << "createQuad: add " << faceK << endl; -#endif - quads.push_back(faceK); - break; - } - } -#endif - } - - // Add quads to mesh - const BOP_IT_Faces quadsEnd = quads.end(); - for(BOP_IT_Faces quad=quads.begin();quad!=quadsEnd;quad++) m_mesh->addFace(*quad); - return (quads.size() > 0); -} - -/** - * Returns a new quad (convex) from the merge of two triangles that share the - * vertex index v. - * @param faceI mesh triangle - * @param faceJ mesh triangle - * @param v vertex index shared by both triangles - * @return a new convex quad if the merge is possible - */ -BOP_Face* BOP_Merge2::createQuad(BOP_Face3 *faceI, BOP_Face3 *faceJ) -{ - // Test if both triangles share a vertex index - BOP_Index v; - unsigned int i; - for(i=0;i<3 ;i++) { - v = faceI->getVertex(i); - if( faceJ->containsVertex(v) ) break; - } - if (i == 3) return NULL; - - BOP_Face *faceK = NULL; - - // Get faces data - BOP_Index prevI, nextI, prevJ, nextJ; - faceI->getNeighbours(v,prevI,nextI); - faceJ->getNeighbours(v,prevJ,nextJ); - MT_Point3 vertex = m_mesh->getVertex(v)->getPoint(); - MT_Point3 vPrevI = m_mesh->getVertex(prevI)->getPoint(); - MT_Point3 vNextI = m_mesh->getVertex(nextI)->getPoint(); - MT_Point3 vPrevJ = m_mesh->getVertex(prevJ)->getPoint(); - MT_Point3 vNextJ = m_mesh->getVertex(nextJ)->getPoint(); - - // Quad test - if (prevI == nextJ) { - if (!BOP_collinear(vNextI,vertex,vPrevJ) && !BOP_collinear(vNextI,vPrevI,vPrevJ) && - BOP_convex(vertex,vNextI,vPrevI,vPrevJ)) { - faceK = new BOP_Face4(v,nextI,prevI,prevJ,faceI->getPlane(),faceI->getOriginalFace()); - faceK->setTAG(faceI->getTAG()); - BOP_Index edge; - m_mesh->getIndexEdge(v,prevI,edge); - m_mesh->getVertex(v)->removeEdge(edge); - m_mesh->getVertex(prevI)->removeEdge(edge); - } - } - else if (nextI == prevJ) { - if (!BOP_collinear(vPrevI,vertex,vNextJ) && !BOP_collinear(vPrevI,vNextI,vNextJ) && - BOP_convex(vertex,vNextJ,vNextI,vPrevI)) { - faceK = new BOP_Face4(v,nextJ,nextI,prevI,faceI->getPlane(),faceI->getOriginalFace()); - faceK->setTAG(faceI->getTAG()); - BOP_Index edge; - m_mesh->getIndexEdge(v,nextI,edge); - m_mesh->getVertex(v)->removeEdge(edge); - m_mesh->getVertex(nextI)->removeEdge(edge); - } - } - return faceK; -} - -/** - * Returns a new quad (convex) from the merge of two triangles that share the - * vertex index v. - * @param faceI mesh triangle - * @param faceJ mesh triangle - * @param v vertex index shared by both triangles - * @return a new convex quad if the merge is possible - */ -BOP_Face* BOP_Merge2::createQuad(BOP_Face3 *faceI, BOP_Face4 *faceJ) -{ - // Test if triangle and quad share a vertex index - BOP_Index v; - unsigned int i; - for(i=0;i<3 ;i++) { - v = faceI->getVertex(i); - if( faceJ->containsVertex(v) ) break; - } - if (i == 3) return NULL; - - BOP_Face *faceK = NULL; - - // Get faces data - BOP_Index prevI, nextI, prevJ, nextJ, oppJ; - faceI->getNeighbours(v,prevI,nextI); - faceJ->getNeighbours(v,prevJ,nextJ,oppJ); - - // Quad test - BOP_Index edge; - if (nextI == prevJ) { - if (prevI == nextJ) { // v is in center - faceK = new BOP_Face3(nextJ,oppJ,prevJ,faceI->getPlane(),faceI->getOriginalFace()); - faceK->setTAG(faceI->getTAG()); - m_mesh->getIndexEdge(v,prevI,edge); - m_mesh->getVertex(v)->removeEdge(edge); - m_mesh->getVertex(prevI)->removeEdge(edge); - m_mesh->getIndexEdge(v,nextI,edge); - m_mesh->getVertex(v)->removeEdge(edge); - m_mesh->getVertex(nextI)->removeEdge(edge); - freeVerts(v, m_mesh->getVertex(v)); - } else if (prevI == oppJ) { // nextI is in center - faceK = new BOP_Face3(v,nextJ,oppJ,faceI->getPlane(),faceI->getOriginalFace()); - faceK->setTAG(faceI->getTAG()); - m_mesh->getIndexEdge(v,nextI,edge); - m_mesh->getVertex(v)->removeEdge(edge); - m_mesh->getVertex(nextI)->removeEdge(edge); - m_mesh->getIndexEdge(prevI,nextI,edge); - m_mesh->getVertex(prevI)->removeEdge(edge); - m_mesh->getVertex(nextI)->removeEdge(edge); - freeVerts(nextI, m_mesh->getVertex(nextI)); - } - } else if (nextI == oppJ && prevI == nextJ ) { // prevI is in center - faceK = new BOP_Face3(prevJ,v,oppJ,faceI->getPlane(),faceI->getOriginalFace()); - faceK->setTAG(faceI->getTAG()); - m_mesh->getIndexEdge(v,prevI,edge); - m_mesh->getVertex(v)->removeEdge(edge); - m_mesh->getVertex(prevI)->removeEdge(edge); - m_mesh->getIndexEdge(nextI,prevI,edge); - m_mesh->getVertex(nextI)->removeEdge(edge); - m_mesh->getVertex(prevI)->removeEdge(edge); - freeVerts(prevI, m_mesh->getVertex(prevI)); - } - return faceK; -} - -/** - * Returns a new quad (convex) from the merge of two triangles that share the - * vertex index v. - * @param faceI mesh triangle - * @param faceJ mesh triangle - * @param v vertex index shared by both triangles - * @return a new convex quad if the merge is possible - */ -BOP_Face* BOP_Merge2::createQuad(BOP_Face4 *faceI, BOP_Face4 *faceJ) -{ - BOP_Face *faceK = NULL; - // - // Test if both quads share a vertex index - // - BOP_Index v; - unsigned int i; - for(i=0;i<4 ;i++) { - v = faceI->getVertex(i); - if( faceJ->containsVertex(v) ) break; - } - if (i == 3) return NULL; - - - // Get faces data - BOP_Index prevI, nextI, oppI, prevJ, nextJ, oppJ; - faceI->getNeighbours(v,prevI,nextI,oppI); - faceJ->getNeighbours(v,prevJ,nextJ,oppJ); - - // Quad test - BOP_Index edge; - if (nextI == prevJ) { - if (prevI == nextJ) { // v is in center - faceK = new BOP_Face4(nextI,oppI,nextJ,oppJ,faceI->getPlane(),faceI->getOriginalFace()); - faceK->setTAG(faceI->getTAG()); - m_mesh->getIndexEdge(v,prevI,edge); - m_mesh->getVertex(v)->removeEdge(edge); - m_mesh->getVertex(prevI)->removeEdge(edge); - m_mesh->getIndexEdge(v,nextI,edge); - m_mesh->getVertex(v)->removeEdge(edge); - m_mesh->getVertex(nextI)->removeEdge(edge); - freeVerts(v, m_mesh->getVertex(v)); - } else if (oppI == oppJ) { // nextI is in center - faceK = new BOP_Face4(v,nextJ,oppJ,prevI,faceI->getPlane(),faceI->getOriginalFace()); - faceK->setTAG(faceI->getTAG()); - m_mesh->getIndexEdge(v,nextI,edge); - m_mesh->getVertex(v)->removeEdge(edge); - m_mesh->getVertex(nextI)->removeEdge(edge); - m_mesh->getIndexEdge(prevI,nextI,edge); - m_mesh->getVertex(prevI)->removeEdge(edge); - m_mesh->getVertex(nextI)->removeEdge(edge); - freeVerts(nextI, m_mesh->getVertex(nextI)); - } - } else if (prevI == nextJ && oppI == oppJ) { // prevI is in center - faceK = new BOP_Face4(v,nextI,oppJ,prevJ,faceI->getPlane(),faceI->getOriginalFace()); - faceK->setTAG(faceI->getTAG()); - m_mesh->getIndexEdge(v,prevI,edge); - m_mesh->getVertex(v)->removeEdge(edge); - m_mesh->getVertex(prevI)->removeEdge(edge); - m_mesh->getIndexEdge(nextI,prevI,edge); - m_mesh->getVertex(nextI)->removeEdge(edge); - m_mesh->getVertex(prevI)->removeEdge(edge); - freeVerts(prevI, m_mesh->getVertex(prevI)); - } - return faceK; -} - -/** - * Returns if a index is inside a set of indexs. - * @param indexs set of indexs - * @param i index - * @return true if the index is inside the set, false otherwise - */ -bool BOP_Merge2::containsIndex(BOP_Indexs indexs, BOP_Index i) -{ - const BOP_IT_Indexs indexsEnd = indexs.end(); - for(BOP_IT_Indexs it=indexs.begin();it!=indexsEnd;it++) { - if (*it == i) return true; - } - return false; -} - -/** - * Creates a list of lists L1, L2, ... LN where - * LX = mesh faces with vertex v that come from the same original face - * @param facesByOriginalFace list of faces lists - * @param v vertex index - */ -void BOP_Merge2::getFaces(BOP_LFaces &facesByOriginalFace, BOP_Index v) -{ - // Get edges with vertex v - - BOP_Indexs edgeIndexs = m_mesh->getVertex(v)->getEdges(); - const BOP_IT_Indexs edgeEnd = edgeIndexs.end(); - for(BOP_IT_Indexs edgeIndex = edgeIndexs.begin();edgeIndex != edgeEnd;edgeIndex++) { - // For each edge, add its no broken faces to the output list - BOP_Edge* edge = m_mesh->getEdge(*edgeIndex); - BOP_Indexs faceIndexs = edge->getFaces(); - const BOP_IT_Indexs faceEnd = faceIndexs.end(); - for(BOP_IT_Indexs faceIndex=faceIndexs.begin();faceIndex!=faceEnd;faceIndex++) { - BOP_Face* face = m_mesh->getFace(*faceIndex); - if (face->getTAG() != BROKEN) { - bool found = false; - // Search if we already have created a list for the - // faces that come from the same original face - const BOP_IT_LFaces lfEnd = facesByOriginalFace.end(); - for(BOP_IT_LFaces facesByOriginalFaceX=facesByOriginalFace.begin(); - facesByOriginalFaceX!=lfEnd; facesByOriginalFaceX++) { - if (((*facesByOriginalFaceX)[0])->getOriginalFace() == face->getOriginalFace()) { - // Search that the face has not been added to the list before - for(unsigned int i = 0;i<(*facesByOriginalFaceX).size();i++) { - if ((*facesByOriginalFaceX)[i] == face) { - found = true; - break; - } - } - if (!found) { - // Add the face to the list - if (face->getTAG()==OVERLAPPED) facesByOriginalFaceX->insert(facesByOriginalFaceX->begin(),face); - else facesByOriginalFaceX->push_back(face); - found = true; - } - break; - } - } - if (!found) { - // Create a new list and add the current face - BOP_Faces facesByOriginalFaceX; - facesByOriginalFaceX.push_back(face); - facesByOriginalFace.push_back(facesByOriginalFaceX); - } - } - } - } -} - -/** - * Creates a list of lists L1, L2, ... LN where - * LX = mesh faces with vertex v that come from the same original face - * and without any of the vertices that appear before v in vertices - * @param facesByOriginalFace list of faces lists - * @param vertices vector with vertices indexs that contains v - * @param v vertex index - */ -void BOP_Merge2::getFaces(BOP_LFaces &facesByOriginalFace, BOP_Indexs vertices, BOP_Index v) -{ - // Get edges with vertex v - BOP_Indexs edgeIndexs = m_mesh->getVertex(v)->getEdges(); - const BOP_IT_Indexs edgeEnd = edgeIndexs.end(); - for(BOP_IT_Indexs edgeIndex = edgeIndexs.begin();edgeIndex != edgeEnd;edgeIndex++) { - // Foreach edge, add its no broken faces to the output list - BOP_Edge* edge = m_mesh->getEdge(*edgeIndex); - BOP_Indexs faceIndexs = edge->getFaces(); - const BOP_IT_Indexs faceEnd = faceIndexs.end(); - for(BOP_IT_Indexs faceIndex=faceIndexs.begin();faceIndex!=faceEnd;faceIndex++) { - BOP_Face* face = m_mesh->getFace(*faceIndex); - if (face->getTAG() != BROKEN) { - // Search if the face contains any of the forbidden vertices - bool found = false; - for(BOP_IT_Indexs vertex = vertices.begin();*vertex!= v;vertex++) { - if (face->containsVertex(*vertex)) { - // face contains a forbidden vertex! - found = true; - break; - } - } - if (!found) { - // Search if we already have created a list with the - // faces that come from the same original face - const BOP_IT_LFaces lfEnd = facesByOriginalFace.end(); - for(BOP_IT_LFaces facesByOriginalFaceX=facesByOriginalFace.begin(); - facesByOriginalFaceX!=lfEnd; facesByOriginalFaceX++) { - if (((*facesByOriginalFaceX)[0])->getOriginalFace() == face->getOriginalFace()) { - // Search that the face has not been added to the list before - for(unsigned int i = 0;i<(*facesByOriginalFaceX).size();i++) { - if ((*facesByOriginalFaceX)[i] == face) { - found = true; - break; - } - } - if (!found) { - // Add face to the list - if (face->getTAG()==OVERLAPPED) facesByOriginalFaceX->insert(facesByOriginalFaceX->begin(),face); - else facesByOriginalFaceX->push_back(face); - found = true; - } - break; - } - } - if (!found) { - // Create a new list and add the current face - BOP_Faces facesByOriginalFaceX; - facesByOriginalFaceX.push_back(face); - facesByOriginalFace.push_back(facesByOriginalFaceX); - } - } - } - } - } -} - -#endif /* BOP_NEW_MERGE */ diff --git a/intern/boolop/intern/BOP_Merge2.h b/intern/boolop/intern/BOP_Merge2.h deleted file mode 100644 index 71ec0702a0b..00000000000 --- a/intern/boolop/intern/BOP_Merge2.h +++ /dev/null @@ -1,104 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file boolop/intern/BOP_Merge2.h - * \ingroup boolopintern - */ - - -#ifndef __BOP_MERGE2_H__ -#define __BOP_MERGE2_H__ - -#include "BOP_Misc.h" - -#ifdef BOP_NEW_MERGE - -#include "BOP_Mesh.h" -#include "BOP_Tag.h" -#include "BOP_MathUtils.h" -#include "MEM_SmartPtr.h" - -typedef std::vector< BOP_Faces > BOP_LFaces; -typedef std::vector< BOP_Faces >::iterator BOP_IT_LFaces; - -class BOP_Merge2 { - private: - BOP_Mesh* m_mesh; - BOP_Index m_firstVertex; - static BOP_Merge2 SINGLETON; - - BOP_Merge2() {}; - bool mergeFaces(); - bool mergeFaces(BOP_Indexs &mergeVertices); - bool mergeFaces(BOP_Faces &oldFaces, BOP_Faces &newFaces, BOP_Indexs &vertices, BOP_Index v); - bool mergeFaces(BOP_Faces &faces, BOP_Faces &oldFaces, BOP_Faces &newFaces, BOP_Indexs &vertices, BOP_Index v); - BOP_Face *mergeFaces(BOP_Face *faceI, BOP_Face *faceJ, BOP_Index v); - BOP_Face *mergeFaces(BOP_Face *faceI, BOP_Face *faceJ, BOP_Indexs &pending, BOP_Index v); - BOP_Face *mergeFaces(BOP_Face3 *faceI, BOP_Face3 *faceJ, BOP_Index v); - BOP_Face *mergeFaces(BOP_Face4 *faceI, BOP_Face3 *faceJ, BOP_Index v); - BOP_Face *mergeFaces(BOP_Face4 *faceI, BOP_Face3 *faceJ, BOP_Indexs &pending, BOP_Index v); - BOP_Face *mergeFaces(BOP_Face4 *faceI, BOP_Face4 *faceJ, BOP_Indexs &pending, BOP_Index v); - bool createQuads(); - bool containsIndex(BOP_Indexs indexs, BOP_Index index); - void getFaces(BOP_LFaces &facesByOriginalFace, BOP_Index v); - void getFaces(BOP_LFaces &facesByOriginalFace, BOP_Indexs vertices, BOP_Index v); - BOP_Face *createQuad(BOP_Face3 *faceI, BOP_Face3 *faceJ); - BOP_Face *createQuad(BOP_Face3 *faceI, BOP_Face4 *faceJ); - BOP_Face *createQuad(BOP_Face4 *faceI, BOP_Face4 *faceJ); - - bool mergeVertex(BOP_Face *faceI, BOP_Face *faceJ, BOP_Index v, - BOP_Indexs &mergeVertices); - bool mergeVertex(BOP_Face *faceI, BOP_Face *faceJ, BOP_Index v, - BOP_Indexs &pending, BOP_Faces &oldFaces, BOP_Faces &newFaces ); - BOP_Face *find3Neighbor(BOP_Face *faceI, BOP_Face *faceJ, - BOP_Index X, BOP_Index I, BOP_Index P, BOP_Index N ); - BOP_Face *find4Neighbor(BOP_Face *faceI, BOP_Face *faceJ, - BOP_Index X, BOP_Index I, BOP_Index P, BOP_Index N, - BOP_Face **faceL, BOP_Index &O); - BOP_Face3 *collapse(BOP_Face4 *faceC, BOP_Index X); - void mergeFaces(BOP_Face *A, BOP_Face *B, BOP_Index X, - BOP_Index I, BOP_Index N, BOP_Index P, BOP_Faces &newFaces ); - void freeVerts(BOP_Index v, BOP_Vertex *vert); - - void mergeVertex(BOP_Faces&, BOP_Index, BOP_Index); - void mergeVertex(BOP_Face3 *, BOP_Index, BOP_Index); - void mergeVertex(BOP_Face4 *, BOP_Index, BOP_Index); - void cleanup( void ); - - public: - - static BOP_Merge2 &getInstance() { - return SINGLETON; - } - - void mergeFaces(BOP_Mesh *m, BOP_Index v); -}; - -void dumpmesh(BOP_Mesh *, bool); - -#endif /* BOP_NEW_MERGE2 */ -#endif diff --git a/intern/boolop/intern/BOP_Mesh.cpp b/intern/boolop/intern/BOP_Mesh.cpp deleted file mode 100644 index 673caa3e921..00000000000 --- a/intern/boolop/intern/BOP_Mesh.cpp +++ /dev/null @@ -1,1090 +0,0 @@ -/* - * - * - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file boolop/intern/BOP_Mesh.cpp - * \ingroup boolopintern - */ - - -#include "BOP_Mesh.h" -#include "BOP_MathUtils.h" -#include <iostream> -#include <fstream> - -#include "MEM_guardedalloc.h" -#include "BLI_blenlib.h" - -BOP_Mesh::BOP_Mesh() -{ -#ifdef HASH -#ifdef HASH_PRINTF_DEBUG - printf ("has hashing\n"); -#endif - hash = NULL; - hashsize = 0; -#endif -} - -/** - * Destroys a mesh. - */ -BOP_Mesh::~BOP_Mesh() -{ - const BOP_IT_Vertexs vertexsEnd = m_vertexs.end(); - for(BOP_IT_Vertexs itv=m_vertexs.begin();itv!=vertexsEnd;itv++){ - delete *itv; - } - m_vertexs.clear(); - - const BOP_IT_Edges edgesEnd = m_edges.end(); - for(BOP_IT_Edges ite=m_edges.begin();ite!=edgesEnd;ite++){ - delete *ite; - } - m_edges.clear(); - - const BOP_IT_Faces facesEnd = m_faces.end(); - for(BOP_IT_Faces itf=m_faces.begin();itf!=facesEnd;itf++){ - delete *itf; - } - m_faces.clear(); - -#ifdef HASH - while( hashsize ) { - --hashsize; - BLI_freelistN( &hash[hashsize] ); - } - MEM_freeN( hash ); - hash = NULL; -#endif -} - -/** - * Adds a new vertex. - * @param p vertex point - * @return mesh vertex index - */ -BOP_Index BOP_Mesh::addVertex(MT_Point3 p) -{ - m_vertexs.push_back(new BOP_Vertex(p)); - return m_vertexs.size()-1; -} - -/** - * Adds a new edge. - * @param v1 mesh vertex index - * @param v2 mesh vertex index - * @return mesh edge index - */ -BOP_Index BOP_Mesh::addEdge(BOP_Index v1, BOP_Index v2) -{ -#ifdef HASH - /* prepare a new hash entry for the edge */ - int minv; - EdgeEntry *h = (EdgeEntry *)MEM_callocN( sizeof( EdgeEntry ), "edgehash" ); - - /* store sorted, smallest vert first */ - if( v1 < v2 ) { - minv = HASH(v1); - h->v1 = v1; - h->v2 = v2; - } else { - minv = HASH(v2); - h->v1 = v2; - h->v2 = v1; - } - h->index = m_edges.size(); - - /* if hash index larger than hash list, extend the list */ - if( minv >= hashsize ) { - int newsize = (minv + 8) & ~7; - ListBase *nhash = (ListBase *)MEM_mallocN( - newsize * sizeof( ListBase ), - "edgehashtable" ); - /* copy old entries */ - memcpy( nhash, hash, sizeof( ListBase ) * hashsize ); - /* clear new ones */ - while( hashsize < newsize ) { - nhash[hashsize].first = nhash[hashsize].last = NULL; - ++hashsize; - } - if( hash ) - MEM_freeN( hash ); - hash = nhash; - } - - /* add the entry to tail of the right hash list */ - BLI_addtail( &hash[minv], h ); -#endif - m_edges.push_back(new BOP_Edge(v1,v2)); - return m_edges.size()-1; -} - -#ifdef HASH -/** - * replace one vertex with another in the hash list - * @param o old mesh vertex index - * @param n new mesh vertex index - * @param x edge's other mesh vertex index - */ -void BOP_Mesh::rehashVertex(BOP_Index o, BOP_Index n, BOP_Index x) -{ - EdgeEntry *edge; - int minv = HASH(o); - BOP_Index v1, v2; - - /* figure out where and what to look for */ - if( o < x ) { - minv = HASH(o); - v1 = o; v2 = x; - } else { - minv = HASH(x); - v1 = x; v2 = o; - } - - /* if hash is valid, search for the match */ - if( minv < hashsize ) { - for(edge = (EdgeEntry *)hash[minv].first; - edge; edge = edge->next ) { - if(edge->v1 == v1 && edge->v2 == v2) - break; - } - - /* NULL edge == no match */ - if(!edge) { -#ifdef HASH_PRINTF_DEBUG - printf ("OOPS! didn't find edge (%d %d)\n",v1,v2); -#endif - return; - } -#ifdef HASH_PRINTF_DEBUG - printf ("found edge (%d %d)\n",v1,v2); -#endif - /* remove the edge from the old hash list */ - BLI_remlink( &hash[minv], edge ); - - /* decide where the new edge should go */ - if( n < x ) { - minv = HASH(n); - v1 = n; v2 = x; - } else { - minv = HASH(x); - edge->v1 = x; edge->v2 = n; - } - - /* if necessary, extend the hash list */ - if( minv >= hashsize ) { -#ifdef HASH_PRINTF_DEBUG - printf ("OOPS! new vertex too large! (%d->%d)\n",o,n); -#endif - int newsize = (minv + 8) & ~7; - ListBase *nhash = (ListBase *)MEM_mallocN( - newsize * sizeof( ListBase ), - "edgehashtable" ); - memcpy( nhash, hash, sizeof( ListBase ) * hashsize ); - while( hashsize < newsize ) { - nhash[hashsize].first = nhash[hashsize].last = NULL; - ++hashsize; - } - if( hash ) - MEM_freeN( hash ); - hash = nhash; - } - - /* add the entry to tail of the right hash list */ - BLI_addtail( &hash[minv], edge ); - } else { -#ifdef HASH_PRINTF_DEBUG - printf ("OOPS! hash not large enough for (%d %d)\n",minv,hashsize); -#endif - } -} -#endif - -/** - * Adds a new face. - * @param face mesh face - * @return mesh face index - */ -BOP_Index BOP_Mesh::addFace(BOP_Face *face) -{ - if (face->size()==3) - return addFace((BOP_Face3 *)face); - else - return addFace((BOP_Face4 *)face); -} - -/** - * Adds a new triangle. - * @param face mesh triangle - * @return mesh face index - */ -BOP_Index BOP_Mesh::addFace(BOP_Face3 *face) -{ - BOP_Index indexface = m_faces.size(); - - BOP_Index index1 = face->getVertex(0); - BOP_Index index2 = face->getVertex(1); - BOP_Index index3 = face->getVertex(2); - - m_faces.push_back((BOP_Face *)face); - - BOP_Index edge; - - if (!getIndexEdge(index1,index2,edge)) { - edge = addEdge(index1,index2); - getVertex(index1)->addEdge(edge); - getVertex(index2)->addEdge(edge); - } - - getEdge(edge)->addFace(indexface); - - if (!getIndexEdge(index2,index3,edge)) { - edge = addEdge(index2,index3); - getVertex(index2)->addEdge(edge); - getVertex(index3)->addEdge(edge); - } - - getEdge(edge)->addFace(indexface); - - if (!getIndexEdge(index3,index1,edge)) { - edge = addEdge(index3,index1); - getVertex(index3)->addEdge(edge); - getVertex(index1)->addEdge(edge); - } - - getEdge(edge)->addFace(indexface); - - if ((index1 == index2) || (index1 == index3) || (index2 == index3)) - face->setTAG(BROKEN); - - return indexface; -} - -/** - * Adds a new quad. - * @param face mesh quad - * @return mesh face index - */ -BOP_Index BOP_Mesh::addFace(BOP_Face4 *face) -{ - m_faces.push_back((BOP_Face *)face); - BOP_Index indexface = m_faces.size()-1; - - BOP_Index index1 = face->getVertex(0); - BOP_Index index2 = face->getVertex(1); - BOP_Index index3 = face->getVertex(2); - BOP_Index index4 = face->getVertex(3); - - BOP_Index edge; - - if (!getIndexEdge(index1,index2,edge)) { - edge = addEdge(index1,index2); - getVertex(index1)->addEdge(edge); - getVertex(index2)->addEdge(edge); - } - - getEdge(edge)->addFace(indexface); - - if (!getIndexEdge(index2,index3,edge)) { - edge = addEdge(index2,index3); - getVertex(index2)->addEdge(edge); - getVertex(index3)->addEdge(edge); - } - - getEdge(edge)->addFace(indexface); - - if (!getIndexEdge(index3,index4,edge)) { - edge = addEdge(index3,index4); - getVertex(index3)->addEdge(edge); - getVertex(index4)->addEdge(edge); - } - - getEdge(edge)->addFace(indexface); - - if (!getIndexEdge(index4,index1,edge)) { - edge = addEdge(index4,index1); - getVertex(index4)->addEdge(edge); - getVertex(index1)->addEdge(edge); - } - - getEdge(edge)->addFace(indexface); - - if ((index1 == index2) || (index1 == index3) || (index1 == index4) || - (index2 == index3) || (index2 == index4) || (index3 == index4)) - face->setTAG(BROKEN); - - return m_faces.size()-1; -} - -/** - * Returns if a faces set contains the specified face. - * @param faces faces set - * @param face face - * @return true if the set contains the specified face - */ -bool BOP_Mesh::containsFace(BOP_Faces *faces, BOP_Face *face) -{ - const BOP_IT_Faces facesEnd = faces->end(); - for(BOP_IT_Faces it = faces->begin();it!=facesEnd;it++) { - if (face == *it) - return true; - } - - return false; -} -/** - * Returns the first edge with the specified vertex index from a list of edge indexs. - * @param edges edge indexs - * @param v vertex index - * @return first edge with the specified vertex index, NULL otherwise - */ -BOP_Edge* BOP_Mesh::getEdge(BOP_Indexs edges, BOP_Index v) -{ - const BOP_IT_Indexs edgesEnd = edges.end(); - for(BOP_IT_Indexs it=edges.begin();it!=edgesEnd;it++){ - BOP_Edge *edge = m_edges[*it]; - if ((edge->getVertex1() == v) || (edge->getVertex2() == v)) - return edge; - } - return NULL; -} - -/** - * Returns the mesh edge with the specified vertex indexs. - * @param v1 vertex index - * @param v2 vertex index - * @return mesh edge with the specified vertex indexs, NULL otherwise - */ -BOP_Edge* BOP_Mesh::getEdge(BOP_Index v1, BOP_Index v2) -{ -#ifdef HASH - int minv; - EdgeEntry *edge; - - /* figure out where and what to search for */ - if( v1 < v2 ) { - minv = HASH(v1); - } else { - minv = HASH(v2); - BOP_Index tmp = v1; - v1 = v2; - v2 = tmp; - } - - /* if hash index valid, search the list and return match if found */ - if( minv < hashsize ) { - for(edge = (EdgeEntry *)hash[minv].first; - edge; edge = edge->next ) { - if(edge->v1 == v1 && edge->v2 == v2) - return m_edges[edge->index]; - } - } -#else - const BOP_IT_Edges edgesEnd = m_edges.end(); - for(BOP_IT_Edges edge=m_edges.begin();edge!=edgesEnd;edge++) { - if (((*edge)->getVertex1() == v1 && (*edge)->getVertex2() == v2) || - ((*edge)->getVertex1() == v2 && (*edge)->getVertex2() == v1)) - return *edge; - } -#endif - return NULL; -} - -/** - * Returns the mesh edge index with the specified vertex indexs. - * @param v1 vertex index - * @param v2 vertex index - * @param e edge index with the specified vertex indexs - * @return true if there is a mesh edge with the specified vertex indexs, false otherwise - */ -bool BOP_Mesh::getIndexEdge(BOP_Index v1, BOP_Index v2, BOP_Index &e) -{ -#ifdef HASH - int minv; - EdgeEntry *edge; - - /* figure out what and where to look */ - if( v1 < v2 ) { - minv = HASH(v1); - } else { - minv = HASH(v2); - BOP_Index tmp = v1; - v1 = v2; - v2 = tmp; - } - - /* if hash index is valid, look for a match */ - if( minv < hashsize ) { - for(edge = (EdgeEntry *)hash[minv].first; - edge; edge = edge->next ) { - if(edge->v1 == v1 && edge->v2 == v2) - break; - } - - /* edge != NULL means match */ - if(edge) { -#ifdef HASH_PRINTF_DEBUG - printf ("found edge (%d %d)\n",v1,v2); -#endif - e = edge->index; -#ifdef BOP_NEW_MERGE - if( m_edges[e]->getUsed() == false ) { - m_edges[e]->setUsed(true); - m_vertexs[v1]->addEdge(e); - m_vertexs[v2]->addEdge(e); - } -#endif - return true; - } -#ifdef HASH_PRINTF_DEBUG - else - printf ("didn't find edge (%d %d)\n",v1,v2); -#endif - } -#else - BOP_Index pos=0; - const BOP_IT_Edges edgesEnd = m_edges.end(); - for(BOP_IT_Edges edge=m_edges.begin();edge!=edgesEnd;edge++,pos++) { - if (((*edge)->getVertex1() == v1 && (*edge)->getVertex2() == v2) || - ((*edge)->getVertex1() == v2 && (*edge)->getVertex2() == v1)){ - e = pos; - return true; - } - } -#endif - return false; -} - -/** - * Returns the mesh edge on the specified face and relative edge index. - * @param face mesh face - * @param edge face relative edge index - * @return mesh edge on the specified face and relative index, NULL otherwise - */ -BOP_Edge* BOP_Mesh::getEdge(BOP_Face *face, unsigned int edge) -{ - if (face->size()==3) - return getEdge((BOP_Face3 *)face,edge); - else - return getEdge((BOP_Face4 *)face,edge); -} - -/** - * Returns the mesh edge on the specified triangle and relative edge index. - * @param face mesh triangle - * @param edge face relative edge index - * @return mesh edge on the specified triangle and relative index, NULL otherwise - */ -BOP_Edge* BOP_Mesh::getEdge(BOP_Face3 *face, unsigned int edge) -{ - switch(edge){ - case 1: - return getEdge(m_vertexs[face->getVertex(0)]->getEdges(),face->getVertex(1)); - case 2: - return getEdge(m_vertexs[face->getVertex(1)]->getEdges(),face->getVertex(2)); - case 3: - return getEdge(m_vertexs[face->getVertex(2)]->getEdges(),face->getVertex(0)); - }; - - return NULL; -} - -/** - * Returns the mesh edge on the specified quad and relative edge index. - * @param face mesh quad - * @param edge face relative edge index - * @return mesh edge on the specified quad and relative index, NULL otherwise - */ -BOP_Edge * BOP_Mesh::getEdge(BOP_Face4 *face, unsigned int edge) -{ - switch(edge){ - case 1: - return getEdge(m_vertexs[face->getVertex(0)]->getEdges(),face->getVertex(1)); - case 2: - return getEdge(m_vertexs[face->getVertex(1)]->getEdges(),face->getVertex(2)); - case 3: - return getEdge(m_vertexs[face->getVertex(2)]->getEdges(),face->getVertex(3)); - case 4: - return getEdge(m_vertexs[face->getVertex(3)]->getEdges(),face->getVertex(0)); - }; - - return NULL; -} - -/** - * Returns the mesh face with the specified vertex indexs. - * @param v1 vertex index - * @param v2 vertex index - * @param v3 vertex index - * @return mesh edge with the specified vertex indexs, NULL otherwise - */ -BOP_Face* BOP_Mesh::getFace(BOP_Index v1, BOP_Index v2, BOP_Index v3) -{ - const BOP_IT_Faces facesEnd = m_faces.end(); - for(BOP_IT_Faces face=m_faces.begin();face!=facesEnd;face++) { - if ((*face)->containsVertex(v1) && (*face)->containsVertex(v2) && - (*face)->containsVertex(v3)) - return (*face); - } - return NULL; -} - -/** - * Returns the mesh face index with the specified vertex indexs. - * @param v1 vertex index - * @param v2 vertex index - * @param v3 vertex index - * @param f face index with the specified vertex indexs - * @return true if there is a mesh face with the specified vertex indexs, false otherwise - */ -bool BOP_Mesh::getIndexFace(BOP_Index v1, BOP_Index v2, BOP_Index v3, BOP_Index &f) -{ - BOP_Index pos=0; - const BOP_IT_Faces facesEnd = m_faces.end(); - for(BOP_IT_Faces face=m_faces.begin();face!=facesEnd;face++,pos++) { - if ((*face)->containsVertex(v1) && (*face)->containsVertex(v2) && - (*face)->containsVertex(v3)){ - f = pos; - return true; - } - } - return false; -} - -/** - * Returns the vertices set of this mesh. - * @return vertices set - */ -BOP_Vertexs &BOP_Mesh::getVertexs() -{ - return m_vertexs; -} - -/** - * Returns the edges set of this mesh. - * @return edges set - */ -BOP_Edges &BOP_Mesh::getEdges() -{ - return m_edges; -} - -/** - * Returns the faces set of this mesh. - * @return faces set - */ -BOP_Faces &BOP_Mesh::getFaces() -{ - return m_faces; -} - -/** - * Returns the mesh vertex with the specified index. - * @param i vertex index - * @return vertex with the specified index - */ -BOP_Vertex* BOP_Mesh::getVertex(BOP_Index i) -{ - return m_vertexs[i]; -} - -/** - * Returns the mesh edge with the specified index. - * @param i edge index - * @return edge with the specified index - */ -BOP_Edge* BOP_Mesh::getEdge(BOP_Index i) -{ - return m_edges[i]; -} - -/** - * Returns the mesh face with the specified index. - * @param i face index - * @return face with the specified index - */ -BOP_Face* BOP_Mesh::getFace(BOP_Index i) -{ - return m_faces[i]; -} - -/** - * Returns the number of vertices of this mesh. - * @return number of vertices - */ -unsigned int BOP_Mesh::getNumVertexs() -{ - return m_vertexs.size(); -} - -/** - * Returns the number of edges of this mesh. - * @return number of edges - */ -unsigned int BOP_Mesh::getNumEdges() -{ - return m_edges.size(); -} - -/** - * Returns the number of faces of this mesh. - * @return number of faces - */ -unsigned int BOP_Mesh::getNumFaces() -{ - return m_faces.size(); -} - -/** - * Returns the number of vertices of this mesh with the specified tag. - * @return number of vertices with the specified tag - */ -unsigned int BOP_Mesh::getNumVertexs(BOP_TAG tag) -{ - unsigned int count = 0; - const BOP_IT_Vertexs vertexsEnd = m_vertexs.end(); - for(BOP_IT_Vertexs vertex=m_vertexs.begin();vertex!=vertexsEnd;vertex++) { - if ((*vertex)->getTAG() == tag) count++; - } - return count; -} -/** - * Returns the number of faces of this mesh with the specified tag. - * @return number of faces with the specified tag - */ -unsigned int BOP_Mesh::getNumFaces(BOP_TAG tag) -{ - unsigned int count = 0; - const BOP_IT_Faces facesEnd = m_faces.end(); - for(BOP_IT_Faces face=m_faces.begin();face!=facesEnd;face++) { - if ((*face)->getTAG() == tag) count++; - } - return count; -} - -/** - * Marks faces which bad edges as BROKEN (invalid face, no further processing). - * @param edge edge which is being replaced - * @param mesh mesh containing faces - */ - -static void removeBrokenFaces( BOP_Edge *edge, BOP_Mesh *mesh ) -{ - BOP_Faces m_faces = mesh->getFaces(); - - BOP_Indexs edgeFaces = edge->getFaces(); - const BOP_IT_Indexs edgeFacesEnd = edgeFaces.end(); - for(BOP_IT_Indexs idxFace=edgeFaces.begin();idxFace!=edgeFacesEnd; - idxFace++) - m_faces[*idxFace]->setTAG(BROKEN); -} - -/** - * Replaces a vertex index. - * @param oldIndex old vertex index - * @param newIndex new vertex index - */ -BOP_Index BOP_Mesh::replaceVertexIndex(BOP_Index oldIndex, BOP_Index newIndex) -{ - BOP_IT_Indexs oldEdgeIndex; - if (oldIndex==newIndex) return newIndex; - - // Update faces, edges and vertices - BOP_Vertex *oldVertex = m_vertexs[oldIndex]; - BOP_Vertex *newVertex = m_vertexs[newIndex]; - BOP_Indexs oldEdges = oldVertex->getEdges(); - - // Update faces to the newIndex - BOP_IT_Indexs oldEdgesEnd = oldEdges.end(); - for(oldEdgeIndex=oldEdges.begin();oldEdgeIndex!=oldEdgesEnd; - oldEdgeIndex++) { - BOP_Edge *edge = m_edges[*oldEdgeIndex]; - if ((edge->getVertex1()==oldIndex && edge->getVertex2()==newIndex) || - (edge->getVertex2()==oldIndex && edge->getVertex1()==newIndex)) { - // Remove old edge ==> set edge faces to BROKEN - removeBrokenFaces( edge, this ); - oldVertex->removeEdge(*oldEdgeIndex); - newVertex->removeEdge(*oldEdgeIndex); - } - else { - BOP_Indexs faces = edge->getFaces(); - const BOP_IT_Indexs facesEnd = faces.end(); - for(BOP_IT_Indexs face=faces.begin();face!=facesEnd;face++) { - if (m_faces[*face]->getTAG()!=BROKEN) - m_faces[*face]->replaceVertexIndex(oldIndex,newIndex); - } - } - } - - oldEdgesEnd = oldEdges.end(); - for(oldEdgeIndex=oldEdges.begin();oldEdgeIndex!=oldEdgesEnd; - oldEdgeIndex++) { - BOP_Edge * edge = m_edges[*oldEdgeIndex]; - BOP_Edge * edge2; - BOP_Index v1 = edge->getVertex1(); - - v1 = (v1==oldIndex?edge->getVertex2():v1); - if ((edge2 = getEdge(newIndex,v1)) == NULL) { - edge->replaceVertexIndex(oldIndex,newIndex); - if ( edge->getVertex1() == edge->getVertex2() ) { - removeBrokenFaces( edge, this ); - oldVertex->removeEdge(*oldEdgeIndex); - } -#ifdef HASH - rehashVertex(oldIndex,newIndex,v1); -#endif - newVertex->addEdge(*oldEdgeIndex); - } - else { - BOP_Indexs faces = edge->getFaces(); - const BOP_IT_Indexs facesEnd = faces.end(); - for(BOP_IT_Indexs f=faces.begin();f!=facesEnd;f++) { - if (m_faces[*f]->getTAG()!=BROKEN) - edge2->addFace(*f); - } - BOP_Vertex *oppositeVertex = m_vertexs[v1]; - oppositeVertex->removeEdge(*oldEdgeIndex); - edge->replaceVertexIndex(oldIndex,newIndex); - if ( edge->getVertex1() == edge->getVertex2() ) { - removeBrokenFaces( edge, this ); - oldVertex->removeEdge(*oldEdgeIndex); - newVertex->removeEdge(*oldEdgeIndex); - } -#ifdef HASH - rehashVertex(oldIndex,newIndex,v1); -#endif - } - } - oldVertex->setTAG(BROKEN); - - return newIndex; -} - -bool BOP_Mesh::isClosedMesh() -{ - for(unsigned int i=0; i<m_edges.size(); i++) { - BOP_Edge *edge = m_edges[i]; - BOP_Indexs faces = edge->getFaces(); - unsigned int count = 0; - const BOP_IT_Indexs facesEnd = faces.end(); - for(BOP_IT_Indexs it = faces.begin();it!=facesEnd;it++) { - if (m_faces[*it]->getTAG()!=BROKEN) - count++; - } - - if ((count%2)!=0) return false; - } - - return true; -} - - -#ifdef BOP_DEBUG -/****************************************************************************** - * DEBUG METHODS * - * This functions are used to test the mesh state and debug program errors. * - ******************************************************************************/ - -/** - * print - */ -void BOP_Mesh::print() -{ - unsigned int i; - cout << "--Faces--" << endl; - for(i=0;i<m_faces.size();i++){ - cout << "Face " << i << ": " << m_faces[i] << endl; - } - - cout << "--Vertices--" << endl; - for(i=0;i<m_vertexs.size();i++){ - cout << "Point " << i << ": " << m_vertexs[i]->getPoint() << endl; - } -} - -/** - * printFormat - */ -void BOP_Mesh::printFormat(BOP_Faces *faces) -{ - if (faces->size()) { - for(unsigned int it=1;it<faces->size();it++) { - if ((*faces)[it]->getTAG()!=BROKEN) { - cout << m_vertexs[(*faces)[it]->getVertex(0)]->getPoint() << " "; - cout << m_vertexs[(*faces)[it]->getVertex(1)]->getPoint() << " "; - cout << m_vertexs[(*faces)[it]->getVertex(2)]->getPoint() << endl; - } - } - } -} - -/** - * saveFormat - */ -void BOP_Mesh::saveFormat(BOP_Faces *faces,char *filename) -{ - ofstream fout(filename); - - if (!fout.is_open()) { - cerr << "BOP_Mesh::saveFormat Error: Could not create file." << endl; - return; - } - - unsigned int count = 0; - if (faces->size()) { - for(unsigned int it=0;it<faces->size();it++) { - if ((*faces)[it]->getTAG()!=BROKEN) { - count++; - } - } - } - - fout << count << endl; - if (faces->size()) { - for(unsigned int it=0;it<faces->size();it++) { - if ((*faces)[it]->getTAG()!=BROKEN){ - fout << m_vertexs[(*faces)[it]->getVertex(0)]->getPoint() << " "; - fout << m_vertexs[(*faces)[it]->getVertex(1)]->getPoint() << " "; - fout << m_vertexs[(*faces)[it]->getVertex(2)]->getPoint() << endl; - } - } - } - - fout.close(); -} - -/** - * printFormat - */ -void BOP_Mesh::printFormat() -{ - cout << "--Vertices--" << endl; - if (m_vertexs.size()>0) { - cout << "{" << m_vertexs[0]->getPoint().x() << ","; - cout << m_vertexs[0]->getPoint().y() << ","; - cout << m_vertexs[0]->getPoint().z() << "}"; - for(unsigned int i=1;i<m_vertexs.size();i++) { - cout << ",{" << m_vertexs[i]->getPoint().x() << ","; - cout << m_vertexs[i]->getPoint().y() << ","; - cout << m_vertexs[i]->getPoint().z() << "}"; - } - cout << endl; - } - - cout << "--Faces--" << endl; - if (m_faces.size()>0) { - cout << "{" << m_faces[0]->getVertex(0) << ","; - cout << m_faces[0]->getVertex(1) << "," << m_faces[0]->getVertex(2) << "}"; - for(unsigned int i=1;i<m_faces.size();i++) { - cout << ",{" << m_faces[i]->getVertex(0) << ","; - cout << m_faces[i]->getVertex(1) << "," << m_faces[i]->getVertex(2) << "}"; - } - cout << endl; - } -} - -/** - * printFace - */ -void BOP_Mesh::printFace(BOP_Face *face, int col) -{ - cout << "--Face" << endl; - cout << m_vertexs[face->getVertex(0)]->getPoint(); - cout << " " << m_vertexs[face->getVertex(1)]->getPoint(); - cout << " " << m_vertexs[face->getVertex(2)]->getPoint(); - if (face->size()==4) - cout << " " << m_vertexs[face->getVertex(3)]->getPoint(); - cout << " " << col << endl; -} - -/** - * testMesh - */ -void BOP_Mesh::testMesh() -{ - - BOP_Face* cares[10]; - unsigned int nedges=0,i; - for(i=0;i<m_edges.size();i++) { - BOP_Edge *edge = m_edges[i]; - BOP_Indexs faces = edge->getFaces(); - unsigned int count = 0; - const BOP_IT_Indexs facesEnd = faces.end(); - for(BOP_IT_Indexs it = faces.begin();it!=facesEnd;it++) { - if (m_faces[*it]->getTAG()!=BROKEN) { - cares[count] = m_faces[*it]; - count++; - - } - } - - if ((count%2)!=0) nedges++; - } - if (nedges) - cout << nedges << " wrong edges." << endl; - else - cout << "well edges." << endl; - - unsigned int duplFaces = 0; - unsigned int wrongFaces = 0; - for(i=0;i<m_faces.size();i++){ - BOP_Face *faceI = m_faces[i]; - if (faceI->getTAG()==BROKEN) - continue; - - if (testFace(faceI)){ - wrongFaces++; - cout << "Wrong Face: " << faceI << endl; - } - - for(unsigned int j=i+1;j<m_faces.size();j++){ - BOP_Face *faceJ = m_faces[j]; - - if (faceJ->getTAG()==BROKEN) - continue; - - if (testFaces(faceI,faceJ)){ - duplFaces++; - cout << "Duplicate FaceI: " << faceI << endl; - cout << "Duplicate FaceJ: " << faceJ << endl; - } - } - } - - cout << duplFaces << " duplicate faces." << endl; - cout << wrongFaces << " wrong faces." << endl; -} - -/** - * testFace - */ -bool BOP_Mesh::testFace(BOP_Face *face){ - - for(unsigned int i=0;i<face->size();i++){ - for(unsigned int j=i+1;j<face->size();j++){ - if (face->getVertex(i)==face->getVertex(j)) - return true; - } - } - - return false; -} - -/** - * testFaces - */ -bool BOP_Mesh::testFaces(BOP_Face *faceI, BOP_Face *faceJ){ - - if (faceI->size()<faceJ->size()){ - for(unsigned int i=0;i<faceI->size();i++){ - if (!faceJ->containsVertex(faceI->getVertex(i))) - return false; - } - //faceI->setTAG(BROKEN); - } - else{ - for(unsigned int i=0;i<faceJ->size();i++){ - if (!faceI->containsVertex(faceJ->getVertex(i))) - return false; - } - //faceJ->setTAG(BROKEN); - } - - return true; -} - -/** - * testPlane - */ -void BOP_Mesh::testPlane(BOP_Face *face) -{ - MT_Plane3 plane1(m_vertexs[face->getVertex(0)]->getPoint(), - m_vertexs[face->getVertex(1)]->getPoint(), - m_vertexs[face->getVertex(2)]->getPoint()); - - if (BOP_orientation(plane1,face->getPlane()) < 0) { - cout << "Test Plane " << face << " v1: "; - cout << m_vertexs[face->getVertex(0)]->getPoint() << " v2: "; - cout << m_vertexs[face->getVertex(1)]->getPoint() << " v3: "; - cout << m_vertexs[face->getVertex(2)]->getPoint() << " plane: "; - cout << face->getPlane() << endl; - cout << "Incorrect vertices order!!! plane1: " << plane1 << " ("; - cout << BOP_orientation(plane1,face->getPlane()) << ") " << " invert "; - cout << MT_Plane3(m_vertexs[face->getVertex(2)]->getPoint(), - m_vertexs[face->getVertex(1)]->getPoint(), - m_vertexs[face->getVertex(0)]->getPoint()) << endl; - if (BOP_collinear(m_vertexs[face->getVertex(0)]->getPoint(), - m_vertexs[face->getVertex(1)]->getPoint(), - m_vertexs[face->getVertex(2)]->getPoint())) { - cout << " COLLINEAR!!!" << endl; - } - else { - cout << endl; - } - } -} - -/** - * testEdges - */ -bool BOP_Mesh::testEdges(BOP_Faces *facesObj) -{ - for(unsigned int i=0;i<m_edges.size();i++) { - BOP_Edge *edge = m_edges[i]; - BOP_Indexs faces = edge->getFaces(); - unsigned int count = 0; - const BOP_IT_Indexs facesEnd = faces.end(); - for(BOP_IT_Indexs it = faces.begin();it!=facesEnd;it++) { - if ((m_faces[*it]->getTAG()!=BROKEN) && containsFace(facesObj,m_faces[*it])) - count++; - } - if ((count%2)!=0) { - return false; - } - } - - return true; -} - -/** - * updatePlanes - */ -void BOP_Mesh::updatePlanes() -{ - const BOP_IT_Faces facesEnd = m_faces.end(); - for(BOP_IT_Faces it = m_faces.begin();it!=facesEnd;it++) { - BOP_Face *face = *it; - MT_Plane3 plane(m_vertexs[face->getVertex(0)]->getPoint(), - m_vertexs[face->getVertex(1)]->getPoint(), - m_vertexs[face->getVertex(2)]->getPoint()); - face->setPlane(plane); - } -} - -#endif diff --git a/intern/boolop/intern/BOP_Mesh.h b/intern/boolop/intern/BOP_Mesh.h deleted file mode 100644 index 9c1b4ad04ea..00000000000 --- a/intern/boolop/intern/BOP_Mesh.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - * - * - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file boolop/intern/BOP_Mesh.h - * \ingroup boolopintern - */ - - -#ifndef __BOP_MESH_H__ -#define __BOP_MESH_H__ - -#include "BOP_Vertex.h" -#include "BOP_Edge.h" -#include "BOP_Face.h" -#include "DNA_listBase.h" - -typedef std::vector<BOP_Vertex *> BOP_Vertexs; -typedef std::vector<BOP_Edge *> BOP_Edges; -typedef std::vector<BOP_Vertex *>::iterator BOP_IT_Vertexs; -typedef std::vector<BOP_Edge *>::iterator BOP_IT_Edges; - -#ifdef HASH -typedef struct EdgeEntry { - struct EdgeEntry *next, *pref; - BOP_Index v1, v2, index; -} EdgeEntry; -#endif - -class BOP_Mesh -{ -private: - BOP_Vertexs m_vertexs; - BOP_Edges m_edges; - BOP_Faces m_faces; -#ifdef HASH - ListBase *hash; - int hashsize; -#endif - - BOP_Index addEdge(BOP_Index v1, BOP_Index v2); - BOP_Edge *getEdge(BOP_Indexs edges, BOP_Index v2); - bool containsFace(BOP_Faces *faces, BOP_Face *face); - - bool testEdges(BOP_Faces *faces); - bool testFaces(BOP_Face *faceI, BOP_Face *faceJ); - bool testFace(BOP_Face *face); - -public: - BOP_Mesh(); - ~BOP_Mesh(); - - BOP_Index addVertex(MT_Point3 point); - BOP_Index addFace(BOP_Face *face); - BOP_Index addFace(BOP_Face3 *face); - BOP_Index addFace(BOP_Face4 *face); - BOP_Vertex* getVertex(BOP_Index v); - BOP_Face*getFace(BOP_Index v); - BOP_Edge* getEdge(BOP_Index v); - BOP_Edge* getEdge(BOP_Face * face, unsigned int edge); - BOP_Edge* getEdge(BOP_Face3 * face, unsigned int edge); - BOP_Edge* getEdge(BOP_Face4 * face, unsigned int edge); - BOP_Edge* getEdge(BOP_Index v1, BOP_Index v2); - bool getIndexEdge(BOP_Index v1, BOP_Index v2, BOP_Index &e); - BOP_Vertexs &getVertexs(); - BOP_Edges &getEdges(); - BOP_Faces &getFaces(); - BOP_Face* getFace(BOP_Index v1, BOP_Index v2, BOP_Index v3); - bool getIndexFace(BOP_Index v1, BOP_Index v2, BOP_Index v3, BOP_Index &f); - unsigned int getNumVertexs(); - unsigned int getNumEdges(); - unsigned int getNumFaces(); - unsigned int getNumVertexs(BOP_TAG tag); - unsigned int getNumFaces(BOP_TAG tag); - BOP_Index replaceVertexIndex(BOP_Index oldIndex, BOP_Index newIndex); -#ifdef HASH - void rehashVertex(BOP_Index oldIndex, BOP_Index newIndex, - BOP_Index otherIndex); -#endif - bool isClosedMesh(); - - // Debug functions - void print(); - void printFormat(); - void printFormat(BOP_Faces *faces); - void saveFormat(BOP_Faces *faces, char *filename); - void printFace(BOP_Face *face, int col = 0); - void testPlane(BOP_Face *face); - void testMesh(); - void updatePlanes(); -}; - -#endif diff --git a/intern/boolop/intern/BOP_Misc.h b/intern/boolop/intern/BOP_Misc.h deleted file mode 100644 index 4a808771df2..00000000000 --- a/intern/boolop/intern/BOP_Misc.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * - * - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): Ken Hughes - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file boolop/intern/BOP_Misc.h - * \ingroup boolopintern - */ - - -/* - * This file contains various definitions used across the modules - */ - -/* - * define operator>> for faces, edges and vertices, and also add some - * debugging functions for displaying various internal data structures - */ - -// #define BOP_DEBUG - -#define HASH(x) ((x) >> 5) /* each "hash" covers 32 indices */ -// #define HASH_PRINTF_DEBUG /* uncomment to enable debug output */ - -/* - * temporary: control which method is used to merge final triangles and - * quads back together after an operation. If both methods are included, - * the "rt" debugging button on the Scene panel (F10) is used to control - * which is active. Setting it to 100 enables the original method, any - * other value enables the new method. - */ - -#define BOP_ORIG_MERGE /* include original merge code */ -#define BOP_NEW_MERGE /* include new merge code */ diff --git a/intern/boolop/intern/BOP_Segment.cpp b/intern/boolop/intern/BOP_Segment.cpp deleted file mode 100644 index 79e04380015..00000000000 --- a/intern/boolop/intern/BOP_Segment.cpp +++ /dev/null @@ -1,249 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file boolop/intern/BOP_Segment.cpp - * \ingroup boolopintern - */ - - -#include "BOP_Segment.h" - -#define UNDEFINED 0 - -/** - * Constructs a new segment. - */ -BOP_Segment::BOP_Segment(){ - m_cfg1 = UNDEFINED; - m_cfg2 = UNDEFINED; -} - -/** - * Returns the relative edge index between two relative vertex indices. - * @param v1 relative vertex index - * @param v2 relative vertex index - * @return relative edge index between two relative vertex indices, -1 otherwise - */ -int BOP_Segment::getEdgeBetween(unsigned int v1, unsigned int v2) -{ - if ((v1 == 1 && v2 == 2) || (v1 == 2 && v2 == 1)) return 1; - if ((v1 == 3 && v2 == 2) || (v1 == 2 && v2 == 3)) return 2; - if ((v1 == 1 && v2 == 3) || (v1 == 3 && v2 == 1)) return 3; - return -1; -} - -/** - * Returns if a relative vertex index is on a relative edge index. - * @param v relative vertex index - * @param e relative edge index - * @return true if the relative vertex index is on the relative edge index, - * false otherwise. - */ -bool BOP_Segment::isOnEdge(unsigned int v, unsigned int e) -{ - if (v == 1 && (e == 1 || e == 3)) return true; - if (v == 2 && (e == 1 || e == 2)) return true; - if (v == 3 && (e == 2 || e == 3)) return true; - return false; -} - -/** - * Inverts the segment, swapping ends data. - */ -void BOP_Segment::invert() -{ - BOP_Index aux = m_v1; - m_v1 = m_v2; - m_v2 = aux; - aux = m_cfg1; - m_cfg1 = m_cfg2; - m_cfg2 = aux; -} - -/** - * Sorts the segment according to ends configuration. - * The criterion to sort is ... - * - * UNDEFINED < VERTEX < EDGE < IN - * cfg1 > cfg2 - * - * so ... - * - * VERTEX(cfg1) => UNDEFINED(cfg2) || VERTEX(cfg2) - * EDGE(cfg1) => UNDEFINED(cfg2) || VERTEX(cfg2) || EDGE(cfg2) - * IN(cfg1) => UNDEFINED(cfg2) || VERTEX(cfg2) || EDGE(cfg2) || IN(cfg2) - */ -void BOP_Segment::sort() -{ - if (m_cfg1 < m_cfg2) invert(); -} - -/** - * Returns if the specified end segment configuration is IN. - * @return true if the specified end segment configuration is IN, false otherwise - */ -bool BOP_Segment::isIn(unsigned int cfg) -{ - return (cfg == 20); -} - -/** - * Returns if the specified end segment configuration is EDGE. - * @return true if the specified end segment configuration is EDGE, false otherwise - */ -bool BOP_Segment::isEdge(unsigned int cfg) -{ - return (cfg > 10) && (cfg < 20); -} - -/** - * Returns if the specified end segment configuration is VERTEX. - * @return true if the specified end segment configuration is VERTEX, false otherwise - */ -bool BOP_Segment::isVertex(unsigned int cfg) -{ - return (cfg!=UNDEFINED) && (cfg < 10); -} - -/** - * Returns if the specified end segment configuration is DEFINED (not UNDEFINED). - * @return true if the specified end segment configuration is DEFINED, false otherwise - */ -bool BOP_Segment::isDefined(unsigned int cfg) -{ - return (cfg != UNDEFINED); -} - -/** - * Returns if the specified end segment configuration is UNDEFINED. - * @return true if the specified end segment configuration is UNDEFINED, false otherwise - */ -bool BOP_Segment::isUndefined(unsigned int cfg) -{ - return (cfg == UNDEFINED); -} - -/** - * Returns the relative edge index from the specified end segment configuration. - * @return relative edge index from the specified end segment configuration - */ -unsigned int BOP_Segment::getEdge(unsigned int cfg) -{ - return cfg-10; -} - -/** - * Returns the relative vertex index from the specified end segment configuration. - * @return relative vertex index from the specified end segment configuration - */ -BOP_Index BOP_Segment::getVertex(unsigned int cfg) -{ - return cfg; -} - -/** - * Returns the end segment configuration for the specified relative edge index. - * @return end segment configuration for the specified relative edge index - */ -unsigned int BOP_Segment::createEdgeCfg(unsigned int edge) -{ - return 10+edge; -} - -/** - * Returns the end segment configuration for the specified relative vertex index. - * @return end segment configuration for the specified relative vertex index - */ -unsigned int BOP_Segment::createVertexCfg(BOP_Index vertex) -{ - return vertex; -} - -/** - * Returns the end segment IN configuration. - * @return end segment IN configuration - */ -unsigned int BOP_Segment::createInCfg() -{ - return 20; -} - -/** - * Returns the end segment UNDEFINED configuration. - * @return end segment UNDEFINED configuration - */ -unsigned int BOP_Segment::createUndefinedCfg() -{ - return UNDEFINED; -} - -/** - * Returns the inner segment configuration. - * @return inner segment configuration - */ -unsigned int BOP_Segment::getConfig() -{ - if (isUndefined(m_cfg1)) return m_cfg2; - else if (isUndefined(m_cfg2)) return m_cfg1; - else if (isVertex(m_cfg1)) { - // v1 is vertex - if (isVertex(m_cfg2)) { - // v2 is vertex - return createEdgeCfg(getEdgeBetween(getVertex(m_cfg1),getVertex(m_cfg2))); - } - else if (isEdge(m_cfg2)) { - // v2 is edge - if (isOnEdge(m_cfg1,getEdge(m_cfg2))) return m_cfg2; - else return createInCfg(); //IN - } - else return createInCfg(); //IN - } - else if (isEdge(m_cfg1)) { - // v1 is edge - if (isVertex(m_cfg2)) { - // v2 is vertex - if (isOnEdge(m_cfg2,getEdge(m_cfg1))) return m_cfg1; - else return createInCfg(); //IN - } - else if (isEdge(m_cfg2)) { - // v2 is edge - if (m_cfg1 == m_cfg2) return m_cfg1; - else return createInCfg(); // IN - } - else return createInCfg(); // IN - } - else return createInCfg(); // IN -} - -/** - * Implements operator << - */ -std::ostream &operator<<(std::ostream &stream, const BOP_Segment &c) -{ - std::cout << "m_v1: " << c.m_v1 << "(" << c.m_cfg1 << ") m_v2: " << c.m_v2 << "(" << c.m_cfg2 << ")"; - return stream; -} diff --git a/intern/boolop/intern/BOP_Segment.h b/intern/boolop/intern/BOP_Segment.h deleted file mode 100644 index 5a49ae844c4..00000000000 --- a/intern/boolop/intern/BOP_Segment.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file boolop/intern/BOP_Segment.h - * \ingroup boolopintern - */ - - -#ifndef __BOP_SEGMENT_H__ -#define __BOP_SEGMENT_H__ - -#include "BOP_Indexs.h" -#include <iostream> - -class BOP_Segment -{ -private: - int getEdgeBetween(unsigned int v1, unsigned int v2); - bool isOnEdge(unsigned int v, unsigned int e); - -public: - // Cfg : Configuration of the vertices - // Values: - // 20 IN, - // 1X Intersected edge X{1,2,3} of the face, - // 0X Coincident vertice X{1,2,3} of the face, - // 0 otherwise - unsigned int m_cfg1, m_cfg2; - BOP_Index m_v1, m_v2; // if cfgX >0, vX is the vertice index of the face - BOP_Segment(); - - static bool isIn(unsigned int cfg); - static bool isEdge(unsigned int cfg); - static bool isVertex(unsigned int cfg); - static bool isDefined(unsigned int cfg); - static bool isUndefined(unsigned int cfg); - static unsigned int getEdge(unsigned int cfg); - static BOP_Index getVertex(unsigned int cfg); - static unsigned int createEdgeCfg(unsigned int edge); - static unsigned int createVertexCfg(BOP_Index vertex); - static unsigned int createInCfg(); - static unsigned int createUndefinedCfg(); - void invert(); - void sort(); - unsigned int getConfig(); - - friend std::ostream &operator<<(std::ostream &stream, const BOP_Segment &c); -}; - -#endif diff --git a/intern/boolop/intern/BOP_Splitter.cpp b/intern/boolop/intern/BOP_Splitter.cpp deleted file mode 100644 index 0839b6af30b..00000000000 --- a/intern/boolop/intern/BOP_Splitter.cpp +++ /dev/null @@ -1,194 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file boolop/intern/BOP_Splitter.cpp - * \ingroup boolopintern - */ - - -#include "BOP_Splitter.h" -#include "BOP_Tag.h" - -#include <iostream> - -/** - * Returns the split point resulting from intersect a plane and a mesh face - * according to its specified relative edge. - * @param plane split plane - * @param m mesh - * @param f face - * @param e relative edge index - * @return intersection point - */ -MT_Point3 BOP_splitEdge(MT_Plane3 plane, BOP_Mesh *m, BOP_Face *f, unsigned int e) -{ - int v1 = -1, v2 = -1; - - switch(e) { - case 1: - v1 = f->getVertex(0); - v2 = f->getVertex(1); - break; - case 2: - v1 = f->getVertex(1); - v2 = f->getVertex(2); - break; - case 3: - v1 = f->getVertex(2); - v2 = f->getVertex(0); - break; - default: - // wrong relative edge index! - break; - } - - MT_Point3 p1 = m->getVertex(v1)->getPoint(); - MT_Point3 p2 = m->getVertex(v2)->getPoint(); - return BOP_intersectPlane(plane,p1,p2); -} - -/** - * Returns the segment resulting from intersect a plane and a mesh face. - * @param plane split plane - * @param m mesh - * @param f face - * @return segment if there is intersection, NULL otherwise - */ -BOP_Segment BOP_splitFace(MT_Plane3 plane, BOP_Mesh *m, BOP_Face *f) -{ - BOP_Vertex *v1 = m->getVertex(f->getVertex(0)); - BOP_Vertex *v2 = m->getVertex(f->getVertex(1)); - BOP_Vertex *v3 = m->getVertex(f->getVertex(2)); - - // Classify face vertices - BOP_TAG tag1 = BOP_createTAG(BOP_classify(v1->getPoint(),plane)); - BOP_TAG tag2 = BOP_createTAG(BOP_classify(v2->getPoint(),plane)); - BOP_TAG tag3 = BOP_createTAG(BOP_classify(v3->getPoint(),plane)); - - // Classify face according to its vertices classification - BOP_TAG tag = BOP_createTAG(tag1,tag2,tag3); - - BOP_Segment s; - - switch(tag) { - case IN_IN_IN : - case OUT_OUT_OUT : - case ON_ON_ON : - s.m_cfg1 = s.m_cfg2 = BOP_Segment::createUndefinedCfg(); - break; - - case ON_OUT_OUT : - case ON_IN_IN : - s.m_v1 = f->getVertex(0); - s.m_cfg1 = BOP_Segment::createVertexCfg(1); - s.m_cfg2 = BOP_Segment::createUndefinedCfg(); - break; - - case OUT_ON_OUT : - case IN_ON_IN : - s.m_v1 = f->getVertex(1); - s.m_cfg1 = BOP_Segment::createVertexCfg(2); - s.m_cfg2 = BOP_Segment::createUndefinedCfg(); - break; - - case OUT_OUT_ON : - case IN_IN_ON : - s.m_v1 = f->getVertex(2); - s.m_cfg1 = BOP_Segment::createVertexCfg(3); - s.m_cfg2 = BOP_Segment::createUndefinedCfg(); - break; - - case ON_ON_IN : - case ON_ON_OUT : - s.m_v1 = f->getVertex(0); - s.m_v2 = f->getVertex(1); - s.m_cfg1 = BOP_Segment::createVertexCfg(1); - s.m_cfg2 = BOP_Segment::createVertexCfg(2); - break; - - case ON_OUT_ON : - case ON_IN_ON : - s.m_v1 = f->getVertex(0); - s.m_v2 = f->getVertex(2); - s.m_cfg1 = BOP_Segment::createVertexCfg(1); - s.m_cfg2 = BOP_Segment::createVertexCfg(3); - break; - - case OUT_ON_ON : - case IN_ON_ON : - s.m_v1 = f->getVertex(1); - s.m_v2 = f->getVertex(2); - s.m_cfg1 = BOP_Segment::createVertexCfg(2); - s.m_cfg2 = BOP_Segment::createVertexCfg(3); - break; - - case IN_OUT_ON : - case OUT_IN_ON : - s.m_v2 = f->getVertex(2); - s.m_cfg1 = BOP_Segment::createEdgeCfg(1); - s.m_cfg2 = BOP_Segment::createVertexCfg(3); - break; - - case IN_ON_OUT : - case OUT_ON_IN : - s.m_v1 = f->getVertex(1); - s.m_cfg1 = BOP_Segment::createVertexCfg(2); - s.m_cfg2 = BOP_Segment::createEdgeCfg(3); - break; - - case ON_IN_OUT : - case ON_OUT_IN : - s.m_v1 = f->getVertex(0); - s.m_cfg1 = BOP_Segment::createVertexCfg(1); - s.m_cfg2 = BOP_Segment::createEdgeCfg(2); - break; - - case OUT_IN_IN : - case IN_OUT_OUT : - s.m_cfg1 = BOP_Segment::createEdgeCfg(1); - s.m_cfg2 = BOP_Segment::createEdgeCfg(3); - break; - - case OUT_IN_OUT : - case IN_OUT_IN : - s.m_cfg1 = BOP_Segment::createEdgeCfg(1); - s.m_cfg2 = BOP_Segment::createEdgeCfg(2); - break; - - case OUT_OUT_IN : - case IN_IN_OUT : - s.m_cfg1 = BOP_Segment::createEdgeCfg(2); - s.m_cfg2 = BOP_Segment::createEdgeCfg(3); - break; - - default: - // wrong TAG! - break; - } - - return s; -} diff --git a/intern/boolop/intern/BOP_Splitter.h b/intern/boolop/intern/BOP_Splitter.h deleted file mode 100644 index 8d79b89aa91..00000000000 --- a/intern/boolop/intern/BOP_Splitter.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file boolop/intern/BOP_Splitter.h - * \ingroup boolopintern - */ - - -#ifndef __BOP_SPLITTER_H__ -#define __BOP_SPLITTER_H__ - -#include "BOP_MathUtils.h" -#include "BOP_Segment.h" -#include "BOP_Mesh.h" - -#include "MT_Plane3.h" -#include "MT_Point3.h" - -MT_Point3 BOP_splitEdge(MT_Plane3 plane, BOP_Mesh *mesh, BOP_Face *face, unsigned int edge); -BOP_Segment BOP_splitFace(MT_Plane3 plane, BOP_Mesh *mesh, BOP_Face *face); - -#endif diff --git a/intern/boolop/intern/BOP_Tag.cpp b/intern/boolop/intern/BOP_Tag.cpp deleted file mode 100644 index cdc04b67d4a..00000000000 --- a/intern/boolop/intern/BOP_Tag.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file boolop/intern/BOP_Tag.cpp - * \ingroup boolopintern - */ - - -#include "BOP_Tag.h" - -/** - * Gets the tag description. - * @param t tag - * @param dest tag description - */ -void BOP_stringTAG(BOP_TAG t, char *dest) { - - switch(t){ - case IN_IN_IN: - sprintf(dest, "IN_IN_IN"); - break; - case IN_IN_ON: - sprintf(dest, "IN_IN_ON"); - break; - case IN_ON_IN: - sprintf(dest, "IN_ON_IN"); - break; - case IN_ON_ON: - sprintf(dest, "IN_ON_ON"); - break; - case ON_IN_IN: - sprintf(dest, "ON_IN_IN"); - break; - case ON_IN_ON: - sprintf(dest, "ON_IN_ON"); - break; - case ON_ON_IN: - sprintf(dest, "ON_ON_IN"); - break; - case ON_ON_ON: - sprintf(dest, "ON_ON_ON"); - break; - case OUT_OUT_OUT: - sprintf(dest, "OUT_OUT_OUT"); - break; - case OUT_OUT_ON: - sprintf(dest, "OUT_OUT_ON"); - break; - case OUT_ON_OUT: - sprintf(dest, "OUT_ON_OUT"); - break; - case OUT_ON_ON: - sprintf(dest, "OUT_ON_ON"); - break; - case ON_OUT_OUT: - sprintf(dest, "ON_OUT_OUT"); - break; - case ON_OUT_ON: - sprintf(dest, "ON_OUT_ON"); - break; - case ON_ON_OUT: - sprintf(dest, "ON_ON_OUT"); - break; - case OUT_OUT_IN: - sprintf(dest, "OUT_OUT_IN"); - break; - case OUT_IN_OUT: - sprintf(dest, "OUT_IN_OUT"); - break; - case OUT_IN_IN: - sprintf(dest, "OUT_IN_IN"); - break; - case IN_OUT_OUT: - sprintf(dest, "IN_OUT_OUT"); - break; - case IN_OUT_IN: - sprintf(dest, "IN_OUT_IN"); - break; - case IN_IN_OUT: - sprintf(dest, "IN_IN_OUT"); - break; - case OUT_ON_IN: - sprintf(dest, "OUT_ON_IN"); - break; - case OUT_IN_ON: - sprintf(dest, "OUT_IN_ON"); - break; - case IN_ON_OUT: - sprintf(dest, "IN_ON_OUT"); - break; - case IN_OUT_ON: - sprintf(dest, "IN_OUT_ON"); - break; - case ON_IN_OUT: - sprintf(dest, "ON_IN_OUT"); - break; - case ON_OUT_IN: - sprintf(dest, "ON_OUT_IN"); - break; - case UNCLASSIFIED: - sprintf(dest, "UNCLASSIFIED"); - break; - case BROKEN: - sprintf(dest, "BROKEN"); - break; - case PHANTOM: - sprintf(dest, "PHANTOM"); - break; - case OVERLAPPED: - sprintf(dest, "OVERLAPPED"); - break; - case INOUT: - sprintf(dest, "INOUT"); - break; - default: - sprintf(dest, "DESCONEGUT %d",t); - break; - } - -} diff --git a/intern/boolop/intern/BOP_Tag.h b/intern/boolop/intern/BOP_Tag.h deleted file mode 100644 index b7438275e90..00000000000 --- a/intern/boolop/intern/BOP_Tag.h +++ /dev/null @@ -1,147 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file boolop/intern/BOP_Tag.h - * \ingroup boolopintern - */ - - -#include <string.h> -#include <stdio.h> - -#ifndef __BOP_TAG_H__ -#define __BOP_TAG_H__ - -#define IN_TAG 0x02 // Below the plane -#define ON_TAG 0x00 // On the plane -#define OUT_TAG 0x01 // Above the plane -#define INOUT_TAG 0x0E // Above and below the plane -#define INON_TAG 0x12 // Below and on the plane -#define OUTON_TAG 0x11 // Above and on the plane -#define UNCLASSIFIED_TAG 0x0F // Expecting to be classified - -#define PHANTOM_TAG 0x0C // Phantom face: verts form collinear triangle -#define OVERLAPPED_TAG 0x0D // Overlapped face -#define BROKEN_TAG 0x0B // Splitted and unused ... - -#define ON_ON_IN_TAG IN_TAG -#define ON_IN_ON_TAG IN_TAG << 2 -#define IN_ON_ON_TAG IN_TAG << 4 - -#define ON_ON_OUT_TAG OUT_TAG -#define ON_OUT_ON_TAG OUT_TAG << 2 -#define OUT_ON_ON_TAG OUT_TAG << 4 - -#define ON_ON_ON_TAG ON_TAG -#define IN_IN_IN_TAG IN_ON_ON_TAG | ON_IN_ON_TAG | ON_ON_IN_TAG -#define OUT_OUT_OUT_TAG OUT_ON_ON_TAG | ON_OUT_ON_TAG | ON_ON_OUT_TAG - -#define IN_IN_ON_TAG IN_ON_ON_TAG | ON_IN_ON_TAG -#define IN_ON_IN_TAG IN_ON_ON_TAG | ON_ON_IN_TAG -#define ON_IN_IN_TAG ON_IN_ON_TAG | ON_ON_IN_TAG - -#define OUT_OUT_ON_TAG OUT_ON_ON_TAG | ON_OUT_ON_TAG -#define OUT_ON_OUT_TAG OUT_ON_ON_TAG | ON_ON_OUT_TAG -#define ON_OUT_OUT_TAG ON_OUT_ON_TAG | ON_ON_OUT_TAG - -#define IN_OUT_OUT_TAG IN_ON_ON_TAG | ON_OUT_OUT_TAG -#define OUT_IN_OUT_TAG ON_IN_ON_TAG | OUT_ON_OUT_TAG -#define OUT_OUT_IN_TAG ON_ON_IN_TAG | OUT_OUT_ON_TAG - -#define OUT_IN_IN_TAG ON_IN_IN_TAG | OUT_ON_ON_TAG -#define IN_OUT_IN_TAG IN_ON_IN_TAG | ON_OUT_ON_TAG -#define IN_IN_OUT_TAG IN_IN_ON_TAG | ON_ON_OUT_TAG - -#define IN_ON_OUT_TAG IN_ON_ON_TAG | ON_ON_OUT_TAG -#define IN_OUT_ON_TAG IN_ON_ON_TAG | ON_OUT_ON_TAG -#define ON_IN_OUT_TAG ON_IN_ON_TAG | ON_ON_OUT_TAG -#define ON_OUT_IN_TAG ON_ON_IN_TAG | ON_OUT_ON_TAG -#define OUT_IN_ON_TAG ON_IN_ON_TAG | OUT_ON_ON_TAG -#define OUT_ON_IN_TAG ON_ON_IN_TAG | OUT_ON_ON_TAG - -typedef enum BOP_TAGEnum { - IN = IN_TAG, - ON = ON_TAG, - OUT = OUT_TAG, - INOUT = INOUT_TAG, - INON = INON_TAG, - OUTON = OUTON_TAG, - UNCLASSIFIED = UNCLASSIFIED_TAG, - PHANTOM = PHANTOM_TAG, - OVERLAPPED = OVERLAPPED_TAG, - BROKEN = BROKEN_TAG, - IN_ON_ON = IN_ON_ON_TAG, - ON_IN_ON = ON_IN_ON_TAG, - ON_ON_IN = ON_ON_IN_TAG, - OUT_ON_ON = OUT_ON_ON_TAG, - ON_OUT_ON = ON_OUT_ON_TAG, - ON_ON_OUT = ON_ON_OUT_TAG, - ON_ON_ON = ON_ON_ON_TAG, - IN_IN_IN = IN_IN_IN_TAG, - OUT_OUT_OUT = OUT_OUT_OUT_TAG, - IN_IN_ON = IN_IN_ON_TAG, - IN_ON_IN = IN_ON_IN_TAG, - ON_IN_IN = ON_IN_IN_TAG, - OUT_OUT_ON = OUT_OUT_ON_TAG, - OUT_ON_OUT = OUT_ON_OUT_TAG, - ON_OUT_OUT = ON_OUT_OUT_TAG, - IN_OUT_OUT = IN_OUT_OUT_TAG, - OUT_IN_OUT = OUT_IN_OUT_TAG, - OUT_OUT_IN = OUT_OUT_IN_TAG, - OUT_IN_IN = OUT_IN_IN_TAG, - IN_OUT_IN = IN_OUT_IN_TAG, - IN_IN_OUT = IN_IN_OUT_TAG, - IN_ON_OUT = IN_ON_OUT_TAG, - IN_OUT_ON = IN_OUT_ON_TAG, - ON_IN_OUT = ON_IN_OUT_TAG, - ON_OUT_IN = ON_OUT_IN_TAG, - OUT_IN_ON = OUT_IN_ON_TAG, - OUT_ON_IN = OUT_ON_IN_TAG } BOP_TAG; - -inline BOP_TAG BOP_createTAG(BOP_TAG tag1, BOP_TAG tag2, BOP_TAG tag3) -{ - return (BOP_TAG) (tag1 << 4 | tag2 << 2 | tag3); -} - -inline BOP_TAG BOP_createTAG(int i) -{ - return i < 0 ? IN : i > 0 ? OUT : ON; -} - -inline BOP_TAG BOP_addON(BOP_TAG tag) -{ - return (tag==IN?INON:(tag==OUT?OUTON:tag)); -} - -void BOP_stringTAG(BOP_TAG tag, char *dest); - -inline bool BOP_compTAG(BOP_TAG tag1, BOP_TAG tag2) -{ - return (tag1==tag2) || (BOP_addON(tag1) == BOP_addON(tag2)); -} - -#endif diff --git a/intern/boolop/intern/BOP_Triangulator.cpp b/intern/boolop/intern/BOP_Triangulator.cpp deleted file mode 100644 index 65f7dae1c0c..00000000000 --- a/intern/boolop/intern/BOP_Triangulator.cpp +++ /dev/null @@ -1,573 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file boolop/intern/BOP_Triangulator.cpp - * \ingroup boolopintern - */ - - -#include "BOP_Triangulator.h" -#include <iostream> - -void BOP_addFace(BOP_Mesh* mesh, BOP_Faces *faces, BOP_Face* face, BOP_TAG tag); -void BOP_splitQuad(BOP_Mesh* mesh, MT_Plane3 plane, BOP_Index v1, BOP_Index v2, BOP_Index v3, BOP_Index v4, - BOP_Face* triangles[], BOP_Index original); -BOP_Index BOP_getTriangleVertex(BOP_Mesh* mesh, BOP_Index v1, BOP_Index v2, BOP_Index v3, BOP_Index v4); -BOP_Index BOP_getNearestVertex(BOP_Mesh* mesh, BOP_Index u, BOP_Index v1, BOP_Index v2); -bool BOP_isInsideCircle(BOP_Mesh* mesh, BOP_Index v1, BOP_Index v2, BOP_Index v3, BOP_Index v4, BOP_Index v5); -bool BOP_isInsideCircle(BOP_Mesh* mesh, BOP_Index v1, BOP_Index v2, BOP_Index v3, BOP_Index w); -void BOP_triangulateC_split(BOP_Mesh* mesh, BOP_Faces* faces, BOP_Face* face, - BOP_Index v1, BOP_Index v2, BOP_Index v3, BOP_Index v4, BOP_Index v5); -void BOP_triangulateD_split(BOP_Mesh* mesh, BOP_Faces* faces, BOP_Face* face, - BOP_Index v1, BOP_Index v2, BOP_Index v3, BOP_Index v4, BOP_Index v5); - -/** - * Triangulates the face in two new faces by splitting one edge. - * - * * - * /|\ - * / | \ - * / | \ - * / | \ - * / | \ - * *-----x-----* - * - * @param mesh mesh that contains the faces, edges and vertices - * @param faces set of faces that contains face and will contains new faces - * @param face input face to be triangulate - * @param v vertex index that intersects the edge - * @param e relative edge index used to triangulate the face - */ - - -void BOP_triangulateA(BOP_Mesh *mesh, BOP_Faces *faces, BOP_Face * face, BOP_Index v, unsigned int e) -{ - BOP_Face *face1, *face2; - if (e == 1) { - face1 = new BOP_Face3(face->getVertex(0), v, face->getVertex(2), face->getPlane(), - face->getOriginalFace()); - face2 = new BOP_Face3(v, face->getVertex(1), face->getVertex(2), face->getPlane(), - face->getOriginalFace()); - } - else if (e == 2) { - face1 = new BOP_Face3(face->getVertex(0), face->getVertex(1), v, face->getPlane(), - face->getOriginalFace()); - face2 = new BOP_Face3(face->getVertex(0), v, face->getVertex(2), face->getPlane(), - face->getOriginalFace()); - } - else if (e == 3) { - face1 = new BOP_Face3(face->getVertex(0), face->getVertex(1), v, face->getPlane(), - face->getOriginalFace()); - face2 = new BOP_Face3(face->getVertex(1), face->getVertex(2), v, face->getPlane(), - face->getOriginalFace()); - } - else { - return; - } - - BOP_addFace(mesh, faces, face1, face->getTAG()); - BOP_addFace(mesh, faces, face2, face->getTAG()); - face1->setSplit(face->getSplit()); - face2->setSplit(face->getSplit()); - - face->setTAG(BROKEN); - face->freeBBox(); -} - -/** - * Triangulates the face in three new faces by one inner point. - * - * * - * / \ - * / \ - * / \ - * / x \ - * / \ - * *-----------* - * - * @param mesh mesh that contains the faces, edges and vertices - * @param faces set of faces that contains face and will contains new faces - * @param face input face to be triangulate - * @param v vertex index that lays inside face - */ -void BOP_triangulateB(BOP_Mesh* mesh, BOP_Faces* faces, BOP_Face* face, BOP_Index v) -{ - BOP_Face *face1 = new BOP_Face3(face->getVertex(0), face->getVertex(1), v, face->getPlane(), - face->getOriginalFace()); - BOP_Face *face2 = new BOP_Face3(face->getVertex(1), face->getVertex(2), v, face->getPlane(), - face->getOriginalFace()); - BOP_Face *face3 = new BOP_Face3(face->getVertex(2), face->getVertex(0), v, face->getPlane(), - face->getOriginalFace()); - - BOP_addFace(mesh,faces,face1,face->getTAG()); - BOP_addFace(mesh,faces,face2,face->getTAG()); - BOP_addFace(mesh,faces,face3,face->getTAG()); - face1->setSplit(face->getSplit()); - face2->setSplit(face->getSplit()); - face3->setSplit(face->getSplit()); - face->setTAG(BROKEN); - face->freeBBox(); -} - - -/** - * Triangulates the face in five new faces by two inner points. - * - * * - * / \ - * / \ - * / \ - * / x x \ - * / \ - * *-----------* - * - * @param mesh mesh that contains the faces, edges and vertices - * @param faces set of faces that contains face and will contains new faces - * @param face input face to be triangulate - * @param v1 first vertex index that lays inside face - * @param v2 second vertex index that lays inside face - */ -void BOP_triangulateC(BOP_Mesh* mesh, BOP_Faces* faces, BOP_Face* face, BOP_Index v1, BOP_Index v2) -{ - if (!BOP_isInsideCircle(mesh, face->getVertex(0), v1, v2, face->getVertex(1), face->getVertex(2))) { - BOP_triangulateC_split(mesh, faces, face, face->getVertex(0), face->getVertex(1), - face->getVertex(2), v1, v2); - } - else if (!BOP_isInsideCircle(mesh, face->getVertex(1), v1, v2, face->getVertex(0), face->getVertex(2))) { - BOP_triangulateC_split(mesh, faces, face, face->getVertex(1), face->getVertex(2), - face->getVertex(0), v1, v2); - } - else if (!BOP_isInsideCircle(mesh, face->getVertex(2), v1, v2, face->getVertex(0), face->getVertex(1))) { - BOP_triangulateC_split(mesh, faces, face, face->getVertex(2), face->getVertex(0), - face->getVertex(1), v1, v2); - } - else { - BOP_triangulateC_split(mesh, faces, face, face->getVertex(2), face->getVertex(0), - face->getVertex(1), v1, v2); - } -} - -/** - * Triangulates the face (v1,v2,v3) in five new faces by two inner points (v4,v5), where - * v1 v4 v5 defines the nice triangle and v4 v5 v2 v3 defines the quad to be tessellated. - * @param mesh mesh that contains the faces, edges and vertices - * @param faces set of faces that contains face and will contains new faces - * @param face input face to be triangulate - * @param v1 first vertex index that defines the original triangle - * @param v2 second vertex index that defines the original triangle - * @param v3 third vertex index that defines the original triangle - * @param v4 first vertex index that lays inside face - * @param v5 second vertex index that lays inside face - */ -void BOP_triangulateC_split(BOP_Mesh* mesh, BOP_Faces* faces, BOP_Face* face, - BOP_Index v1, BOP_Index v2, BOP_Index v3, BOP_Index v4, BOP_Index v5) -{ - BOP_Index v = BOP_getTriangleVertex(mesh, v1, v2, v4, v5); - BOP_Index w = (v == v4 ? v5 : v4); - BOP_Face *face1 = new BOP_Face3(v1, v, w, face->getPlane(), face->getOriginalFace()); - BOP_Face *face2 = new BOP_Face3(v1, v2, v, face->getPlane(), face->getOriginalFace()); - BOP_Face *face3 = new BOP_Face3(v1, w, v3, face->getPlane(), face->getOriginalFace()); - - // v1 v w defines the nice triangle in the correct order - // v1 v2 v defines one lateral triangle in the correct order - // v1 w v3 defines the other lateral triangle in the correct order - // w v v2 v3 defines the quad in the correct order - - BOP_addFace(mesh, faces, face1, face->getTAG()); - BOP_addFace(mesh, faces, face2, face->getTAG()); - BOP_addFace(mesh, faces, face3, face->getTAG()); - - face1->setSplit(face->getSplit()); - face2->setSplit(face->getSplit()); - face3->setSplit(face->getSplit()); - - BOP_Face *faces45[2]; - - BOP_splitQuad(mesh, face->getPlane(), v2, v3, w, v, faces45, face->getOriginalFace()); - BOP_addFace(mesh, faces, faces45[0], face->getTAG()); - BOP_addFace(mesh, faces, faces45[1], face->getTAG()); - faces45[0]->setSplit(face->getSplit()); - faces45[1]->setSplit(face->getSplit()); - - face->setTAG(BROKEN); - face->freeBBox(); -} - - -/** - * Triangulates the face in three new faces by splitting twice an edge. - * - * * - * / \ - * / \ - * / \ - * / \ - * / \ - * *---x---x---* - * - * @param mesh mesh that contains the faces, edges and vertices - * @param faces set of faces that contains face and will contains new faces - * @param face input face to be triangulate - * @param v1 first vertex index that intersects the edge - * @param v2 second vertex index that intersects the edge - * @param e relative edge index used to triangulate the face - */ -void BOP_triangulateD(BOP_Mesh* mesh, BOP_Faces* faces, BOP_Face* face, BOP_Index v1, - BOP_Index v2, unsigned int e) -{ - if (e == 1) { - BOP_triangulateD_split(mesh, faces, face, face->getVertex(0), face->getVertex(1), - face->getVertex(2), v1, v2); - } - else if (e == 2) { - BOP_triangulateD_split(mesh, faces, face, face->getVertex(1), face->getVertex(2), - face->getVertex(0), v1, v2); - } - else if (e == 3) { - BOP_triangulateD_split(mesh, faces, face, face->getVertex(2), face->getVertex(0), - face->getVertex(1), v1, v2); - } -} - -/** - * Triangulates the face (v1,v2,v3) in three new faces by splitting twice an edge. - * @param mesh mesh that contains the faces, edges and vertices - * @param faces set of faces that contains face and will contains new faces - * @param face input face to be triangulate - * @param v1 first vertex index that defines the original triangle - * @param v2 second vertex index that defines the original triangle - * @param v3 third vertex index that defines the original triangle - * @param v4 first vertex index that lays on the edge - * @param v5 second vertex index that lays on the edge - */ -void BOP_triangulateD_split(BOP_Mesh* mesh, BOP_Faces* faces, BOP_Face* face, - BOP_Index v1, BOP_Index v2, BOP_Index v3, BOP_Index v4, BOP_Index v5) -{ - BOP_Index v = BOP_getNearestVertex(mesh, v1, v4, v5); - BOP_Index w = (v == v4 ? v5 : v4); - BOP_Face *face1 = new BOP_Face3(v1, v, v3, face->getPlane(), face->getOriginalFace()); - BOP_Face *face2 = new BOP_Face3(v, w, v3, face->getPlane(), face->getOriginalFace()); - BOP_Face *face3 = new BOP_Face3(w, v2, v3, face->getPlane(), face->getOriginalFace()); - - BOP_addFace(mesh, faces, face1, face->getTAG()); - BOP_addFace(mesh, faces, face2, face->getTAG()); - BOP_addFace(mesh, faces, face3, face->getTAG()); - face1->setSplit(face->getSplit()); - face2->setSplit(face->getSplit()); - face3->setSplit(face->getSplit()); - - face->setTAG(BROKEN); - face->freeBBox(); -} - - -/** - * Triangulates the face in three new faces by splitting two edges. - * - * * - * / \ - * / \ - * x x - * / \ - * / \ - * *-----------* - * - * @param mesh mesh that contains the faces, edges and vertices - * @param faces set of faces that contains face and will contains new faces - * @param face input face to be triangulate - * @param v1 vertex index that intersects the first edge - * @param v1 vertex index that intersects the second edge - * @param e1 first relative edge index used to triangulate the face - * @param e2 second relative edge index used to triangulate the face - */ -void BOP_triangulateE(BOP_Mesh* mesh, BOP_Faces* faces, BOP_Face* face, - BOP_Index v1, BOP_Index v2, unsigned int e1, unsigned int e2) -{ - // Sort the edges to reduce the cases - if (e1 > e2) { - unsigned int aux = e1; - e1 = e2; - e2 = aux; - aux = v1; - v1 = v2; - v2 = aux; - } - // e1 < e2! - BOP_Face *face1; - BOP_Face *faces23[2]; - if (e1 == 1 && e2 == 2) { - // the vertex is 2 - face1 = new BOP_Face3(face->getVertex(1), v2, v1, face->getPlane(), - face->getOriginalFace()); - BOP_splitQuad(mesh, face->getPlane(), face->getVertex(2), face->getVertex(0), v1, v2, - faces23, face->getOriginalFace()); - } - else if (e1 == 1 && e2 == 3) { - // the vertex is 1 - face1 = new BOP_Face3(face->getVertex(0), v1, v2, face->getPlane(), - face->getOriginalFace()); - BOP_splitQuad(mesh, face->getPlane(), face->getVertex(1), face->getVertex(2), v2, v1, - faces23, face->getOriginalFace()); - } - else if (e1 == 2 && e2 == 3) { - // the vertex is 3 - face1 = new BOP_Face3(face->getVertex(2), v2, v1, face->getPlane(), - face->getOriginalFace()); - BOP_splitQuad(mesh, face->getPlane(), face->getVertex(0), face->getVertex(1), v1, v2, - faces23, face->getOriginalFace()); - } - else { - return; - } - - BOP_addFace(mesh, faces, face1, face->getTAG()); - BOP_addFace(mesh, faces, faces23[0], face->getTAG()); - BOP_addFace(mesh, faces, faces23[1], face->getTAG()); - face1->setSplit(face->getSplit()); - faces23[0]->setSplit(face->getSplit()); - faces23[1]->setSplit(face->getSplit()); - face->setTAG(BROKEN); - face->freeBBox(); -} - -/** - * Triangulates the face in four new faces by one edge and one inner point. - * - * * - * / \ - * / \ - * x x \ - * / \ - * / \ - * *-----------* - * - * @param mesh mesh that contains the faces, edges and vertices - * @param faces set of faces that contains face and will contains new faces - * @param face input face to be triangulate - * @param v1 vertex index that lays inside face - * @param v2 vertex index that intersects the edge - * @param e relative edge index used to triangulate the face - */ -void BOP_triangulateF(BOP_Mesh* mesh, BOP_Faces* faces, BOP_Face* face, - BOP_Index v1, BOP_Index v2, unsigned int e) -{ - BOP_Face *faces12[2]; - BOP_Face *faces34[2]; - if (e == 1) { - BOP_splitQuad(mesh, face->getPlane(), face->getVertex(2), face->getVertex(0), v2, v1, - faces12, face->getOriginalFace()); - BOP_splitQuad(mesh, face->getPlane(), face->getVertex(1), face->getVertex(2), v1, v2, - faces34, face->getOriginalFace()); - } - else if (e == 2) { - BOP_splitQuad(mesh, face->getPlane(), face->getVertex(0), face->getVertex(1), v2, v1, - faces12, face->getOriginalFace()); - BOP_splitQuad(mesh, face->getPlane(), face->getVertex(2), face->getVertex(0), v1, v2, - faces34, face->getOriginalFace()); - } - else if (e==3) { - BOP_splitQuad(mesh, face->getPlane(), face->getVertex(1), face->getVertex(2), v2, v1, - faces12, face->getOriginalFace()); - BOP_splitQuad(mesh, face->getPlane(), face->getVertex(0), face->getVertex(1), v1, v2, - faces34, face->getOriginalFace()); - } - else { - return; - } - - BOP_addFace(mesh, faces, faces12[0], face->getTAG()); - BOP_addFace(mesh, faces, faces12[1], face->getTAG()); - BOP_addFace(mesh, faces, faces34[0], face->getTAG()); - BOP_addFace(mesh, faces, faces34[1], face->getTAG()); - faces12[0]->setSplit(face->getSplit()); - faces12[1]->setSplit(face->getSplit()); - faces34[0]->setSplit(face->getSplit()); - faces34[1]->setSplit(face->getSplit()); - - face->setTAG(BROKEN); - face->freeBBox(); -} - -/** - * Adds the new face into the faces set and the mesh and sets it a new tag. - * @param mesh mesh that contains the faces, edges and vertices - * @param faces set of faces that contains oldFace - * @param face input face to be added - * @param tag tag of the new face - */ -void BOP_addFace(BOP_Mesh* mesh, BOP_Faces* faces, BOP_Face* face, BOP_TAG tag) -{ - BOP_Index av1 = face->getVertex(0); - BOP_Index av2 = face->getVertex(1); - BOP_Index av3 = face->getVertex(2); - - /* - * Before adding a new face to the face list, be sure it's not - * already there. Duplicate faces have been found to cause at - * least two instances of infinite loops. Also, some faces are - * created which have the same vertex twice. Don't add these either. - * - * When someone has more time to look into this issue, it's possible - * this code may be removed again. - */ - if( av1==av2 || av2==av3 || av3==av1 ) return; - - for(unsigned int idxFace=0;idxFace<faces->size();idxFace++) { - BOP_Face *faceA = (*faces)[idxFace]; - BOP_Index bv1 = faceA->getVertex(0); - BOP_Index bv2 = faceA->getVertex(1); - BOP_Index bv3 = faceA->getVertex(2); - - if( ( av1==bv1 && av2==bv2 && av3==bv3 ) || - ( av1==bv1 && av2==bv3 && av3==bv2 ) || - ( av1==bv2 && av2==bv1 && av3==bv3 ) || - ( av1==bv2 && av2==bv3 && av3==bv1 ) || - ( av1==bv3 && av2==bv2 && av3==bv1 ) || - ( av1==bv3 && av2==bv1 && av3==bv3 ) ) - return; - } - - face->setTAG(tag); - faces->push_back(face); - mesh->addFace(face); -} - -/** - * Computes the best quad triangulation. - * @param mesh mesh that contains the faces, edges and vertices - * @param plane plane used to create the news faces - * @param v1 first vertex index - * @param v2 second vertex index - * @param v3 third vertex index - * @param v4 fourth vertex index - * @param triangles array of faces where the new two faces will be saved - * @param original face index to the new faces - */ -void BOP_splitQuad(BOP_Mesh* mesh, MT_Plane3 plane, BOP_Index v1, BOP_Index v2, - BOP_Index v3, BOP_Index v4, BOP_Face* triangles[], BOP_Index original) -{ - MT_Point3 p1 = mesh->getVertex(v1)->getPoint(); - MT_Point3 p2 = mesh->getVertex(v2)->getPoint(); - MT_Point3 p3 = mesh->getVertex(v3)->getPoint(); - MT_Point3 p4 = mesh->getVertex(v4)->getPoint(); - - int res = BOP_concave(p1,p2,p3,p4); - - if (res==0) { - MT_Plane3 plane1(p1, p2, p3); - MT_Plane3 plane2(p1, p3, p4); - - if (BOP_isInsideCircle(mesh, v1, v2, v4, v3) && - BOP_orientation(plane1, plane) && - BOP_orientation(plane2, plane)) { - triangles[0] = new BOP_Face3(v1, v2, v3, plane, original); - triangles[1] = new BOP_Face3(v1, v3, v4, plane, original); - } - else { - triangles[0] = new BOP_Face3(v1, v2, v4, plane, original); - triangles[1] = new BOP_Face3(v2, v3, v4, plane, original); - } - } - else if (res==-1) { - triangles[0] = new BOP_Face3(v1, v2, v4, plane, original); - triangles[1] = new BOP_Face3(v2, v3, v4, plane, original); - } - else { - triangles[0] = new BOP_Face3(v1, v2, v3, plane, original); - triangles[1] = new BOP_Face3(v1, v3, v4, plane, original); - } -} - -/** - * Returns the vertex (v3 or v4) that splits the quad (v1,v2,v3,v4) in the best pair of triangles. - * @param mesh mesh that contains the faces, edges and vertices - * @param v1 first vertex index - * @param v2 second vertex index - * @param v3 third vertex index - * @param v4 fourth vertex index - * @return v3 if the best split triangles are (v1,v2,v3) and (v1,v3,v4), v4 otherwise - */ -BOP_Index BOP_getTriangleVertex(BOP_Mesh* mesh, BOP_Index v1, BOP_Index v2, BOP_Index v3, BOP_Index v4) -{ - if (BOP_isInsideCircle(mesh, v1, v2, v4, v3)) { - return v3; - } - return v4; -} - -/** - * Returns which of vertex v1 or v2 is nearest to u. - * @param mesh mesh that contains the faces, edges and vertices - * @param u reference vertex index - * @param v1 first vertex index - * @param v2 second vertex index - * @return the nearest vertex index - */ -BOP_Index BOP_getNearestVertex(BOP_Mesh* mesh, BOP_Index u, BOP_Index v1, BOP_Index v2) -{ - MT_Point3 q = mesh->getVertex(u)->getPoint(); - MT_Point3 p1 = mesh->getVertex(v1)->getPoint(); - MT_Point3 p2 = mesh->getVertex(v2)->getPoint(); - if (BOP_comp(q.distance(p1), q.distance(p2)) > 0) return v2; - else return v1; -} - -/** - * Computes if vertexs v4 and v5 are not inside the circle defined by v1,v2,v3 (seems to be a nice triangle) - * @param mesh mesh that contains the faces, edges and vertices - * @param v1 first vertex index - * @param v2 second vertex index - * @param v3 third vertex index - * @param v4 fourth vertex index - * @param v5 five vertex index - * @return if v1,v2,v3 defines a nice triangle against v4,v5 - */ -bool BOP_isInsideCircle(BOP_Mesh* mesh, BOP_Index v1, BOP_Index v2, BOP_Index v3, BOP_Index v4, BOP_Index v5) -{ - return BOP_isInsideCircle(mesh->getVertex(v1)->getPoint(), - mesh->getVertex(v2)->getPoint(), - mesh->getVertex(v3)->getPoint(), - mesh->getVertex(v4)->getPoint(), - mesh->getVertex(v5)->getPoint()); -} - -/** - * Computes if vertex w is not inside the circle defined by v1,v2,v3 (seems to be a nice triangle) - * @param mesh mesh that contains the faces, edges and vertices - * @param v1 first vertex index - * @param v2 second vertex index - * @param v3 third vertex index - * @param w fourth vertex index - * @return if v1,v2,v3 defines a nice triangle against w - */ -bool BOP_isInsideCircle(BOP_Mesh* mesh, BOP_Index v1, BOP_Index v2, BOP_Index v3, BOP_Index w) -{ - return BOP_isInsideCircle(mesh->getVertex(v1)->getPoint(), - mesh->getVertex(v2)->getPoint(), - mesh->getVertex(v3)->getPoint(), - mesh->getVertex(w)->getPoint()); -} diff --git a/intern/boolop/intern/BOP_Triangulator.h b/intern/boolop/intern/BOP_Triangulator.h deleted file mode 100644 index 55dd51d09c3..00000000000 --- a/intern/boolop/intern/BOP_Triangulator.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file boolop/intern/BOP_Triangulator.h - * \ingroup boolopintern - */ - - -#ifndef __BOP_TRIANGULATOR_H__ -#define __BOP_TRIANGULATOR_H__ - -#include "BOP_MathUtils.h" -#include "BOP_Mesh.h" - -void BOP_triangulateA(BOP_Mesh *mesh, BOP_Faces *faces, BOP_Face * face, BOP_Index v, unsigned int e); -void BOP_triangulateB(BOP_Mesh * mesh, BOP_Faces *faces, BOP_Face * face, BOP_Index v); -void BOP_triangulateC(BOP_Mesh * mesh, BOP_Faces *faces, BOP_Face * face, BOP_Index v1, BOP_Index v2); -void BOP_triangulateD(BOP_Mesh * mesh, BOP_Faces *faces, BOP_Face * face, BOP_Index v1, BOP_Index v2, unsigned int e); -void BOP_triangulateE(BOP_Mesh *mesh, BOP_Faces *faces, BOP_Face * face, BOP_Index v1, BOP_Index v2, unsigned int e1, unsigned int e2); -void BOP_triangulateF(BOP_Mesh *mesh, BOP_Faces *faces, BOP_Face * face, BOP_Index v1, BOP_Index v2, unsigned int e); - -#endif diff --git a/intern/boolop/intern/BOP_Vertex.cpp b/intern/boolop/intern/BOP_Vertex.cpp deleted file mode 100644 index a3377156f9d..00000000000 --- a/intern/boolop/intern/BOP_Vertex.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file boolop/intern/BOP_Vertex.cpp - * \ingroup boolopintern - */ - - -#include "BOP_Vertex.h" - -/** - * Constructs a new vertex with the specified coordinates. - * @param x X-axis coordinate - * @param y Y-axis coordinate - * @param z Z-axis coordinate - */ -BOP_Vertex::BOP_Vertex(double x, double y, double z) -{ - m_point.setValue(x,y,z); - m_tag = UNCLASSIFIED; -} - -/** - * Constructs a new vertex with the specified point. - * @param p point XYZ - */ -BOP_Vertex::BOP_Vertex(MT_Point3 p) -{ - m_point = p; - m_tag = UNCLASSIFIED; -} - -/** - * Adds a new edge index to this vertex. - * @param i edge index - */ -void BOP_Vertex::addEdge(BOP_Index i) -{ - if (!containsEdge(i)) - m_edges.push_back(i); -} - -/** - * Removes an edge index from this vertex. - * @param i edge index - */ -void BOP_Vertex::removeEdge(BOP_Index i) -{ - for(BOP_IT_Indexs it = m_edges.begin();it!=m_edges.end();it++) { - if ((*it)==i) { - m_edges.erase(it); - return; - } - } -} - -/** - * Returns if this vertex contains the specified edge index. - * @param i edge index - * @return true if this vertex contains the specified edge index, false otherwise - */ -bool BOP_Vertex::containsEdge(BOP_Index i) -{ - int pos=0; - for(BOP_IT_Indexs it = m_edges.begin();it!=m_edges.end();pos++,it++) { - if ((*it)==i){ - return true; - } - } - - return false; -} - -#ifdef BOP_DEBUG -/** - * Implements operator <<. - */ -#include <iomanip> - -ostream &operator<<(ostream &stream, BOP_Vertex *v) -{ - char aux[20]; - BOP_stringTAG(v->m_tag,aux); - MT_Point3 point = v->getPoint(); - stream << setprecision(6) << showpoint << fixed; - stream << "Vertex[" << point[0] << "," << point[1] << ","; - stream << point[2] << "] (" << aux << ")"; - return stream; -} -#endif - diff --git a/intern/boolop/intern/BOP_Vertex.h b/intern/boolop/intern/BOP_Vertex.h deleted file mode 100644 index 1aae2207972..00000000000 --- a/intern/boolop/intern/BOP_Vertex.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file boolop/intern/BOP_Vertex.h - * \ingroup boolopintern - */ - - -#ifndef __BOP_VERTEX_H__ -#define __BOP_VERTEX_H__ - -#include "BOP_Tag.h" -#include "BOP_Indexs.h" -#include "MT_Point3.h" -#include "BOP_Misc.h" - -class BOP_Vertex -{ -private: - MT_Point3 m_point; - BOP_Indexs m_edges; - BOP_TAG m_tag; - - bool containsEdge(BOP_Index i); - -public: - BOP_Vertex(double x, double y, double z); - BOP_Vertex(MT_Point3 d); - void addEdge(BOP_Index i); - void removeEdge(BOP_Index i); - inline BOP_Index getEdge(unsigned int i) { return m_edges[i];}; - inline unsigned int getNumEdges() { return m_edges.size();}; - inline BOP_Indexs &getEdges() { return m_edges;}; - inline MT_Point3 getPoint() const { return m_point;}; - inline BOP_TAG getTAG() { return m_tag;}; - inline void setTAG(BOP_TAG t) { m_tag = t;}; -#ifdef BOP_DEBUG - friend ostream &operator<<(ostream &stream, BOP_Vertex *v); -#endif - -}; - -#endif diff --git a/intern/bsp/CMakeLists.txt b/intern/bsp/CMakeLists.txt index 6a337b99be9..e492c04423e 100644 --- a/intern/bsp/CMakeLists.txt +++ b/intern/bsp/CMakeLists.txt @@ -29,6 +29,7 @@ set(INC ../guardedalloc ../memutil ../moto/include + ../../extern/carve/include ) set(INC_SYS @@ -36,15 +37,34 @@ set(INC_SYS ) set(SRC + intern/BOP_CarveInterface.cpp intern/BSP_CSGMesh.cpp intern/BSP_MeshPrimitives.cpp intern/CSG_BooleanOps.cpp extern/CSG_BooleanOps.h + intern/BOP_Interface.h intern/BSP_CSGException.h intern/BSP_CSGMesh.h intern/BSP_CSGMesh_CFIterator.h intern/BSP_MeshPrimitives.h ) +if(WITH_BOOST) + if(NOT MSVC) + # Boost is setting as preferred collections library in the Carve code when using MSVC compiler + add_definitions( + -DHAVE_BOOST_UNORDERED_COLLECTIONS + ) + endif() + + add_definitions( + -DCARVE_SYSTEM_BOOST + ) + + list(APPEND INC + ${BOOST_INCLUDE_DIR} + ) +endif() + blender_add_lib(bf_intern_bsp "${SRC}" "${INC}" "${INC_SYS}") diff --git a/intern/bsp/SConscript b/intern/bsp/SConscript index 4927c33dc8a..d3f7cf1c6ec 100644 --- a/intern/bsp/SConscript +++ b/intern/bsp/SConscript @@ -3,7 +3,21 @@ Import ('env') sources = env.Glob('intern/*.cpp') -incs = 'intern ../container ../moto/include ../memutil ../guardedalloc' +incs = 'intern ../container ../moto/include ../memutil ../guardedalloc ../../extern/carve/include' -env.BlenderLib ('bf_intern_bsp', sources, Split(incs), [], libtype=['core','player'], priority=[200,100] ) +defs = [] + +if env['WITH_BF_BOOST']: + isMINGW = env['OURPLATFORM'] in ('win32-mingw', 'win64-mingw') + + if env['OURPLATFORM'] not in ('win32-vc', 'win64-vc') and not isMINGW: + # Boost is setting as preferred collections library in the Carve code when using MSVC compiler + defs.append('HAVE_BOOST_UNORDERED_COLLECTIONS') + + if not isMINGW: + defs.append('CARVE_SYSTEM_BOOST') + + incs += ' ' + env['BF_BOOST_INC'] + +env.BlenderLib ('bf_intern_bsp', sources, Split(incs), defs, libtype=['core','player'], priority=[200,100] ) diff --git a/intern/boolop/intern/BOP_CarveInterface.cpp b/intern/bsp/intern/BOP_CarveInterface.cpp index 4b3bda113fd..255d885007c 100644 --- a/intern/boolop/intern/BOP_CarveInterface.cpp +++ b/intern/bsp/intern/BOP_CarveInterface.cpp @@ -26,12 +26,12 @@ * ***** END GPL LICENSE BLOCK ***** */ -/** \file boolop/intern/BOP_CarveInterface.cpp - * \ingroup boolopintern +/** \file bsp/intern/BOP_CarveInterface.cpp + * \ingroup bsp */ -#include "../extern/BOP_Interface.h" -#include "../../bsp/intern/BSP_CSGMesh_CFIterator.h" +#include "BOP_Interface.h" +#include "BSP_CSGMesh_CFIterator.h" #include <carve/csg_triangulator.hpp> #include <carve/interpolator.hpp> diff --git a/intern/boolop/extern/BOP_Interface.h b/intern/bsp/intern/BOP_Interface.h index fbada7dcab5..c7402388a29 100644 --- a/intern/boolop/extern/BOP_Interface.h +++ b/intern/bsp/intern/BOP_Interface.h @@ -26,13 +26,13 @@ */ /** \file BOP_Interface.h - * \ingroup boolop + * \ingroup bsp */ #ifndef __BOP_INTERFACE_H__ #define __BOP_INTERFACE_H__ -#include "../../bsp/intern/BSP_CSGMesh.h" +#include "BSP_CSGMesh.h" typedef enum EnumBoolOpState {BOP_OK, BOP_NO_SOLID, BOP_ERROR} BoolOpState; typedef enum EnumBoolOpType {BOP_INTERSECTION=e_csg_intersection, BOP_UNION=e_csg_union, BOP_DIFFERENCE=e_csg_difference} BoolOpType; diff --git a/intern/bsp/intern/CSG_BooleanOps.cpp b/intern/bsp/intern/CSG_BooleanOps.cpp index df1374ef10b..4f71e7992a1 100644 --- a/intern/bsp/intern/CSG_BooleanOps.cpp +++ b/intern/bsp/intern/CSG_BooleanOps.cpp @@ -31,7 +31,6 @@ /** - * Implementation of external api for CSG part of BSP lib interface. */ @@ -39,7 +38,7 @@ #include "BSP_CSGMesh_CFIterator.h" #include "MEM_RefCountPtr.h" -#include "../../boolop/extern/BOP_Interface.h" +#include "BOP_Interface.h" #include <iostream> using namespace std; diff --git a/intern/bsp/test/BSP_GhostTest/BSP_GhostTest.dsp b/intern/bsp/test/BSP_GhostTest/BSP_GhostTest.dsp deleted file mode 100644 index 4474eaa5d90..00000000000 --- a/intern/bsp/test/BSP_GhostTest/BSP_GhostTest.dsp +++ /dev/null @@ -1,126 +0,0 @@ -# Microsoft Developer Studio Project File - Name="BSP_GhostTest" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Console Application" 0x0103
-
-CFG=BSP_GhostTest - Win32 Debug
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "BSP_GhostTest.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "BSP_GhostTest.mak" CFG="BSP_GhostTest - Win32 Debug"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "BSP_GhostTest - Win32 Release" (based on "Win32 (x86) Console Application")
-!MESSAGE "BSP_GhostTest - Win32 Debug" (based on "Win32 (x86) Console Application")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "BSP_GhostTest - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release"
-# PROP BASE Intermediate_Dir "Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release"
-# PROP Intermediate_Dir "Release"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD CPP /nologo /G6 /MT /W3 /GX /O2 /Ob2 /I "../../extern/" /I "../../../../lib/windows/string/include" /I "../../../../lib/windows/ghost/include" /I "../../../../lib/windows/moto/include" /I "../../../../lib/windows/memutil/include" /I "../../../../lib/windows/container/include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD BASE RSC /l 0x413 /d "NDEBUG"
-# ADD RSC /l 0x413 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
-# ADD LINK32 glu32.lib opengl32.lib kernel32.lib user32.lib gdi32.lib /nologo /subsystem:console /machine:I386 /libpath:"..\..\..\..\lib\windows\glut-3.7\lib\\"
-
-!ELSEIF "$(CFG)" == "BSP_GhostTest - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug"
-# PROP BASE Intermediate_Dir "Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Debug"
-# PROP Intermediate_Dir "Debug"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
-# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../../extern/" /I "../../../../lib/windows/string/include" /I "../../../../lib/windows/ghost/include" /I "../../../../lib/windows/moto/include" /I "../../../../lib/windows/memutil/include" /I "../../../../lib/windows/container/include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
-# ADD BASE RSC /l 0x413 /d "_DEBUG"
-# ADD RSC /l 0x413 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 glu32.lib opengl32.lib user32.lib gdi32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\..\..\..\lib\windows\glut-3.7\lib\\"
-
-!ENDIF
-
-# Begin Target
-
-# Name "BSP_GhostTest - Win32 Release"
-# Name "BSP_GhostTest - Win32 Debug"
-# Begin Source File
-
-SOURCE=.\BSP_GhostTest3D.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\BSP_GhostTest3D.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\BSP_MeshDrawer.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\BSP_MeshDrawer.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\BSP_PlyLoader.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\BSP_PlyLoader.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\BSP_TMesh.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\main.cpp
-# End Source File
-# Begin Source File
-
-SOURCE=.\ply.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\plyfile.c
-# End Source File
-# End Target
-# End Project
diff --git a/intern/bsp/test/BSP_GhostTest/BSP_GhostTest.dsw b/intern/bsp/test/BSP_GhostTest/BSP_GhostTest.dsw deleted file mode 100644 index 0d9ca3d2b08..00000000000 --- a/intern/bsp/test/BSP_GhostTest/BSP_GhostTest.dsw +++ /dev/null @@ -1,125 +0,0 @@ -Microsoft Developer Studio Workspace File, Format Version 6.00
-# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
-
-###############################################################################
-
-Project: "BSP_GhostTest"=.\BSP_GhostTest.dsp - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
- Begin Project Dependency
- Project_Dep_Name bsplib
- End Project Dependency
- Begin Project Dependency
- Project_Dep_Name ghost
- End Project Dependency
- Begin Project Dependency
- Project_Dep_Name string
- End Project Dependency
- Begin Project Dependency
- Project_Dep_Name MoTo
- End Project Dependency
-}}}
-
-###############################################################################
-
-Project: "MoTo"=..\..\..\moto\make\msvc_6_0\MoTo.dsp - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
-}}}
-
-###############################################################################
-
-Project: "bsplib"=..\..\make\msvc6_0\bsplib.dsp - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
- Begin Project Dependency
- Project_Dep_Name container
- End Project Dependency
- Begin Project Dependency
- Project_Dep_Name memutil
- End Project Dependency
- Begin Project Dependency
- Project_Dep_Name MoTo
- End Project Dependency
-}}}
-
-###############################################################################
-
-Project: "container"=..\..\..\container\make\msvc_6_0\container.dsp - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
- Begin Project Dependency
- Project_Dep_Name memutil
- End Project Dependency
-}}}
-
-###############################################################################
-
-Project: "ghost"=..\..\..\ghost\make\msvc\ghost.dsp - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
-}}}
-
-###############################################################################
-
-Project: "memutil"=..\..\..\memutil\make\msvc_60\memutil.dsp - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
-}}}
-
-###############################################################################
-
-Project: "string"=..\..\..\string\make\msvc_6_0\string.dsp - Package Owner=<4>
-
-Package=<5>
-{{{
-}}}
-
-Package=<4>
-{{{
-}}}
-
-###############################################################################
-
-Global:
-
-Package=<5>
-{{{
-}}}
-
-Package=<3>
-{{{
-}}}
-
-###############################################################################
-
diff --git a/intern/bsp/test/BSP_GhostTest/BSP_GhostTest3D.cpp b/intern/bsp/test/BSP_GhostTest/BSP_GhostTest3D.cpp deleted file mode 100644 index 46cde625cf2..00000000000 --- a/intern/bsp/test/BSP_GhostTest/BSP_GhostTest3D.cpp +++ /dev/null @@ -1,649 +0,0 @@ -/** - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** - -* Copyright (C) 2001 NaN Technologies B.V. -*/ -#if defined(WIN32) || defined(__APPLE__) -# ifdef WIN32 -# include <windows.h> -# include <GL/gl.h> -# include <GL/glu.h> -# else // WIN32 -# include <AGL/gl.h> -# endif // WIN32 -#else // defined(WIN32) || defined(__APPLE__) -# include <GL/gl.h> -# include <GL/glu.h> -#endif // defined(WIN32) || defined(__APPLE__) - - -#include "BSP_GhostTest3D.h" -#include "BSP_MeshDrawer.h" - -#include "GHOST_ISystem.h" -#include "GHOST_IWindow.h" - -#include "MT_Quaternion.h" -#include "MT_Transform.h" -#include "CSG_BooleanOps.h" - -#include <iostream> - - int -EmptyInterpFunc( - void *d1, - void * d2, - void *dnew, - float epsilon -){ - return 0; -} - - - -using namespace std; - - -BSP_GhostTestApp3D:: -BSP_GhostTestApp3D( -) : - m_window(NULL), - m_system(NULL), - m_finish_me_off(false), - m_current_object(0) -{ - //nothing to do; -} - - void -BSP_GhostTestApp3D:: -SetMesh( - MEM_SmartPtr<BSP_TMesh> mesh -){ - m_meshes.push_back(mesh); - - BSP_RotationSetting rotation_setting; - BSP_TranslationSetting translation_setting; - - rotation_setting.m_angle_x = MT_Scalar(0); - rotation_setting.m_angle_y = MT_Scalar(0); - rotation_setting.m_moving = false; - rotation_setting.x_old = 0; - rotation_setting.y_old = 0; - - translation_setting.m_t_x = MT_Scalar(0); - translation_setting.m_t_y = MT_Scalar(0); - translation_setting.m_t_z = MT_Scalar(0); - translation_setting.m_moving = false; - translation_setting.x_old = 0; - translation_setting.y_old = 0; - - m_rotation_settings.push_back(rotation_setting); - m_translation_settings.push_back(translation_setting); - m_render_modes.push_back(e_wireframe_shaded); - m_scale_settings.push_back(MT_Scalar(1)); - -} - - void -BSP_GhostTestApp3D:: -Swap( - int i -){ - - if (!m_rotation_settings[i].m_moving && !m_translation_settings[i].m_moving) { - swap(m_meshes[i],m_meshes.back()); - swap(m_rotation_settings[i],m_rotation_settings.back()); - swap(m_translation_settings[i],m_translation_settings.back()); - swap(m_scale_settings[i],m_scale_settings.back()); - swap(m_render_modes[i],m_render_modes.back()); - } -} - - - MT_Transform -BSP_GhostTestApp3D:: -GetTransform( - int i -){ - - MT_Quaternion q_ax(MT_Vector3(0,1,0),m_rotation_settings[i].m_angle_x); - MT_Quaternion q_ay(MT_Vector3(1,0,0),m_rotation_settings[i].m_angle_y); - - MT_Point3 tr( - m_translation_settings[i].m_t_x, - m_translation_settings[i].m_t_y, - m_translation_settings[i].m_t_z - ); - - - MT_Matrix3x3 rotx(q_ax); - MT_Matrix3x3 roty(q_ay); - - MT_Matrix3x3 rot = rotx * roty; - - MT_Transform trans(tr,rot); - - MT_Transform scalet; - scalet.setIdentity(); - scalet.scale(m_scale_settings[i],m_scale_settings[i],m_scale_settings[i]); - - return trans * scalet; -} - - void -BSP_GhostTestApp3D:: -Operate( - int type -){ - - CSG_VertexIteratorDescriptor * vA = VertexIt_Construct(m_meshes[0],GetTransform(0)); - CSG_FaceIteratorDescriptor * fA = FaceIt_Construct(m_meshes[0]); - - CSG_VertexIteratorDescriptor * vB = VertexIt_Construct(m_meshes[1],GetTransform(1)); - CSG_FaceIteratorDescriptor * fB = FaceIt_Construct(m_meshes[1]); - - // describe properties. - - CSG_MeshPropertyDescriptor props; - props.user_face_vertex_data_size = 0; - props.user_data_size = 0; - - CSG_BooleanOperation * op = CSG_NewBooleanFunction(); - props = CSG_DescibeOperands(op,props,props); - - CSG_PerformBooleanOperation( - op,CSG_OperationType(type), - *fA,*vA,*fB,*vB,EmptyInterpFunc - ); - - CSG_FaceIteratorDescriptor out_f; - CSG_OutputFaceDescriptor(op,&out_f); - - CSG_VertexIteratorDescriptor out_v; - CSG_OutputVertexDescriptor(op,&out_v); - - MEM_SmartPtr<BSP_TMesh> new_mesh (BuildMesh(props,out_f,out_v)); - - // free stuff - - CSG_FreeVertexDescriptor(&out_v); - CSG_FreeFaceDescriptor(&out_f); - CSG_FreeBooleanOperation(op); - - op = NULL; - SetMesh(new_mesh); -} - - - void -BSP_GhostTestApp3D:: -UpdateFrame( -) { - if (m_window) { - - GHOST_Rect v_rect; - m_window->getClientBounds(v_rect); - - glViewport(0,0,v_rect.getWidth(),v_rect.getHeight()); - - } -} - - -MT_Vector3 -BSP_GhostTestApp3D:: -UnProject( - const MT_Vector3 & vec -) { - - GLint viewport[4]; - GLdouble mvmatrix[16],projmatrix[16]; - - glGetIntegerv(GL_VIEWPORT,viewport); - glGetDoublev(GL_MODELVIEW_MATRIX,mvmatrix); - glGetDoublev(GL_PROJECTION_MATRIX,projmatrix); - - GLdouble realy = viewport[3] - vec.y() - 1; - GLdouble outx,outy,outz; - - gluUnProject(vec.x(),realy,vec.z(),mvmatrix,projmatrix,viewport,&outx,&outy,&outz); - - return MT_Vector3(outx,outy,outz); -} - - - bool -BSP_GhostTestApp3D:: -InitApp( -){ - - // create a system and window with opengl - // rendering context. - - GHOST_TSuccess success = GHOST_ISystem::createSystem(); - if (success == GHOST_kFailure) return false; - - m_system = GHOST_ISystem::getSystem(); - if (m_system == NULL) return false; - - m_system->addEventConsumer(this); - - m_window = m_system->createWindow( - "GHOST crud3D!", - 100,100,512,512,GHOST_kWindowStateNormal, - GHOST_kDrawingContextTypeOpenGL,false - ); - - if ( - m_window == NULL - ) { - m_system = NULL; - GHOST_ISystem::disposeSystem(); - return false; - } - - // make an opengl frustum for this wind - - MT_Vector3 min,max; - - min = m_meshes[0]->m_min; - max = m_meshes[0]->m_max; - InitOpenGl(min,max); - - return true; -} - - void -BSP_GhostTestApp3D:: -Run( -){ - if (m_system == NULL) { - return; - } - - while (!m_finish_me_off) { - m_system->processEvents(true); - m_system->dispatchEvents(); - }; -} - - bool -BSP_GhostTestApp3D:: -processEvent( - GHOST_IEvent* event -){ - - bool handled = false; - - switch(event->getType()) { - case GHOST_kEventWindowSize: - case GHOST_kEventWindowActivate: - UpdateFrame(); - case GHOST_kEventWindowUpdate: - DrawPolies(); - handled = true; - break; - case GHOST_kEventButtonDown: - { - int x,y; - m_system->getCursorPosition(x,y); - - - int wx,wy; - m_window->screenToClient(x,y,wx,wy); - - GHOST_TButtonMask button = - static_cast<GHOST_TEventButtonData *>(event->getData())->button; - - if (button == GHOST_kButtonMaskLeft) { - m_rotation_settings[m_current_object].m_moving = true; - m_rotation_settings[m_current_object].x_old = x; - m_rotation_settings[m_current_object].y_old = y; - } else - if (button == GHOST_kButtonMaskRight) { - m_translation_settings[m_current_object].m_moving = true; - m_translation_settings[m_current_object].x_old = x; - m_translation_settings[m_current_object].y_old = y; - } else - - m_window->invalidate(); - handled = true; - break; - - } - - case GHOST_kEventButtonUp: - { - - GHOST_TButtonMask button = - static_cast<GHOST_TEventButtonData *>(event->getData())->button; - - if (button == GHOST_kButtonMaskLeft) { - m_rotation_settings[m_current_object].m_moving = false; - m_rotation_settings[m_current_object].x_old = 0; - m_rotation_settings[m_current_object].y_old = 0; - - } else - if (button == GHOST_kButtonMaskRight) { - m_translation_settings[m_current_object].m_moving = false; - m_translation_settings[m_current_object].x_old; - m_translation_settings[m_current_object].y_old; - - } - m_window->invalidate(); - handled = true; - break; - - } - - case GHOST_kEventCursorMove: - { - int x,y; - m_system->getCursorPosition(x,y); - int wx,wy; - m_window->screenToClient(x,y,wx,wy); - - if (m_rotation_settings[m_current_object].m_moving) { - m_rotation_settings[m_current_object].m_angle_x = MT_Scalar(wx)/20; - m_rotation_settings[m_current_object].x_old = wx; - m_rotation_settings[m_current_object].m_angle_y = MT_Scalar(wy)/20; - m_rotation_settings[m_current_object].y_old = wy; - - m_window->invalidate(); - } - if (m_translation_settings[m_current_object].m_moving) { - - // project current objects bounding box center into screen space. - // unproject mouse point into object space using z-value from - // projected bounding box center. - - GHOST_Rect bounds; - m_window->getClientBounds(bounds); - - int w_h = bounds.getHeight(); - - y = w_h - wy; - x = wx; - - double mvmatrix[16]; - double projmatrix[16]; - GLint viewport[4]; - - double px, py, pz,sz; - - /* Get the matrices needed for gluUnProject */ - glGetIntegerv(GL_VIEWPORT, viewport); - glGetDoublev(GL_MODELVIEW_MATRIX, mvmatrix); - glGetDoublev(GL_PROJECTION_MATRIX, projmatrix); - - // work out the position of the end effector in screen space - - GLdouble ex,ey,ez; - - ex = m_translation_settings[m_current_object].m_t_x; - ey = m_translation_settings[m_current_object].m_t_y; - ez = m_translation_settings[m_current_object].m_t_z; - - gluProject(ex, ey, ez, mvmatrix, projmatrix, viewport, &px, &py, &sz); - gluUnProject((GLdouble) x, (GLdouble) y, sz, mvmatrix, projmatrix, viewport, &px, &py, &pz); - - m_translation_settings[m_current_object].m_t_x = px; - m_translation_settings[m_current_object].m_t_y = py; - m_translation_settings[m_current_object].m_t_z = pz; - m_window->invalidate(); - - } - - handled = true; - break; - } - - case GHOST_kEventKeyDown : - { - GHOST_TEventKeyData *kd = - static_cast<GHOST_TEventKeyData *>(event->getData()); - - - switch(kd->key) { - case GHOST_kKeyI: - { - // now intersect meshes. - Operate(e_csg_intersection); - handled = true; - m_window->invalidate(); - break; - } - case GHOST_kKeyU: - { - Operate(e_csg_union); - handled = true; - m_window->invalidate(); - break; - } - case GHOST_kKeyD: - { - Operate(e_csg_difference); - handled = true; - m_window->invalidate(); - break; - } - - case GHOST_kKeyA: - { - - m_scale_settings[m_current_object] *= 1.1; - handled = true; - m_window->invalidate(); - break; - } - case GHOST_kKeyZ: - { - m_scale_settings[m_current_object] *= 0.8; - - handled = true; - m_window->invalidate(); - break; - } - - case GHOST_kKeyR: - m_render_modes[m_current_object]++; - if (m_render_modes[m_current_object] > e_last_render_mode) { - m_render_modes[m_current_object] = e_first_render_mode; - } - handled = true; - m_window->invalidate(); - break; - - case GHOST_kKeyB: - handled = true; - m_window->invalidate(); - break; - - case GHOST_kKeyQ: - m_finish_me_off = true; - handled = true; - break; - - case GHOST_kKeyS: - Swap(m_current_object); - m_window->invalidate(); - handled = true; - break; - - case GHOST_kKeySpace: - - // increment the current object only if the object is not being - // manipulated. - if (! (m_rotation_settings[m_current_object].m_moving || m_translation_settings[m_current_object].m_moving)) { - m_current_object ++; - if (m_current_object >= m_meshes.size()) { - m_current_object = 0; - - } - } - m_window->invalidate(); - handled = true; - break; - default : - break; - } - } - - default : - break; - } - return handled; -}; - -BSP_GhostTestApp3D:: -~BSP_GhostTestApp3D( -){ - - if (m_window) { - m_system->disposeWindow(m_window); - m_window = NULL; - GHOST_ISystem::disposeSystem(); - m_system = NULL; - } -}; - - - - void -BSP_GhostTestApp3D:: -DrawPolies( -){ - - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - for (int i = 0; i < m_meshes.size(); ++i) { - MT_Transform trans = GetTransform(i); - - float opengl_mat[16]; - trans.getValue(opengl_mat); - - glPushMatrix(); - glMultMatrixf(opengl_mat); - MT_Vector3 color(1.0,1.0,1.0); - if (i == m_current_object) { - color = MT_Vector3(1.0,0,0); - } - BSP_MeshDrawer::DrawMesh(m_meshes[i].Ref(),m_render_modes[i]); - - glPopMatrix(); - } - - m_window->swapBuffers(); - -} - - void -BSP_GhostTestApp3D:: -InitOpenGl( - const MT_Vector3 &min, - const MT_Vector3 &max -){ - - GLfloat light_diffuse0[] = {1.0, 0.0, 0.0, 0.5}; /* Red diffuse light. */ - GLfloat light_position0[] = {1.0, 1.0, 1.0, 0.0}; /* Infinite light location. */ - - GLfloat light_diffuse1[] = {1.0, 1.0, 1.0, 0.5}; /* Red diffuse light. */ - GLfloat light_position1[] = {1.0, 0, 0, 0.0}; /* Infinite light location. */ - - /* Enable a single OpenGL light. */ - - glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse0); - glLightfv(GL_LIGHT0, GL_POSITION, light_position0); - - glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse1); - glLightfv(GL_LIGHT1, GL_POSITION, light_position1); - - - glEnable(GL_LIGHT0); - glEnable(GL_LIGHT1); - glEnable(GL_LIGHTING); - - // make sure there is no back face culling. - // glDisable(GL_CULL_FACE); - - // use two sided lighting model - glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE); - - /* Use depth buffering for hidden surface elimination. */ - - glEnable(GL_DEPTH_TEST); - - /* Setup the view of the cube. */ - - glMatrixMode(GL_PROJECTION); - - // center of the box + 3* depth of box - - MT_Vector3 center = (min + max) * 0.5; - MT_Vector3 diag = max - min; - - float depth = diag.length(); - float distance = 5; - - gluPerspective( - /* field of view in degree */ 40.0, - /* aspect ratio */ 1.0, - /* Z near */ 1.0, - /* Z far */ distance * depth * 2 - ); - glMatrixMode(GL_MODELVIEW); - - gluLookAt( - center.x(), center.y(), center.z() + distance*depth, //eye - center.x(), center.y(), center.z(), //center - 0.0, 1.0, 0. - ); /* up is in positive Y direction */ - -} - - - - - - - - - - - - - - - - - - - - - diff --git a/intern/bsp/test/BSP_GhostTest/BSP_GhostTest3D.h b/intern/bsp/test/BSP_GhostTest/BSP_GhostTest3D.h deleted file mode 100644 index 8bfa6d061ee..00000000000 --- a/intern/bsp/test/BSP_GhostTest/BSP_GhostTest3D.h +++ /dev/null @@ -1,159 +0,0 @@ -/** - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -#ifndef __BSP_GHOSTTEST3D_H__ -#define __BSP_GHOSTTEST3D_H__ - -#include "GHOST_IEventConsumer.h" -#include "MT_Vector3.h" -#include "BSP_TMesh.h" -#include "BSP_MeshDrawer.h" - -#include <vector> - -class GHOST_IWindow; -class GHOST_ISystem; - - -class BSP_GhostTestApp3D : -public GHOST_IEventConsumer -{ -public : - // Construct an instance of the application; - - BSP_GhostTestApp3D( - ); - - // initialize the applicaton - - bool - InitApp( - ); - - // Run the application untill internal return. - void - Run( - ); - - ~BSP_GhostTestApp3D( - ); - - void - SetMesh( - MEM_SmartPtr<BSP_TMesh> mesh - ); - -private : - - struct BSP_RotationSetting { - MT_Scalar m_angle_x; - MT_Scalar m_angle_y; - int x_old; - int y_old; - bool m_moving; - }; - - struct BSP_TranslationSetting { - MT_Scalar m_t_x; - MT_Scalar m_t_y; - MT_Scalar m_t_z; - int x_old; - int y_old; - bool m_moving; - }; - - // Return the transform of object i - - MT_Transform - GetTransform( - int active_object - ); - - // Perform an operation between the first two objects in the - // list - - void - Operate( - int type - ); - - // Swap mesh i and settings with the last mesh in list. - - void - Swap( - int i - ); - - void - DrawPolies( - ); - - void - UpdateFrame( - ); - - MT_Vector3 - UnProject( - const MT_Vector3 & vec - ); - - // Create a frustum and projection matrix to - // look at the bounding box - - void - InitOpenGl( - const MT_Vector3 &min, - const MT_Vector3 &max - ); - - - // inherited from GHOST_IEventConsumer - bool - processEvent( - GHOST_IEvent* event - ); - - GHOST_IWindow *m_window; - GHOST_ISystem *m_system; - - bool m_finish_me_off; - - // List of current meshes. - std::vector< MEM_SmartPtr<BSP_TMesh> > m_meshes; - - std::vector< BSP_RotationSetting> m_rotation_settings; - std::vector< BSP_TranslationSetting> m_translation_settings; - std::vector< MT_Scalar> m_scale_settings; - std::vector< int> m_render_modes; - - int m_current_object; - - -}; - -#endif - diff --git a/intern/bsp/test/BSP_GhostTest/BSP_MeshDrawer.cpp b/intern/bsp/test/BSP_GhostTest/BSP_MeshDrawer.cpp deleted file mode 100644 index a1a3150c4d4..00000000000 --- a/intern/bsp/test/BSP_GhostTest/BSP_MeshDrawer.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/** - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -#include "BSP_MeshDrawer.h" - -#include "BSP_TMesh.h" - -#if defined(WIN32) || defined(__APPLE__) -# ifdef WIN32 -# include <windows.h> -# include <GL/gl.h> -# include <GL/glu.h> -# else // WIN32 -# include <AGL/gl.h> -# endif // WIN32 -#else // defined(WIN32) || defined(__APPLE__) -# include <GL/gl.h> -# include <GL/glu.h> -#endif // defined(WIN32) || defined(__APPLE__) - -#include <vector> - -using namespace std; - - void -BSP_MeshDrawer:: -DrawMesh( - BSP_TMesh &mesh, - int render_mode -){ - - - if (render_mode == e_none) return; - - // decompose polygons into triangles. - - glEnable(GL_LIGHTING); - - - if (render_mode == e_wireframe || render_mode == e_wireframe_shaded) { - - glColor3f(0.0, 0.0, 0.0); - - if (render_mode == e_wireframe) { - glDisable(GL_LIGHTING); - } else { - glEnable(GL_LIGHTING); - } - - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - - glEnable(GL_POLYGON_OFFSET_FILL); - glPolygonOffset(1.0,1.0); - - glBegin(GL_TRIANGLES); - DrawPolies(mesh); - glEnd(); - - glColor3f(1.0, 1.0, 1.0); - glDisable(GL_LIGHTING); - glDisable(GL_POLYGON_OFFSET_FILL); - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - - glBegin(GL_TRIANGLES); - DrawPolies(mesh); - glEnd(); - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - } else { - - glEnable(GL_LIGHTING); - - glBegin(GL_TRIANGLES); - DrawPolies(mesh); - glEnd(); - } - - -} - - - void -BSP_MeshDrawer:: -DrawPolies( - BSP_TMesh &mesh -){ - - const vector<BSP_TVertex> & verts = mesh.VertexSet(); - const vector<BSP_TFace> &faces = mesh.FaceSet(); - - // just draw the edges for now. - - vector<BSP_TVertex>::const_iterator vertex_it = verts.begin(); - - - vector<BSP_TFace>::const_iterator faces_it = faces.begin(); - vector<BSP_TFace>::const_iterator faces_end = faces.end(); - - for (;faces_it != faces_end; ++faces_it ){ - - glNormal3f( - faces_it->m_normal.x(), - faces_it->m_normal.y(), - faces_it->m_normal.z() - ); - - glVertex3f( - verts[faces_it->m_verts[0]].m_pos.x(), - verts[faces_it->m_verts[0]].m_pos.y(), - verts[faces_it->m_verts[0]].m_pos.z() - ); - glVertex3f( - verts[faces_it->m_verts[1]].m_pos.x(), - verts[faces_it->m_verts[1]].m_pos.y(), - verts[faces_it->m_verts[1]].m_pos.z() - ); - glVertex3f( - verts[faces_it->m_verts[2]].m_pos.x(), - verts[faces_it->m_verts[2]].m_pos.y(), - verts[faces_it->m_verts[2]].m_pos.z() - ); - } -} - - - - - - - - - - diff --git a/intern/bsp/test/BSP_GhostTest/BSP_MeshDrawer.h b/intern/bsp/test/BSP_GhostTest/BSP_MeshDrawer.h deleted file mode 100644 index 17aeccc603a..00000000000 --- a/intern/bsp/test/BSP_GhostTest/BSP_MeshDrawer.h +++ /dev/null @@ -1,71 +0,0 @@ -/** - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -#ifndef __BSP_MESHDRAWER_H__ -#define __BSP_MESHDRAWER_H__ - -class BSP_TMesh; -class MT_Vector3; - -enum BSP_TRenderMode { - e_shaded, - e_none, - e_wireframe, - e_wireframe_shaded, - e_first_render_mode = e_shaded, - e_last_render_mode = e_wireframe_shaded -}; - -class BSP_MeshDrawer -{ -public : - static - void - DrawMesh( - BSP_TMesh &mesh, - int render_mode - ); - -private : - - static - void - DrawPolies( - BSP_TMesh &mesh - ); - - - BSP_MeshDrawer( - ); - - ~BSP_MeshDrawer( - ); - -}; - -#endif - diff --git a/intern/bsp/test/BSP_GhostTest/BSP_PlyLoader.cpp b/intern/bsp/test/BSP_GhostTest/BSP_PlyLoader.cpp deleted file mode 100644 index 65a1da34a9b..00000000000 --- a/intern/bsp/test/BSP_GhostTest/BSP_PlyLoader.cpp +++ /dev/null @@ -1,192 +0,0 @@ -/** - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -#include "BSP_PlyLoader.h" - -#include "MT_Vector3.h" -#include "ply.h" - -struct LoadVertex { - float x,y,z; /* the usual 3-space position of a vertex */ -}; - -struct LoadFace { - unsigned char intensity; /* this user attaches intensity to faces */ - unsigned char nverts; /* number of vertex indices in list */ - int *verts; /* vertex index list */ -}; - - - MEM_SmartPtr<BSP_TMesh> -BSP_PlyLoader:: -NewMeshFromFile( - char * file_name, - MT_Vector3 &min, - MT_Vector3 &max - -) { - - min = MT_Vector3(MT_INFINITY,MT_INFINITY,MT_INFINITY); - max = MT_Vector3(-MT_INFINITY,-MT_INFINITY,-MT_INFINITY); - - PlyProperty vert_props[] = { /* list of property information for a vertex */ - {"x", PLY_FLOAT, PLY_FLOAT, offsetof(LoadVertex,x), 0, 0, 0, 0}, - {"y", PLY_FLOAT, PLY_FLOAT, offsetof(LoadVertex,y), 0, 0, 0, 0}, - {"z", PLY_FLOAT, PLY_FLOAT, offsetof(LoadVertex,z), 0, 0, 0, 0}, - }; - - PlyProperty face_props[] = { /* list of property information for a vertex */ - {"vertex_indices", PLY_INT, PLY_INT, offsetof(LoadFace,verts), - 1, PLY_UCHAR, PLY_UCHAR, offsetof(LoadFace,nverts)}, - }; - - MEM_SmartPtr<BSP_TMesh> mesh = new BSP_TMesh; - - if (mesh == NULL) return NULL; - - int i,j; - PlyFile *ply; - int nelems; - char **elist; - int file_type; - float version; - int nprops; - int num_elems; - PlyProperty **plist; - - char *elem_name; - - LoadVertex load_vertex; - LoadFace load_face; - - /* open a PLY file for reading */ - ply = ply_open_for_reading( - file_name, - &nelems, - &elist, - &file_type, - &version - ); - - if (ply == NULL) return NULL; - - /* go through each kind of element that we learned is in the file */ - /* and read them */ - - for (i = 0; i < nelems; i++) { - - /* get the description of the first element */ - - elem_name = elist[i]; - plist = ply_get_element_description (ply, elem_name, &num_elems, &nprops); - - /* print the name of the element, for debugging */ - - /* if we're on vertex elements, read them in */ - - if (equal_strings ("vertex", elem_name)) { - - /* set up for getting vertex elements */ - - ply_get_property (ply, elem_name, &vert_props[0]); - ply_get_property (ply, elem_name, &vert_props[1]); - ply_get_property (ply, elem_name, &vert_props[2]); - - // make some memory for the vertices - mesh->VertexSet().reserve(num_elems); - - /* grab all the vertex elements */ - for (j = 0; j < num_elems; j++) { - - /* grab and element from the file */ - ply_get_element (ply, (void *)&load_vertex); - // pass the vertex into the mesh builder. - - if (load_vertex.x < min.x()) { - min.x() = load_vertex.x; - } else - if (load_vertex.x > max.x()) { - max.x()= load_vertex.x; - } - - if (load_vertex.y < min.y()) { - min.y() = load_vertex.y; - } else - if (load_vertex.y > max.y()) { - max.y()= load_vertex.y; - } - - if (load_vertex.z < min.z()) { - min.z() = load_vertex.z; - } else - if (load_vertex.z > max.z()) { - max.z()= load_vertex.z; - } - - BSP_TVertex my_vert; - my_vert.m_pos = MT_Vector3(load_vertex.x,load_vertex.y,load_vertex.z); - mesh->VertexSet().push_back(my_vert); - } - - - } - - /* if we're on face elements, read them in */ - if (equal_strings ("face", elem_name)) { - - /* set up for getting face elements */ - - ply_get_property (ply, elem_name, &face_props[0]); - - /* grab all the face elements */ - for (j = 0; j < num_elems; j++) { - - ply_get_element (ply, (void *)&load_face); - - int v; - for (v = 2; v< load_face.nverts; v++) { - - BSP_TFace f; - - f.m_verts[0] = load_face.verts[0]; - f.m_verts[1] = load_face.verts[v-1]; - f.m_verts[2] = load_face.verts[v]; - - mesh->BuildNormal(f); - mesh->FaceSet().push_back(f); - } - // free up the memory this pile of shit used to allocate the polygon's vertices - free (load_face.verts); - } - - } - } - /* close the PLY file */ - ply_close (ply); - - return mesh; -} diff --git a/intern/bsp/test/BSP_GhostTest/BSP_PlyLoader.h b/intern/bsp/test/BSP_GhostTest/BSP_PlyLoader.h deleted file mode 100644 index 8fcac29253b..00000000000 --- a/intern/bsp/test/BSP_GhostTest/BSP_PlyLoader.h +++ /dev/null @@ -1,60 +0,0 @@ -/** - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -#ifndef __BSP_PLYLOADER_H__ -#define __BSP_PLYLOADER_H__ - -#include "MEM_SmartPtr.h" -#include "BSP_TMesh.h" - -class BSP_PlyLoader { -public : - - static - MEM_SmartPtr<BSP_TMesh> - NewMeshFromFile( - char * file_name, - MT_Vector3 &min, - MT_Vector3 &max - ); - - -private : - - // unimplemented - not for instantiation. - - BSP_PlyLoader( - ); - - ~BSP_PlyLoader( - ); -}; - - - -#endif - diff --git a/intern/bsp/test/BSP_GhostTest/BSP_TMesh.h b/intern/bsp/test/BSP_GhostTest/BSP_TMesh.h deleted file mode 100644 index 793fb47f73b..00000000000 --- a/intern/bsp/test/BSP_GhostTest/BSP_TMesh.h +++ /dev/null @@ -1,397 +0,0 @@ -/** - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -#ifndef __BSP_TMESH_H__ -#define __BSP_TMESH_H__ - -#include "MT_Point3.h" -#include "MT_Vector3.h" -#include "MT_Transform.h" - -#include "MEM_SmartPtr.h" - -#include <vector> - -#include "CSG_BooleanOps.h" - -/** - * A very basic test mesh. - */ - -struct BSP_TVertex { - MT_Point3 m_pos; -}; - -struct BSP_TFace { - int m_verts[3]; - MT_Vector3 m_normal; -}; - - -class BSP_TMesh { -public : - - std::vector<BSP_TVertex> m_verts; - std::vector<BSP_TFace> m_faces; - - MT_Vector3 m_min,m_max; - - std::vector<BSP_TVertex> & - VertexSet( - ){ - return m_verts; - } - - std::vector<BSP_TFace> & - FaceSet( - ) { - return m_faces; - } - - void - AddFace( - int *verts, - int num_verts - ){ - int i; - for (i= 2; i <num_verts; i++) { - BSP_TFace f; - f.m_verts[0] = verts[0]; - f.m_verts[1] = verts[i-1]; - f.m_verts[2] = verts[i]; - - m_faces.push_back(f); - - BuildNormal(m_faces.back()); - } - } - - void - BuildNormal( - BSP_TFace & f - ) const { - MT_Vector3 l1 = - m_verts[f.m_verts[1]].m_pos - - m_verts[f.m_verts[0]].m_pos; - MT_Vector3 l2 = - m_verts[f.m_verts[2]].m_pos - - m_verts[f.m_verts[1]].m_pos; - - MT_Vector3 normal = l1.cross(l2); - - f.m_normal = normal.safe_normalized(); - } - -}; - - - -/** - * some iterator functions to describe the mesh to the BSP module. - */ - -/** - * This class defines 2 C style iterators over a CSG mesh, one for - * vertices and 1 for faces. They conform to the iterator interface - * defined in CSG_BooleanOps.h - */ - -struct VertexIt { - BSP_TMesh * mesh; - BSP_TVertex * pos; - MT_Transform trans; -}; - - -static - void -VertexIt_Destruct( - CSG_VertexIteratorDescriptor * iterator -) { - delete ((VertexIt *)(iterator->it)); - iterator->it = NULL; - delete(iterator); -}; - - -static - int -VertexIt_Done( - CSG_IteratorPtr it -) { - // assume CSG_IteratorPtr is of the correct type. - VertexIt * vertex_it = (VertexIt *)it; - - if (vertex_it->pos < vertex_it->mesh->VertexSet().end()) return 0; - return 1; -}; - -static - void -VertexIt_Fill( - CSG_IteratorPtr it, - CSG_IVertex *vert -) { - // assume CSG_IteratorPtr is of the correct type. - VertexIt * vertex_it = (VertexIt *)it; - - MT_Point3 p = vertex_it->pos->m_pos; - p = vertex_it->trans * p; - - p.getValue(vert->position); -}; - -static - void -VertexIt_Step( - CSG_IteratorPtr it -) { - // assume CSG_IteratorPtr is of the correct type. - VertexIt * vertex_it = (VertexIt *)it; - - ++(vertex_it->pos); -}; - -static - void -VertexIt_Reset( - CSG_IteratorPtr it -) { - // assume CSG_IteratorPtr is of the correct type. - VertexIt * vertex_it = (VertexIt *)it; - - vertex_it->pos = vertex_it->mesh->VertexSet().begin(); -}; - -static - CSG_VertexIteratorDescriptor * -VertexIt_Construct( - BSP_TMesh *mesh, - MT_Transform trans -){ - // user should have insured mesh is not equal to NULL. - - CSG_VertexIteratorDescriptor * output = new CSG_VertexIteratorDescriptor; - if (output == NULL) return NULL; - output->Done = VertexIt_Done; - output->Fill = VertexIt_Fill; - output->Step = VertexIt_Step; - output->Reset = VertexIt_Reset; - output->num_elements = mesh->VertexSet().size(); - - VertexIt * v_it = new VertexIt; - v_it->mesh = mesh; - v_it->pos = mesh->VertexSet().begin(); - v_it->trans = trans; - output->it = v_it; - return output; -}; - - -/** - * Face iterator. - */ - -struct FaceIt { - BSP_TMesh * mesh; - BSP_TFace *pos; -}; - - -static - void -FaceIt_Destruct( - CSG_FaceIteratorDescriptor * iterator -) { - delete ((FaceIt *)(iterator->it)); - iterator->it = NULL; - delete(iterator); -}; - - -static - int -FaceIt_Done( - CSG_IteratorPtr it -) { - // assume CSG_IteratorPtr is of the correct type. - FaceIt * face_it = (FaceIt *)it; - - if (face_it->pos < face_it->mesh->FaceSet().end()) { - return 0; - } - return 1; -}; - -static - void -FaceIt_Fill( - CSG_IteratorPtr it, - CSG_IFace *face -){ - // assume CSG_IteratorPtr is of the correct type. - FaceIt * face_it = (FaceIt *)it; - // essentially iterating through a triangle fan here. - - face->vertex_index[0] = int(face_it->pos->m_verts[0]); - face->vertex_index[1] = int(face_it->pos->m_verts[1]); - face->vertex_index[2] = int(face_it->pos->m_verts[2]); - - face->vertex_number = 3; -}; - -static - void -FaceIt_Step( - CSG_IteratorPtr it -) { - // assume CSG_IteratorPtr is of the correct type. - FaceIt * face_it = (FaceIt *)it; - - face_it->pos ++; -}; - -static - void -FaceIt_Reset( - CSG_IteratorPtr it -) { - // assume CSG_IteratorPtr is of the correct type. - FaceIt * face_it = (FaceIt *)it; - - face_it->pos = face_it->mesh->FaceSet().begin(); -}; - -static - CSG_FaceIteratorDescriptor * -FaceIt_Construct( - BSP_TMesh * mesh -) { - CSG_FaceIteratorDescriptor * output = new CSG_FaceIteratorDescriptor; - if (output == NULL) return NULL; - - output->Done = FaceIt_Done; - output->Fill = FaceIt_Fill; - output->Step = FaceIt_Step; - output->Reset = FaceIt_Reset; - - output->num_elements = mesh->FaceSet().size(); - - FaceIt * f_it = new FaceIt; - f_it->mesh = mesh; - f_it->pos = mesh->FaceSet().begin(); - - output->it = f_it; - - return output; -}; - -/** - * Some Build functions. - */ - -static - MEM_SmartPtr<BSP_TMesh> -BuildMesh( - CSG_MeshPropertyDescriptor &props, - CSG_FaceIteratorDescriptor &face_it, - CSG_VertexIteratorDescriptor &vertex_it -) { - MEM_SmartPtr<BSP_TMesh> mesh = new BSP_TMesh(); - - CSG_IVertex vert; - - while (!vertex_it.Done(vertex_it.it)) { - - vertex_it.Fill(vertex_it.it,&vert); - - BSP_TVertex v; - v.m_pos = MT_Point3(vert.position); - mesh->VertexSet().push_back(v); - - vertex_it.Step(vertex_it.it); - } - - - CSG_IFace face; - - while (!face_it.Done(face_it.it)) { - face_it.Fill(face_it.it,&face); - - BSP_TFace f; - - f.m_verts[0] = face.vertex_index[0], - f.m_verts[1] = face.vertex_index[1], - f.m_verts[2] = face.vertex_index[2], - - mesh->BuildNormal(f); - - mesh->FaceSet().push_back(f); - - face_it.Step(face_it.it); - } - - return mesh; -}; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#endif - diff --git a/intern/bsp/test/BSP_GhostTest/main.cpp b/intern/bsp/test/BSP_GhostTest/main.cpp deleted file mode 100644 index 25185f40192..00000000000 --- a/intern/bsp/test/BSP_GhostTest/main.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/** - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -#include "BSP_GhostTest3D.h" - -#include "BSP_TMesh.h" -#include "MEM_SmartPtr.h" -#include "BSP_PlyLoader.h" - -#include <iostream> - -using namespace std; -#if 1 - MEM_SmartPtr<BSP_TMesh> -NewTestMesh( - int x, - int y, - MT_Scalar fx, - MT_Scalar fy, - MT_Scalar ampx, - MT_Scalar ampy, - MT_Scalar sx, - MT_Scalar sy -) { - - MEM_SmartPtr<BSP_TMesh> output = new BSP_TMesh; - - std::vector<BSP_TVertex> &verts = output->VertexSet(); - - int i,j; - - MT_Scalar x_scale = fx*MT_PI/x; - MT_Scalar y_scale = fy*MT_PI/y; - - MT_Scalar fsx = sx/x; - MT_Scalar fsy = sy/y; - - for (j = 0; j < y; j++) { - for (i = 0; i < x; i++) { - float z = ampx*sin(x_scale * i) + ampy*sin(y_scale * j); - - MT_Vector3 val(i*fsx - sx/2,j*fsy - sy/2,z); - - BSP_TVertex chuff; - chuff.m_pos = val; - verts.push_back(chuff); - } - } - - int poly[4]; - - for (j = 0; j < (y-1); j++) { - for (i = 0; i < (x-1); i++) { - - poly[0] = j*x + i; - poly[1] = poly[0] + 1; - poly[2] = poly[1] + y; - poly[3] = poly[2] -1; - - output->AddFace(poly,4); - } - } - - output->m_min = MT_Vector3(-sx/2,-sy/2,-ampx -ampy); - output->m_max = MT_Vector3(sx/2,sy/2,ampx + ampy); - - return output; -} -#endif - - -int main() -{ - MT_Vector3 min,max; - MT_Vector3 min2,max2; - -#if 1 - MEM_SmartPtr<BSP_TMesh> mesh1 = BSP_PlyLoader::NewMeshFromFile("bsp_cube.ply",min,max); - MEM_SmartPtr<BSP_TMesh> mesh2 = BSP_PlyLoader::NewMeshFromFile("bsp_cube.ply",min2,max2); - - mesh1->m_min = min; - mesh1->m_max = max; - mesh2->m_min = min2; - mesh1->m_max = max2; - -#else - MEM_SmartPtr<BSP_TMesh> mesh1 = NewTestMesh(10,10,2,2,4,4,20,20); - MEM_SmartPtr<BSP_TMesh> mesh2 = NewTestMesh(10,10,2,2,4,4,20,20); -#endif - - if (!mesh1) { - cout << "could not load mesh!"; - return 0; - } - - - -// MEM_SmartPtr<BSP_TMesh> mesh2 = new BSP_TMesh(mesh1.Ref()); - - BSP_GhostTestApp3D app; - - cout << "Mesh polygons :" << mesh1->FaceSet().size() << "\n"; - cout << "Mesh vertices :" << mesh1->VertexSet().size() << "\n"; - - app.SetMesh(mesh1); - app.SetMesh(mesh2); - - - app.InitApp(); - - app.Run(); - - return 0; - -} - - - - diff --git a/intern/bsp/test/BSP_GhostTest/ply.h b/intern/bsp/test/BSP_GhostTest/ply.h deleted file mode 100644 index 12425ded898..00000000000 --- a/intern/bsp/test/BSP_GhostTest/ply.h +++ /dev/null @@ -1,196 +0,0 @@ -/** - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/* - -Header for PLY polygon files. - -- Greg Turk, March 1994 - -A PLY file contains a single polygonal _object_. - -An object is composed of lists of _elements_. Typical elements are -vertices, faces, edges and materials. - -Each type of element for a given object has one or more _properties_ -associated with the element type. For instance, a vertex element may -have as properties three floating-point values x,y,z and three unsigned -chars for red, green and blue. - ---------------------------------------------------------------- - -Copyright (c) 1994 The Board of Trustees of The Leland Stanford -Junior University. All rights reserved. - -Permission to use, copy, modify and distribute this software and its -documentation for any purpose is hereby granted without fee, provided -that the above copyright notice and this permission notice appear in -all copies of this software and that you do not sell the software. - -THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND, -EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY -WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - -*/ - -#ifndef __PLY_H__ -#define __PLY_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include <stdio.h> -#include <stddef.h> - -#define PLY_ASCII 1 /* ascii PLY file */ -#define PLY_BINARY_BE 2 /* binary PLY file, big endian */ -#define PLY_BINARY_LE 3 /* binary PLY file, little endian */ - -#define PLY_OKAY 0 /* ply routine worked okay */ -#define PLY_ERROR -1 /* error in ply routine */ - -/* scalar data types supported by PLY format */ - -#define PLY_START_TYPE 0 -#define PLY_CHAR 1 -#define PLY_SHORT 2 -#define PLY_INT 3 -#define PLY_UCHAR 4 -#define PLY_USHORT 5 -#define PLY_UINT 6 -#define PLY_FLOAT 7 -#define PLY_DOUBLE 8 -#define PLY_END_TYPE 9 - -#define PLY_SCALAR 0 -#define PLY_LIST 1 - - -typedef struct PlyProperty { /* description of a property */ - - char *name; /* property name */ - int external_type; /* file's data type */ - int internal_type; /* program's data type */ - int offset; /* offset bytes of prop in a struct */ - - int is_list; /* 1 = list, 0 = scalar */ - int count_external; /* file's count type */ - int count_internal; /* program's count type */ - int count_offset; /* offset byte for list count */ - -} PlyProperty; - -typedef struct PlyElement { /* description of an element */ - char *name; /* element name */ - int num; /* number of elements in this object */ - int size; /* size of element (bytes) or -1 if variable */ - int nprops; /* number of properties for this element */ - PlyProperty **props; /* list of properties in the file */ - char *store_prop; /* flags: property wanted by user? */ - int other_offset; /* offset to un-asked-for props, or -1 if none*/ - int other_size; /* size of other_props structure */ -} PlyElement; - -typedef struct PlyOtherProp { /* describes other properties in an element */ - char *name; /* element name */ - int size; /* size of other_props */ - int nprops; /* number of properties in other_props */ - PlyProperty **props; /* list of properties in other_props */ -} PlyOtherProp; - -typedef struct OtherData { /* for storing other_props for an other element */ - void *other_props; -} OtherData; - -typedef struct OtherElem { /* data for one "other" element */ - char *elem_name; /* names of other elements */ - int elem_count; /* count of instances of each element */ - OtherData **other_data; /* actual property data for the elements */ - PlyOtherProp *other_props; /* description of the property data */ -} OtherElem; - -typedef struct PlyOtherElems { /* "other" elements, not interpreted by user */ - int num_elems; /* number of other elements */ - OtherElem *other_list; /* list of data for other elements */ -} PlyOtherElems; - -typedef struct PlyFile { /* description of PLY file */ - FILE *fp; /* file pointer */ - int file_type; /* ascii or binary */ - float version; /* version number of file */ - int nelems; /* number of elements of object */ - PlyElement **elems; /* list of elements */ - int num_comments; /* number of comments */ - char **comments; /* list of comments */ - int num_obj_info; /* number of items of object information */ - char **obj_info; /* list of object info items */ - PlyElement *which_elem; /* which element we're currently writing */ - PlyOtherElems *other_elems; /* "other" elements from a PLY file */ -} PlyFile; - -/* memory allocation */ -static char *my_alloc(); -#define myalloc(mem_size) my_alloc((mem_size), __LINE__, __FILE__) - - -/*** delcaration of routines ***/ - -extern PlyFile *ply_write(FILE *, int, char **, int); -extern PlyFile *ply_open_for_writing(char *, int, char **, int, float *); -extern void ply_describe_element(PlyFile *, char *, int, int, PlyProperty *); -extern void ply_describe_property(PlyFile *, char *, PlyProperty *); -extern void ply_element_count(PlyFile *, char *, int); -extern void ply_header_complete(PlyFile *); -extern void ply_put_element_setup(PlyFile *, char *); -extern void ply_put_element(PlyFile *, void *); -extern void ply_put_comment(PlyFile *, char *); -extern void ply_put_obj_info(PlyFile *, char *); -extern PlyFile *ply_read(FILE *, int *, char ***); -extern PlyFile *ply_open_for_reading( char *, int *, char ***, int *, float *); -extern PlyProperty **ply_get_element_description(PlyFile *, char *, int*, int*); -extern void ply_get_element_setup( PlyFile *, char *, int, PlyProperty *); -extern void ply_get_property(PlyFile *, char *, PlyProperty *); -extern PlyOtherProp *ply_get_other_properties(PlyFile *, char *, int); -extern void ply_get_element(PlyFile *, void *); -extern char **ply_get_comments(PlyFile *, int *); -extern char **ply_get_obj_info(PlyFile *, int *); -extern void ply_close(PlyFile *); -extern void ply_get_info(PlyFile *, float *, int *); -extern PlyOtherElems *ply_get_other_element (PlyFile *, char *, int); -extern void ply_describe_other_elements ( PlyFile *, PlyOtherElems *); -extern void ply_put_other_elements (PlyFile *); -extern void ply_free_other_elements (PlyOtherElems *); - -extern int equal_strings(char *, char *); - - -#ifdef __cplusplus -} -#endif -#endif /* !__PLY_H__ */ - diff --git a/intern/bsp/test/BSP_GhostTest/plyfile.c b/intern/bsp/test/BSP_GhostTest/plyfile.c deleted file mode 100644 index b0134f06557..00000000000 --- a/intern/bsp/test/BSP_GhostTest/plyfile.c +++ /dev/null @@ -1,2545 +0,0 @@ -/** - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/* - - - The interface routines for reading and writing PLY polygon files. - - Greg Turk, February 1994 - - --------------------------------------------------------------- - - A PLY file contains a single polygonal _object_. - - An object is composed of lists of _elements_. Typical elements are - vertices, faces, edges and materials. - - Each type of element for a given object has one or more _properties_ - associated with the element type. For instance, a vertex element may - have as properties the floating-point values x,y,z and the three unsigned - chars representing red, green and blue. - - --------------------------------------------------------------- - - Copyright (c) 1994 The Board of Trustees of The Leland Stanford - Junior University. All rights reserved. - - Permission to use, copy, modify and distribute this software and its - documentation for any purpose is hereby granted without fee, provided - that the above copyright notice and this permission notice appear in - all copies of this software and that you do not sell the software. - - THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND, - EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY - WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. - - */ - -#include <stdio.h> -#include <stdlib.h> -#include <math.h> -#include <string.h> -#include "ply.h" - -char *type_names[] = { - "invalid", - "char", "short", "int", - "uchar", "ushort", "uint", - "float", "double", -}; - -int ply_type_size[] = { - 0, 1, 2, 4, 1, 2, 4, 4, 8 -}; - -#define NO_OTHER_PROPS -1 - -#define DONT_STORE_PROP 0 -#define STORE_PROP 1 - -#define OTHER_PROP 0 -#define NAMED_PROP 1 - - -/* returns 1 if strings are equal, 0 if not */ -int equal_strings(char *, char *); - -/* find an element in a plyfile's list */ -PlyElement *find_element(PlyFile *, char *); - -/* find a property in an element's list */ -PlyProperty *find_property(PlyElement *, char *, int *); - -/* write to a file the word describing a PLY file data type */ -void write_scalar_type(FILE *, int); - -/* read a line from a file and break it up into separate words */ -char **get_words(FILE *, int *, char **); -char **old_get_words(FILE *, int *); - -/* write an item to a file */ -void write_binary_item(FILE *, int, unsigned int, double, int); -void write_ascii_item(FILE *, int, unsigned int, double, int); -double old_write_ascii_item(FILE *, char *, int); - -/* add information to a PLY file descriptor */ -void add_element(PlyFile *, char **); -void add_property(PlyFile *, char **); -void add_comment(PlyFile *, char *); -void add_obj_info(PlyFile *, char *); - -/* copy a property */ -void copy_property(PlyProperty *, PlyProperty *); - -/* store a value into where a pointer and a type specify */ -void store_item(char *, int, int, unsigned int, double); - -/* return the value of a stored item */ -void get_stored_item(void *, int, int *, unsigned int *, double *); - -/* return the value stored in an item, given ptr to it and its type */ -double get_item_value(char *, int); - -/* get binary or ascii item and store it according to ptr and type */ -void get_ascii_item(char *, int, int *, unsigned int *, double *); -void get_binary_item(FILE *, int, int *, unsigned int *, double *); - -/* get a bunch of elements from a file */ -void ascii_get_element(PlyFile *, char *); -void binary_get_element(PlyFile *, char *); - -/* memory allocation */ -char *my_alloc(int, int, char *); - - -/*************/ -/* Writing */ -/*************/ - - -/****************************************************************************** - Given a file pointer, get ready to write PLY data to the file. - - Entry: - fp - the given file pointer - nelems - number of elements in object - elem_names - list of element names - file_type - file type, either ascii or binary - - Exit: - returns a pointer to a PlyFile, used to refer to this file, or NULL if error -******************************************************************************/ - -PlyFile *ply_write( - FILE *fp, - int nelems, - char **elem_names, - int file_type - ) -{ - int i; - PlyFile *plyfile; - PlyElement *elem; - - /* check for NULL file pointer */ - if (fp == NULL) - return (NULL); - - /* create a record for this object */ - - plyfile = (PlyFile *) myalloc(sizeof(PlyFile)); - plyfile->file_type = file_type; - plyfile->num_comments = 0; - plyfile->num_obj_info = 0; - plyfile->nelems = nelems; - plyfile->version = 1.0; - plyfile->fp = fp; - plyfile->other_elems = NULL; - - /* tuck aside the names of the elements */ - - plyfile->elems = (PlyElement **) myalloc(sizeof(PlyElement *) * nelems); - for (i = 0; i < nelems; i++) { - elem = (PlyElement *) myalloc(sizeof(PlyElement)); - plyfile->elems[i] = elem; - elem->name = strdup(elem_names[i]); - elem->num = 0; - elem->nprops = 0; - } - - /* return pointer to the file descriptor */ - return (plyfile); -} - - -/****************************************************************************** - Open a polygon file for writing. - - Entry: - filename - name of file to read from - nelems - number of elements in object - elem_names - list of element names - file_type - file type, either ascii or binary - - Exit: - version - version number of PLY file - returns a file identifier, used to refer to this file, or NULL if error -******************************************************************************/ - -PlyFile *ply_open_for_writing( - char *filename, - int nelems, - char **elem_names, - int file_type, - float *version - ) -{ - PlyFile *plyfile; - char *name; - FILE *fp; - - /* tack on the extension .ply, if necessary */ - - name = (char *) myalloc(sizeof(char) * (strlen(filename) + 5)); - strcpy(name, filename); - if (strlen(name) < 4 || - strcmp(name + strlen(name) - 4, ".ply") != 0) - strcat(name, ".ply"); - - /* open the file for writing */ - - fp = fopen(name, "w"); - if (fp == NULL) { - return (NULL); - } - - /* create the actual PlyFile structure */ - - plyfile = ply_write(fp, nelems, elem_names, file_type); - if (plyfile == NULL) - return (NULL); - - /* say what PLY file version number we're writing */ - *version = plyfile->version; - - /* return pointer to the file descriptor */ - return (plyfile); -} - - -/****************************************************************************** - Describe an element, including its properties and how many will be written - to the file. - - Entry: - plyfile - file identifier - elem_name - name of element that information is being specified about - nelems - number of elements of this type to be written - nprops - number of properties contained in the element - prop_list - list of properties -******************************************************************************/ - -void ply_describe_element( - PlyFile *plyfile, - char *elem_name, - int nelems, - int nprops, - PlyProperty *prop_list - ) -{ - int i; - PlyElement *elem; - PlyProperty *prop; - - /* look for appropriate element */ - elem = find_element(plyfile, elem_name); - if (elem == NULL) { - fprintf(stderr, "ply_describe_element: can't find element '%s'\n", elem_name); - exit(-1); - } - - elem->num = nelems; - - /* copy the list of properties */ - - elem->nprops = nprops; - elem->props = (PlyProperty **) myalloc(sizeof(PlyProperty *) * nprops); - elem->store_prop = (char *) myalloc(sizeof(char) * nprops); - - for (i = 0; i < nprops; i++) { - prop = (PlyProperty *) myalloc(sizeof(PlyProperty)); - elem->props[i] = prop; - elem->store_prop[i] = NAMED_PROP; - copy_property(prop, &prop_list[i]); - } -} - - -/****************************************************************************** - Describe a property of an element. - - Entry: - plyfile - file identifier - elem_name - name of element that information is being specified about - prop - the new property -******************************************************************************/ - -void ply_describe_property( - PlyFile *plyfile, - char *elem_name, - PlyProperty *prop - ) -{ - PlyElement *elem; - PlyProperty *elem_prop; - - /* look for appropriate element */ - elem = find_element(plyfile, elem_name); - if (elem == NULL) { - fprintf(stderr, "ply_describe_property: can't find element '%s'\n", - elem_name); - return; - } - - /* create room for new property */ - - if (elem->nprops == 0) { - elem->props = (PlyProperty **) myalloc(sizeof(PlyProperty *)); - elem->store_prop = (char *) myalloc(sizeof(char)); - elem->nprops = 1; - } - else { - elem->nprops++; - elem->props = (PlyProperty **) - realloc(elem->props, sizeof(PlyProperty *) * elem->nprops); - elem->store_prop = (char *) - realloc(elem->store_prop, sizeof(char) * elem->nprops); - } - - /* copy the new property */ - - elem_prop = (PlyProperty *) myalloc(sizeof(PlyProperty)); - elem->props[elem->nprops - 1] = elem_prop; - elem->store_prop[elem->nprops - 1] = NAMED_PROP; - copy_property(elem_prop, prop); -} - - -/****************************************************************************** - Describe what the "other" properties are that are to be stored, and where - they are in an element. -******************************************************************************/ - -void ply_describe_other_properties( - PlyFile *plyfile, - PlyOtherProp *other, - int offset - ) -{ - int i; - PlyElement *elem; - PlyProperty *prop; - - /* look for appropriate element */ - elem = find_element(plyfile, other->name); - if (elem == NULL) { - fprintf(stderr, "ply_describe_other_properties: can't find element '%s'\n", - other->name); - return; - } - - /* create room for other properties */ - - if (elem->nprops == 0) { - elem->props = (PlyProperty **) - myalloc(sizeof(PlyProperty *) * other->nprops); - elem->store_prop = (char *) myalloc(sizeof(char) * other->nprops); - elem->nprops = 0; - } - else { - int newsize; - newsize = elem->nprops + other->nprops; - elem->props = (PlyProperty **) - realloc(elem->props, sizeof(PlyProperty *) * newsize); - elem->store_prop = (char *) - realloc(elem->store_prop, sizeof(char) * newsize); - } - - /* copy the other properties */ - - for (i = 0; i < other->nprops; i++) { - prop = (PlyProperty *) myalloc(sizeof(PlyProperty)); - copy_property(prop, other->props[i]); - elem->props[elem->nprops] = prop; - elem->store_prop[elem->nprops] = OTHER_PROP; - elem->nprops++; - } - - /* save other info about other properties */ - elem->other_size = other->size; - elem->other_offset = offset; -} - - -/****************************************************************************** - State how many of a given element will be written. - - Entry: - plyfile - file identifier - elem_name - name of element that information is being specified about - nelems - number of elements of this type to be written -******************************************************************************/ - -void ply_element_count( - PlyFile *plyfile, - char *elem_name, - int nelems - ) -{ - PlyElement *elem; - - /* look for appropriate element */ - elem = find_element(plyfile, elem_name); - if (elem == NULL) { - fprintf(stderr, "ply_element_count: can't find element '%s'\n", elem_name); - exit(-1); - } - - elem->num = nelems; -} - - -/****************************************************************************** - Signal that we've described everything a PLY file's header and that the - header should be written to the file. - - Entry: - plyfile - file identifier -******************************************************************************/ - -void ply_header_complete(PlyFile *plyfile) -{ - int i, j; - FILE *fp = plyfile->fp; - PlyElement *elem; - PlyProperty *prop; - - fprintf(fp, "ply\n"); - - switch (plyfile->file_type) { - case PLY_ASCII: - fprintf(fp, "format ascii 1.0\n"); - break; - case PLY_BINARY_BE: - fprintf(fp, "format binary_big_endian 1.0\n"); - break; - case PLY_BINARY_LE: - fprintf(fp, "format binary_little_endian 1.0\n"); - break; - default: - fprintf(stderr, "ply_header_complete: bad file type = %d\n", - plyfile->file_type); - exit(-1); - } - - /* write out the comments */ - - for (i = 0; i < plyfile->num_comments; i++) - fprintf(fp, "comment %s\n", plyfile->comments[i]); - - /* write out object information */ - - for (i = 0; i < plyfile->num_obj_info; i++) - fprintf(fp, "obj_info %s\n", plyfile->obj_info[i]); - - /* write out information about each element */ - - for (i = 0; i < plyfile->nelems; i++) { - - elem = plyfile->elems[i]; - fprintf(fp, "element %s %d\n", elem->name, elem->num); - - /* write out each property */ - for (j = 0; j < elem->nprops; j++) { - prop = elem->props[j]; - if (prop->is_list) { - fprintf(fp, "property list "); - write_scalar_type(fp, prop->count_external); - fprintf(fp, " "); - write_scalar_type(fp, prop->external_type); - fprintf(fp, " %s\n", prop->name); - } - else { - fprintf(fp, "property "); - write_scalar_type(fp, prop->external_type); - fprintf(fp, " %s\n", prop->name); - } - } - } - - fprintf(fp, "end_header\n"); -} - - -/****************************************************************************** - Specify which elements are going to be written. This should be called - before a call to the routine ply_put_element(). - - Entry: - plyfile - file identifier - elem_name - name of element we're talking about -******************************************************************************/ - -void ply_put_element_setup(PlyFile *plyfile, char *elem_name) -{ - PlyElement *elem; - - elem = find_element(plyfile, elem_name); - if (elem == NULL) { - fprintf(stderr, "ply_elements_setup: can't find element '%s'\n", elem_name); - exit(-1); - } - - plyfile->which_elem = elem; -} - - -/****************************************************************************** - Write an element to the file. This routine assumes that we're - writing the type of element specified in the last call to the routine - ply_put_element_setup(). - - Entry: - plyfile - file identifier - elem_ptr - pointer to the element -******************************************************************************/ - -void ply_put_element(PlyFile *plyfile, void *elem_ptr) -{ - int j, k; - FILE *fp = plyfile->fp; - PlyElement *elem; - PlyProperty *prop; - char *elem_data, *item; - char **item_ptr; - int list_count; - int item_size; - int int_val; - unsigned int uint_val; - double double_val; - char **other_ptr; - - elem = plyfile->which_elem; - elem_data = elem_ptr; - other_ptr = (char **) (((char *) elem_ptr) + elem->other_offset); - - /* write out either to an ascii or binary file */ - - if (plyfile->file_type == PLY_ASCII) { - - /* write an ascii file */ - - /* write out each property of the element */ - for (j = 0; j < elem->nprops; j++) { - prop = elem->props[j]; - if (elem->store_prop[j] == OTHER_PROP) - elem_data = *other_ptr; - else - elem_data = elem_ptr; - if (prop->is_list) { - item = elem_data + prop->count_offset; - get_stored_item((void *) item, prop->count_internal, - &int_val, &uint_val, &double_val); - write_ascii_item(fp, int_val, uint_val, double_val, - prop->count_external); - list_count = uint_val; - item_ptr = (char **) (elem_data + prop->offset); - item = item_ptr[0]; - item_size = ply_type_size[prop->internal_type]; - for (k = 0; k < list_count; k++) { - get_stored_item((void *) item, prop->internal_type, - &int_val, &uint_val, &double_val); - write_ascii_item(fp, int_val, uint_val, double_val, - prop->external_type); - item += item_size; - } - } - else { - item = elem_data + prop->offset; - get_stored_item((void *) item, prop->internal_type, - &int_val, &uint_val, &double_val); - write_ascii_item(fp, int_val, uint_val, double_val, - prop->external_type); - } - } - - fprintf(fp, "\n"); - } - else { - - /* write a binary file */ - - /* write out each property of the element */ - for (j = 0; j < elem->nprops; j++) { - prop = elem->props[j]; - if (elem->store_prop[j] == OTHER_PROP) - elem_data = *other_ptr; - else - elem_data = elem_ptr; - if (prop->is_list) { - item = elem_data + prop->count_offset; - item_size = ply_type_size[prop->count_internal]; - get_stored_item((void *) item, prop->count_internal, - &int_val, &uint_val, &double_val); - write_binary_item(fp, int_val, uint_val, double_val, - prop->count_external); - list_count = uint_val; - item_ptr = (char **) (elem_data + prop->offset); - item = item_ptr[0]; - item_size = ply_type_size[prop->internal_type]; - for (k = 0; k < list_count; k++) { - get_stored_item((void *) item, prop->internal_type, - &int_val, &uint_val, &double_val); - write_binary_item(fp, int_val, uint_val, double_val, - prop->external_type); - item += item_size; - } - } - else { - item = elem_data + prop->offset; - item_size = ply_type_size[prop->internal_type]; - get_stored_item((void *) item, prop->internal_type, - &int_val, &uint_val, &double_val); - write_binary_item(fp, int_val, uint_val, double_val, - prop->external_type); - } - } - - } -} - - -/****************************************************************************** - Specify a comment that will be written in the header. - - Entry: - plyfile - file identifier - comment - the comment to be written -******************************************************************************/ - -void ply_put_comment(PlyFile *plyfile, char *comment) -{ - /* (re)allocate space for new comment */ - if (plyfile->num_comments == 0) - plyfile->comments = (char **) myalloc(sizeof(char *)); - else - plyfile->comments = (char **) realloc(plyfile->comments, - sizeof(char *) * (plyfile->num_comments + 1)); - - /* add comment to list */ - plyfile->comments[plyfile->num_comments] = strdup(comment); - plyfile->num_comments++; -} - - -/****************************************************************************** - Specify a piece of object information (arbitrary text) that will be written - in the header. - - Entry: - plyfile - file identifier - obj_info - the text information to be written -******************************************************************************/ - -void ply_put_obj_info(PlyFile *plyfile, char *obj_info) -{ - /* (re)allocate space for new info */ - if (plyfile->num_obj_info == 0) - plyfile->obj_info = (char **) myalloc(sizeof(char *)); - else - plyfile->obj_info = (char **) realloc(plyfile->obj_info, - sizeof(char *) * (plyfile->num_obj_info + 1)); - - /* add info to list */ - plyfile->obj_info[plyfile->num_obj_info] = strdup(obj_info); - plyfile->num_obj_info++; -} - - - - - - - -/*************/ -/* Reading */ -/*************/ - - - -/****************************************************************************** - Given a file pointer, get ready to read PLY data from the file. - - Entry: - fp - the given file pointer - - Exit: - nelems - number of elements in object - elem_names - list of element names - returns a pointer to a PlyFile, used to refer to this file, or NULL if error -******************************************************************************/ - -PlyFile *ply_read(FILE *fp, int *nelems, char ***elem_names) -{ - int i, j; - PlyFile *plyfile; - int nwords; - char **words; - int found_format = 0; - char **elist; - PlyElement *elem; - char *orig_line; - - /* check for NULL file pointer */ - if (fp == NULL) - return (NULL); - - /* create record for this object */ - - plyfile = (PlyFile *) myalloc(sizeof(PlyFile)); - plyfile->nelems = 0; - plyfile->comments = NULL; - plyfile->num_comments = 0; - plyfile->obj_info = NULL; - plyfile->num_obj_info = 0; - plyfile->fp = fp; - plyfile->other_elems = NULL; - - /* read and parse the file's header */ - - words = get_words(plyfile->fp, &nwords, &orig_line); - if (!words || !equal_strings(words[0], "ply")) - return (NULL); - - while (words) { - - /* parse words */ - - if (equal_strings(words[0], "format")) { - if (nwords != 3) - return (NULL); - if (equal_strings(words[1], "ascii")) - plyfile->file_type = PLY_ASCII; - else if (equal_strings(words[1], "binary_big_endian")) - plyfile->file_type = PLY_BINARY_BE; - else if (equal_strings(words[1], "binary_little_endian")) - plyfile->file_type = PLY_BINARY_LE; - else - return (NULL); - plyfile->version = (float)atof(words[2]); - found_format = 1; - } - else if (equal_strings(words[0], "element")) - add_element(plyfile, words); - else if (equal_strings(words[0], "property")) - add_property(plyfile, words); - else if (equal_strings(words[0], "comment")) - add_comment(plyfile, orig_line); - else if (equal_strings(words[0], "obj_info")) - add_obj_info(plyfile, orig_line); - else if (equal_strings(words[0], "end_header")) - break; - - /* free up words space */ - free(words); - - words = get_words(plyfile->fp, &nwords, &orig_line); - } - - /* create tags for each property of each element, to be used */ - /* later to say whether or not to store each property for the user */ - - for (i = 0; i < plyfile->nelems; i++) { - elem = plyfile->elems[i]; - elem->store_prop = (char *) myalloc(sizeof(char) * elem->nprops); - for (j = 0; j < elem->nprops; j++) - elem->store_prop[j] = DONT_STORE_PROP; - elem->other_offset = NO_OTHER_PROPS; /* no "other" props by default */ - } - - /* set return values about the elements */ - - elist = (char **) myalloc(sizeof(char *) * plyfile->nelems); - for (i = 0; i < plyfile->nelems; i++) - elist[i] = strdup(plyfile->elems[i]->name); - - *elem_names = elist; - *nelems = plyfile->nelems; - - /* return a pointer to the file's information */ - - return (plyfile); -} - - -/****************************************************************************** - Open a polygon file for reading. - - Entry: - filename - name of file to read from - - Exit: - nelems - number of elements in object - elem_names - list of element names - file_type - file type, either ascii or binary - version - version number of PLY file - returns a file identifier, used to refer to this file, or NULL if error -******************************************************************************/ - -PlyFile *ply_open_for_reading( - char *filename, - int *nelems, - char ***elem_names, - int *file_type, - float *version - ) -{ - FILE *fp; - PlyFile *plyfile; - char *name; - - /* tack on the extension .ply, if necessary */ - - name = (char *) myalloc(sizeof(char) * (strlen(filename) + 5)); - strcpy(name, filename); - if (strlen(name) < 4 || - strcmp(name + strlen(name) - 4, ".ply") != 0) - strcat(name, ".ply"); - - /* open the file for reading */ - - fp = fopen(name, "r"); - if (fp == NULL) - return (NULL); - - /* create the PlyFile data structure */ - - plyfile = ply_read(fp, nelems, elem_names); - - /* determine the file type and version */ - - *file_type = plyfile->file_type; - *version = plyfile->version; - - /* return a pointer to the file's information */ - - return (plyfile); -} - - -/****************************************************************************** - Get information about a particular element. - - Entry: - plyfile - file identifier - elem_name - name of element to get information about - - Exit: - nelems - number of elements of this type in the file - nprops - number of properties - returns a list of properties, or NULL if the file doesn't contain that elem -******************************************************************************/ - -PlyProperty **ply_get_element_description( - PlyFile *plyfile, - char *elem_name, - int *nelems, - int *nprops - ) -{ - int i; - PlyElement *elem; - PlyProperty *prop; - PlyProperty **prop_list; - - /* find information about the element */ - elem = find_element(plyfile, elem_name); - if (elem == NULL) - return (NULL); - - *nelems = elem->num; - *nprops = elem->nprops; - - /* make a copy of the element's property list */ - prop_list = (PlyProperty **) myalloc(sizeof(PlyProperty *) * elem->nprops); - for (i = 0; i < elem->nprops; i++) { - prop = (PlyProperty *) myalloc(sizeof(PlyProperty)); - copy_property(prop, elem->props[i]); - prop_list[i] = prop; - } - - /* return this duplicate property list */ - return (prop_list); -} - - -/****************************************************************************** - Specify which properties of an element are to be returned. This should be - called before a call to the routine ply_get_element(). - - Entry: - plyfile - file identifier - elem_name - which element we're talking about - nprops - number of properties - prop_list - list of properties -******************************************************************************/ - -void ply_get_element_setup( - PlyFile *plyfile, - char *elem_name, - int nprops, - PlyProperty *prop_list - ) -{ - int i; - PlyElement *elem; - PlyProperty *prop; - int index; - - /* find information about the element */ - elem = find_element(plyfile, elem_name); - plyfile->which_elem = elem; - - /* deposit the property information into the element's description */ - for (i = 0; i < nprops; i++) { - - /* look for actual property */ - prop = find_property(elem, prop_list[i].name, &index); - if (prop == NULL) { - fprintf(stderr, "Warning: Can't find property '%s' in element '%s'\n", - prop_list[i].name, elem_name); - continue; - } - - /* store its description */ - prop->internal_type = prop_list[i].internal_type; - prop->offset = prop_list[i].offset; - prop->count_internal = prop_list[i].count_internal; - prop->count_offset = prop_list[i].count_offset; - - /* specify that the user wants this property */ - elem->store_prop[index] = STORE_PROP; - } -} - - -/****************************************************************************** - Specify a property of an element that is to be returned. This should be - called (usually multiple times) before a call to the routine ply_get_element(). - This routine should be used in preference to the less flexible old routine - called ply_get_element_setup(). - - Entry: - plyfile - file identifier - elem_name - which element we're talking about - prop - property to add to those that will be returned -******************************************************************************/ - -void ply_get_property( - PlyFile *plyfile, - char *elem_name, - PlyProperty *prop - ) -{ - PlyElement *elem; - PlyProperty *prop_ptr; - int index; - - /* find information about the element */ - elem = find_element(plyfile, elem_name); - plyfile->which_elem = elem; - - /* deposit the property information into the element's description */ - - prop_ptr = find_property(elem, prop->name, &index); - if (prop_ptr == NULL) { - fprintf(stderr, "Warning: Can't find property '%s' in element '%s'\n", - prop->name, elem_name); - return; - } - prop_ptr->internal_type = prop->internal_type; - prop_ptr->offset = prop->offset; - prop_ptr->count_internal = prop->count_internal; - prop_ptr->count_offset = prop->count_offset; - - /* specify that the user wants this property */ - elem->store_prop[index] = STORE_PROP; -} - - -/****************************************************************************** - Read one element from the file. This routine assumes that we're reading - the type of element specified in the last call to the routine - ply_get_element_setup(). - - Entry: - plyfile - file identifier - elem_ptr - pointer to location where the element information should be put -******************************************************************************/ - -void ply_get_element(PlyFile *plyfile, void *elem_ptr) -{ - if (plyfile->file_type == PLY_ASCII) - ascii_get_element(plyfile, (char *) elem_ptr); - else - binary_get_element(plyfile, (char *) elem_ptr); -} - - -/****************************************************************************** - Extract the comments from the header information of a PLY file. - - Entry: - plyfile - file identifier - - Exit: - num_comments - number of comments returned - returns a pointer to a list of comments -******************************************************************************/ - -char **ply_get_comments(PlyFile *plyfile, int *num_comments) -{ - *num_comments = plyfile->num_comments; - return (plyfile->comments); -} - - -/****************************************************************************** - Extract the object information (arbitrary text) from the header information - of a PLY file. - - Entry: - plyfile - file identifier - - Exit: - num_obj_info - number of lines of text information returned - returns a pointer to a list of object info lines -******************************************************************************/ - -char **ply_get_obj_info(PlyFile *plyfile, int *num_obj_info) -{ - *num_obj_info = plyfile->num_obj_info; - return (plyfile->obj_info); -} - - -/****************************************************************************** - Make ready for "other" properties of an element-- those properties that - the user has not explicitly asked for, but that are to be stashed away - in a special structure to be carried along with the element's other - information. - - Entry: - plyfile - file identifier - elem - element for which we want to save away other properties -******************************************************************************/ - -void setup_other_props(PlyElement *elem) -{ - int i; - PlyProperty *prop; - int size = 0; - int type_size; - - /* Examine each property in decreasing order of size. */ - /* We do this so that all data types will be aligned by */ - /* word, half-word, or whatever within the structure. */ - - for (type_size = 8; type_size > 0; type_size /= 2) { - - /* add up the space taken by each property, and save this information */ - /* away in the property descriptor */ - - for (i = 0; i < elem->nprops; i++) { - - /* don't bother with properties we've been asked to store explicitly */ - if (elem->store_prop[i]) - continue; - - prop = elem->props[i]; - - /* internal types will be same as external */ - prop->internal_type = prop->external_type; - prop->count_internal = prop->count_external; - - /* check list case */ - if (prop->is_list) { - - /* pointer to list */ - if (type_size == sizeof(void *)) { - prop->offset = size; - size += sizeof(void *); /* always use size of a pointer here */ - } - - /* count of number of list elements */ - if (type_size == ply_type_size[prop->count_external]) { - prop->count_offset = size; - size += ply_type_size[prop->count_external]; - } - } - /* not list */ - else if (type_size == ply_type_size[prop->external_type]) { - prop->offset = size; - size += ply_type_size[prop->external_type]; - } - } - - } - - /* save the size for the other_props structure */ - elem->other_size = size; -} - - -/****************************************************************************** - Specify that we want the "other" properties of an element to be tucked - away within the user's structure. The user needn't be concerned for how - these properties are stored. - - Entry: - plyfile - file identifier - elem_name - name of element that we want to store other_props in - offset - offset to where other_props will be stored inside user's structure - - Exit: - returns pointer to structure containing description of other_props -******************************************************************************/ - -PlyOtherProp *ply_get_other_properties( - PlyFile *plyfile, - char *elem_name, - int offset - ) -{ - int i; - PlyElement *elem; - PlyOtherProp *other; - PlyProperty *prop; - int nprops; - - /* find information about the element */ - elem = find_element(plyfile, elem_name); - if (elem == NULL) { - fprintf(stderr, "ply_get_other_properties: Can't find element '%s'\n", - elem_name); - return (NULL); - } - - /* remember that this is the "current" element */ - plyfile->which_elem = elem; - - /* save the offset to where to store the other_props */ - elem->other_offset = offset; - - /* place the appropriate pointers, etc. in the element's property list */ - setup_other_props(elem); - - /* create structure for describing other_props */ - other = (PlyOtherProp *) myalloc(sizeof(PlyOtherProp)); - other->name = strdup(elem_name); -#if 0 - if (elem->other_offset == NO_OTHER_PROPS) { - other->size = 0; - other->props = NULL; - other->nprops = 0; - return (other); - } -#endif - other->size = elem->other_size; - other->props = (PlyProperty **) myalloc(sizeof(PlyProperty) * elem->nprops); - - /* save descriptions of each "other" property */ - nprops = 0; - for (i = 0; i < elem->nprops; i++) { - if (elem->store_prop[i]) - continue; - prop = (PlyProperty *) myalloc(sizeof(PlyProperty)); - copy_property(prop, elem->props[i]); - other->props[nprops] = prop; - nprops++; - } - other->nprops = nprops; - -#if 1 - /* set other_offset pointer appropriately if there are NO other properties */ - if (other->nprops == 0) { - elem->other_offset = NO_OTHER_PROPS; - } -#endif - - /* return structure */ - return (other); -} - - - - -/*************************/ -/* Other Element Stuff */ -/*************************/ - - - - -/****************************************************************************** - Grab all the data for an element that a user does not want to explicitly - read in. - - Entry: - plyfile - pointer to file - elem_name - name of element whose data is to be read in - elem_count - number of instances of this element stored in the file - - Exit: - returns pointer to ALL the "other" element data for this PLY file -******************************************************************************/ - -PlyOtherElems *ply_get_other_element( - PlyFile *plyfile, - char *elem_name, - int elem_count - ) -{ - int i; - PlyElement *elem; - PlyOtherElems *other_elems; - OtherElem *other; - - /* look for appropriate element */ - elem = find_element(plyfile, elem_name); - if (elem == NULL) { - fprintf(stderr, - "ply_get_other_element: can't find element '%s'\n", elem_name); - exit(-1); - } - - /* create room for the new "other" element, initializing the */ - /* other data structure if necessary */ - - if (plyfile->other_elems == NULL) { - plyfile->other_elems = (PlyOtherElems *) myalloc(sizeof(PlyOtherElems)); - other_elems = plyfile->other_elems; - other_elems->other_list = (OtherElem *) myalloc(sizeof(OtherElem)); - other = &(other_elems->other_list[0]); - other_elems->num_elems = 1; - } - else { - other_elems = plyfile->other_elems; - other_elems->other_list = (OtherElem *) realloc(other_elems->other_list, - sizeof(OtherElem) * other_elems->num_elems + 1); - other = &(other_elems->other_list[other_elems->num_elems]); - other_elems->num_elems++; - } - - /* count of element instances in file */ - other->elem_count = elem_count; - - /* save name of element */ - other->elem_name = strdup(elem_name); - - /* create a list to hold all the current elements */ - other->other_data = (OtherData **) - malloc(sizeof(OtherData *) * other->elem_count); - - /* set up for getting elements */ - other->other_props = ply_get_other_properties(plyfile, elem_name, - offsetof(OtherData, other_props)); - - /* grab all these elements */ - for (i = 0; i < other->elem_count; i++) { - /* grab and element from the file */ - other->other_data[i] = (OtherData *) malloc(sizeof(OtherData)); - ply_get_element(plyfile, (void *) other->other_data[i]); - } - - /* return pointer to the other elements data */ - return (other_elems); -} - - -/****************************************************************************** - Pass along a pointer to "other" elements that we want to save in a given - PLY file. These other elements were presumably read from another PLY file. - - Entry: - plyfile - file pointer in which to store this other element info - other_elems - info about other elements that we want to store -******************************************************************************/ - -void ply_describe_other_elements( - PlyFile *plyfile, - PlyOtherElems *other_elems - ) -{ - int i; - OtherElem *other; - - /* ignore this call if there is no other element */ - if (other_elems == NULL) - return; - - /* save pointer to this information */ - plyfile->other_elems = other_elems; - - /* describe the other properties of this element */ - - for (i = 0; i < other_elems->num_elems; i++) { - other = &(other_elems->other_list[i]); - ply_element_count(plyfile, other->elem_name, other->elem_count); - ply_describe_other_properties(plyfile, other->other_props, - offsetof(OtherData, other_props)); - } -} - - -/****************************************************************************** - Write out the "other" elements specified for this PLY file. - - Entry: - plyfile - pointer to PLY file to write out other elements for -******************************************************************************/ - -void ply_put_other_elements(PlyFile *plyfile) -{ - int i, j; - OtherElem *other; - - /* make sure we have other elements to write */ - if (plyfile->other_elems == NULL) - return; - - /* write out the data for each "other" element */ - - for (i = 0; i < plyfile->other_elems->num_elems; i++) { - - other = &(plyfile->other_elems->other_list[i]); - ply_put_element_setup(plyfile, other->elem_name); - - /* write out each instance of the current element */ - for (j = 0; j < other->elem_count; j++) - ply_put_element(plyfile, (void *) other->other_data[j]); - } -} - - -/****************************************************************************** - Free up storage used by an "other" elements data structure. - - Entry: - other_elems - data structure to free up -******************************************************************************/ - - - - -/*******************/ -/* Miscellaneous */ -/*******************/ - - - -/****************************************************************************** - Close a PLY file. - - Entry: - plyfile - identifier of file to close -******************************************************************************/ - -void ply_close(PlyFile *plyfile) -{ - fclose(plyfile->fp); - - /* free up memory associated with the PLY file */ - free(plyfile); -} - - -/****************************************************************************** - Get version number and file type of a PlyFile. - - Entry: - ply - pointer to PLY file - - Exit: - version - version of the file - file_type - PLY_ASCII, PLY_BINARY_BE, or PLY_BINARY_LE -******************************************************************************/ - -void ply_get_info(PlyFile *ply, float *version, int *file_type) -{ - if (ply == NULL) - return; - - *version = ply->version; - *file_type = ply->file_type; -} - - -/****************************************************************************** - Compare two strings. Returns 1 if they are the same, 0 if not. -******************************************************************************/ - -int equal_strings(char *s1, char *s2) -{ - - while (*s1 && *s2) - if (*s1++ != *s2++) - return (0); - - if (*s1 != *s2) - return (0); - else - return (1); -} - - -/****************************************************************************** - Find an element from the element list of a given PLY object. - - Entry: - plyfile - file id for PLY file - element - name of element we're looking for - - Exit: - returns the element, or NULL if not found -******************************************************************************/ - -PlyElement *find_element(PlyFile *plyfile, char *element) -{ - int i; - - for (i = 0; i < plyfile->nelems; i++) - if (equal_strings(element, plyfile->elems[i]->name)) - return (plyfile->elems[i]); - - return (NULL); -} - - -/****************************************************************************** - Find a property in the list of properties of a given element. - - Entry: - elem - pointer to element in which we want to find the property - prop_name - name of property to find - - Exit: - index - index to position in list - returns a pointer to the property, or NULL if not found -******************************************************************************/ - -PlyProperty *find_property(PlyElement *elem, char *prop_name, int *index) -{ - int i; - - for (i = 0; i < elem->nprops; i++) - if (equal_strings(prop_name, elem->props[i]->name)) { - *index = i; - return (elem->props[i]); - } - - *index = -1; - return (NULL); -} - - -/****************************************************************************** - Read an element from an ascii file. - - Entry: - plyfile - file identifier - elem_ptr - pointer to element -******************************************************************************/ - -void ascii_get_element(PlyFile *plyfile, char *elem_ptr) -{ - int j, k; - PlyElement *elem; - PlyProperty *prop; - char **words; - int nwords; - int which_word; - char *elem_data, *item; - char *item_ptr; - int item_size; - int int_val; - unsigned int uint_val; - double double_val; - int list_count; - int store_it; - char **store_array; - char *orig_line; - char *other_data; - int other_flag; - - other_flag = 0; - other_data = NULL; - item = NULL; - item_size = 0; - - /* the kind of element we're reading currently */ - elem = plyfile->which_elem; - - /* do we need to setup for other_props? */ - - if (elem->other_offset != NO_OTHER_PROPS) { - char **ptr; - other_flag = 1; - /* make room for other_props */ - other_data = (char *) myalloc(elem->other_size); - /* store pointer in user's structure to the other_props */ - ptr = (char **) (elem_ptr + elem->other_offset); - *ptr = other_data; - } - else { - other_flag = 0; - other_data = NULL; - item = NULL; - item_size = 0; - } - - /* read in the element */ - - words = get_words(plyfile->fp, &nwords, &orig_line); - if (words == NULL) { - fprintf(stderr, "ply_get_element: unexpected end of file\n"); - exit(-1); - } - - which_word = 0; - - for (j = 0; j < elem->nprops; j++) { - - prop = elem->props[j]; - store_it = (elem->store_prop[j] | other_flag); - - /* store either in the user's structure or in other_props */ - if (elem->store_prop[j]) - elem_data = elem_ptr; - else - elem_data = other_data; - - if (prop->is_list) { /* a list */ - - /* get and store the number of items in the list */ - get_ascii_item(words[which_word++], prop->count_external, - &int_val, &uint_val, &double_val); - if (store_it) { - item = elem_data + prop->count_offset; - store_item(item, prop->count_internal, int_val, uint_val, double_val); - } - - /* allocate space for an array of items and store a ptr to the array */ - list_count = int_val; - item_size = ply_type_size[prop->internal_type]; - store_array = (char **) (elem_data + prop->offset); - - if (list_count == 0) { - if (store_it) - *store_array = NULL; - } - else { - if (store_it) { - item_ptr = (char *) myalloc(sizeof(char) * item_size * list_count); - item = item_ptr; - *store_array = item_ptr; - } - - /* read items and store them into the array */ - for (k = 0; k < list_count; k++) { - get_ascii_item(words[which_word++], prop->external_type, - &int_val, &uint_val, &double_val); - if (store_it) { - store_item(item, prop->internal_type, - int_val, uint_val, double_val); - item += item_size; - } - } - } - - } - else { /* not a list */ - get_ascii_item(words[which_word++], prop->external_type, - &int_val, &uint_val, &double_val); - if (store_it) { - item = elem_data + prop->offset; - store_item(item, prop->internal_type, int_val, uint_val, double_val); - } - } - - } - - free(words); -} - - -/****************************************************************************** - Read an element from a binary file. - - Entry: - plyfile - file identifier - elem_ptr - pointer to an element -******************************************************************************/ - -void binary_get_element(PlyFile *plyfile, char *elem_ptr) -{ - int j, k; - PlyElement *elem; - PlyProperty *prop; - FILE *fp = plyfile->fp; - char *elem_data, *item; - char *item_ptr; - int item_size; - int int_val; - unsigned int uint_val; - double double_val; - int list_count; - int store_it; - char **store_array; - char *other_data; - int other_flag; - - - other_flag = 0; - other_data = NULL; - item = NULL; - item_size = 0; - - /* the kind of element we're reading currently */ - elem = plyfile->which_elem; - - /* do we need to setup for other_props? */ - - if (elem->other_offset != NO_OTHER_PROPS) { - char **ptr; - other_flag = 1; - /* make room for other_props */ - other_data = (char *) myalloc(elem->other_size); - /* store pointer in user's structure to the other_props */ - ptr = (char **) (elem_ptr + elem->other_offset); - *ptr = other_data; - } - else { - other_flag = 0; - other_data = NULL; - item = NULL; - item_size = 0; - } - /* read in a number of elements */ - - for (j = 0; j < elem->nprops; j++) { - - prop = elem->props[j]; - store_it = (elem->store_prop[j] | other_flag); - - /* store either in the user's structure or in other_props */ - if (elem->store_prop[j]) - elem_data = elem_ptr; - else - elem_data = other_data; - - if (prop->is_list) { /* a list */ - - /* get and store the number of items in the list */ - get_binary_item(fp, prop->count_external, - &int_val, &uint_val, &double_val); - if (store_it) { - item = elem_data + prop->count_offset; - store_item(item, prop->count_internal, int_val, uint_val, double_val); - } - - /* allocate space for an array of items and store a ptr to the array */ - list_count = int_val; - /* The "if" was added by Afra Zomorodian 8/22/95 - * so that zipper won't crash reading plies that have additional - * properties. - */ - if (store_it) { - item_size = ply_type_size[prop->internal_type]; - } - store_array = (char **) (elem_data + prop->offset); - if (list_count == 0) { - if (store_it) - *store_array = NULL; - } - else { - if (store_it) { - item_ptr = (char *) myalloc(sizeof(char) * item_size * list_count); - item = item_ptr; - *store_array = item_ptr; - } - - /* read items and store them into the array */ - for (k = 0; k < list_count; k++) { - get_binary_item(fp, prop->external_type, - &int_val, &uint_val, &double_val); - if (store_it) { - store_item(item, prop->internal_type, - int_val, uint_val, double_val); - item += item_size; - } - } - } - - } - else { /* not a list */ - get_binary_item(fp, prop->external_type, - &int_val, &uint_val, &double_val); - if (store_it) { - item = elem_data + prop->offset; - store_item(item, prop->internal_type, int_val, uint_val, double_val); - } - } - - } -} - - -/****************************************************************************** - Write to a file the word that represents a PLY data type. - - Entry: - fp - file pointer - code - code for type -******************************************************************************/ - -void write_scalar_type(FILE *fp, int code) -{ - /* make sure this is a valid code */ - - if (code <= PLY_START_TYPE || code >= PLY_END_TYPE) { - fprintf(stderr, "write_scalar_type: bad data code = %d\n", code); - exit(-1); - } - - /* write the code to a file */ - - fprintf(fp, "%s", type_names[code]); -} - - -/****************************************************************************** - Get a text line from a file and break it up into words. - - IMPORTANT: The calling routine call "free" on the returned pointer once - finished with it. - - Entry: - fp - file to read from - - Exit: - nwords - number of words returned - orig_line - the original line of characters - returns a list of words from the line, or NULL if end-of-file -******************************************************************************/ - -char **get_words(FILE *fp, int *nwords, char **orig_line) -{ -#define BIG_STRING 4096 - static char str[BIG_STRING]; - static char str_copy[BIG_STRING]; - char **words; - int max_words = 10; - int num_words = 0; - char *ptr, *ptr2; - char *result; - - words = (char **) myalloc(sizeof(char *) * max_words); - - /* read in a line */ - result = fgets(str, BIG_STRING, fp); - if (result == NULL) { - *nwords = 0; - *orig_line = NULL; - return (NULL); - } - - /* convert line-feed and tabs into spaces */ - /* (this guarentees that there will be a space before the */ - /* null character at the end of the string) */ - - str[BIG_STRING - 2] = ' '; - str[BIG_STRING - 1] = '\0'; - - for (ptr = str, ptr2 = str_copy; *ptr != '\0'; ptr++, ptr2++) { - *ptr2 = *ptr; - if (*ptr == '\t') { - *ptr = ' '; - *ptr2 = ' '; - } - else if (*ptr == '\n') { - *ptr = ' '; - *ptr2 = '\0'; - break; - } - } - - /* find the words in the line */ - - ptr = str; - while (*ptr != '\0') { - - /* jump over leading spaces */ - while (*ptr == ' ') - ptr++; - - /* break if we reach the end */ - if (*ptr == '\0') - break; - - /* save pointer to beginning of word */ - if (num_words >= max_words) { - max_words += 10; - words = (char **) realloc(words, sizeof(char *) * max_words); - } - words[num_words++] = ptr; - - /* jump over non-spaces */ - while (*ptr != ' ') - ptr++; - - /* place a null character here to mark the end of the word */ - *ptr++ = '\0'; - } - - /* return the list of words */ - *nwords = num_words; - *orig_line = str_copy; - return (words); -} - - -/****************************************************************************** - Return the value of an item, given a pointer to it and its type. - - Entry: - item - pointer to item - type - data type that "item" points to - - Exit: - returns a double-precision float that contains the value of the item -******************************************************************************/ - -double get_item_value(char *item, int type) -{ - unsigned char *puchar; - char *pchar; - short int *pshort; - unsigned short int *pushort; - int *pint; - unsigned int *puint; - float *pfloat; - double *pdouble; - int int_value; - unsigned int uint_value; - double double_value; - - switch (type) { - case PLY_CHAR: - pchar = (char *) item; - int_value = *pchar; - return ((double) int_value); - case PLY_UCHAR: - puchar = (unsigned char *) item; - int_value = *puchar; - return ((double) int_value); - case PLY_SHORT: - pshort = (short int *) item; - int_value = *pshort; - return ((double) int_value); - case PLY_USHORT: - pushort = (unsigned short int *) item; - int_value = *pushort; - return ((double) int_value); - case PLY_INT: - pint = (int *) item; - int_value = *pint; - return ((double) int_value); - case PLY_UINT: - puint = (unsigned int *) item; - uint_value = *puint; - return ((double) uint_value); - case PLY_FLOAT: - pfloat = (float *) item; - double_value = *pfloat; - return (double_value); - case PLY_DOUBLE: - pdouble = (double *) item; - double_value = *pdouble; - return (double_value); - default: - fprintf(stderr, "get_item_value: bad type = %d\n", type); - exit(-1); - } -} - - -/****************************************************************************** - Write out an item to a file as raw binary bytes. - - Entry: - fp - file to write to - int_val - integer version of item - uint_val - unsigned integer version of item - double_val - double-precision float version of item - type - data type to write out -******************************************************************************/ - -void write_binary_item( - FILE *fp, - int int_val, - unsigned int uint_val, - double double_val, - int type - ) -{ - unsigned char uchar_val; - char char_val; - unsigned short ushort_val; - short short_val; - float float_val; - - switch (type) { - case PLY_CHAR: - char_val = (char)int_val; - fwrite(&char_val, 1, 1, fp); - break; - case PLY_SHORT: - short_val = (short)int_val; - fwrite(&short_val, 2, 1, fp); - break; - case PLY_INT: - fwrite(&int_val, 4, 1, fp); - break; - case PLY_UCHAR: - uchar_val = (unsigned char) uint_val; - fwrite(&uchar_val, 1, 1, fp); - break; - case PLY_USHORT: - ushort_val = (unsigned short)uint_val; - fwrite(&ushort_val, 2, 1, fp); - break; - case PLY_UINT: - fwrite(&uint_val, 4, 1, fp); - break; - case PLY_FLOAT: - float_val = (float) double_val; - fwrite(&float_val, 4, 1, fp); - break; - case PLY_DOUBLE: - fwrite(&double_val, 8, 1, fp); - break; - default: - fprintf(stderr, "write_binary_item: bad type = %d\n", type); - exit(-1); - } -} - - -/****************************************************************************** - Write out an item to a file as ascii characters. - - Entry: - fp - file to write to - int_val - integer version of item - uint_val - unsigned integer version of item - double_val - double-precision float version of item - type - data type to write out -******************************************************************************/ - -void write_ascii_item( - FILE *fp, - int int_val, - unsigned int uint_val, - double double_val, - int type - ) -{ - switch (type) { - case PLY_CHAR: - case PLY_SHORT: - case PLY_INT: - fprintf(fp, "%d ", int_val); - break; - case PLY_UCHAR: - case PLY_USHORT: - case PLY_UINT: - fprintf(fp, "%u ", uint_val); - break; - case PLY_FLOAT: - case PLY_DOUBLE: - fprintf(fp, "%g ", double_val); - break; - default: - fprintf(stderr, "write_ascii_item: bad type = %d\n", type); - exit(-1); - } -} - - -/****************************************************************************** - Write out an item to a file as ascii characters. - - Entry: - fp - file to write to - item - pointer to item to write - type - data type that "item" points to - - Exit: - returns a double-precision float that contains the value of the written item -******************************************************************************/ - -double old_write_ascii_item(FILE *fp, char *item, int type) -{ - unsigned char *puchar; - char *pchar; - short int *pshort; - unsigned short int *pushort; - int *pint; - unsigned int *puint; - float *pfloat; - double *pdouble; - int int_value; - unsigned int uint_value; - double double_value; - - switch (type) { - case PLY_CHAR: - pchar = (char *) item; - int_value = *pchar; - fprintf(fp, "%d ", int_value); - return ((double) int_value); - case PLY_UCHAR: - puchar = (unsigned char *) item; - int_value = *puchar; - fprintf(fp, "%d ", int_value); - return ((double) int_value); - case PLY_SHORT: - pshort = (short int *) item; - int_value = *pshort; - fprintf(fp, "%d ", int_value); - return ((double) int_value); - case PLY_USHORT: - pushort = (unsigned short int *) item; - int_value = *pushort; - fprintf(fp, "%d ", int_value); - return ((double) int_value); - case PLY_INT: - pint = (int *) item; - int_value = *pint; - fprintf(fp, "%d ", int_value); - return ((double) int_value); - case PLY_UINT: - puint = (unsigned int *) item; - uint_value = *puint; - fprintf(fp, "%u ", uint_value); - return ((double) uint_value); - case PLY_FLOAT: - pfloat = (float *) item; - double_value = *pfloat; - fprintf(fp, "%g ", double_value); - return (double_value); - case PLY_DOUBLE: - pdouble = (double *) item; - double_value = *pdouble; - fprintf(fp, "%g ", double_value); - return (double_value); - default: - fprintf(stderr, "old_write_ascii_item: bad type = %d\n", type); - exit(-1); - } -} - - -/****************************************************************************** - Get the value of an item that is in memory, and place the result - into an integer, an unsigned integer and a double. - - Entry: - ptr - pointer to the item - type - data type supposedly in the item - - Exit: - int_val - integer value - uint_val - unsigned integer value - double_val - double-precision floating point value -******************************************************************************/ - -void get_stored_item( - void *ptr, - int type, - int *int_val, - unsigned int *uint_val, - double *double_val - ) -{ - switch (type) { - case PLY_CHAR: - *int_val = *((char *) ptr); - *uint_val = *int_val; - *double_val = *int_val; - break; - case PLY_UCHAR: - *uint_val = *((unsigned char *) ptr); - *int_val = *uint_val; - *double_val = *uint_val; - break; - case PLY_SHORT: - *int_val = *((short int *) ptr); - *uint_val = *int_val; - *double_val = *int_val; - break; - case PLY_USHORT: - *uint_val = *((unsigned short int *) ptr); - *int_val = *uint_val; - *double_val = *uint_val; - break; - case PLY_INT: - *int_val = *((int *) ptr); - *uint_val = *int_val; - *double_val = *int_val; - break; - case PLY_UINT: - *uint_val = *((unsigned int *) ptr); - *int_val = *uint_val; - *double_val = *uint_val; - break; - case PLY_FLOAT: - *double_val = *((float *) ptr); - *int_val = (int)*double_val; - *uint_val = (unsigned int)*double_val; - break; - case PLY_DOUBLE: - *double_val = *((double *) ptr); - *int_val = (int)*double_val; - *uint_val = (unsigned int) *double_val; - break; - default: - fprintf(stderr, "get_stored_item: bad type = %d\n", type); - exit(-1); - } -} - - -/****************************************************************************** - Get the value of an item from a binary file, and place the result - into an integer, an unsigned integer and a double. - - Entry: - fp - file to get item from - type - data type supposedly in the word - - Exit: - int_val - integer value - uint_val - unsigned integer value - double_val - double-precision floating point value -******************************************************************************/ - -void get_binary_item( - FILE *fp, - int type, - int *int_val, - unsigned int *uint_val, - double *double_val - ) -{ - char c[8]; - void *ptr; - - ptr = (void *) c; - - switch (type) { - case PLY_CHAR: - fread(ptr, 1, 1, fp); - *int_val = *((char *) ptr); - *uint_val = *int_val; - *double_val = *int_val; - break; - case PLY_UCHAR: - fread(ptr, 1, 1, fp); - *uint_val = *((unsigned char *) ptr); - *int_val = *uint_val; - *double_val = *uint_val; - break; - case PLY_SHORT: - fread(ptr, 2, 1, fp); - *int_val = *((short int *) ptr); - *uint_val = *int_val; - *double_val = *int_val; - break; - case PLY_USHORT: - fread(ptr, 2, 1, fp); - *uint_val = *((unsigned short int *) ptr); - *int_val = *uint_val; - *double_val = *uint_val; - break; - case PLY_INT: - fread(ptr, 4, 1, fp); - *int_val = *((int *) ptr); - *uint_val = *int_val; - *double_val = *int_val; - break; - case PLY_UINT: - fread(ptr, 4, 1, fp); - *uint_val = *((unsigned int *) ptr); - *int_val = *uint_val; - *double_val = *uint_val; - break; - case PLY_FLOAT: - fread(ptr, 4, 1, fp); - *double_val = *((float *) ptr); - *int_val = (int)*double_val; - *uint_val = (unsigned int) *double_val; - break; - case PLY_DOUBLE: - fread(ptr, 8, 1, fp); - *double_val = *((double *) ptr); - *int_val = (int)*double_val; - *uint_val = (unsigned int)*double_val; - break; - default: - fprintf(stderr, "get_binary_item: bad type = %d\n", type); - exit(-1); - } -} - - -/****************************************************************************** - Extract the value of an item from an ascii word, and place the result - into an integer, an unsigned integer and a double. - - Entry: - word - word to extract value from - type - data type supposedly in the word - - Exit: - int_val - integer value - uint_val - unsigned integer value - double_val - double-precision floating point value -******************************************************************************/ - -void get_ascii_item( - char *word, - int type, - int *int_val, - unsigned int *uint_val, - double *double_val - ) -{ - switch (type) { - case PLY_CHAR: - case PLY_UCHAR: - case PLY_SHORT: - case PLY_USHORT: - case PLY_INT: - *int_val = atoi(word); - *uint_val = *int_val; - *double_val = *int_val; - break; - - case PLY_UINT: - *uint_val = strtoul(word, (char **) NULL, 10); - *int_val = *uint_val; - *double_val = *uint_val; - break; - - case PLY_FLOAT: - case PLY_DOUBLE: - *double_val = atof(word); - *int_val = (int) *double_val; - *uint_val = (unsigned int) *double_val; - break; - - default: - fprintf(stderr, "get_ascii_item: bad type = %d\n", type); - exit(-1); - } -} - - -/****************************************************************************** - Store a value into a place being pointed to, guided by a data type. - - Entry: - item - place to store value - type - data type - int_val - integer version of value - uint_val - unsigned integer version of value - double_val - double version of value - - Exit: - item - pointer to stored value -******************************************************************************/ - -void store_item( - char *item, - int type, - int int_val, - unsigned int uint_val, - double double_val - ) -{ - unsigned char *puchar; - short int *pshort; - unsigned short int *pushort; - int *pint; - unsigned int *puint; - float *pfloat; - double *pdouble; - - switch (type) { - case PLY_CHAR: - *item = (char) int_val; - break; - case PLY_UCHAR: - puchar = (unsigned char *) item; - *puchar = (unsigned char)uint_val; - break; - case PLY_SHORT: - pshort = (short *) item; - *pshort = (short)int_val; - break; - case PLY_USHORT: - pushort = (unsigned short *) item; - *pushort = (unsigned short)uint_val; - break; - case PLY_INT: - pint = (int *) item; - *pint = int_val; - break; - case PLY_UINT: - puint = (unsigned int *) item; - *puint = uint_val; - break; - case PLY_FLOAT: - pfloat = (float *) item; - *pfloat = (float)double_val; - break; - case PLY_DOUBLE: - pdouble = (double *) item; - *pdouble = double_val; - break; - default: - fprintf(stderr, "store_item: bad type = %d\n", type); - exit(-1); - } -} - - -/****************************************************************************** - Add an element to a PLY file descriptor. - - Entry: - plyfile - PLY file descriptor - words - list of words describing the element - nwords - number of words in the list -******************************************************************************/ - -void add_element(PlyFile *plyfile, char **words) -{ - PlyElement *elem; - - /* create the new element */ - elem = (PlyElement *) myalloc(sizeof(PlyElement)); - elem->name = strdup(words[1]); - elem->num = atoi(words[2]); - elem->nprops = 0; - - /* make room for new element in the object's list of elements */ - if (plyfile->nelems == 0) - plyfile->elems = (PlyElement **) myalloc(sizeof(PlyElement *)); - else - plyfile->elems = (PlyElement **) realloc(plyfile->elems, - sizeof(PlyElement *) * (plyfile->nelems + 1)); - - /* add the new element to the object's list */ - plyfile->elems[plyfile->nelems] = elem; - plyfile->nelems++; -} - - -/****************************************************************************** - Return the type of a property, given the name of the property. - - Entry: - name - name of property type - - Exit: - returns integer code for property, or 0 if not found -******************************************************************************/ - -int get_prop_type(char *type_name) -{ - int i; - - for (i = PLY_START_TYPE + 1; i < PLY_END_TYPE; i++) - if (equal_strings(type_name, type_names[i])) - return (i); - - /* if we get here, we didn't find the type */ - return (0); -} - - -/****************************************************************************** - Add a property to a PLY file descriptor. - - Entry: - plyfile - PLY file descriptor - words - list of words describing the property - nwords - number of words in the list -******************************************************************************/ - -void add_property(PlyFile *plyfile, char **words) -{ - PlyProperty *prop; - PlyElement *elem; - - /* create the new property */ - - prop = (PlyProperty *) myalloc(sizeof(PlyProperty)); - - if (equal_strings(words[1], "list")) { /* is a list */ - prop->count_external = get_prop_type(words[2]); - prop->external_type = get_prop_type(words[3]); - prop->name = strdup(words[4]); - prop->is_list = 1; - } - else { /* not a list */ - prop->external_type = get_prop_type(words[1]); - prop->name = strdup(words[2]); - prop->is_list = 0; - } - - /* add this property to the list of properties of the current element */ - - elem = plyfile->elems[plyfile->nelems - 1]; - - if (elem->nprops == 0) - elem->props = (PlyProperty **) myalloc(sizeof(PlyProperty *)); - else - elem->props = (PlyProperty **) realloc(elem->props, - sizeof(PlyProperty *) * (elem->nprops + 1)); - - elem->props[elem->nprops] = prop; - elem->nprops++; -} - - -/****************************************************************************** - Add a comment to a PLY file descriptor. - - Entry: - plyfile - PLY file descriptor - line - line containing comment -******************************************************************************/ - -void add_comment(PlyFile *plyfile, char *line) -{ - int i; - - /* skip over "comment" and leading spaces and tabs */ - i = 7; - while (line[i] == ' ' || line[i] == '\t') - i++; - - ply_put_comment(plyfile, &line[i]); -} - - -/****************************************************************************** - Add a some object information to a PLY file descriptor. - - Entry: - plyfile - PLY file descriptor - line - line containing text info -******************************************************************************/ - -void add_obj_info(PlyFile *plyfile, char *line) -{ - int i; - - /* skip over "obj_info" and leading spaces and tabs */ - i = 8; - while (line[i] == ' ' || line[i] == '\t') - i++; - - ply_put_obj_info(plyfile, &line[i]); -} - - -/****************************************************************************** - Copy a property. -******************************************************************************/ - -void copy_property(PlyProperty *dest, PlyProperty *src) -{ - dest->name = strdup(src->name); - dest->external_type = src->external_type; - dest->internal_type = src->internal_type; - dest->offset = src->offset; - - dest->is_list = src->is_list; - dest->count_external = src->count_external; - dest->count_internal = src->count_internal; - dest->count_offset = src->count_offset; -} - - -/****************************************************************************** - Allocate some memory. - - Entry: - size - amount of memory requested (in bytes) - lnum - line number from which memory was requested - fname - file name from which memory was requested -******************************************************************************/ - -static char *my_alloc(int size, int lnum, char *fname) -{ - char *ptr; - - ptr = (char *) malloc(size); - - if (ptr == 0) { - fprintf(stderr, "Memory allocation bombed on line %d in %s\n", lnum, fname); - } - - return (ptr); -} - diff --git a/intern/cycles/app/cycles_test.cpp b/intern/cycles/app/cycles_test.cpp index f5890998adc..75f76efc8e1 100644 --- a/intern/cycles/app/cycles_test.cpp +++ b/intern/cycles/app/cycles_test.cpp @@ -245,7 +245,7 @@ static void options_parse(int argc, const char **argv) NULL); if(ap.parse(argc, argv) < 0) { - fprintf(stderr, "%s\n", ap.error_message().c_str()); + fprintf(stderr, "%s\n", ap.geterror().c_str()); ap.usage(); exit(EXIT_FAILURE); } diff --git a/intern/cycles/blender/blender_object.cpp b/intern/cycles/blender/blender_object.cpp index 242f7c8ecef..eb9cc7bc4de 100644 --- a/intern/cycles/blender/blender_object.cpp +++ b/intern/cycles/blender/blender_object.cpp @@ -247,8 +247,11 @@ void BlenderSync::sync_object(BL::Object b_parent, int b_index, BL::Object b_ob, scene->object_manager->tag_update(scene); } + /* updated dupli objects require particle sync */ + bool need_particle_update = object_need_particle_update(b_ob); + /* object sync */ - if(object_updated || (object->mesh && object->mesh->need_update)) { + if(object_updated || (object->mesh && object->mesh->need_update) || need_particle_update) { object->name = b_ob.name().c_str(); object->pass_id = b_ob.pass_index(); object->tfm = tfm; @@ -275,7 +278,7 @@ void BlenderSync::sync_object(BL::Object b_parent, int b_index, BL::Object b_ob, object->particle_id = particle_id; /* particle sync */ - if (object_use_particles(b_ob)) + if (need_particle_update) sync_particles(object, b_ob); object->tag_update(scene); diff --git a/intern/cycles/blender/blender_particles.cpp b/intern/cycles/blender/blender_particles.cpp index d669aa34a68..e32c80a51b5 100644 --- a/intern/cycles/blender/blender_particles.cpp +++ b/intern/cycles/blender/blender_particles.cpp @@ -31,7 +31,7 @@ CCL_NAMESPACE_BEGIN /* Particles Sync */ -bool BlenderSync::object_use_particles(BL::Object b_ob) +bool BlenderSync::object_need_particle_update(BL::Object b_ob) { /* Particle data is only needed for * a) Billboard render mode if object's own material uses particle info @@ -39,7 +39,7 @@ bool BlenderSync::object_use_particles(BL::Object b_ob) * * Note: Meshes have to be synced at this point! */ - bool use_particles = false; + bool need_update = false; BL::Object::particle_systems_iterator b_psys; for (b_ob.particle_systems.begin(b_psys); b_psys != b_ob.particle_systems.end(); ++b_psys) { @@ -54,7 +54,7 @@ bool BlenderSync::object_use_particles(BL::Object b_ob) BL::ID key = (BKE_object_is_modified(b_ob))? b_ob: b_ob.data(); Mesh *mesh = mesh_map.find(key); if (mesh) { - use_particles |= mesh->need_attribute(scene, ATTR_STD_PARTICLE); + need_update |= mesh->need_attribute(scene, ATTR_STD_PARTICLE) && mesh->need_update; } break; } @@ -66,7 +66,7 @@ bool BlenderSync::object_use_particles(BL::Object b_ob) BL::ID key = (BKE_object_is_modified(b_dupli_ob))? b_dupli_ob: b_dupli_ob.data(); Mesh *mesh = mesh_map.find(key); if (mesh) { - use_particles |= mesh->need_attribute(scene, ATTR_STD_PARTICLE); + need_update |= mesh->need_attribute(scene, ATTR_STD_PARTICLE) && mesh->need_update; } } break; @@ -80,7 +80,7 @@ bool BlenderSync::object_use_particles(BL::Object b_ob) BL::ID key = (BKE_object_is_modified(*b_gob))? *b_gob: b_gob->data(); Mesh *mesh = mesh_map.find(key); if (mesh) { - use_particles |= mesh->need_attribute(scene, ATTR_STD_PARTICLE); + need_update |= mesh->need_attribute(scene, ATTR_STD_PARTICLE) && mesh->need_update; } } } @@ -93,7 +93,7 @@ bool BlenderSync::object_use_particles(BL::Object b_ob) } } - return use_particles; + return need_update; } static bool use_particle_system(BL::ParticleSystem b_psys) diff --git a/intern/cycles/blender/blender_sync.h b/intern/cycles/blender/blender_sync.h index 1a6c04db10c..6065235a278 100644 --- a/intern/cycles/blender/blender_sync.h +++ b/intern/cycles/blender/blender_sync.h @@ -92,7 +92,7 @@ private: bool BKE_object_is_modified(BL::Object b_ob); bool object_is_mesh(BL::Object b_ob); bool object_is_light(BL::Object b_ob); - bool object_use_particles(BL::Object b_ob); + bool object_need_particle_update(BL::Object b_ob); int object_count_particles(BL::Object b_ob); /* variables */ diff --git a/intern/ghost/intern/GHOST_SystemCocoa.mm b/intern/ghost/intern/GHOST_SystemCocoa.mm index 760dc0cbfd5..9f08f4cff80 100644 --- a/intern/ghost/intern/GHOST_SystemCocoa.mm +++ b/intern/ghost/intern/GHOST_SystemCocoa.mm @@ -527,7 +527,7 @@ int cocoa_request_qtcodec_settings(bContext *C, wmOperator *op) // So WM_exit needs to be called directly, as the event loop will never run before termination - (void)applicationWillTerminate:(NSNotification *)aNotification { - /*G.afbreek = 0; //Let Cocoa perform the termination at the end + /*G.is_break = FALSE; //Let Cocoa perform the termination at the end WM_exit(C);*/ } diff --git a/intern/ghost/intern/GHOST_SystemX11.cpp b/intern/ghost/intern/GHOST_SystemX11.cpp index e8f172f8b1c..7ac9b0c3c24 100644 --- a/intern/ghost/intern/GHOST_SystemX11.cpp +++ b/intern/ghost/intern/GHOST_SystemX11.cpp @@ -152,7 +152,9 @@ GHOST_SystemX11:: ~GHOST_SystemX11() { #if defined(WITH_X11_XINPUT) && defined(X_HAVE_UTF8_STRING) - XCloseIM(m_xim); + if (m_xim) { + XCloseIM(m_xim); + } #endif XCloseDisplay(m_display); diff --git a/intern/smoke/intern/WAVELET_NOISE.h b/intern/smoke/intern/WAVELET_NOISE.h index 66dfb95d143..fce901b68aa 100644 --- a/intern/smoke/intern/WAVELET_NOISE.h +++ b/intern/smoke/intern/WAVELET_NOISE.h @@ -107,7 +107,7 @@ static void downsampleNeumann(const float *from, float *to, int n, int stride) // if these values are not local incorrect results are generated float downCoeffs[32] = { DOWNCOEFFS }; const float *const aCoCenter= &downCoeffs[16]; - for (int i = 0; i < n / 2; i++) { + for (int i = 0; i <= n / 2; i++) { to[i * stride] = 0; for (int k = 2 * i - 16; k < 2 * i + 16; k++) { // handle boundary diff --git a/intern/string/STR_HashedString.h b/intern/string/STR_HashedString.h index f56e365bdb3..8bfbde65895 100644 --- a/intern/string/STR_HashedString.h +++ b/intern/string/STR_HashedString.h @@ -27,14 +27,10 @@ /** \file string/STR_HashedString.h * \ingroup string - */ - - -/** - + * * Copyright (C) 2001 NaN Technologies B.V. * This file was formerly known as: GEN_StdString.cpp. - * @date November, 14, 2001 + * \date November, 14, 2001 */ #ifndef __STR_HASHEDSTRING_H__ @@ -53,22 +49,22 @@ // static inline void STR_gHashMix(dword& a, dword& b, dword& c) { - a -= b; a -= c; a ^= (c>>13); - b -= c; b -= a; b ^= (a<<8); - c -= a; c -= b; c ^= (b>>13); - a -= b; a -= c; a ^= (c>>12); - b -= c; b -= a; b ^= (a<<16); - c -= a; c -= b; c ^= (b>>5); - a -= b; a -= c; a ^= (c>>3); - b -= c; b -= a; b ^= (a<<10); - c -= a; c -= b; c ^= (b>>15); + a -= b; a -= c; a ^= (c >> 13); + b -= c; b -= a; b ^= (a << 8); + c -= a; c -= b; c ^= (b >> 13); + a -= b; a -= c; a ^= (c >> 12); + b -= c; b -= a; b ^= (a << 16); + c -= a; c -= b; c ^= (b >> 5); + a -= b; a -= c; a ^= (c >> 3); + b -= c; b -= a; b ^= (a << 10); + c -= a; c -= b; c ^= (b >> 15); } // // Fast Hashable<int32> functionality // http://www.concentric.net/~Ttwang/tech/inthash.htm // -static inline dword STR_gHash(dword inDWord) +static inline dword STR_gHash(dword inDWord) { dword key = inDWord; key += ~(key << 16); @@ -80,43 +76,43 @@ static inline dword STR_gHash(dword inDWord) return key; } -enum { GOLDEN_RATIO = 0x9e3779b9 }; // arbitrary value to initialize hash funtion, well not so arbitrary - // as this value is taken from the pigs library (Orange Games/Lost Boys) +enum { GOLDEN_RATIO = 0x9e3779b9 }; /* arbitrary value to initialize hash funtion, well not so arbitrary + * as this value is taken from the pigs library (Orange Games/Lost Boys) */ -static dword STR_gHash(const void* in, int len, dword init_val) +static dword STR_gHash(const void *in, int len, dword init_val) { - unsigned int length = len; + unsigned int length = len; dword a = (dword)GOLDEN_RATIO; dword b = (dword)GOLDEN_RATIO; - dword c = init_val; // the previous hash value + dword c = init_val; /* the previous hash value */ byte *p_in = (byte *)in; // Do the largest part of the key while (length >= 12) { - a += (p_in[0] + ((dword)p_in[1]<<8) + ((dword)p_in[2] <<16) + ((dword)p_in[3] <<24)); - b += (p_in[4] + ((dword)p_in[5]<<8) + ((dword)p_in[6] <<16) + ((dword)p_in[7] <<24)); - c += (p_in[8] + ((dword)p_in[9]<<8) + ((dword)p_in[10]<<16) + ((dword)p_in[11]<<24)); + a += (p_in[0] + ((dword)p_in[1] << 8) + ((dword)p_in[2] << 16) + ((dword)p_in[3] << 24)); + b += (p_in[4] + ((dword)p_in[5] << 8) + ((dword)p_in[6] << 16) + ((dword)p_in[7] << 24)); + c += (p_in[8] + ((dword)p_in[9] << 8) + ((dword)p_in[10] << 16) + ((dword)p_in[11] << 24)); STR_gHashMix(a, b, c); p_in += 12; length -= 12; } // Handle the last 11 bytes c += len; - switch(length) { - case 11: c+=((dword)p_in[10]<<24); - case 10: c+=((dword)p_in[9]<<16); - case 9 : c+=((dword)p_in[8]<<8); // the first byte of c is reserved for the length - case 8 : b+=((dword)p_in[7]<<24); - case 7 : b+=((dword)p_in[6]<<16); - case 6 : b+=((dword)p_in[5]<<8); - case 5 : b+=p_in[4]; - case 4 : a+=((dword)p_in[3]<<24); - case 3 : a+=((dword)p_in[2]<<16); - case 2 : a+=((dword)p_in[1]<<8); - case 1 : a+=p_in[0]; + switch (length) { + case 11: c += ((dword)p_in[10] << 24); + case 10: c += ((dword)p_in[9] << 16); + case 9: c += ((dword)p_in[8] << 8); /* the first byte of c is reserved for the length */ + case 8: b += ((dword)p_in[7] << 24); + case 7: b += ((dword)p_in[6] << 16); + case 6: b += ((dword)p_in[5] << 8); + case 5: b += p_in[4]; + case 4: a += ((dword)p_in[3] << 24); + case 3: a += ((dword)p_in[2] << 16); + case 2: a += ((dword)p_in[1] << 8); + case 1: a += p_in[0]; } STR_gHashMix(a, b, c); @@ -129,18 +125,18 @@ static dword STR_gHash(const void* in, int len, dword init_val) class STR_HashedString : public STR_String { public: - STR_HashedString() : STR_String(),m_Hashed(false) {} - STR_HashedString(const char* str) : STR_String(str),m_Hashed(false) {} - STR_HashedString(const STR_String& str) : STR_String(str),m_Hashed(false) {} + STR_HashedString() : STR_String(), m_Hashed(false) {} + STR_HashedString(const char *str) : STR_String(str), m_Hashed(false) {} + STR_HashedString(const STR_String &str) : STR_String(str), m_Hashed(false) {} - inline dword hash(dword init=0) const + inline dword hash(dword init = 0) const { if (!m_Hashed) { - const char* str = *this; + const char *str = *this; int length = this->Length(); - m_CachedHash = STR_gHash(str,length,init); - m_Hashed=true; + m_CachedHash = STR_gHash(str, length, init); + m_Hashed = true; } return m_CachedHash; } diff --git a/release/datafiles/clkernelstoh.py b/release/datafiles/clkernelstoh.py deleted file mode 100755 index 9c24c9e2d03..00000000000 --- a/release/datafiles/clkernelstoh.py +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- - -# ***** BEGIN GPL LICENSE BLOCK ***** -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -# The Original Code is Copyright (C) 2012 Blender Foundation. -# All rights reserved. -# -# Contributor(s): Jeroen Bakker -# -# ***** END GPL LICENCE BLOCK ***** - -# <pep8 compliant> - -import sys -import os - -if len(sys.argv) < 2: - sys.stdout.write("Usage: clkernelstoh <cl_file>\n") - sys.exit(1) - -filename = sys.argv[1] - -try: - fpin = open(filename, "r") -except: - sys.stdout.write("Unable to open input %s\n" % sys.argv[1]) - sys.exit(1) - -if filename[0:2] == "." + os.sep: - filename = filename[2:] - -cname = filename + ".h" -sys.stdout.write("Making H file <%s>\n" % cname) - -filename = filename.split("/")[-1].split("\\")[-1] -filename = filename.replace(".", "_") - -try: - fpout = open(cname, "w") -except: - sys.stdout.write("Unable to open output %s\n" % cname) - sys.exit(1) - -fpout.write("/* clkernelstoh output of file <%s> */\n\n" % filename) -fpout.write("const char * clkernelstoh_%s = " % filename) - -lines = fpin.readlines() -for line in lines: - fpout.write("\"") - fpout.write(line.rstrip()) - fpout.write("\\n\" \\\n") -fpout.write("\"\\0\";\n") - -fpin.close() -fpout.close() diff --git a/release/scripts/modules/bl_i18n_utils/spell_check_utils.py b/release/scripts/modules/bl_i18n_utils/spell_check_utils.py index d668f2badfc..ef4926c4a98 100644 --- a/release/scripts/modules/bl_i18n_utils/spell_check_utils.py +++ b/release/scripts/modules/bl_i18n_utils/spell_check_utils.py @@ -297,6 +297,7 @@ dict_uimsgs = { "gimbal", "grayscale", "icosphere", + "inpaint", "lightmap", "lossless", "lossy", "midtones", diff --git a/release/scripts/presets/interaction/blender.py b/release/scripts/presets/interaction/blender.py index c5454e479a3..0c79a3fc909 100644 --- a/release/scripts/presets/interaction/blender.py +++ b/release/scripts/presets/interaction/blender.py @@ -1,7 +1,8 @@ # Configuration Blender import bpy -bpy.context.user_preferences.view.use_mouse_auto_depth = False +bpy.context.user_preferences.view.use_mouse_depth_cursor = False +bpy.context.user_preferences.view.use_mouse_depth_navigate = False bpy.context.user_preferences.view.use_zoom_to_mouse = False bpy.context.user_preferences.view.use_rotate_around_active = False bpy.context.user_preferences.edit.use_drag_immediately = False diff --git a/release/scripts/presets/tracking_settings/blurry_footage.py b/release/scripts/presets/tracking_settings/blurry_footage.py index f2df4a15320..0423f7662a2 100644 --- a/release/scripts/presets/tracking_settings/blurry_footage.py +++ b/release/scripts/presets/tracking_settings/blurry_footage.py @@ -1,12 +1,17 @@ import bpy settings = bpy.context.edit_movieclip.tracking.settings -settings.default_correlation_min = 0.75 -settings.default_pattern_size = 21 -settings.default_search_size = 100 + +settings.default_pattern_size = 31 +settings.default_search_size = 91 +settings.default_motion_model = 'Loc' +settings.use_default_brute = True +settings.use_default_normalization = False +settings.use_default_mask = False settings.default_frames_limit = 0 settings.default_pattern_match = 'PREV_FRAME' settings.default_margin = 0 settings.use_default_red_channel = True settings.use_default_green_channel = True settings.use_default_blue_channel = True +settings.default_correlation_min = 0.6
\ No newline at end of file diff --git a/release/scripts/presets/tracking_settings/blurry_movie.py b/release/scripts/presets/tracking_settings/blurry_movie.py deleted file mode 100644 index fe68f1352c1..00000000000 --- a/release/scripts/presets/tracking_settings/blurry_movie.py +++ /dev/null @@ -1,9 +0,0 @@ -import bpy -settings = bpy.context.edit_movieclip.tracking.settings - -settings.default_correlation_min = 0.75 -settings.default_pattern_size = 11 -settings.default_search_size = 202 -settings.default_frames_limit = 25 -settings.default_pattern_match = 'KEYFRAME' -settings.default_margin = 0 diff --git a/release/scripts/presets/tracking_settings/default.py b/release/scripts/presets/tracking_settings/default.py index 0cc3a21c845..0aef22195e7 100644 --- a/release/scripts/presets/tracking_settings/default.py +++ b/release/scripts/presets/tracking_settings/default.py @@ -1,12 +1,17 @@ import bpy settings = bpy.context.edit_movieclip.tracking.settings -settings.default_correlation_min = 0.75 -settings.default_pattern_size = 11 -settings.default_search_size = 61 + +settings.default_pattern_size = 15 +settings.default_search_size = 51 +settings.default_motion_model = 'Loc' +settings.use_default_brute = True +settings.use_default_normalization = False +settings.use_default_mask = False settings.default_frames_limit = 0 settings.default_pattern_match = 'KEYFRAME' settings.default_margin = 0 settings.use_default_red_channel = True settings.use_default_green_channel = True settings.use_default_blue_channel = True +settings.default_correlation_min = 0.75
\ No newline at end of file diff --git a/release/scripts/presets/tracking_settings/fast_motion.py b/release/scripts/presets/tracking_settings/fast_motion.py index 5e6e44e6a42..f7f6b37db74 100644 --- a/release/scripts/presets/tracking_settings/fast_motion.py +++ b/release/scripts/presets/tracking_settings/fast_motion.py @@ -1,12 +1,17 @@ import bpy settings = bpy.context.edit_movieclip.tracking.settings -settings.default_correlation_min = 0.7 + settings.default_pattern_size = 31 -settings.default_search_size = 300 +settings.default_search_size = 151 +settings.default_motion_model = 'LocRot' +settings.use_default_brute = True +settings.use_default_normalization = True +settings.use_default_mask = False settings.default_frames_limit = 0 settings.default_pattern_match = 'PREV_FRAME' -settings.default_margin = 5 +settings.default_margin = 0 settings.use_default_red_channel = True settings.use_default_green_channel = True settings.use_default_blue_channel = True +settings.default_correlation_min = 0.6
\ No newline at end of file diff --git a/release/scripts/presets/tracking_settings/planar.py b/release/scripts/presets/tracking_settings/planar.py new file mode 100644 index 00000000000..b25df1fc466 --- /dev/null +++ b/release/scripts/presets/tracking_settings/planar.py @@ -0,0 +1,17 @@ +import bpy +settings = bpy.context.edit_movieclip.tracking.settings + + +settings.default_pattern_size = 41 +settings.default_search_size = 91 +settings.default_motion_model = 'Perspective' +settings.use_default_brute = False +settings.use_default_normalization = False +settings.use_default_mask = False +settings.default_frames_limit = 0 +settings.default_pattern_match = 'KEYFRAME' +settings.default_margin = 0 +settings.use_default_red_channel = True +settings.use_default_green_channel = True +settings.use_default_blue_channel = True +settings.default_correlation_min = 0.75
\ No newline at end of file diff --git a/release/scripts/startup/bl_operators/__init__.py b/release/scripts/startup/bl_operators/__init__.py index 8fb264eb411..0ecb0d46c5f 100644 --- a/release/scripts/startup/bl_operators/__init__.py +++ b/release/scripts/startup/bl_operators/__init__.py @@ -30,6 +30,7 @@ _modules = ( "freestyle", "image", "mesh", + "node", "object_align", "object", "object_randomize_transform", diff --git a/release/scripts/startup/bl_operators/clip.py b/release/scripts/startup/bl_operators/clip.py index a30502b454e..c45d2f2e702 100644 --- a/release/scripts/startup/bl_operators/clip.py +++ b/release/scripts/startup/bl_operators/clip.py @@ -90,14 +90,17 @@ def CLIP_track_view_selected(sc, track): return False -def CLIP_default_settings_from_track(clip, track): +def CLIP_default_settings_from_track(clip, track, framenr): settings = clip.tracking.settings width = clip.size[0] height = clip.size[1] - pattern = track.pattern_max - track.pattern_min - search = track.search_max - track.search_min + marker = track.markers.find_frame(framenr, False) + pattern_bb = marker.pattern_bound_box + + pattern = Vector(pattern_bb[1]) - Vector(pattern_bb[0]) + search = marker.search_max - marker.search_min pattern[0] = pattern[0] * width pattern[1] = pattern[1] * height @@ -111,6 +114,10 @@ def CLIP_default_settings_from_track(clip, track): settings.default_frames_limit = track.frames_limit settings.default_pattern_match = track.pattern_match settings.default_margin = track.margin + settings.default_motion_model = track.motion_model + settings.use_default_brute = track.use_brute + settings.use_default_normalization = track.use_normalization + settings.use_default_mask = track.use_mask settings.use_default_red_channel = track.use_red_channel settings.use_default_green_channel = track.use_green_channel settings.use_default_blue_channel = track.use_blue_channel @@ -862,6 +869,9 @@ class CLIP_OT_track_settings_as_default(Operator): sc = context.space_data clip = sc.clip - CLIP_default_settings_from_track(clip, clip.tracking.tracks.active) + track = clip.tracking.tracks.active + framenr = context.scene.frame_current - clip.frame_start + 1 + + CLIP_default_settings_from_track(clip, track, framenr) return {'FINISHED'} diff --git a/release/scripts/startup/bl_operators/node.py b/release/scripts/startup/bl_operators/node.py new file mode 100644 index 00000000000..2f7fc359864 --- /dev/null +++ b/release/scripts/startup/bl_operators/node.py @@ -0,0 +1,136 @@ +# ##### BEGIN GPL LICENSE BLOCK ##### +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# ##### END GPL LICENSE BLOCK ##### + +# <pep8-80 compliant> + +import bpy +from bpy.types import Operator +from bpy.props import EnumProperty + +# XXX These node item lists should actually be generated by a callback at operator execution time (see node_type_items below), +# using the active node tree from the context. Due to a difficult bug in bpy this is not possible (item list memory gets freed too early), +# so for now just copy the static item lists to these global variables. +# +# In the custom_nodes branch, the static per-tree-type node items are replaced by a single independent type list anyway (with a poll function +# to limit node types to the respective trees). So this workaround is only temporary. + +# lazy init +node_type_items_dict = {} + +# Prefixes used to distinguish base node types and node groups +node_type_prefix = 'NODE_' +node_group_prefix = 'GROUP_' + +# Generate a list of enum items for a given node class +# Copy existing type enum, adding a prefix to distinguish from node groups +# Skip the base node group type, node groups will be added below for all existing group trees +def node_type_items(node_class): + return [(node_type_prefix + item.identifier, item.name, item.description) + for item in node_class.bl_rna.properties['type'].enum_items if item.identifier != 'GROUP'] + +# Generate items for node group types +# Filter by the given tree_type +# Node group trees don't have a description property yet (could add this as a custom property though) +def node_group_items(tree_type): + return [(node_group_prefix + group.name, group.name, '') + for group in bpy.data.node_groups if group.type == tree_type] + +# Returns the enum item list for the edited tree in the context +def node_type_items_cb(self, context): + snode = context.space_data + if not snode: + return [] + tree = snode.edit_tree + if not tree: + return [] + + # Lists of basic node types for each + if not node_type_items_dict: + node_type_items_dict.update({ + 'SHADER': node_type_items(bpy.types.ShaderNode), + 'COMPOSITING': node_type_items(bpy.types.CompositorNode), + 'TEXTURE': node_type_items(bpy.types.TextureNode), + }) + + # XXX Does not work correctly, see comment above + #return [(item.identifier, item.name, item.description, item.value) for item in tree.nodes.bl_rna.functions['new'].parameters['type'].enum_items] + + if tree.type in node_type_items_dict: + return node_type_items_dict[tree.type] + node_group_items(tree.type) + else: + return [] + + +class NODE_OT_add_search(Operator): + '''Add a node to the active tree''' + bl_idname = "node.add_search" + bl_label = "Search and Add Node" + bl_options = {'REGISTER', 'UNDO'} + + # XXX this should be called 'node_type' but the operator search property is hardcoded to 'type' by a hack in bpy_operator_wrap.c ... + type = EnumProperty( + name="Node Type", + description="Node type", + items=node_type_items_cb, + ) + + _node_type_items_dict = None + + def create_node(self, context): + space = context.space_data + tree = space.edit_tree + + # Enum item identifier has an additional prefix to distinguish base node types from node groups + item = self.type + if (item.startswith(node_type_prefix)): + # item means base node type + node = tree.nodes.new(type=item[len(node_type_prefix):]) + elif (item.startswith(node_group_prefix)): + # item means node group type + node = tree.nodes.new(type='GROUP', group=bpy.data.node_groups[item[len(node_group_prefix):]]) + else: + return None + + for n in tree.nodes: + if n == node: + node.select = True + tree.nodes.active = node + else: + node.select = False + node.location = space.cursor_location + return node + + @classmethod + def poll(cls, context): + space = context.space_data + # needs active node editor and a tree to add nodes to + return space.type == 'NODE_EDITOR' and space.edit_tree + + def execute(self, context): + self.create_node(context) + return {'FINISHED'} + + def invoke(self, context, event): + space = context.space_data + v2d = context.region.view2d + + # convert mouse position to the View2D for later node placement + space.cursor_location = v2d.region_to_view(event.mouse_region_x, event.mouse_region_y) + + context.window_manager.invoke_search_popup(self) + return {'CANCELLED'} diff --git a/release/scripts/startup/bl_operators/presets.py b/release/scripts/startup/bl_operators/presets.py index 05f76208a5f..db492450e28 100644 --- a/release/scripts/startup/bl_operators/presets.py +++ b/release/scripts/startup/bl_operators/presets.py @@ -436,15 +436,19 @@ class AddPresetTrackingSettings(AddPresetBase, Operator): ] preset_values = [ - "settings.default_correlation_min", - "settings.default_pattern_size", - "settings.default_search_size", - "settings.default_frames_limit", - "settings.default_pattern_match", - "settings.default_margin", - "settings.use_default_red_channel", - "settings.use_default_green_channel", - "settings.use_default_blue_channel" + "default_correlation_min", + "default_pattern_size", + "default_search_size", + "default_frames_limit", + "default_pattern_match", + "default_margin", + "default_motion_model", + "use_default_brute", + "use_default_normalization", + "use_default_mask", + "use_default_red_channel", + "use_default_green_channel", + "use_default_blue_channel" ] preset_subdir = "tracking_settings" diff --git a/release/scripts/startup/bl_operators/screen_play_rendered_anim.py b/release/scripts/startup/bl_operators/screen_play_rendered_anim.py index 9cb9dfc708c..b4733ac9d87 100644 --- a/release/scripts/startup/bl_operators/screen_play_rendered_anim.py +++ b/release/scripts/startup/bl_operators/screen_play_rendered_anim.py @@ -28,7 +28,9 @@ import os def guess_player_path(preset): import sys - if preset == 'BLENDER24': + if preset == 'INTERNAL': + return bpy.app.binary_path + elif preset == 'BLENDER24': player_path = "blender" if sys.platform == "darwin": @@ -110,32 +112,7 @@ class PlayRenderedAnim(Operator): cmd = [player_path] # extra options, fps controls etc. - if preset == 'BLENDER24': - # ----------------------------------------------------------------- - # Check blender is not 2.5x until it supports playback again - try: - process = subprocess.Popen([player_path, '--version'], - stdout=subprocess.PIPE, - ) - except: - # ignore and allow the main execution to catch the problem. - process = None - - if process is not None: - process.wait() - out = process.stdout.read() - process.stdout.close() - out_split = out.strip().split() - if out_split[0] == b'Blender': - if not out_split[1].startswith(b'2.4'): - self.report({'ERROR'}, - "Blender %s doesn't support playback: %r" % - (out_split[1].decode(), player_path)) - return {'CANCELLED'} - del out, out_split - del process - # ----------------------------------------------------------------- - + if preset in {'BLENDER24', 'INTERNAL'}: opts = ["-a", "-f", str(rd.fps), str(rd.fps_base), "-j", str(scene.frame_step), file] cmd.extend(opts) diff --git a/release/scripts/startup/bl_ui/properties_mask_common.py b/release/scripts/startup/bl_ui/properties_mask_common.py index e40b46fda70..7cd2ae0b509 100644 --- a/release/scripts/startup/bl_ui/properties_mask_common.py +++ b/release/scripts/startup/bl_ui/properties_mask_common.py @@ -127,6 +127,8 @@ class MASK_PT_spline(): row.prop(spline, "use_cyclic") row.prop(spline, "use_fill") + col.prop(spline, "use_self_intersection_check") + class MASK_PT_point(): # subclasses must define... diff --git a/release/scripts/startup/bl_ui/properties_object_constraint.py b/release/scripts/startup/bl_ui/properties_object_constraint.py index e4da581ab83..3d671a0d1b7 100644 --- a/release/scripts/startup/bl_ui/properties_object_constraint.py +++ b/release/scripts/startup/bl_ui/properties_object_constraint.py @@ -773,16 +773,26 @@ class ConstraintButtonsPanel(): row.prop(con, "use_active_clip") row.prop(con, "use_3d_position") + col = layout.column() + if not con.use_active_clip: - layout.prop(con, "clip") + col.prop(con, "clip") + + row = col.row() + row.prop(con, "frame_method", expand=True) if clip: - layout.prop_search(con, "object", clip.tracking, "objects", icon='OBJECT_DATA') - layout.prop_search(con, "track", clip.tracking, "tracks", icon='ANIM_DATA') + tracking = clip.tracking - layout.prop(con, "camera") + col.prop_search(con, "object", tracking, "objects", icon='OBJECT_DATA') - row = layout.row() + tracking_object = tracking.objects.get(con.object, tracking.objects[0]) + + col.prop_search(con, "track", tracking_object, "tracks", icon='ANIM_DATA') + + col.prop(con, "camera") + + row = col.row() row.active = not con.use_3d_position row.prop(con, "depth_object") diff --git a/release/scripts/startup/bl_ui/properties_render.py b/release/scripts/startup/bl_ui/properties_render.py index f034a458c6e..ad5996a0b26 100644 --- a/release/scripts/startup/bl_ui/properties_render.py +++ b/release/scripts/startup/bl_ui/properties_render.py @@ -66,6 +66,7 @@ class RENDER_PT_render(RenderButtonsPanel, Panel): row = layout.row() row.operator("render.render", text="Image", icon='RENDER_STILL') row.operator("render.render", text="Animation", icon='RENDER_ANIMATION').animation = True + row.operator("render.play_rendered_anim", text="Play", icon='RENDER_ANIMATION') layout.prop(rd, "display_mode", text="Display") diff --git a/release/scripts/startup/bl_ui/space_clip.py b/release/scripts/startup/bl_ui/space_clip.py index 559cf7f93b7..efac7a66086 100644 --- a/release/scripts/startup/bl_ui/space_clip.py +++ b/release/scripts/startup/bl_ui/space_clip.py @@ -232,9 +232,9 @@ class CLIP_PT_tools_marker(CLIP_PT_tracking_panel, Panel): col.label(text="Tracker:") col.prop(settings, "default_motion_model") - col.prop(settings, "default_use_brute") - col.prop(settings, "default_use_normalization") - col.prop(settings, "default_use_mask") + col.prop(settings, "use_default_brute") + col.prop(settings, "use_default_normalization") + col.prop(settings, "use_default_mask") col.prop(settings, "default_correlation_min") col.separator() @@ -843,7 +843,7 @@ class CLIP_PT_footage(CLIP_PT_clip_view_panel, Panel): col = layout.column() col.template_movieclip(sc, "clip", compact=True) - col.prop(clip, "start_frame") + col.prop(clip, "frame_start") col.prop(clip, "frame_offset") diff --git a/release/scripts/startup/bl_ui/space_image.py b/release/scripts/startup/bl_ui/space_image.py index 7752eb9771a..5302ad9b471 100644 --- a/release/scripts/startup/bl_ui/space_image.py +++ b/release/scripts/startup/bl_ui/space_image.py @@ -106,6 +106,10 @@ class IMAGE_MT_select(Menu): layout.operator("uv.select_pinned") layout.operator("uv.select_linked") + layout.separator() + + layout.operator("uv.select_split") + class IMAGE_MT_image(Menu): bl_label = "Image" @@ -383,11 +387,17 @@ class IMAGE_HT_header(Header): layout.prop(sima, "mode", text="") + if show_maskedit: + row = layout.row() + row.template_ID(sima, "mask", new="mask.new") + + if show_uvedit or show_maskedit: + layout.prop(sima, "pivot_point", text="", icon_only=True) + # uv editing if show_uvedit: uvedit = sima.uv_editor - layout.prop(uvedit, "pivot_point", text="", icon_only=True) layout.prop(toolsettings, "use_uv_select_sync", text="") if toolsettings.use_uv_select_sync: @@ -408,14 +418,6 @@ class IMAGE_HT_header(Header): mesh = context.edit_object.data layout.prop_search(mesh.uv_textures, "active", mesh, "uv_textures", text="") - if show_maskedit: - row = layout.row() - row.template_ID(sima, "mask", new="mask.new") - - # reused for mask - uvedit = sima.uv_editor - layout.prop(uvedit, "pivot_point", text="", icon_only=True) - if ima: # layers layout.template_image_layers(ima, iuser) @@ -430,7 +432,7 @@ class IMAGE_HT_header(Header): if ima.type == 'COMPOSITE' and ima.source in {'MOVIE', 'SEQUENCE'}: row.operator("image.play_composite", icon='PLAY') - if show_uvedit or mode == 'PAINT': + if show_uvedit or show_maskedit or mode == 'PAINT': layout.prop(sima, "use_realtime_update", text="", icon_only=True, icon='LOCKED') @@ -617,6 +619,7 @@ class IMAGE_PT_view_properties(Panel): sima = context.space_data ima = sima.image show_uvedit = sima.show_uvedit + show_maskedit = sima.show_maskedit uvedit = sima.uv_editor split = layout.split() @@ -635,12 +638,12 @@ class IMAGE_PT_view_properties(Panel): col.label(text="Coordinates:") col.prop(uvedit, "show_normalized_coords", text="Normalized") - if show_uvedit: - + if show_uvedit or show_maskedit: col = layout.column() col.label("Cursor Location:") - col.row().prop(uvedit, "cursor_location", text="") + col.row().prop(sima, "cursor_location", text="") + if show_uvedit: col.separator() col.label(text="UVs:") diff --git a/release/scripts/startup/bl_ui/space_node.py b/release/scripts/startup/bl_ui/space_node.py index e66d8f70c81..46baef9b043 100644 --- a/release/scripts/startup/bl_ui/space_node.py +++ b/release/scripts/startup/bl_ui/space_node.py @@ -94,6 +94,10 @@ class NODE_HT_header(Header): if toolsettings.snap_node_element != 'INCREMENT': row.prop(toolsettings, "snap_target", text="") + row = layout.row(align=True) + row.operator("node.clipboard_copy", text="", icon='COPYDOWN') + row.operator("node.clipboard_paste", text="", icon='PASTEDOWN') + layout.template_running_jobs() @@ -111,6 +115,7 @@ class NODE_MT_view(Menu): layout.separator() + layout.operator("node.view_selected") layout.operator("node.view_all") if context.space_data.show_backdrop: diff --git a/release/scripts/startup/bl_ui/space_sequencer.py b/release/scripts/startup/bl_ui/space_sequencer.py index d099db1645b..77789496a15 100644 --- a/release/scripts/startup/bl_ui/space_sequencer.py +++ b/release/scripts/startup/bl_ui/space_sequencer.py @@ -423,7 +423,7 @@ class SEQUENCER_PT_effect(SequencerButtonsPanel, Panel): return strip.type in {'ADD', 'SUBTRACT', 'ALPHA_OVER', 'ALPHA_UNDER', 'CROSS', 'GAMMA_CROSS', 'MULTIPLY', 'OVER_DROP', 'WIPE', 'GLOW', 'TRANSFORM', 'COLOR', 'SPEED', - 'MULTICAM', 'ADJUSTMENT'} + 'MULTICAM'} def draw(self, context): layout = self.layout @@ -763,20 +763,26 @@ class SEQUENCER_PT_filter(SequencerButtonsPanel, Panel): layout.prop(strip, "use_color_balance") if strip.use_color_balance and strip.color_balance: # TODO - need to add this somehow - row = layout.row() - row.active = strip.use_color_balance - col = row.column() + col = layout.column() + col.label(text="Lift:") col.template_color_wheel(strip.color_balance, "lift", value_slider=False, cubic=True) - col.row().prop(strip.color_balance, "lift") - col.prop(strip.color_balance, "invert_lift", text="Inverse") - col = row.column() + row = col.row() + row.prop(strip.color_balance, "lift", text="") + row.prop(strip.color_balance, "invert_lift", text="Inverse") + + col = layout.column() + col.label(text="Gamma:") col.template_color_wheel(strip.color_balance, "gamma", value_slider=False, lock_luminosity=True, cubic=True) - col.row().prop(strip.color_balance, "gamma") - col.prop(strip.color_balance, "invert_gamma", text="Inverse") - col = row.column() + row = col.row() + row.prop(strip.color_balance, "gamma", text="") + row.prop(strip.color_balance, "invert_gamma", text="Inverse") + + col = layout.column() + col.label(text="Gain:") col.template_color_wheel(strip.color_balance, "gain", value_slider=False, lock_luminosity=True, cubic=True) - col.row().prop(strip.color_balance, "gain") - col.prop(strip.color_balance, "invert_gain", text="Inverse") + row = col.row() + row.prop(strip.color_balance, "gain", text="") + row.prop(strip.color_balance, "invert_gain", text="Inverse") class SEQUENCER_PT_proxy(SequencerButtonsPanel, Panel): diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py index e443c7804a6..e7dd9fb4751 100644 --- a/release/scripts/startup/bl_ui/space_userpref.py +++ b/release/scripts/startup/bl_ui/space_userpref.py @@ -197,7 +197,8 @@ class USERPREF_PT_interface(Panel): col = row.column() col.label(text="View Manipulation:") - col.prop(view, "use_mouse_auto_depth") + col.prop(view, "use_mouse_depth_cursor") + col.prop(view, "use_mouse_depth_navigate") col.prop(view, "use_zoom_to_mouse") col.prop(view, "use_rotate_around_active") col.prop(view, "use_global_pivot") diff --git a/source/blender/avi/intern/avi.c b/source/blender/avi/intern/avi.c index 1c79c9b4237..9d4704cf0f2 100644 --- a/source/blender/avi/intern/avi.c +++ b/source/blender/avi/intern/avi.c @@ -970,7 +970,7 @@ AviError AVI_write_frame(AviMovie *movie, int frame_num, ...) if (movie->entries != NULL) { temp = (AviIndexEntry *)MEM_reallocN(movie->entries, (frame_num + 1) * entry_size); /* clear new bytes */ - memset(&temp[movie->index_entries], 0, ((frame_num + 1) - movie->index_entries) * entry_size); + memset(&temp[movie->index_entries + 1], 0, (frame_num - movie->index_entries) * entry_size); } else { temp = (AviIndexEntry *) MEM_callocN((frame_num + 1) * entry_size, "newidxentry"); diff --git a/source/blender/blenkernel/BKE_blender.h b/source/blender/blenkernel/BKE_blender.h index 0c09c24e709..dec4d3cb8cb 100644 --- a/source/blender/blenkernel/BKE_blender.h +++ b/source/blender/blenkernel/BKE_blender.h @@ -44,7 +44,9 @@ extern "C" { #define BLENDER_VERSION 263 #define BLENDER_SUBVERSION 17 -#define BLENDER_MINVERSION 250 +/* 262 was the last editmesh release but its has compatibility code for bmesh data, + * so set the minversion to 2.61 */ +#define BLENDER_MINVERSION 261 #define BLENDER_MINSUBVERSION 0 /* used by packaging tools */ diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h index bcda970e60c..30b3ab38c6f 100644 --- a/source/blender/blenkernel/BKE_cloth.h +++ b/source/blender/blenkernel/BKE_cloth.h @@ -57,7 +57,6 @@ struct CollisionTree; /* Bits to or into the ClothVertex.flags. */ #define CLOTH_VERT_FLAG_PINNED 1 #define CLOTH_VERT_FLAG_NOSELFCOLL 2 /* vertex NOT used for self collisions */ -#define CLOTH_VERT_FLAG_PINNED_EM 3 /** * This structure describes a cloth object against which the @@ -181,7 +180,7 @@ typedef enum { //////////////////////////////////////////////// // needed for implicit.c -int cloth_bvh_objcollision (struct Object *ob, struct ClothModifierData * clmd, float step, float dt ); +int cloth_bvh_objcollision (struct Object *ob, struct ClothModifierData *clmd, float step, float dt ); //////////////////////////////////////////////// diff --git a/source/blender/blenkernel/BKE_context.h b/source/blender/blenkernel/BKE_context.h index 7a1172335d8..f5e073eb27a 100644 --- a/source/blender/blenkernel/BKE_context.h +++ b/source/blender/blenkernel/BKE_context.h @@ -221,7 +221,7 @@ void CTX_data_list_add(bContextDataResult *result, void *data); #define CTX_DATA_END \ } \ BLI_freelistN(&ctx_data_list); \ - } +} (void)0 int ctx_data_list_count(const bContext *C, int (*func)(const bContext *, ListBase *)); diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h index 3dc68edf12b..8d486218d21 100644 --- a/source/blender/blenkernel/BKE_customdata.h +++ b/source/blender/blenkernel/BKE_customdata.h @@ -310,7 +310,7 @@ int CustomData_layertype_is_singleton(int type); /* make sure the name of layer at index is unique */ void CustomData_set_layer_unique_name(struct CustomData *data, int index); -void CustomData_validate_layer_name(const struct CustomData *data, int type, char *name, char *outname); +void CustomData_validate_layer_name(const struct CustomData *data, int type, const char *name, char *outname); /* for file reading compatibility, returns false if the layer was freed, * only after this test passes, layer->data should be assigned */ diff --git a/source/blender/blenkernel/BKE_fcurve.h b/source/blender/blenkernel/BKE_fcurve.h index f7aa4470c19..ad1a63fd1e6 100644 --- a/source/blender/blenkernel/BKE_fcurve.h +++ b/source/blender/blenkernel/BKE_fcurve.h @@ -83,7 +83,7 @@ void bezt_add_to_cfra_elem(ListBase *lb, struct BezTriple *bezt); /* tidy up for driver targets loopers */ #define DRIVER_TARGETS_LOOPER_END \ - } +} /* ---------------------- */ diff --git a/source/blender/blenkernel/BKE_font.h b/source/blender/blenkernel/BKE_font.h index 6636a70e94d..938a13483d5 100644 --- a/source/blender/blenkernel/BKE_font.h +++ b/source/blender/blenkernel/BKE_font.h @@ -46,7 +46,7 @@ struct TmpFont; struct CharInfo; struct Main; -struct chartrans { +struct CharTrans { float xof, yof; float rot; short linenr, charnr; @@ -71,15 +71,19 @@ typedef struct EditFont { } EditFont; +int BKE_vfont_is_builtin(struct VFont *vfont); void BKE_vfont_builtin_register(void *mem, int size); +void BKE_vfont_free_data(struct VFont *vfont); void BKE_vfont_free(struct VFont *sc); void BKE_vfont_free_global_ttf(void); struct VFont *BKE_vfont_builtin_get(void); struct VFont *BKE_vfont_load(struct Main *bmain, const char *name); -struct TmpFont *BKE_vfont_find_tmpfont(struct VFont *vfont); -struct chartrans *BKE_vfont_to_curve(struct Main *bmain, struct Scene *scene, struct Object *ob, int mode); +struct TmpFont *BKE_vfont_tmpfont_find(struct VFont *vfont); +void BKE_vfont_tmpfont_remove(struct VFont *vfont); + +struct CharTrans *BKE_vfont_to_curve(struct Main *bmain, struct Scene *scene, struct Object *ob, int mode); int BKE_vfont_select_get(struct Object *ob, int *start, int *end); diff --git a/source/blender/blenkernel/BKE_global.h b/source/blender/blenkernel/BKE_global.h index 2d30844af80..2656495a918 100644 --- a/source/blender/blenkernel/BKE_global.h +++ b/source/blender/blenkernel/BKE_global.h @@ -60,20 +60,31 @@ typedef struct Global { /* strings of recent opened files */ struct ListBase recent_files; - - short afbreek, moving, file_loaded; + + /* has escape been pressed or Ctrl+C pressed in background mode, used for render quit */ + short is_break; + + short moving, file_loaded; char background; char factory_startup; short winpos, displaymode; /* used to be in Render */ - short rendering; /* to indicate render is busy, prevent renderwindow events etc */ - short rt; + /* to indicate render is busy, prevent renderwindow events etc */ + short is_rendering; + + /* debug value, can be set from the UI and python, used for testing nonstandard features */ + short debug_value; + + /* saved to the blend file as FileGlobal.globalf, + * however this is now only used for runtime options */ int f; + + /* debug flag, G_DEBUG, G_DEBUG_PYTHON & friends, set python or command line args */ int debug; /* Used for BMesh transformations */ struct BME_Glob *editBMesh; - + /* Frank's variables */ int save_over; @@ -88,7 +99,7 @@ typedef struct Global { /* this variable is written to / read from FileGlobal->fileflags */ int fileflags; - + /* save the allowed windowstate of blender when using -W or -w */ int windowstate; } Global; @@ -123,7 +134,7 @@ enum { G_DEBUG_JOBS = (1 << 5) /* jobs time profiling */ }; -#define G_DEBUG_ALL (G_DEBUG | G_DEBUG_FFMPEG | G_DEBUG_PYTHON | G_DEBUG_EVENTS | G_DEBUG_WM) +#define G_DEBUG_ALL (G_DEBUG | G_DEBUG_FFMPEG | G_DEBUG_PYTHON | G_DEBUG_EVENTS | G_DEBUG_WM | G_DEBUG_JOBS) /* G.fileflags */ diff --git a/source/blender/blenkernel/BKE_mask.h b/source/blender/blenkernel/BKE_mask.h index 1148cffffb4..1836a88555b 100644 --- a/source/blender/blenkernel/BKE_mask.h +++ b/source/blender/blenkernel/BKE_mask.h @@ -64,19 +64,19 @@ void BKE_mask_layer_copy_list(struct ListBase *masklayers_new, struct ListBase * /* splines */ struct MaskSpline *BKE_mask_spline_add(struct MaskLayer *masklay); -int BKE_mask_spline_resolution(struct MaskSpline *spline, int width, int height); -int BKE_mask_spline_feather_resolution(struct MaskSpline *spline, int width, int height); +unsigned int BKE_mask_spline_resolution(struct MaskSpline *spline, int width, int height); +unsigned int BKE_mask_spline_feather_resolution(struct MaskSpline *spline, int width, int height); -int BKE_mask_spline_differentiate_calc_total(const struct MaskSpline *spline, const int resol); +int BKE_mask_spline_differentiate_calc_total(const struct MaskSpline *spline, const unsigned int resol); float (*BKE_mask_spline_differentiate(struct MaskSpline *spline, int *tot_diff_point))[2]; float (*BKE_mask_spline_feather_differentiated_points(struct MaskSpline *spline, int *tot_feather_point))[2]; float (*BKE_mask_spline_differentiate_with_resolution_ex(struct MaskSpline *spline, int *tot_diff_point, - const int resol))[2]; + const unsigned int resol))[2]; float (*BKE_mask_spline_differentiate_with_resolution(struct MaskSpline *spline, int width, int height, int *tot_diff_point))[2]; float (*BKE_mask_spline_feather_differentiated_points_with_resolution_ex(struct MaskSpline *spline, int *tot_feather_point, - const int resol, const int do_collapse))[2]; + const unsigned int resol))[2]; float (*BKE_mask_spline_feather_differentiated_points_with_resolution(struct MaskSpline *spline, int width, int height, int *tot_feather_point))[2]; float (*BKE_mask_spline_feather_points(struct MaskSpline *spline, int *tot_feather_point))[2]; @@ -98,16 +98,18 @@ void BKE_mask_point_handle(struct MaskSplinePoint *point, float handle[2]); void BKE_mask_point_set_handle(struct MaskSplinePoint *point, float loc[2], int keep_direction, float orig_handle[2], float orig_vec[3][3]); -float *BKE_mask_point_segment_diff(struct MaskSpline *spline, struct MaskSplinePoint *point, int *tot_diff_point); +float *BKE_mask_point_segment_diff(struct MaskSpline *spline, struct MaskSplinePoint *point, + unsigned int *tot_diff_point); float *BKE_mask_point_segment_feather_diff(struct MaskSpline *spline, struct MaskSplinePoint *point, - int *tot_feather_point); + unsigned int *tot_feather_point); float *BKE_mask_point_segment_diff_with_resolution(struct MaskSpline *spline, struct MaskSplinePoint *point, - int width, int height, int *tot_diff_point); + int width, int height, + unsigned int *tot_diff_point); float *BKE_mask_point_segment_feather_diff_with_resolution(struct MaskSpline *spline, struct MaskSplinePoint *point, int width, int height, - int *tot_feather_point); + unsigned int *tot_feather_point); void BKE_mask_point_segment_co(struct MaskSpline *spline, struct MaskSplinePoint *point, float u, float co[2]); void BKE_mask_point_normal(struct MaskSpline *spline, struct MaskSplinePoint *point, diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 93b5e748987..61845619452 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -359,6 +359,7 @@ void nodeInternalRelink(struct bNodeTree *ntree, struct bNode *node); void nodeToView(struct bNode *node, float x, float y, float *rx, float *ry); void nodeFromView(struct bNode *node, float x, float y, float *rx, float *ry); +int nodeAttachNodeCheck(struct bNode *node, struct bNode *parent); void nodeAttachNode(struct bNode *node, struct bNode *parent); void nodeDetachNode(struct bNode *node); @@ -384,6 +385,15 @@ void nodeFreePreview(struct bNode *node); int nodeSocketIsHidden(struct bNodeSocket *sock); void nodeSocketSetType(struct bNodeSocket *sock, int type); +/* Node Clipboard */ +void BKE_node_clipboard_init(struct bNodeTree *ntree); +void BKE_node_clipboard_clear(void); +void BKE_node_clipboard_add_node(struct bNode *node); +void BKE_node_clipboard_add_link(struct bNodeLink *link); +const struct ListBase *BKE_node_clipboard_get_nodes(void); +const struct ListBase *BKE_node_clipboard_get_links(void); +int BKE_node_clipboard_get_type(void); + /* ************** NODE TYPE ACCESS *************** */ struct bNodeTemplate nodeMakeTemplate(struct bNode *node); @@ -661,6 +671,7 @@ void ntreeGPUMaterialNodes(struct bNodeTree *ntree, struct GPUMateria #define CMP_NODE_KEYINGSCREEN 269 #define CMP_NODE_KEYING 270 #define CMP_NODE_TRACKPOS 271 +#define CMP_NODE_INPAINT 272 #define CMP_NODE_GLARE 301 #define CMP_NODE_TONEMAP 302 diff --git a/source/blender/blenkernel/BKE_sequencer.h b/source/blender/blenkernel/BKE_sequencer.h index a8890d5a37e..78e65fe3ea6 100644 --- a/source/blender/blenkernel/BKE_sequencer.h +++ b/source/blender/blenkernel/BKE_sequencer.h @@ -61,26 +61,29 @@ typedef struct SeqIterator { int valid; } SeqIterator; -void seq_begin(struct Editing *ed, SeqIterator *iter, int use_pointer); -void seq_next(SeqIterator *iter); -void seq_end(SeqIterator *iter); -void seq_array(struct Editing *ed, struct Sequence ***seqarray, int *tot, int use_pointer); +void BKE_seqence_iterator_begin(struct Editing *ed, SeqIterator *iter, int use_pointer); +void BKE_seqence_iterator_next(SeqIterator *iter); +void BKE_seqence_iterator_end(SeqIterator *iter); #define SEQP_BEGIN(ed, _seq) \ { \ SeqIterator iter; \ - for (seq_begin(ed, &iter, 1); iter.valid; seq_next(&iter)) { \ + for (BKE_seqence_iterator_begin(ed, &iter, 1); \ + iter.valid; \ + BKE_seqence_iterator_next(&iter)) { \ _seq = iter.seq; #define SEQ_BEGIN(ed, _seq) \ { \ SeqIterator iter; \ - for (seq_begin(ed, &iter, 0); iter.valid; seq_next(&iter)) { \ + for (BKE_seqence_iterator_begin(ed, &iter, 0); \ + iter.valid; \ + BKE_seqence_iterator_next(&iter)) { \ _seq = iter.seq; #define SEQ_END \ } \ - seq_end(&iter); \ + BKE_seqence_iterator_end(&iter); \ } typedef struct SeqRenderData { @@ -93,12 +96,8 @@ typedef struct SeqRenderData { float motion_blur_shutter; } SeqRenderData; -SeqRenderData seq_new_render_data( - struct Main *bmain, struct Scene *scene, - int rectx, int recty, int preview_render_size); - -int seq_cmp_render_data(const SeqRenderData *a, const SeqRenderData *b); -unsigned int seq_hash_render_data(const SeqRenderData *a); +SeqRenderData BKE_sequencer_new_render_data(struct Main *bmain, struct Scene *scene, int rectx, int recty, + int preview_render_size); /* Wipe effect */ enum { @@ -110,8 +109,9 @@ enum { DO_CLOCK_WIPE }; - struct SeqEffectHandle { + int multithreaded; + /* constructors & destructor */ /* init is _only_ called on first creation */ void (*init)(struct Sequence *seq); @@ -147,27 +147,29 @@ struct SeqEffectHandle { * float-rects or byte-rects * (mixed cases are handled one layer up...) */ - struct ImBuf * (*execute)(SeqRenderData context, - struct Sequence *seq, float cfra, - float facf0, float facf1, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3); + struct ImBuf * (*execute)(SeqRenderData context, struct Sequence *seq, float cfra, float facf0, float facf1, + struct ImBuf *ibuf1, struct ImBuf *ibuf2, struct ImBuf *ibuf3); + + struct ImBuf * (*init_execution)(SeqRenderData context, struct ImBuf *ibuf1, struct ImBuf *ibuf2, struct ImBuf *ibuf3); + + void (*execute_slice)(SeqRenderData context, struct Sequence *seq, float cfra, float facf0, float facf1, + struct ImBuf *ibuf1, struct ImBuf *ibuf2, struct ImBuf *ibuf3, + int start_line, int total_lines, struct ImBuf *out); }; /* ********************* prototypes *************** */ /* ********************************************************************** - * sequence.c + * sequencer.c * * sequencer render functions * ********************************************************************** */ -struct ImBuf *give_ibuf_seq(SeqRenderData context, float cfra, int chanshown); -struct ImBuf *give_ibuf_seq_threaded(SeqRenderData context, float cfra, int chanshown); -struct ImBuf *give_ibuf_seq_direct(SeqRenderData context, float cfra, struct Sequence *seq); -struct ImBuf *give_ibuf_seqbase(SeqRenderData context, float cfra, int chan_shown, struct ListBase *seqbasep); -void give_ibuf_prefetch_request(SeqRenderData context, float cfra, int chan_shown); - +struct ImBuf *BKE_sequencer_give_ibuf(SeqRenderData context, float cfra, int chanshown); +struct ImBuf *BKE_sequencer_give_ibuf_threaded(SeqRenderData context, float cfra, int chanshown); +struct ImBuf *BKE_sequencer_give_ibuf_direct(SeqRenderData context, float cfra, struct Sequence *seq); +struct ImBuf *BKE_sequencer_give_ibuf_seqbase(SeqRenderData context, float cfra, int chan_shown, struct ListBase *seqbasep); +void BKE_sequencer_give_ibuf_prefetch_request(SeqRenderData context, float cfra, int chan_shown); /* ********************************************************************** * sequencer scene functions @@ -179,43 +181,35 @@ void BKE_sequencer_editing_free(struct Scene *scene); void BKE_sequencer_sort(struct Scene *scene); struct Sequence *BKE_sequencer_active_get(struct Scene *scene); -int BKE_sequencer_active_get_pair(struct Scene *scene, - struct Sequence **seq_act, struct Sequence **seq_other); +int BKE_sequencer_active_get_pair(struct Scene *scene, struct Sequence **seq_act, struct Sequence **seq_other); void BKE_sequencer_active_set(struct Scene *scene, struct Sequence *seq); -struct Mask *BKE_sequencer_mask_get(struct Scene *scene); +struct Mask *BKE_sequencer_mask_get(struct Scene *scene); /* apply functions recursively */ -int seqbase_recursive_apply(struct ListBase *seqbase, int (*apply_func)(struct Sequence *seq, void *), void *arg); -int seq_recursive_apply(struct Sequence *seq, int (*apply_func)(struct Sequence *, void *), void *arg); +int BKE_sequencer_base_recursive_apply(struct ListBase *seqbase, int (*apply_func)(struct Sequence *seq, void *), void *arg); +int BKE_sequencer_recursive_apply(struct Sequence *seq, int (*apply_func)(struct Sequence *, void *), void *arg); /* maintenance functions, mostly for RNA */ -// extern -void seq_free_sequence(struct Scene *scene, struct Sequence *seq); -void seq_free_sequence_recurse(struct Scene *scene, struct Sequence *seq); -void seq_free_strip(struct Strip *strip); - -void seq_free_clipboard(void); -const char *give_seqname(struct Sequence *seq); -void calc_sequence(struct Scene *scene, struct Sequence *seq); -void calc_sequence_disp(struct Scene *scene, struct Sequence *seq); -void reload_sequence_new_file(struct Scene *scene, struct Sequence *seq, int lock_range); -void build_seqar_cb(struct ListBase *seqbase, struct Sequence ***seqar, int *totseq, - int (*test_func)(struct Sequence *seq)); -int evaluate_seq_frame(struct Scene *scene, int cfra); -struct StripElem *give_stripelem(struct Sequence *seq, int cfra); - -// intern -void printf_strip(struct Sequence *seq); // debugging function (unused) -void update_changed_seq_and_deps(struct Scene *scene, struct Sequence *changed_seq, int len_change, int ibuf_change); - -int input_have_to_preprocess( - SeqRenderData context, struct Sequence *seq, float cfra); - -struct SeqIndexBuildContext *seq_proxy_rebuild_context(struct Main *bmain, struct Scene *scene, struct Sequence *seq); -void seq_proxy_rebuild(struct SeqIndexBuildContext *context, - short *stop, short *do_update, float *progress); -void seq_proxy_rebuild_finish(struct SeqIndexBuildContext *context, short stop); +/* extern */ + +void BKE_sequencer_free_clipboard(void); + +void BKE_sequence_free(struct Scene *scene, struct Sequence *seq); +const char *BKE_sequence_give_name(struct Sequence *seq); +void BKE_sequence_calc(struct Scene *scene, struct Sequence *seq); +void BKE_sequence_calc_disp(struct Scene *scene, struct Sequence *seq); +void BKE_sequence_reload_new_file(struct Scene *scene, struct Sequence *seq, int lock_range); +int BKE_sequencer_evaluate_frame(struct Scene *scene, int cfra); +struct StripElem *BKE_sequencer_give_stripelem(struct Sequence *seq, int cfra); + +/* intern */ +void BKE_sequencer_update_changed_seq_and_deps(struct Scene *scene, struct Sequence *changed_seq, int len_change, int ibuf_change); +int BKE_sequencer_input_have_to_preprocess(SeqRenderData context, struct Sequence *seq, float cfra); + +struct SeqIndexBuildContext *BKE_sequencer_proxy_rebuild_context(struct Main *bmain, struct Scene *scene, struct Sequence *seq); +void BKE_sequencer_proxy_rebuild(struct SeqIndexBuildContext *context, short *stop, short *do_update, float *progress); +void BKE_sequencer_proxy_rebuild_finish(struct SeqIndexBuildContext *context, short stop); /* ********************************************************************** * seqcache.c @@ -230,20 +224,20 @@ typedef enum { SEQ_STRIPELEM_IBUF_ENDSTILL } seq_stripelem_ibuf_t; -void seq_stripelem_cache_destruct(void); -void seq_stripelem_cache_cleanup(void); +void BKE_sequencer_cache_destruct(void); +void BKE_sequencer_cache_cleanup(void); /* returned ImBuf is properly refed and has to be freed */ -struct ImBuf *seq_stripelem_cache_get(SeqRenderData context, struct Sequence *seq, - float cfra, seq_stripelem_ibuf_t type); +struct ImBuf *BKE_sequencer_cache_get(SeqRenderData context, struct Sequence *seq, float cfra, seq_stripelem_ibuf_t type); /* passed ImBuf is properly refed, so ownership is *not* * transfered to the cache. * you can pass the same ImBuf multiple times to the cache without problems. */ - -void seq_stripelem_cache_put(SeqRenderData context, struct Sequence *seq, - float cfra, seq_stripelem_ibuf_t type, struct ImBuf *nval); + +void BKE_sequencer_cache_put(SeqRenderData context, struct Sequence *seq, float cfra, seq_stripelem_ibuf_t type, struct ImBuf *nval); + +void BKE_sequencer_cache_cleanup_sequence(struct Sequence *seq); /* ********************************************************************** * seqeffects.c @@ -253,13 +247,12 @@ void seq_stripelem_cache_put(SeqRenderData context, struct Sequence *seq, */ /* intern */ -struct SeqEffectHandle get_sequence_blend(struct Sequence *seq); -void sequence_effect_speed_rebuild_map(struct Scene *scene, struct Sequence *seq, int force); +struct SeqEffectHandle BKE_sequence_get_blend(struct Sequence *seq); +void BKE_sequence_effect_speed_rebuild_map(struct Scene *scene, struct Sequence *seq, int force); /* extern */ -struct SeqEffectHandle get_sequence_effect(struct Sequence *seq); -int get_sequence_effect_num_inputs(int seq_type); - +struct SeqEffectHandle BKE_sequence_get_effect(struct Sequence *seq); +int BKE_sequence_effect_get_num_inputs(int seq_type); /* ********************************************************************** * Sequencer editing functions @@ -267,43 +260,43 @@ int get_sequence_effect_num_inputs(int seq_type); */ /* for transform but also could use elsewhere */ -int seq_tx_get_start(struct Sequence *seq); -int seq_tx_get_end(struct Sequence *seq); -int seq_tx_get_final_left(struct Sequence *seq, int metaclip); -int seq_tx_get_final_right(struct Sequence *seq, int metaclip); -void seq_tx_set_final_left(struct Sequence *seq, int val); -void seq_tx_set_final_right(struct Sequence *seq, int val); -void seq_tx_handle_xlimits(struct Sequence *seq, int leftflag, int rightflag); -int seq_tx_test(struct Sequence *seq); -int seq_single_check(struct Sequence *seq); -void seq_single_fix(struct Sequence *seq); -int seq_test_overlap(struct ListBase *seqbasep, struct Sequence *test); -void seq_translate(struct Scene *scene, struct Sequence *seq, int delta); -void seq_sound_init(struct Scene *scene, struct Sequence *seq); -struct Sequence *seq_foreground_frame_get(struct Scene *scene, int frame); -struct ListBase *seq_seqbase(struct ListBase *seqbase, struct Sequence *seq); -struct Sequence *seq_metastrip(ListBase *seqbase /* = ed->seqbase */, - struct Sequence *meta /* = NULL */, struct Sequence *seq); - -void seq_offset_animdata(struct Scene *scene, struct Sequence *seq, int ofs); -void seq_dupe_animdata(struct Scene *scene, const char *name_src, const char *name_dst); -int shuffle_seq(struct ListBase *seqbasep, struct Sequence *test, struct Scene *evil_scene); -int shuffle_seq_time(ListBase *seqbasep, struct Scene *evil_scene); -int seqbase_isolated_sel_check(struct ListBase *seqbase); -void free_imbuf_seq(struct Scene *scene, struct ListBase *seqbasep, int check_mem_usage, int keep_file_handles); -struct Sequence *seq_dupli_recursive(struct Scene *scene, struct Scene *scene_to, struct Sequence *seq, int dupe_flag); -int seq_swap(struct Sequence *seq_a, struct Sequence *seq_b, const char **error_str); - -void seq_update_sound_bounds_all(struct Scene *scene); -void seq_update_sound_bounds(struct Scene *scene, struct Sequence *seq); -void seq_update_muting(struct Editing *ed); -void seq_update_sound(struct Scene *scene, struct bSound *sound); -void seqbase_unique_name_recursive(ListBase *seqbasep, struct Sequence *seq); -void seqbase_dupli_recursive(struct Scene *scene, struct Scene *scene_to, ListBase *nseqbase, ListBase *seqbase, int dupe_flag); - -void clear_scene_in_allseqs(struct Main *bmain, struct Scene *sce); - -struct Sequence *get_seq_by_name(struct ListBase *seqbase, const char *name, int recursive); +int BKE_sequence_tx_get_final_left(struct Sequence *seq, int metaclip); +int BKE_sequence_tx_get_final_right(struct Sequence *seq, int metaclip); +void BKE_sequence_tx_set_final_left(struct Sequence *seq, int val); +void BKE_sequence_tx_set_final_right(struct Sequence *seq, int val); +void BKE_sequence_tx_handle_xlimits(struct Sequence *seq, int leftflag, int rightflag); +int BKE_sequence_tx_test(struct Sequence *seq); +int BKE_sequence_single_check(struct Sequence *seq); +void BKE_sequence_single_fix(struct Sequence *seq); +int BKE_sequence_test_overlap(struct ListBase *seqbasep, struct Sequence *test); +void BKE_sequence_translate(struct Scene *scene, struct Sequence *seq, int delta); +void BKE_sequence_sound_init(struct Scene *scene, struct Sequence *seq); +struct Sequence *BKE_sequencer_foreground_frame_get(struct Scene *scene, int frame); +struct ListBase *BKE_sequence_seqbase(struct ListBase *seqbase, struct Sequence *seq); +struct Sequence *BKE_sequence_metastrip(ListBase *seqbase /* = ed->seqbase */, struct Sequence *meta /* = NULL */, struct Sequence *seq); + +void BKE_sequencer_offset_animdata(struct Scene *scene, struct Sequence *seq, int ofs); +void BKE_sequencer_dupe_animdata(struct Scene *scene, const char *name_src, const char *name_dst); +int BKE_sequence_base_shuffle(struct ListBase *seqbasep, struct Sequence *test, struct Scene *evil_scene); +int BKE_sequence_base_shuffle_time(ListBase *seqbasep, struct Scene *evil_scene); +int BKE_sequence_base_isolated_sel_check(struct ListBase *seqbase); +void BKE_sequencer_free_imbuf(struct Scene *scene, struct ListBase *seqbasep, int check_mem_usage, int keep_file_handles); +struct Sequence *BKE_sequence_dupli_recursive(struct Scene *scene, struct Scene *scene_to, struct Sequence *seq, int dupe_flag); +int BKE_sequence_swap(struct Sequence *seq_a, struct Sequence *seq_b, const char **error_str); + +void BKE_sequence_invalidate_cache(struct Scene *scene, struct Sequence *seq); + +void BKE_sequencer_update_sound_bounds_all(struct Scene *scene); +void BKE_sequencer_update_sound_bounds(struct Scene *scene, struct Sequence *seq); +void BKE_sequencer_update_muting(struct Editing *ed); +void BKE_sequencer_update_sound(struct Scene *scene, struct bSound *sound); + +void BKE_seqence_base_unique_name_recursive(ListBase *seqbasep, struct Sequence *seq); +void BKE_sequence_base_dupli_recursive(struct Scene *scene, struct Scene *scene_to, ListBase *nseqbase, ListBase *seqbase, int dupe_flag); + +void BKE_sequencer_clear_scene_in_allseqs(struct Main *bmain, struct Scene *sce); + +struct Sequence *BKE_sequwnce_get_by_name(struct ListBase *seqbase, const char *name, int recursive); /* api for adding new sequence strips */ typedef struct SeqLoadInfo { @@ -335,13 +328,11 @@ typedef struct SeqLoadInfo { /* use as an api function */ typedef struct Sequence *(*SeqLoadFunc)(struct bContext *, ListBase *, struct SeqLoadInfo *); -struct Sequence *alloc_sequence(ListBase *lb, int cfra, int machine); - -void seq_load_apply(struct Scene *scene, struct Sequence *seq, struct SeqLoadInfo *seq_load); +struct Sequence *BKE_sequence_alloc(ListBase *lb, int cfra, int machine); -struct Sequence *sequencer_add_image_strip(struct bContext *C, ListBase *seqbasep, struct SeqLoadInfo *seq_load); -struct Sequence *sequencer_add_sound_strip(struct bContext *C, ListBase *seqbasep, struct SeqLoadInfo *seq_load); -struct Sequence *sequencer_add_movie_strip(struct bContext *C, ListBase *seqbasep, struct SeqLoadInfo *seq_load); +struct Sequence *BKE_sequencer_add_image_strip(struct bContext *C, ListBase *seqbasep, struct SeqLoadInfo *seq_load); +struct Sequence *BKE_sequencer_add_sound_strip(struct bContext *C, ListBase *seqbasep, struct SeqLoadInfo *seq_load); +struct Sequence *BKE_sequencer_add_movie_strip(struct bContext *C, ListBase *seqbasep, struct SeqLoadInfo *seq_load); /* view3d draw callback, run when not in background view */ typedef struct ImBuf *(*SequencerDrawView)(struct Scene *, struct Object *, int, int, unsigned int, int, int, char[256]); @@ -351,4 +342,4 @@ extern SequencerDrawView sequencer_view3d_cb; extern ListBase seqbase_clipboard; extern int seqbase_clipboard_frame; -#endif // __BKE_SEQUENCER_H__ +#endif /* __BKE_SEQUENCER_H__ */ diff --git a/source/blender/blenkernel/intern/anim.c b/source/blender/blenkernel/intern/anim.c index 43b2df7ff95..111ac68b345 100644 --- a/source/blender/blenkernel/intern/anim.c +++ b/source/blender/blenkernel/intern/anim.c @@ -755,8 +755,8 @@ static void group_duplilist(ListBase *lb, Scene *scene, Object *ob, int par_inde /* check the group instance and object layers match, also that the object visible flags are ok. */ if ((dob->origlay & group->layer) == 0 || - (G.rendering == 0 && dob->ob->restrictflag & OB_RESTRICT_VIEW) || - (G.rendering && dob->ob->restrictflag & OB_RESTRICT_RENDER)) + ((G.is_rendering == FALSE) && dob->ob->restrictflag & OB_RESTRICT_VIEW) || + ((G.is_rendering == TRUE) && dob->ob->restrictflag & OB_RESTRICT_RENDER)) { dob->no_draw = TRUE; } @@ -934,7 +934,7 @@ static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, fl else dm = mesh_get_derived_deform(scene, par, CD_MASK_BAREMESH); - if (G.rendering) { + if (G.is_rendering) { vdd.orco = (float(*)[3])BKE_mesh_orco_verts_get(par); BKE_mesh_orco_verts_transform(me, vdd.orco, me->totvert, 0); } @@ -1066,7 +1066,7 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa mloop = dm->getLoopArray(dm); mvert = dm->getVertArray(dm); - if (G.rendering) { + if (G.is_rendering) { orco = (float(*)[3])BKE_mesh_orco_verts_get(par); BKE_mesh_orco_verts_transform(me, orco, me->totvert, 0); @@ -1177,7 +1177,7 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa mul_m4_m4m3(obmat, tmat, mat); dob = new_dupli_object(lb, ob, obmat, par->lay, a, par_index, OB_DUPLIFACES, animated); - if (G.rendering) { + if (G.is_rendering) { w = 1.0f / (float)mp->totloop; if (orco) { @@ -1251,7 +1251,7 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p if (!psys_check_enabled(par, psys)) return; - if (G.rendering == 0) + if (G.is_rendering == FALSE) no_draw_flag |= PARS_NO_DISP; ctime = BKE_scene_frame_get(scene); /* NOTE: in old animsys, used parent object's timeoffset... */ @@ -1445,7 +1445,7 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p dob = new_dupli_object(lb, go->ob, mat, par->lay, counter, index, OB_DUPLIPARTS, animated); copy_m4_m4(dob->omat, obcopylist[b].obmat); - if (G.rendering) + if (G.is_rendering) psys_get_dupli_texture(psys, part, sim.psmd, pa, cpa, dob->uv, dob->orco); } } @@ -1493,7 +1493,7 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p dob = new_dupli_object(lb, ob, mat, ob->lay, counter, index, GS(id->name) == ID_GR ? OB_DUPLIGROUP : OB_DUPLIPARTS, animated); copy_m4_m4(dob->omat, oldobmat); - if (G.rendering) + if (G.is_rendering) psys_get_dupli_texture(psys, part, sim.psmd, pa, cpa, dob->uv, dob->orco); } @@ -1549,7 +1549,7 @@ static void font_duplilist(ListBase *lb, Scene *scene, Object *par, int par_inde { Object *ob, *obar[256] = {NULL}; Curve *cu; - struct chartrans *ct, *chartransdata; + struct CharTrans *ct, *chartransdata; float vec[3], obmat[4][4], pmat[4][4], fsize, xof, yof; int slen, a; @@ -1599,7 +1599,7 @@ static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBas return; /* Should the dupli's be generated for this object? - Respect restrict flags */ - if (G.rendering) { + if (G.is_rendering) { if (ob->restrictflag & OB_RESTRICT_RENDER) { return; } diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c index 9e222307aa9..0b5d0d90c67 100644 --- a/source/blender/blenkernel/intern/blender.c +++ b/source/blender/blenkernel/intern/blender.c @@ -116,7 +116,7 @@ void free_blender(void) BLI_callback_global_finalize(); - seq_stripelem_cache_destruct(); + BKE_sequencer_cache_destruct(); IMB_moviecache_destruct(); free_nodesystem(); @@ -457,7 +457,7 @@ int blender_test_break(void) blender_test_break_cb(); } - return (G.afbreek == 1); + return (G.is_break == TRUE); } diff --git a/source/blender/blenkernel/intern/bmfont.c b/source/blender/blenkernel/intern/bmfont.c index 722dc1834dd..18161bc6fcb 100644 --- a/source/blender/blenkernel/intern/bmfont.c +++ b/source/blender/blenkernel/intern/bmfont.c @@ -75,7 +75,7 @@ void calcAlpha(ImBuf * ibuf) if (ibuf) { rect = (char *) ibuf->rect; - for (i = ibuf->x * ibuf->y ; i > 0 ; i--) { + for (i = ibuf->x * ibuf->y; i > 0; i--) { rect[3] = MAX3(rect[0], rect[1], rect[2]); rect += 4; } diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c index e1cfcee1367..ed7ac0e1a32 100644 --- a/source/blender/blenkernel/intern/camera.c +++ b/source/blender/blenkernel/intern/camera.c @@ -57,8 +57,8 @@ void *BKE_camera_add(const char *name) cam = BKE_libblock_alloc(&G.main->camera, ID_CA, name); cam->lens = 35.0f; - cam->sensor_x = 32.0f; - cam->sensor_y = 18.0f; + cam->sensor_x = DEFAULT_SENSOR_WIDTH; + cam->sensor_y = DEFAULT_SENSOR_HEIGHT; cam->clipsta = 0.1f; cam->clipend = 100.0f; cam->drawsize = 0.5f; diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c index 74bfa0d60fc..af7afe7bf30 100644 --- a/source/blender/blenkernel/intern/cloth.c +++ b/source/blender/blenkernel/intern/cloth.c @@ -96,6 +96,7 @@ static CM_SOLVER_DEF solvers [] = static void cloth_to_object (Object *ob, ClothModifierData *clmd, float (*vertexCos)[3]); static void cloth_from_mesh ( ClothModifierData *clmd, DerivedMesh *dm ); static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *dm, float framenr, int first); +static void cloth_update_springs( ClothModifierData *clmd ); static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm ); static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm ); @@ -399,11 +400,25 @@ static int do_step_cloth(Object *ob, ClothModifierData *clmd, DerivedMesh *resul copy_v3_v3(verts->txold, verts->x); /* Get the current position. */ - copy_v3_v3(verts->xconst, mvert[i].co); - mul_m4_v3(ob->obmat, verts->xconst); + if ((clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL) && + ((!(cloth->verts[i].flags & CLOTH_VERT_FLAG_PINNED)) + && (cloth->verts[i].goal > ALMOST_ZERO))) + { + copy_v3_v3(verts->xconst, mvert[i].co); + mul_m4_v3(ob->obmat, verts->xconst); + } + else + { + /* This fixed animated goals not to jump back to "first frame position" */ + copy_v3_v3(verts->xconst, verts->txold); + } } effectors = pdInitEffectors(clmd->scene, ob, NULL, clmd->sim_parms->effector_weights); + + /* Support for dynamic vertex groups, changing from frame to frame */ + cloth_apply_vgroup ( clmd, result ); + cloth_update_springs( clmd ); tstart(); @@ -662,7 +677,7 @@ void cloth_free_modifier(ClothModifierData *clmd ) void cloth_free_modifier_extern(ClothModifierData *clmd ) { Cloth *cloth = NULL; - if (G.rt > 0) + if (G.debug_value > 0) printf("cloth_free_modifier_extern\n"); if ( !clmd ) @@ -671,7 +686,7 @@ void cloth_free_modifier_extern(ClothModifierData *clmd ) cloth = clmd->clothObject; if ( cloth ) { - if (G.rt > 0) + if (G.debug_value > 0) printf("cloth_free_modifier_extern in\n"); // If our solver provides a free function, call it @@ -790,11 +805,21 @@ static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm ) if (cloth_uses_vgroup(clmd)) { for ( i = 0; i < numverts; i++, verts++ ) { + + /* Reset Goal values to standard */ + if ( clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL ) + verts->goal= clmd->sim_parms->defgoal; + else + verts->goal= 0.0f; + dvert = dm->getVertData ( dm, i, CD_MDEFORMVERT ); if ( dvert ) { + for ( j = 0; j < dvert->totweight; j++ ) { + verts->flags &= ~CLOTH_VERT_FLAG_PINNED; if (( dvert->dw[j].def_nr == (clmd->sim_parms->vgroup_mass-1)) && (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL )) { verts->goal = dvert->dw [j].weight; + /* goalfac= 1.0f; */ /* UNUSED */ /* @@ -803,9 +828,8 @@ static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm ) */ verts->goal = powf(verts->goal, 4.0f); - if ( verts->goal >=SOFTGOALSNAP ) { + if ( verts->goal >=SOFTGOALSNAP ) verts->flags |= CLOTH_VERT_FLAG_PINNED; - } } if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_SCALING ) { @@ -819,6 +843,7 @@ static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm ) } } + verts->flags &= ~CLOTH_VERT_FLAG_NOSELFCOLL; if (clmd->coll_parms->flags & CLOTH_COLLSETTINGS_FLAG_SELF ) { if ( dvert->dw[j].def_nr == (clmd->coll_parms->vgroup_selfcol-1)) { if (dvert->dw [j].weight > 0.0f) { @@ -826,13 +851,6 @@ static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm ) } } } - /* - // for later - if ( dvert->dw[j].def_nr == (clmd->sim_parms->vgroup_weight-1)) - { - verts->mass = dvert->dw [j].weight; - } - */ } } } @@ -852,7 +870,7 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d // If we have a clothObject, free it. if ( clmd->clothObject != NULL ) { cloth_free_modifier ( clmd ); - if (G.rt > 0) + if (G.debug_value > 0) printf("cloth_free_modifier cloth_from_object\n"); } @@ -1058,6 +1076,51 @@ static void cloth_free_errorsprings(Cloth *cloth, EdgeHash *UNUSED(edgehash), Li BLI_edgehash_free ( cloth->edgehash, NULL ); } +/* update stiffness if vertex group values are changing from frame to frame */ +static void cloth_update_springs( ClothModifierData *clmd ) +{ + Cloth *cloth = clmd->clothObject; + LinkNode *search = NULL; + + search = cloth->springs; + while (search) { + ClothSpring *spring = search->link; + + spring->stiffness = 0.0f; + + if(spring->type == CLOTH_SPRING_TYPE_STRUCTURAL) + { + spring->stiffness = (cloth->verts[spring->kl].struct_stiff + cloth->verts[spring->ij].struct_stiff) / 2.0f; + } + else if(spring->type == CLOTH_SPRING_TYPE_SHEAR) + { + spring->stiffness = (cloth->verts[spring->kl].shear_stiff + cloth->verts[spring->ij].shear_stiff) / 2.0f; + } + else if(spring->type == CLOTH_SPRING_TYPE_BENDING) + { + spring->stiffness = (cloth->verts[spring->kl].bend_stiff + cloth->verts[spring->ij].bend_stiff) / 2.0f; + } + else if(spring->type == CLOTH_SPRING_TYPE_GOAL) + { + /* Warning: Appending NEW goal springs does not work because implicit solver would need reset! */ + + /* Activate / Deactivate existing springs */ + if ((!(cloth->verts[spring->ij].flags & CLOTH_VERT_FLAG_PINNED)) && (cloth->verts[spring->ij].goal > ALMOST_ZERO)) + { + spring->flags &= ~CLOTH_SPRING_FLAG_DEACTIVATE; + } + else + { + spring->flags |= CLOTH_SPRING_FLAG_DEACTIVATE; + } + } + + search = search->next; + } + + +} + static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm ) { Cloth *cloth = clmd->clothObject; @@ -1278,7 +1341,7 @@ static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm ) cloth->edgehash = edgehash; - if (G.rt > 0) + if (G.debug_value > 0) printf("avg_len: %f\n", clmd->sim_parms->avg_spring_len); return 1; diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index 8298023161b..16edbc3f0a9 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -82,8 +82,6 @@ #include "BKE_tessmesh.h" #include "BKE_tracking.h" #include "BKE_movieclip.h" -#include "BKE_tracking.h" -#include "BKE_movieclip.h" #ifdef WITH_PYTHON #include "BPY_extern.h" @@ -3115,7 +3113,7 @@ static void clampto_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *tar copy_m4_m4(obmat, cob->matrix); copy_v3_v3(ownLoc, obmat[3]); - INIT_MINMAX(curveMin, curveMax) + INIT_MINMAX(curveMin, curveMax); BKE_object_minmax(ct->tar, curveMin, curveMax); /* get targetmatrix */ @@ -3985,6 +3983,41 @@ static void followtrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase add_v2_v2v2(pos, marker->pos, track->offset); + /* aspect correction */ + if (data->frame_method != FOLLOWTRACK_FRAME_STRETCH) { + int width, height; + float w_src, h_src, w_dst, h_dst, asp_src, asp_dst; + + BKE_movieclip_get_size(clip, NULL, &width, &height); + + /* apply clip display aspect */ + w_src = width * clip->aspx; + h_src = height * clip->aspy; + + w_dst = scene->r.xsch * scene->r.xasp; + h_dst = scene->r.ysch * scene->r.yasp; + + asp_src = w_src / h_src; + asp_dst = w_dst / h_dst; + + if (fabsf(asp_src - asp_dst) >= FLT_EPSILON) { + if ((asp_src > asp_dst) == (data->frame_method == FOLLOWTRACK_FRAME_CROP)) { + /* fit X */ + float div = asp_src / asp_dst; + float cent = (float) width / 2.0f; + + pos[0] = (((pos[0] * width - cent) * div) + cent) / width; + } + else { + /* fit Y */ + float div = asp_dst / asp_src; + float cent = (float) height / 2.0f; + + pos[1] = (((pos[1] * height - cent) * div) + cent) / height; + } + } + } + BKE_camera_params_init(¶ms); BKE_camera_params_from_object(¶ms, camob); diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index e7dc825accd..e2bb1aaa2c7 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -2222,7 +2222,7 @@ void BKE_curve_bevelList_make(Object *ob) bl->nr = 0; } else { - if (G.rendering && cu->resolu_ren != 0) + if (G.is_rendering && cu->resolu_ren != 0) resolu = cu->resolu_ren; else resolu = nu->resolu; diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index 8dd3b3da705..d92c4ca8632 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -2793,7 +2793,7 @@ void CustomData_set_layer_unique_name(CustomData *data, int index) BLI_uniquename_cb(customdata_unique_check, &data_arg, typeInfo->defaultname, '.', nlayer->name, sizeof(nlayer->name)); } -void CustomData_validate_layer_name(const CustomData *data, int type, char *name, char *outname) +void CustomData_validate_layer_name(const CustomData *data, int type, const char *name, char *outname) { int index = -1; diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c index 636f60c7ce1..87ebc597ecd 100644 --- a/source/blender/blenkernel/intern/depsgraph.c +++ b/source/blender/blenkernel/intern/depsgraph.c @@ -2846,6 +2846,18 @@ void DAG_id_tag_update(ID *id, short flag) } } } + else if (idtype == ID_VF) { + /* this is weak still, should be done delayed as well */ + for (ob = bmain->object.first; ob; ob = ob->id.next) { + if (ob->type == OB_FONT) { + Curve *cu = ob->data; + + if (ELEM4((struct VFont *)id, cu->vfont, cu->vfontb, cu->vfonti, cu->vfontbi)) { + ob->recalc |= (flag & OB_RECALC_ALL); + } + } + } + } else { /* disable because this is called on various ID types automatically. * where printing warning is not useful. for now just ignore */ diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c index 00a76e87d83..64959fd3aa1 100644 --- a/source/blender/blenkernel/intern/displist.c +++ b/source/blender/blenkernel/intern/displist.c @@ -677,7 +677,7 @@ void BKE_displist_make_mball(Scene *scene, Object *ob) /* XXX: mball stuff uses plenty of global variables * while this is unchanged updating during render is unsafe */ - if (G.rendering) + if (G.is_rendering) return; BKE_displist_free(&(ob->disp)); diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c index 050f921998d..02e5dc02746 100644 --- a/source/blender/blenkernel/intern/font.c +++ b/source/blender/blenkernel/intern/font.c @@ -63,26 +63,34 @@ static ListBase ttfdata = {NULL, NULL}; /* The vfont code */ -void BKE_vfont_free(struct VFont *vf) + +void BKE_vfont_free_data(struct VFont *vfont) { - if (vf == NULL) return; + if (vfont->data) { + while (vfont->data->characters.first) { + VChar *che = vfont->data->characters.first; - if (vf->data) { - while (vf->data->characters.first) { - VChar *che = vf->data->characters.first; - while (che->nurbsbase.first) { Nurb *nu = che->nurbsbase.first; if (nu->bezt) MEM_freeN(nu->bezt); BLI_freelinkN(&che->nurbsbase, nu); } - - BLI_freelinkN(&vf->data->characters, che); + + BLI_freelinkN(&vfont->data->characters, che); } - MEM_freeN(vf->data); - vf->data = NULL; + MEM_freeN(vfont->data); + vfont->data = NULL; } + + BKE_vfont_tmpfont_remove(vfont); +} + +void BKE_vfont_free(struct VFont *vf) +{ + if (vf == NULL) return; + + BKE_vfont_free_data(vf); if (vf->packedfile) { freePackedFile(vf->packedfile); @@ -93,6 +101,11 @@ void BKE_vfont_free(struct VFont *vf) static void *builtin_font_data = NULL; static int builtin_font_size = 0; +int BKE_vfont_is_builtin(struct VFont *vfont) +{ + return (strcmp(vfont->name, FO_BUILTIN_NAME) == 0); +} + void BKE_vfont_builtin_register(void *mem, int size) { builtin_font_data = mem; @@ -115,34 +128,54 @@ static PackedFile *get_builtin_packedfile(void) } } +static void vfont_tmpfont_free(struct TmpFont *tf) +{ + if (tf->pf) { + freePackedFile(tf->pf); /* NULL when the font file can't be found on disk */ + } + MEM_freeN(tf); +} + void BKE_vfont_free_global_ttf(void) { - struct TmpFont *tf; + struct TmpFont *tf, *tf_next; - for (tf = ttfdata.first; tf; tf = tf->next) { - if (tf->pf) freePackedFile(tf->pf); /* NULL when the font file can't be found on disk */ - tf->pf = NULL; - tf->vfont = NULL; + for (tf = ttfdata.first; tf; tf = tf_next) { + tf_next = tf->next; + vfont_tmpfont_free(tf); } - BLI_freelistN(&ttfdata); + ttfdata.first = ttfdata.last = NULL; } -struct TmpFont *BKE_vfont_find_tmpfont(VFont *vfont) +struct TmpFont *BKE_vfont_tmpfont_find(VFont *vfont) { struct TmpFont *tmpfnt = NULL; if (vfont == NULL) return NULL; /* Try finding the font from font list */ - tmpfnt = ttfdata.first; - while (tmpfnt) { - if (tmpfnt->vfont == vfont) + for (tmpfnt = ttfdata.first; tmpfnt; tmpfnt = tmpfnt->next) { + if (tmpfnt->vfont == vfont) { break; - tmpfnt = tmpfnt->next; + } } + return tmpfnt; } +/* assumes a VFont's tmpfont can't be in the database more then once */ +void BKE_vfont_tmpfont_remove(VFont *vfont) +{ + struct TmpFont *tmpfnt; + + tmpfnt = BKE_vfont_tmpfont_find(vfont); + + if (tmpfnt) { + vfont_tmpfont_free(tmpfnt); + BLI_remlink(&ttfdata, tmpfnt); + } +} + static VFontData *vfont_get_data(Main *bmain, VFont *vfont) { struct TmpFont *tmpfnt = NULL; @@ -151,13 +184,13 @@ static VFontData *vfont_get_data(Main *bmain, VFont *vfont) if (vfont == NULL) return NULL; /* Try finding the font from font list */ - tmpfnt = BKE_vfont_find_tmpfont(vfont); + tmpfnt = BKE_vfont_tmpfont_find(vfont); /* And then set the data */ if (!vfont->data) { PackedFile *pf; - if (strcmp(vfont->name, FO_BUILTIN_NAME) == 0) { + if (BKE_vfont_is_builtin(vfont)) { pf = get_builtin_packedfile(); } else { @@ -194,7 +227,11 @@ static VFontData *vfont_get_data(Main *bmain, VFont *vfont) if (!pf) { printf("Font file doesn't exist: %s\n", vfont->name); + /* DON'T DO THIS + * missing file shouldn't modifty path! - campbell */ +#if 0 strcpy(vfont->name, FO_BUILTIN_NAME); +#endif pf = get_builtin_packedfile(); } } @@ -223,7 +260,7 @@ VFont *BKE_vfont_load(Main *bmain, const char *name) BLI_strncpy(filename, name, sizeof(filename)); pf = get_builtin_packedfile(); - is_builtin = 1; + is_builtin = TRUE; } else { char dir[FILE_MAXDIR]; @@ -234,7 +271,7 @@ VFont *BKE_vfont_load(Main *bmain, const char *name) pf = newPackedFile(NULL, name, bmain->name); tpf = newPackedFile(NULL, name, bmain->name); - is_builtin = 0; + is_builtin = FALSE; } if (pf) { @@ -292,11 +329,13 @@ static VFont *which_vfont(Curve *cu, CharInfo *info) VFont *BKE_vfont_builtin_get(void) { - VFont *vf; + VFont *vfont; - for (vf = G.main->vfont.first; vf; vf = vf->id.next) - if (strcmp(vf->name, FO_BUILTIN_NAME) == 0) - return vf; + for (vfont = G.main->vfont.first; vfont; vfont = vfont->id.next) { + if (BKE_vfont_is_builtin(vfont)) { + return vfont; + } + } return BKE_vfont_load(G.main, FO_BUILTIN_NAME); } @@ -359,7 +398,8 @@ static void build_underline(Curve *cu, float x1, float y1, float x2, float y2, i } -static void buildchar(Main *bmain, Curve *cu, unsigned long character, CharInfo *info, float ofsx, float ofsy, float rot, int charidx) +static void buildchar(Main *bmain, Curve *cu, unsigned long character, CharInfo *info, + float ofsx, float ofsy, float rot, int charidx) { BezTriple *bezt1, *bezt2; Nurb *nu1 = NULL, *nu2 = NULL; @@ -385,8 +425,8 @@ static void buildchar(Main *bmain, Curve *cu, unsigned long character, CharInfo /* make a copy at distance ofsx, ofsy with shear*/ fsize = cu->fsize; shear = cu->shear; - si = (float)sin(rot); - co = (float)cos(rot); + si = sinf(rot); + co = cosf(rot); che = find_vfont_char(vfd, character); @@ -520,7 +560,7 @@ static float char_width(Curve *cu, VChar *che, CharInfo *info) } } -struct chartrans *BKE_vfont_to_curve(Main *bmain, Scene *scene, Object *ob, int mode) +struct CharTrans *BKE_vfont_to_curve(Main *bmain, Scene *scene, Object *ob, int mode) { VFont *vfont, *oldvfont; VFontData *vfd = NULL; @@ -528,7 +568,7 @@ struct chartrans *BKE_vfont_to_curve(Main *bmain, Scene *scene, Object *ob, int CharInfo *info = NULL, *custrinfo; TextBox *tb; VChar *che; - struct chartrans *chartransdata = NULL, *ct; + struct CharTrans *chartransdata = NULL, *ct; float *f, xof, yof, xtrax, linedist, *linedata, *linedata2, *linedata3, *linedata4; float twidth, maxlen = 0; int i, slen, j; @@ -538,7 +578,7 @@ struct chartrans *BKE_vfont_to_curve(Main *bmain, Scene *scene, Object *ob, int short cnr = 0, lnr = 0, wsnr = 0; wchar_t *mem, *tmp, ascii; - /* renark: do calculations including the trailing '\0' of a string + /* remark: do calculations including the trailing '\0' of a string * because the cursor can be at that location */ if (ob->type != OB_FONT) return NULL; @@ -583,7 +623,7 @@ struct chartrans *BKE_vfont_to_curve(Main *bmain, Scene *scene, Object *ob, int /* calc offset and rotation of each char */ ct = chartransdata = - (struct chartrans *)MEM_callocN((slen + 1) * sizeof(struct chartrans), "buildtext"); + (struct CharTrans *)MEM_callocN((slen + 1) * sizeof(struct CharTrans), "buildtext"); /* We assume the worst case: 1 character per line (is freed at end anyway) */ @@ -631,10 +671,10 @@ makebreak: /* * The character wasn't in the current curve base so load it - * But if the font is FO_BUILTIN_NAME then do not try loading since + * But if the font is built-in then do not try loading since * whole font is in the memory already */ - if (che == NULL && strcmp(vfont->name, FO_BUILTIN_NAME)) { + if (che == NULL && BKE_vfont_is_builtin(vfont) == FALSE) { BLI_vfontchar_from_freetypefont(vfont, ascii); } @@ -665,7 +705,10 @@ makebreak: twidth = char_width(cu, che, info); /* Calculate positions */ - if ((tb->w != 0.0f) && (ct->dobreak == 0) && ((xof - (tb->x / cu->fsize) + twidth) * cu->fsize) > tb->w + cu->xof * cu->fsize) { + if ((tb->w != 0.0f) && + (ct->dobreak == 0) && + (((xof - (tb->x / cu->fsize) + twidth) * cu->fsize) > tb->w + cu->xof * cu->fsize)) + { // fprintf(stderr, "linewidth exceeded: %c%c%c...\n", mem[i], mem[i+1], mem[i+2]); for (j = i; j && (mem[j] != '\n') && (mem[j] != '\r') && (chartransdata[j].dobreak == 0); j--) { if (mem[j] == ' ' || mem[j] == '-') { @@ -691,6 +734,7 @@ makebreak: } } } + if (ascii == '\n' || ascii == '\r' || ascii == 0 || ct->dobreak) { ct->xof = xof; ct->yof = yof; @@ -760,15 +804,18 @@ makebreak: wsfac = cu->wordspace; wsnr++; } - else wsfac = 1.0f; + else { + wsfac = 1.0f; + } /* Set the width of the character */ twidth = char_width(cu, che, info); xof += (twidth * wsfac * (1.0f + (info->kern / 40.0f)) ) + xtrax; - if (sb) + if (sb) { sb->w = (xof * cu->fsize) - sb->w; + } } ct++; } @@ -812,7 +859,7 @@ makebreak: /* do nothing */ } -// if ((mem[j]!='\r') && (mem[j]!='\n') && (mem[j])) { +// if ((mem[j] != '\r') && (mem[j] != '\n') && (mem[j])) { ct->xof += ct->charnr * linedata[ct->linenr]; // } ct++; @@ -887,11 +934,14 @@ makebreak: else if (cu->spacemode == CU_MIDDLE) { timeofs = (1.0f - distfac) / 2.0f; } - else if (cu->spacemode == CU_FLUSH) distfac = 1.0f; - + else if (cu->spacemode == CU_FLUSH) { + distfac = 1.0f; + } } - else distfac = 1.0; - + else { + distfac = 1.0; + } + distfac /= (maxx - minx); timeofs += distfac * cu->xof; /* not cyclic */ @@ -920,10 +970,10 @@ makebreak: mul_v3_fl(vec, sizefac); - ct->rot = (float)(M_PI - atan2(rotvec[1], rotvec[0])); + ct->rot = (float)M_PI - atan2f(rotvec[1], rotvec[0]); - si = (float)sin(ct->rot); - co = (float)cos(ct->rot); + si = sinf(ct->rot); + co = cosf(ct->rot); yof = ct->yof; @@ -986,21 +1036,21 @@ makebreak: f = cu->editfont->textcurs[0]; f[0] = cu->fsize * (-0.1f * co + ct->xof); - f[1] = cu->fsize * (0.1f * si + ct->yof); + f[1] = cu->fsize * ( 0.1f * si + ct->yof); - f[2] = cu->fsize * (0.1f * co + ct->xof); + f[2] = cu->fsize * ( 0.1f * co + ct->xof); f[3] = cu->fsize * (-0.1f * si + ct->yof); - f[4] = cu->fsize * (0.1f * co + 0.8f * si + ct->xof); + f[4] = cu->fsize * ( 0.1f * co + 0.8f * si + ct->xof); f[5] = cu->fsize * (-0.1f * si + 0.8f * co + ct->yof); f[6] = cu->fsize * (-0.1f * co + 0.8f * si + ct->xof); - f[7] = cu->fsize * (0.1f * si + 0.8f * co + ct->yof); + f[7] = cu->fsize * ( 0.1f * si + 0.8f * co + ct->yof); } MEM_freeN(linedata); - MEM_freeN(linedata2); + MEM_freeN(linedata2); MEM_freeN(linedata3); MEM_freeN(linedata4); @@ -1031,7 +1081,8 @@ makebreak: float ulwidth, uloverlap = 0.0f; if ((i < (slen - 1)) && (mem[i + 1] != '\n') && (mem[i + 1] != '\r') && - ((mem[i + 1] != ' ') || (custrinfo[i + 1].flag & CU_CHINFO_UNDERLINE)) && ((custrinfo[i + 1].flag & CU_CHINFO_WRAP) == 0)) + ((mem[i + 1] != ' ') || (custrinfo[i + 1].flag & CU_CHINFO_UNDERLINE)) && + ((custrinfo[i + 1].flag & CU_CHINFO_WRAP) == 0)) { uloverlap = xtrax + 0.1f; } diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 658be1fb494..fbcd943e13f 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -603,7 +603,7 @@ static ImBuf *add_ibuf_size(unsigned int width, unsigned int height, const char if (floatbuf) { ibuf = IMB_allocImBuf(width, height, depth, IB_rectfloat); - rect_float = (float *)ibuf->rect_float; + rect_float = ibuf->rect_float; ibuf->profile = IB_PROFILE_LINEAR_RGB; } else { @@ -741,7 +741,7 @@ void free_old_images(void) return; /* of course not! */ - if (G.rendering) + if (G.is_rendering) return; lasttime = ctime; @@ -969,7 +969,6 @@ int BKE_imtype_is_movie(const char imtype) switch (imtype) { case R_IMF_IMTYPE_AVIRAW: case R_IMF_IMTYPE_AVIJPEG: - case R_IMF_IMTYPE_AVICODEC: case R_IMF_IMTYPE_QUICKTIME: case R_IMF_IMTYPE_FFMPEG: case R_IMF_IMTYPE_H264: @@ -1084,7 +1083,6 @@ char BKE_imtype_from_arg(const char *imtype_arg) else if (!strcmp(imtype_arg, "AVIRAW")) return R_IMF_IMTYPE_AVIRAW; else if (!strcmp(imtype_arg, "AVIJPEG")) return R_IMF_IMTYPE_AVIJPEG; else if (!strcmp(imtype_arg, "PNG")) return R_IMF_IMTYPE_PNG; - else if (!strcmp(imtype_arg, "AVICODEC")) return R_IMF_IMTYPE_AVICODEC; else if (!strcmp(imtype_arg, "QUICKTIME")) return R_IMF_IMTYPE_QUICKTIME; else if (!strcmp(imtype_arg, "BMP")) return R_IMF_IMTYPE_BMP; #ifdef WITH_HDR @@ -1180,7 +1178,7 @@ int BKE_add_image_extension(char *string, const char imtype) extension = ".jp2"; } #endif - else { // R_IMF_IMTYPE_AVICODEC, R_IMF_IMTYPE_AVIRAW, R_IMF_IMTYPE_AVIJPEG, R_IMF_IMTYPE_JPEG90, R_IMF_IMTYPE_QUICKTIME etc + else { // R_IMF_IMTYPE_AVIRAW, R_IMF_IMTYPE_AVIJPEG, R_IMF_IMTYPE_JPEG90, R_IMF_IMTYPE_QUICKTIME etc if (!(BLI_testextensie(string, ".jpg") || BLI_testextensie(string, ".jpeg"))) extension = ".jpg"; } @@ -1444,7 +1442,7 @@ static void stampdata(Scene *scene, Object *camera, StampData *stamp_data, int d } if (scene->r.stamp & R_STAMP_SEQSTRIP) { - Sequence *seq = seq_foreground_frame_get(scene, scene->r.cfra); + Sequence *seq = BKE_sequencer_foreground_frame_get(scene, scene->r.cfra); if (seq) BLI_strncpy(text, seq->name + 2, sizeof(text)); else BLI_strncpy(text, "<none>", sizeof(text)); diff --git a/source/blender/blenkernel/intern/implicit.c b/source/blender/blenkernel/intern/implicit.c index 8a573aaa676..616214c21ff 100644 --- a/source/blender/blenkernel/intern/implicit.c +++ b/source/blender/blenkernel/intern/implicit.c @@ -120,7 +120,7 @@ typedef float lfVector[3]; typedef struct fmatrix3x3 { float m[3][3]; /* 3x3 matrix */ unsigned int c, r; /* column and row number */ - int pinned; /* is this vertex allowed to move? */ + /* int pinned; // is this vertex allowed to move? */ float n1, n2, n3; /* three normal vectors for collision constrains */ unsigned int vcount; /* vertex count */ unsigned int scount; /* spring count */ @@ -700,17 +700,39 @@ typedef struct Implicit_Data { fmatrix3x3 *A, *dFdV, *dFdX, *S, *P, *Pinv, *bigI, *M; } Implicit_Data; +/* Init constraint matrix */ +static void update_matrixS(ClothVertex *verts, int numverts, fmatrix3x3 *S) +{ + unsigned int pinned = 0; + int i = 0; + + /* Clear matrix from old vertex constraints */ + for(i = 0; i < S[0].vcount; i++) + S[i].c = S[i].r = 0; + + /* Set new vertex constraints */ + for (i = 0; i < numverts; i++) { + if (verts [i].flags & CLOTH_VERT_FLAG_PINNED) { + S[pinned].c = S[pinned].r = i; + pinned++; + } + } + + // S is special and needs specific vcount and scount + S[0].vcount = pinned; + S[0].scount = 0; +} + int implicit_init(Object *UNUSED(ob), ClothModifierData *clmd) { unsigned int i = 0; - unsigned int pinned = 0; Cloth *cloth = NULL; ClothVertex *verts = NULL; ClothSpring *spring = NULL; Implicit_Data *id = NULL; LinkNode *search = NULL; - if (G.rt > 0) + if (G.debug_value > 0) printf("implicit_init\n"); // init memory guard @@ -743,24 +765,19 @@ int implicit_init(Object *UNUSED(ob), ClothModifierData *clmd) id->dV = create_lfvector(cloth->numverts); id->z = create_lfvector(cloth->numverts); - for (i=0;i<cloth->numverts;i++) { + id->S[0].vcount = 0; + + for (i = 0; i < cloth->numverts; i++) { id->A[i].r = id->A[i].c = id->dFdV[i].r = id->dFdV[i].c = id->dFdX[i].r = id->dFdX[i].c = id->P[i].c = id->P[i].r = id->Pinv[i].c = id->Pinv[i].r = id->bigI[i].c = id->bigI[i].r = id->M[i].r = id->M[i].c = i; - if (verts [i].flags & CLOTH_VERT_FLAG_PINNED) { - id->S[pinned].pinned = 1; - id->S[pinned].c = id->S[pinned].r = i; - pinned++; - } + update_matrixS(verts, cloth->numverts, id->S); initdiag_fmatrixS(id->M[i].m, verts[i].mass); } - // S is special and needs specific vcount and scount - id->S[0].vcount = pinned; id->S[0].scount = 0; - // init springs search = cloth->springs; - for (i=0;i<cloth->numsprings;i++) { + for (i = 0; i < cloth->numsprings; i++) { spring = search->link; // dFdV_start[i].r = big_I[i].r = big_zero[i].r = @@ -784,6 +801,7 @@ int implicit_init(Object *UNUSED(ob), ClothModifierData *clmd) return 1; } + int implicit_free(ClothModifierData *clmd) { Implicit_Data *id; @@ -1640,8 +1658,9 @@ static void cloth_calc_force(ClothModifierData *clmd, float UNUSED(frame), lfVec search = cloth->springs; while (search) { // only handle active springs - // if (((clmd->sim_parms->flags & CSIMSETT_FLAG_TEARING_ENABLED) && !(springs[i].flags & CSPRING_FLAG_DEACTIVATE))|| !(clmd->sim_parms->flags & CSIMSETT_FLAG_TEARING_ENABLED)) {} - cloth_calc_spring_force(clmd, search->link, lF, lX, lV, dFdV, dFdX, time); + ClothSpring *spring = search->link; + if( !(spring->flags & CLOTH_SPRING_FLAG_DEACTIVATE)) + cloth_calc_spring_force(clmd, search->link, lF, lX, lV, dFdV, dFdX, time); search = search->next; } @@ -1650,8 +1669,9 @@ static void cloth_calc_force(ClothModifierData *clmd, float UNUSED(frame), lfVec search = cloth->springs; while (search) { // only handle active springs - // if (((clmd->sim_parms->flags & CSIMSETT_FLAG_TEARING_ENABLED) && !(springs[i].flags & CSPRING_FLAG_DEACTIVATE))|| !(clmd->sim_parms->flags & CSIMSETT_FLAG_TEARING_ENABLED)) - cloth_apply_spring_force(clmd, search->link, lF, lX, lV, dFdV, dFdX); + ClothSpring *spring = search->link; + if (!(spring->flags & CLOTH_SPRING_FLAG_DEACTIVATE)) + cloth_apply_spring_force(clmd, search->link, lF, lX, lV, dFdV, dFdX); search = search->next; } // printf("\n"); @@ -1781,6 +1801,10 @@ int implicit_solver(Object *ob, float frame, ClothModifierData *clmd, ListBase * int do_extra_solve; if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL) { /* do goal stuff */ + + /* Update vertex constraints for pinned vertices */ + update_matrixS(verts, cloth->numverts, id->S); + for (i = 0; i < numverts; i++) { // update velocities with constrained velocities from pinned verts if (verts [i].flags & CLOTH_VERT_FLAG_PINNED) { @@ -1918,7 +1942,7 @@ void implicit_set_positions(ClothModifierData *clmd) copy_v3_v3(id->X[i], verts[i].x); copy_v3_v3(id->V[i], verts[i].v); } - if (G.rt > 0) + if (G.debug_value > 0) printf("implicit_set_positions\n"); } diff --git a/source/blender/blenkernel/intern/mask.c b/source/blender/blenkernel/intern/mask.c index b3f146586a8..4b4dcff229d 100644 --- a/source/blender/blenkernel/intern/mask.c +++ b/source/blender/blenkernel/intern/mask.c @@ -265,10 +265,10 @@ MaskSpline *BKE_mask_spline_add(MaskLayer *masklay) return spline; } -int BKE_mask_spline_resolution(MaskSpline *spline, int width, int height) +unsigned int BKE_mask_spline_resolution(MaskSpline *spline, int width, int height) { float max_segment = 0.01f; - int i, resol = 1; + unsigned int i, resol = 1; if (width != 0 && height != 0) { if (width >= height) @@ -281,7 +281,7 @@ int BKE_mask_spline_resolution(MaskSpline *spline, int width, int height) MaskSplinePoint *point = &spline->points[i]; BezTriple *bezt, *bezt_next; float a, b, c, len; - int cur_resol; + unsigned int cur_resol; bezt = &point->bezt; bezt_next = mask_spline_point_next_bezt(spline, spline->points, point); @@ -298,24 +298,27 @@ int BKE_mask_spline_resolution(MaskSpline *spline, int width, int height) cur_resol = len / max_segment; resol = MAX2(resol, cur_resol); - } - - BLI_assert(resol > 0); - if (resol > MASK_RESOL_MAX) { - resol = MASK_RESOL_MAX; + if (resol >= MASK_RESOL_MAX) { + break; + } } - return resol; + return CLAMPIS(resol, 1, MASK_RESOL_MAX); } -int BKE_mask_spline_feather_resolution(MaskSpline *spline, int width, int height) +unsigned int BKE_mask_spline_feather_resolution(MaskSpline *spline, int width, int height) { const float max_segment = 0.005; - int resol = BKE_mask_spline_resolution(spline, width, height); + unsigned int resol = BKE_mask_spline_resolution(spline, width, height); float max_jump = 0.0f; int i; + /* avoid checking the featrher if we already hit the maximum value */ + if (resol >= MASK_RESOL_MAX) { + return MASK_RESOL_MAX; + } + for (i = 0; i < spline->tot_point; i++) { MaskSplinePoint *point = &spline->points[i]; float prev_u, prev_w; @@ -325,9 +328,16 @@ int BKE_mask_spline_feather_resolution(MaskSpline *spline, int width, int height prev_w = point->bezt.weight; for (j = 0; j < point->tot_uw; j++) { - float jump = fabsf((point->uw[j].w - prev_w) / (point->uw[j].u - prev_u)); + const float w_diff = (point->uw[j].w - prev_w); + const float u_diff = (point->uw[j].u - prev_u); - max_jump = MAX2(max_jump, jump); + /* avoid divide by zero and very high values, + * though these get clamped eventually */ + if (u_diff > FLT_EPSILON) { + float jump = fabsf(w_diff / u_diff); + + max_jump = MAX2(max_jump, jump); + } prev_u = point->uw[j].u; prev_w = point->uw[j].w; @@ -336,35 +346,22 @@ int BKE_mask_spline_feather_resolution(MaskSpline *spline, int width, int height resol += max_jump / max_segment; - BLI_assert(resol > 0); - - if (resol > MASK_RESOL_MAX) { - resol = MASK_RESOL_MAX; - } - - return resol; + return CLAMPIS(resol, 1, MASK_RESOL_MAX); } -int BKE_mask_spline_differentiate_calc_total(const MaskSpline *spline, const int resol) +int BKE_mask_spline_differentiate_calc_total(const MaskSpline *spline, const unsigned int resol) { - int len; - - /* count */ - len = (spline->tot_point - 1) * resol; - if (spline->flag & MASK_SPLINE_CYCLIC) { - len += resol; + return spline->tot_point * resol; } else { - len++; + return ((spline->tot_point - 1) * resol) + 1; } - - return len; } float (*BKE_mask_spline_differentiate_with_resolution_ex(MaskSpline *spline, int *tot_diff_point, - const int resol + const unsigned int resol ))[2] { MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline); @@ -425,7 +422,7 @@ float (*BKE_mask_spline_differentiate_with_resolution(MaskSpline *spline, int wi int *tot_diff_point ))[2] { - int resol = BKE_mask_spline_resolution(spline, width, height); + int unsigned resol = BKE_mask_spline_resolution(spline, width, height); return BKE_mask_spline_differentiate_with_resolution_ex(spline, tot_diff_point, resol); } @@ -484,14 +481,29 @@ static void feather_bucket_check_intersect(float (*feather_points)[2], int tot_f continue; if (isect_seg_seg_v2(v1, v2, v3, v4)) { - int k, len; + int k; float p[2]; + float min_a[2], max_a[2]; + float min_b[2], max_b[2]; isect_seg_seg_v2_point(v1, v2, v3, v4, p); - /* TODO: for now simply choose the shortest loop, could be made smarter in some way */ - len = cur_a - check_b; - if (len < tot_feather_point - len) { + INIT_MINMAX2(min_a, max_a); + INIT_MINMAX2(min_b, max_b); + + /* collapse loop with smaller AABB */ + for (k = 0; k < tot_feather_point; k++) { + if (k >= check_b && k <= cur_a) { + DO_MINMAX2(feather_points[k], min_a, max_a); + } + else { + DO_MINMAX2(feather_points[k], min_b, max_b); + } + } + + if (max_a[0] - min_a[0] < max_b[0] - min_b[0] || + max_a[1] - min_a[1] < max_b[1] - min_b[1]) + { for (k = check_b; k <= cur_a; k++) { copy_v2_v2(feather_points[k], p); } @@ -705,8 +717,7 @@ static void spline_feather_collapse_inner_loops(MaskSpline *spline, float (*feat */ float (*BKE_mask_spline_feather_differentiated_points_with_resolution_ex(MaskSpline *spline, int *tot_feather_point, - const int resol, - const int do_collapse + const unsigned int resol ))[2] { MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline); @@ -768,10 +779,8 @@ float (*BKE_mask_spline_feather_differentiated_points_with_resolution_ex(MaskSpl *tot_feather_point = tot; - /* this is slow! - don't do on draw */ - if (do_collapse) { + if (spline->flag & MASK_SPLINE_NOINTERSECT) spline_feather_collapse_inner_loops(spline, feather, tot); - } return feather; } @@ -779,9 +788,9 @@ float (*BKE_mask_spline_feather_differentiated_points_with_resolution_ex(MaskSpl float (*BKE_mask_spline_feather_differentiated_points_with_resolution(MaskSpline *spline, int width, int height, int *tot_feather_point))[2] { - int resol = BKE_mask_spline_feather_resolution(spline, width, height); + unsigned int resol = BKE_mask_spline_feather_resolution(spline, width, height); - return BKE_mask_spline_feather_differentiated_points_with_resolution_ex(spline, tot_feather_point, resol, FALSE); + return BKE_mask_spline_feather_differentiated_points_with_resolution_ex(spline, tot_feather_point, resol); } float (*BKE_mask_spline_feather_differentiated_points(MaskSpline *spline, int *tot_feather_point))[2] @@ -1056,10 +1065,11 @@ void BKE_mask_point_set_handle(MaskSplinePoint *point, float loc[2], int keep_di float *BKE_mask_point_segment_feather_diff_with_resolution(MaskSpline *spline, MaskSplinePoint *point, int width, int height, - int *tot_feather_point) + unsigned int *tot_feather_point) { float *feather, *fp; - int i, resol = BKE_mask_spline_feather_resolution(spline, width, height); + unsigned int resol = BKE_mask_spline_feather_resolution(spline, width, height); + unsigned int i; feather = fp = MEM_callocN(2 * resol * sizeof(float), "mask point spline feather diff points"); @@ -1080,13 +1090,13 @@ float *BKE_mask_point_segment_feather_diff_with_resolution(MaskSpline *spline, M return feather; } -float *BKE_mask_point_segment_feather_diff(MaskSpline *spline, MaskSplinePoint *point, int *tot_feather_point) +float *BKE_mask_point_segment_feather_diff(MaskSpline *spline, MaskSplinePoint *point, unsigned int *tot_feather_point) { return BKE_mask_point_segment_feather_diff_with_resolution(spline, point, 0, 0, tot_feather_point); } float *BKE_mask_point_segment_diff_with_resolution(MaskSpline *spline, MaskSplinePoint *point, - int width, int height, int *tot_diff_point) + int width, int height, unsigned int *tot_diff_point) { MaskSplinePoint *points_array = BKE_mask_spline_point_array_from_point(spline, point); @@ -1115,7 +1125,7 @@ float *BKE_mask_point_segment_diff_with_resolution(MaskSpline *spline, MaskSplin return diff_points; } -float *BKE_mask_point_segment_diff(MaskSpline *spline, MaskSplinePoint *point, int *tot_diff_point) +float *BKE_mask_point_segment_diff(MaskSpline *spline, MaskSplinePoint *point, unsigned int *tot_diff_point) { return BKE_mask_point_segment_diff_with_resolution(spline, point, 0, 0, tot_diff_point); } @@ -1289,12 +1299,13 @@ MaskSplinePointUW *BKE_mask_point_sort_uw(MaskSplinePoint *point, MaskSplinePoin void BKE_mask_point_add_uw(MaskSplinePoint *point, float u, float w) { if (!point->uw) - point->uw = MEM_callocN(sizeof(*point->uw), "mask point uw"); + point->uw = MEM_mallocN(sizeof(*point->uw), "mask point uw"); else point->uw = MEM_reallocN(point->uw, (point->tot_uw + 1) * sizeof(*point->uw)); point->uw[point->tot_uw].u = u; point->uw[point->tot_uw].w = w; + point->uw[point->tot_uw].flag = 0; point->tot_uw++; @@ -1485,7 +1496,9 @@ MaskLayerShape *BKE_mask_layer_shape_alloc(MaskLayer *masklay, const int frame) void BKE_mask_layer_shape_free(MaskLayerShape *masklay_shape) { - MEM_freeN(masklay_shape->data); + if (masklay_shape->data) { + MEM_freeN(masklay_shape->data); + } MEM_freeN(masklay_shape); } diff --git a/source/blender/blenkernel/intern/mask_rasterize.c b/source/blender/blenkernel/intern/mask_rasterize.c index b26e6de59c4..1fde1168999 100644 --- a/source/blender/blenkernel/intern/mask_rasterize.c +++ b/source/blender/blenkernel/intern/mask_rasterize.c @@ -577,16 +577,16 @@ void BKE_maskrasterize_handle_init(MaskRasterHandle *mr_handle, struct Mask *mas float (*diff_feather_points)[2]; int tot_diff_feather_points; - const int resol_a = BKE_mask_spline_resolution(spline, width, height) / 4; - const int resol_b = BKE_mask_spline_feather_resolution(spline, width, height) / 4; - const int resol = CLAMPIS(MAX2(resol_a, resol_b), 4, 512); + const unsigned int resol_a = BKE_mask_spline_resolution(spline, width, height) / 4; + const unsigned int resol_b = BKE_mask_spline_feather_resolution(spline, width, height) / 4; + const unsigned int resol = CLAMPIS(MAX2(resol_a, resol_b), 4, 512); diff_points = BKE_mask_spline_differentiate_with_resolution_ex( spline, &tot_diff_point, resol); if (do_feather) { diff_feather_points = BKE_mask_spline_feather_differentiated_points_with_resolution_ex( - spline, &tot_diff_feather_points, resol, TRUE); + spline, &tot_diff_feather_points, resol); BLI_assert(diff_feather_points); } else { diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index e93b08f15fc..ad9aa8c9cb1 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -1031,13 +1031,18 @@ static int material_in_nodetree(bNodeTree *ntree, Material *mat) bNode *node; for (node = ntree->nodes.first; node; node = node->next) { - if (node->id && GS(node->id->name) == ID_MA) { - if (node->id == (ID *)mat) - return 1; + if (node->id) { + if (GS(node->id->name) == ID_MA) { + if (node->id == (ID *)mat) { + return 1; + } + } + else if (node->type == NODE_GROUP) { + if (material_in_nodetree((bNodeTree *)node->id, mat)) { + return 1; + } + } } - else if (node->type == NODE_GROUP) - if (material_in_nodetree((bNodeTree *)node->id, mat)) - return 1; } return 0; diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index f897543db18..fa5304b081a 100644 --- a/source/blender/blenkernel/intern/mball.c +++ b/source/blender/blenkernel/intern/mball.c @@ -2288,7 +2288,7 @@ void BKE_mball_polygonize(Scene *scene, Object *ob, ListBase *dispbase) mb = ob->data; if (totelem == 0) return; - if (!(G.rendering) && (mb->flag == MB_UPDATE_NEVER)) return; + if ((G.is_rendering == FALSE) && (mb->flag == MB_UPDATE_NEVER)) return; if (G.moving && mb->flag == MB_UPDATE_FAST) return; curindex = totindex = 0; @@ -2335,7 +2335,7 @@ void BKE_mball_polygonize(Scene *scene, Object *ob, ListBase *dispbase) } /* width is size per polygonize cube */ - if (G.rendering) width = mb->rendersize; + if (G.is_rendering) width = mb->rendersize; else { width = mb->wiresize; if (G.moving && mb->flag == MB_UPDATE_HALFRES) width *= 2; diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 592bc10424f..7cee9626c3f 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -347,9 +347,12 @@ bNode *nodeCopyNode(struct bNodeTree *ntree, struct bNode *node) bNodeSocket *sock, *oldsock; *nnode = *node; - nodeUniqueName(ntree, nnode); - - BLI_addtail(&ntree->nodes, nnode); + /* can be called for nodes outside a node tree (e.g. clipboard) */ + if (ntree) { + nodeUniqueName(ntree, nnode); + + BLI_addtail(&ntree->nodes, nnode); + } BLI_duplicatelist(&nnode->inputs, &node->inputs); oldsock = node->inputs.first; @@ -390,7 +393,8 @@ bNode *nodeCopyNode(struct bNodeTree *ntree, struct bNode *node) nnode->new_node = NULL; nnode->preview = NULL; - ntree->update |= NTREE_UPDATE_NODES; + if (ntree) + ntree->update |= NTREE_UPDATE_NODES; return nnode; } @@ -417,7 +421,7 @@ bNodeLink *nodeAddLink(bNodeTree *ntree, bNode *fromnode, bNodeSocket *fromsock, from = -1; /* OK but flip */ } } - else { + else if (ntree) { /* check tree sockets */ for (sock = ntree->inputs.first; sock; sock = sock->next) if (sock == fromsock) @@ -446,7 +450,7 @@ bNodeLink *nodeAddLink(bNodeTree *ntree, bNode *fromnode, bNodeSocket *fromsock, to = -1; /* OK but flip */ } } - else { + else if (ntree) { /* check tree sockets */ for (sock = ntree->outputs.first; sock; sock = sock->next) if (sock == tosock) @@ -464,7 +468,8 @@ bNodeLink *nodeAddLink(bNodeTree *ntree, bNode *fromnode, bNodeSocket *fromsock, if (from >= 0 && to >= 0) { link = MEM_callocN(sizeof(bNodeLink), "link"); - BLI_addtail(&ntree->links, link); + if (ntree) + BLI_addtail(&ntree->links, link); link->fromnode = fromnode; link->fromsock = fromsock; link->tonode = tonode; @@ -472,26 +477,32 @@ bNodeLink *nodeAddLink(bNodeTree *ntree, bNode *fromnode, bNodeSocket *fromsock, } else if (from <= 0 && to <= 0) { link = MEM_callocN(sizeof(bNodeLink), "link"); - BLI_addtail(&ntree->links, link); + if (ntree) + BLI_addtail(&ntree->links, link); link->fromnode = tonode; link->fromsock = tosock; link->tonode = fromnode; link->tosock = fromsock; } - ntree->update |= NTREE_UPDATE_LINKS; + if (ntree) + ntree->update |= NTREE_UPDATE_LINKS; return link; } void nodeRemLink(bNodeTree *ntree, bNodeLink *link) { - BLI_remlink(&ntree->links, link); + /* can be called for links outside a node tree (e.g. clipboard) */ + if (ntree) + BLI_remlink(&ntree->links, link); + if (link->tosock) link->tosock->link = NULL; MEM_freeN(link); - ntree->update |= NTREE_UPDATE_LINKS; + if (ntree) + ntree->update |= NTREE_UPDATE_LINKS; } void nodeRemSocketLinks(bNodeTree *ntree, bNodeSocket *sock) @@ -581,9 +592,25 @@ void nodeFromView(bNode *node, float x, float y, float *rx, float *ry) } } +int nodeAttachNodeCheck(bNode *node, bNode *parent) +{ + bNode *parent_recurse; + for (parent_recurse = node; parent_recurse; parent_recurse = parent_recurse->parent) { + if (parent_recurse == parent) { + return TRUE; + } + } + + return FALSE; +} + void nodeAttachNode(bNode *node, bNode *parent) { float locx, locy; + + BLI_assert(parent->type == NODE_FRAME); + BLI_assert(nodeAttachNodeCheck(parent, node) == FALSE); + nodeToView(node, 0.0f, 0.0f, &locx, &locy); node->parent = parent; @@ -596,6 +623,9 @@ void nodeDetachNode(struct bNode *node) float locx, locy; if (node->parent) { + + BLI_assert(node->parent->type == NODE_FRAME); + /* transform to view space */ nodeToView(node, 0.0f, 0.0f, &locx, &locy); node->locx = locx; @@ -885,20 +915,24 @@ static void node_unlink_attached(bNodeTree *ntree, bNode *parent) void nodeFreeNode(bNodeTree *ntree, bNode *node) { - bNodeTreeType *treetype = ntreeGetType(ntree->type); bNodeSocket *sock, *nextsock; - /* remove all references to this node */ - nodeUnlinkNode(ntree, node); - node_unlink_attached(ntree, node); - - BLI_remlink(&ntree->nodes, node); + /* can be called for nodes outside a node tree (e.g. clipboard) */ + if (ntree) { + bNodeTreeType *treetype = ntreeGetType(ntree->type); + + /* remove all references to this node */ + nodeUnlinkNode(ntree, node); + node_unlink_attached(ntree, node); + + BLI_remlink(&ntree->nodes, node); + + if (treetype->free_node_cache) + treetype->free_node_cache(ntree, node); + } /* since it is called while free database, node->id is undefined */ - if (treetype->free_node_cache) - treetype->free_node_cache(ntree, node); - if (node->typeinfo && node->typeinfo->freestoragefunc) node->typeinfo->freestoragefunc(node); @@ -917,7 +951,8 @@ void nodeFreeNode(bNodeTree *ntree, bNode *node) MEM_freeN(node); - ntree->update |= NTREE_UPDATE_NODES; + if (ntree) + ntree->update |= NTREE_UPDATE_NODES; } /* do not free ntree itself here, BKE_libblock_free calls this function too */ @@ -1388,6 +1423,64 @@ void nodeSocketSetType(bNodeSocket *sock, int type) node_socket_free_default_value(old_type, old_default_value); } +/* ************** Node Clipboard *********** */ + +typedef struct bNodeClipboard { + ListBase nodes; + ListBase links; + int type; +} bNodeClipboard; + +bNodeClipboard node_clipboard; + +void BKE_node_clipboard_init(struct bNodeTree *ntree) +{ + node_clipboard.type = ntree->type; +} + +void BKE_node_clipboard_clear(void) +{ + bNode *node, *node_next; + bNodeLink *link, *link_next; + + for (link = node_clipboard.links.first; link; link = link_next) { + link_next = link->next; + nodeRemLink(NULL, link); + } + node_clipboard.links.first = node_clipboard.links.last = NULL; + + for (node = node_clipboard.nodes.first; node; node = node_next) { + node_next = node->next; + nodeFreeNode(NULL, node); + } + node_clipboard.nodes.first = node_clipboard.nodes.last = NULL; +} + +void BKE_node_clipboard_add_node(bNode *node) +{ + BLI_addtail(&node_clipboard.nodes, node); +} + +void BKE_node_clipboard_add_link(bNodeLink *link) +{ + BLI_addtail(&node_clipboard.links, link); +} + +const ListBase *BKE_node_clipboard_get_nodes(void) +{ + return &node_clipboard.nodes; +} + +const ListBase *BKE_node_clipboard_get_links(void) +{ + return &node_clipboard.links; +} + +int BKE_node_clipboard_get_type(void) +{ + return node_clipboard.type; +} + /* ************** dependency stuff *********** */ /* node is guaranteed to be not checked before */ @@ -1567,8 +1660,6 @@ void ntreeUpdateTree(bNodeTree *ntree) else if (node->typeinfo->updatefunc) node->typeinfo->updatefunc(ntree, node); } - /* clear update flag */ - node->update = 0; } /* check link validity */ @@ -1590,7 +1681,10 @@ void ntreeUpdateTree(bNodeTree *ntree) /* XXX hack, should be done by depsgraph!! */ ntreeVerifyNodes(G.main, &ntree->id); - /* clear the update flag */ + /* clear update flags */ + for (node = ntree->nodes.first; node; node = node->next) { + node->update = 0; + } ntree->update = 0; } @@ -1897,6 +1991,7 @@ static void registerCompositNodes(bNodeTreeType *ttype) register_node_type_cmp_bilateralblur(ttype); register_node_type_cmp_vecblur(ttype); register_node_type_cmp_dilateerode(ttype); + register_node_type_cmp_inpaint(ttype); register_node_type_cmp_defocus(ttype); register_node_type_cmp_valtorgb(ttype); @@ -2085,6 +2180,10 @@ static void free_typeinfos(ListBase *list) void init_nodesystem(void) { + /* init clipboard */ + node_clipboard.nodes.first = node_clipboard.nodes.last = NULL; + node_clipboard.links.first = node_clipboard.links.last = NULL; + registerCompositNodes(ntreeGetType(NTREE_COMPOSIT)); registerShaderNodes(ntreeGetType(NTREE_SHADER)); registerTextureNodes(ntreeGetType(NTREE_TEXTURE)); diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index efcc131038f..409e1e3921a 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -2653,7 +2653,7 @@ void BKE_object_handle_update(Scene *scene, Object *ob) while (psys) { if (psys_check_enabled(ob, psys)) { /* check use of dupli objects here */ - if (psys->part && (psys->part->draw_as == PART_DRAW_REND || G.rendering) && + if (psys->part && (psys->part->draw_as == PART_DRAW_REND || G.is_rendering) && ((psys->part->ren_as == PART_DRAW_OB && psys->part->dup_ob) || (psys->part->ren_as == PART_DRAW_GR && psys->part->dup_group))) { @@ -2673,7 +2673,7 @@ void BKE_object_handle_update(Scene *scene, Object *ob) psys = psys->next; } - if (G.rendering && ob->transflag & OB_DUPLIPARTS) { + if (G.is_rendering && ob->transflag & OB_DUPLIPARTS) { /* this is to make sure we get render level duplis in groups: * the derivedmesh must be created before init_render_mesh, * since object_duplilist does dupliparticles before that */ diff --git a/source/blender/blenkernel/intern/packedFile.c b/source/blender/blenkernel/intern/packedFile.c index 52acbeb94e5..f115a41d419 100644 --- a/source/blender/blenkernel/intern/packedFile.c +++ b/source/blender/blenkernel/intern/packedFile.c @@ -50,13 +50,14 @@ #include "BLI_blenlib.h" #include "BLI_utildefines.h" -#include "BKE_utildefines.h" +#include "BKE_font.h" #include "BKE_global.h" -#include "BKE_main.h" -#include "BKE_sound.h" #include "BKE_image.h" +#include "BKE_main.h" #include "BKE_packedFile.h" #include "BKE_report.h" +#include "BKE_sound.h" +#include "BKE_utildefines.h" #ifdef _WIN32 #define open _open @@ -219,7 +220,7 @@ PackedFile *newPackedFile(ReportList *reports, const char *filename, const char void packAll(Main *bmain, ReportList *reports) { Image *ima; - VFont *vf; + VFont *vfont; bSound *sound; for (ima = bmain->image.first; ima; ima = ima->id.next) { @@ -233,9 +234,9 @@ void packAll(Main *bmain, ReportList *reports) } } - for (vf = bmain->vfont.first; vf; vf = vf->id.next) - if (vf->packedfile == NULL && vf->id.lib == NULL && strcmp(vf->name, FO_BUILTIN_NAME) != 0) - vf->packedfile = newPackedFile(reports, vf->name, bmain->name); + for (vfont = bmain->vfont.first; vfont; vfont = vfont->id.next) + if (vfont->packedfile == NULL && vfont->id.lib == NULL && BKE_vfont_is_builtin(vfont) == FALSE) + vfont->packedfile = newPackedFile(reports, vfont->name, bmain->name); for (sound = bmain->sound.first; sound; sound = sound->id.next) if (sound->packedfile == NULL && sound->id.lib == NULL) diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index c8b07e2ec11..26952db8fba 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -276,7 +276,7 @@ int psys_check_enabled(Object *ob, ParticleSystem *psys) return 0; psmd = psys_get_modifier(ob, psys); - if (psys->renderdata || G.rendering) { + if (psys->renderdata || G.is_rendering) { if (!(psmd->modifier.mode & eModifierMode_Render)) return 0; } @@ -681,7 +681,7 @@ void psys_render_set(Object *ob, ParticleSystem *psys, float viewmat[][4], float ParticleRenderData *data; ParticleSystemModifierData *psmd = psys_get_modifier(ob, psys); - if (!G.rendering) + if (G.is_rendering == FALSE) return; if (psys->renderdata) return; @@ -2356,7 +2356,7 @@ void psys_find_parents(ParticleSimulationData *sim) int from = PART_FROM_FACE; totparent = (int)(totchild * part->parents * 0.3f); - if (G.rendering && part->child_nbr && part->ren_child_nbr) + if (G.is_rendering && part->child_nbr && part->ren_child_nbr) totparent *= (float)part->child_nbr / (float)part->ren_child_nbr; tree = BLI_kdtree_new(totparent); @@ -2433,7 +2433,7 @@ static int psys_threads_init_path(ParticleThread *threads, Scene *scene, float c if (totchild && part->childtype == PART_CHILD_FACES) { totparent = (int)(totchild * part->parents * 0.3f); - if (G.rendering && part->child_nbr && part->ren_child_nbr) + if (G.is_rendering && part->child_nbr && part->ren_child_nbr) totparent *= (float)part->child_nbr / (float)part->ren_child_nbr; /* part->parents could still be 0 so we can't test with totparent */ @@ -3876,7 +3876,10 @@ void psys_get_texture(ParticleSimulationData *sim, ParticleData *pa, ParticleTex case TEXCO_PARTICLE: /* texture coordinates in range [-1, 1] */ texvec[0] = 2.f * (cfra - pa->time) / (pa->dietime - pa->time) - 1.f; - texvec[1] = 0.f; + if (sim->psys->totpart > 0) + texvec[1] = 2.f * (float)(pa - sim->psys->particles) / (float)sim->psys->totpart - 1.f; + else + texvec[1] = 0.0f; texvec[2] = 0.f; break; } diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index 0b3131f0a1c..bae8efa758e 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -4104,7 +4104,7 @@ static void particles_fluid_step(ParticleSimulationData *sim, int UNUSED(cfra)) } gzread(gzf, &totpart, sizeof(totpart)); - totpart = (G.rendering)?totpart:(part->disp*totpart)/100; + totpart = (G.is_rendering)?totpart:(part->disp*totpart) / 100; part->totpart= totpart; part->sta=part->end = 1.0f; diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index 101f53fe94f..e990f461d4c 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -2807,7 +2807,7 @@ void BKE_ptcache_bake(PTCacheBaker* baker) thread_data.scene = baker->scene; thread_data.main = baker->main; - G.afbreek = 0; + G.is_break = FALSE; /* set caches to baking mode and figure out start frame */ if (pid) { diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 5e4a150c4af..e097a54c478 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -239,7 +239,7 @@ Scene *BKE_scene_copy(Scene *sce, int type) if (sce->ed) { scen->ed = MEM_callocN(sizeof(Editing), "addseq"); scen->ed->seqbasep = &scen->ed->seqbase; - seqbase_dupli_recursive(sce, scen, &scen->ed->seqbase, &sce->ed->seqbase, SEQ_DUPE_ALL); + BKE_sequence_base_dupli_recursive(sce, scen, &scen->ed->seqbase, &sce->ed->seqbase, SEQ_DUPE_ALL); } } @@ -646,7 +646,7 @@ void BKE_scene_unlink(Main *bmain, Scene *sce, Scene *newsce) sce1->set = NULL; /* check all sequences */ - clear_scene_in_allseqs(bmain, sce); + BKE_sequencer_clear_scene_in_allseqs(bmain, sce); /* check render layer nodes in other scenes */ clear_scene_in_nodes(bmain, sce); diff --git a/source/blender/blenkernel/intern/seqcache.c b/source/blender/blenkernel/intern/seqcache.c index 0d91dcb7faa..a4ea5d1fb26 100644 --- a/source/blender/blenkernel/intern/seqcache.c +++ b/source/blender/blenkernel/intern/seqcache.c @@ -37,6 +37,7 @@ #include "BKE_sequencer.h" #include "IMB_moviecache.h" +#include "IMB_imbuf_types.h" typedef struct SeqCacheKey { struct Sequence *seq; @@ -47,6 +48,73 @@ typedef struct SeqCacheKey { static struct MovieCache *moviecache = NULL; +static int seq_cmp_render_data(const SeqRenderData *a, const SeqRenderData *b) +{ + if (a->preview_render_size < b->preview_render_size) { + return -1; + } + if (a->preview_render_size > b->preview_render_size) { + return 1; + } + + if (a->rectx < b->rectx) { + return -1; + } + if (a->rectx > b->rectx) { + return 1; + } + + if (a->recty < b->recty) { + return -1; + } + if (a->recty > b->recty) { + return 1; + } + + if (a->bmain < b->bmain) { + return -1; + } + if (a->bmain > b->bmain) { + return 1; + } + + if (a->scene < b->scene) { + return -1; + } + if (a->scene > b->scene) { + return 1; + } + + if (a->motion_blur_shutter < b->motion_blur_shutter) { + return -1; + } + if (a->motion_blur_shutter > b->motion_blur_shutter) { + return 1; + } + + if (a->motion_blur_samples < b->motion_blur_samples) { + return -1; + } + if (a->motion_blur_samples > b->motion_blur_samples) { + return 1; + } + + return 0; +} + +static unsigned int seq_hash_render_data(const SeqRenderData *a) +{ + unsigned int rval = a->rectx + a->recty; + + rval ^= a->preview_render_size; + rval ^= ((intptr_t) a->bmain) << 6; + rval ^= ((intptr_t) a->scene) << 6; + rval ^= (int)(a->motion_blur_shutter * 100.0f) << 10; + rval ^= a->motion_blur_samples << 24; + + return rval; +} + static unsigned int seqcache_hashhash(const void *key_) { const SeqCacheKey *key = (SeqCacheKey *) key_; @@ -88,13 +156,13 @@ static int seqcache_hashcmp(const void *a_, const void *b_) return seq_cmp_render_data(&a->context, &b->context); } -void seq_stripelem_cache_destruct(void) +void BKE_sequencer_cache_destruct(void) { if (moviecache) IMB_moviecache_free(moviecache); } -void seq_stripelem_cache_cleanup(void) +void BKE_sequencer_cache_cleanup(void) { if (moviecache) { IMB_moviecache_free(moviecache); @@ -102,11 +170,21 @@ void seq_stripelem_cache_cleanup(void) } } -struct ImBuf *seq_stripelem_cache_get( - SeqRenderData context, struct Sequence *seq, - float cfra, seq_stripelem_ibuf_t type) +static int seqcache_key_check_seq(void *userkey, void *userdata) { + SeqCacheKey *key = (SeqCacheKey *) userkey; + Sequence *seq = (Sequence *) userdata; + return key->seq == seq; +} + +void BKE_sequencer_cache_cleanup_sequence(Sequence *seq) +{ + IMB_moviecache_cleanup(moviecache, seqcache_key_check_seq, seq); +} + +struct ImBuf *BKE_sequencer_cache_get(SeqRenderData context, Sequence *seq, float cfra, seq_stripelem_ibuf_t type) +{ if (moviecache && seq) { SeqCacheKey key; @@ -121,9 +199,7 @@ struct ImBuf *seq_stripelem_cache_get( return NULL; } -void seq_stripelem_cache_put( - SeqRenderData context, struct Sequence *seq, - float cfra, seq_stripelem_ibuf_t type, struct ImBuf *i) +void BKE_sequencer_cache_put(SeqRenderData context, Sequence *seq, float cfra, seq_stripelem_ibuf_t type, ImBuf *i) { SeqCacheKey key; diff --git a/source/blender/blenkernel/intern/seqeffects.c b/source/blender/blenkernel/intern/seqeffects.c index 0532a019ecc..911b6b00b98 100644 --- a/source/blender/blenkernel/intern/seqeffects.c +++ b/source/blender/blenkernel/intern/seqeffects.c @@ -56,9 +56,40 @@ #include "RNA_access.h" -/* **** XXX **** */ +static void slize_get_byte_buffers(const SeqRenderData *context, const ImBuf *ibuf1, const ImBuf *ibuf2, + const ImBuf *ibuf3, const ImBuf *out, int start_line, unsigned char **rect1, + unsigned char **rect2, unsigned char **rect3, unsigned char **rect_out) +{ + int offset = 4 * start_line * context->rectx; + + *rect1 = (unsigned char*) ibuf1->rect + offset; + *rect_out = (unsigned char*) out->rect + offset; + + if (ibuf2) + *rect2 = (unsigned char*) ibuf2->rect + offset; + + if (ibuf3) + *rect3 = (unsigned char*) ibuf3->rect + offset; +} + +static void slize_get_float_buffers(const SeqRenderData *context, const ImBuf *ibuf1, const ImBuf *ibuf2, + const ImBuf *ibuf3, const ImBuf *out, int start_line, + float **rect1, float **rect2, float **rect3, float **rect_out) +{ + int offset = 4 * start_line * context->rectx; + + *rect1 = ibuf1->rect_float + offset; + *rect_out = out->rect_float + offset; + + if (ibuf2) + *rect2 = ibuf2->rect_float + offset; + + if (ibuf3) + *rect3 = ibuf3->rect_float + offset; +} + +/*********************** Glow effect *************************/ -/* Glow effect */ enum { GlowR = 0, GlowG = 1, @@ -66,12 +97,9 @@ enum { GlowA = 3 }; -static ImBuf *prepare_effect_imbufs( - SeqRenderData context, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3) +static ImBuf *prepare_effect_imbufs(SeqRenderData context, ImBuf *ibuf1, ImBuf *ibuf2, ImBuf *ibuf3) { - struct ImBuf *out; + ImBuf *out; int x = context.rectx; int y = context.recty; @@ -114,9 +142,7 @@ static ImBuf *prepare_effect_imbufs( return out; } -/* ********************************************************************** - * ALPHA OVER - * ********************************************************************** */ +/*********************** Alpha Over *************************/ static void init_alpha_over_or_under(Sequence *seq) { @@ -127,23 +153,21 @@ static void init_alpha_over_or_under(Sequence *seq) seq->seq1 = seq2; } -static void do_alphaover_effect_byte(float facf0, float facf1, int x, int y, - char *rect1, char *rect2, char *out) +static void do_alphaover_effect_byte(float facf0, float facf1, int x, int y, char *rect1, char *rect2, char *out) { int fac2, mfac, fac, fac4; int xo, tempc; char *rt1, *rt2, *rt; xo = x; - rt1 = (char *)rect1; - rt2 = (char *)rect2; - rt = (char *)out; + rt1 = (char *) rect1; + rt2 = (char *) rect2; + rt = (char *) out; - fac2 = (int)(256.0f * facf0); - fac4 = (int)(256.0f * facf1); + fac2 = (int) (256.0f * facf0); + fac4 = (int) (256.0f * facf1); while (y--) { - x = xo; while (x--) { @@ -152,8 +176,8 @@ static void do_alphaover_effect_byte(float facf0, float facf1, int x, int y, fac = fac2; mfac = 256 - ( (fac2 * rt1[3]) >> 8); - if (fac == 0) *( (unsigned int *)rt) = *( (unsigned int *)rt2); - else if (mfac == 0) *( (unsigned int *)rt) = *( (unsigned int *)rt1); + if (fac == 0) *( (unsigned int *) rt) = *( (unsigned int *) rt2); + else if (mfac == 0) *( (unsigned int *) rt) = *( (unsigned int *) rt1); else { tempc = (fac * rt1[0] + mfac * rt2[0]) >> 8; if (tempc > 255) rt[0] = 255; else rt[0] = tempc; @@ -172,12 +196,11 @@ static void do_alphaover_effect_byte(float facf0, float facf1, int x, int y, x = xo; while (x--) { - fac = fac4; mfac = 256 - ( (fac4 * rt1[3]) >> 8); - if (fac == 0) *( (unsigned int *)rt) = *( (unsigned int *)rt2); - else if (mfac == 0) *( (unsigned int *)rt) = *( (unsigned int *)rt1); + if (fac == 0) *( (unsigned int *) rt) = *( (unsigned int *) rt2); + else if (mfac == 0) *( (unsigned int *) rt) = *( (unsigned int *) rt1); else { tempc = (fac * rt1[0] + mfac * rt2[0]) >> 8; if (tempc > 255) rt[0] = 255; else rt[0] = tempc; @@ -193,8 +216,7 @@ static void do_alphaover_effect_byte(float facf0, float facf1, int x, int y, } } -static void do_alphaover_effect_float(float facf0, float facf1, int x, int y, - float *rect1, float *rect2, float *out) +static void do_alphaover_effect_float(float facf0, float facf1, int x, int y, float *rect1, float *rect2, float *out) { float fac2, mfac, fac, fac4; int xo; @@ -209,10 +231,8 @@ static void do_alphaover_effect_float(float facf0, float facf1, int x, int y, fac4 = facf1; while (y--) { - x = xo; while (x--) { - /* rt = rt1 over rt2 (alpha from rt1) */ fac = fac2; @@ -233,12 +253,12 @@ static void do_alphaover_effect_float(float facf0, float facf1, int x, int y, rt1 += 4; rt2 += 4; rt += 4; } - if (y == 0) break; + if (y == 0) + break; y--; x = xo; while (x--) { - fac = fac4; mfac = 1.0f - (fac4 * rt1[3]); @@ -259,37 +279,29 @@ static void do_alphaover_effect_float(float facf0, float facf1, int x, int y, } } -static ImBuf *do_alphaover_effect( - SeqRenderData context, Sequence *UNUSED(seq), float UNUSED(cfra), - float facf0, float facf1, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3) +static void do_alphaover_effect(SeqRenderData context, Sequence *UNUSED(seq), float UNUSED(cfra), float facf0, + float facf1, ImBuf *ibuf1, ImBuf *ibuf2, ImBuf *UNUSED(ibuf3), + int start_line, int total_lines, ImBuf *out) { - struct ImBuf *out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); - if (out->rect_float) { - do_alphaover_effect_float( - facf0, facf1, context.rectx, context.recty, - ibuf1->rect_float, ibuf2->rect_float, - out->rect_float); + float *rect1, *rect2, *rect_out; + + slize_get_float_buffers(&context, ibuf1, ibuf2, NULL, out, start_line, &rect1, &rect2, NULL, &rect_out); + + do_alphaover_effect_float(facf0, facf1, context.rectx, total_lines, rect1, rect2, rect_out); } else { - do_alphaover_effect_byte( - facf0, facf1, context.rectx, context.recty, - (char *) ibuf1->rect, (char *) ibuf2->rect, - (char *) out->rect); + unsigned char *rect1, *rect2, *rect_out; + + slize_get_byte_buffers(&context, ibuf1, ibuf2, NULL, out, start_line, &rect1, &rect2, NULL, &rect_out); + + do_alphaover_effect_byte(facf0, facf1, context.rectx, total_lines, (char *) rect1, (char *) rect2, (char *) rect_out); } - return out; } +/*********************** Alpha Under *************************/ -/* ********************************************************************** - * ALPHA UNDER - * ********************************************************************** */ - -static void do_alphaunder_effect_byte( - float facf0, float facf1, int x, int y, char *rect1, - char *rect2, char *out) +static void do_alphaunder_effect_byte(float facf0, float facf1, int x, int y, char *rect1, char *rect2, char *out) { int fac2, mfac, fac, fac4; int xo; @@ -304,22 +316,20 @@ static void do_alphaunder_effect_byte( fac4 = (int)(256.0f * facf1); while (y--) { - x = xo; while (x--) { - /* rt = rt1 under rt2 (alpha from rt2) */ /* this complex optimization is because the * 'skybuf' can be crossed in */ - if (rt2[3] == 0 && fac2 == 256) *( (unsigned int *)rt) = *( (unsigned int *)rt1); - else if (rt2[3] == 255) *( (unsigned int *)rt) = *( (unsigned int *)rt2); + if (rt2[3] == 0 && fac2 == 256) *( (unsigned int *) rt) = *( (unsigned int *) rt1); + else if (rt2[3] == 255) *( (unsigned int *) rt) = *( (unsigned int *) rt2); else { mfac = rt2[3]; fac = (fac2 * (256 - mfac)) >> 8; - if (fac == 0) *( (unsigned int *)rt) = *( (unsigned int *)rt2); + if (fac == 0) *( (unsigned int *) rt) = *( (unsigned int *) rt2); else { rt[0] = (fac * rt1[0] + mfac * rt2[0]) >> 8; rt[1] = (fac * rt1[1] + mfac * rt2[1]) >> 8; @@ -330,14 +340,14 @@ static void do_alphaunder_effect_byte( rt1 += 4; rt2 += 4; rt += 4; } - if (y == 0) break; + if (y == 0) + break; y--; x = xo; while (x--) { - - if (rt2[3] == 0 && fac4 == 256) *( (unsigned int *)rt) = *( (unsigned int *)rt1); - else if (rt2[3] == 255) *( (unsigned int *)rt) = *( (unsigned int *)rt2); + if (rt2[3] == 0 && fac4 == 256) *( (unsigned int *) rt) = *( (unsigned int *) rt1); + else if (rt2[3] == 255) *( (unsigned int *) rt) = *( (unsigned int *) rt2); else { mfac = rt2[3]; fac = (fac4 * (256 - mfac)) >> 8; @@ -355,10 +365,7 @@ static void do_alphaunder_effect_byte( } } - -static void do_alphaunder_effect_float(float facf0, float facf1, int x, int y, - float *rect1, float *rect2, - float *out) +static void do_alphaunder_effect_float(float facf0, float facf1, int x, int y, float *rect1, float *rect2, float *out) { float fac2, mfac, fac, fac4; int xo; @@ -373,10 +380,8 @@ static void do_alphaunder_effect_float(float facf0, float facf1, int x, int y, fac4 = facf1; while (y--) { - x = xo; while (x--) { - /* rt = rt1 under rt2 (alpha from rt2) */ /* this complex optimization is because the @@ -405,15 +410,14 @@ static void do_alphaunder_effect_float(float facf0, float facf1, int x, int y, rt1 += 4; rt2 += 4; rt += 4; } - if (y == 0) break; + if (y == 0) + break; y--; x = xo; while (x--) { - if (rt2[3] <= 0 && fac4 >= 1.0f) { memcpy(rt, rt1, 4 * sizeof(float)); - } else if (rt2[3] >= 1.0f) { memcpy(rt, rt2, 4 * sizeof(float)); @@ -437,38 +441,29 @@ static void do_alphaunder_effect_float(float facf0, float facf1, int x, int y, } } -static ImBuf *do_alphaunder_effect( - SeqRenderData context, Sequence *UNUSED(seq), float UNUSED(cfra), - float facf0, float facf1, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3) +static void do_alphaunder_effect(SeqRenderData context, Sequence *UNUSED(seq), float UNUSED(cfra), + float facf0, float facf1, ImBuf *ibuf1, ImBuf *ibuf2, ImBuf *UNUSED(ibuf3), + int start_line, int total_lines, ImBuf *out) { - struct ImBuf *out = prepare_effect_imbufs( - context, ibuf1, ibuf2, ibuf3); - if (out->rect_float) { - do_alphaunder_effect_float( - facf0, facf1, context.rectx, context.recty, - ibuf1->rect_float, ibuf2->rect_float, - out->rect_float); + float *rect1, *rect2, *rect_out; + + slize_get_float_buffers(&context, ibuf1, ibuf2, NULL, out, start_line, &rect1, &rect2, NULL, &rect_out); + + do_alphaunder_effect_float(facf0, facf1, context.rectx, total_lines, rect1, rect2, rect_out); } else { - do_alphaunder_effect_byte( - facf0, facf1, context.rectx, context.recty, - (char *) ibuf1->rect, (char *) ibuf2->rect, - (char *) out->rect); + unsigned char *rect1, *rect2, *rect_out; + + slize_get_byte_buffers(&context, ibuf1, ibuf2, NULL, out, start_line, &rect1, &rect2, NULL, &rect_out); + + do_alphaunder_effect_byte(facf0, facf1, context.rectx, total_lines, (char *) rect1, (char *) rect2, (char *) rect_out); } - return out; } +/*********************** Cross *************************/ -/* ********************************************************************** - * CROSS - * ********************************************************************** */ - -static void do_cross_effect_byte(float facf0, float facf1, int x, int y, - char *rect1, char *rect2, - char *out) +static void do_cross_effect_byte(float facf0, float facf1, int x, int y, char *rect1, char *rect2, char *out) { int fac1, fac2, fac3, fac4; int xo; @@ -479,16 +474,14 @@ static void do_cross_effect_byte(float facf0, float facf1, int x, int y, rt2 = rect2; rt = out; - fac2 = (int)(256.0f * facf0); + fac2 = (int) (256.0f * facf0); fac1 = 256 - fac2; - fac4 = (int)(256.0f * facf1); + fac4 = (int) (256.0f * facf1); fac3 = 256 - fac4; while (y--) { - x = xo; while (x--) { - rt[0] = (fac1 * rt1[0] + fac2 * rt2[0]) >> 8; rt[1] = (fac1 * rt1[1] + fac2 * rt2[1]) >> 8; rt[2] = (fac1 * rt1[2] + fac2 * rt2[2]) >> 8; @@ -497,12 +490,12 @@ static void do_cross_effect_byte(float facf0, float facf1, int x, int y, rt1 += 4; rt2 += 4; rt += 4; } - if (y == 0) break; + if (y == 0) + break; y--; x = xo; while (x--) { - rt[0] = (fac3 * rt1[0] + fac4 * rt2[0]) >> 8; rt[1] = (fac3 * rt1[1] + fac4 * rt2[1]) >> 8; rt[2] = (fac3 * rt1[2] + fac4 * rt2[2]) >> 8; @@ -514,8 +507,7 @@ static void do_cross_effect_byte(float facf0, float facf1, int x, int y, } } -static void do_cross_effect_float(float facf0, float facf1, int x, int y, - float *rect1, float *rect2, float *out) +static void do_cross_effect_float(float facf0, float facf1, int x, int y, float *rect1, float *rect2, float *out) { float fac1, fac2, fac3, fac4; int xo; @@ -532,10 +524,8 @@ static void do_cross_effect_float(float facf0, float facf1, int x, int y, fac3 = 1.0f - fac4; while (y--) { - x = xo; while (x--) { - rt[0] = fac1 * rt1[0] + fac2 * rt2[0]; rt[1] = fac1 * rt1[1] + fac2 * rt2[1]; rt[2] = fac1 * rt1[2] + fac2 * rt2[2]; @@ -544,12 +534,12 @@ static void do_cross_effect_float(float facf0, float facf1, int x, int y, rt1 += 4; rt2 += 4; rt += 4; } - if (y == 0) break; + if (y == 0) + break; y--; x = xo; while (x--) { - rt[0] = fac3 * rt1[0] + fac4 * rt2[0]; rt[1] = fac3 * rt1[1] + fac4 * rt2[1]; rt[2] = fac3 * rt1[2] + fac4 * rt2[2]; @@ -561,36 +551,27 @@ static void do_cross_effect_float(float facf0, float facf1, int x, int y, } } -/* careful: also used by speed effect! */ - -static ImBuf *do_cross_effect( - SeqRenderData context, Sequence *UNUSED(seq), float UNUSED(cfra), - float facf0, float facf1, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3) +static void do_cross_effect(SeqRenderData context, Sequence *UNUSED(seq), float UNUSED(cfra), + float facf0, float facf1, ImBuf *ibuf1, ImBuf *ibuf2, ImBuf *UNUSED(ibuf3), + int start_line, int total_lines, ImBuf *out) { - struct ImBuf *out = prepare_effect_imbufs( - context, ibuf1, ibuf2, ibuf3); - if (out->rect_float) { - do_cross_effect_float( - facf0, facf1, context.rectx, context.recty, - ibuf1->rect_float, ibuf2->rect_float, - out->rect_float); + float *rect1, *rect2, *rect_out; + + slize_get_float_buffers(&context, ibuf1, ibuf2, NULL, out, start_line, &rect1, &rect2, NULL, &rect_out); + + do_cross_effect_float(facf0, facf1, context.rectx, total_lines, rect1, rect2, rect_out); } else { - do_cross_effect_byte( - facf0, facf1, context.rectx, context.recty, - (char *) ibuf1->rect, (char *) ibuf2->rect, - (char *) out->rect); + unsigned char *rect1, *rect2, *rect_out; + + slize_get_byte_buffers(&context, ibuf1, ibuf2, NULL, out, start_line, &rect1, &rect2, NULL, &rect_out); + + do_cross_effect_byte(facf0, facf1, context.rectx, total_lines, (char *) rect1, (char *) rect2, (char *) rect_out); } - return out; } - -/* ********************************************************************** - * GAMMA CROSS - * ********************************************************************** */ +/*********************** Gamma Cross *************************/ /* copied code from initrender.c */ static unsigned short gamtab[65536]; @@ -614,39 +595,36 @@ static void makeGammaTables(float gamma) /* we need two tables: one forward, one backward */ int i; - valid_gamma = gamma; - valid_inv_gamma = 1.0f / gamma; + valid_gamma = gamma; + valid_inv_gamma = 1.0f / gamma; color_step = 1.0f / RE_GAMMA_TABLE_SIZE; inv_color_step = (float) RE_GAMMA_TABLE_SIZE; - /* We could squeeze out the two range tables to gain some memory. */ + /* We could squeeze out the two range tables to gain some memory */ for (i = 0; i < RE_GAMMA_TABLE_SIZE; i++) { - color_domain_table[i] = i * color_step; - gamma_range_table[i] = pow(color_domain_table[i], - valid_gamma); - inv_gamma_range_table[i] = pow(color_domain_table[i], - valid_inv_gamma); - } - - /* The end of the table should match 1.0 carefully. In order to avoid */ - /* rounding errors, we just set this explicitly. The last segment may */ - /* have a different length than the other segments, but our */ - /* interpolation is insensitive to that. */ - color_domain_table[RE_GAMMA_TABLE_SIZE] = 1.0; + color_domain_table[i] = i * color_step; + gamma_range_table[i] = pow(color_domain_table[i], valid_gamma); + inv_gamma_range_table[i] = pow(color_domain_table[i], valid_inv_gamma); + } + + /* The end of the table should match 1.0 carefully. In order to avoid + * rounding errors, we just set this explicitly. The last segment may + * have a different length than the other segments, but our + * interpolation is insensitive to that + */ + color_domain_table[RE_GAMMA_TABLE_SIZE] = 1.0; gamma_range_table[RE_GAMMA_TABLE_SIZE] = 1.0; inv_gamma_range_table[RE_GAMMA_TABLE_SIZE] = 1.0; - /* To speed up calculations, we make these calc factor tables. They are */ - /* multiplication factors used in scaling the interpolation. */ + /* To speed up calculations, we make these calc factor tables. They are + * multiplication factors used in scaling the interpolation + */ for (i = 0; i < RE_GAMMA_TABLE_SIZE; i++) { - gamfactor_table[i] = inv_color_step * - (gamma_range_table[i + 1] - gamma_range_table[i]); - inv_gamfactor_table[i] = inv_color_step * - (inv_gamma_range_table[i + 1] - inv_gamma_range_table[i]); + gamfactor_table[i] = inv_color_step * (gamma_range_table[i + 1] - gamma_range_table[i]); + inv_gamfactor_table[i] = inv_color_step * (inv_gamma_range_table[i + 1] - inv_gamma_range_table[i]); } -} /* end of void makeGammaTables(float gamma) */ - +} static float gammaCorrect(float c) { @@ -654,17 +632,17 @@ static float gammaCorrect(float c) float res = 0.0; i = floor(c * inv_color_step); - /* Clip to range [0, 1]: outside, just do the complete calculation. */ - /* We may have some performance problems here. Stretching up the LUT */ - /* may help solve that, by exchanging LUT size for the interpolation. */ - /* Negative colors are explicitly handled. */ + /* Clip to range [0, 1]: outside, just do the complete calculation. + * We may have some performance problems here. Stretching up the LUT + * may help solve that, by exchanging LUT size for the interpolation. + * Negative colors are explicitly handled. + */ if (i < 0) res = -pow(abs(c), valid_gamma); else if (i >= RE_GAMMA_TABLE_SIZE) res = pow(c, valid_gamma); - else res = gamma_range_table[i] + - ( (c - color_domain_table[i]) * gamfactor_table[i]); + else res = gamma_range_table[i] + ( (c - color_domain_table[i]) * gamfactor_table[i]); return res; -} /* end of float gammaCorrect(float col) */ +} /* ------------------------------------------------------------------------- */ @@ -674,15 +652,13 @@ static float invGammaCorrect(float col) float res = 0.0; i = floor(col * inv_color_step); - /* Negative colors are explicitly handled. */ + /* Negative colors are explicitly handled */ if (i < 0) res = -pow(abs(col), valid_inv_gamma); else if (i >= RE_GAMMA_TABLE_SIZE) res = pow(col, valid_inv_gamma); - else res = inv_gamma_range_table[i] + - ( (col - color_domain_table[i]) * inv_gamfactor_table[i]); + else res = inv_gamma_range_table[i] + ( (col - color_domain_table[i]) * inv_gamfactor_table[i]); return res; -} /* end of float invGammaCorrect(float col) */ - +} static void gamtabs(float gamma) { @@ -708,7 +684,6 @@ static void gamtabs(float gamma) igamtab1[a - 1] = (65535.0 * pow(val, gamma)) - 1; } } - } static void build_gammatabs(void) @@ -732,29 +707,24 @@ static void free_gammacross(Sequence *UNUSED(seq)) { } -static void do_gammacross_effect_byte(float facf0, float UNUSED(facf1), - int x, int y, - unsigned char *rect1, - unsigned char *rect2, - unsigned char *out) +static void do_gammacross_effect_byte(float facf0, float UNUSED(facf1), int x, int y, unsigned char *rect1, + unsigned char *rect2, unsigned char *out) { int fac1, fac2, col; int xo; unsigned char *rt1, *rt2, *rt; xo = x; - rt1 = (unsigned char *)rect1; - rt2 = (unsigned char *)rect2; - rt = (unsigned char *)out; + rt1 = (unsigned char *) rect1; + rt2 = (unsigned char *) rect2; + rt = (unsigned char *) out; fac2 = (int)(256.0f * facf0); fac1 = 256 - fac2; while (y--) { - x = xo; while (x--) { - col = (fac1 * igamtab1[rt1[0]] + fac2 * igamtab1[rt2[0]]) >> 8; if (col > 65535) rt[0] = 255; else rt[0] = ( (char *)(gamtab + col))[MOST_SIG_BYTE]; col = (fac1 * igamtab1[rt1[1]] + fac2 * igamtab1[rt2[1]]) >> 8; @@ -767,12 +737,12 @@ static void do_gammacross_effect_byte(float facf0, float UNUSED(facf1), rt1 += 4; rt2 += 4; rt += 4; } - if (y == 0) break; + if (y == 0) + break; y--; x = xo; while (x--) { - col = (fac1 * igamtab1[rt1[0]] + fac2 * igamtab1[rt2[0]]) >> 8; if (col > 65535) rt[0] = 255; else rt[0] = ( (char *)(gamtab + col))[MOST_SIG_BYTE]; col = (fac1 * igamtab1[rt1[1]] + fac2 * igamtab1[rt2[1]]) >> 8; @@ -785,13 +755,10 @@ static void do_gammacross_effect_byte(float facf0, float UNUSED(facf1), rt1 += 4; rt2 += 4; rt += 4; } } - } -static void do_gammacross_effect_float(float facf0, float UNUSED(facf1), - int x, int y, - float *rect1, float *rect2, - float *out) +static void do_gammacross_effect_float(float facf0, float UNUSED(facf1), int x, int y, float *rect1, + float *rect2, float *out) { float fac1, fac2; int xo; @@ -806,62 +773,56 @@ static void do_gammacross_effect_float(float facf0, float UNUSED(facf1), fac1 = 1.0f - fac2; while (y--) { - x = xo * 4; while (x--) { - - *rt = gammaCorrect( - fac1 * invGammaCorrect(*rt1) + fac2 * invGammaCorrect(*rt2)); + *rt = gammaCorrect(fac1 * invGammaCorrect(*rt1) + fac2 * invGammaCorrect(*rt2)); rt1++; rt2++; rt++; } - if (y == 0) break; + if (y == 0) + break; y--; x = xo * 4; while (x--) { - - *rt = gammaCorrect( - fac1 * invGammaCorrect(*rt1) + fac2 * invGammaCorrect(*rt2)); + *rt = gammaCorrect(fac1 * invGammaCorrect(*rt1) + fac2 * invGammaCorrect(*rt2)); rt1++; rt2++; rt++; } } } -static ImBuf *do_gammacross_effect( - SeqRenderData context, - Sequence *UNUSED(seq), float UNUSED(cfra), - float facf0, float facf1, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3) +static struct ImBuf *gammacross_init_execution(SeqRenderData context, ImBuf *ibuf1, ImBuf *ibuf2, ImBuf *ibuf3) { - struct ImBuf *out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); - + ImBuf *out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); build_gammatabs(); + return out; +} + +static void do_gammacross_effect(SeqRenderData context, Sequence *UNUSED(seq), float UNUSED(cfra), + float facf0, float facf1, ImBuf *ibuf1, ImBuf *ibuf2, ImBuf *UNUSED(ibuf3), + int start_line, int total_lines, ImBuf *out) +{ if (out->rect_float) { - do_gammacross_effect_float( - facf0, facf1, context.rectx, context.recty, - ibuf1->rect_float, ibuf2->rect_float, - out->rect_float); + float *rect1, *rect2, *rect_out; + + slize_get_float_buffers(&context, ibuf1, ibuf2, NULL, out, start_line, &rect1, &rect2, NULL, &rect_out); + + do_gammacross_effect_float(facf0, facf1, context.rectx, total_lines, rect1, rect2, rect_out); } else { - do_gammacross_effect_byte( - facf0, facf1, context.rectx, context.recty, - (unsigned char *) ibuf1->rect, (unsigned char *) ibuf2->rect, - (unsigned char *) out->rect); + unsigned char *rect1, *rect2, *rect_out; + + slize_get_byte_buffers(&context, ibuf1, ibuf2, NULL, out, start_line, &rect1, &rect2, NULL, &rect_out); + + do_gammacross_effect_byte(facf0, facf1, context.rectx, total_lines, rect1, rect2, rect_out); } - return out; } +/*********************** Add *************************/ -/* ********************************************************************** - * ADD - * ********************************************************************** */ - -static void do_add_effect_byte(float facf0, float facf1, int x, int y, - unsigned char *rect1, unsigned char *rect2, +static void do_add_effect_byte(float facf0, float facf1, int x, int y, unsigned char *rect1, unsigned char *rect2, unsigned char *out) { int col, xo, fac1, fac3; @@ -876,10 +837,9 @@ static void do_add_effect_byte(float facf0, float facf1, int x, int y, fac3 = (int)(256.0f * facf1); while (y--) { - x = xo; - while (x--) { + while (x--) { col = rt1[0] + ((fac1 * rt2[0]) >> 8); if (col > 255) rt[0] = 255; else rt[0] = col; col = rt1[1] + ((fac1 * rt2[1]) >> 8); @@ -892,12 +852,12 @@ static void do_add_effect_byte(float facf0, float facf1, int x, int y, rt1 += 4; rt2 += 4; rt += 4; } - if (y == 0) break; + if (y == 0) + break; y--; x = xo; while (x--) { - col = rt1[0] + ((fac3 * rt2[0]) >> 8); if (col > 255) rt[0] = 255; else rt[0] = col; col = rt1[1] + ((fac3 * rt2[1]) >> 8); @@ -912,9 +872,7 @@ static void do_add_effect_byte(float facf0, float facf1, int x, int y, } } -static void do_add_effect_float(float facf0, float facf1, int x, int y, - float *rect1, float *rect2, - float *out) +static void do_add_effect_float(float facf0, float facf1, int x, int y, float *rect1, float *rect2, float *out) { int xo; float fac1, fac3; @@ -929,7 +887,6 @@ static void do_add_effect_float(float facf0, float facf1, int x, int y, fac3 = facf1; while (y--) { - x = xo * 4; while (x--) { *rt = *rt1 + fac1 * (*rt2); @@ -937,7 +894,8 @@ static void do_add_effect_float(float facf0, float facf1, int x, int y, rt1++; rt2++; rt++; } - if (y == 0) break; + if (y == 0) + break; y--; x = xo * 4; @@ -949,54 +907,43 @@ static void do_add_effect_float(float facf0, float facf1, int x, int y, } } -static ImBuf *do_add_effect(SeqRenderData context, - Sequence *UNUSED(seq), float UNUSED(cfra), - float facf0, float facf1, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3) +static void do_add_effect(SeqRenderData context, Sequence *UNUSED(seq), float UNUSED(cfra), float facf0, float facf1, + ImBuf *ibuf1, ImBuf *ibuf2, ImBuf *UNUSED(ibuf3), int start_line, int total_lines, ImBuf *out) { - struct ImBuf *out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); - if (out->rect_float) { - do_add_effect_float( - facf0, facf1, context.rectx, context.recty, - ibuf1->rect_float, ibuf2->rect_float, - out->rect_float); + float *rect1, *rect2, *rect_out; + + slize_get_float_buffers(&context, ibuf1, ibuf2, NULL, out, start_line, &rect1, &rect2, NULL, &rect_out); + + do_add_effect_float(facf0, facf1, context.rectx, total_lines, rect1, rect2, rect_out); } else { - do_add_effect_byte( - facf0, facf1, context.rectx, context.recty, - (unsigned char *) ibuf1->rect, (unsigned char *) ibuf2->rect, - (unsigned char *) out->rect); + unsigned char *rect1, *rect2, *rect_out; + + slize_get_byte_buffers(&context, ibuf1, ibuf2, NULL, out, start_line, &rect1, &rect2, NULL, &rect_out); + + do_add_effect_byte(facf0, facf1, context.rectx, total_lines, rect1, rect2, rect_out); } - return out; } +/*********************** Sub *************************/ -/* ********************************************************************** - * SUB - * ********************************************************************** */ - -static void do_sub_effect_byte(float facf0, float facf1, - int x, int y, - char *rect1, char *rect2, char *out) +static void do_sub_effect_byte(float facf0, float facf1, int x, int y, char *rect1, char *rect2, char *out) { int col, xo, fac1, fac3; char *rt1, *rt2, *rt; xo = x; - rt1 = (char *)rect1; - rt2 = (char *)rect2; - rt = (char *)out; + rt1 = (char *) rect1; + rt2 = (char *) rect2; + rt = (char *) out; - fac1 = (int)(256.0f * facf0); - fac3 = (int)(256.0f * facf1); + fac1 = (int) (256.0f * facf0); + fac3 = (int) (256.0f * facf1); while (y--) { - x = xo; while (x--) { - col = rt1[0] - ((fac1 * rt2[0]) >> 8); if (col < 0) rt[0] = 0; else rt[0] = col; col = rt1[1] - ((fac1 * rt2[1]) >> 8); @@ -1009,12 +956,12 @@ static void do_sub_effect_byte(float facf0, float facf1, rt1 += 4; rt2 += 4; rt += 4; } - if (y == 0) break; + if (y == 0) + break; y--; x = xo; while (x--) { - col = rt1[0] - ((fac3 * rt2[0]) >> 8); if (col < 0) rt[0] = 0; else rt[0] = col; col = rt1[1] - ((fac3 * rt2[1]) >> 8); @@ -1029,9 +976,7 @@ static void do_sub_effect_byte(float facf0, float facf1, } } -static void do_sub_effect_float(float facf0, float facf1, int x, int y, - float *rect1, float *rect2, - float *out) +static void do_sub_effect_float(float facf0, float facf1, int x, int y, float *rect1, float *rect2, float *out) { int xo; float fac1, fac3; @@ -1046,7 +991,6 @@ static void do_sub_effect_float(float facf0, float facf1, int x, int y, fac3 = facf1; while (y--) { - x = xo * 4; while (x--) { *rt = *rt1 - fac1 * (*rt2); @@ -1054,7 +998,8 @@ static void do_sub_effect_float(float facf0, float facf1, int x, int y, rt1++; rt2++; rt++; } - if (y == 0) break; + if (y == 0) + break; y--; x = xo * 4; @@ -1066,40 +1011,32 @@ static void do_sub_effect_float(float facf0, float facf1, int x, int y, } } -static ImBuf *do_sub_effect( - SeqRenderData context, Sequence *UNUSED(seq), float UNUSED(cfra), - float facf0, float facf1, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3) +static void do_sub_effect(SeqRenderData context, Sequence *UNUSED(seq), float UNUSED(cfra), float facf0, float facf1, + ImBuf *ibuf1, ImBuf *ibuf2, ImBuf *UNUSED(ibuf3), int start_line, int total_lines, ImBuf *out) { - struct ImBuf *out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); - if (out->rect_float) { - do_sub_effect_float( - facf0, facf1, context.rectx, context.recty, - ibuf1->rect_float, ibuf2->rect_float, - out->rect_float); + float *rect1, *rect2, *rect_out; + + slize_get_float_buffers(&context, ibuf1, ibuf2, NULL, out, start_line, &rect1, &rect2, NULL, &rect_out); + + do_sub_effect_float(facf0, facf1, context.rectx, total_lines, rect1, rect2, rect_out); } else { - do_sub_effect_byte( - facf0, facf1, context.rectx, context.recty, - (char *) ibuf1->rect, (char *) ibuf2->rect, - (char *) out->rect); + unsigned char *rect1, *rect2, *rect_out; + + slize_get_byte_buffers(&context, ibuf1, ibuf2, NULL, out, start_line, &rect1, &rect2, NULL, &rect_out); + + do_sub_effect_byte(facf0, facf1, context.rectx, total_lines, (char *) rect1, (char *) rect2, (char *) rect_out); } - return out; } -/* ********************************************************************** - * DROP - * ********************************************************************** */ +/*********************** Drop *************************/ /* Must be > 0 or add precopy, etc to the function */ #define XOFF 8 #define YOFF 8 -static void do_drop_effect_byte(float facf0, float facf1, int x, int y, - char *rect2i, char *rect1i, - char *outi) +static void do_drop_effect_byte(float facf0, float facf1, int x, int y, char *rect2i, char *rect1i, char *outi) { int height, width, temp, fac, fac1, fac2; char *rt1, *rt2, *out; @@ -1108,8 +1045,8 @@ static void do_drop_effect_byte(float facf0, float facf1, int x, int y, width = x; height = y; - fac1 = (int)(70.0f * facf0); - fac2 = (int)(70.0f * facf1); + fac1 = (int) (70.0f * facf0); + fac2 = (int) (70.0f * facf1); rt2 = (char *) (rect2i + YOFF * width); rt1 = (char *) rect1i; @@ -1137,9 +1074,7 @@ static void do_drop_effect_byte(float facf0, float facf1, int x, int y, memcpy(out, rt1, sizeof(int) * YOFF * width); } -static void do_drop_effect_float(float facf0, float facf1, int x, int y, - float *rect2i, float *rect1i, - float *outi) +static void do_drop_effect_float(float facf0, float facf1, int x, int y, float *rect2i, float *rect1i, float *outi) { int height, width; float temp, fac, fac1, fac2; @@ -1178,12 +1113,9 @@ static void do_drop_effect_float(float facf0, float facf1, int x, int y, memcpy(out, rt1, 4 * sizeof(float) * YOFF * width); } -/* ********************************************************************** - * MUL - * ********************************************************************** */ +/*********************** Mul *************************/ -static void do_mul_effect_byte(float facf0, float facf1, int x, int y, - unsigned char *rect1, unsigned char *rect2, +static void do_mul_effect_byte(float facf0, float facf1, int x, int y, unsigned char *rect1, unsigned char *rect2, unsigned char *out) { int xo, fac1, fac3; @@ -1231,9 +1163,7 @@ static void do_mul_effect_byte(float facf0, float facf1, int x, int y, } } -static void do_mul_effect_float(float facf0, float facf1, int x, int y, - float *rect1, float *rect2, - float *out) +static void do_mul_effect_float(float facf0, float facf1, int x, int y, float *rect1, float *rect2, float *out) { int xo; float fac1, fac3; @@ -1252,10 +1182,8 @@ static void do_mul_effect_float(float facf0, float facf1, int x, int y, */ while (y--) { - x = xo; while (x--) { - rt[0] = rt1[0] + fac1 * rt1[0] * (rt2[0] - 1.0f); rt[1] = rt1[1] + fac1 * rt1[1] * (rt2[1] - 1.0f); rt[2] = rt1[2] + fac1 * rt1[2] * (rt2[2] - 1.0f); @@ -1264,12 +1192,12 @@ static void do_mul_effect_float(float facf0, float facf1, int x, int y, rt1 += 4; rt2 += 4; rt += 4; } - if (y == 0) break; + if (y == 0) + break; y--; x = xo; while (x--) { - rt[0] = rt1[0] + fac3 * rt1[0] * (rt2[0] - 1.0f); rt[1] = rt1[1] + fac3 * rt1[1] * (rt2[1] - 1.0f); rt[2] = rt1[2] + fac3 * rt1[2] * (rt2[2] - 1.0f); @@ -1280,33 +1208,26 @@ static void do_mul_effect_float(float facf0, float facf1, int x, int y, } } -static ImBuf *do_mul_effect( - SeqRenderData context, Sequence *UNUSED(seq), float UNUSED(cfra), - float facf0, float facf1, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3) +static void do_mul_effect(SeqRenderData context, Sequence *UNUSED(seq), float UNUSED(cfra), float facf0, float facf1, + ImBuf *ibuf1, ImBuf *ibuf2, ImBuf *UNUSED(ibuf3), int start_line, int total_lines, ImBuf *out) { - struct ImBuf *out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); - if (out->rect_float) { - do_mul_effect_float( - facf0, facf1, context.rectx, context.recty, - ibuf1->rect_float, ibuf2->rect_float, - out->rect_float); + float *rect1, *rect2, *rect_out; + + slize_get_float_buffers(&context, ibuf1, ibuf2, NULL, out, start_line, &rect1, &rect2, NULL, &rect_out); + + do_mul_effect_float(facf0, facf1, context.rectx, total_lines, rect1, rect2, rect_out); } else { - do_mul_effect_byte( - facf0, facf1, context.rectx, context.recty, - (unsigned char *) ibuf1->rect, (unsigned char *) ibuf2->rect, - (unsigned char *) out->rect); - } + unsigned char *rect1, *rect2, *rect_out; - return out; + slize_get_byte_buffers(&context, ibuf1, ibuf2, NULL, out, start_line, &rect1, &rect2, NULL, &rect_out); + + do_mul_effect_byte(facf0, facf1, context.rectx, total_lines, rect1, rect2, rect_out); + } } -/* ********************************************************************** - * WIPE - * ********************************************************************** */ +/*********************** Wipe *************************/ typedef struct WipeZone { float angle; @@ -1326,7 +1247,7 @@ static void precalc_wipe_zone(WipeZone *wipezone, WipeVars *wipe, int xo, int yo wipezone->pythangle = 1.0f / sqrtf(wipezone->angle * wipezone->angle + 1.0f); } -// This function calculates the blur band for the wipe effects +/* This function calculates the blur band for the wipe effects */ static float in_band(float width, float dist, int side, int dir) { float alpha; @@ -1348,13 +1269,12 @@ static float in_band(float width, float dist, int side, int dir) return alpha; } -static float check_zone(WipeZone *wipezone, int x, int y, - Sequence *seq, float facf0) +static float check_zone(WipeZone *wipezone, int x, int y, Sequence *seq, float facf0) { float posx, posy, hyp, hyp2, angle, hwidth, b1, b2, b3, pointdist; /* some future stuff */ - // float hyp3, hyp4, b4, b5 - float temp1, temp2, temp3, temp4; //some placeholder variables + /* float hyp3, hyp4, b4, b5 */ + float temp1, temp2, temp3, temp4; /* some placeholder variables */ int xo = wipezone->xo; int yo = wipezone->yo; float halfx = xo * 0.5f; @@ -1412,9 +1332,9 @@ static float check_zone(WipeZone *wipezone, int x, int y, case DO_DOUBLE_WIPE: if (!wipe->forward) - facf0 = 1.0f - facf0; // Go the other direction + facf0 = 1.0f - facf0; /* Go the other direction */ - width = wipezone->width; // calculate the blur width + width = wipezone->width; /* calculate the blur width */ hwidth = width * 0.5f; if (angle == 0) { b1 = posy * 0.5f; @@ -1586,8 +1506,10 @@ static float check_zone(WipeZone *wipezone, int x, int y, static void init_wipe_effect(Sequence *seq) { - if (seq->effectdata) MEM_freeN(seq->effectdata); - seq->effectdata = MEM_callocN(sizeof(struct WipeVars), "wipevars"); + if (seq->effectdata) + MEM_freeN(seq->effectdata); + + seq->effectdata = MEM_callocN(sizeof(WipeVars), "wipevars"); } static int num_inputs_wipe(void) @@ -1597,7 +1519,9 @@ static int num_inputs_wipe(void) static void free_wipe_effect(Sequence *seq) { - if (seq->effectdata) MEM_freeN(seq->effectdata); + if (seq->effectdata) + MEM_freeN(seq->effectdata); + seq->effectdata = NULL; } @@ -1606,9 +1530,7 @@ static void copy_wipe_effect(Sequence *dst, Sequence *src) dst->effectdata = MEM_dupallocN(src->effectdata); } -static void do_wipe_effect_byte(Sequence *seq, float facf0, float UNUSED(facf1), - int x, int y, - unsigned char *rect1, +static void do_wipe_effect_byte(Sequence *seq, float facf0, float UNUSED(facf1), int x, int y, unsigned char *rect1, unsigned char *rect2, unsigned char *out) { WipeZone wipezone; @@ -1667,9 +1589,7 @@ static void do_wipe_effect_byte(Sequence *seq, float facf0, float UNUSED(facf1), } } -static void do_wipe_effect_float(Sequence *seq, float facf0, float UNUSED(facf1), - int x, int y, - float *rect1, +static void do_wipe_effect_float(Sequence *seq, float facf0, float UNUSED(facf1), int x, int y, float *rect1, float *rect2, float *out) { WipeZone wipezone; @@ -1728,40 +1648,35 @@ static void do_wipe_effect_float(Sequence *seq, float facf0, float UNUSED(facf1) } } -static ImBuf *do_wipe_effect( - SeqRenderData context, Sequence *seq, float UNUSED(cfra), - float facf0, float facf1, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3) +static ImBuf *do_wipe_effect(SeqRenderData context, Sequence *seq, float UNUSED(cfra), float facf0, float facf1, + ImBuf *ibuf1, ImBuf *ibuf2, ImBuf *ibuf3) { - struct ImBuf *out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); + ImBuf *out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); if (out->rect_float) { - do_wipe_effect_float(seq, - facf0, facf1, context.rectx, context.recty, - ibuf1->rect_float, ibuf2->rect_float, - out->rect_float); + do_wipe_effect_float(seq, facf0, facf1, context.rectx, context.recty, ibuf1->rect_float, + ibuf2->rect_float, out->rect_float); } else { - do_wipe_effect_byte(seq, - facf0, facf1, context.rectx, context.recty, - (unsigned char *) ibuf1->rect, (unsigned char *) ibuf2->rect, - (unsigned char *) out->rect); + do_wipe_effect_byte(seq, facf0, facf1, context.rectx, context.recty, (unsigned char *) ibuf1->rect, + (unsigned char *) ibuf2->rect, (unsigned char *) out->rect); } return out; } -/* ********************************************************************** - * TRANSFORM - * ********************************************************************** */ + +/*********************** Transform *************************/ + static void init_transform_effect(Sequence *seq) { TransformVars *transform; - if (seq->effectdata) MEM_freeN(seq->effectdata); - seq->effectdata = MEM_callocN(sizeof(struct TransformVars), "transformvars"); + if (seq->effectdata) + MEM_freeN(seq->effectdata); + + seq->effectdata = MEM_callocN(sizeof(TransformVars), "transformvars"); - transform = (TransformVars *)seq->effectdata; + transform = (TransformVars *) seq->effectdata; transform->ScalexIni = 1.0f; transform->ScaleyIni = 1.0f; @@ -1792,9 +1707,8 @@ static void copy_transform_effect(Sequence *dst, Sequence *src) dst->effectdata = MEM_dupallocN(src->effectdata); } -static void transform_image(int x, int y, struct ImBuf *ibuf1, struct ImBuf *out, - float scale_x, float scale_y, float translate_x, float translate_y, - float rotate, int interpolation) +static void transform_image(int x, int y, ImBuf *ibuf1, ImBuf *out, float scale_x, float scale_y, + float translate_x, float translate_y, float rotate, int interpolation) { int xo, yo, xi, yi; float xt, yt, xr, yr; @@ -1803,30 +1717,29 @@ static void transform_image(int x, int y, struct ImBuf *ibuf1, struct ImBuf *out xo = x; yo = y; - // Rotate + /* Rotate */ s = sin(rotate); c = cos(rotate); for (yi = 0; yi < yo; yi++) { for (xi = 0; xi < xo; xi++) { - - //translate point + /* translate point */ xt = xi - translate_x; yt = yi - translate_y; - //rotate point with center ref + /* rotate point with center ref */ xr = c * xt + s * yt; yr = -s * xt + c * yt; - //scale point with center ref + /* scale point with center ref */ xt = xr / scale_x; yt = yr / scale_y; - //undo reference center point + /* undo reference center point */ xt += (xo / 2.0f); yt += (yo / 2.0f); - //interpolate + /* interpolate */ switch (interpolation) { case 0: neareast_interpolation(ibuf1, out, xt, yt, xi, yi); @@ -1842,10 +1755,9 @@ static void transform_image(int x, int y, struct ImBuf *ibuf1, struct ImBuf *out } } -static void do_transform(Scene *scene, Sequence *seq, float UNUSED(facf0), int x, int y, - struct ImBuf *ibuf1, struct ImBuf *out) +static void do_transform(Scene *scene, Sequence *seq, float UNUSED(facf0), int x, int y, ImBuf *ibuf1, ImBuf *out) { - TransformVars *transform = (TransformVars *)seq->effectdata; + TransformVars *transform = (TransformVars *) seq->effectdata; float scale_x, scale_y, translate_x, translate_y, rotate_radians; /* Scale */ @@ -1876,28 +1788,19 @@ static void do_transform(Scene *scene, Sequence *seq, float UNUSED(facf0), int x } -static ImBuf *do_transform_effect( - SeqRenderData context, Sequence *seq, float UNUSED(cfra), - float facf0, float UNUSED(facf1), - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3) +static ImBuf *do_transform_effect(SeqRenderData context, Sequence *seq, float UNUSED(cfra), float facf0, + float UNUSED(facf1), ImBuf *ibuf1, ImBuf *ibuf2, ImBuf *ibuf3) { - struct ImBuf *out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); + ImBuf *out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); - do_transform(context.scene, seq, facf0, - context.rectx, context.recty, ibuf1, out); + do_transform(context.scene, seq, facf0, context.rectx, context.recty, ibuf1, out); return out; } +/*********************** Glow *************************/ -/* ********************************************************************** - * GLOW - * ********************************************************************** */ - -static void RVBlurBitmap2_byte(unsigned char *map, int width, int height, - float blur, - int quality) +static void RVBlurBitmap2_byte(unsigned char *map, int width, int height, float blur, int quality) /* MUUUCCH better than the previous blur. */ /* We do the blurring in two passes which is a whole lot faster. */ /* I changed the math arount to implement an actual Gaussian */ @@ -1913,16 +1816,16 @@ static void RVBlurBitmap2_byte(unsigned char *map, int width, int height, int index, ix, halfWidth; float fval, k, curColor[3], curColor2[3], weight = 0; - /* If we're not really blurring, bail out */ + /* If we're not really blurring, bail out */ if (blur <= 0) return; - /* Allocate memory for the tempmap and the blur filter matrix */ + /*Allocate memory for the tempmap and the blur filter matrix */ temp = MEM_mallocN((width * height * 4), "blurbitmaptemp"); if (!temp) return; - /* Allocate memory for the filter elements */ + /*Allocate memory for the filter elements */ halfWidth = ((quality + 1) * blur); filter = (float *)MEM_mallocN(sizeof(float) * halfWidth * 2, "blurbitmapfilter"); if (!filter) { @@ -1930,11 +1833,10 @@ static void RVBlurBitmap2_byte(unsigned char *map, int width, int height, return; } - /* Apparently we're calculating a bell curve */ - /* based on the standard deviation (or radius) */ - /* This code is based on an example */ - /* posted to comp.graphics.algorithms by */ - /* Blancmange (bmange@airdmhor.gen.nz) */ + /* Apparently we're calculating a bell curve based on the standard deviation (or radius) + * This code is based on an example posted to comp.graphics.algorithms by + * Blancmange (bmange@airdmhor.gen.nz) + */ k = -1.0f / (2.0f * (float)M_PI * blur * blur); for (ix = 0; ix < halfWidth; ix++) { @@ -1944,7 +1846,7 @@ static void RVBlurBitmap2_byte(unsigned char *map, int width, int height, } filter[0] = weight; - /* Normalize the array */ + /* Normalize the array */ fval = 0; for (ix = 0; ix < halfWidth * 2; ix++) fval += filter[ix]; @@ -1952,9 +1854,9 @@ static void RVBlurBitmap2_byte(unsigned char *map, int width, int height, for (ix = 0; ix < halfWidth * 2; ix++) filter[ix] /= fval; - /* Blur the rows */ + /* Blur the rows */ for (y = 0; y < height; y++) { - /* Do the left & right strips */ + /* Do the left & right strips */ for (x = 0; x < halfWidth; x++) { index = (x + y * width) * 4; fx = 0; @@ -1967,12 +1869,9 @@ static void RVBlurBitmap2_byte(unsigned char *map, int width, int height, curColor[1] += map[(i + y * width) * 4 + GlowG] * filter[fx]; curColor[2] += map[(i + y * width) * 4 + GlowB] * filter[fx]; - curColor2[0] += map[(width - 1 - i + y * width) * 4 + GlowR] * - filter[fx]; - curColor2[1] += map[(width - 1 - i + y * width) * 4 + GlowG] * - filter[fx]; - curColor2[2] += map[(width - 1 - i + y * width) * 4 + GlowB] * - filter[fx]; + curColor2[0] += map[(width - 1 - i + y * width) * 4 + GlowR] * filter[fx]; + curColor2[1] += map[(width - 1 - i + y * width) * 4 + GlowG] * filter[fx]; + curColor2[2] += map[(width - 1 - i + y * width) * 4 + GlowB] * filter[fx]; } fx++; } @@ -1985,7 +1884,8 @@ static void RVBlurBitmap2_byte(unsigned char *map, int width, int height, temp[((width - 1 - x + y * width) * 4) + GlowB] = curColor2[2]; } - /* Do the main body */ + + /* Do the main body */ for (x = halfWidth; x < width - halfWidth; x++) { index = (x + y * width) * 4; fx = 0; @@ -2002,13 +1902,12 @@ static void RVBlurBitmap2_byte(unsigned char *map, int width, int height, } } - /* Swap buffers */ + /* Swap buffers */ swap = temp; temp = map; map = swap; - - /* Blur the columns */ + /* Blur the columns */ for (x = 0; x < width; x++) { - /* Do the top & bottom strips */ + /* Do the top & bottom strips */ for (y = 0; y < halfWidth; y++) { index = (x + y * width) * 4; fy = 0; @@ -2016,18 +1915,15 @@ static void RVBlurBitmap2_byte(unsigned char *map, int width, int height, zero_v3(curColor2); for (i = y - halfWidth; i < y + halfWidth; i++) { if ((i >= 0) && (i < height)) { - /* Bottom */ + /* Bottom */ curColor[0] += map[(x + i * width) * 4 + GlowR] * filter[fy]; curColor[1] += map[(x + i * width) * 4 + GlowG] * filter[fy]; curColor[2] += map[(x + i * width) * 4 + GlowB] * filter[fy]; - /* Top */ - curColor2[0] += map[(x + (height - 1 - i) * width) * - 4 + GlowR] * filter[fy]; - curColor2[1] += map[(x + (height - 1 - i) * width) * - 4 + GlowG] * filter[fy]; - curColor2[2] += map[(x + (height - 1 - i) * width) * - 4 + GlowB] * filter[fy]; + /* Top */ + curColor2[0] += map[(x + (height - 1 - i) * width) * 4 + GlowR] * filter[fy]; + curColor2[1] += map[(x + (height - 1 - i) * width) * 4 + GlowG] * filter[fy]; + curColor2[2] += map[(x + (height - 1 - i) * width) * 4 + GlowB] * filter[fy]; } fy++; } @@ -2038,7 +1934,8 @@ static void RVBlurBitmap2_byte(unsigned char *map, int width, int height, temp[((x + (height - 1 - y) * width) * 4) + GlowG] = curColor2[1]; temp[((x + (height - 1 - y) * width) * 4) + GlowB] = curColor2[2]; } - /* Do the main body */ + + /* Do the main body */ for (y = halfWidth; y < height - halfWidth; y++) { index = (x + y * width) * 4; fy = 0; @@ -2055,18 +1952,15 @@ static void RVBlurBitmap2_byte(unsigned char *map, int width, int height, } } - - /* Swap buffers */ + /* Swap buffers */ swap = temp; temp = map; /* map = swap; */ /* UNUSED */ - /* Tidy up */ + /* Tidy up */ MEM_freeN(filter); MEM_freeN(temp); } -static void RVBlurBitmap2_float(float *map, int width, int height, - float blur, - int quality) +static void RVBlurBitmap2_float(float *map, int width, int height, float blur, int quality) /* MUUUCCH better than the previous blur. */ /* We do the blurring in two passes which is a whole lot faster. */ /* I changed the math arount to implement an actual Gaussian */ @@ -2077,21 +1971,21 @@ static void RVBlurBitmap2_float(float *map, int width, int height, /*=============================== */ { float *temp = NULL, *swap; - float *filter = NULL; + float *filter = NULL; int x, y, i, fx, fy; int index, ix, halfWidth; float fval, k, curColor[3], curColor2[3], weight = 0; - /* If we're not really blurring, bail out */ + /* If we're not really blurring, bail out */ if (blur <= 0) return; - /* Allocate memory for the tempmap and the blur filter matrix */ + /* Allocate memory for the tempmap and the blur filter matrix */ temp = MEM_mallocN((width * height * 4 * sizeof(float)), "blurbitmaptemp"); if (!temp) return; - /* Allocate memory for the filter elements */ + /* Allocate memory for the filter elements */ halfWidth = ((quality + 1) * blur); filter = (float *)MEM_mallocN(sizeof(float) * halfWidth * 2, "blurbitmapfilter"); if (!filter) { @@ -2099,11 +1993,10 @@ static void RVBlurBitmap2_float(float *map, int width, int height, return; } - /* Apparently we're calculating a bell curve */ - /* based on the standard deviation (or radius) */ - /* This code is based on an example */ - /* posted to comp.graphics.algorithms by */ - /* Blancmange (bmange@airdmhor.gen.nz) */ + /* Apparently we're calculating a bell curve based on the standard deviation (or radius) + * This code is based on an example posted to comp.graphics.algorithms by + * Blancmange (bmange@airdmhor.gen.nz) + */ k = -1.0f / (2.0f * (float)M_PI * blur * blur); @@ -2114,7 +2007,7 @@ static void RVBlurBitmap2_float(float *map, int width, int height, } filter[0] = weight; - /* Normalize the array */ + /* Normalize the array */ fval = 0; for (ix = 0; ix < halfWidth * 2; ix++) fval += filter[ix]; @@ -2122,9 +2015,9 @@ static void RVBlurBitmap2_float(float *map, int width, int height, for (ix = 0; ix < halfWidth * 2; ix++) filter[ix] /= fval; - /* Blur the rows */ + /* Blur the rows */ for (y = 0; y < height; y++) { - /* Do the left & right strips */ + /* Do the left & right strips */ for (x = 0; x < halfWidth; x++) { index = (x + y * width) * 4; fx = 0; @@ -2137,12 +2030,9 @@ static void RVBlurBitmap2_float(float *map, int width, int height, curColor[1] += map[(i + y * width) * 4 + GlowG] * filter[fx]; curColor[2] += map[(i + y * width) * 4 + GlowB] * filter[fx]; - curColor2[0] += map[(width - 1 - i + y * width) * 4 + GlowR] * - filter[fx]; - curColor2[1] += map[(width - 1 - i + y * width) * 4 + GlowG] * - filter[fx]; - curColor2[2] += map[(width - 1 - i + y * width) * 4 + GlowB] * - filter[fx]; + curColor2[0] += map[(width - 1 - i + y * width) * 4 + GlowR] * filter[fx]; + curColor2[1] += map[(width - 1 - i + y * width) * 4 + GlowG] * filter[fx]; + curColor2[2] += map[(width - 1 - i + y * width) * 4 + GlowB] * filter[fx]; } fx++; } @@ -2155,7 +2045,8 @@ static void RVBlurBitmap2_float(float *map, int width, int height, temp[((width - 1 - x + y * width) * 4) + GlowB] = curColor2[2]; } - /* Do the main body */ + + /* Do the main body */ for (x = halfWidth; x < width - halfWidth; x++) { index = (x + y * width) * 4; fx = 0; @@ -2172,13 +2063,12 @@ static void RVBlurBitmap2_float(float *map, int width, int height, } } - /* Swap buffers */ + /* Swap buffers */ swap = temp; temp = map; map = swap; - - /* Blur the columns */ + /* Blur the columns */ for (x = 0; x < width; x++) { - /* Do the top & bottom strips */ + /* Do the top & bottom strips */ for (y = 0; y < halfWidth; y++) { index = (x + y * width) * 4; fy = 0; @@ -2186,18 +2076,15 @@ static void RVBlurBitmap2_float(float *map, int width, int height, zero_v3(curColor2); for (i = y - halfWidth; i < y + halfWidth; i++) { if ((i >= 0) && (i < height)) { - /* Bottom */ + /* Bottom */ curColor[0] += map[(x + i * width) * 4 + GlowR] * filter[fy]; curColor[1] += map[(x + i * width) * 4 + GlowG] * filter[fy]; curColor[2] += map[(x + i * width) * 4 + GlowB] * filter[fy]; - /* Top */ - curColor2[0] += map[(x + (height - 1 - i) * width) * - 4 + GlowR] * filter[fy]; - curColor2[1] += map[(x + (height - 1 - i) * width) * - 4 + GlowG] * filter[fy]; - curColor2[2] += map[(x + (height - 1 - i) * width) * - 4 + GlowB] * filter[fy]; + /* Top */ + curColor2[0] += map[(x + (height - 1 - i) * width) * 4 + GlowR] * filter[fy]; + curColor2[1] += map[(x + (height - 1 - i) * width) * 4 + GlowG] * filter[fy]; + curColor2[2] += map[(x + (height - 1 - i) * width) * 4 + GlowB] * filter[fy]; } fy++; } @@ -2208,7 +2095,8 @@ static void RVBlurBitmap2_float(float *map, int width, int height, temp[((x + (height - 1 - y) * width) * 4) + GlowG] = curColor2[1]; temp[((x + (height - 1 - y) * width) * 4) + GlowB] = curColor2[2]; } - /* Do the main body */ + + /* Do the main body */ for (y = halfWidth; y < height - halfWidth; y++) { index = (x + y * width) * 4; fy = 0; @@ -2225,11 +2113,10 @@ static void RVBlurBitmap2_float(float *map, int width, int height, } } - - /* Swap buffers */ + /* Swap buffers */ swap = temp; temp = map; /* map = swap; */ /* UNUSED */ - /* Tidy up */ + /* Tidy up */ MEM_freeN(filter); MEM_freeN(temp); } @@ -2254,8 +2141,7 @@ static void RVAddBitmaps_byte(unsigned char *a, unsigned char *b, unsigned char } } -static void RVAddBitmaps_float(float *a, float *b, float *c, - int width, int height) +static void RVAddBitmaps_float(float *a, float *b, float *c, int width, int height) { int x, y, index; @@ -2270,21 +2156,20 @@ static void RVAddBitmaps_float(float *a, float *b, float *c, } } -/* For each pixel whose total luminance exceeds the threshold, */ -/* Multiply it's value by BOOST and add it to the output map */ -static void RVIsolateHighlights_byte(unsigned char *in, unsigned char *out, - int width, int height, int threshold, +/* For each pixel whose total luminance exceeds the threshold, + * Multiply it's value by BOOST and add it to the output map + */ +static void RVIsolateHighlights_byte(unsigned char *in, unsigned char *out, int width, int height, int threshold, float boost, float clamp) { int x, y, index; int intensity; - for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { index = (x + y * width) * 4; - /* Isolate the intensity */ + /* Isolate the intensity */ intensity = (in[index + GlowR] + in[index + GlowG] + in[index + GlowB] - threshold); if (intensity > 0) { out[index + GlowR] = MIN2(255 * clamp, (in[index + GlowR] * boost * intensity) / 255); @@ -2302,19 +2187,16 @@ static void RVIsolateHighlights_byte(unsigned char *in, unsigned char *out, } } -static void RVIsolateHighlights_float(float *in, float *out, - int width, int height, float threshold, - float boost, float clamp) +static void RVIsolateHighlights_float(float *in, float *out, int width, int height, float threshold, float boost, float clamp) { int x, y, index; float intensity; - for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { index = (x + y * width) * 4; - /* Isolate the intensity */ + /* Isolate the intensity */ intensity = (in[index + GlowR] + in[index + GlowG] + in[index + GlowB] - threshold); if (intensity > 0) { out[index + GlowR] = MIN2(clamp, (in[index + GlowR] * boost * intensity)); @@ -2336,8 +2218,10 @@ static void init_glow_effect(Sequence *seq) { GlowVars *glow; - if (seq->effectdata) MEM_freeN(seq->effectdata); - seq->effectdata = MEM_callocN(sizeof(struct GlowVars), "glowvars"); + if (seq->effectdata) + MEM_freeN(seq->effectdata); + + seq->effectdata = MEM_callocN(sizeof(GlowVars), "glowvars"); glow = (GlowVars *)seq->effectdata; glow->fMini = 0.25; @@ -2355,7 +2239,9 @@ static int num_inputs_glow(void) static void free_glow_effect(Sequence *seq) { - if (seq->effectdata) MEM_freeN(seq->effectdata); + if (seq->effectdata) + MEM_freeN(seq->effectdata); + seq->effectdata = NULL; } @@ -2364,10 +2250,8 @@ static void copy_glow_effect(Sequence *dst, Sequence *src) dst->effectdata = MEM_dupallocN(src->effectdata); } -//void do_glow_effect(Cast *cast, float facf0, float facf1, int xo, int yo, ImBuf *ibuf1, ImBuf *ibuf2, ImBuf *outbuf, ImBuf *use) -static void do_glow_effect_byte(Sequence *seq, int render_size, float facf0, float UNUSED(facf1), - int x, int y, char *rect1, - char *UNUSED(rect2), char *out) +static void do_glow_effect_byte(Sequence *seq, int render_size, float facf0, float UNUSED(facf1), int x, int y, + char *rect1, char *UNUSED(rect2), char *out) { unsigned char *outbuf = (unsigned char *)out; unsigned char *inbuf = (unsigned char *)rect1; @@ -2379,8 +2263,7 @@ static void do_glow_effect_byte(Sequence *seq, int render_size, float facf0, flo RVAddBitmaps_byte(inbuf, outbuf, outbuf, x, y); } -static void do_glow_effect_float(Sequence *seq, int render_size, float facf0, float UNUSED(facf1), - int x, int y, +static void do_glow_effect_float(Sequence *seq, int render_size, float facf0, float UNUSED(facf1), int x, int y, float *rect1, float *UNUSED(rect2), float *out) { float *outbuf = out; @@ -2393,44 +2276,35 @@ static void do_glow_effect_float(Sequence *seq, int render_size, float facf0, fl RVAddBitmaps_float(inbuf, outbuf, outbuf, x, y); } -static ImBuf *do_glow_effect( - SeqRenderData context, Sequence *seq, float UNUSED(cfra), - float facf0, float facf1, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3) +static ImBuf *do_glow_effect(SeqRenderData context, Sequence *seq, float UNUSED(cfra), float facf0, float facf1, + ImBuf *ibuf1, ImBuf *ibuf2, ImBuf *ibuf3) { - struct ImBuf *out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); + ImBuf *out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); int render_size = 100 * context.rectx / context.scene->r.xsch; if (out->rect_float) { - do_glow_effect_float(seq, render_size, - facf0, facf1, - context.rectx, context.recty, - ibuf1->rect_float, ibuf2->rect_float, - out->rect_float); + do_glow_effect_float(seq, render_size, facf0, facf1, context.rectx, context.recty, + ibuf1->rect_float, ibuf2->rect_float, out->rect_float); } else { - do_glow_effect_byte(seq, render_size, - facf0, facf1, - context.rectx, context.recty, - (char *) ibuf1->rect, (char *) ibuf2->rect, - (char *) out->rect); + do_glow_effect_byte(seq, render_size, facf0, facf1, context.rectx, context.recty, + (char *) ibuf1->rect, (char *) ibuf2->rect, (char *) out->rect); } return out; } -/* ********************************************************************** - * SOLID COLOR - * ********************************************************************** */ +/*********************** Solid color *************************/ static void init_solid_color(Sequence *seq) { SolidColorVars *cv; - if (seq->effectdata) MEM_freeN(seq->effectdata); - seq->effectdata = MEM_callocN(sizeof(struct SolidColorVars), "solidcolor"); + if (seq->effectdata) + MEM_freeN(seq->effectdata); + + seq->effectdata = MEM_callocN(sizeof(SolidColorVars), "solidcolor"); cv = (SolidColorVars *)seq->effectdata; cv->col[0] = cv->col[1] = cv->col[2] = 0.5; @@ -2443,7 +2317,9 @@ static int num_inputs_color(void) static void free_solid_color(Sequence *seq) { - if (seq->effectdata) MEM_freeN(seq->effectdata); + if (seq->effectdata) + MEM_freeN(seq->effectdata); + seq->effectdata = NULL; } @@ -2452,19 +2328,15 @@ static void copy_solid_color(Sequence *dst, Sequence *src) dst->effectdata = MEM_dupallocN(src->effectdata); } -static int early_out_color(struct Sequence *UNUSED(seq), - float UNUSED(facf0), float UNUSED(facf1)) +static int early_out_color(Sequence *UNUSED(seq), float UNUSED(facf0), float UNUSED(facf1)) { - return -1; + return EARLY_NO_INPUT; } -static ImBuf *do_solid_color( - SeqRenderData context, Sequence *seq, float UNUSED(cfra), - float facf0, float facf1, - struct ImBuf *ibuf1, struct ImBuf *ibuf2, - struct ImBuf *ibuf3) +static ImBuf *do_solid_color(SeqRenderData context, Sequence *seq, float UNUSED(cfra), float facf0, float facf1, + ImBuf *ibuf1, ImBuf *ibuf2, ImBuf *ibuf3) { - struct ImBuf *out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); + ImBuf *out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); SolidColorVars *cv = (SolidColorVars *)seq->effectdata; @@ -2541,9 +2413,7 @@ static ImBuf *do_solid_color( return out; } -/* ********************************************************************** - * MULTICAM - * ********************************************************************** */ +/*********************** Mulitcam *************************/ /* no effect inputs for multicam, we use give_ibuf_seq */ static int num_inputs_multicam(void) @@ -2551,19 +2421,16 @@ static int num_inputs_multicam(void) return 0; } -static int early_out_multicam(struct Sequence *UNUSED(seq), float UNUSED(facf0), float UNUSED(facf1)) +static int early_out_multicam(Sequence *UNUSED(seq), float UNUSED(facf0), float UNUSED(facf1)) { - return -1; + return EARLY_NO_INPUT; } -static ImBuf *do_multicam( - SeqRenderData context, Sequence *seq, float cfra, - float UNUSED(facf0), float UNUSED(facf1), - struct ImBuf *UNUSED(ibuf1), struct ImBuf *UNUSED(ibuf2), - struct ImBuf *UNUSED(ibuf3)) +static ImBuf *do_multicam(SeqRenderData context, Sequence *seq, float cfra, float UNUSED(facf0), float UNUSED(facf1), + ImBuf *UNUSED(ibuf1), ImBuf *UNUSED(ibuf2), ImBuf *UNUSED(ibuf3)) { - struct ImBuf *i; - struct ImBuf *out; + ImBuf *i; + ImBuf *out; Editing *ed; ListBase *seqbasep; @@ -2575,17 +2442,17 @@ static ImBuf *do_multicam( if (!ed) { return NULL; } - seqbasep = seq_seqbase(&ed->seqbase, seq); + seqbasep = BKE_sequence_seqbase(&ed->seqbase, seq); if (!seqbasep) { return NULL; } - i = give_ibuf_seqbase(context, cfra, seq->multicam_source, seqbasep); + i = BKE_sequencer_give_ibuf_seqbase(context, cfra, seq->multicam_source, seqbasep); if (!i) { return NULL; } - if (input_have_to_preprocess(context, seq, cfra)) { + if (BKE_sequencer_input_have_to_preprocess(context, seq, cfra)) { out = IMB_dupImBuf(i); IMB_freeImBuf(i); } @@ -2596,9 +2463,7 @@ static ImBuf *do_multicam( return out; } -/* ********************************************************************** - * ADJUSTMENT - * ********************************************************************** */ +/*********************** Adjustment *************************/ /* no effect inputs for adjustment, we use give_ibuf_seq */ static int num_inputs_adjustment(void) @@ -2606,35 +2471,34 @@ static int num_inputs_adjustment(void) return 0; } -static int early_out_adjustment(struct Sequence *UNUSED(seq), float UNUSED(facf0), float UNUSED(facf1)) +static int early_out_adjustment(Sequence *UNUSED(seq), float UNUSED(facf0), float UNUSED(facf1)) { - return -1; + return EARLY_NO_INPUT; } static ImBuf *do_adjustment_impl(SeqRenderData context, Sequence *seq, float cfra) { Editing *ed; ListBase *seqbasep; - struct ImBuf *i = NULL; + ImBuf *i = NULL; ed = context.scene->ed; - seqbasep = seq_seqbase(&ed->seqbase, seq); + seqbasep = BKE_sequence_seqbase(&ed->seqbase, seq); - if (seq->machine > 0) { - i = give_ibuf_seqbase(context, cfra, - seq->machine - 1, seqbasep); + if (seq->machine > 1) { + i = BKE_sequencer_give_ibuf_seqbase(context, cfra, seq->machine - 1, seqbasep); } /* found nothing? so let's work the way up the metastrip stack, so - * that it is possible to group a bunch of adjustment strips into - * a metastrip and have that work on everything below the metastrip + * that it is possible to group a bunch of adjustment strips into + * a metastrip and have that work on everything below the metastrip */ if (!i) { Sequence *meta; - meta = seq_metastrip(&ed->seqbase, NULL, seq); + meta = BKE_sequence_metastrip(&ed->seqbase, NULL, seq); if (meta) { i = do_adjustment_impl(context, meta, cfra); @@ -2644,14 +2508,11 @@ static ImBuf *do_adjustment_impl(SeqRenderData context, Sequence *seq, float cfr return i; } -static ImBuf *do_adjustment( - SeqRenderData context, Sequence *seq, float cfra, - float UNUSED(facf0), float UNUSED(facf1), - struct ImBuf *UNUSED(ibuf1), struct ImBuf *UNUSED(ibuf2), - struct ImBuf *UNUSED(ibuf3)) +static ImBuf *do_adjustment(SeqRenderData context, Sequence *seq, float cfra, float UNUSED(facf0), float UNUSED(facf1), + ImBuf *UNUSED(ibuf1), ImBuf *UNUSED(ibuf2), ImBuf *UNUSED(ibuf3)) { - struct ImBuf *i = NULL; - struct ImBuf *out; + ImBuf *i = NULL; + ImBuf *out; Editing *ed; ed = context.scene->ed; @@ -2662,7 +2523,7 @@ static ImBuf *do_adjustment( i = do_adjustment_impl(context, seq, cfra); - if (input_have_to_preprocess(context, seq, cfra)) { + if (BKE_sequencer_input_have_to_preprocess(context, seq, cfra)) { out = IMB_dupImBuf(i); IMB_freeImBuf(i); } @@ -2673,16 +2534,16 @@ static ImBuf *do_adjustment( return out; } -/* ********************************************************************** - * SPEED - * ********************************************************************** */ +/*********************** Speed *************************/ + static void init_speed_effect(Sequence *seq) { SpeedControlVars *v; - if (seq->effectdata) MEM_freeN(seq->effectdata); - seq->effectdata = MEM_callocN(sizeof(struct SpeedControlVars), - "speedcontrolvars"); + if (seq->effectdata) + MEM_freeN(seq->effectdata); + + seq->effectdata = MEM_callocN(sizeof(SpeedControlVars), "speedcontrolvars"); v = (SpeedControlVars *)seq->effectdata; v->globalSpeed = 1.0; @@ -2707,8 +2568,10 @@ static int num_inputs_speed(void) static void free_speed_effect(Sequence *seq) { SpeedControlVars *v = (SpeedControlVars *)seq->effectdata; - if (v->frameMap) MEM_freeN(v->frameMap); - if (seq->effectdata) MEM_freeN(seq->effectdata); + if (v->frameMap) + MEM_freeN(v->frameMap); + if (seq->effectdata) + MEM_freeN(seq->effectdata); seq->effectdata = NULL; } @@ -2721,19 +2584,17 @@ static void copy_speed_effect(Sequence *dst, Sequence *src) v->length = 0; } -static int early_out_speed(struct Sequence *UNUSED(seq), - float UNUSED(facf0), float UNUSED(facf1)) +static int early_out_speed(Sequence *UNUSED(seq), float UNUSED(facf0), float UNUSED(facf1)) { - return 1; + return EARLY_USE_INPUT_1; } -static void store_icu_yrange_speed(struct Sequence *seq, - short UNUSED(adrcode), float *ymin, float *ymax) +static void store_icu_yrange_speed(Sequence *seq, short UNUSED(adrcode), float *ymin, float *ymax) { SpeedControlVars *v = (SpeedControlVars *)seq->effectdata; /* if not already done, load / initialize data */ - get_sequence_effect(seq); + BKE_sequence_get_effect(seq); if ((v->flags & SEQ_SPEED_INTEGRATE) != 0) { *ymin = -100.0; @@ -2750,16 +2611,17 @@ static void store_icu_yrange_speed(struct Sequence *seq, } } } -void sequence_effect_speed_rebuild_map(Scene *scene, Sequence *seq, int force) + +void BKE_sequence_effect_speed_rebuild_map(Scene *scene, Sequence *seq, int force) { int cfra; float fallback_fac = 1.0f; - SpeedControlVars *v = (SpeedControlVars *)seq->effectdata; + SpeedControlVars *v = (SpeedControlVars *) seq->effectdata; FCurve *fcu = NULL; int flags = v->flags; /* if not already done, load / initialize data */ - get_sequence_effect(seq); + BKE_sequence_get_effect(seq); if ((force == FALSE) && (seq->len == v->length) && @@ -2782,8 +2644,7 @@ void sequence_effect_speed_rebuild_map(Scene *scene, Sequence *seq, int force) v->length = seq->len; - v->frameMap = MEM_callocN(sizeof(float) * v->length, - "speedcontrol frameMap"); + v->frameMap = MEM_callocN(sizeof(float) * v->length, "speedcontrol frameMap"); } fallback_fac = 1.0; @@ -2792,8 +2653,7 @@ void sequence_effect_speed_rebuild_map(Scene *scene, Sequence *seq, int force) if ((seq->seq1->enddisp != seq->seq1->start) && (seq->seq1->len != 0)) { - fallback_fac = (float) seq->seq1->len / - (float) (seq->seq1->enddisp - seq->seq1->start); + fallback_fac = (float) seq->seq1->len / (float) (seq->seq1->enddisp - seq->seq1->start); flags = SEQ_SPEED_INTEGRATE; fcu = NULL; } @@ -2861,22 +2721,61 @@ void sequence_effect_speed_rebuild_map(Scene *scene, Sequence *seq, int force) } } -/* ********************************************************************** - * sequence effect factory - * ********************************************************************** */ +static ImBuf *do_speed_effect(SeqRenderData context, Sequence *UNUSED(seq), float UNUSED(cfra), + float facf0, float facf1, ImBuf *ibuf1, ImBuf *ibuf2, ImBuf *ibuf3) +{ + ImBuf *out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); + if (out->rect_float) { + do_cross_effect_float(facf0, facf1, context.rectx, context.recty, + ibuf1->rect_float, ibuf2->rect_float, out->rect_float); + } + else { + do_cross_effect_byte(facf0, facf1, context.rectx, context.recty, + (char *) ibuf1->rect, (char *) ibuf2->rect, (char *) out->rect); + } + return out; +} + +/*********************** overdrop *************************/ -static void init_noop(struct Sequence *UNUSED(seq)) +static void do_overdrop_effect(SeqRenderData context, Sequence *UNUSED(seq), float UNUSED(cfra), float facf0, float facf1, + ImBuf *ibuf1, ImBuf *ibuf2, ImBuf *UNUSED(ibuf3), int start_line, int total_lines, ImBuf *out) { + int x = context.rectx; + int y = total_lines; + + if (out->rect_float) { + float *rect1, *rect2, *rect_out; + + slize_get_float_buffers(&context, ibuf1, ibuf2, NULL, out, start_line, &rect1, &rect2, NULL, &rect_out); + + do_drop_effect_float(facf0, facf1, x, y, rect1, rect2, rect_out); + do_alphaover_effect_float(facf0, facf1, x, y, rect1, rect2, rect_out); + } + else { + unsigned char *rect1, *rect2, *rect_out; + slize_get_byte_buffers(&context, ibuf1, ibuf2, NULL, out, start_line, &rect1, &rect2, NULL, &rect_out); + + do_drop_effect_byte(facf0, facf1, x, y, (char *) rect1, (char *) rect2, (char *) rect_out); + do_alphaover_effect_byte(facf0, facf1, x, y, (char *) rect1, (char *) rect2, (char *) rect_out); + } } -static void load_noop(struct Sequence *UNUSED(seq)) +/*********************** sequence effect factory *************************/ + +static void init_noop(Sequence *UNUSED(seq)) { } -static void free_noop(struct Sequence *UNUSED(seq)) +static void load_noop(Sequence *UNUSED(seq)) +{ + +} + +static void free_noop(Sequence *UNUSED(seq)) { } @@ -2886,47 +2785,41 @@ static int num_inputs_default(void) return 2; } -static int early_out_noop(struct Sequence *UNUSED(seq), - float UNUSED(facf0), float UNUSED(facf1)) +static int early_out_noop(Sequence *UNUSED(seq), float UNUSED(facf0), float UNUSED(facf1)) { - return 0; + return EARLY_DO_EFFECT; } -static int early_out_fade(struct Sequence *UNUSED(seq), - float facf0, float facf1) +static int early_out_fade(Sequence *UNUSED(seq), float facf0, float facf1) { if (facf0 == 0.0f && facf1 == 0.0f) { - return 1; + return EARLY_USE_INPUT_1; } else if (facf0 == 1.0f && facf1 == 1.0f) { - return 2; + return EARLY_USE_INPUT_2; } - return 0; + return EARLY_DO_EFFECT; } -static int early_out_mul_input2(struct Sequence *UNUSED(seq), - float facf0, float facf1) +static int early_out_mul_input2(Sequence *UNUSED(seq), float facf0, float facf1) { if (facf0 == 0.0f && facf1 == 0.0f) { - return 1; + return EARLY_USE_INPUT_1; } - return 0; + return EARLY_DO_EFFECT; } -static void store_icu_yrange_noop(struct Sequence *UNUSED(seq), - short UNUSED(adrcode), float *UNUSED(ymin), float *UNUSED(ymax)) +static void store_icu_yrange_noop(Sequence *UNUSED(seq), short UNUSED(adrcode), float *UNUSED(ymin), float *UNUSED(ymax)) { /* defaults are fine */ } -static void get_default_fac_noop(struct Sequence *UNUSED(seq), float UNUSED(cfra), - float *facf0, float *facf1) +static void get_default_fac_noop(Sequence *UNUSED(seq), float UNUSED(cfra), float *facf0, float *facf1) { *facf0 = *facf1 = 1.0; } -static void get_default_fac_fade(struct Sequence *seq, float cfra, - float *facf0, float *facf1) +static void get_default_fac_fade(Sequence *seq, float cfra, float *facf0, float *facf1) { *facf0 = (float)(cfra - seq->startdisp); *facf1 = (float)(*facf0 + 0.5f); @@ -2934,39 +2827,9 @@ static void get_default_fac_fade(struct Sequence *seq, float cfra, *facf1 /= seq->len; } -static ImBuf *do_overdrop_effect(SeqRenderData context, - Sequence *UNUSED(seq), - float UNUSED(cfra), - float facf0, float facf1, - struct ImBuf *ibuf1, - struct ImBuf *ibuf2, - struct ImBuf *ibuf3) +static struct ImBuf *init_execution(SeqRenderData context, ImBuf *ibuf1, ImBuf *ibuf2, ImBuf *ibuf3) { - struct ImBuf *out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); - int x = context.rectx; - int y = context.recty; - - if (out->rect_float) { - do_drop_effect_float( - facf0, facf1, x, y, - ibuf1->rect_float, ibuf2->rect_float, - out->rect_float); - do_alphaover_effect_float( - facf0, facf1, x, y, - ibuf1->rect_float, ibuf2->rect_float, - out->rect_float); - } - else { - do_drop_effect_byte( - facf0, facf1, x, y, - (char *) ibuf1->rect, - (char *) ibuf2->rect, - (char *) out->rect); - do_alphaover_effect_byte( - facf0, facf1, x, y, - (char *) ibuf1->rect, (char *) ibuf2->rect, - (char *) out->rect); - } + ImBuf *out = prepare_effect_imbufs(context, ibuf1, ibuf2, ibuf3); return out; } @@ -2976,6 +2839,7 @@ static struct SeqEffectHandle get_sequence_effect_impl(int seq_type) struct SeqEffectHandle rval; int sequence_type = seq_type; + rval.multithreaded = FALSE; rval.init = init_noop; rval.num_inputs = num_inputs_default; rval.load = load_noop; @@ -2984,44 +2848,55 @@ static struct SeqEffectHandle get_sequence_effect_impl(int seq_type) rval.get_default_fac = get_default_fac_noop; rval.store_icu_yrange = store_icu_yrange_noop; rval.execute = NULL; + rval.init_execution = init_execution; + rval.execute_slice = NULL; rval.copy = NULL; switch (sequence_type) { case SEQ_TYPE_CROSS: - rval.execute = do_cross_effect; + rval.multithreaded = TRUE; + rval.execute_slice = do_cross_effect; rval.early_out = early_out_fade; rval.get_default_fac = get_default_fac_fade; break; case SEQ_TYPE_GAMCROSS: + rval.multithreaded = TRUE; rval.init = init_gammacross; rval.load = load_gammacross; rval.free = free_gammacross; rval.early_out = early_out_fade; rval.get_default_fac = get_default_fac_fade; - rval.execute = do_gammacross_effect; + rval.init_execution = gammacross_init_execution; + rval.execute_slice = do_gammacross_effect; break; case SEQ_TYPE_ADD: - rval.execute = do_add_effect; + rval.multithreaded = TRUE; + rval.execute_slice = do_add_effect; rval.early_out = early_out_mul_input2; break; case SEQ_TYPE_SUB: - rval.execute = do_sub_effect; + rval.multithreaded = TRUE; + rval.execute_slice = do_sub_effect; rval.early_out = early_out_mul_input2; break; case SEQ_TYPE_MUL: - rval.execute = do_mul_effect; + rval.multithreaded = TRUE; + rval.execute_slice = do_mul_effect; rval.early_out = early_out_mul_input2; break; case SEQ_TYPE_ALPHAOVER: + rval.multithreaded = TRUE; rval.init = init_alpha_over_or_under; - rval.execute = do_alphaover_effect; + rval.execute_slice = do_alphaover_effect; break; case SEQ_TYPE_OVERDROP: - rval.execute = do_overdrop_effect; + rval.multithreaded = TRUE; + rval.execute_slice = do_overdrop_effect; break; case SEQ_TYPE_ALPHAUNDER: + rval.multithreaded = TRUE; rval.init = init_alpha_over_or_under; - rval.execute = do_alphaunder_effect; + rval.execute_slice = do_alphaunder_effect; break; case SEQ_TYPE_WIPE: rval.init = init_wipe_effect; @@ -3052,7 +2927,7 @@ static struct SeqEffectHandle get_sequence_effect_impl(int seq_type) rval.load = load_speed_effect; rval.free = free_speed_effect; rval.copy = copy_speed_effect; - rval.execute = do_cross_effect; + rval.execute = do_speed_effect; rval.early_out = early_out_speed; rval.store_icu_yrange = store_icu_yrange_speed; break; @@ -3079,10 +2954,9 @@ static struct SeqEffectHandle get_sequence_effect_impl(int seq_type) return rval; } - -struct SeqEffectHandle get_sequence_effect(Sequence *seq) +struct SeqEffectHandle BKE_sequence_get_effect(Sequence *seq) { - struct SeqEffectHandle rval = {NULL}; + struct SeqEffectHandle rval = {FALSE, NULL}; if (seq->type & SEQ_TYPE_EFFECT) { rval = get_sequence_effect_impl(seq->type); @@ -3095,9 +2969,9 @@ struct SeqEffectHandle get_sequence_effect(Sequence *seq) return rval; } -struct SeqEffectHandle get_sequence_blend(Sequence *seq) +struct SeqEffectHandle BKE_sequence_get_blend(Sequence *seq) { - struct SeqEffectHandle rval = {NULL}; + struct SeqEffectHandle rval = {FALSE, NULL}; if (seq->blend_mode != 0) { rval = get_sequence_effect_impl(seq->blend_mode); @@ -3110,12 +2984,12 @@ struct SeqEffectHandle get_sequence_blend(Sequence *seq) return rval; } -int get_sequence_effect_num_inputs(int seq_type) +int BKE_sequence_effect_get_num_inputs(int seq_type) { struct SeqEffectHandle rval = get_sequence_effect_impl(seq_type); int cnt = rval.num_inputs(); - if (rval.execute) { + if (rval.execute || (rval.execute_slice && rval.init_execution)) { return cnt; } return 0; diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c index 2900cb55529..4f1b324bc28 100644 --- a/source/blender/blenkernel/intern/sequencer.c +++ b/source/blender/blenkernel/intern/sequencer.c @@ -80,40 +80,40 @@ # include "AUD_C-API.h" #endif -static ImBuf *seq_render_strip_stack( - SeqRenderData context, ListBase *seqbasep, float cfra, int chanshown); - -static ImBuf *seq_render_strip( - SeqRenderData context, Sequence *seq, float cfra); - +static ImBuf *seq_render_strip_stack(SeqRenderData context, ListBase *seqbasep, float cfra, int chanshown); +static ImBuf *seq_render_strip(SeqRenderData context, Sequence *seq, float cfra); static void seq_free_animdata(Scene *scene, Sequence *seq); - /* **** XXX ******** */ #define SELECT 1 ListBase seqbase_clipboard; int seqbase_clipboard_frame; SequencerDrawView sequencer_view3d_cb = NULL; /* NULL in background mode */ - -void printf_strip(Sequence *seq) +#if 0 /* unused function */ +static void printf_strip(Sequence *seq) { - fprintf(stderr, "name: '%s', len:%d, start:%d, (startofs:%d, endofs:%d), (startstill:%d, endstill:%d), machine:%d, (startdisp:%d, enddisp:%d)\n", - seq->name, seq->len, seq->start, seq->startofs, seq->endofs, seq->startstill, seq->endstill, seq->machine, seq->startdisp, seq->enddisp); - fprintf(stderr, "\tseq_tx_set_final_left: %d %d\n\n", seq_tx_get_final_left(seq, 0), seq_tx_get_final_right(seq, 0)); + fprintf(stderr, "name: '%s', len:%d, start:%d, (startofs:%d, endofs:%d), " + "(startstill:%d, endstill:%d), machine:%d, (startdisp:%d, enddisp:%d)\n", + seq->name, seq->len, seq->start, seq->startofs, seq->endofs, seq->startstill, seq->endstill, seq->machine, + seq->startdisp, seq->enddisp); + + fprintf(stderr, "\tseq_tx_set_final_left: %d %d\n\n", seq_tx_get_final_left(seq, 0), + seq_tx_get_final_right(seq, 0)); } +#endif -int seqbase_recursive_apply(ListBase *seqbase, int (*apply_func)(Sequence *seq, void *), void *arg) +int BKE_sequencer_base_recursive_apply(ListBase *seqbase, int (*apply_func)(Sequence *seq, void *), void *arg) { Sequence *iseq; for (iseq = seqbase->first; iseq; iseq = iseq->next) { - if (seq_recursive_apply(iseq, apply_func, arg) == -1) + if (BKE_sequencer_recursive_apply(iseq, apply_func, arg) == -1) return -1; /* bail out */ } return 1; } -int seq_recursive_apply(Sequence *seq, int (*apply_func)(Sequence *, void *), void *arg) +int BKE_sequencer_recursive_apply(Sequence *seq, int (*apply_func)(Sequence *, void *), void *arg) { int ret = apply_func(seq, arg); @@ -121,14 +121,12 @@ int seq_recursive_apply(Sequence *seq, int (*apply_func)(Sequence *, void *), vo return -1; /* bail out */ if (ret && seq->seqbase.first) - ret = seqbase_recursive_apply(&seq->seqbase, apply_func, arg); + ret = BKE_sequencer_base_recursive_apply(&seq->seqbase, apply_func, arg); return ret; } -/* ********************************************************************** - * alloc / free functions - * ********************************************************************** */ +/*********************** alloc / free functions *************************/ /* free */ @@ -140,10 +138,11 @@ static void free_proxy_seq(Sequence *seq) } } -void seq_free_strip(Strip *strip) +static void seq_free_strip(Strip *strip) { strip->us--; - if (strip->us > 0) return; + if (strip->us > 0) + return; if (strip->us < 0) { printf("error: negative users in strip\n"); return; @@ -173,14 +172,16 @@ void seq_free_strip(Strip *strip) MEM_freeN(strip); } -void seq_free_sequence(Scene *scene, Sequence *seq) +void BKE_sequence_free(Scene *scene, Sequence *seq) { - if (seq->strip) seq_free_strip(seq->strip); + if (seq->strip) + seq_free_strip(seq->strip); - if (seq->anim) IMB_free_anim(seq->anim); + if (seq->anim) + IMB_free_anim(seq->anim); if (seq->type & SEQ_TYPE_EFFECT) { - struct SeqEffectHandle sh = get_sequence_effect(seq); + struct SeqEffectHandle sh = BKE_sequence_get_effect(seq); sh.free(seq); } @@ -205,7 +206,7 @@ void seq_free_sequence(Scene *scene, Sequence *seq) MEM_freeN(seq); } -void seq_free_sequence_recurse(Scene *scene, Sequence *seq) +static void seq_free_sequence_recurse(Scene *scene, Sequence *seq) { Sequence *iseq; @@ -213,7 +214,7 @@ void seq_free_sequence_recurse(Scene *scene, Sequence *seq) seq_free_sequence_recurse(scene, iseq); } - seq_free_sequence(scene, seq); + BKE_sequence_free(scene, seq); } @@ -234,10 +235,10 @@ static void seq_free_clipboard_recursive(Sequence *seq_parent) seq_free_clipboard_recursive(seq); } - seq_free_sequence(NULL, seq_parent); + BKE_sequence_free(NULL, seq_parent); } -void seq_free_clipboard(void) +void BKE_sequencer_free_clipboard(void) { Sequence *seq, *nseq; @@ -271,7 +272,7 @@ void BKE_sequencer_editing_free(Scene *scene) SEQ_BEGIN (ed, seq) { - seq_free_sequence(scene, seq); + BKE_sequence_free(scene, seq); } SEQ_END @@ -285,13 +286,9 @@ void BKE_sequencer_editing_free(Scene *scene) scene->ed = NULL; } -/* ********************************************************************** - * sequencer pipeline functions - * ********************************************************************** */ +/*********************** sequencer pipeline functions *************************/ -SeqRenderData seq_new_render_data( - struct Main *bmain, struct Scene *scene, - int rectx, int recty, int preview_render_size) +SeqRenderData BKE_sequencer_new_render_data(Main *bmain, Scene *scene, int rectx, int recty, int preview_render_size) { SeqRenderData rval; @@ -306,79 +303,13 @@ SeqRenderData seq_new_render_data( return rval; } -int seq_cmp_render_data(const SeqRenderData *a, const SeqRenderData *b) -{ - if (a->preview_render_size < b->preview_render_size) { - return -1; - } - if (a->preview_render_size > b->preview_render_size) { - return 1; - } - - if (a->rectx < b->rectx) { - return -1; - } - if (a->rectx > b->rectx) { - return 1; - } - - if (a->recty < b->recty) { - return -1; - } - if (a->recty > b->recty) { - return 1; - } - - if (a->bmain < b->bmain) { - return -1; - } - if (a->bmain > b->bmain) { - return 1; - } - - if (a->scene < b->scene) { - return -1; - } - if (a->scene > b->scene) { - return 1; - } - - if (a->motion_blur_shutter < b->motion_blur_shutter) { - return -1; - } - if (a->motion_blur_shutter > b->motion_blur_shutter) { - return 1; - } - - if (a->motion_blur_samples < b->motion_blur_samples) { - return -1; - } - if (a->motion_blur_samples > b->motion_blur_samples) { - return 1; - } - - return 0; -} - -unsigned int seq_hash_render_data(const SeqRenderData *a) -{ - unsigned int rval = a->rectx + a->recty; - - rval ^= a->preview_render_size; - rval ^= ((intptr_t) a->bmain) << 6; - rval ^= ((intptr_t) a->scene) << 6; - rval ^= (int)(a->motion_blur_shutter * 100.0f) << 10; - rval ^= a->motion_blur_samples << 24; - - return rval; -} - /* ************************* iterator ************************** */ /* *************** (replaces old WHILE_SEQ) ********************* */ /* **************** use now SEQ_BEGIN () SEQ_END ***************** */ /* sequence strip iterator: - * - builds a full array, recursively into meta strips */ + * - builds a full array, recursively into meta strips + */ static void seq_count(ListBase *seqbase, int *tot) { @@ -407,7 +338,7 @@ static void seq_build_array(ListBase *seqbase, Sequence ***array, int depth) } } -void seq_array(Editing *ed, Sequence ***seqarray, int *tot, int use_pointer) +static void seq_array(Editing *ed, Sequence ***seqarray, int *tot, int use_pointer) { Sequence **array; @@ -432,7 +363,7 @@ void seq_array(Editing *ed, Sequence ***seqarray, int *tot, int use_pointer) seq_build_array(&ed->seqbase, &array, 0); } -void seq_begin(Editing *ed, SeqIterator *iter, int use_pointer) +void BKE_seqence_iterator_begin(Editing *ed, SeqIterator *iter, int use_pointer) { memset(iter, 0, sizeof(*iter)); seq_array(ed, &iter->array, &iter->tot, use_pointer); @@ -444,7 +375,7 @@ void seq_begin(Editing *ed, SeqIterator *iter, int use_pointer) } } -void seq_next(SeqIterator *iter) +void BKE_seqence_iterator_next(SeqIterator *iter) { if (++iter->cur < iter->tot) iter->seq = iter->array[iter->cur]; @@ -452,7 +383,7 @@ void seq_next(SeqIterator *iter) iter->valid = 0; } -void seq_end(SeqIterator *iter) +void BKE_seqence_iterator_end(SeqIterator *iter) { if (iter->array) MEM_freeN(iter->array); @@ -460,73 +391,6 @@ void seq_end(SeqIterator *iter) iter->valid = 0; } -/* - * ********************************************************************** - * build_seqar - * ********************************************************************* - * Build a complete array of _all_ sequences (including those - * in metastrips!) - * ********************************************************************* - */ - -static void do_seq_count_cb(ListBase *seqbase, int *totseq, - int (*test_func)(Sequence *seq)) -{ - Sequence *seq; - - seq = seqbase->first; - while (seq) { - int test = test_func(seq); - if (test & BUILD_SEQAR_COUNT_CURRENT) { - (*totseq)++; - } - if (seq->seqbase.first && (test & BUILD_SEQAR_COUNT_CHILDREN)) { - do_seq_count_cb(&seq->seqbase, totseq, test_func); - } - seq = seq->next; - } -} - -static void do_build_seqar_cb(ListBase *seqbase, Sequence ***seqar, int depth, - int (*test_func)(Sequence *seq)) -{ - Sequence *seq; - - seq = seqbase->first; - while (seq) { - int test = test_func(seq); - seq->depth = depth; - - if (seq->seqbase.first && (test & BUILD_SEQAR_COUNT_CHILDREN)) { - do_build_seqar_cb(&seq->seqbase, seqar, depth + 1, test_func); - } - if (test & BUILD_SEQAR_COUNT_CURRENT) { - **seqar = seq; - (*seqar)++; - } - seq = seq->next; - } -} - -void build_seqar_cb(ListBase *seqbase, Sequence ***seqar, int *totseq, - int (*test_func)(Sequence *seq)) -{ - Sequence **tseqar; - - *totseq = 0; - do_seq_count_cb(seqbase, totseq, test_func); - - if (*totseq == 0) { - *seqar = NULL; - return; - } - *seqar = MEM_mallocN(sizeof(void *) * *totseq, "seqar"); - tseqar = *seqar; - - do_build_seqar_cb(seqbase, seqar, 0, test_func); - *seqar = tseqar; -} - static int metaseq_start(Sequence *metaseq) { return metaseq->start + metaseq->startofs; @@ -545,8 +409,7 @@ static void seq_update_sound_bounds_recursive_rec(Scene *scene, Sequence *metase * since sound is played outside of evaluating the imbufs, */ for (seq = metaseq->seqbase.first; seq; seq = seq->next) { if (seq->type == SEQ_TYPE_META) { - seq_update_sound_bounds_recursive_rec(scene, seq, - maxi(start, metaseq_start(seq)), + seq_update_sound_bounds_recursive_rec(scene, seq, maxi(start, metaseq_start(seq)), mini(end, metaseq_end(seq))); } else if (ELEM(seq->type, SEQ_TYPE_SOUND_RAM, SEQ_TYPE_SCENE)) { @@ -558,7 +421,9 @@ static void seq_update_sound_bounds_recursive_rec(Scene *scene, Sequence *metase if (seq->start + seq->len - seq->endofs > end) endofs = seq->start + seq->len - end; - sound_move_scene_sound(scene, seq->scene_sound, seq->start + startofs, seq->start + seq->len - endofs, startofs); + + sound_move_scene_sound(scene, seq->scene_sound, seq->start + startofs, + seq->start + seq->len - endofs, startofs); } } } @@ -569,10 +434,12 @@ static void seq_update_sound_bounds_recursive(Scene *scene, Sequence *metaseq) seq_update_sound_bounds_recursive_rec(scene, metaseq, metaseq_start(metaseq), metaseq_end(metaseq)); } -void calc_sequence_disp(Scene *scene, Sequence *seq) +void BKE_sequence_calc_disp(Scene *scene, Sequence *seq) { - if (seq->startofs && seq->startstill) seq->startstill = 0; - if (seq->endofs && seq->endstill) seq->endstill = 0; + if (seq->startofs && seq->startstill) + seq->startstill = 0; + if (seq->endofs && seq->endstill) + seq->endstill = 0; seq->startdisp = seq->start + seq->startofs - seq->startstill; seq->enddisp = seq->start + seq->len - seq->endofs + seq->endstill; @@ -586,13 +453,13 @@ void calc_sequence_disp(Scene *scene, Sequence *seq) } if (ELEM(seq->type, SEQ_TYPE_SOUND_RAM, SEQ_TYPE_SCENE)) { - seq_update_sound_bounds(scene, seq); + BKE_sequencer_update_sound_bounds(scene, seq); } else if (seq->type == SEQ_TYPE_META) seq_update_sound_bounds_recursive(scene, seq); } -void calc_sequence(Scene *scene, Sequence *seq) +void BKE_sequence_calc(Scene *scene, Sequence *seq) { Sequence *seqm; int min, max; @@ -600,7 +467,7 @@ void calc_sequence(Scene *scene, Sequence *seq) /* check all metas recursively */ seqm = seq->seqbase.first; while (seqm) { - if (seqm->seqbase.first) calc_sequence(scene, seqm); + if (seqm->seqbase.first) BKE_sequence_calc(scene, seqm); seqm = seqm->next; } @@ -608,8 +475,10 @@ void calc_sequence(Scene *scene, Sequence *seq) if (seq->type & SEQ_TYPE_EFFECT) { /* pointers */ - if (seq->seq2 == NULL) seq->seq2 = seq->seq1; - if (seq->seq3 == NULL) seq->seq3 = seq->seq1; + if (seq->seq2 == NULL) + seq->seq2 = seq->seq1; + if (seq->seq3 == NULL) + seq->seq3 = seq->seq1; /* effecten go from seq1 -> seq2: test */ @@ -640,7 +509,7 @@ void calc_sequence(Scene *scene, Sequence *seq) seq->len = seq->enddisp - seq->startdisp; } else { - calc_sequence_disp(scene, seq); + BKE_sequence_calc_disp(scene, seq); } } else { @@ -661,12 +530,12 @@ void calc_sequence(Scene *scene, Sequence *seq) } seq_update_sound_bounds_recursive(scene, seq); } - calc_sequence_disp(scene, seq); + BKE_sequence_calc_disp(scene, seq); } } /* note: caller should run calc_sequence(scene, seq) after */ -void reload_sequence_new_file(Scene *scene, Sequence *seq, int lock_range) +void BKE_sequence_reload_new_file(Scene *scene, Sequence *seq, int lock_range) { char str[FILE_MAX]; int prev_startdisp = 0, prev_enddisp = 0; @@ -681,7 +550,7 @@ void reload_sequence_new_file(Scene *scene, Sequence *seq, int lock_range) if (lock_range) { /* keep so we don't have to move the actual start and end points (only the data) */ - calc_sequence_disp(scene, seq); + BKE_sequence_calc_disp(scene, seq); prev_startdisp = seq->startdisp; prev_enddisp = seq->enddisp; } @@ -690,7 +559,7 @@ void reload_sequence_new_file(Scene *scene, Sequence *seq, int lock_range) case SEQ_TYPE_IMAGE: { /* Hack? */ - size_t olen = MEM_allocN_len(seq->strip->stripdata) / sizeof(struct StripElem); + size_t olen = MEM_allocN_len(seq->strip->stripdata) / sizeof(StripElem); seq->len = olen; seq->len -= seq->anim_startofs; @@ -712,10 +581,7 @@ void reload_sequence_new_file(Scene *scene, Sequence *seq, int lock_range) return; } - seq->len = IMB_anim_get_duration(seq->anim, - seq->strip->proxy ? - seq->strip->proxy->tc : - IMB_TC_RECORD_RUN); + seq->len = IMB_anim_get_duration(seq->anim, seq->strip->proxy ? seq->strip->proxy->tc : IMB_TC_RECORD_RUN); seq->anim_preseek = IMB_anim_get_preseek(seq->anim); @@ -772,12 +638,12 @@ void reload_sequence_new_file(Scene *scene, Sequence *seq, int lock_range) free_proxy_seq(seq); if (lock_range) { - seq_tx_set_final_left(seq, prev_startdisp); - seq_tx_set_final_right(seq, prev_enddisp); - seq_single_fix(seq); + BKE_sequence_tx_set_final_left(seq, prev_startdisp); + BKE_sequence_tx_set_final_right(seq, prev_enddisp); + BKE_sequence_single_fix(seq); } - calc_sequence(scene, seq); + BKE_sequence_calc(scene, seq); } void BKE_sequencer_sort(Scene *scene) @@ -788,7 +654,8 @@ void BKE_sequencer_sort(Scene *scene) Sequence *seq, *seqt; - if (ed == NULL) return; + if (ed == NULL) + return; seqbase.first = seqbase.last = NULL; effbase.first = effbase.last = NULL; @@ -805,7 +672,8 @@ void BKE_sequencer_sort(Scene *scene) } seqt = seqt->next; } - if (seqt == NULL) BLI_addtail(&effbase, seq); + if (seqt == NULL) + BLI_addtail(&effbase, seq); } else { seqt = seqbase.first; @@ -816,7 +684,8 @@ void BKE_sequencer_sort(Scene *scene) } seqt = seqt->next; } - if (seqt == NULL) BLI_addtail(&seqbase, seq); + if (seqt == NULL) + BLI_addtail(&seqbase, seq); } } @@ -824,7 +693,6 @@ void BKE_sequencer_sort(Scene *scene) *(ed->seqbasep) = seqbase; } - static int clear_scene_in_allseqs_cb(Sequence *seq, void *arg_pt) { if (seq->scene == (Scene *)arg_pt) @@ -832,14 +700,14 @@ static int clear_scene_in_allseqs_cb(Sequence *seq, void *arg_pt) return 1; } -void clear_scene_in_allseqs(Main *bmain, Scene *scene) +void BKE_sequencer_clear_scene_in_allseqs(Main *bmain, Scene *scene) { Scene *scene_iter; /* when a scene is deleted: test all seqs */ for (scene_iter = bmain->scene.first; scene_iter; scene_iter = scene_iter->id.next) { if (scene_iter != scene && scene_iter->ed) { - seqbase_recursive_apply(&scene_iter->ed->seqbase, clear_scene_in_allseqs_cb, scene); + BKE_sequencer_base_recursive_apply(&scene_iter->ed->seqbase, clear_scene_in_allseqs_cb, scene); } } } @@ -852,13 +720,6 @@ typedef struct SeqUniqueInfo { int match; } SeqUniqueInfo; -#if 0 -static void seqbase_unique_name(ListBase *seqbasep, Sequence *seq) -{ - BLI_uniquename(seqbasep, seq, "Sequence", '.', offsetof(Sequence, name), SEQ_NAME_MAXSTR); -} -#endif - static void seqbase_unique_name(ListBase *seqbasep, SeqUniqueInfo *sui) { Sequence *seq; @@ -878,7 +739,7 @@ static int seqbase_unique_name_recursive_cb(Sequence *seq, void *arg_pt) return 1; } -void seqbase_unique_name_recursive(ListBase *seqbasep, struct Sequence *seq) +void BKE_seqence_base_unique_name_recursive(ListBase *seqbasep, Sequence *seq) { SeqUniqueInfo sui; char *dot; @@ -901,7 +762,7 @@ void seqbase_unique_name_recursive(ListBase *seqbasep, struct Sequence *seq) while (sui.match) { sui.match = 0; seqbase_unique_name(seqbasep, &sui); - seqbase_recursive_apply(seqbasep, seqbase_unique_name_recursive_cb, &sui); + BKE_sequencer_base_recursive_apply(seqbasep, seqbase_unique_name_recursive_cb, &sui); } BLI_strncpy(seq->name + 2, sui.name_dest, sizeof(seq->name) - 2); @@ -937,7 +798,7 @@ static const char *give_seqname_by_type(int type) } } -const char *give_seqname(Sequence *seq) +const char *BKE_sequence_give_name(Sequence *seq) { const char *name = give_seqname_by_type(seq->type); @@ -952,7 +813,7 @@ const char *give_seqname(Sequence *seq) return name; } -/* ***************** DO THE SEQUENCE ***************** */ +/*********************** DO THE SEQUENCE *************************/ static void make_black_ibuf(ImBuf *ibuf) { @@ -970,7 +831,7 @@ static void make_black_ibuf(ImBuf *ibuf) rect_float = ibuf->rect_float; if (rect) { - memset(rect, 0, tot * sizeof(char) * 4); + memset(rect, 0, tot * sizeof(char) * 4); } if (rect_float) { @@ -1053,18 +914,19 @@ static float give_stripelem_index(Sequence *seq, float cfra) return nr; } -StripElem *give_stripelem(Sequence *seq, int cfra) +StripElem *BKE_sequencer_give_stripelem(Sequence *seq, int cfra) { StripElem *se = seq->strip->stripdata; - if (seq->type == SEQ_TYPE_IMAGE) { /* only - * IMAGE strips use the whole array, - * MOVIE strips use only - * the first element, all other strips - * don't use this... */ - int nr = (int)give_stripelem_index(seq, cfra); + if (seq->type == SEQ_TYPE_IMAGE) { + /* only IMAGE strips use the whole array, MOVIE strips use only the first element, + * all other strips don't use this... + */ + + int nr = (int) give_stripelem_index(seq, cfra); - if (nr == -1 || se == NULL) return NULL; + if (nr == -1 || se == NULL) + return NULL; se += nr + seq->anim_startofs; } @@ -1090,12 +952,14 @@ static int evaluate_seq_frame_gen(Sequence **seq_arr, ListBase *seqbase, int cfr return totseq; } -int evaluate_seq_frame(Scene *scene, int cfra) +int BKE_sequencer_evaluate_frame(Scene *scene, int cfra) { Editing *ed = BKE_sequencer_editing_get(scene, FALSE); Sequence *seq_arr[MAXSEQ + 1]; - if (ed == NULL) return 0; + if (ed == NULL) + return 0; + return evaluate_seq_frame_gen(seq_arr, ed->seqbasep, cfra); } @@ -1144,10 +1008,7 @@ static int get_shown_sequences(ListBase *seqbasep, int cfra, int chanshown, Sequ return cnt; } - -/* ********************************************************************** - * proxy management - * ********************************************************************** */ +/*********************** proxy management *************************/ typedef struct SeqIndexBuildContext { struct IndexBuildContext *index_context; @@ -1207,9 +1068,7 @@ static void seq_open_anim_file(Sequence *seq) seq->strip->dir, seq->strip->stripdata->name); BLI_path_abs(name, G.main->name); - seq->anim = openanim(name, IB_rect | - ((seq->flag & SEQ_FILTERY) ? - IB_animdeinterlace : 0), seq->streamindex); + seq->anim = openanim(name, IB_rect | ((seq->flag & SEQ_FILTERY) ? IB_animdeinterlace : 0), seq->streamindex); if (seq->anim == NULL) { return; @@ -1269,15 +1128,13 @@ static int seq_proxy_get_fname(Sequence *seq, int cfra, int render_size, char *n /* generate a separate proxy directory for each preview size */ if (seq->type == SEQ_TYPE_IMAGE) { - BLI_snprintf(name, PROXY_MAXFILE, "%s/images/%d/%s_proxy", dir, - render_size, - give_stripelem(seq, cfra)->name); + BLI_snprintf(name, PROXY_MAXFILE, "%s/images/%d/%s_proxy", dir, render_size, + BKE_sequencer_give_stripelem(seq, cfra)->name); frameno = 1; } else { frameno = (int)give_stripelem_index(seq, cfra) + seq->anim_startofs; - BLI_snprintf(name, PROXY_MAXFILE, "%s/proxy_misc/%d/####", dir, - render_size); + BLI_snprintf(name, PROXY_MAXFILE, "%s/proxy_misc/%d/####", dir, render_size); } BLI_path_abs(name, G.main->name); @@ -1326,11 +1183,9 @@ static ImBuf *seq_proxy_fetch(SeqRenderData context, Sequence *seq, int cfra) seq_open_anim_file(seq); - frameno = IMB_anim_index_get_frame_index(seq->anim, seq->strip->proxy->tc, - frameno); + frameno = IMB_anim_index_get_frame_index(seq->anim, seq->strip->proxy->tc, frameno); - return IMB_anim_absolute(seq->strip->proxy->anim, frameno, - IMB_TC_NONE, IMB_PROXY_NONE); + return IMB_anim_absolute(seq->strip->proxy->anim, frameno, IMB_TC_NONE, IMB_PROXY_NONE); } if (seq_proxy_get_fname(seq, cfra, render_size, name) == 0) { @@ -1345,9 +1200,7 @@ static ImBuf *seq_proxy_fetch(SeqRenderData context, Sequence *seq, int cfra) } } -static void seq_proxy_build_frame(SeqRenderData context, - Sequence *seq, int cfra, - int proxy_render_size) +static void seq_proxy_build_frame(SeqRenderData context, Sequence *seq, int cfra, int proxy_render_size) { char name[PROXY_MAXFILE]; int quality; @@ -1387,7 +1240,7 @@ static void seq_proxy_build_frame(SeqRenderData context, IMB_freeImBuf(ibuf); } -struct SeqIndexBuildContext *seq_proxy_rebuild_context(Main *bmain, Scene *scene, Sequence *seq) +SeqIndexBuildContext *BKE_sequencer_proxy_rebuild_context(Main *bmain, Scene *scene, Sequence *seq) { SeqIndexBuildContext *context; Sequence *nseq; @@ -1402,7 +1255,7 @@ struct SeqIndexBuildContext *seq_proxy_rebuild_context(Main *bmain, Scene *scene context = MEM_callocN(sizeof(SeqIndexBuildContext), "seq proxy rebuild context"); - nseq = seq_dupli_recursive(scene, scene, seq, 0); + nseq = BKE_sequence_dupli_recursive(scene, scene, seq, 0); context->tc_flags = nseq->strip->proxy->build_tc_flags; context->size_flags = nseq->strip->proxy->build_size_flags; @@ -1425,7 +1278,7 @@ struct SeqIndexBuildContext *seq_proxy_rebuild_context(Main *bmain, Scene *scene return context; } -void seq_proxy_rebuild(SeqIndexBuildContext *context, short *stop, short *do_update, float *progress) +void BKE_sequencer_proxy_rebuild(SeqIndexBuildContext *context, short *stop, short *do_update, float *progress) { SeqRenderData render_context; Sequence *seq = context->seq; @@ -1451,15 +1304,11 @@ void seq_proxy_rebuild(SeqIndexBuildContext *context, short *stop, short *do_upd /* fail safe code */ - render_context = seq_new_render_data( - context->bmain, context->scene, - (scene->r.size * (float)scene->r.xsch) / 100.0f + 0.5f, - (scene->r.size * (float)scene->r.ysch) / 100.0f + 0.5f, - 100); + render_context = BKE_sequencer_new_render_data(context->bmain, context->scene, + (scene->r.size * (float) scene->r.xsch) / 100.0f + 0.5f, + (scene->r.size * (float) scene->r.ysch) / 100.0f + 0.5f, 100); - for (cfra = seq->startdisp + seq->startstill; - cfra < seq->enddisp - seq->endstill; cfra++) - { + for (cfra = seq->startdisp + seq->startstill; cfra < seq->enddisp - seq->endstill; cfra++) { if (context->size_flags & IMB_PROXY_25) { seq_proxy_build_frame(render_context, seq, cfra, 25); } @@ -1473,16 +1322,15 @@ void seq_proxy_rebuild(SeqIndexBuildContext *context, short *stop, short *do_upd seq_proxy_build_frame(render_context, seq, cfra, 100); } - *progress = (float)cfra / (seq->enddisp - seq->endstill - - seq->startdisp + seq->startstill); + *progress = (float) cfra / (seq->enddisp - seq->endstill - seq->startdisp + seq->startstill); *do_update = TRUE; - if (*stop || G.afbreek) + if (*stop || G.is_break) break; } } -void seq_proxy_rebuild_finish(SeqIndexBuildContext *context, short stop) +void BKE_sequencer_proxy_rebuild_finish(SeqIndexBuildContext *context, short stop) { if (context->index_context) { IMB_close_anim_proxies(context->seq->anim); @@ -1495,9 +1343,7 @@ void seq_proxy_rebuild_finish(SeqIndexBuildContext *context, short stop) MEM_freeN(context); } -/* ********************************************************************** - * color balance - * ********************************************************************** */ +/*********************** color balance *************************/ static StripColorBalance calc_cb(StripColorBalance *cb_) { @@ -1550,7 +1396,8 @@ MINLINE float color_balance_fl(float in, const float lift, const float gain, con float x = (((in - 1.0f) * lift) + 1.0f) * gain; /* prevent NaN */ - if (x < 0.f) x = 0.f; + if (x < 0.f) + x = 0.f; return powf(x, gamma) * mul; } @@ -1562,6 +1409,7 @@ static void make_cb_table_byte(float lift, float gain, float gamma, for (y = 0; y < 256; y++) { float v = color_balance_fl((float)y * (1.0f / 255.0f), lift, gain, gamma, mul); + table[y] = FTOCHAR(v); } } @@ -1573,22 +1421,22 @@ static void make_cb_table_float(float lift, float gain, float gamma, for (y = 0; y < 256; y++) { float v = color_balance_fl((float)y * (1.0f / 255.0f), lift, gain, gamma, mul); + table[y] = v; } } -static void color_balance_byte_byte(Sequence *seq, ImBuf *ibuf, float mul) +static void color_balance_byte_byte(Sequence *seq, unsigned char *rect, int width, int height, float mul) { unsigned char cb_tab[3][256]; int c; - unsigned char *p = (unsigned char *) ibuf->rect; - unsigned char *e = p + ibuf->x * 4 * ibuf->y; + unsigned char *p = rect; + unsigned char *e = p + width * 4 * height; StripColorBalance cb = calc_cb(seq->strip->color_balance); for (c = 0; c < 3; c++) { - make_cb_table_byte(cb.lift[c], cb.gain[c], cb.gamma[c], - cb_tab[c], mul); + make_cb_table_byte(cb.lift[c], cb.gain[c], cb.gamma[c], cb_tab[c], mul); } while (p < e) { @@ -1600,18 +1448,16 @@ static void color_balance_byte_byte(Sequence *seq, ImBuf *ibuf, float mul) } } -static void color_balance_byte_float(Sequence *seq, ImBuf *ibuf, float mul) +static void color_balance_byte_float(Sequence *seq, unsigned char *rect, float *rect_float, int width, int height, float mul) { float cb_tab[4][256]; int c, i; - unsigned char *p = (unsigned char *) ibuf->rect; - unsigned char *e = p + ibuf->x * 4 * ibuf->y; + unsigned char *p = rect; + unsigned char *e = p + width * 4 * height; float *o; StripColorBalance cb; - imb_addrectfloatImBuf(ibuf); - - o = ibuf->rect_float; + o = rect_float; cb = calc_cb(seq->strip->color_balance); @@ -1633,10 +1479,10 @@ static void color_balance_byte_float(Sequence *seq, ImBuf *ibuf, float mul) } } -static void color_balance_float_float(Sequence *seq, ImBuf *ibuf, float mul) +static void color_balance_float_float(Sequence *seq, float *rect_float, int width, int height, float mul) { - float *p = ibuf->rect_float; - float *e = ibuf->rect_float + ibuf->x * 4 * ibuf->y; + float *p = rect_float; + float *e = rect_float + width * 4 * height; StripColorBalance cb = calc_cb(seq->strip->color_balance); while (p < e) { @@ -1648,16 +1494,96 @@ static void color_balance_float_float(Sequence *seq, ImBuf *ibuf, float mul) } } -static void color_balance(Sequence *seq, ImBuf *ibuf, float mul) +typedef struct ColorBalanceInitData { + Sequence *seq; + ImBuf *ibuf; + float mul; +} ColorBalanceInitData; + +typedef struct ColorBalanceThread { + Sequence *seq; + float mul; + + int width, height; + + unsigned char *rect; + float *rect_float; +} ColorBalanceThread; + +static void color_balance_init_handle(void *handle_v, int start_line, int tot_line, void *init_data_v) +{ + ColorBalanceThread *handle = (ColorBalanceThread *) handle_v; + ColorBalanceInitData *init_data = (ColorBalanceInitData *) init_data_v; + ImBuf *ibuf = init_data->ibuf; + + int offset = 4 * start_line * ibuf->x; + + memset(handle, 0, sizeof(ColorBalanceThread)); + + handle->seq = init_data->seq; + handle->mul = init_data->mul; + handle->width = ibuf->x; + handle->height = tot_line; + + if (ibuf->rect) + handle->rect = (unsigned char *) ibuf->rect + offset; + + if (ibuf->rect_float) + handle->rect_float = ibuf->rect_float + offset; +} + +static void *color_balance_do_thread(void *thread_data_v) { - if (ibuf->rect_float) { - color_balance_float_float(seq, ibuf, mul); + ColorBalanceThread *thread_data = (ColorBalanceThread *) thread_data_v; + Sequence *seq = thread_data->seq; + int width = thread_data->width, height = thread_data->height; + unsigned char *rect = thread_data->rect; + float *rect_float = thread_data->rect_float; + float mul = thread_data->mul; + + if (rect_float) { + color_balance_float_float(seq, rect_float, width, height, mul); } else if (seq->flag & SEQ_MAKE_FLOAT) { - color_balance_byte_float(seq, ibuf, mul); + color_balance_byte_float(seq, rect, rect_float, width, height, mul); } else { - color_balance_byte_byte(seq, ibuf, mul); + color_balance_byte_byte(seq, rect, width, height, mul); + } + + return NULL; +} + +static void color_balance(Sequence *seq, ImBuf *ibuf, float mul) +{ + if (!ibuf->rect_float && seq->flag & SEQ_MAKE_FLOAT) + imb_addrectfloatImBuf(ibuf); + + if (BLI_thread_is_main()) { + /* color balance could have been called from prefetching job which + * is already multithreaded, so doing threading here makes no sense + */ + ColorBalanceInitData init_data; + + init_data.seq = seq; + init_data.ibuf = ibuf; + init_data.mul = mul; + + IMB_processor_apply_threaded(ibuf->y, sizeof(ColorBalanceThread), &init_data, + color_balance_init_handle, color_balance_do_thread); + + } + else { + ColorBalanceThread handle; + + handle.seq = seq; + handle.mul = mul; + handle.width = ibuf->x; + handle.height = ibuf->y; + handle.rect = (unsigned char *)ibuf->rect; + handle.rect_float = ibuf->rect_float; + + color_balance_do_thread(&handle); } } @@ -1679,8 +1605,7 @@ static void color_balance(Sequence *seq, ImBuf *ibuf, float mul) * - Premultiply */ -int input_have_to_preprocess( - SeqRenderData UNUSED(context), Sequence *seq, float UNUSED(cfra)) +int BKE_sequencer_input_have_to_preprocess(SeqRenderData UNUSED(context), Sequence *seq, float UNUSED(cfra)) { float mul; @@ -1707,9 +1632,8 @@ int input_have_to_preprocess( return FALSE; } -static ImBuf *input_preprocess( - SeqRenderData context, Sequence *seq, float UNUSED(cfra), ImBuf *ibuf, - int is_proxy_image, int is_preprocessed) +static ImBuf *input_preprocess(SeqRenderData context, Sequence *seq, float UNUSED(cfra), ImBuf *ibuf, + int is_proxy_image, int is_preprocessed) { float mul; @@ -1729,12 +1653,10 @@ static ImBuf *input_preprocess( double yscale = 1.0; if (is_proxy_image) { - double f = seq_rendersize_to_scale_factor( - context.preview_render_size); + double f = seq_rendersize_to_scale_factor(context.preview_render_size); if (f != 1.0) { - IMB_scalefastImBuf( - ibuf, ibuf->x / f, ibuf->y / f); + IMB_scalefastImBuf(ibuf, ibuf->x / f, ibuf->y / f); } } @@ -1745,12 +1667,8 @@ static ImBuf *input_preprocess( t = *seq->strip->transform; } - xscale = context.scene->r.xsch ? - ((double) context.rectx / - (double) context.scene->r.xsch) : 1.0; - yscale = context.scene->r.ysch ? - ((double) context.recty / - (double) context.scene->r.ysch) : 1.0; + xscale = context.scene->r.xsch ? ((double) context.rectx / (double) context.scene->r.xsch) : 1.0; + yscale = context.scene->r.ysch ? ((double) context.recty / (double) context.scene->r.ysch) : 1.0; c.left *= xscale; c.right *= xscale; c.top *= yscale; c.bottom *= yscale; @@ -1780,12 +1698,9 @@ static ImBuf *input_preprocess( make_black_ibuf(ibuf); } else { - ImBuf *i = IMB_allocImBuf( - dx, dy, 32, - ibuf->rect_float ? IB_rectfloat : IB_rect); + ImBuf *i = IMB_allocImBuf(dx, dy, 32, ibuf->rect_float ? IB_rectfloat : IB_rect); - IMB_rectcpy(i, ibuf, - t.xofs, t.yofs, c.left, c.bottom, sx, sy); + IMB_rectcpy(i, ibuf, t.xofs, t.yofs, c.left, c.bottom, sx, sy); IMB_freeImBuf(ibuf); @@ -1847,21 +1762,16 @@ static ImBuf *input_preprocess( return ibuf; } -static ImBuf *copy_from_ibuf_still(SeqRenderData context, Sequence *seq, - float nr) +static ImBuf *copy_from_ibuf_still(SeqRenderData context, Sequence *seq, float nr) { ImBuf *rval = NULL; ImBuf *ibuf = NULL; if (nr == 0) { - ibuf = seq_stripelem_cache_get( - context, seq, seq->start, - SEQ_STRIPELEM_IBUF_STARTSTILL); + ibuf = BKE_sequencer_cache_get(context, seq, seq->start, SEQ_STRIPELEM_IBUF_STARTSTILL); } else if (nr == seq->len - 1) { - ibuf = seq_stripelem_cache_get( - context, seq, seq->start, - SEQ_STRIPELEM_IBUF_ENDSTILL); + ibuf = BKE_sequencer_cache_get(context, seq, seq->start, SEQ_STRIPELEM_IBUF_ENDSTILL); } if (ibuf) { @@ -1872,8 +1782,7 @@ static ImBuf *copy_from_ibuf_still(SeqRenderData context, Sequence *seq, return rval; } -static void copy_to_ibuf_still(SeqRenderData context, Sequence *seq, float nr, - ImBuf *ibuf) +static void copy_to_ibuf_still(SeqRenderData context, Sequence *seq, float nr, ImBuf *ibuf) { if (nr == 0 || nr == seq->len - 1) { /* we have to store a copy, since the passed ibuf @@ -1882,39 +1791,102 @@ static void copy_to_ibuf_still(SeqRenderData context, Sequence *seq, float nr, ibuf = IMB_dupImBuf(ibuf); if (nr == 0) { - seq_stripelem_cache_put( - context, seq, seq->start, - SEQ_STRIPELEM_IBUF_STARTSTILL, ibuf); + BKE_sequencer_cache_put(context, seq, seq->start, SEQ_STRIPELEM_IBUF_STARTSTILL, ibuf); } if (nr == seq->len - 1) { - seq_stripelem_cache_put( - context, seq, seq->start, - SEQ_STRIPELEM_IBUF_ENDSTILL, ibuf); + BKE_sequencer_cache_put(context, seq, seq->start, SEQ_STRIPELEM_IBUF_ENDSTILL, ibuf); } IMB_freeImBuf(ibuf); } } -/* ********************************************************************** - * strip rendering functions - * ********************************************************************** */ +/*********************** strip rendering functions *************************/ -static ImBuf *seq_render_strip_stack( - SeqRenderData context, ListBase *seqbasep, float cfra, int chanshown); +typedef struct RenderEffectInitData { + struct SeqEffectHandle *sh; + SeqRenderData context; + Sequence *seq; + float cfra, facf0, facf1; + ImBuf *ibuf1, *ibuf2, *ibuf3; -static ImBuf *seq_render_strip( - SeqRenderData context, Sequence *seq, float cfra); + ImBuf *out; +} RenderEffectInitData; + +typedef struct RenderEffectThread { + struct SeqEffectHandle *sh; + SeqRenderData context; + Sequence *seq; + float cfra, facf0, facf1; + ImBuf *ibuf1, *ibuf2, *ibuf3; + ImBuf *out; + int start_line, tot_line; +} RenderEffectThread; -static ImBuf *seq_render_effect_strip_impl( - SeqRenderData context, Sequence *seq, float cfra) +static void render_effect_execute_init_handle(void *handle_v, int start_line, int tot_line, void *init_data_v) +{ + RenderEffectThread *handle = (RenderEffectThread *) handle_v; + RenderEffectInitData *init_data = (RenderEffectInitData *) init_data_v; + + handle->sh = init_data->sh; + handle->context = init_data->context; + handle->seq = init_data->seq; + handle->cfra = init_data->cfra; + handle->facf0 = init_data->facf0; + handle->facf1 = init_data->facf1; + handle->ibuf1 = init_data->ibuf1; + handle->ibuf2 = init_data->ibuf2; + handle->ibuf3 = init_data->ibuf3; + handle->out = init_data->out; + + handle->start_line = start_line; + handle->tot_line = tot_line; +} + +static void *render_effect_execute_do_thread(void *thread_data_v) +{ + RenderEffectThread *thread_data = (RenderEffectThread *) thread_data_v; + + thread_data->sh->execute_slice(thread_data->context, thread_data->seq, thread_data->cfra, + thread_data->facf0, thread_data->facf1, thread_data->ibuf1, + thread_data->ibuf2, thread_data->ibuf3, thread_data->start_line, + thread_data->tot_line, thread_data->out); + + return NULL; +} + +static ImBuf *seq_render_effect_execute_threaded(struct SeqEffectHandle *sh, SeqRenderData context, Sequence *seq, + float cfra, float facf0, float facf1, + ImBuf *ibuf1, ImBuf *ibuf2, ImBuf *ibuf3) +{ + RenderEffectInitData init_data; + ImBuf *out = sh->init_execution(context, ibuf1, ibuf2, ibuf3); + + init_data.sh = sh; + init_data.context = context; + init_data.seq = seq; + init_data.cfra = cfra; + init_data.facf0 = facf0; + init_data.facf1 = facf1; + init_data.ibuf1 = ibuf1; + init_data.ibuf2 = ibuf2; + init_data.ibuf3 = ibuf3; + init_data.out = out; + + IMB_processor_apply_threaded(out->y, sizeof(RenderEffectThread), &init_data, + render_effect_execute_init_handle, render_effect_execute_do_thread); + + return out; +} + +static ImBuf *seq_render_effect_strip_impl(SeqRenderData context, Sequence *seq, float cfra) { float fac, facf; int early_out; int i; - struct SeqEffectHandle sh = get_sequence_effect(seq); + struct SeqEffectHandle sh = BKE_sequence_get_effect(seq); FCurve *fcu = NULL; ImBuf *ibuf[3]; Sequence *input[3]; @@ -1924,7 +1896,8 @@ static ImBuf *seq_render_effect_strip_impl( input[0] = seq->seq1; input[1] = seq->seq2; input[2] = seq->seq3; - if (!sh.execute) { /* effect not supported in this version... */ + if (!sh.execute && !(sh.execute_slice && sh.init_execution)) { + /* effect not supported in this version... */ out = IMB_allocImBuf(context.rectx, context.recty, 32, IB_rect); return out; } @@ -1952,19 +1925,19 @@ static ImBuf *seq_render_effect_strip_impl( switch (early_out) { case EARLY_NO_INPUT: - out = sh.execute(context, seq, cfra, fac, facf, - NULL, NULL, NULL); + out = sh.execute(context, seq, cfra, fac, facf, NULL, NULL, NULL); break; case EARLY_DO_EFFECT: for (i = 0; i < 3; i++) { if (input[i]) - ibuf[i] = seq_render_strip( - context, input[i], cfra); + ibuf[i] = seq_render_strip(context, input[i], cfra); } if (ibuf[0] && ibuf[1]) { - out = sh.execute(context, seq, cfra, fac, facf, - ibuf[0], ibuf[1], ibuf[2]); + if (sh.multithreaded) + out = seq_render_effect_execute_threaded(&sh, context, seq, cfra, fac, facf, ibuf[0], ibuf[1], ibuf[2]); + else + out = sh.execute(context, seq, cfra, fac, facf, ibuf[0], ibuf[1], ibuf[2]); } break; case EARLY_USE_INPUT_1: @@ -1972,7 +1945,7 @@ static ImBuf *seq_render_effect_strip_impl( ibuf[0] = seq_render_strip(context, input[0], cfra); } if (ibuf[0]) { - if (input_have_to_preprocess(context, seq, cfra)) { + if (BKE_sequencer_input_have_to_preprocess(context, seq, cfra)) { out = IMB_dupImBuf(ibuf[0]); } else { @@ -1986,7 +1959,7 @@ static ImBuf *seq_render_effect_strip_impl( ibuf[1] = seq_render_strip(context, input[1], cfra); } if (ibuf[1]) { - if (input_have_to_preprocess(context, seq, cfra)) { + if (BKE_sequencer_input_have_to_preprocess(context, seq, cfra)) { out = IMB_dupImBuf(ibuf[1]); } else { @@ -2008,8 +1981,7 @@ static ImBuf *seq_render_effect_strip_impl( return out; } -static ImBuf *seq_render_movieclip_strip( - SeqRenderData context, Sequence *seq, float nr) +static ImBuf *seq_render_movieclip_strip(SeqRenderData context, Sequence *seq, float nr) { ImBuf *ibuf = NULL; MovieClipUser user; @@ -2048,21 +2020,17 @@ static ImBuf *seq_render_movieclip_strip( } if (seq->clip_flag & SEQ_MOVIECLIP_RENDER_STABILIZED) { - ibuf = BKE_movieclip_get_stable_ibuf( - seq->clip, &user, tloc, &tscale, &tangle, - 0); + ibuf = BKE_movieclip_get_stable_ibuf(seq->clip, &user, tloc, &tscale, &tangle, 0); } else { - ibuf = BKE_movieclip_get_ibuf_flag( - seq->clip, &user, 0, MOVIECLIP_CACHE_SKIP); + ibuf = BKE_movieclip_get_ibuf_flag(seq->clip, &user, 0, MOVIECLIP_CACHE_SKIP); } return ibuf; } -static ImBuf *seq_render_mask_strip( - SeqRenderData context, Sequence *seq, float nr) +static ImBuf *seq_render_mask_strip(SeqRenderData context, Sequence *seq, float nr) { /* TODO - add option to rasterize to alpha imbuf? */ ImBuf *ibuf = NULL; @@ -2084,9 +2052,7 @@ static ImBuf *seq_render_mask_strip( mr_handle = BKE_maskrasterize_handle_new(); - BKE_maskrasterize_handle_init(mr_handle, mask_temp, - context.rectx, context.recty, - TRUE, TRUE, TRUE); + BKE_maskrasterize_handle_init(mr_handle, mask_temp, context.rectx, context.recty, TRUE, TRUE, TRUE); BKE_mask_free(mask_temp); MEM_freeN(mask_temp); @@ -2139,8 +2105,7 @@ static ImBuf *seq_render_mask_strip( return ibuf; } -static ImBuf *seq_render_scene_strip( - SeqRenderData context, Sequence *seq, float nr) +static ImBuf *seq_render_scene_strip(SeqRenderData context, Sequence *seq, float nr) { ImBuf *ibuf = NULL; float frame; @@ -2158,7 +2123,7 @@ static ImBuf *seq_render_scene_strip( * for display in render/imagewindow * * Hmm, don't see, why we can't do that all the time, - * and since G.rendering is uhm, gone... (Peter) + * and since G.is_rendering is uhm, gone... (Peter) */ /* New info: @@ -2179,9 +2144,9 @@ static ImBuf *seq_render_scene_strip( * -jahka */ - int rendering = G.rendering; + int rendering = G.is_rendering; int doseq; - int doseq_gl = G.rendering ? /*(scene->r.seq_flag & R_SEQ_GL_REND)*/ 0 : /*(scene->r.seq_flag & R_SEQ_GL_PREV)*/ 1; + int doseq_gl = G.is_rendering ? /*(scene->r.seq_flag & R_SEQ_GL_REND)*/ 0 : /*(scene->r.seq_flag & R_SEQ_GL_PREV)*/ 1; int have_seq = FALSE; Scene *scene; @@ -2227,7 +2192,7 @@ static ImBuf *seq_render_scene_strip( /* for old scened this can be uninitialized, * should probably be added to do_versions at some point if the functionality stays */ if (context.scene->r.seq_prev_type == 0) - context.scene->r.seq_prev_type = 3 /* ==OB_SOLID */; + context.scene->r.seq_prev_type = 3 /* == OB_SOLID */; /* opengl offscreen render */ BKE_scene_update_for_newframe(context.bmain, scene, scene->lay); @@ -2249,7 +2214,7 @@ static ImBuf *seq_render_scene_strip( RE_BlenderFrame(re, context.bmain, scene, NULL, camera, scene->lay, frame, FALSE); /* restore previous state after it was toggled on & off by RE_BlenderFrame */ - G.rendering = rendering; + G.is_rendering = rendering; } RE_AcquireResultImage(re, &rres); @@ -2299,14 +2264,14 @@ static ImBuf *seq_render_strip(SeqRenderData context, Sequence *seq, float cfra) { ImBuf *ibuf = NULL; char name[FILE_MAX]; - int use_preprocess = input_have_to_preprocess(context, seq, cfra); + int use_preprocess = BKE_sequencer_input_have_to_preprocess(context, seq, cfra); int is_proxy_image = FALSE; float nr = give_stripelem_index(seq, cfra); /* all effects are handled similarly with the exception of speed effect */ int type = (seq->type & SEQ_TYPE_EFFECT && seq->type != SEQ_TYPE_SPEED) ? SEQ_TYPE_EFFECT : seq->type; int is_preprocessed = !ELEM3(type, SEQ_TYPE_IMAGE, SEQ_TYPE_MOVIE, SEQ_TYPE_SCENE); - ibuf = seq_stripelem_cache_get(context, seq, cfra, SEQ_STRIPELEM_IBUF); + ibuf = BKE_sequencer_cache_get(context, seq, cfra, SEQ_STRIPELEM_IBUF); /* currently, we cache preprocessed images in SEQ_STRIPELEM_IBUF, * but not(!) on SEQ_STRIPELEM_IBUF_ENDSTILL and ..._STARTSTILL */ @@ -2352,7 +2317,7 @@ static ImBuf *seq_render_strip(SeqRenderData context, Sequence *seq, float cfra) float f_cfra; SpeedControlVars *s = (SpeedControlVars *)seq->effectdata; - sequence_effect_speed_rebuild_map(context.scene, seq, 0); + BKE_sequence_effect_speed_rebuild_map(context.scene, seq, 0); /* weeek! */ f_cfra = seq->start + s->frameMap[(int)nr]; @@ -2373,13 +2338,12 @@ static ImBuf *seq_render_strip(SeqRenderData context, Sequence *seq, float cfra) } case SEQ_TYPE_EFFECT: { - ibuf = seq_render_effect_strip_impl( - context, seq, seq->start + nr); + ibuf = seq_render_effect_strip_impl(context, seq, seq->start + nr); break; } case SEQ_TYPE_IMAGE: { - StripElem *s_elem = give_stripelem(seq, cfra); + StripElem *s_elem = BKE_sequencer_give_stripelem(seq, cfra); if (s_elem) { BLI_join_dirfile(name, sizeof(name), seq->strip->dir, s_elem->name); @@ -2407,16 +2371,11 @@ static ImBuf *seq_render_strip(SeqRenderData context, Sequence *seq, float cfra) seq_open_anim_file(seq); if (seq->anim) { - IMB_anim_set_preseek(seq->anim, - seq->anim_preseek); + IMB_anim_set_preseek(seq->anim, seq->anim_preseek); - ibuf = IMB_anim_absolute( - seq->anim, nr + seq->anim_startofs, - seq->strip->proxy ? - seq->strip->proxy->tc : - IMB_TC_RECORD_RUN, - seq_rendersize_to_proxysize( - context.preview_render_size)); + ibuf = IMB_anim_absolute(seq->anim, nr + seq->anim_startofs, + seq->strip->proxy ? seq->strip->proxy->tc : IMB_TC_RECORD_RUN, + seq_rendersize_to_proxysize(context.preview_render_size)); /* we don't need both (speed reasons)! */ if (ibuf && ibuf->rect_float && ibuf->rect) @@ -2430,7 +2389,8 @@ static ImBuf *seq_render_strip(SeqRenderData context, Sequence *seq, float cfra) break; } case SEQ_TYPE_SCENE: - { // scene can be NULL after deletions + { + /* scene can be NULL after deletions */ ibuf = seq_render_scene_strip(context, seq, nr); /* Scene strips update all animation, so we need to restore original state.*/ @@ -2462,7 +2422,7 @@ static ImBuf *seq_render_strip(SeqRenderData context, Sequence *seq, float cfra) copy_to_ibuf_still(context, seq, nr, ibuf); break; } - } + } if (ibuf == NULL) ibuf = IMB_allocImBuf(context.rectx, context.recty, 32, IB_rect); @@ -2471,17 +2431,14 @@ static ImBuf *seq_render_strip(SeqRenderData context, Sequence *seq, float cfra) use_preprocess = TRUE; if (use_preprocess) - ibuf = input_preprocess(context, seq, cfra, ibuf, - is_proxy_image, is_preprocessed); + ibuf = input_preprocess(context, seq, cfra, ibuf, is_proxy_image, is_preprocessed); - seq_stripelem_cache_put(context, seq, cfra, SEQ_STRIPELEM_IBUF, ibuf); + BKE_sequencer_cache_put(context, seq, cfra, SEQ_STRIPELEM_IBUF, ibuf); return ibuf; } -/* ********************************************************************** - * strip stack rendering functions - * ********************************************************************** */ +/*********************** strip stack rendering functions *************************/ static int seq_must_swap_input_in_blend_mode(Sequence *seq) { @@ -2499,7 +2456,7 @@ static int seq_must_swap_input_in_blend_mode(Sequence *seq) static int seq_get_early_out_for_blend_mode(Sequence *seq) { - struct SeqEffectHandle sh = get_sequence_blend(seq); + struct SeqEffectHandle sh = BKE_sequence_get_blend(seq); float facf = seq->blend_opacity / 100.0f; int early_out = sh.early_out(seq, facf, facf); @@ -2518,8 +2475,7 @@ static int seq_get_early_out_for_blend_mode(Sequence *seq) return early_out; } -static ImBuf *seq_render_strip_stack( - SeqRenderData context, ListBase *seqbasep, float cfra, int chanshown) +static ImBuf *seq_render_strip_stack(SeqRenderData context, ListBase *seqbasep, float cfra, int chanshown) { Sequence *seq_arr[MAXSEQ + 1]; int count; @@ -2540,8 +2496,7 @@ static ImBuf *seq_render_strip_stack( } #endif - out = seq_stripelem_cache_get(context, seq_arr[count - 1], - cfra, SEQ_STRIPELEM_IBUF_COMP); + out = BKE_sequencer_cache_get(context, seq_arr[count - 1], cfra, SEQ_STRIPELEM_IBUF_COMP); if (out) { return out; @@ -2549,8 +2504,7 @@ static ImBuf *seq_render_strip_stack( if (count == 1) { out = seq_render_strip(context, seq_arr[0], cfra); - seq_stripelem_cache_put(context, seq_arr[0], cfra, - SEQ_STRIPELEM_IBUF_COMP, out); + BKE_sequencer_cache_put(context, seq_arr[0], cfra, SEQ_STRIPELEM_IBUF_COMP, out); return out; } @@ -2560,8 +2514,7 @@ static ImBuf *seq_render_strip_stack( int early_out; Sequence *seq = seq_arr[i]; - out = seq_stripelem_cache_get( - context, seq, cfra, SEQ_STRIPELEM_IBUF_COMP); + out = BKE_sequencer_cache_get(context, seq, cfra, SEQ_STRIPELEM_IBUF_COMP); if (out) { break; @@ -2595,9 +2548,7 @@ static ImBuf *seq_render_strip_stack( } } - seq_stripelem_cache_put(context, seq_arr[i], cfra, - SEQ_STRIPELEM_IBUF_COMP, out); - + BKE_sequencer_cache_put(context, seq_arr[i], cfra, SEQ_STRIPELEM_IBUF_COMP, out); i++; @@ -2605,7 +2556,7 @@ static ImBuf *seq_render_strip_stack( Sequence *seq = seq_arr[i]; if (seq_get_early_out_for_blend_mode(seq) == EARLY_DO_EFFECT) { - struct SeqEffectHandle sh = get_sequence_blend(seq); + struct SeqEffectHandle sh = BKE_sequence_get_blend(seq); ImBuf *ibuf1 = out; ImBuf *ibuf2 = seq_render_strip(context, seq, cfra); @@ -2613,22 +2564,23 @@ static ImBuf *seq_render_strip_stack( int swap_input = seq_must_swap_input_in_blend_mode(seq); if (swap_input) { - out = sh.execute(context, seq, cfra, - facf, facf, - ibuf2, ibuf1, NULL); + if (sh.multithreaded) + out = seq_render_effect_execute_threaded(&sh, context, seq, cfra, facf, facf, ibuf2, ibuf1, NULL); + else + out = sh.execute(context, seq, cfra, facf, facf, ibuf2, ibuf1, NULL); } else { - out = sh.execute(context, seq, cfra, - facf, facf, - ibuf1, ibuf2, NULL); + if (sh.multithreaded) + out = seq_render_effect_execute_threaded(&sh, context, seq, cfra, facf, facf, ibuf1, ibuf2, NULL); + else + out = sh.execute(context, seq, cfra, facf, facf, ibuf1, ibuf2, NULL); } IMB_freeImBuf(ibuf1); IMB_freeImBuf(ibuf2); } - seq_stripelem_cache_put(context, seq_arr[i], cfra, - SEQ_STRIPELEM_IBUF_COMP, out); + BKE_sequencer_cache_put(context, seq_arr[i], cfra, SEQ_STRIPELEM_IBUF_COMP, out); } return out; @@ -2639,7 +2591,7 @@ static ImBuf *seq_render_strip_stack( * you have to free after usage! */ -ImBuf *give_ibuf_seq(SeqRenderData context, float cfra, int chanshown) +ImBuf *BKE_sequencer_give_ibuf(SeqRenderData context, float cfra, int chanshown) { Editing *ed = BKE_sequencer_editing_get(context.scene, FALSE); int count; @@ -2659,30 +2611,17 @@ ImBuf *give_ibuf_seq(SeqRenderData context, float cfra, int chanshown) return seq_render_strip_stack(context, seqbasep, cfra, chanshown); } -ImBuf *give_ibuf_seqbase(SeqRenderData context, float cfra, int chanshown, ListBase *seqbasep) +ImBuf *BKE_sequencer_give_ibuf_seqbase(SeqRenderData context, float cfra, int chanshown, ListBase *seqbasep) { return seq_render_strip_stack(context, seqbasep, cfra, chanshown); } -ImBuf *give_ibuf_seq_direct(SeqRenderData context, float cfra, Sequence *seq) +ImBuf *BKE_sequencer_give_ibuf_direct(SeqRenderData context, float cfra, Sequence *seq) { return seq_render_strip(context, seq, cfra); } -#if 0 -/* check used when we need to change seq->blend_mode but not to effect or audio strips */ -static int seq_can_blend(Sequence *seq) -{ - if (ELEM4(seq->type, SEQ_TYPE_IMAGE, SEQ_TYPE_META, SEQ_TYPE_SCENE, SEQ_TYPE_MOVIE)) { - return 1; - } - else { - return 0; - } -} -#endif - /* *********************** threading api ******************* */ static ListBase running_threads; @@ -2727,152 +2666,7 @@ typedef struct PrefetchQueueElem { ImBuf *ibuf; } PrefetchQueueElem; -#if 0 -static void *seq_prefetch_thread(void *This_) -{ - PrefetchThread *This = This_; - - while (!seq_thread_shutdown) { - PrefetchQueueElem *e; - int s_last; - - pthread_mutex_lock(&queue_lock); - e = prefetch_wait.first; - if (e) { - BLI_remlink(&prefetch_wait, e); - } - s_last = seq_last_given_monoton_cfra; - - This->current = e; - - pthread_mutex_unlock(&queue_lock); - - if (!e) { - pthread_mutex_lock(&prefetch_ready_lock); - - This->running = FALSE; - - pthread_cond_signal(&prefetch_ready_cond); - pthread_mutex_unlock(&prefetch_ready_lock); - - pthread_mutex_lock(&wakeup_lock); - if (!seq_thread_shutdown) { - pthread_cond_wait(&wakeup_cond, &wakeup_lock); - } - pthread_mutex_unlock(&wakeup_lock); - continue; - } - - This->running = TRUE; - - if (e->cfra >= s_last) { - e->ibuf = give_ibuf_seq_impl(This->scene, - e->rectx, e->recty, e->cfra, e->chanshown, - e->preview_render_size); - } - - pthread_mutex_lock(&queue_lock); - - BLI_addtail(&prefetch_done, e); - - for (e = prefetch_wait.first; e; e = e->next) { - if (s_last > e->monoton_cfra) { - BLI_remlink(&prefetch_wait, e); - MEM_freeN(e); - } - } - - for (e = prefetch_done.first; e; e = e->next) { - if (s_last > e->monoton_cfra) { - BLI_remlink(&prefetch_done, e); - MEM_freeN(e); - } - } - - pthread_mutex_unlock(&queue_lock); - - pthread_mutex_lock(&frame_done_lock); - pthread_cond_signal(&frame_done_cond); - pthread_mutex_unlock(&frame_done_lock); - } - return 0; -} - -static void seq_start_threads(Scene *scene) -{ - int i; - - running_threads.first = running_threads.last = NULL; - prefetch_wait.first = prefetch_wait.last = NULL; - prefetch_done.first = prefetch_done.last = NULL; - - seq_thread_shutdown = FALSE; - seq_last_given_monoton_cfra = monoton_cfra = 0; - - /* since global structures are modified during the processing - * of one frame, only one render thread is currently possible... - * - * (but we code, in the hope, that we can remove this restriction - * soon...) - */ - - fprintf(stderr, "SEQ-THREAD: seq_start_threads\n"); - - for (i = 0; i < 1; i++) { - PrefetchThread *t = MEM_callocN(sizeof(PrefetchThread), "prefetch_thread"); - t->scene = scene; - t->running = TRUE; - BLI_addtail(&running_threads, t); - - pthread_create(&t->pthread, NULL, seq_prefetch_thread, t); - } - - /* init malloc mutex */ - BLI_init_threads(0, 0, 0); -} - -static void seq_stop_threads() -{ - PrefetchThread *tslot; - PrefetchQueueElem *e; - - fprintf(stderr, "SEQ-THREAD: seq_stop_threads()\n"); - - if (seq_thread_shutdown) { - fprintf(stderr, "SEQ-THREAD: ... already stopped\n"); - return; - } - - pthread_mutex_lock(&wakeup_lock); - - seq_thread_shutdown = TRUE; - - pthread_cond_broadcast(&wakeup_cond); - pthread_mutex_unlock(&wakeup_lock); - - for (tslot = running_threads.first; tslot; tslot = tslot->next) { - pthread_join(tslot->pthread, NULL); - } - - - for (e = prefetch_wait.first; e; e = e->next) { - BLI_remlink(&prefetch_wait, e); - MEM_freeN(e); - } - - for (e = prefetch_done.first; e; e = e->next) { - BLI_remlink(&prefetch_done, e); - MEM_freeN(e); - } - - BLI_freelistN(&running_threads); - - /* deinit malloc mutex */ - BLI_end_threads(0); -} -#endif - -void give_ibuf_prefetch_request(SeqRenderData context, float cfra, int chanshown) +void BKE_sequencer_give_ibuf_prefetch_request(SeqRenderData context, float cfra, int chanshown) { PrefetchQueueElem *e; if (seq_thread_shutdown) { @@ -2896,44 +2690,13 @@ void give_ibuf_prefetch_request(SeqRenderData context, float cfra, int chanshown pthread_mutex_unlock(&wakeup_lock); } -#if 0 -static void seq_wait_for_prefetch_ready() -{ - PrefetchThread *tslot; - - if (seq_thread_shutdown) { - return; - } - - fprintf(stderr, "SEQ-THREAD: rendering prefetch frames...\n"); - - pthread_mutex_lock(&prefetch_ready_lock); - - for (;; ) { - for (tslot = running_threads.first; tslot; tslot = tslot->next) { - if (tslot->running) { - break; - } - } - if (!tslot) { - break; - } - pthread_cond_wait(&prefetch_ready_cond, &prefetch_ready_lock); - } - - pthread_mutex_unlock(&prefetch_ready_lock); - - fprintf(stderr, "SEQ-THREAD: prefetch done\n"); -} -#endif - -ImBuf *give_ibuf_seq_threaded(SeqRenderData context, float cfra, int chanshown) +ImBuf *BKE_sequencer_give_ibuf_threaded(SeqRenderData context, float cfra, int chanshown) { PrefetchQueueElem *e = NULL; int found_something = FALSE; if (seq_thread_shutdown) { - return give_ibuf_seq(context, cfra, chanshown); + return BKE_sequencer_give_ibuf(context, cfra, chanshown); } while (!e) { @@ -2999,9 +2762,7 @@ ImBuf *give_ibuf_seq_threaded(SeqRenderData context, float cfra, int chanshown) e = NULL; if (!found_something) { - fprintf(stderr, - "SEQ-THREAD: Requested frame " - "not in queue ???\n"); + fprintf(stderr, "SEQ-THREAD: Requested frame not in queue ???\n"); break; } pthread_mutex_lock(&frame_done_lock); @@ -3023,8 +2784,44 @@ static void free_anim_seq(Sequence *seq) } } -void free_imbuf_seq(Scene *scene, ListBase *seqbase, int check_mem_usage, - int keep_file_handles) +void BKE_sequence_invalidate_cache(Scene *scene, Sequence *seq) +{ + Editing *ed = scene->ed; + Sequence *cur; + int left = seq->startdisp, right = seq->enddisp; + + /* invalidate cache for current sequence */ + BKE_sequencer_cache_cleanup_sequence(seq); + + /* invalidate cache for all dependent sequences */ + SEQ_BEGIN (ed, cur) + { + int cur_left = cur->startdisp, cur_right = cur->enddisp; + + if (cur == seq) + continue; + + /* sequence is outside of changed one, shouldn't be invalidated */ + if (cur_right < left || cur_left > right) + continue; + + /* sequence is below changed one, not dependent on it */ + if (cur->machine < seq->machine) + continue; + + /* sequence is not blending with lower machines, no need to invalidate */ + if ((cur->blend_mode == SEQ_BLEND_REPLACE) || + (cur->blend_mode == SEQ_TYPE_CROSS && cur->blend_opacity == 100.0f)) + { + continue; + } + + BKE_sequencer_cache_cleanup_sequence(cur); + } + SEQ_END +} + +void BKE_sequencer_free_imbuf(Scene *scene, ListBase *seqbase, int check_mem_usage, int keep_file_handles) { Sequence *seq; @@ -3052,18 +2849,18 @@ void free_imbuf_seq(Scene *scene, ListBase *seqbase, int check_mem_usage, } } - seq_stripelem_cache_cleanup(); + BKE_sequencer_cache_cleanup(); for (seq = seqbase->first; seq; seq = seq->next) { if (seq->strip) { if (seq->type == SEQ_TYPE_MOVIE && !keep_file_handles) free_anim_seq(seq); if (seq->type == SEQ_TYPE_SPEED) { - sequence_effect_speed_rebuild_map(scene, seq, 1); + BKE_sequence_effect_speed_rebuild_map(scene, seq, 1); } } if (seq->type == SEQ_TYPE_META) { - free_imbuf_seq(scene, &seq->seqbase, FALSE, keep_file_handles); + BKE_sequencer_free_imbuf(scene, &seq->seqbase, FALSE, keep_file_handles); } if (seq->type == SEQ_TYPE_SCENE) { /* FIXME: recurs downwards, @@ -3105,18 +2902,18 @@ static int update_changed_seq_recurs(Scene *scene, Sequence *seq, Sequence *chan if (seq->type == SEQ_TYPE_MOVIE) free_anim_seq(seq); if (seq->type == SEQ_TYPE_SPEED) { - sequence_effect_speed_rebuild_map(scene, seq, 1); + BKE_sequence_effect_speed_rebuild_map(scene, seq, 1); } } if (len_change) - calc_sequence(scene, seq); + BKE_sequence_calc(scene, seq); } return free_imbuf; } -void update_changed_seq_and_deps(Scene *scene, Sequence *changed_seq, int len_change, int ibuf_change) +void BKE_sequencer_update_changed_seq_and_deps(Scene *scene, Sequence *changed_seq, int len_change, int ibuf_change) { Editing *ed = BKE_sequencer_editing_get(scene, FALSE); Sequence *seq; @@ -3133,38 +2930,38 @@ void update_changed_seq_and_deps(Scene *scene, Sequence *changed_seq, int len_ch * left and right are the bounds at which the sequence is rendered, * start and end are from the start and fixed length of the sequence. */ -int seq_tx_get_start(Sequence *seq) +static int seq_tx_get_start(Sequence *seq) { return seq->start; } -int seq_tx_get_end(Sequence *seq) +static int seq_tx_get_end(Sequence *seq) { return seq->start + seq->len; } -int seq_tx_get_final_left(Sequence *seq, int metaclip) +int BKE_sequence_tx_get_final_left(Sequence *seq, int metaclip) { if (metaclip && seq->tmp) { /* return the range clipped by the parents range */ - return maxi(seq_tx_get_final_left(seq, 0), seq_tx_get_final_left((Sequence *)seq->tmp, TRUE)); + return maxi(BKE_sequence_tx_get_final_left(seq, 0), BKE_sequence_tx_get_final_left((Sequence *)seq->tmp, TRUE)); } else { return (seq->start - seq->startstill) + seq->startofs; } } -int seq_tx_get_final_right(Sequence *seq, int metaclip) +int BKE_sequence_tx_get_final_right(Sequence *seq, int metaclip) { if (metaclip && seq->tmp) { /* return the range clipped by the parents range */ - return mini(seq_tx_get_final_right(seq, 0), seq_tx_get_final_right((Sequence *)seq->tmp, TRUE)); + return mini(BKE_sequence_tx_get_final_right(seq, 0), BKE_sequence_tx_get_final_right((Sequence *)seq->tmp, TRUE)); } else { return ((seq->start + seq->len) + seq->endstill) - seq->endofs; } } -void seq_tx_set_final_left(Sequence *seq, int val) +void BKE_sequence_tx_set_final_left(Sequence *seq, int val) { if (val < (seq)->start) { seq->startstill = abs(val - (seq)->start); @@ -3176,7 +2973,7 @@ void seq_tx_set_final_left(Sequence *seq, int val) } } -void seq_tx_set_final_right(Sequence *seq, int val) +void BKE_sequence_tx_set_final_right(Sequence *seq, int val) { if (val > (seq)->start + (seq)->len) { seq->endstill = abs(val - (seq->start + (seq)->len)); @@ -3190,16 +2987,16 @@ void seq_tx_set_final_right(Sequence *seq, int val) /* used so we can do a quick check for single image seq * since they work a bit differently to normal image seq's (during transform) */ -int seq_single_check(Sequence *seq) +int BKE_sequence_single_check(Sequence *seq) { return ((seq->len == 1) && (seq->type == SEQ_TYPE_IMAGE || ((seq->type & SEQ_TYPE_EFFECT) && - get_sequence_effect_num_inputs(seq->type) == 0))); + BKE_sequence_effect_get_num_inputs(seq->type) == 0))); } /* check if the selected seq's reference unselected seq's */ -int seqbase_isolated_sel_check(ListBase *seqbase) +int BKE_sequence_base_isolated_sel_check(ListBase *seqbase) { Sequence *seq; /* is there more than 1 select */ @@ -3243,16 +3040,16 @@ int seqbase_isolated_sel_check(ListBase *seqbase) /* use to impose limits when dragging/extending - so impossible situations don't happen * Cant use the SEQ_LEFTSEL and SEQ_LEFTSEL directly because the strip may be in a metastrip */ -void seq_tx_handle_xlimits(Sequence *seq, int leftflag, int rightflag) +void BKE_sequence_tx_handle_xlimits(Sequence *seq, int leftflag, int rightflag) { if (leftflag) { - if (seq_tx_get_final_left(seq, 0) >= seq_tx_get_final_right(seq, 0)) { - seq_tx_set_final_left(seq, seq_tx_get_final_right(seq, 0) - 1); + if (BKE_sequence_tx_get_final_left(seq, 0) >= BKE_sequence_tx_get_final_right(seq, 0)) { + BKE_sequence_tx_set_final_left(seq, BKE_sequence_tx_get_final_right(seq, 0) - 1); } - if (seq_single_check(seq) == 0) { - if (seq_tx_get_final_left(seq, 0) >= seq_tx_get_end(seq)) { - seq_tx_set_final_left(seq, seq_tx_get_end(seq) - 1); + if (BKE_sequence_single_check(seq) == 0) { + if (BKE_sequence_tx_get_final_left(seq, 0) >= seq_tx_get_end(seq)) { + BKE_sequence_tx_set_final_left(seq, seq_tx_get_end(seq) - 1); } /* dosnt work now - TODO */ @@ -3268,13 +3065,13 @@ void seq_tx_handle_xlimits(Sequence *seq, int leftflag, int rightflag) } if (rightflag) { - if (seq_tx_get_final_right(seq, 0) <= seq_tx_get_final_left(seq, 0)) { - seq_tx_set_final_right(seq, seq_tx_get_final_left(seq, 0) + 1); + if (BKE_sequence_tx_get_final_right(seq, 0) <= BKE_sequence_tx_get_final_left(seq, 0)) { + BKE_sequence_tx_set_final_right(seq, BKE_sequence_tx_get_final_left(seq, 0) + 1); } - if (seq_single_check(seq) == 0) { - if (seq_tx_get_final_right(seq, 0) <= seq_tx_get_start(seq)) { - seq_tx_set_final_right(seq, seq_tx_get_start(seq) + 1); + if (BKE_sequence_single_check(seq) == 0) { + if (BKE_sequence_tx_get_final_right(seq, 0) <= seq_tx_get_start(seq)) { + BKE_sequence_tx_set_final_right(seq, seq_tx_get_start(seq) + 1); } } } @@ -3286,27 +3083,27 @@ void seq_tx_handle_xlimits(Sequence *seq, int leftflag, int rightflag) } } -void seq_single_fix(Sequence *seq) +void BKE_sequence_single_fix(Sequence *seq) { int left, start, offset; - if (!seq_single_check(seq)) + if (!BKE_sequence_single_check(seq)) return; /* make sure the image is always at the start since there is only one, * adjusting its start should be ok */ - left = seq_tx_get_final_left(seq, 0); + left = BKE_sequence_tx_get_final_left(seq, 0); start = seq->start; if (start != left) { offset = left - start; - seq_tx_set_final_left(seq, seq_tx_get_final_left(seq, 0) - offset); - seq_tx_set_final_right(seq, seq_tx_get_final_right(seq, 0) - offset); + BKE_sequence_tx_set_final_left(seq, BKE_sequence_tx_get_final_left(seq, 0) - offset); + BKE_sequence_tx_set_final_right(seq, BKE_sequence_tx_get_final_right(seq, 0) - offset); seq->start += offset; } } -int seq_tx_test(Sequence *seq) +int BKE_sequence_tx_test(Sequence *seq) { - return (seq->type < SEQ_TYPE_EFFECT) || (get_sequence_effect_num_inputs(seq->type) == 0); + return (seq->type < SEQ_TYPE_EFFECT) || (BKE_sequence_effect_get_num_inputs(seq->type) == 0); } static int seq_overlap(Sequence *seq1, Sequence *seq2) @@ -3315,7 +3112,7 @@ static int seq_overlap(Sequence *seq1, Sequence *seq2) ((seq1->enddisp <= seq2->startdisp) || (seq1->startdisp >= seq2->enddisp)) == 0); } -int seq_test_overlap(ListBase *seqbasep, Sequence *test) +int BKE_sequence_test_overlap(ListBase *seqbasep, Sequence *test) { Sequence *seq; @@ -3330,27 +3127,27 @@ int seq_test_overlap(ListBase *seqbasep, Sequence *test) } -void seq_translate(Scene *evil_scene, Sequence *seq, int delta) +void BKE_sequence_translate(Scene *evil_scene, Sequence *seq, int delta) { - seq_offset_animdata(evil_scene, seq, delta); + BKE_sequencer_offset_animdata(evil_scene, seq, delta); seq->start += delta; if (seq->type == SEQ_TYPE_META) { Sequence *seq_child; for (seq_child = seq->seqbase.first; seq_child; seq_child = seq_child->next) { - seq_translate(evil_scene, seq_child, delta); + BKE_sequence_translate(evil_scene, seq_child, delta); } } - calc_sequence_disp(evil_scene, seq); + BKE_sequence_calc_disp(evil_scene, seq); } -void seq_sound_init(Scene *scene, Sequence *seq) +void BKE_sequence_sound_init(Scene *scene, Sequence *seq) { if (seq->type == SEQ_TYPE_META) { Sequence *seq_child; for (seq_child = seq->seqbase.first; seq_child; seq_child = seq_child->next) { - seq_sound_init(scene, seq_child); + BKE_sequence_sound_init(scene, seq_child); } } else { @@ -3363,7 +3160,7 @@ void seq_sound_init(Scene *scene, Sequence *seq) } } -Sequence *seq_foreground_frame_get(Scene *scene, int frame) +Sequence *BKE_sequencer_foreground_frame_get(Scene *scene, int frame) { Editing *ed = BKE_sequencer_editing_get(scene, FALSE); Sequence *seq, *best_seq = NULL; @@ -3386,17 +3183,17 @@ Sequence *seq_foreground_frame_get(Scene *scene, int frame) } /* return 0 if there werent enough space */ -int shuffle_seq(ListBase *seqbasep, Sequence *test, Scene *evil_scene) +int BKE_sequence_base_shuffle(ListBase *seqbasep, Sequence *test, Scene *evil_scene) { int orig_machine = test->machine; test->machine++; - calc_sequence(evil_scene, test); - while (seq_test_overlap(seqbasep, test) ) { + BKE_sequence_calc(evil_scene, test); + while (BKE_sequence_test_overlap(seqbasep, test) ) { if (test->machine >= MAXSEQ) { break; } test->machine++; - calc_sequence(evil_scene, test); // XXX - I don't think this is needed since were only moving vertically, Campbell. + BKE_sequence_calc(evil_scene, test); // XXX - I don't think this is needed since were only moving vertically, Campbell. } @@ -3414,9 +3211,9 @@ int shuffle_seq(ListBase *seqbasep, Sequence *test, Scene *evil_scene) test->machine = orig_machine; new_frame = new_frame + (test->start - test->startdisp); /* adjust by the startdisp */ - seq_translate(evil_scene, test, new_frame - test->start); + BKE_sequence_translate(evil_scene, test, new_frame - test->start); - calc_sequence(evil_scene, test); + BKE_sequence_calc(evil_scene, test); return 0; } else { @@ -3465,13 +3262,13 @@ static int shuffle_seq_time_offset(Scene *scene, ListBase *seqbasep, char dir) for (seq = seqbasep->first; seq; seq = seq->next) { if (seq->tmp) - calc_sequence_disp(scene, seq); /* corrects dummy startdisp/enddisp values */ + BKE_sequence_calc_disp(scene, seq); /* corrects dummy startdisp/enddisp values */ } return tot_ofs; } -int shuffle_seq_time(ListBase *seqbasep, Scene *evil_scene) +int BKE_sequence_base_shuffle_time(ListBase *seqbasep, Scene *evil_scene) { /* note: seq->tmp is used to tag strips to move */ @@ -3484,7 +3281,7 @@ int shuffle_seq_time(ListBase *seqbasep, Scene *evil_scene) if (offset) { for (seq = seqbasep->first; seq; seq = seq->next) { if (seq->tmp) { - seq_translate(evil_scene, seq, offset); + BKE_sequence_translate(evil_scene, seq, offset); seq->flag &= ~SEQ_OVERLAP; } } @@ -3493,7 +3290,7 @@ int shuffle_seq_time(ListBase *seqbasep, Scene *evil_scene) return offset ? 0 : 1; } -void seq_update_sound_bounds_all(Scene *scene) +void BKE_sequencer_update_sound_bounds_all(Scene *scene) { Editing *ed = scene->ed; @@ -3505,13 +3302,13 @@ void seq_update_sound_bounds_all(Scene *scene) seq_update_sound_bounds_recursive(scene, seq); } else if (ELEM(seq->type, SEQ_TYPE_SOUND_RAM, SEQ_TYPE_SCENE)) { - seq_update_sound_bounds(scene, seq); + BKE_sequencer_update_sound_bounds(scene, seq); } } } } -void seq_update_sound_bounds(Scene *scene, Sequence *seq) +void BKE_sequencer_update_sound_bounds(Scene *scene, Sequence *seq) { sound_move_scene_sound_defaults(scene, seq); /* mute is set in seq_update_muting_recursive */ @@ -3543,7 +3340,7 @@ static void seq_update_muting_recursive(ListBase *seqbasep, Sequence *metaseq, i } } -void seq_update_muting(Editing *ed) +void BKE_sequencer_update_muting(Editing *ed) { if (ed) { /* mute all sounds up to current metastack list */ @@ -3572,7 +3369,7 @@ static void seq_update_sound_recursive(Scene *scene, ListBase *seqbasep, bSound } } -void seq_update_sound(struct Scene *scene, struct bSound *sound) +void BKE_sequencer_update_sound(Scene *scene, bSound *sound) { if (scene->ed) { seq_update_sound_recursive(scene, &scene->ed->seqbase, sound); @@ -3580,7 +3377,7 @@ void seq_update_sound(struct Scene *scene, struct bSound *sound) } /* in cases where we done know the sequence's listbase */ -ListBase *seq_seqbase(ListBase *seqbase, Sequence *seq) +ListBase *BKE_sequence_seqbase(ListBase *seqbase, Sequence *seq) { Sequence *iseq; ListBase *lb = NULL; @@ -3589,7 +3386,7 @@ ListBase *seq_seqbase(ListBase *seqbase, Sequence *seq) if (seq == iseq) { return seqbase; } - else if (iseq->seqbase.first && (lb = seq_seqbase(&iseq->seqbase, seq))) { + else if (iseq->seqbase.first && (lb = BKE_sequence_seqbase(&iseq->seqbase, seq))) { return lb; } } @@ -3597,7 +3394,7 @@ ListBase *seq_seqbase(ListBase *seqbase, Sequence *seq) return NULL; } -Sequence *seq_metastrip(ListBase *seqbase, Sequence *meta, Sequence *seq) +Sequence *BKE_sequence_metastrip(ListBase *seqbase, Sequence *meta, Sequence *seq) { Sequence *iseq; @@ -3608,7 +3405,7 @@ Sequence *seq_metastrip(ListBase *seqbase, Sequence *meta, Sequence *seq) return meta; } else if (iseq->seqbase.first && - (rval = seq_metastrip(&iseq->seqbase, iseq, seq))) + (rval = BKE_sequence_metastrip(&iseq->seqbase, iseq, seq))) { return rval; } @@ -3617,7 +3414,7 @@ Sequence *seq_metastrip(ListBase *seqbase, Sequence *meta, Sequence *seq) return NULL; } -int seq_swap(Sequence *seq_a, Sequence *seq_b, const char **error_str) +int BKE_sequence_swap(Sequence *seq_a, Sequence *seq_b, const char **error_str) { char name[sizeof(seq_a->name)]; @@ -3640,7 +3437,7 @@ int seq_swap(Sequence *seq_a, Sequence *seq_b, const char **error_str) } if ((seq_a->type & SEQ_TYPE_EFFECT) && (seq_b->type & SEQ_TYPE_EFFECT)) { - if (get_sequence_effect_num_inputs(seq_a->type) != get_sequence_effect_num_inputs(seq_b->type)) { + if (BKE_sequence_effect_get_num_inputs(seq_a->type) != BKE_sequence_effect_get_num_inputs(seq_b->type)) { *error_str = "Strips must have the same number of inputs"; return 0; } @@ -3674,7 +3471,7 @@ int seq_swap(Sequence *seq_a, Sequence *seq_b, const char **error_str) } /* XXX - hackish function needed for transforming strips! TODO - have some better solution */ -void seq_offset_animdata(Scene *scene, Sequence *seq, int ofs) +void BKE_sequencer_offset_animdata(Scene *scene, Sequence *seq, int ofs) { char str[SEQ_NAME_MAXSTR + 3]; FCurve *fcu; @@ -3697,7 +3494,7 @@ void seq_offset_animdata(Scene *scene, Sequence *seq, int ofs) } } -void seq_dupe_animdata(Scene *scene, const char *name_src, const char *name_dst) +void BKE_sequencer_dupe_animdata(Scene *scene, const char *name_src, const char *name_dst) { char str_from[SEQ_NAME_MAXSTR + 3]; FCurve *fcu; @@ -3754,8 +3551,7 @@ static void seq_free_animdata(Scene *scene, Sequence *seq) } } - -Sequence *get_seq_by_name(ListBase *seqbase, const char *name, int recursive) +Sequence *BKE_sequwnce_get_by_name(ListBase *seqbase, const char *name, int recursive) { Sequence *iseq = NULL; Sequence *rseq = NULL; @@ -3763,7 +3559,7 @@ Sequence *get_seq_by_name(ListBase *seqbase, const char *name, int recursive) for (iseq = seqbase->first; iseq; iseq = iseq->next) { if (strcmp(name, iseq->name + 2) == 0) return iseq; - else if (recursive && (iseq->seqbase.first) && (rseq = get_seq_by_name(&iseq->seqbase, name, 1))) { + else if (recursive && (iseq->seqbase.first) && (rseq = BKE_sequwnce_get_by_name(&iseq->seqbase, name, 1))) { return rseq; } } @@ -3775,14 +3571,19 @@ Sequence *get_seq_by_name(ListBase *seqbase, const char *name, int recursive) Sequence *BKE_sequencer_active_get(Scene *scene) { Editing *ed = BKE_sequencer_editing_get(scene, FALSE); - if (ed == NULL) return NULL; + + if (ed == NULL) + return NULL; + return ed->act_seq; } void BKE_sequencer_active_set(Scene *scene, Sequence *seq) { Editing *ed = BKE_sequencer_editing_get(scene, FALSE); - if (ed == NULL) return; + + if (ed == NULL) + return; ed->act_seq = seq; } @@ -3830,11 +3631,11 @@ Mask *BKE_sequencer_mask_get(Scene *scene) /* api like funcs for adding */ -void seq_load_apply(Scene *scene, Sequence *seq, SeqLoadInfo *seq_load) +static void seq_load_apply(Scene *scene, Sequence *seq, SeqLoadInfo *seq_load) { if (seq) { BLI_strncpy(seq->name + 2, seq_load->name, sizeof(seq->name) - 2); - seqbase_unique_name_recursive(&scene->ed->seqbase, seq); + BKE_seqence_base_unique_name_recursive(&scene->ed->seqbase, seq); if (seq_load->flag & SEQ_LOAD_FRAME_ADVANCE) { seq_load->start_frame += (seq->enddisp - seq->startdisp); @@ -3857,7 +3658,7 @@ void seq_load_apply(Scene *scene, Sequence *seq, SeqLoadInfo *seq_load) } } -Sequence *alloc_sequence(ListBase *lb, int cfra, int machine) +Sequence *BKE_sequence_alloc(ListBase *lb, int cfra, int machine) { Sequence *seq; @@ -3881,13 +3682,13 @@ Sequence *alloc_sequence(ListBase *lb, int cfra, int machine) } /* NOTE: this function doesn't fill in image names */ -Sequence *sequencer_add_image_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo *seq_load) +Sequence *BKE_sequencer_add_image_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo *seq_load) { Scene *scene = CTX_data_scene(C); /* only for active seq */ Sequence *seq; Strip *strip; - seq = alloc_sequence(seqbasep, seq_load->start_frame, seq_load->channel); + seq = BKE_sequence_alloc(seqbasep, seq_load->start_frame, seq_load->channel); seq->type = SEQ_TYPE_IMAGE; seq->blend_mode = SEQ_TYPE_CROSS; /* so alpha adjustment fade to the strip below */ @@ -3905,7 +3706,7 @@ Sequence *sequencer_add_image_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo } #ifdef WITH_AUDASPACE -Sequence *sequencer_add_sound_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo *seq_load) +Sequence *BKE_sequencer_add_sound_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo *seq_load) { Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); /* only for sound */ @@ -3918,11 +3719,14 @@ Sequence *sequencer_add_sound_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo AUD_SoundInfo info; - sound = sound_new_file(CTX_data_main(C), seq_load->path); /* handles relative paths */ + sound = sound_new_file(bmain, seq_load->path); /* handles relative paths */ if (sound == NULL || sound->playback_handle == NULL) { - //if (op) - // BKE_report(op->reports, RPT_ERROR, "Unsupported audio format"); + /* + if (op) + BKE_report(op->reports, RPT_ERROR, "Unsupported audio format"); + */ + return NULL; } @@ -3930,17 +3734,19 @@ Sequence *sequencer_add_sound_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo if (info.specs.channels == AUD_CHANNELS_INVALID) { sound_delete(bmain, sound); - //if (op) - // BKE_report(op->reports, RPT_ERROR, "Unsupported audio format"); + /* + if (op) + BKE_report(op->reports, RPT_ERROR, "Unsupported audio format"); + */ return NULL; } - seq = alloc_sequence(seqbasep, seq_load->start_frame, seq_load->channel); + seq = BKE_sequence_alloc(seqbasep, seq_load->start_frame, seq_load->channel); seq->type = SEQ_TYPE_SOUND_RAM; seq->sound = sound; BLI_strncpy(seq->name + 2, "Sound", SEQ_NAME_MAXSTR - 2); - seqbase_unique_name_recursive(&scene->ed->seqbase, seq); + BKE_seqence_base_unique_name_recursive(&scene->ed->seqbase, seq); /* basic defaults */ seq->strip = strip = MEM_callocN(sizeof(Strip), "strip"); @@ -3954,7 +3760,7 @@ Sequence *sequencer_add_sound_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo seq->scene_sound = sound_add_scene_sound(scene, seq, seq_load->start_frame, seq_load->start_frame + seq->len, 0); - calc_sequence_disp(scene, seq); + BKE_sequence_calc_disp(scene, seq); /* last active name */ BLI_strncpy(ed->act_sounddir, strip->dir, FILE_MAXDIR); @@ -3964,16 +3770,16 @@ Sequence *sequencer_add_sound_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo return seq; } #else // WITH_AUDASPACE -Sequence *sequencer_add_sound_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo *seq_load) +Sequence *BKE_sequencer_add_sound_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo *seq_load) { - (void)C; - (void)seqbasep; - (void)seq_load; + (void) C; + (void) seqbasep; + (void) seq_load; return NULL; } #endif // WITH_AUDASPACE -Sequence *sequencer_add_movie_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo *seq_load) +Sequence *BKE_sequencer_add_movie_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo *seq_load) { Scene *scene = CTX_data_scene(C); /* only for sound */ char path[sizeof(seq_load->path)]; @@ -3992,14 +3798,14 @@ Sequence *sequencer_add_movie_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo if (an == NULL) return NULL; - seq = alloc_sequence(seqbasep, seq_load->start_frame, seq_load->channel); + seq = BKE_sequence_alloc(seqbasep, seq_load->start_frame, seq_load->channel); seq->type = SEQ_TYPE_MOVIE; seq->blend_mode = SEQ_TYPE_CROSS; /* so alpha adjustment fade to the strip below */ seq->anim = an; seq->anim_preseek = IMB_anim_get_preseek(an); BLI_strncpy(seq->name + 2, "Movie", SEQ_NAME_MAXSTR - 2); - seqbase_unique_name_recursive(&scene->ed->seqbase, seq); + BKE_seqence_base_unique_name_recursive(&scene->ed->seqbase, seq); /* basic defaults */ seq->strip = strip = MEM_callocN(sizeof(Strip), "strip"); @@ -4011,14 +3817,14 @@ Sequence *sequencer_add_movie_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo BLI_split_dirfile(seq_load->path, strip->dir, se->name, sizeof(strip->dir), sizeof(se->name)); - calc_sequence_disp(scene, seq); + BKE_sequence_calc_disp(scene, seq); if (seq_load->flag & SEQ_LOAD_MOVIE_SOUND) { int start_frame_back = seq_load->start_frame; seq_load->channel++; - sequencer_add_sound_strip(C, seqbasep, seq_load); + BKE_sequencer_add_sound_strip(C, seqbasep, seq_load); seq_load->start_frame = start_frame_back; seq_load->channel--; @@ -4033,8 +3839,7 @@ Sequence *sequencer_add_movie_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo return seq; } - -static Sequence *seq_dupli(struct Scene *scene, struct Scene *scene_to, Sequence *seq, int dupe_flag) +static Sequence *seq_dupli(Scene *scene, Scene *scene_to, Sequence *seq, int dupe_flag) { Scene *sce_audio = scene_to ? scene_to : scene; Sequence *seqn = MEM_dupallocN(seq); @@ -4042,7 +3847,7 @@ static Sequence *seq_dupli(struct Scene *scene, struct Scene *scene_to, Sequence seq->tmp = seqn; seqn->strip = MEM_dupallocN(seq->strip); - // XXX: add F-Curve duplication stuff? + /* XXX: add F-Curve duplication stuff? */ if (seq->strip->crop) { seqn->strip->crop = MEM_dupallocN(seq->strip->crop); @@ -4097,7 +3902,7 @@ static Sequence *seq_dupli(struct Scene *scene, struct Scene *scene_to, Sequence if (seq->type & SEQ_TYPE_EFFECT) { struct SeqEffectHandle sh; - sh = get_sequence_effect(seq); + sh = BKE_sequence_get_effect(seq); if (sh.copy) sh.copy(seq, seqn); } @@ -4106,27 +3911,25 @@ static Sequence *seq_dupli(struct Scene *scene, struct Scene *scene_to, Sequence } else { - fprintf(stderr, "Aiiiiekkk! sequence type not " - "handled in duplicate!\nExpect a crash" - " now...\n"); + fprintf(stderr, "Aiiiiekkk! sequence type not handled in duplicate!\nExpect a crash now...\n"); } if (dupe_flag & SEQ_DUPE_UNIQUE_NAME) - seqbase_unique_name_recursive(&scene->ed->seqbase, seqn); + BKE_seqence_base_unique_name_recursive(&scene->ed->seqbase, seqn); if (dupe_flag & SEQ_DUPE_ANIM) - seq_dupe_animdata(scene, seq->name + 2, seqn->name + 2); + BKE_sequencer_dupe_animdata(scene, seq->name + 2, seqn->name + 2); return seqn; } -Sequence *seq_dupli_recursive(struct Scene *scene, struct Scene *scene_to, Sequence *seq, int dupe_flag) +Sequence *BKE_sequence_dupli_recursive(Scene *scene, Scene *scene_to, Sequence *seq, int dupe_flag) { Sequence *seqn = seq_dupli(scene, scene_to, seq, dupe_flag); if (seq->type == SEQ_TYPE_META) { Sequence *s; for (s = seq->seqbase.first; s; s = s->next) { - Sequence *n = seq_dupli_recursive(scene, scene_to, s, dupe_flag); + Sequence *n = BKE_sequence_dupli_recursive(scene, scene_to, s, dupe_flag); if (n) { BLI_addtail(&seqn->seqbase, n); } @@ -4135,7 +3938,7 @@ Sequence *seq_dupli_recursive(struct Scene *scene, struct Scene *scene_to, Seque return seqn; } -void seqbase_dupli_recursive(Scene *scene, Scene *scene_to, ListBase *nseqbase, ListBase *seqbase, int dupe_flag) +void BKE_sequence_base_dupli_recursive(Scene *scene, Scene *scene_to, ListBase *nseqbase, ListBase *seqbase, int dupe_flag) { Sequence *seq; Sequence *seqn = NULL; @@ -4153,7 +3956,7 @@ void seqbase_dupli_recursive(Scene *scene, Scene *scene_to, ListBase *nseqbase, BLI_addtail(nseqbase, seqn); if (seq->type == SEQ_TYPE_META) - seqbase_dupli_recursive(scene, scene_to, &seqn->seqbase, &seq->seqbase, dupe_flag); + BKE_sequence_base_dupli_recursive(scene, scene_to, &seqn->seqbase, &seq->seqbase, dupe_flag); if (dupe_flag & SEQ_DUPE_CONTEXT) { if (seq == last_seq) { diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index 26ca3805c28..008dc332710 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -1941,7 +1941,7 @@ static int sb_detect_vertex_collisionCached(float opco[3], float facenormal[3], } } - if ((deflected < 2)&& (G.rt != 444)) { /* we did not hit a face until now */ + if ((deflected < 2)&& (G.debug_value != 444)) { /* we did not hit a face until now */ /* see if 'outer' hits an edge */ float dist; @@ -2493,7 +2493,7 @@ static void softbody_calc_forcesEx(Scene *scene, Object *ob, float forcetime, fl static void softbody_calc_forces(Scene *scene, Object *ob, float forcetime, float timenow, int nl_flags) { /* redirection to the new threaded Version */ - if (!(G.rt & 0x10)) { // 16 + if (!(G.debug_value & 0x10)) { // 16 softbody_calc_forcesEx(scene, ob, forcetime, timenow, nl_flags); return; } @@ -2504,7 +2504,7 @@ static void softbody_calc_forces(Scene *scene, Object *ob, float forcetime, floa /*backward compatibility note: fixing bug [17428] which forces adaptive step size to tiny steps in some situations - .. keeping G.rt==17 0x11 option for old files 'needing' the bug*/ + .. keeping G.debug_value==17 0x11 option for old files 'needing' the bug*/ /* rule we never alter free variables :bp->vec bp->pos in here ! * this will ruin adaptive stepsize AKA heun! (BM) @@ -2756,9 +2756,9 @@ static void softbody_calc_forces(Scene *scene, Object *ob, float forcetime, floa if (sb_deflect_face(ob, bp->pos, facenormal, defforce, &cf, timenow, vel, &intrusion)) { if ((!nl_flags)&&(intrusion < 0.0f)) { - if (G.rt & 0x01) { // 17 we did check for bit 0x10 before + if (G.debug_value & 0x01) { // 17 we did check for bit 0x10 before /*fixing bug [17428] this forces adaptive step size to tiny steps - in some situations .. keeping G.rt==17 option for old files 'needing' the bug + in some situations .. keeping G.debug_value==17 option for old files 'needing' the bug */ /*bjornmose: uugh.. what an evil hack violation of the 'don't touch bp->pos in here' rule @@ -2837,7 +2837,7 @@ static void softbody_calc_forces(Scene *scene, Object *ob, float forcetime, floa nlEnd(NL_MATRIX); nlEnd(NL_SYSTEM); - if ((G.rt == 32) && (nl_flags & NLF_BUILD)) { + if ((G.debug_value == 32) && (nl_flags & NLF_BUILD)) { printf("####MEE#####\n"); nlPrintMatrix(); } @@ -2849,7 +2849,7 @@ static void softbody_calc_forces(Scene *scene, Object *ob, float forcetime, floa float f; int index =0; /* for debug purpose .. anyhow cropping B vector looks like working */ - if (G.rt ==32) + if (G.debug_value ==32) for (a=2*sb->totpoint, bp= sb->bpoint; a>0; a--, bp++) { f=nlGetVariable(0, index); printf("(%f ", f);index++; diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c index 28fb75db41c..14360297ec0 100644 --- a/source/blender/blenkernel/intern/sound.c +++ b/source/blender/blenkernel/intern/sound.c @@ -524,7 +524,7 @@ void sound_update_sequencer(struct Main *main, bSound *sound) struct Scene *scene; for (scene = main->scene.first; scene; scene = scene->id.next) { - seq_update_sound(scene, sound); + BKE_sequencer_update_sound(scene, sound); } } diff --git a/source/blender/blenkernel/intern/writeavi.c b/source/blender/blenkernel/intern/writeavi.c index cd19f8a987c..dab44b5463c 100644 --- a/source/blender/blenkernel/intern/writeavi.c +++ b/source/blender/blenkernel/intern/writeavi.c @@ -80,13 +80,6 @@ bMovieHandle *BKE_movie_handle_get(const char imtype) mh.get_movie_path = filepath_avi; /* do the platform specific handles */ -#if defined(_WIN32) && !defined(FREE_WINDOWS) - if (imtype == R_IMF_IMTYPE_AVICODEC) { - //XXX mh.start_movie= start_avi_codec; - //XXX mh.append_movie= append_avi_codec; - //XXX mh.end_movie= end_avi_codec; - } -#endif #ifdef WITH_QUICKTIME if (imtype == R_IMF_IMTYPE_QUICKTIME) { mh.start_movie = start_qt; diff --git a/source/blender/blenkernel/intern/writeframeserver.c b/source/blender/blenkernel/intern/writeframeserver.c index a0f367961d2..d8fddb9851a 100644 --- a/source/blender/blenkernel/intern/writeframeserver.c +++ b/source/blender/blenkernel/intern/writeframeserver.c @@ -252,7 +252,7 @@ static int handle_request(RenderData *rd, char *req) } if (strcmp(path, "/close.txt") == 0) { safe_puts(good_bye); - G.afbreek = 1; /* Abort render */ + G.is_break = TRUE; /* Abort render */ return -1; } return -1; diff --git a/source/blender/blenlib/BLI_array.h b/source/blender/blenlib/BLI_array.h index 18258014529..32c2d5b9dc7 100644 --- a/source/blender/blenlib/BLI_array.h +++ b/source/blender/blenlib/BLI_array.h @@ -151,7 +151,7 @@ if (arr && (char *)arr != _##arr##_static) { \ BLI_array_fake_user(arr); \ MEM_freeN(arr); \ - } + } (void)0 #define BLI_array_pop(arr) ( \ (arr && _##arr##_count) ? \ @@ -162,12 +162,12 @@ /* resets the logical size of an array to zero, but doesn't * free the memory. */ #define BLI_array_empty(arr) \ - _##arr##_count = 0 + _##arr##_count = 0; (void)0 /* set the count of the array, doesn't actually increase the allocated array * size. don't use this unless you know what you're doing. */ #define BLI_array_length_set(arr, count) \ - _##arr##_count = (count) + _##arr##_count = (count); (void)0 /* only to prevent unused warnings */ #define BLI_array_fake_user(arr) \ @@ -187,5 +187,7 @@ MEM_mallocN(sizeof(*(arr)) * (realsize), allocstr) \ ) \ -#define BLI_array_fixedstack_free(arr) \ - if (_##arr##_is_static) MEM_freeN(arr) +#define BLI_array_fixedstack_free(arr) \ + if (_##arr##_is_static) { \ + MEM_freeN(arr); \ + } (void)0 diff --git a/source/blender/blenlib/BLI_stack.h b/source/blender/blenlib/BLI_stack.h new file mode 100644 index 00000000000..9151e6ab93f --- /dev/null +++ b/source/blender/blenlib/BLI_stack.h @@ -0,0 +1,54 @@ +/* + * ***** 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. + * + * Contributor(s): Nicholas Bishop + * + * ***** END GPL LICENSE BLOCK ***** + * + */ + +#ifndef __BLI_STACK_H__ +#define __BLI_STACK_H__ + +/** \file BLI_stack.h + * \ingroup bli + */ + +typedef struct BLI_Stack BLI_Stack; + +/* Create a new homogeneous stack with elements of 'elem_size' bytes */ +BLI_Stack *BLI_stack_new(int elem_size, const char *description); + +/* Free the stack's data and the stack itself */ +void BLI_stack_free(BLI_Stack *stack); + +/* Copies the source value onto the stack (note that it copies + * elem_size bytes from 'src', the pointer itself is not stored) */ +void BLI_stack_push(BLI_Stack *stack, void *src); + +/* Retrieves and removes the top element from the stack. The value is + * copies to 'dst', which must be at least elem_size bytes. + * + * Does not reduce amount of allocated memory. + * + * If stack is empty, 'dst' will not be modified. */ +void BLI_stack_pop(BLI_Stack *stack, void *dst); + +/* Returns TRUE if the stack is empty, FALSE otherwise */ +int BLI_stack_empty(const BLI_Stack *stack); + +#endif diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h index 536236c07ac..78d54defafd 100644 --- a/source/blender/blenlib/BLI_utildefines.h +++ b/source/blender/blenlib/BLI_utildefines.h @@ -81,7 +81,7 @@ #define INIT_MINMAX(min, max) { \ (min)[0] = (min)[1] = (min)[2] = 1.0e30f; \ (max)[0] = (max)[1] = (max)[2] = -1.0e30f; \ - } + } (void)0 #define INIT_MINMAX2(min, max) { \ (min)[0] = (min)[1] = 1.0e30f; \ (max)[0] = (max)[1] = -1.0e30f; \ @@ -185,7 +185,7 @@ } \ else { \ CLAMP(a, c, b); \ - } (void) + } (void)0 #define IS_EQ(a, b) ((fabs((double)(a) - (b)) >= (double) FLT_EPSILON) ? 0 : 1) #define IS_EQF(a, b) ((fabsf((float)(a) - (b)) >= (float) FLT_EPSILON) ? 0 : 1) diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt index 7fba0a3fadc..e4c4166953c 100644 --- a/source/blender/blenlib/CMakeLists.txt +++ b/source/blender/blenlib/CMakeLists.txt @@ -82,6 +82,7 @@ set(SRC intern/rct.c intern/scanfill.c intern/smallhash.c + intern/stack.c intern/storage.c intern/string.c intern/string_cursor_utf8.c @@ -136,6 +137,7 @@ set(SRC BLI_rect.h BLI_scanfill.h BLI_smallhash.h + BLI_stack.h BLI_string.h BLI_string_cursor_utf8.h BLI_string_utf8.h diff --git a/source/blender/blenlib/intern/bpath.c b/source/blender/blenlib/intern/bpath.c index d030506f4a6..ccc45b465f4 100644 --- a/source/blender/blenlib/intern/bpath.c +++ b/source/blender/blenlib/intern/bpath.c @@ -74,6 +74,7 @@ #include "BLI_bpath.h" #include "BLI_utildefines.h" +#include "BKE_font.h" #include "BKE_library.h" #include "BKE_main.h" #include "BKE_report.h" @@ -485,9 +486,9 @@ void BLI_bpath_traverse_id(Main *bmain, ID *id, BPathVisitor visit_cb, const int break; case ID_VF: { - VFont *vf = (VFont *)id; - if (vf->packedfile == NULL || (flag & BLI_BPATH_TRAVERSE_SKIP_PACKED) == 0) { - if (strcmp(vf->name, FO_BUILTIN_NAME) != 0) { + VFont *vfont = (VFont *)id; + if (vfont->packedfile == NULL || (flag & BLI_BPATH_TRAVERSE_SKIP_PACKED) == 0) { + if (BKE_vfont_is_builtin(vfont) == FALSE) { rewrite_path_fixed(((VFont *)id)->name, visit_cb, absbase, bpath_user_data); } } diff --git a/source/blender/blenlib/intern/freetypefont.c b/source/blender/blenlib/intern/freetypefont.c index 774e37a8476..60999e76c47 100644 --- a/source/blender/blenlib/intern/freetypefont.c +++ b/source/blender/blenlib/intern/freetypefont.c @@ -296,7 +296,7 @@ static int objchr_to_ftvfontdata(VFont *vfont, FT_ULong charcode) struct TmpFont *tf; /* Find the correct FreeType font */ - tf = BKE_vfont_find_tmpfont(vfont); + tf = BKE_vfont_tmpfont_find(vfont); /* What, no font found. Something strange here */ if (!tf) return FALSE; diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index b908a32bf4c..5d3a658b206 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -430,7 +430,7 @@ int isect_seg_seg_v2(const float v1[2], const float v2[2], const float v3[2], co { #define CCW(A, B, C) ((C[1] - A[1]) * (B[0] - A[0]) > (B[1]-A[1]) * (C[0]-A[0])) - return CCW(v1, v3, v4) != CCW(v2, v3, v4) && CCW(v1, v2, v3) != CCW(v1, v2, v4); + return CCW(v1, v3, v4) != CCW(v2, v3, v4) && CCW(v1, v2, v3) != CCW(v1, v2, v4); #undef CCW } @@ -1991,8 +1991,13 @@ void barycentric_weights_v2(const float v1[2], const float v2[2], const float v3 void barycentric_weights_v2_quad(const float v1[2], const float v2[2], const float v3[2], const float v4[2], const float co[2], float w[4]) { -#define MEAN_VALUE_HALF_TAN_V2(_area, i1, i2) ((_area = cross_v2v2(dirs[i1], dirs[i2])) != 0.0f ? \ - (((lens[i1] * lens[i2]) - dot_v2v2(dirs[i1], dirs[i2])) / _area) : 0.0f) + /* note: fabsf() here is not needed for convex quads (and not used in interp_weights_poly_v2). + * but in the case of concave/bowtie quads for the mask rasterizer it gives unreliable results + * without adding absf(). If this becomes an issue for more general useage we could have + * this optional or use a different function - Campbell */ +#define MEAN_VALUE_HALF_TAN_V2(_area, i1, i2) \ + ((_area = cross_v2v2(dirs[i1], dirs[i2])) != 0.0f ? \ + fabsf(((lens[i1] * lens[i2]) - dot_v2v2(dirs[i1], dirs[i2])) / _area) : 0.0f) float wtot, area; diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c index a2da9f5f791..1698733dda7 100644 --- a/source/blender/blenlib/intern/math_rotation.c +++ b/source/blender/blenlib/intern/math_rotation.c @@ -1660,12 +1660,12 @@ void quat_apply_track(float quat[4], short axis, short upflag) { /* rotations are hard coded to match vec_to_quat */ const float quat_track[][4] = { - {0.70710676908493, 0.0, -0.70710676908493, 0.0}, /* pos-y90 */ + {M_SQRT1_2, 0.0, -M_SQRT1_2, 0.0}, /* pos-y90 */ {0.5, 0.5, 0.5, 0.5}, /* Quaternion((1,0,0), radians(90)) * Quaternion((0,1,0), radians(90)) */ - {0.70710676908493, 0.0, 0.0, 0.70710676908493}, /* pos-z90 */ - {0.70710676908493, 0.0, 0.70710676908493, 0.0}, /* neg-y90 */ + {M_SQRT1_2, 0.0, 0.0, M_SQRT1_2}, /* pos-z90 */ + {M_SQRT1_2, 0.0, M_SQRT1_2, 0.0}, /* neg-y90 */ {0.5, -0.5, -0.5, 0.5}, /* Quaternion((1,0,0), radians(-90)) * Quaternion((0,1,0), radians(-90)) */ - {-3.0908619663705394e-08, 0.70710676908493, 0.70710676908493, 3.0908619663705394e-08} /* no rotation */ + {0.0, M_SQRT1_2, M_SQRT1_2, 0.0} /* no rotation */ }; assert(axis >= 0 && axis <= 5); @@ -1680,8 +1680,8 @@ void quat_apply_track(float quat[4], short axis, short upflag) * up axis is used X->Y, Y->X, Z->X, if this first up axis isn used then rotate 90d * the strange bit shift below just find the low axis {X:Y, Y:X, Z:X} */ if (upflag != (2 - axis) >> 1) { - float q[4] = {0.70710676908493, 0.0, 0.0, 0.0}; /* assign 90d rotation axis */ - q[axis + 1] = ((axis == 1)) ? 0.70710676908493 : -0.70710676908493; /* flip non Y axis */ + float q[4] = {M_SQRT1_2, 0.0, 0.0, 0.0}; /* assign 90d rotation axis */ + q[axis + 1] = ((axis == 1)) ? M_SQRT1_2 : -M_SQRT1_2; /* flip non Y axis */ mul_qt_qtqt(quat, quat, q); } } diff --git a/source/blender/blenlib/intern/rct.c b/source/blender/blenlib/intern/rct.c index 658d45ad171..68a00d81444 100644 --- a/source/blender/blenlib/intern/rct.c +++ b/source/blender/blenlib/intern/rct.c @@ -206,19 +206,19 @@ void BLI_rcti_init(rcti *rect, int xmin, int xmax, int ymin, int ymax) } } -void BLI_rcti_init_minmax(struct rcti *rect) +void BLI_rcti_init_minmax(rcti *rect) { rect->xmin = rect->ymin = INT_MAX; rect->xmax = rect->ymax = INT_MIN; } -void BLI_rctf_init_minmax(struct rctf *rect) +void BLI_rctf_init_minmax(rctf *rect) { - rect->xmin = rect->ymin = FLT_MAX; - rect->xmax = rect->ymax = FLT_MIN; + rect->xmin = rect->ymin = FLT_MAX; + rect->xmax = rect->ymax = -FLT_MAX; } -void BLI_rcti_do_minmax_v(struct rcti *rect, const int xy[2]) +void BLI_rcti_do_minmax_v(rcti *rect, const int xy[2]) { if (xy[0] < rect->xmin) rect->xmin = xy[0]; if (xy[0] > rect->xmax) rect->xmax = xy[0]; @@ -226,7 +226,7 @@ void BLI_rcti_do_minmax_v(struct rcti *rect, const int xy[2]) if (xy[1] > rect->ymax) rect->ymax = xy[1]; } -void BLI_rctf_do_minmax_v(struct rctf *rect, const float xy[2]) +void BLI_rctf_do_minmax_v(rctf *rect, const float xy[2]) { if (xy[0] < rect->xmin) rect->xmin = xy[0]; if (xy[0] > rect->xmax) rect->xmax = xy[0]; diff --git a/source/blender/blenlib/intern/stack.c b/source/blender/blenlib/intern/stack.c new file mode 100644 index 00000000000..5be2ed941a7 --- /dev/null +++ b/source/blender/blenlib/intern/stack.c @@ -0,0 +1,110 @@ +/* + * ***** 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. + * + * Contributor(s): Nicholas Bishop + * + * ***** END GPL LICENSE BLOCK ***** + * + */ + +/** \file blender/blenlib/intern/stack.c + * \ingroup bli + */ + +#include <string.h> +#include <stdlib.h> /* abort() */ + +#include "BLI_stack.h" /* own include */ + +#include "BLI_utildefines.h" +#include "MEM_guardedalloc.h" + +struct BLI_Stack { + void *data; + + int totelem; + int maxelem; + + int elem_size; +}; + +BLI_Stack *BLI_stack_new(int elem_size, const char *description) +{ + BLI_Stack *stack = MEM_callocN(sizeof(*stack), description); + + stack->elem_size = elem_size; + + return stack; +} + +void BLI_stack_free(BLI_Stack *stack) +{ + if (stack) { + if (stack->data) + MEM_freeN(stack->data); + MEM_freeN(stack); + } +} + +/* Gets the last element in the stack */ +#define STACK_LAST_ELEM(stack__) \ + (((char *)(stack__)->data) + \ + ((stack__)->elem_size * ((stack__)->totelem - 1))) + +void BLI_stack_push(BLI_Stack *stack, void *src) +{ + /* Ensure stack is large enough */ + if (stack->totelem == stack->maxelem) { + if (stack->maxelem == 0) { + /* Initialize stack with space for a small hardcoded + * number of elements */ + stack->maxelem = 32; + stack->data = MEM_mallocN((stack->elem_size * + stack->maxelem), AT); + } + else { + /* Double stack size */ + int maxelem = stack->maxelem + stack->maxelem; + /* Check for overflow */ + BLI_assert(maxelem > stack->maxelem); + stack->data = MEM_reallocN(stack->data, + (stack->elem_size * + maxelem)); + stack->maxelem = maxelem; + } + } + + BLI_assert(stack->totelem < stack->maxelem); + + /* Copy source to end of stack */ + stack->totelem++; + memcpy(STACK_LAST_ELEM(stack), src, stack->elem_size); +} + +void BLI_stack_pop(BLI_Stack *stack, void *dst) +{ + BLI_assert(stack->totelem > 0); + if (stack->totelem > 0) { + memcpy(dst, STACK_LAST_ELEM(stack), stack->elem_size); + stack->totelem--; + } +} + +int BLI_stack_empty(const BLI_Stack *stack) +{ + return stack->totelem == 0; +} diff --git a/source/blender/blenlib/intern/string_utf8.c b/source/blender/blenlib/intern/string_utf8.c index ff234a971aa..8047de2eeca 100644 --- a/source/blender/blenlib/intern/string_utf8.c +++ b/source/blender/blenlib/intern/string_utf8.c @@ -261,7 +261,9 @@ size_t BLI_strncpy_wchar_from_utf8(wchar_t *dst_w, const char *src_c, const size { int len=0; - if (dst_w==NULL || src_c==NULL) return(0); + if (dst_w == NULL || src_c == NULL) { + return 0; + } while (*src_c && len < maxcpy) { size_t step= 0; diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 29616898124..9bfd6c4fd88 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -4400,6 +4400,7 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb) smd->flow = NULL; smd->domain = NULL; smd->coll = newdataadr(fd, smd->coll); + smd->coll->smd = smd; if (smd->coll) { smd->coll->points = NULL; smd->coll->numpoints = 0; @@ -4875,8 +4876,8 @@ static void lib_link_scene(FileData *fd, Main *main) (void)marker; #endif - seq_update_muting(sce->ed); - seq_update_sound_bounds_all(sce); + BKE_sequencer_update_muting(sce->ed); + BKE_sequencer_update_sound_bounds_all(sce); if (sce->nodetree) { lib_link_ntree(fd, &sce->id, sce->nodetree); @@ -5463,7 +5464,7 @@ static int lib_link_seq_clipboard_cb(Sequence *seq, void *arg_pt) static void lib_link_clipboard_restore(Main *newmain) { /* update IDs stored in sequencer clipboard */ - seqbase_recursive_apply(&seqbase_clipboard, lib_link_seq_clipboard_cb, newmain); + BKE_sequencer_base_recursive_apply(&seqbase_clipboard, lib_link_seq_clipboard_cb, newmain); } /* called from kernel/blender.c */ @@ -8311,14 +8312,14 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath) /* ************* APPEND LIBRARY ************** */ -struct bheadsort { +struct BHeadSort { BHead *bhead; void *old; }; static int verg_bheadsort(const void *v1, const void *v2) { - const struct bheadsort *x1=v1, *x2=v2; + const struct BHeadSort *x1=v1, *x2=v2; if (x1->old > x2->old) return 1; else if (x1->old < x2->old) return -1; @@ -8328,7 +8329,7 @@ static int verg_bheadsort(const void *v1, const void *v2) static void sort_bhead_old_map(FileData *fd) { BHead *bhead; - struct bheadsort *bhs; + struct BHeadSort *bhs; int tot = 0; for (bhead = blo_firstbhead(fd); bhead; bhead = blo_nextbhead(fd, bhead)) @@ -8337,14 +8338,14 @@ static void sort_bhead_old_map(FileData *fd) fd->tot_bheadmap = tot; if (tot == 0) return; - bhs = fd->bheadmap = MEM_mallocN(tot*sizeof(struct bheadsort), "bheadsort"); + bhs = fd->bheadmap = MEM_mallocN(tot*sizeof(struct BHeadSort), STRINGIFY(BHeadSort)); for (bhead = blo_firstbhead(fd); bhead; bhead = blo_nextbhead(fd, bhead), bhs++) { bhs->bhead = bhead; bhs->old = bhead->old; } - qsort(fd->bheadmap, tot, sizeof(struct bheadsort), verg_bheadsort); + qsort(fd->bheadmap, tot, sizeof(struct BHeadSort), verg_bheadsort); } static BHead *find_previous_lib(FileData *fd, BHead *bhead) @@ -8366,7 +8367,7 @@ static BHead *find_bhead(FileData *fd, void *old) #if 0 BHead *bhead; #endif - struct bheadsort *bhs, bhs_s; + struct BHeadSort *bhs, bhs_s; if (!old) return NULL; @@ -8375,7 +8376,7 @@ static BHead *find_bhead(FileData *fd, void *old) sort_bhead_old_map(fd); bhs_s.old = old; - bhs = bsearch(&bhs_s, fd->bheadmap, fd->tot_bheadmap, sizeof(struct bheadsort), verg_bheadsort); + bhs = bsearch(&bhs_s, fd->bheadmap, fd->tot_bheadmap, sizeof(struct BHeadSort), verg_bheadsort); if (bhs) return bhs->bhead; @@ -9679,7 +9680,7 @@ static void read_libraries(FileData *basefd, ListBase *mainlist) fd = blo_openblenderfile(mainptr->curlib->filepath, basefd->reports); /* allow typing in a new lib path */ - if (G.rt == -666) { + if (G.debug_value == -666) { while (fd == NULL) { char newlib_path[FILE_MAX] = {0}; printf("Missing library...'\n"); diff --git a/source/blender/blenloader/intern/readfile.h b/source/blender/blenloader/intern/readfile.h index a3aa8e783a0..a979a16220d 100644 --- a/source/blender/blenloader/intern/readfile.h +++ b/source/blender/blenloader/intern/readfile.h @@ -84,7 +84,7 @@ typedef struct FileData { struct OldNewMap *imamap; struct OldNewMap *movieclipmap; - struct bheadsort *bheadmap; + struct BHeadSort *bheadmap; int tot_bheadmap; ListBase *mainlist; diff --git a/source/blender/blenloader/intern/undofile.c b/source/blender/blenloader/intern/undofile.c index 21a9290968b..38fd6e9d32d 100644 --- a/source/blender/blenloader/intern/undofile.c +++ b/source/blender/blenloader/intern/undofile.c @@ -104,7 +104,7 @@ void add_memfilechunk(MemFile *compare, MemFile *current, const char *buf, unsig static MemFileChunk *compchunk = NULL; MemFileChunk *curchunk; - /* this function inits when compare != NULL or when current==NULL */ + /* this function inits when compare != NULL or when current == NULL */ if (compare) { compchunk = compare->chunks.first; return; diff --git a/source/blender/blenloader/intern/versioning_250.c b/source/blender/blenloader/intern/versioning_250.c index ca071e0cc25..d551caea425 100644 --- a/source/blender/blenloader/intern/versioning_250.c +++ b/source/blender/blenloader/intern/versioning_250.c @@ -653,7 +653,7 @@ static void do_versions_seq_unique_name_all_strips(Scene * sce, ListBase *seqbas Sequence * seq = seqbasep->first; while (seq) { - seqbase_unique_name_recursive(&sce->ed->seqbase, seq); + BKE_seqence_base_unique_name_recursive(&sce->ed->seqbase, seq); if (seq->seqbase.first) { do_versions_seq_unique_name_all_strips(sce, &seq->seqbase); } diff --git a/source/blender/bmesh/operators/bmo_create.c b/source/blender/bmesh/operators/bmo_create.c index c17f23eb658..5fec9f259ee 100644 --- a/source/blender/bmesh/operators/bmo_create.c +++ b/source/blender/bmesh/operators/bmo_create.c @@ -1312,7 +1312,7 @@ void bmo_contextual_create_exec(BMesh *bm, BMOperator *op) * */ - /* Here we check for consistancy and create 2 edges */ + /* Here we check for consistency and create 2 edges */ if (totf == 0 && totv >= 4 && totv == tote + 2) { /* find a free standing vertex and 2 endpoint verts */ BMVert *v_free = NULL, *v_a = NULL, *v_b = NULL; diff --git a/source/blender/collada/AnimationExporter.cpp b/source/blender/collada/AnimationExporter.cpp index 57829f777c5..0e8ead61437 100644 --- a/source/blender/collada/AnimationExporter.cpp +++ b/source/blender/collada/AnimationExporter.cpp @@ -106,7 +106,8 @@ void AnimationExporter::operator()(Object *ob) if ((!strcmp(transformName, "lens")) || (!strcmp(transformName, "ortho_scale")) || - (!strcmp(transformName, "clip_end")) || (!strcmp(transformName, "clip_start"))) + (!strcmp(transformName, "clip_end")) || + (!strcmp(transformName, "clip_start"))) { dae_animation(ob, fcu, transformName, true); } @@ -203,8 +204,10 @@ void AnimationExporter::dae_animation(Object *ob, FCurve *fcu, char *transformNa } //axis names for colors - else if (!strcmp(transformName, "color") || !strcmp(transformName, "specular_color") || !strcmp(transformName, "diffuse_color") || - (!strcmp(transformName, "alpha"))) + else if (!strcmp(transformName, "color") || + !strcmp(transformName, "specular_color") || + !strcmp(transformName, "diffuse_color") || + !strcmp(transformName, "alpha")) { const char *axis_names[] = {"R", "G", "B"}; if (fcu->array_index < 3) @@ -212,8 +215,10 @@ void AnimationExporter::dae_animation(Object *ob, FCurve *fcu, char *transformNa } //axis names for transforms - else if ((!strcmp(transformName, "location") || !strcmp(transformName, "scale")) || - (!strcmp(transformName, "rotation_euler")) || (!strcmp(transformName, "rotation_quaternion"))) + else if (!strcmp(transformName, "location") || + !strcmp(transformName, "scale") || + !strcmp(transformName, "rotation_euler") || + !strcmp(transformName, "rotation_quaternion")) { const char *axis_names[] = {"X", "Y", "Z"}; if (fcu->array_index < 3) @@ -260,9 +265,13 @@ void AnimationExporter::dae_animation(Object *ob, FCurve *fcu, char *transformNa MEM_freeN(eul); MEM_freeN(eul_axis); } + else if(!strcmp(transformName, "lens") && (ob->type == OB_CAMERA)) { + output_id = create_lens_source_from_fcurve((Camera *) ob->data, COLLADASW::InputSemantic::OUTPUT, fcu, anim_id); + } else { output_id = create_source_from_fcurve(COLLADASW::InputSemantic::OUTPUT, fcu, anim_id, axis_name); } + // create interpolations source std::string interpolation_id = create_interpolation_source(fcu, anim_id, axis_name, &has_tangents); @@ -553,7 +562,7 @@ void AnimationExporter::add_source_parameters(COLLADASW::SourceBase::ParameterNa } } -void AnimationExporter::get_source_values(BezTriple *bezt, COLLADASW::InputSemantic::Semantics semantic, bool rotation, float *values, int *length) +void AnimationExporter::get_source_values(BezTriple *bezt, COLLADASW::InputSemantic::Semantics semantic, bool is_rotation, float *values, int *length) { switch (semantic) { case COLLADASW::InputSemantic::INPUT: @@ -562,7 +571,7 @@ void AnimationExporter::get_source_values(BezTriple *bezt, COLLADASW::InputSeman break; case COLLADASW::InputSemantic::OUTPUT: *length = 1; - if (rotation) { + if (is_rotation) { values[0] = RAD2DEGF(bezt->vec[1][1]); } else { @@ -578,7 +587,7 @@ void AnimationExporter::get_source_values(BezTriple *bezt, COLLADASW::InputSeman values[0] = 0; values[1] = 0; } - else if (rotation) { + else if (is_rotation) { values[1] = RAD2DEGF(bezt->vec[0][1]); } else { @@ -594,7 +603,7 @@ void AnimationExporter::get_source_values(BezTriple *bezt, COLLADASW::InputSeman values[0] = 0; values[1] = 0; } - else if (rotation) { + else if (is_rotation) { values[1] = RAD2DEGF(bezt->vec[2][1]); } else { @@ -654,6 +663,44 @@ std::string AnimationExporter::create_source_from_fcurve(COLLADASW::InputSemanti return source_id; } +/* + * Similar to create_source_from_fcurve, but adds conversion of lens + * animation data from focal length to FOV. + */ +std::string AnimationExporter::create_lens_source_from_fcurve(Camera *cam, COLLADASW::InputSemantic::Semantics semantic, FCurve *fcu, const std::string& anim_id) +{ + std::string source_id = anim_id + get_semantic_suffix(semantic); + + COLLADASW::FloatSourceF source(mSW); + source.setId(source_id); + source.setArrayId(source_id + ARRAY_ID_SUFFIX); + source.setAccessorCount(fcu->totvert); + + source.setAccessorStride(1); + + COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList(); + add_source_parameters(param, semantic, false, "", false); + + source.prepareToAppendValues(); + + for (unsigned int i = 0; i < fcu->totvert; i++) { + float values[3]; // be careful! + int length = 0; + get_source_values(&fcu->bezt[i], semantic, false, values, &length); + for (int j = 0; j < length; j++) + { + float val = RAD2DEGF(focallength_to_fov(values[j], cam->sensor_x)); + source.appendValues(val); + } + } + + source.finish(); + + return source_id; +} + + + //Currently called only to get OUTPUT source values ( if rotation and hence the axis is also specified ) std::string AnimationExporter::create_source_from_array(COLLADASW::InputSemantic::Semantics semantic, float *v, int tot, bool is_rot, const std::string& anim_id, const char *axis_name) { diff --git a/source/blender/collada/AnimationExporter.h b/source/blender/collada/AnimationExporter.h index 1313687db28..0a7832e9d64 100644 --- a/source/blender/collada/AnimationExporter.h +++ b/source/blender/collada/AnimationExporter.h @@ -133,6 +133,8 @@ protected: std::string create_source_from_fcurve(COLLADASW::InputSemantic::Semantics semantic, FCurve *fcu, const std::string& anim_id, const char *axis_name); + std::string create_lens_source_from_fcurve(Camera *cam, COLLADASW::InputSemantic::Semantics semantic, FCurve *fcu, const std::string& anim_id); + std::string create_source_from_array(COLLADASW::InputSemantic::Semantics semantic, float *v, int tot, bool is_rot, const std::string& anim_id, const char *axis_name); std::string create_source_from_vector(COLLADASW::InputSemantic::Semantics semantic, std::vector<float> &fra, bool is_rot, const std::string& anim_id, const char *axis_name); diff --git a/source/blender/collada/AnimationImporter.cpp b/source/blender/collada/AnimationImporter.cpp index 9c11358ce7f..a237222774d 100644 --- a/source/blender/collada/AnimationImporter.cpp +++ b/source/blender/collada/AnimationImporter.cpp @@ -652,6 +652,51 @@ void AnimationImporter:: Assign_float_animations(const COLLADAFW::UniqueId& list } +/* + * Lens animations must be stored in COLLADA by using FOV, + * while blender internally uses focal length. + * The imported animation curves must be converted appropriately. + */ +void AnimationImporter::Assign_lens_animations(const COLLADAFW::UniqueId& listid, ListBase *AnimCurves, const double aspect, Camera *cam, const char *anim_type, int fov_type) +{ + char rna_path[100]; + if (animlist_map.find(listid) == animlist_map.end()) { + return; + } + else { + //anim_type has animations + const COLLADAFW::AnimationList *animlist = animlist_map[listid]; + const COLLADAFW::AnimationList::AnimationBindings& bindings = animlist->getAnimationBindings(); + //all the curves belonging to the current binding + std::vector<FCurve *> animcurves; + for (unsigned int j = 0; j < bindings.getCount(); j++) { + animcurves = curve_map[bindings[j].animation]; + + BLI_strncpy(rna_path, anim_type, sizeof(rna_path)); + + modify_fcurve(&animcurves, rna_path, 0); + std::vector<FCurve *>::iterator iter; + //Add the curves of the current animation to the object + for (iter = animcurves.begin(); iter != animcurves.end(); iter++) { + FCurve *fcu = *iter; + + for (unsigned int i = 0; i < fcu->totvert; i++) { + + double input_fov = fcu->bezt[i].vec[1][1]; + double xfov = (fov_type == CAMERA_YFOV) ? aspect * input_fov : input_fov; + + // fov is in degrees, cam->lens is in millimiters + double fov = fov_to_focallength(DEG2RADF(input_fov), cam->sensor_x); + + fcu->bezt[i].vec[1][1] = fov; + } + + BLI_addtail(AnimCurves, fcu); + } + } + } +} + void AnimationImporter::apply_matrix_curves(Object *ob, std::vector<FCurve *>& animcurves, COLLADAFW::Node *root, COLLADAFW::Node *node, COLLADAFW::Transformation *tm) { @@ -796,6 +841,39 @@ void AnimationImporter::apply_matrix_curves(Object *ob, std::vector<FCurve *>& a } +/* + * This function returns the aspet ration from the Collada camera. + * + * Note:COLLADA allows to specify either XFov, or YFov alone. + * In tghat case the aspect ratio can be determined from + * the viewport aspect ratio (which is 1:1 ?) + * XXX: check this: its probably wrong! + * If both values are specified, then the aspect ration is simply xfov/yfov + * and if aspect ratio is efined, then .. well then its that one. + */ +static const double get_aspect_ratio(const COLLADAFW::Camera *camera) +{ + double aspect = camera->getAspectRatio().getValue(); + + if(aspect == 0) + { + const double yfov = camera->getYFov().getValue(); + + if(yfov == 0) + aspect=1; // assume yfov and xfov are equal + else + { + const double xfov = camera->getXFov().getValue(); + if (xfov==0) + aspect = 1; + else + aspect = xfov / yfov; + } + } + return aspect; +} + + void AnimationImporter::translate_Animations(COLLADAFW::Node *node, std::map<COLLADAFW::UniqueId, COLLADAFW::Node *>& root_map, std::multimap<COLLADAFW::UniqueId, Object *>& object_map, @@ -804,8 +882,15 @@ void AnimationImporter::translate_Animations(COLLADAFW::Node *node, AnimationImporter::AnimMix *animType = get_animation_type(node, FW_object_map); bool is_joint = node->getType() == COLLADAFW::Node::JOINT; - COLLADAFW::Node *root = root_map.find(node->getUniqueId()) == root_map.end() ? node : root_map[node->getUniqueId()]; - Object *ob = is_joint ? armature_importer->get_armature_for_joint(root) : object_map.find(node->getUniqueId())->second; + COLLADAFW::UniqueId uid = node->getUniqueId(); + COLLADAFW::Node *root = root_map.find(uid) == root_map.end() ? node : root_map[uid]; + + Object *ob; + if(is_joint) + ob = armature_importer->get_armature_for_joint(root); + else + ob = object_map.find(uid) == object_map.end() ? NULL : object_map.find(uid)->second; + if (!ob) { fprintf(stderr, "cannot find Object for Node with id=\"%s\"\n", node->getOriginalId().c_str()); return; @@ -917,10 +1002,11 @@ void AnimationImporter::translate_Animations(COLLADAFW::Node *node, } if (animType->camera != 0) { - Camera *camera = (Camera *) ob->data; - - if (!camera->adt || !camera->adt->action) act = verify_adt_action((ID *)&camera->id, 1); - else act = camera->adt->action; + Camera *cam = (Camera *) ob->data; + if (!cam->adt || !cam->adt->action) + act = verify_adt_action((ID *)&cam->id, 1); + else + act = cam->adt->action; ListBase *AnimCurves = &(act->curves); const COLLADAFW::InstanceCameraPointerArray& nodeCameras = node->getInstanceCameras(); @@ -931,7 +1017,15 @@ void AnimationImporter::translate_Animations(COLLADAFW::Node *node, if ((animType->camera & CAMERA_XFOV) != 0) { const COLLADAFW::AnimatableFloat *xfov = &(camera->getXFov()); const COLLADAFW::UniqueId& listid = xfov->getAnimationList(); - Assign_float_animations(listid, AnimCurves, "lens"); + double aspect = get_aspect_ratio(camera); + Assign_lens_animations(listid, AnimCurves, aspect, cam, "lens", CAMERA_XFOV); + } + + else if ((animType->camera & CAMERA_YFOV) != 0) { + const COLLADAFW::AnimatableFloat *yfov = &(camera->getYFov()); + const COLLADAFW::UniqueId& listid = yfov->getAnimationList(); + double aspect = get_aspect_ratio(camera); + Assign_lens_animations(listid, AnimCurves, aspect, cam, "lens", CAMERA_YFOV); } else if ((animType->camera & CAMERA_XMAG) != 0) { @@ -940,6 +1034,12 @@ void AnimationImporter::translate_Animations(COLLADAFW::Node *node, Assign_float_animations(listid, AnimCurves, "ortho_scale"); } + else if ((animType->camera & CAMERA_YMAG) != 0) { + const COLLADAFW::AnimatableFloat *ymag = &(camera->getYMag()); + const COLLADAFW::UniqueId& listid = ymag->getAnimationList(); + Assign_float_animations(listid, AnimCurves, "ortho_scale"); + } + if ((animType->camera & CAMERA_ZFAR) != 0) { const COLLADAFW::AnimatableFloat *zfar = &(camera->getFarClippingPlane()); const COLLADAFW::UniqueId& listid = zfar->getAnimationList(); @@ -1166,14 +1266,27 @@ AnimationImporter::AnimMix *AnimationImporter::get_animation_type(const COLLADAF const COLLADAFW::InstanceCameraPointerArray& nodeCameras = node->getInstanceCameras(); for (unsigned int i = 0; i < nodeCameras.getCount(); i++) { - const COLLADAFW::Camera *camera = (COLLADAFW::Camera *) FW_object_map[nodeCameras[i]->getInstanciatedObjectId()]; + const COLLADAFW::Camera *camera = (COLLADAFW::Camera *) FW_object_map[nodeCameras[i]->getInstanciatedObjectId()]; + if ( camera == NULL ) { + // Can happen if the node refers to an unknown camera. + continue; + } + + const bool is_perspective_type = camera->getCameraType() == COLLADAFW::Camera::PERSPECTIVE; - if (camera->getCameraType() == COLLADAFW::Camera::PERSPECTIVE) { - types->camera = setAnimType(&(camera->getXMag()), (types->camera), CAMERA_XFOV); + int addition; + const COLLADAFW::Animatable *mag; + const COLLADAFW::UniqueId listid = camera->getYMag().getAnimationList(); + if (animlist_map.find(listid) != animlist_map.end()) { + mag = &(camera->getYMag()); + addition = (is_perspective_type) ? CAMERA_YFOV: CAMERA_YMAG; } else { - types->camera = setAnimType(&(camera->getXMag()), (types->camera), CAMERA_XMAG); + mag = &(camera->getXMag()); + addition = (is_perspective_type) ? CAMERA_XFOV: CAMERA_XMAG; } + types->camera = setAnimType(mag, (types->camera), addition); + types->camera = setAnimType(&(camera->getFarClippingPlane()), (types->camera), CAMERA_ZFAR); types->camera = setAnimType(&(camera->getNearClippingPlane()), (types->camera), CAMERA_ZNEAR); @@ -1205,10 +1318,14 @@ AnimationImporter::AnimMix *AnimationImporter::get_animation_type(const COLLADAF int AnimationImporter::setAnimType(const COLLADAFW::Animatable *prop, int types, int addition) { - const COLLADAFW::UniqueId& listid = prop->getAnimationList(); + int anim_type; + const COLLADAFW::UniqueId& listid = prop->getAnimationList(); if (animlist_map.find(listid) != animlist_map.end()) - return types | addition; - else return types; + anim_type = types | addition; + else + anim_type = types; + + return anim_type; } // Is not used anymore. diff --git a/source/blender/collada/AnimationImporter.h b/source/blender/collada/AnimationImporter.h index d6a93a36c6e..db61692484b 100644 --- a/source/blender/collada/AnimationImporter.h +++ b/source/blender/collada/AnimationImporter.h @@ -102,8 +102,10 @@ private: // INANIMATE = 0, CAMERA_XFOV = 2, CAMERA_XMAG = 4, - CAMERA_ZFAR = 8, - CAMERA_ZNEAR = 16 + CAMERA_YFOV = 8, + CAMERA_YMAG = 16, + CAMERA_ZFAR = 32, + CAMERA_ZNEAR = 64 }; enum matAnim @@ -163,6 +165,7 @@ public: void Assign_color_animations(const COLLADAFW::UniqueId& listid, ListBase *AnimCurves, const char * anim_type); void Assign_float_animations(const COLLADAFW::UniqueId& listid, ListBase *AnimCurves, const char * anim_type); + void Assign_lens_animations(const COLLADAFW::UniqueId& listid, ListBase *AnimCurves, const double aspect, Camera *cam, const char *anim_type, int fov_type); int setAnimType ( const COLLADAFW::Animatable * prop, int type, int addition); diff --git a/source/blender/collada/CameraExporter.cpp b/source/blender/collada/CameraExporter.cpp index be424fbbb4d..7d438f7f12f 100644 --- a/source/blender/collada/CameraExporter.cpp +++ b/source/blender/collada/CameraExporter.cpp @@ -84,7 +84,7 @@ void CamerasExporter::operator()(Object *ob, Scene *sce) default: { COLLADASW::OrthographicOptic ortho(mSW); - ortho.setXMag(cam->ortho_scale, "xmag"); + ortho.setXMag(cam->ortho_scale / 2, "xmag"); ortho.setAspectRatio((float)(sce->r.xsch) / (float)(sce->r.ysch), false, "aspect_ratio"); ortho.setZFar(cam->clipend, false, "zfar"); ortho.setZNear(cam->clipsta, false, "znear"); diff --git a/source/blender/collada/DocumentImporter.cpp b/source/blender/collada/DocumentImporter.cpp index ca07512f439..7cfce9d2526 100644 --- a/source/blender/collada/DocumentImporter.cpp +++ b/source/blender/collada/DocumentImporter.cpp @@ -308,7 +308,7 @@ Object *DocumentImporter::create_camera_object(COLLADAFW::InstanceCamera *camera { const COLLADAFW::UniqueId& cam_uid = camera->getInstanciatedObjectId(); if (uid_camera_map.find(cam_uid) == uid_camera_map.end()) { - fprintf(stderr, "Couldn't find camera by UID.\n"); + // fprintf(stderr, "Couldn't find camera by UID.\n"); return NULL; } @@ -443,7 +443,13 @@ void DocumentImporter::write_node(COLLADAFW::Node *node, COLLADAFW::Node *parent } while (camera_done < camera.getCount()) { ob = create_camera_object(camera[camera_done], sce); - objects_done->push_back(ob); + if (ob == NULL) { + std::string id = node->getOriginalId(); + std::string name = node->getName(); + fprintf(stderr, "<node id=\"%s\", name=\"%s\" >...contains a reference to an unknown instance_camera.\n", id.c_str(), name.c_str()); + } + else + objects_done->push_back(ob); ++camera_done; } while (lamp_done < lamp.getCount()) { @@ -846,7 +852,7 @@ bool DocumentImporter::writeCamera(const COLLADAFW::Camera *camera) switch (cam->type) { case CAM_ORTHO: { - double ymag = camera->getYMag().getValue(); + double ymag = 2 * camera->getYMag().getValue(); double aspect = camera->getAspectRatio().getValue(); double xmag = aspect * ymag; cam->ortho_scale = (float)xmag; @@ -873,7 +879,7 @@ bool DocumentImporter::writeCamera(const COLLADAFW::Camera *camera) { switch (cam->type) { case CAM_ORTHO: - cam->ortho_scale = (float)camera->getXMag().getValue(); + cam->ortho_scale = (float)camera->getXMag().getValue() * 2; break; case CAM_PERSP: default: diff --git a/source/blender/compositor/CMakeLists.txt b/source/blender/compositor/CMakeLists.txt index 870e379b343..550441be9b7 100644 --- a/source/blender/compositor/CMakeLists.txt +++ b/source/blender/compositor/CMakeLists.txt @@ -50,6 +50,21 @@ set(INC_SYS ) +# --- data file --- +# ... may make this a macro +list(APPEND INC + ${CMAKE_CURRENT_BINARY_DIR}/operations +) +add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/operations/COM_OpenCLKernels.cl.h + COMMAND ${CMAKE_COMMAND} + -DFILE_FROM=${CMAKE_CURRENT_SOURCE_DIR}/operations/COM_OpenCLKernels.cl + -DFILE_TO=${CMAKE_CURRENT_BINARY_DIR}/operations/COM_OpenCLKernels.cl.h + -DVAR_NAME=clkernelstoh_COM_OpenCLKernels_cl + -P ${CMAKE_SOURCE_DIR}/build_files/cmake/data_to_c.cmake + DEPENDS operations/COM_OpenCLKernels.cl) +# --- end data file -- + set(SRC COM_compositor.h COM_defines.h @@ -286,6 +301,8 @@ set(SRC nodes/COM_FilterNode.h nodes/COM_DilateErodeNode.cpp nodes/COM_DilateErodeNode.h + nodes/COM_InpaintNode.cpp + nodes/COM_InpaintNode.h nodes/COM_BlurNode.cpp nodes/COM_BlurNode.h nodes/COM_BokehBlurNode.cpp @@ -590,6 +607,8 @@ set(SRC operations/COM_ConvolutionEdgeFilterOperation.cpp operations/COM_DilateErodeOperation.cpp operations/COM_DilateErodeOperation.h + operations/COM_InpaintOperation.cpp + operations/COM_InpaintOperation.h operations/COM_GlareThresholdOperation.cpp operations/COM_GlareThresholdOperation.h operations/COM_GlareBaseOperation.cpp @@ -634,6 +653,9 @@ set(SRC operations/COM_MaskOperation.cpp operations/COM_MaskOperation.h + + # generated file + ${CMAKE_CURRENT_BINARY_DIR}/operations/COM_OpenCLKernels.cl.h ) blender_add_lib(bf_compositor "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/compositor/COM_compositor.h b/source/blender/compositor/COM_compositor.h index cd1615c9094..4e955ea3df1 100644 --- a/source/blender/compositor/COM_compositor.h +++ b/source/blender/compositor/COM_compositor.h @@ -297,7 +297,7 @@ extern "C" { * - output nodes can have different priorities in the WorkScheduler. * This is implemented in the COM_execute function. */ -void COM_execute(RenderData* rd, bNodeTree *editingtree, int rendering); +void COM_execute(RenderData *rd, bNodeTree *editingtree, int rendering); /** * @brief Return a list of highlighted bnodes pointers. @@ -310,7 +310,7 @@ void COM_startReadHighlights(void); * @param bnode * @return */ -int COM_isHighlightedbNode(bNode* bnode); +int COM_isHighlightedbNode(bNode *bnode); #ifdef __cplusplus } diff --git a/source/blender/compositor/COM_defines.h b/source/blender/compositor/COM_defines.h index e11048b23f3..3cc161a5877 100644 --- a/source/blender/compositor/COM_defines.h +++ b/source/blender/compositor/COM_defines.h @@ -107,4 +107,6 @@ typedef enum OrderOfChunks { #define COM_NUMBER_OF_CHANNELS 4 +#define COM_BLUR_BOKEH_PIXELS 512 + #endif diff --git a/source/blender/compositor/SConscript b/source/blender/compositor/SConscript index d7f18cfa436..9f947ca7327 100644 --- a/source/blender/compositor/SConscript +++ b/source/blender/compositor/SConscript @@ -11,4 +11,7 @@ incs += '../opencl ../nodes ../nodes/intern ../nodes/composite ' if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc'): incs += ' ' + env['BF_PTHREADS_INC'] +# data files +incs += ' ' + env['DATA_HEADERS'] + env.BlenderLib ( 'bf_composite', sources, Split(incs), defines=defs, libtype=['core'], priority = [164] ) diff --git a/source/blender/compositor/intern/COM_Converter.cpp b/source/blender/compositor/intern/COM_Converter.cpp index 37d38261ea5..24c3c36b79e 100644 --- a/source/blender/compositor/intern/COM_Converter.cpp +++ b/source/blender/compositor/intern/COM_Converter.cpp @@ -74,6 +74,7 @@ #include "COM_HueSaturationValueNode.h" #include "COM_IDMaskNode.h" #include "COM_ImageNode.h" +#include "COM_InpaintNode.h" #include "COM_InvertNode.h" #include "COM_KeyingNode.h" #include "COM_KeyingScreenNode.h" @@ -303,6 +304,9 @@ Node *Converter::convert(bNode *b_node, bool fast) case CMP_NODE_DILATEERODE: node = new DilateErodeNode(b_node); break; + case CMP_NODE_INPAINT: + node = new InpaintNode(b_node); + break; case CMP_NODE_LENSDIST: node = new LensDistortionNode(b_node); break; diff --git a/source/blender/compositor/intern/COM_ExecutionGroup.cpp b/source/blender/compositor/intern/COM_ExecutionGroup.cpp index 46a0db7af2d..30875afcb3f 100644 --- a/source/blender/compositor/intern/COM_ExecutionGroup.cpp +++ b/source/blender/compositor/intern/COM_ExecutionGroup.cpp @@ -186,7 +186,7 @@ void ExecutionGroup::deinitExecution() this->m_cachedReadOperations.clear(); this->m_bTree = NULL; } -void ExecutionGroup::determineResolution(unsigned int resolution[]) +void ExecutionGroup::determineResolution(unsigned int resolution[2]) { NodeOperation *operation = this->getOutputNodeOperation(); resolution[0] = operation->getWidth(); diff --git a/source/blender/compositor/intern/COM_ExecutionGroup.h b/source/blender/compositor/intern/COM_ExecutionGroup.h index e890715cafe..c7a7d06134e 100644 --- a/source/blender/compositor/intern/COM_ExecutionGroup.h +++ b/source/blender/compositor/intern/COM_ExecutionGroup.h @@ -270,13 +270,13 @@ public: * @brief determine the resolution of this ExecutionGroup * @param resolution */ - void determineResolution(unsigned int resolution[]); + void determineResolution(unsigned int resolution[2]); /** * @brief set the resolution of this executiongroup * @param resolution */ - void setResolution(unsigned int resolution[]) { this->m_width = resolution[0]; this->m_height = resolution[1]; } + void setResolution(unsigned int resolution[2]) { this->m_width = resolution[0]; this->m_height = resolution[1]; } /** * @brief get the width of this execution group @@ -316,7 +316,7 @@ public: * @brief get all inputbuffers needed to calculate an chunk * @note all inputbuffers must be executed * @param chunkNumber the chunk to be calculated - * @return MemoryBuffer** the inputbuffers + * @return (MemoryBuffer **) the inputbuffers */ MemoryBuffer **getInputBuffersCPU(); @@ -324,7 +324,7 @@ public: * @brief get all inputbuffers needed to calculate an chunk * @note all inputbuffers must be executed * @param chunkNumber the chunk to be calculated - * @return MemoryBuffer** the inputbuffers + * @return (MemoryBuffer **) the inputbuffers */ MemoryBuffer **getInputBuffersOpenCL(int chunkNumber); diff --git a/source/blender/compositor/intern/COM_ExecutionSystem.h b/source/blender/compositor/intern/COM_ExecutionSystem.h index 4f6780c8d0b..ac849bf4f6c 100644 --- a/source/blender/compositor/intern/COM_ExecutionSystem.h +++ b/source/blender/compositor/intern/COM_ExecutionSystem.h @@ -153,7 +153,7 @@ public: * @brief Create a new ExecutionSystem and initialize it with the * editingtree. * - * @param editingtree [bNodeTree*] + * @param editingtree [bNodeTree *] * @param rendering [true false] */ ExecutionSystem(RenderData *rd, bNodeTree *editingtree, bool rendering, bool fastcalculation); diff --git a/source/blender/compositor/intern/COM_ExecutionSystemHelper.cpp b/source/blender/compositor/intern/COM_ExecutionSystemHelper.cpp index 4627d20ab2f..e41361fcb2e 100644 --- a/source/blender/compositor/intern/COM_ExecutionSystemHelper.cpp +++ b/source/blender/compositor/intern/COM_ExecutionSystemHelper.cpp @@ -154,12 +154,9 @@ static OutputSocket *find_output(NodeRange &node_range, bNode *bnode, bNodeSocke } SocketConnection *ExecutionSystemHelper::addNodeLink(NodeRange &node_range, vector<SocketConnection *>& links, bNodeLink *b_nodelink) { - /// @note: cyclic lines will be ignored. This has been copied from node.c - if (b_nodelink->tonode != 0 && b_nodelink->fromnode != 0) { - if (!(b_nodelink->fromnode->level >= b_nodelink->tonode->level && b_nodelink->tonode->level != 0xFFF)) { // only add non cyclic lines! so execution will procede - return NULL; - } - } + /// @note: ignore invalid links + if (!(b_nodelink->flag & NODE_LINK_VALID)) + return NULL; InputSocket *inputSocket = find_input(node_range, b_nodelink->tonode, b_nodelink->tosock); OutputSocket *outputSocket = find_output(node_range, b_nodelink->fromnode, b_nodelink->fromsock); diff --git a/source/blender/compositor/intern/COM_InputSocket.cpp b/source/blender/compositor/intern/COM_InputSocket.cpp index 94cb5ff5396..a9c280e0367 100644 --- a/source/blender/compositor/intern/COM_InputSocket.cpp +++ b/source/blender/compositor/intern/COM_InputSocket.cpp @@ -54,7 +54,7 @@ SocketConnection *InputSocket::getConnection() return this->m_connection; } -void InputSocket::determineResolution(unsigned int resolution[], unsigned int preferredResolution[]) +void InputSocket::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]) { if (this->isConnected()) { this->m_connection->getFromSocket()->determineResolution(resolution, preferredResolution); diff --git a/source/blender/compositor/intern/COM_InputSocket.h b/source/blender/compositor/intern/COM_InputSocket.h index 5d0923ff204..259479015aa 100644 --- a/source/blender/compositor/intern/COM_InputSocket.h +++ b/source/blender/compositor/intern/COM_InputSocket.h @@ -89,7 +89,7 @@ public: * @param resolution the result of this operation * @param preferredResolution the preferrable resolution as no resolution could be determined */ - void determineResolution(unsigned int resolution[], unsigned int preferredResolution[]); + void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]); /** * @brief Notifies the Input of the data type (via a SocketConnection) diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.cpp b/source/blender/compositor/intern/COM_MemoryBuffer.cpp index f8c842d8e67..3b8fbd6d708 100644 --- a/source/blender/compositor/intern/COM_MemoryBuffer.cpp +++ b/source/blender/compositor/intern/COM_MemoryBuffer.cpp @@ -105,13 +105,24 @@ float MemoryBuffer::getMaximumValue() return result; } -float MemoryBuffer::getMaximumValue(rcti* rect) +float MemoryBuffer::getMaximumValue(rcti *rect) { - MemoryBuffer *temp = new MemoryBuffer(NULL, rect); - temp->copyContentFrom(this); - float result = temp->getMaximumValue(); - delete temp; - return result; + rcti rect_clamp; + + /* first clamp the rect by the bounds or we get un-initialized values */ + BLI_rcti_isect(rect, &this->m_rect, &rect_clamp); + + if (!BLI_rcti_is_empty(&rect_clamp)) { + MemoryBuffer *temp = new MemoryBuffer(NULL, &rect_clamp); + temp->copyContentFrom(this); + float result = temp->getMaximumValue(); + delete temp; + return result; + } + else { + BLI_assert(0); + return 0.0f; + } } MemoryBuffer::~MemoryBuffer() @@ -125,6 +136,7 @@ MemoryBuffer::~MemoryBuffer() void MemoryBuffer::copyContentFrom(MemoryBuffer *otherBuffer) { if (!otherBuffer) { + BLI_assert(0); return; } unsigned int otherY; @@ -236,7 +248,7 @@ static void imp2radangle(float A, float B, float C, float F, float *a, float *b, *b = sqrtf(F2 / d); *ecc = *a / *b; } - // incr theta by 0.5*pi (angle of major axis) + /* incr theta by 0.5 * pi (angle of major axis) */ *th = 0.5f * (atan2f(B, AmC) + (float)M_PI); } } diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.h b/source/blender/compositor/intern/COM_MemoryBuffer.h index 411c5b9ad8a..5d0d9c97450 100644 --- a/source/blender/compositor/intern/COM_MemoryBuffer.h +++ b/source/blender/compositor/intern/COM_MemoryBuffer.h @@ -26,14 +26,12 @@ class MemoryBuffer; #define _COM_MemoryBuffer_h_ #include "COM_ExecutionGroup.h" -#include "BLI_rect.h" #include "COM_MemoryProxy.h" extern "C" { - //#include "BLI_threads.h" #include "BLI_math.h" + #include "BLI_rect.h" } -//#include <vector> /** * @brief state of a memory buffer @@ -147,6 +145,18 @@ public: const int dx = x - this->m_rect.xmin; const int dy = y - this->m_rect.ymin; const int offset = (this->m_chunkWidth * dy + dx) * COM_NUMBER_OF_CHANNELS; + + BLI_assert(offset >= 0); + BLI_assert(offset < this->determineBufferSize() * COM_NUMBER_OF_CHANNELS); + BLI_assert(x >= this->m_rect.xmin && x < this->m_rect.xmax && + y >= this->m_rect.ymin && y < this->m_rect.ymax); + +#if 0 + /* always true */ + BLI_assert((int)(MEM_allocN_len(this->m_buffer) / sizeof(*this->m_buffer)) == + (int)(this->determineBufferSize() * COM_NUMBER_OF_CHANNELS)); +#endif + copy_v4_v4(result, &this->m_buffer[offset]); } @@ -202,6 +212,9 @@ public: /** * @brief add the content from otherBuffer to this MemoryBuffer * @param otherBuffer source buffer + * + * @note take care when running this on a new buffer since it wont fill in + * uninitialized values in areas where the buffers don't overlap. */ void copyContentFrom(MemoryBuffer *otherBuffer); @@ -229,7 +242,7 @@ public: float *convertToValueBuffer(); float getMaximumValue(); - float getMaximumValue(rcti* rect); + float getMaximumValue(rcti *rect); private: unsigned int determineBufferSize(); diff --git a/source/blender/compositor/intern/COM_NodeOperation.cpp b/source/blender/compositor/intern/COM_NodeOperation.cpp index 9baab584d9e..bae884d713e 100644 --- a/source/blender/compositor/intern/COM_NodeOperation.cpp +++ b/source/blender/compositor/intern/COM_NodeOperation.cpp @@ -38,7 +38,7 @@ NodeOperation::NodeOperation() : NodeBase() this->m_btree = NULL; } -void NodeOperation::determineResolution(unsigned int resolution[], unsigned int preferredResolution[]) +void NodeOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]) { unsigned int temp[2]; unsigned int temp2[2]; diff --git a/source/blender/compositor/intern/COM_NodeOperation.h b/source/blender/compositor/intern/COM_NodeOperation.h index 9b6d574e321..93a19529d34 100644 --- a/source/blender/compositor/intern/COM_NodeOperation.h +++ b/source/blender/compositor/intern/COM_NodeOperation.h @@ -96,7 +96,7 @@ public: * @param resolution the result of this operation * @param preferredResolution the preferrable resolution as no resolution could be determined */ - virtual void determineResolution(unsigned int resolution[], unsigned int preferredResolution[]); + virtual void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]); /** * @brief isOutputOperation determines whether this operation is an output of the ExecutionSystem during rendering or editing. @@ -148,7 +148,7 @@ public: * @param memoryBuffers all input MemoryBuffer's needed * @param outputBuffer the outputbuffer to write to */ - virtual void executeOpenCLRegion(OpenCLDevice* device, rcti *rect, + virtual void executeOpenCLRegion(OpenCLDevice *device, rcti *rect, unsigned int chunkNumber, MemoryBuffer **memoryBuffers, MemoryBuffer *outputBuffer) {} /** @@ -163,7 +163,7 @@ public: * @param clMemToCleanUp all created cl_mem references must be added to this list. Framework will clean this after execution * @param clKernelsToCleanUp all created cl_kernel references must be added to this list. Framework will clean this after execution */ - virtual void executeOpenCL(OpenCLDevice* device, MemoryBuffer *outputMemoryBuffer, cl_mem clOutputBuffer, MemoryBuffer **inputMemoryBuffers, list<cl_mem> *clMemToCleanUp, list<cl_kernel> *clKernelsToCleanUp) {} + virtual void executeOpenCL(OpenCLDevice *device, MemoryBuffer *outputMemoryBuffer, cl_mem clOutputBuffer, MemoryBuffer **inputMemoryBuffers, list<cl_mem> *clMemToCleanUp, list<cl_kernel> *clKernelsToCleanUp) {} virtual void deinitExecution(); bool isResolutionSet() { @@ -174,7 +174,7 @@ public: * @brief set the resolution * @param resolution the resolution to set */ - void setResolution(unsigned int resolution[]) { + void setResolution(unsigned int resolution[2]) { if (!isResolutionSet()) { this->m_width = resolution[0]; this->m_height = resolution[1]; diff --git a/source/blender/compositor/intern/COM_OpenCLDevice.cpp b/source/blender/compositor/intern/COM_OpenCLDevice.cpp index 63f75681779..be5936b495e 100644 --- a/source/blender/compositor/intern/COM_OpenCLDevice.cpp +++ b/source/blender/compositor/intern/COM_OpenCLDevice.cpp @@ -67,7 +67,7 @@ void OpenCLDevice::execute(WorkPackage *work) } cl_mem OpenCLDevice::COM_clAttachMemoryBufferToKernelParameter(cl_kernel kernel, int parameterIndex, int offsetIndex, list<cl_mem> *cleanup, MemoryBuffer **inputMemoryBuffers, SocketReader *reader) { - return COM_clAttachMemoryBufferToKernelParameter(kernel, parameterIndex, offsetIndex, cleanup, inputMemoryBuffers, (ReadBufferOperation*)reader); + return COM_clAttachMemoryBufferToKernelParameter(kernel, parameterIndex, offsetIndex, cleanup, inputMemoryBuffers, (ReadBufferOperation *)reader); } cl_mem OpenCLDevice::COM_clAttachMemoryBufferToKernelParameter(cl_kernel kernel, int parameterIndex, int offsetIndex, list<cl_mem> *cleanup, MemoryBuffer **inputMemoryBuffers, ReadBufferOperation *reader) @@ -106,7 +106,7 @@ void OpenCLDevice::COM_clAttachMemoryBufferOffsetToKernelParameter(cl_kernel ker } } -void OpenCLDevice::COM_clAttachSizeToKernelParameter(cl_kernel kernel, int offsetIndex, NodeOperation* operation) +void OpenCLDevice::COM_clAttachSizeToKernelParameter(cl_kernel kernel, int offsetIndex, NodeOperation *operation) { if (offsetIndex != -1) { cl_int error; @@ -133,7 +133,7 @@ void OpenCLDevice::COM_clEnqueueRange(cl_kernel kernel, MemoryBuffer *outputMemo if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); } } -void OpenCLDevice::COM_clEnqueueRange(cl_kernel kernel, MemoryBuffer *outputMemoryBuffer, int offsetIndex, NodeOperation* operation) +void OpenCLDevice::COM_clEnqueueRange(cl_kernel kernel, MemoryBuffer *outputMemoryBuffer, int offsetIndex, NodeOperation *operation) { cl_int error; const int width = outputMemoryBuffer->getWidth(); diff --git a/source/blender/compositor/intern/COM_OpenCLDevice.h b/source/blender/compositor/intern/COM_OpenCLDevice.h index f1a1e31c930..2021cacabcc 100644 --- a/source/blender/compositor/intern/COM_OpenCLDevice.h +++ b/source/blender/compositor/intern/COM_OpenCLDevice.h @@ -100,9 +100,9 @@ public: cl_mem COM_clAttachMemoryBufferToKernelParameter(cl_kernel kernel, int parameterIndex, int offsetIndex, list<cl_mem> *cleanup, MemoryBuffer **inputMemoryBuffers, ReadBufferOperation *reader); void COM_clAttachMemoryBufferOffsetToKernelParameter(cl_kernel kernel, int offsetIndex, MemoryBuffer *memoryBuffers); void COM_clAttachOutputMemoryBufferToKernelParameter(cl_kernel kernel, int parameterIndex, cl_mem clOutputMemoryBuffer); - void COM_clAttachSizeToKernelParameter(cl_kernel kernel, int offsetIndex, NodeOperation* operation); + void COM_clAttachSizeToKernelParameter(cl_kernel kernel, int offsetIndex, NodeOperation *operation); void COM_clEnqueueRange(cl_kernel kernel, MemoryBuffer *outputMemoryBuffer); - void COM_clEnqueueRange(cl_kernel kernel, MemoryBuffer *outputMemoryBuffer, int offsetIndex, NodeOperation* operation); + void COM_clEnqueueRange(cl_kernel kernel, MemoryBuffer *outputMemoryBuffer, int offsetIndex, NodeOperation *operation); cl_kernel COM_clCreateKernel(const char *kernelname, list<cl_kernel> *clKernelsToCleanUp); }; diff --git a/source/blender/compositor/intern/COM_OutputSocket.cpp b/source/blender/compositor/intern/COM_OutputSocket.cpp index 865ab0472e8..f23a48979da 100644 --- a/source/blender/compositor/intern/COM_OutputSocket.cpp +++ b/source/blender/compositor/intern/COM_OutputSocket.cpp @@ -33,7 +33,7 @@ OutputSocket::OutputSocket(DataType datatype) : Socket(datatype) int OutputSocket::isOutputSocket() const { return true; } const int OutputSocket::isConnected() const { return this->m_connections.size() != 0; } -void OutputSocket::determineResolution(unsigned int resolution[], unsigned int preferredResolution[]) +void OutputSocket::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]) { NodeBase *node = this->getNode(); if (node->isOperation()) { diff --git a/source/blender/compositor/intern/COM_OutputSocket.h b/source/blender/compositor/intern/COM_OutputSocket.h index 4810e1ae065..dc5ca27cbda 100644 --- a/source/blender/compositor/intern/COM_OutputSocket.h +++ b/source/blender/compositor/intern/COM_OutputSocket.h @@ -59,7 +59,7 @@ public: * @param resolution the result of this operation * @param preferredResolution the preferrable resolution as no resolution could be determined */ - void determineResolution(unsigned int resolution[], unsigned int preferredResolution[]); + void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]); /** * @brief determine the actual data type and channel info. diff --git a/source/blender/compositor/intern/COM_SingleThreadedNodeOperation.cpp b/source/blender/compositor/intern/COM_SingleThreadedNodeOperation.cpp index d14b8c48c89..7d1184cb356 100644 --- a/source/blender/compositor/intern/COM_SingleThreadedNodeOperation.cpp +++ b/source/blender/compositor/intern/COM_SingleThreadedNodeOperation.cpp @@ -33,9 +33,9 @@ void SingleThreadedNodeOperation::initExecution() initMutex(); } -void SingleThreadedNodeOperation::executePixel(float *color, int x, int y, void *data) +void SingleThreadedNodeOperation::executePixel(float output[4], int x, int y, void *data) { - this->m_cachedInstance->readNoCheck(color, x, y); + this->m_cachedInstance->readNoCheck(output, x, y); } void SingleThreadedNodeOperation::deinitExecution() diff --git a/source/blender/compositor/intern/COM_SingleThreadedNodeOperation.h b/source/blender/compositor/intern/COM_SingleThreadedNodeOperation.h index 68951eab507..45325be18a9 100644 --- a/source/blender/compositor/intern/COM_SingleThreadedNodeOperation.h +++ b/source/blender/compositor/intern/COM_SingleThreadedNodeOperation.h @@ -39,7 +39,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, int x, int y, void *data); + void executePixel(float output[4], int x, int y, void *data); /** * Initialize the execution diff --git a/source/blender/compositor/intern/COM_Socket.h b/source/blender/compositor/intern/COM_Socket.h index 5607d2f4569..2aebe262594 100644 --- a/source/blender/compositor/intern/COM_Socket.h +++ b/source/blender/compositor/intern/COM_Socket.h @@ -73,7 +73,7 @@ public: const virtual int isConnected() const; int isInputSocket() const; int isOutputSocket() const; - virtual void determineResolution(int resolution[], unsigned int preferredResolution[]) {} + virtual void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]) {} void setEditorSocket(bNodeSocket *editorSocket) { this->m_editorSocket = editorSocket; } bNodeSocket *getbNodeSocket() const { return this->m_editorSocket; } diff --git a/source/blender/compositor/intern/COM_SocketReader.h b/source/blender/compositor/intern/COM_SocketReader.h index 736dd2fc8b6..279ca8ebdb8 100644 --- a/source/blender/compositor/intern/COM_SocketReader.h +++ b/source/blender/compositor/intern/COM_SocketReader.h @@ -63,7 +63,7 @@ protected: * @param y the y-coordinate of the pixel to calculate in image space * @param inputBuffers chunks that can be read by their ReadBufferOperation. */ - virtual void executePixel(float *result, float x, float y, PixelSampler sampler) {} + virtual void executePixel(float output[4], float x, float y, PixelSampler sampler) {} /** * @brief calculate a single pixel @@ -74,8 +74,8 @@ protected: * @param inputBuffers chunks that can be read by their ReadBufferOperation. * @param chunkData chunk specific data a during execution time. */ - virtual void executePixel(float *result, int x, int y, void *chunkData) { - executePixel(result, x, y, COM_PS_NEAREST); + virtual void executePixel(float output[4], int x, int y, void *chunkData) { + executePixel(output, x, y, COM_PS_NEAREST); } /** @@ -88,7 +88,7 @@ protected: * @param dy * @param inputBuffers chunks that can be read by their ReadBufferOperation. */ - virtual void executePixel(float *result, float x, float y, float dx, float dy) {} + virtual void executePixel(float output[4], float x, float y, float dx, float dy) {} public: inline void read(float *result, float x, float y, PixelSampler sampler) { diff --git a/source/blender/compositor/intern/COM_WorkScheduler.cpp b/source/blender/compositor/intern/COM_WorkScheduler.cpp index 7d4134aca13..8c42b05edca 100644 --- a/source/blender/compositor/intern/COM_WorkScheduler.cpp +++ b/source/blender/compositor/intern/COM_WorkScheduler.cpp @@ -77,20 +77,20 @@ void ** g_highlightedNodesRead; #define HIGHLIGHT(wp) \ { \ - ExecutionGroup* group = wp->getExecutionGroup(); \ + ExecutionGroup *group = wp->getExecutionGroup(); \ if (group->isComplex()) { \ - NodeOperation* operation = group->getOutputNodeOperation(); \ - if (operation->isWriteBufferOperation()) {\ - WriteBufferOperation *writeOperation = (WriteBufferOperation*)operation;\ + NodeOperation *operation = group->getOutputNodeOperation(); \ + if (operation->isWriteBufferOperation()) { \ + WriteBufferOperation *writeOperation = (WriteBufferOperation *)operation; \ NodeOperation *complexOperation = writeOperation->getInput(); \ bNode *node = complexOperation->getbNode(); \ if (node) { \ if (node->original) { \ - node = node->original;\ - }\ - if (g_highlightIndex < MAX_HIGHLIGHT) {\ - g_highlightedNodes[g_highlightIndex++] = node;\ - }\ + node = node->original; \ + } \ + if (g_highlightIndex < MAX_HIGHLIGHT) { \ + g_highlightedNodes[g_highlightIndex++] = node; \ + } \ } \ } \ } \ @@ -103,18 +103,18 @@ void COM_startReadHighlights() } g_highlightedNodesRead = g_highlightedNodes; - g_highlightedNodes = new void*[MAX_HIGHLIGHT]; + g_highlightedNodes = new void *[MAX_HIGHLIGHT]; g_highlightIndex = 0; for (int i = 0 ; i < MAX_HIGHLIGHT; i++) { g_highlightedNodes[i] = 0; } } -int COM_isHighlightedbNode(bNode* bnode) +int COM_isHighlightedbNode(bNode *bnode) { if (!g_highlightedNodesRead) return false; for (int i = 0 ; i < MAX_HIGHLIGHT; i++) { - void* p = g_highlightedNodesRead[i]; + void *p = g_highlightedNodesRead[i]; if (!p) return false; if (p == bnode) return true; } @@ -288,7 +288,8 @@ void WorkScheduler::initialize() g_context = clCreateContext(NULL, numberOfDevices, cldevices, clContextError, NULL, &error); if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); } - g_program = clCreateProgramWithSource(g_context, 1, &clkernelstoh_COM_OpenCLKernels_cl, 0, &error); + const char *cl_str[2] = {clkernelstoh_COM_OpenCLKernels_cl, NULL}; + g_program = clCreateProgramWithSource(g_context, 1, cl_str, 0, &error); error = clBuildProgram(g_program, numberOfDevices, cldevices, 0, 0, 0); if (error != CL_SUCCESS) { cl_int error2; diff --git a/source/blender/compositor/intern/COM_compositor.cpp b/source/blender/compositor/intern/COM_compositor.cpp index ab64f8f7bf1..2402f9a1163 100644 --- a/source/blender/compositor/intern/COM_compositor.cpp +++ b/source/blender/compositor/intern/COM_compositor.cpp @@ -54,7 +54,7 @@ void COM_execute(RenderData *rd, bNodeTree *editingtree, int rendering) } - /* set progress bar to 0% and status to init compositing*/ + /* set progress bar to 0% and status to init compositing */ editingtree->progress(editingtree->prh, 0.0); bool twopass = (editingtree->flag&NTREE_TWO_PASS) > 0 && !rendering; diff --git a/source/blender/compositor/nodes/COM_BokehBlurNode.cpp b/source/blender/compositor/nodes/COM_BokehBlurNode.cpp index f45572fe4ae..434fcf2a608 100644 --- a/source/blender/compositor/nodes/COM_BokehBlurNode.cpp +++ b/source/blender/compositor/nodes/COM_BokehBlurNode.cpp @@ -36,24 +36,42 @@ BokehBlurNode::BokehBlurNode(bNode *editorNode) : Node(editorNode) void BokehBlurNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context) { - BokehBlurOperation *operation = new BokehBlurOperation(); InputSocket *inputSizeSocket = this->getInputSocket(2); bool connectedSizeSocket = inputSizeSocket->isConnected(); - const bNodeSocket *sock = this->getInputSocket(2)->getbNodeSocket(); - const float size = ((const bNodeSocketValueFloat *)sock->default_value)->value; + if (connectedSizeSocket) { + VariableSizeBokehBlurOperation *operation = new VariableSizeBokehBlurOperation(); - this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph); - this->getInputSocket(1)->relinkConnections(operation->getInputSocket(1), 1, graph); - this->getInputSocket(2)->relinkConnections(operation->getInputSocket(3), 2, graph); - this->getInputSocket(3)->relinkConnections(operation->getInputSocket(2), 3, graph); - //operation->setSize(((bNodeSocketValueFloat *)this->getInputSocket(2)->getbNodeSocket()->default_value)->value); - operation->setQuality(context->getQuality()); - operation->setbNode(this->getbNode()); - graph->addOperation(operation); - this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket()); + this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph); + this->getInputSocket(1)->relinkConnections(operation->getInputSocket(1), 1, graph); + this->getInputSocket(2)->relinkConnections(operation->getInputSocket(2), 2, graph); + operation->setQuality(context->getQuality()); + operation->setbNode(this->getbNode()); + graph->addOperation(operation); + this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket()); + + operation->setThreshold(0.0f); + + /* TODO, we need to know the max input pixel of the input, this value is arbitrary! */ + operation->setMaxBlur(100.0f); + operation->setDoScaleSize(true); + } + else { + BokehBlurOperation *operation = new BokehBlurOperation(); + + const bNodeSocket *sock = this->getInputSocket(2)->getbNodeSocket(); + const float size = ((const bNodeSocketValueFloat *)sock->default_value)->value; + + this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph); + this->getInputSocket(1)->relinkConnections(operation->getInputSocket(1), 1, graph); + this->getInputSocket(2)->relinkConnections(operation->getInputSocket(3), 2, graph); + this->getInputSocket(3)->relinkConnections(operation->getInputSocket(2), 3, graph); + //operation->setSize(((bNodeSocketValueFloat *)this->getInputSocket(2)->getbNodeSocket()->default_value)->value); + operation->setQuality(context->getQuality()); + operation->setbNode(this->getbNode()); + graph->addOperation(operation); + this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket()); - if (!connectedSizeSocket) { operation->setSize(size); } } diff --git a/source/blender/compositor/nodes/COM_ChannelMatteNode.cpp b/source/blender/compositor/nodes/COM_ChannelMatteNode.cpp index 69f39639660..eab921863e9 100644 --- a/source/blender/compositor/nodes/COM_ChannelMatteNode.cpp +++ b/source/blender/compositor/nodes/COM_ChannelMatteNode.cpp @@ -45,13 +45,13 @@ void ChannelMatteNode::convertToOperations(ExecutionSystem *graph, CompositorCon switch (node->custom1) { case CMP_NODE_CHANNEL_MATTE_CS_RGB: break; - case CMP_NODE_CHANNEL_MATTE_CS_HSV: /*HSV*/ + case CMP_NODE_CHANNEL_MATTE_CS_HSV: /* HSV */ convert = new ConvertRGBToHSVOperation(); break; - case CMP_NODE_CHANNEL_MATTE_CS_YUV: /*YUV*/ + case CMP_NODE_CHANNEL_MATTE_CS_YUV: /* YUV */ convert = new ConvertRGBToYUVOperation(); break; - case CMP_NODE_CHANNEL_MATTE_CS_YCC: /*YCC*/ + case CMP_NODE_CHANNEL_MATTE_CS_YCC: /* YCC */ convert = new ConvertRGBToYCCOperation(); ((ConvertRGBToYCCOperation *)convert)->setMode(0); /* BLI_YCC_ITU_BT601 */ break; diff --git a/source/blender/compositor/nodes/COM_DefocusNode.cpp b/source/blender/compositor/nodes/COM_DefocusNode.cpp index 65825a60b50..c2bd8997525 100644 --- a/source/blender/compositor/nodes/COM_DefocusNode.cpp +++ b/source/blender/compositor/nodes/COM_DefocusNode.cpp @@ -73,11 +73,14 @@ void DefocusNode::convertToOperations(ExecutionSystem *graph, CompositorContext this->getInputSocket(1)->relinkConnections(converter->getInputSocket(0), 1, graph); graph->addOperation(converter); - FastGaussianBlurValueOperation * blur = new FastGaussianBlurValueOperation(); + FastGaussianBlurValueOperation *blur = new FastGaussianBlurValueOperation(); addLink(graph, converter->getOutputSocket(0), blur->getInputSocket(0)); graph->addOperation(blur); radiusOperation = blur; converter->setPostBlur(blur); + + /* maintain close pixels so far Z values don't bleed into the foreground */ + blur->setOverlay(FAST_GAUSS_OVERLAY_MIN); } BokehImageOperation *bokeh = new BokehImageOperation(); @@ -105,7 +108,8 @@ void DefocusNode::convertToOperations(ExecutionSystem *graph, CompositorContext VariableSizeBokehBlurOperation *operation = new VariableSizeBokehBlurOperation(); if (data->preview) { operation->setQuality(COM_QUALITY_LOW); - } else { + } + else { operation->setQuality(context->getQuality()); } operation->setMaxBlur(data->maxblur); diff --git a/source/blender/compositor/nodes/COM_InpaintNode.cpp b/source/blender/compositor/nodes/COM_InpaintNode.cpp new file mode 100644 index 00000000000..e90a3921edc --- /dev/null +++ b/source/blender/compositor/nodes/COM_InpaintNode.cpp @@ -0,0 +1,48 @@ +/* + * Copyright 2011, Blender Foundation. + * + * 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. + * + * Contributor: Peter Schlaile + * Jeroen Bakker + * Monique Dewanchand + */ + +#include "COM_InpaintNode.h" +#include "DNA_scene_types.h" +#include "COM_ExecutionSystem.h" +#include "COM_InpaintOperation.h" +#include "BLI_math.h" + +InpaintNode::InpaintNode(bNode *editorNode) : Node(editorNode) +{ + /* pass */ +} + +void InpaintNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context) +{ + + bNode *editorNode = this->getbNode(); + + /* if (editorNode->custom1 == CMP_NODE_INPAINT_SIMPLE) { */ + if (true) { + InpaintSimpleOperation *operation = new InpaintSimpleOperation(); + operation->setbNode(editorNode); + operation->setIterations(editorNode->custom2); + this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph); + this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket(0)); + graph->addOperation(operation); + } +} diff --git a/intern/boolop/intern/BOP_Indexs.h b/source/blender/compositor/nodes/COM_InpaintNode.h index e001f412c9f..5837b979958 100644 --- a/intern/boolop/intern/BOP_Indexs.h +++ b/source/blender/compositor/nodes/COM_InpaintNode.h @@ -1,5 +1,5 @@ /* - * ***** BEGIN GPL LICENSE BLOCK ***** + * Copyright 2011, Blender Foundation. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -15,28 +15,24 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** + * Contributor: Peter Schlaile + * Jeroen Bakker + * Monique Dewanchand */ -/** \file boolop/intern/BOP_Indexs.h - * \ingroup boolopintern - */ - - -#ifndef __BOP_INDEXS_H__ -#define __BOP_INDEXS_H__ +#ifndef _COM_InpaintNode_h_ +#define _COM_InpaintNode_h_ -#include <vector> +#include "COM_Node.h" -typedef unsigned int BOP_Index; -typedef std::vector<BOP_Index> BOP_Indexs; -typedef std::vector<BOP_Index>::iterator BOP_IT_Indexs; +/** + * @brief InpaintNode + * @ingroup Node + */ +class InpaintNode : public Node { +public: + InpaintNode(bNode *editorNode); + void convertToOperations(ExecutionSystem *graph, CompositorContext *context); +}; #endif diff --git a/source/blender/compositor/nodes/COM_MuteNode.cpp b/source/blender/compositor/nodes/COM_MuteNode.cpp index 2c96473a556..eb2da147eca 100644 --- a/source/blender/compositor/nodes/COM_MuteNode.cpp +++ b/source/blender/compositor/nodes/COM_MuteNode.cpp @@ -110,6 +110,7 @@ void MuteNode::convertToOperations(ExecutionSystem *graph, CompositorContext *co */ if ((editorNode->flag & NODE_MUTED) && editorNode->typeinfo->internal_connect) { vector<InputSocket *> &inputsockets = this->getInputSockets(); + vector<OutputSocket *> relinkedsockets; bNodeTree *editorTree = (bNodeTree *) context->getbNodeTree(); SocketMap socketMap; ListBase intlinks; @@ -132,10 +133,37 @@ void MuteNode::convertToOperations(ExecutionSystem *graph, CompositorContext *co else { createDefaultOutput(graph, toSocket); } + + relinkedsockets.push_back(toSocket); } } } + /* in some cases node could be marked as muted, but it wouldn't have internal connections + * this happens in such cases as muted render layer node + * + * to deal with such cases create default operation for not-relinked output sockets + */ + + for (unsigned int index = 0; index < outputsockets.size(); index++) { + OutputSocket *output = outputsockets[index]; + + if (output->isConnected()) { + bool relinked = false; + vector<OutputSocket *>::iterator it; + + for (it = relinkedsockets.begin(); it != relinkedsockets.end(); it++) { + if (*it == output) { + relinked = true; + break; + } + } + + if (!relinked) + createDefaultOutput(graph, output); + } + } + BLI_freelistN(&intlinks); } else { diff --git a/source/blender/compositor/operations/COM_AlphaOverKeyOperation.cpp b/source/blender/compositor/operations/COM_AlphaOverKeyOperation.cpp index 406a98f81e9..6cc9aae4553 100644 --- a/source/blender/compositor/operations/COM_AlphaOverKeyOperation.cpp +++ b/source/blender/compositor/operations/COM_AlphaOverKeyOperation.cpp @@ -27,7 +27,7 @@ AlphaOverKeyOperation::AlphaOverKeyOperation() : MixBaseOperation() /* pass */ } -void AlphaOverKeyOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void AlphaOverKeyOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor1[4]; float inputOverColor[4]; @@ -38,18 +38,18 @@ void AlphaOverKeyOperation::executePixel(float *outputValue, float x, float y, P this->m_inputColor2Operation->read(inputOverColor, x, y, sampler); if (inputOverColor[3] <= 0.0f) { - copy_v4_v4(outputValue, inputColor1); + copy_v4_v4(output, inputColor1); } else if (value[0] == 1.0f && inputOverColor[3] >= 1.0f) { - copy_v4_v4(outputValue, inputOverColor); + copy_v4_v4(output, inputOverColor); } else { float premul = value[0] * inputOverColor[3]; float mul = 1.0f - premul; - outputValue[0] = (mul * inputColor1[0]) + premul * inputOverColor[0]; - outputValue[1] = (mul * inputColor1[1]) + premul * inputOverColor[1]; - outputValue[2] = (mul * inputColor1[2]) + premul * inputOverColor[2]; - outputValue[3] = (mul * inputColor1[3]) + value[0] * inputOverColor[3]; + output[0] = (mul * inputColor1[0]) + premul * inputOverColor[0]; + output[1] = (mul * inputColor1[1]) + premul * inputOverColor[1]; + output[2] = (mul * inputColor1[2]) + premul * inputOverColor[2]; + output[3] = (mul * inputColor1[3]) + value[0] * inputOverColor[3]; } } diff --git a/source/blender/compositor/operations/COM_AlphaOverKeyOperation.h b/source/blender/compositor/operations/COM_AlphaOverKeyOperation.h index 5f430efb98e..fa884bacf49 100644 --- a/source/blender/compositor/operations/COM_AlphaOverKeyOperation.h +++ b/source/blender/compositor/operations/COM_AlphaOverKeyOperation.h @@ -39,6 +39,6 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; #endif diff --git a/source/blender/compositor/operations/COM_AlphaOverMixedOperation.cpp b/source/blender/compositor/operations/COM_AlphaOverMixedOperation.cpp index b94486b5b4f..111dc899e1d 100644 --- a/source/blender/compositor/operations/COM_AlphaOverMixedOperation.cpp +++ b/source/blender/compositor/operations/COM_AlphaOverMixedOperation.cpp @@ -27,7 +27,7 @@ AlphaOverMixedOperation::AlphaOverMixedOperation() : MixBaseOperation() this->m_x = 0.0f; } -void AlphaOverMixedOperation::executePixel(float outputValue[4], float x, float y, PixelSampler sampler) +void AlphaOverMixedOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor1[4]; float inputOverColor[4]; @@ -38,20 +38,20 @@ void AlphaOverMixedOperation::executePixel(float outputValue[4], float x, float this->m_inputColor2Operation->read(inputOverColor, x, y, sampler); if (inputOverColor[3] <= 0.0f) { - copy_v4_v4(outputValue, inputColor1); + copy_v4_v4(output, inputColor1); } else if (value[0] == 1.0f && inputOverColor[3] >= 1.0f) { - copy_v4_v4(outputValue, inputOverColor); + copy_v4_v4(output, inputOverColor); } else { float addfac = 1.0f - this->m_x + inputOverColor[3] * this->m_x; float premul = value[0] * addfac; float mul = 1.0f - value[0] * inputOverColor[3]; - outputValue[0] = (mul * inputColor1[0]) + premul * inputOverColor[0]; - outputValue[1] = (mul * inputColor1[1]) + premul * inputOverColor[1]; - outputValue[2] = (mul * inputColor1[2]) + premul * inputOverColor[2]; - outputValue[3] = (mul * inputColor1[3]) + value[0] * inputOverColor[3]; + output[0] = (mul * inputColor1[0]) + premul * inputOverColor[0]; + output[1] = (mul * inputColor1[1]) + premul * inputOverColor[1]; + output[2] = (mul * inputColor1[2]) + premul * inputOverColor[2]; + output[3] = (mul * inputColor1[3]) + value[0] * inputOverColor[3]; } } diff --git a/source/blender/compositor/operations/COM_AlphaOverMixedOperation.h b/source/blender/compositor/operations/COM_AlphaOverMixedOperation.h index 308f139884d..91128454783 100644 --- a/source/blender/compositor/operations/COM_AlphaOverMixedOperation.h +++ b/source/blender/compositor/operations/COM_AlphaOverMixedOperation.h @@ -41,7 +41,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); void setX(float x) { this->m_x = x; } }; diff --git a/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.cpp b/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.cpp index dad43f3b179..ac7906f2f98 100644 --- a/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.cpp +++ b/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.cpp @@ -27,7 +27,7 @@ AlphaOverPremultiplyOperation::AlphaOverPremultiplyOperation() : MixBaseOperatio /* pass */ } -void AlphaOverPremultiplyOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void AlphaOverPremultiplyOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor1[4]; float inputOverColor[4]; @@ -39,18 +39,18 @@ void AlphaOverPremultiplyOperation::executePixel(float *outputValue, float x, fl /* Zero alpha values should still permit an add of RGB data */ if (inputOverColor[3] < 0.0f) { - copy_v4_v4(outputValue, inputColor1); + copy_v4_v4(output, inputColor1); } else if (value[0] == 1.0f && inputOverColor[3] >= 1.0f) { - copy_v4_v4(outputValue, inputOverColor); + copy_v4_v4(output, inputOverColor); } else { float mul = 1.0f - value[0] * inputOverColor[3]; - outputValue[0] = (mul * inputColor1[0]) + value[0] * inputOverColor[0]; - outputValue[1] = (mul * inputColor1[1]) + value[0] * inputOverColor[1]; - outputValue[2] = (mul * inputColor1[2]) + value[0] * inputOverColor[2]; - outputValue[3] = (mul * inputColor1[3]) + value[0] * inputOverColor[3]; + output[0] = (mul * inputColor1[0]) + value[0] * inputOverColor[0]; + output[1] = (mul * inputColor1[1]) + value[0] * inputOverColor[1]; + output[2] = (mul * inputColor1[2]) + value[0] * inputOverColor[2]; + output[3] = (mul * inputColor1[3]) + value[0] * inputOverColor[3]; } } diff --git a/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.h b/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.h index 37ddc6dcda5..d6e9e31c35f 100644 --- a/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.h +++ b/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.h @@ -39,7 +39,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; #endif diff --git a/source/blender/compositor/operations/COM_AntiAliasOperation.cpp b/source/blender/compositor/operations/COM_AntiAliasOperation.cpp index 27ba2ef51f6..12bf651992e 100644 --- a/source/blender/compositor/operations/COM_AntiAliasOperation.cpp +++ b/source/blender/compositor/operations/COM_AntiAliasOperation.cpp @@ -42,14 +42,14 @@ void AntiAliasOperation::initExecution() NodeOperation::initMutex(); } -void AntiAliasOperation::executePixel(float *color, int x, int y, void *data) +void AntiAliasOperation::executePixel(float output[4], int x, int y, void *data) { if (y < 0 || (unsigned int)y >= this->m_height || x < 0 || (unsigned int)x >= this->m_width) { - color[0] = 0.0f; + output[0] = 0.0f; } else { int offset = y * this->m_width + x; - color[0] = this->m_buffer[offset] / 255.0f; + output[0] = this->m_buffer[offset] / 255.0f; } } diff --git a/source/blender/compositor/operations/COM_AntiAliasOperation.h b/source/blender/compositor/operations/COM_AntiAliasOperation.h index 7489d2e393a..385d59fec3c 100644 --- a/source/blender/compositor/operations/COM_AntiAliasOperation.h +++ b/source/blender/compositor/operations/COM_AntiAliasOperation.h @@ -43,7 +43,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, int x, int y, void *data); + void executePixel(float output[4], int x, int y, void *data); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_BilateralBlurOperation.cpp b/source/blender/compositor/operations/COM_BilateralBlurOperation.cpp index 1db3ecb2db8..5f5eca96378 100644 --- a/source/blender/compositor/operations/COM_BilateralBlurOperation.cpp +++ b/source/blender/compositor/operations/COM_BilateralBlurOperation.cpp @@ -46,7 +46,7 @@ void BilateralBlurOperation::initExecution() QualityStepHelper::initExecution(COM_QH_INCREASE); } -void BilateralBlurOperation::executePixel(float *color, int x, int y, void *data) +void BilateralBlurOperation::executePixel(float output[4], int x, int y, void *data) { // read the determinator color at x, y, this will be used as the reference color for the determinator float determinatorReferenceColor[4]; @@ -82,13 +82,13 @@ void BilateralBlurOperation::executePixel(float *color, int x, int y, void *data } if (blurDivider > 0.0f) { - mul_v4_v4fl(color, blurColor, 1.0f / blurDivider); + mul_v4_v4fl(output, blurColor, 1.0f / blurDivider); } else { - color[0] = 0.0f; - color[1] = 0.0f; - color[2] = 0.0f; - color[3] = 1.0f; + output[0] = 0.0f; + output[1] = 0.0f; + output[2] = 0.0f; + output[3] = 1.0f; } } diff --git a/source/blender/compositor/operations/COM_BilateralBlurOperation.h b/source/blender/compositor/operations/COM_BilateralBlurOperation.h index c1b5f764f01..8def90941ab 100644 --- a/source/blender/compositor/operations/COM_BilateralBlurOperation.h +++ b/source/blender/compositor/operations/COM_BilateralBlurOperation.h @@ -38,7 +38,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, int x, int y, void *data); + void executePixel(float output[4], int x, int y, void *data); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_BokehBlurOperation.cpp b/source/blender/compositor/operations/COM_BokehBlurOperation.cpp index a3d685de9a6..b31974487ed 100644 --- a/source/blender/compositor/operations/COM_BokehBlurOperation.cpp +++ b/source/blender/compositor/operations/COM_BokehBlurOperation.cpp @@ -66,20 +66,15 @@ void BokehBlurOperation::initExecution() int width = this->m_inputBokehProgram->getWidth(); int height = this->m_inputBokehProgram->getHeight(); - float dimension; - if (width < height) { - dimension = width; - } - else { - dimension = height; - } + float dimension = min(width, height); + this->m_bokehMidX = width / 2.0f; this->m_bokehMidY = height / 2.0f; this->m_bokehDimension = dimension / 2.0f; QualityStepHelper::initExecution(COM_QH_INCREASE); } -void BokehBlurOperation::executePixel(float *color, int x, int y, void *data) +void BokehBlurOperation::executePixel(float output[4], int x, int y, void *data) { float color_accum[4]; float tempBoundingBox[4]; @@ -93,7 +88,8 @@ void BokehBlurOperation::executePixel(float *color, int x, int y, void *data) int bufferwidth = inputBuffer->getWidth(); int bufferstartx = inputBuffer->getRect()->xmin; int bufferstarty = inputBuffer->getRect()->ymin; - int pixelSize = this->m_size * this->getWidth() / 100.0f; + const float max_dim = max(this->getWidth(), this->getHeight()); + int pixelSize = this->m_size * max_dim / 100.0f; zero_v4(color_accum); if (pixelSize<2) { @@ -128,13 +124,13 @@ void BokehBlurOperation::executePixel(float *color, int x, int y, void *data) bufferindex += offsetadd; } } - color[0] = color_accum[0] * (1.0f / multiplier_accum[0]); - color[1] = color_accum[1] * (1.0f / multiplier_accum[1]); - color[2] = color_accum[2] * (1.0f / multiplier_accum[2]); - color[3] = color_accum[3] * (1.0f / multiplier_accum[3]); + output[0] = color_accum[0] * (1.0f / multiplier_accum[0]); + output[1] = color_accum[1] * (1.0f / multiplier_accum[1]); + output[2] = color_accum[2] * (1.0f / multiplier_accum[2]); + output[3] = color_accum[3] * (1.0f / multiplier_accum[3]); } else { - this->m_inputProgram->read(color, x, y, COM_PS_NEAREST); + this->m_inputProgram->read(output, x, y, COM_PS_NEAREST); } } @@ -150,17 +146,19 @@ bool BokehBlurOperation::determineDependingAreaOfInterest(rcti *input, ReadBuffe { rcti newInput; rcti bokehInput; + const float max_dim = max(this->getWidth(), this->getHeight()); if (this->m_sizeavailable) { - newInput.xmax = input->xmax + (this->m_size * this->getWidth() / 100.0f); - newInput.xmin = input->xmin - (this->m_size * this->getWidth() / 100.0f); - newInput.ymax = input->ymax + (this->m_size * this->getWidth() / 100.0f); - newInput.ymin = input->ymin - (this->m_size * this->getWidth() / 100.0f); - } else { - newInput.xmax = input->xmax + (10.0f * this->getWidth() / 100.0f); - newInput.xmin = input->xmin - (10.0f * this->getWidth() / 100.0f); - newInput.ymax = input->ymax + (10.0f * this->getWidth() / 100.0f); - newInput.ymin = input->ymin - (10.0f * this->getWidth() / 100.0f); + newInput.xmax = input->xmax + (this->m_size * max_dim / 100.0f); + newInput.xmin = input->xmin - (this->m_size * max_dim / 100.0f); + newInput.ymax = input->ymax + (this->m_size * max_dim / 100.0f); + newInput.ymin = input->ymin - (this->m_size * max_dim / 100.0f); + } + else { + newInput.xmax = input->xmax + (10.0f * max_dim / 100.0f); + newInput.xmin = input->xmin - (10.0f * max_dim / 100.0f); + newInput.ymax = input->ymax + (10.0f * max_dim / 100.0f); + newInput.ymin = input->ymin - (10.0f * max_dim / 100.0f); } NodeOperation *operation = getInputOperation(1); @@ -193,7 +191,7 @@ bool BokehBlurOperation::determineDependingAreaOfInterest(rcti *input, ReadBuffe return false; } -void BokehBlurOperation::executeOpenCL(OpenCLDevice* device, +void BokehBlurOperation::executeOpenCL(OpenCLDevice *device, MemoryBuffer *outputMemoryBuffer, cl_mem clOutputBuffer, MemoryBuffer **inputMemoryBuffers, list<cl_mem> *clMemToCleanUp, list<cl_kernel> *clKernelsToCleanUp) @@ -202,7 +200,8 @@ void BokehBlurOperation::executeOpenCL(OpenCLDevice* device, if (!this->m_sizeavailable) { updateSize(); } - cl_int radius = this->getWidth() * this->m_size / 100.0f; + const float max_dim = max(this->getWidth(), this->getHeight()); + cl_int radius = this->m_size * max_dim / 100.0f; cl_int step = this->getStep(); device->COM_clAttachMemoryBufferToKernelParameter(kernel, 0, -1, clMemToCleanUp, inputMemoryBuffers, this->m_inputBoundingBoxReader); diff --git a/source/blender/compositor/operations/COM_BokehBlurOperation.h b/source/blender/compositor/operations/COM_BokehBlurOperation.h index eef5429c409..37483d3dc69 100644 --- a/source/blender/compositor/operations/COM_BokehBlurOperation.h +++ b/source/blender/compositor/operations/COM_BokehBlurOperation.h @@ -43,7 +43,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, int x, int y, void *data); + void executePixel(float output[4], int x, int y, void *data); /** * Initialize the execution @@ -59,6 +59,6 @@ public: void setSize(float size) { this->m_size = size; this->m_sizeavailable = true; } - void executeOpenCL(OpenCLDevice* device, MemoryBuffer *outputMemoryBuffer, cl_mem clOutputBuffer, MemoryBuffer **inputMemoryBuffers, list<cl_mem> *clMemToCleanUp, list<cl_kernel> *clKernelsToCleanUp); + void executeOpenCL(OpenCLDevice *device, MemoryBuffer *outputMemoryBuffer, cl_mem clOutputBuffer, MemoryBuffer **inputMemoryBuffers, list<cl_mem> *clMemToCleanUp, list<cl_kernel> *clKernelsToCleanUp); }; #endif diff --git a/source/blender/compositor/operations/COM_BokehImageOperation.cpp b/source/blender/compositor/operations/COM_BokehImageOperation.cpp index d7de201e9df..b87be33eca1 100644 --- a/source/blender/compositor/operations/COM_BokehImageOperation.cpp +++ b/source/blender/compositor/operations/COM_BokehImageOperation.cpp @@ -30,10 +30,8 @@ BokehImageOperation::BokehImageOperation() : NodeOperation() } void BokehImageOperation::initExecution() { - this->m_centerX = getWidth() / 2; - this->m_centerY = getHeight() / 2; - this->m_center[0] = this->m_centerX; - this->m_center[1] = this->m_centerY; + this->m_center[0] = getWidth() / 2; + this->m_center[1] = getHeight() / 2; this->m_inverseRounding = 1.0f - this->m_data->rounding; this->m_circularDistance = getWidth() / 2; this->m_flapRad = (float)(M_PI * 2) / this->m_data->flaps; @@ -47,14 +45,14 @@ void BokehImageOperation::initExecution() } void BokehImageOperation::detemineStartPointOfFlap(float r[2], int flapNumber, float distance) { - r[0] = sinf(this->m_flapRad * flapNumber + this->m_flapRadAdd) * distance + this->m_centerX; - r[1] = cosf(this->m_flapRad * flapNumber + this->m_flapRadAdd) * distance + this->m_centerY; + r[0] = sinf(this->m_flapRad * flapNumber + this->m_flapRadAdd) * distance + this->m_center[0]; + r[1] = cosf(this->m_flapRad * flapNumber + this->m_flapRadAdd) * distance + this->m_center[1]; } float BokehImageOperation::isInsideBokeh(float distance, float x, float y) { float insideBokeh = 0.0f; - const float deltaX = x - this->m_centerX; - const float deltaY = y - this->m_centerY; + const float deltaX = x - this->m_center[0]; + const float deltaY = y - this->m_center[1]; float closestPoint[2]; float lineP1[2]; float lineP2[2]; @@ -87,7 +85,7 @@ float BokehImageOperation::isInsideBokeh(float distance, float x, float y) } return insideBokeh; } -void BokehImageOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void BokehImageOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float shift = this->m_data->lensshift; float shift2 = shift / 2.0f; @@ -96,16 +94,16 @@ void BokehImageOperation::executePixel(float *color, float x, float y, PixelSamp float insideBokehMed = isInsideBokeh(distance - fabsf(shift2 * distance), x, y); float insideBokehMin = isInsideBokeh(distance - fabsf(shift * distance), x, y); if (shift < 0) { - color[0] = insideBokehMax; - color[1] = insideBokehMed; - color[2] = insideBokehMin; + output[0] = insideBokehMax; + output[1] = insideBokehMed; + output[2] = insideBokehMin; } else { - color[0] = insideBokehMin; - color[1] = insideBokehMed; - color[2] = insideBokehMax; + output[0] = insideBokehMin; + output[1] = insideBokehMed; + output[2] = insideBokehMax; } - color[3] = (insideBokehMax + insideBokehMed + insideBokehMin) / 3.0f; + output[3] = (insideBokehMax + insideBokehMed + insideBokehMin) / 3.0f; } void BokehImageOperation::deinitExecution() @@ -118,8 +116,8 @@ void BokehImageOperation::deinitExecution() } } -void BokehImageOperation::determineResolution(unsigned int resolution[], unsigned int preferredResolution[]) +void BokehImageOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]) { - resolution[0] = 512; - resolution[1] = 512; + resolution[0] = COM_BLUR_BOKEH_PIXELS; + resolution[1] = COM_BLUR_BOKEH_PIXELS; } diff --git a/source/blender/compositor/operations/COM_BokehImageOperation.h b/source/blender/compositor/operations/COM_BokehImageOperation.h index a797d0fca53..fe86e162eb2 100644 --- a/source/blender/compositor/operations/COM_BokehImageOperation.h +++ b/source/blender/compositor/operations/COM_BokehImageOperation.h @@ -30,8 +30,6 @@ private: NodeBokehImage *m_data; float m_center[2]; - float m_centerX; - float m_centerY; float m_inverseRounding; float m_circularDistance; float m_flapRad; @@ -47,7 +45,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution @@ -59,7 +57,7 @@ public: */ void deinitExecution(); - void determineResolution(unsigned int resolution[], unsigned int preferredResolution[]); + void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]); void setData(NodeBokehImage *data) { this->m_data = data; } void deleteDataOnFinish() { this->m_deleteData = true; } diff --git a/source/blender/compositor/operations/COM_BoxMaskOperation.cpp b/source/blender/compositor/operations/COM_BoxMaskOperation.cpp index a0fb37f4310..52f84462761 100644 --- a/source/blender/compositor/operations/COM_BoxMaskOperation.cpp +++ b/source/blender/compositor/operations/COM_BoxMaskOperation.cpp @@ -44,7 +44,7 @@ void BoxMaskOperation::initExecution() this->m_aspectRatio = ((float)this->getWidth()) / this->getHeight(); } -void BoxMaskOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void BoxMaskOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputMask[4]; float inputValue[4]; @@ -70,40 +70,40 @@ void BoxMaskOperation::executePixel(float *color, float x, float y, PixelSampler switch (this->m_maskType) { case CMP_NODE_MASKTYPE_ADD: if (inside) { - color[0] = max(inputMask[0], inputValue[0]); + output[0] = max(inputMask[0], inputValue[0]); } else { - color[0] = inputMask[0]; + output[0] = inputMask[0]; } break; case CMP_NODE_MASKTYPE_SUBTRACT: if (inside) { - color[0] = inputMask[0] - inputValue[0]; - CLAMP(color[0], 0, 1); + output[0] = inputMask[0] - inputValue[0]; + CLAMP(output[0], 0, 1); } else { - color[0] = inputMask[0]; + output[0] = inputMask[0]; } break; case CMP_NODE_MASKTYPE_MULTIPLY: if (inside) { - color[0] = inputMask[0] * inputValue[0]; + output[0] = inputMask[0] * inputValue[0]; } else { - color[0] = 0; + output[0] = 0; } break; case CMP_NODE_MASKTYPE_NOT: if (inside) { if (inputMask[0] > 0.0f) { - color[0] = 0; + output[0] = 0; } else { - color[0] = inputValue[0]; + output[0] = inputValue[0]; } } else { - color[0] = inputMask[0]; + output[0] = inputMask[0]; } break; } diff --git a/source/blender/compositor/operations/COM_BoxMaskOperation.h b/source/blender/compositor/operations/COM_BoxMaskOperation.h index 5a6745d9a9b..f39d74829d4 100644 --- a/source/blender/compositor/operations/COM_BoxMaskOperation.h +++ b/source/blender/compositor/operations/COM_BoxMaskOperation.h @@ -45,7 +45,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_BrightnessOperation.cpp b/source/blender/compositor/operations/COM_BrightnessOperation.cpp index 9a6a930c7c9..0613540250c 100644 --- a/source/blender/compositor/operations/COM_BrightnessOperation.cpp +++ b/source/blender/compositor/operations/COM_BrightnessOperation.cpp @@ -37,7 +37,7 @@ void BrightnessOperation::initExecution() this->m_inputContrastProgram = this->getInputSocketReader(2); } -void BrightnessOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void BrightnessOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputValue[4]; float a, b; @@ -65,10 +65,10 @@ void BrightnessOperation::executePixel(float *color, float x, float y, PixelSamp b = a * (brightness + delta); } - color[0] = a * inputValue[0] + b; - color[1] = a * inputValue[1] + b; - color[2] = a * inputValue[2] + b; - color[3] = inputValue[3]; + output[0] = a * inputValue[0] + b; + output[1] = a * inputValue[1] + b; + output[2] = a * inputValue[2] + b; + output[3] = inputValue[3]; } void BrightnessOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_BrightnessOperation.h b/source/blender/compositor/operations/COM_BrightnessOperation.h index 2a6200ad9df..1c8eda63e94 100644 --- a/source/blender/compositor/operations/COM_BrightnessOperation.h +++ b/source/blender/compositor/operations/COM_BrightnessOperation.h @@ -40,7 +40,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_CalculateMeanOperation.cpp b/source/blender/compositor/operations/COM_CalculateMeanOperation.cpp index b0cfdb44736..a2954a20e90 100644 --- a/source/blender/compositor/operations/COM_CalculateMeanOperation.cpp +++ b/source/blender/compositor/operations/COM_CalculateMeanOperation.cpp @@ -42,9 +42,9 @@ void CalculateMeanOperation::initExecution() NodeOperation::initMutex(); } -void CalculateMeanOperation::executePixel(float *color, int x, int y, void *data) +void CalculateMeanOperation::executePixel(float output[4], int x, int y, void *data) { - color[0] = this->m_result; + output[0] = this->m_result; } void CalculateMeanOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_CalculateMeanOperation.h b/source/blender/compositor/operations/COM_CalculateMeanOperation.h index 09727533306..53edea4977e 100644 --- a/source/blender/compositor/operations/COM_CalculateMeanOperation.h +++ b/source/blender/compositor/operations/COM_CalculateMeanOperation.h @@ -46,7 +46,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, int x, int y, void *data); + void executePixel(float output[4], int x, int y, void *data); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_CalculateStandardDeviationOperation.cpp b/source/blender/compositor/operations/COM_CalculateStandardDeviationOperation.cpp index de602ba1dd6..e8268adff7a 100644 --- a/source/blender/compositor/operations/COM_CalculateStandardDeviationOperation.cpp +++ b/source/blender/compositor/operations/COM_CalculateStandardDeviationOperation.cpp @@ -31,9 +31,9 @@ CalculateStandardDeviationOperation::CalculateStandardDeviationOperation() : Cal /* pass */ } -void CalculateStandardDeviationOperation::executePixel(float *color, int x, int y, void *data) +void CalculateStandardDeviationOperation::executePixel(float output[4], int x, int y, void *data) { - color[0] = this->m_standardDeviation; + output[0] = this->m_standardDeviation; } void *CalculateStandardDeviationOperation::initializeTileData(rcti *rect) diff --git a/source/blender/compositor/operations/COM_CalculateStandardDeviationOperation.h b/source/blender/compositor/operations/COM_CalculateStandardDeviationOperation.h index 311cedd7d32..92c4b7fa4a0 100644 --- a/source/blender/compositor/operations/COM_CalculateStandardDeviationOperation.h +++ b/source/blender/compositor/operations/COM_CalculateStandardDeviationOperation.h @@ -39,7 +39,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, int x, int y, void *data); + void executePixel(float output[4], int x, int y, void *data); void *initializeTileData(rcti *rect); diff --git a/source/blender/compositor/operations/COM_ChangeHSVOperation.cpp b/source/blender/compositor/operations/COM_ChangeHSVOperation.cpp index 7a6a22e5c05..e6e93774685 100644 --- a/source/blender/compositor/operations/COM_ChangeHSVOperation.cpp +++ b/source/blender/compositor/operations/COM_ChangeHSVOperation.cpp @@ -39,17 +39,17 @@ void ChangeHSVOperation::deinitExecution() this->m_inputOperation = NULL; } -void ChangeHSVOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void ChangeHSVOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor1[4]; this->m_inputOperation->read(inputColor1, x, y, sampler); - outputValue[0] = inputColor1[0] + (this->m_hue - 0.5f); - if (outputValue[0] > 1.0f) outputValue[0] -= 1.0f; - else if (outputValue[0] < 0.0f) outputValue[0] += 1.0f; - outputValue[1] = inputColor1[1] * this->m_saturation; - outputValue[2] = inputColor1[2] * this->m_value; - outputValue[3] = inputColor1[3]; + output[0] = inputColor1[0] + (this->m_hue - 0.5f); + if (output[0] > 1.0f) output[0] -= 1.0f; + else if (output[0] < 0.0f) output[0] += 1.0f; + output[1] = inputColor1[1] * this->m_saturation; + output[2] = inputColor1[2] * this->m_value; + output[3] = inputColor1[3]; } diff --git a/source/blender/compositor/operations/COM_ChangeHSVOperation.h b/source/blender/compositor/operations/COM_ChangeHSVOperation.h index e5660e44f73..57e5dc991e9 100644 --- a/source/blender/compositor/operations/COM_ChangeHSVOperation.h +++ b/source/blender/compositor/operations/COM_ChangeHSVOperation.h @@ -49,7 +49,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); void setHue(float hue) { this->m_hue = hue; } void setSaturation(float saturation) { this->m_saturation = saturation; } diff --git a/source/blender/compositor/operations/COM_ChannelMatteOperation.cpp b/source/blender/compositor/operations/COM_ChannelMatteOperation.cpp index 85f606fafdf..234a1c7b1e5 100644 --- a/source/blender/compositor/operations/COM_ChannelMatteOperation.cpp +++ b/source/blender/compositor/operations/COM_ChannelMatteOperation.cpp @@ -83,7 +83,7 @@ void ChannelMatteOperation::deinitExecution() this->m_inputImageProgram = NULL; } -void ChannelMatteOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void ChannelMatteOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inColor[4]; float alpha; @@ -100,7 +100,7 @@ void ChannelMatteOperation::executePixel(float *outputValue, float x, float y, P /* flip because 0.0 is transparent, not 1.0 */ alpha = 1.0f - alpha; - /* test range*/ + /* test range */ if (alpha > limit_max) { alpha = inColor[3]; /*whatever it was prior */ } @@ -116,6 +116,6 @@ void ChannelMatteOperation::executePixel(float *outputValue, float x, float y, P */ /* don't make something that was more transparent less transparent */ - outputValue[0] = min(alpha, inColor[3]); + output[0] = min(alpha, inColor[3]); } diff --git a/source/blender/compositor/operations/COM_ChannelMatteOperation.h b/source/blender/compositor/operations/COM_ChannelMatteOperation.h index a02d0618a4c..17f84965f63 100644 --- a/source/blender/compositor/operations/COM_ChannelMatteOperation.h +++ b/source/blender/compositor/operations/COM_ChannelMatteOperation.h @@ -59,7 +59,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); void initExecution(); void deinitExecution(); diff --git a/source/blender/compositor/operations/COM_ChromaMatteOperation.cpp b/source/blender/compositor/operations/COM_ChromaMatteOperation.cpp index 85a19d7c60f..c2406abaa65 100644 --- a/source/blender/compositor/operations/COM_ChromaMatteOperation.cpp +++ b/source/blender/compositor/operations/COM_ChromaMatteOperation.cpp @@ -44,7 +44,7 @@ void ChromaMatteOperation::deinitExecution() this->m_inputKeyProgram = NULL; } -void ChromaMatteOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void ChromaMatteOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inKey[4]; float inImage[4]; @@ -65,7 +65,7 @@ void ChromaMatteOperation::executePixel(float *outputValue, float x, float y, Pi */ /* Algorithm from book "Video Demistified," does not include the spill reduction part */ - /* find theta, the angle that the color space should be rotated based on key*/ + /* find theta, the angle that the color space should be rotated based on key */ theta = atan2(inKey[2], inKey[1]); /*rotate the cb and cr into x/z space */ @@ -88,14 +88,14 @@ void ChromaMatteOperation::executePixel(float *outputValue, float x, float y, Pi /* don't make something that was more transparent less transparent */ if (alpha < inImage[3]) { - outputValue[0] = alpha; + output[0] = alpha; } else { - outputValue[0] = inImage[3]; + output[0] = inImage[3]; } } else { /*pixel is outside key color */ - outputValue[0] = inImage[3]; /* make pixel just as transparent as it was before */ + output[0] = inImage[3]; /* make pixel just as transparent as it was before */ } } diff --git a/source/blender/compositor/operations/COM_ChromaMatteOperation.h b/source/blender/compositor/operations/COM_ChromaMatteOperation.h index 37b58fa45ed..adebb7a30c2 100644 --- a/source/blender/compositor/operations/COM_ChromaMatteOperation.h +++ b/source/blender/compositor/operations/COM_ChromaMatteOperation.h @@ -42,7 +42,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); void initExecution(); void deinitExecution(); diff --git a/source/blender/compositor/operations/COM_ColorBalanceASCCDLOperation.cpp b/source/blender/compositor/operations/COM_ColorBalanceASCCDLOperation.cpp index 33e6db22ef4..dfbbef8c56e 100644 --- a/source/blender/compositor/operations/COM_ColorBalanceASCCDLOperation.cpp +++ b/source/blender/compositor/operations/COM_ColorBalanceASCCDLOperation.cpp @@ -49,7 +49,7 @@ void ColorBalanceASCCDLOperation::initExecution() this->m_inputColorOperation = this->getInputSocketReader(1); } -void ColorBalanceASCCDLOperation::executePixel(float *outputColor, float x, float y, PixelSampler sampler) +void ColorBalanceASCCDLOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor[4]; float value[4]; @@ -61,10 +61,10 @@ void ColorBalanceASCCDLOperation::executePixel(float *outputColor, float x, floa fac = min(1.0f, fac); const float mfac = 1.0f - fac; - outputColor[0] = mfac * inputColor[0] + fac *colorbalance_cdl(inputColor[0], this->m_lift[0], this->m_gamma[0], this->m_gain[0]); - outputColor[1] = mfac * inputColor[1] + fac *colorbalance_cdl(inputColor[1], this->m_lift[1], this->m_gamma[1], this->m_gain[1]); - outputColor[2] = mfac * inputColor[2] + fac *colorbalance_cdl(inputColor[2], this->m_lift[2], this->m_gamma[2], this->m_gain[2]); - outputColor[3] = inputColor[3]; + output[0] = mfac * inputColor[0] + fac *colorbalance_cdl(inputColor[0], this->m_lift[0], this->m_gamma[0], this->m_gain[0]); + output[1] = mfac * inputColor[1] + fac *colorbalance_cdl(inputColor[1], this->m_lift[1], this->m_gamma[1], this->m_gain[1]); + output[2] = mfac * inputColor[2] + fac *colorbalance_cdl(inputColor[2], this->m_lift[2], this->m_gamma[2], this->m_gain[2]); + output[3] = inputColor[3]; } diff --git a/source/blender/compositor/operations/COM_ColorBalanceASCCDLOperation.h b/source/blender/compositor/operations/COM_ColorBalanceASCCDLOperation.h index d6361ea16ba..17fb5f67be9 100644 --- a/source/blender/compositor/operations/COM_ColorBalanceASCCDLOperation.h +++ b/source/blender/compositor/operations/COM_ColorBalanceASCCDLOperation.h @@ -49,7 +49,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_ColorBalanceLGGOperation.cpp b/source/blender/compositor/operations/COM_ColorBalanceLGGOperation.cpp index b0691925361..7e9c10df0a9 100644 --- a/source/blender/compositor/operations/COM_ColorBalanceLGGOperation.cpp +++ b/source/blender/compositor/operations/COM_ColorBalanceLGGOperation.cpp @@ -54,7 +54,7 @@ void ColorBalanceLGGOperation::initExecution() this->m_inputColorOperation = this->getInputSocketReader(1); } -void ColorBalanceLGGOperation::executePixel(float *outputColor, float x, float y, PixelSampler sampler) +void ColorBalanceLGGOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor[4]; float value[4]; @@ -66,10 +66,10 @@ void ColorBalanceLGGOperation::executePixel(float *outputColor, float x, float y fac = min(1.0f, fac); const float mfac = 1.0f - fac; - outputColor[0] = mfac * inputColor[0] + fac *colorbalance_lgg(inputColor[0], this->m_lift[0], this->m_gamma_inv[0], this->m_gain[0]); - outputColor[1] = mfac * inputColor[1] + fac *colorbalance_lgg(inputColor[1], this->m_lift[1], this->m_gamma_inv[1], this->m_gain[1]); - outputColor[2] = mfac * inputColor[2] + fac *colorbalance_lgg(inputColor[2], this->m_lift[2], this->m_gamma_inv[2], this->m_gain[2]); - outputColor[3] = inputColor[3]; + output[0] = mfac * inputColor[0] + fac * colorbalance_lgg(inputColor[0], this->m_lift[0], this->m_gamma_inv[0], this->m_gain[0]); + output[1] = mfac * inputColor[1] + fac * colorbalance_lgg(inputColor[1], this->m_lift[1], this->m_gamma_inv[1], this->m_gain[1]); + output[2] = mfac * inputColor[2] + fac * colorbalance_lgg(inputColor[2], this->m_lift[2], this->m_gamma_inv[2], this->m_gain[2]); + output[3] = inputColor[3]; } diff --git a/source/blender/compositor/operations/COM_ColorBalanceLGGOperation.h b/source/blender/compositor/operations/COM_ColorBalanceLGGOperation.h index c3d44c53e53..edc824475c2 100644 --- a/source/blender/compositor/operations/COM_ColorBalanceLGGOperation.h +++ b/source/blender/compositor/operations/COM_ColorBalanceLGGOperation.h @@ -50,7 +50,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_ColorCorrectionOperation.cpp b/source/blender/compositor/operations/COM_ColorCorrectionOperation.cpp index ebc818b0f7e..b7a3f43237a 100644 --- a/source/blender/compositor/operations/COM_ColorCorrectionOperation.cpp +++ b/source/blender/compositor/operations/COM_ColorCorrectionOperation.cpp @@ -40,7 +40,7 @@ void ColorCorrectionOperation::initExecution() this->m_inputMask = this->getInputSocketReader(1); } -void ColorCorrectionOperation::executePixel(float *output, float x, float y, PixelSampler sampler) +void ColorCorrectionOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputImageColor[4]; float inputMask[4]; diff --git a/source/blender/compositor/operations/COM_ColorCorrectionOperation.h b/source/blender/compositor/operations/COM_ColorCorrectionOperation.h index 685413741fa..018e67b7ada 100644 --- a/source/blender/compositor/operations/COM_ColorCorrectionOperation.h +++ b/source/blender/compositor/operations/COM_ColorCorrectionOperation.h @@ -44,7 +44,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_ColorCurveOperation.cpp b/source/blender/compositor/operations/COM_ColorCurveOperation.cpp index 88bd673a19f..44784837301 100644 --- a/source/blender/compositor/operations/COM_ColorCurveOperation.cpp +++ b/source/blender/compositor/operations/COM_ColorCurveOperation.cpp @@ -58,7 +58,7 @@ void ColorCurveOperation::initExecution() } -void ColorCurveOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void ColorCurveOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { CurveMapping *cumap = this->m_curveMapping; CurveMapping *workingCopy = (CurveMapping *)MEM_dupallocN(cumap); @@ -77,18 +77,18 @@ void ColorCurveOperation::executePixel(float *color, float x, float y, PixelSamp this->m_inputImageProgram->read(image, x, y, sampler); if (*fac >= 1.0f) - curvemapping_evaluate_premulRGBF(workingCopy, color, image); + curvemapping_evaluate_premulRGBF(workingCopy, output, image); else if (*fac <= 0.0f) { - copy_v3_v3(color, image); + copy_v3_v3(output, image); } else { float col[4], mfac = 1.0f - *fac; curvemapping_evaluate_premulRGBF(workingCopy, col, image); - color[0] = mfac * image[0] + *fac * col[0]; - color[1] = mfac * image[1] + *fac * col[1]; - color[2] = mfac * image[2] + *fac * col[2]; + output[0] = mfac * image[0] + *fac * col[0]; + output[1] = mfac * image[1] + *fac * col[1]; + output[2] = mfac * image[2] + *fac * col[2]; } - color[3] = image[3]; + output[3] = image[3]; MEM_freeN(workingCopy); } @@ -126,7 +126,7 @@ void ConstantLevelColorCurveOperation::initExecution() curvemapping_set_black_white(this->m_curveMapping, this->m_black, this->m_white); } -void ConstantLevelColorCurveOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void ConstantLevelColorCurveOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float fac[4]; float image[4]; @@ -136,18 +136,18 @@ void ConstantLevelColorCurveOperation::executePixel(float *color, float x, float this->m_inputImageProgram->read(image, x, y, sampler); if (*fac >= 1.0f) - curvemapping_evaluate_premulRGBF(this->m_curveMapping, color, image); + curvemapping_evaluate_premulRGBF(this->m_curveMapping, output, image); else if (*fac <= 0.0f) { - copy_v3_v3(color, image); + copy_v3_v3(output, image); } else { float col[4], mfac = 1.0f - *fac; curvemapping_evaluate_premulRGBF(this->m_curveMapping, col, image); - color[0] = mfac * image[0] + *fac * col[0]; - color[1] = mfac * image[1] + *fac * col[1]; - color[2] = mfac * image[2] + *fac * col[2]; + output[0] = mfac * image[0] + *fac * col[0]; + output[1] = mfac * image[1] + *fac * col[1]; + output[2] = mfac * image[2] + *fac * col[2]; } - color[3] = image[3]; + output[3] = image[3]; } void ConstantLevelColorCurveOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_ColorCurveOperation.h b/source/blender/compositor/operations/COM_ColorCurveOperation.h index beb2e16298a..063873c6443 100644 --- a/source/blender/compositor/operations/COM_ColorCurveOperation.h +++ b/source/blender/compositor/operations/COM_ColorCurveOperation.h @@ -41,7 +41,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution @@ -70,7 +70,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_ColorMatteOperation.cpp b/source/blender/compositor/operations/COM_ColorMatteOperation.cpp index 5326e397494..d73196e42f5 100644 --- a/source/blender/compositor/operations/COM_ColorMatteOperation.cpp +++ b/source/blender/compositor/operations/COM_ColorMatteOperation.cpp @@ -44,7 +44,7 @@ void ColorMatteOperation::deinitExecution() this->m_inputKeyProgram = NULL; } -void ColorMatteOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void ColorMatteOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inColor[4]; float inKey[4]; @@ -75,11 +75,11 @@ void ColorMatteOperation::executePixel(float *outputValue, float x, float y, Pix /* hue */ ((h_wrap = 2.f * fabsf(inColor[0] - inKey[0])) < hue || (2.f - h_wrap) < hue) ) { - outputValue[0] = 0.0f; /*make transparent*/ + output[0] = 0.0f; /* make transparent */ } else { /*pixel is outside key color */ - outputValue[0] = inColor[3]; /* make pixel just as transparent as it was before */ + output[0] = inColor[3]; /* make pixel just as transparent as it was before */ } } diff --git a/source/blender/compositor/operations/COM_ColorMatteOperation.h b/source/blender/compositor/operations/COM_ColorMatteOperation.h index de7c4dd8ce2..582a94e1873 100644 --- a/source/blender/compositor/operations/COM_ColorMatteOperation.h +++ b/source/blender/compositor/operations/COM_ColorMatteOperation.h @@ -42,7 +42,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); void initExecution(); void deinitExecution(); diff --git a/source/blender/compositor/operations/COM_ColorRampOperation.cpp b/source/blender/compositor/operations/COM_ColorRampOperation.cpp index edd7df89c81..1618c83aece 100644 --- a/source/blender/compositor/operations/COM_ColorRampOperation.cpp +++ b/source/blender/compositor/operations/COM_ColorRampOperation.cpp @@ -43,12 +43,12 @@ void ColorRampOperation::initExecution() this->m_inputProgram = this->getInputSocketReader(0); } -void ColorRampOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void ColorRampOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float values[4]; this->m_inputProgram->read(values, x, y, sampler); - do_colorband(this->m_colorBand, values[0], color); + do_colorband(this->m_colorBand, values[0], output); } void ColorRampOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_ColorRampOperation.h b/source/blender/compositor/operations/COM_ColorRampOperation.h index c5f3fe449de..96d9a525e1e 100644 --- a/source/blender/compositor/operations/COM_ColorRampOperation.h +++ b/source/blender/compositor/operations/COM_ColorRampOperation.h @@ -38,7 +38,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_ColorSpillOperation.cpp b/source/blender/compositor/operations/COM_ColorSpillOperation.cpp index 2c0bfc10bb0..152b10709fb 100644 --- a/source/blender/compositor/operations/COM_ColorSpillOperation.cpp +++ b/source/blender/compositor/operations/COM_ColorSpillOperation.cpp @@ -84,7 +84,7 @@ void ColorSpillOperation::deinitExecution() this->m_inputFacReader = NULL; } -void ColorSpillOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void ColorSpillOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float fac[4]; float input[4]; @@ -93,13 +93,13 @@ void ColorSpillOperation::executePixel(float *outputValue, float x, float y, Pix float rfac = min(1.0f, fac[0]); float map = calculateMapValue(rfac, input); if (map > 0.0f) { - outputValue[0] = input[0] + this->m_rmut * (this->m_settings->uspillr * map); - outputValue[1] = input[1] + this->m_gmut * (this->m_settings->uspillg * map); - outputValue[2] = input[2] + this->m_bmut * (this->m_settings->uspillb * map); - outputValue[3] = input[3]; + output[0] = input[0] + this->m_rmut * (this->m_settings->uspillr * map); + output[1] = input[1] + this->m_gmut * (this->m_settings->uspillg * map); + output[2] = input[2] + this->m_bmut * (this->m_settings->uspillb * map); + output[3] = input[3]; } else { - copy_v4_v4(outputValue, input); + copy_v4_v4(output, input); } } float ColorSpillOperation::calculateMapValue(float fac, float *input) diff --git a/source/blender/compositor/operations/COM_ColorSpillOperation.h b/source/blender/compositor/operations/COM_ColorSpillOperation.h index ea443f2a5a1..94ff78c37b2 100644 --- a/source/blender/compositor/operations/COM_ColorSpillOperation.h +++ b/source/blender/compositor/operations/COM_ColorSpillOperation.h @@ -46,7 +46,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); void initExecution(); void deinitExecution(); diff --git a/source/blender/compositor/operations/COM_CombineChannelsOperation.cpp b/source/blender/compositor/operations/COM_CombineChannelsOperation.cpp index d05040c4c12..ded686bb5de 100644 --- a/source/blender/compositor/operations/COM_CombineChannelsOperation.cpp +++ b/source/blender/compositor/operations/COM_CombineChannelsOperation.cpp @@ -50,7 +50,8 @@ bool CombineChannelsOperation::determineDependingAreaOfInterest(rcti *input, Rea output->xmax = tempOutput.xmax; output->ymax = tempOutput.ymax; first = false; - } else { + } + else { output->xmin = MIN2(output->xmin, tempOutput.xmin); output->ymin = MIN2(output->ymin, tempOutput.ymin); output->xmax = MAX2(output->xmax, tempOutput.xmax); @@ -78,24 +79,24 @@ void CombineChannelsOperation::deinitExecution() } -void CombineChannelsOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void CombineChannelsOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float input[4]; /// @todo: remove if statements if (this->m_inputChannel1Operation) { this->m_inputChannel1Operation->read(input, x, y, sampler); - color[0] = input[0]; + output[0] = input[0]; } if (this->m_inputChannel2Operation) { this->m_inputChannel2Operation->read(input, x, y, sampler); - color[1] = input[0]; + output[1] = input[0]; } if (this->m_inputChannel3Operation) { this->m_inputChannel3Operation->read(input, x, y, sampler); - color[2] = input[0]; + output[2] = input[0]; } if (this->m_inputChannel4Operation) { this->m_inputChannel4Operation->read(input, x, y, sampler); - color[3] = input[0]; + output[3] = input[0]; } } diff --git a/source/blender/compositor/operations/COM_CombineChannelsOperation.h b/source/blender/compositor/operations/COM_CombineChannelsOperation.h index ff1251a3949..460eb9bdcb1 100644 --- a/source/blender/compositor/operations/COM_CombineChannelsOperation.h +++ b/source/blender/compositor/operations/COM_CombineChannelsOperation.h @@ -33,7 +33,7 @@ private: SocketReader *m_inputChannel4Operation; public: CombineChannelsOperation(); - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); void initExecution(); void deinitExecution(); diff --git a/source/blender/compositor/operations/COM_CompositorOperation.cpp b/source/blender/compositor/operations/COM_CompositorOperation.cpp index cba8c753d6a..141d071dddc 100644 --- a/source/blender/compositor/operations/COM_CompositorOperation.cpp +++ b/source/blender/compositor/operations/COM_CompositorOperation.cpp @@ -158,7 +158,7 @@ void CompositorOperation::executeRegion(rcti *rect, unsigned int tileNumber) } } -void CompositorOperation::determineResolution(unsigned int resolution[], unsigned int preferredResolution[]) +void CompositorOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]) { int width = this->m_rd->xsch * this->m_rd->size / 100; int height = this->m_rd->ysch * this->m_rd->size / 100; diff --git a/source/blender/compositor/operations/COM_CompositorOperation.h b/source/blender/compositor/operations/COM_CompositorOperation.h index 882e50b4922..ae94e974db0 100644 --- a/source/blender/compositor/operations/COM_CompositorOperation.h +++ b/source/blender/compositor/operations/COM_CompositorOperation.h @@ -71,6 +71,6 @@ public: void initExecution(); void deinitExecution(); const CompositorPriority getRenderPriority() const { return COM_PRIORITY_MEDIUM; } - void determineResolution(unsigned int resolution[], unsigned int preferredResolution[]); + void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]); }; #endif diff --git a/source/blender/compositor/operations/COM_ConvertColorProfileOperation.cpp b/source/blender/compositor/operations/COM_ConvertColorProfileOperation.cpp index c7272d461d6..79ce149e790 100644 --- a/source/blender/compositor/operations/COM_ConvertColorProfileOperation.cpp +++ b/source/blender/compositor/operations/COM_ConvertColorProfileOperation.cpp @@ -38,11 +38,11 @@ void ConvertColorProfileOperation::initExecution() this->m_inputOperation = this->getInputSocketReader(0); } -void ConvertColorProfileOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void ConvertColorProfileOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float color[4]; this->m_inputOperation->read(color, x, y, sampler); - IMB_buffer_float_from_float(outputValue, color, 4, this->m_toProfile, this->m_fromProfile, this->m_predivided, 1, 1, 0, 0); + IMB_buffer_float_from_float(output, color, 4, this->m_toProfile, this->m_fromProfile, this->m_predivided, 1, 1, 0, 0); } void ConvertColorProfileOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_ConvertColorProfileOperation.h b/source/blender/compositor/operations/COM_ConvertColorProfileOperation.h index 09d96a92d95..a8cbc613fb8 100644 --- a/source/blender/compositor/operations/COM_ConvertColorProfileOperation.h +++ b/source/blender/compositor/operations/COM_ConvertColorProfileOperation.h @@ -59,7 +59,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_ConvertColorToBWOperation.cpp b/source/blender/compositor/operations/COM_ConvertColorToBWOperation.cpp index 4da09a69a15..9cff5e8eaa6 100644 --- a/source/blender/compositor/operations/COM_ConvertColorToBWOperation.cpp +++ b/source/blender/compositor/operations/COM_ConvertColorToBWOperation.cpp @@ -34,11 +34,11 @@ void ConvertColorToBWOperation::initExecution() this->m_inputOperation = this->getInputSocketReader(0); } -void ConvertColorToBWOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void ConvertColorToBWOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor[4]; this->m_inputOperation->read(&inputColor[0], x, y, sampler); - outputValue[0] = rgb_to_bw(inputColor); + output[0] = rgb_to_bw(inputColor); } void ConvertColorToBWOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_ConvertColorToBWOperation.h b/source/blender/compositor/operations/COM_ConvertColorToBWOperation.h index a9951af2e3b..963bd32a2f6 100644 --- a/source/blender/compositor/operations/COM_ConvertColorToBWOperation.h +++ b/source/blender/compositor/operations/COM_ConvertColorToBWOperation.h @@ -44,7 +44,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_ConvertColorToValueProg.cpp b/source/blender/compositor/operations/COM_ConvertColorToValueProg.cpp index 17bd34d51b0..3a65519864a 100644 --- a/source/blender/compositor/operations/COM_ConvertColorToValueProg.cpp +++ b/source/blender/compositor/operations/COM_ConvertColorToValueProg.cpp @@ -34,11 +34,11 @@ void ConvertColorToValueProg::initExecution() this->m_inputOperation = this->getInputSocketReader(0); } -void ConvertColorToValueProg::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void ConvertColorToValueProg::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor[4]; this->m_inputOperation->read(&inputColor[0], x, y, sampler); - outputValue[0] = (inputColor[0] + inputColor[1] + inputColor[2]) / 3.0f; + output[0] = (inputColor[0] + inputColor[1] + inputColor[2]) / 3.0f; } void ConvertColorToValueProg::deinitExecution() diff --git a/source/blender/compositor/operations/COM_ConvertColorToValueProg.h b/source/blender/compositor/operations/COM_ConvertColorToValueProg.h index 6a20d4bf27a..5c25d5d0540 100644 --- a/source/blender/compositor/operations/COM_ConvertColorToValueProg.h +++ b/source/blender/compositor/operations/COM_ConvertColorToValueProg.h @@ -44,7 +44,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_ConvertColorToVectorOperation.cpp b/source/blender/compositor/operations/COM_ConvertColorToVectorOperation.cpp index ec1f0fd37e4..a9b8cbb4272 100644 --- a/source/blender/compositor/operations/COM_ConvertColorToVectorOperation.cpp +++ b/source/blender/compositor/operations/COM_ConvertColorToVectorOperation.cpp @@ -34,9 +34,9 @@ void ConvertColorToVectorOperation::initExecution() this->m_inputOperation = this->getInputSocketReader(0); } -void ConvertColorToVectorOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void ConvertColorToVectorOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { - this->m_inputOperation->read(outputValue, x, y, sampler); + this->m_inputOperation->read(output, x, y, sampler); } void ConvertColorToVectorOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_ConvertColorToVectorOperation.h b/source/blender/compositor/operations/COM_ConvertColorToVectorOperation.h index 861807db8db..93644cb5d1c 100644 --- a/source/blender/compositor/operations/COM_ConvertColorToVectorOperation.h +++ b/source/blender/compositor/operations/COM_ConvertColorToVectorOperation.h @@ -44,7 +44,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.cpp b/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.cpp index 80416bbccdf..88289f12ebb 100644 --- a/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.cpp +++ b/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.cpp @@ -22,6 +22,7 @@ #include "COM_ConvertDepthToRadiusOperation.h" #include "BLI_math.h" +#include "BKE_camera.h" #include "DNA_camera_types.h" ConvertDepthToRadiusOperation::ConvertDepthToRadiusOperation() : NodeOperation() @@ -37,45 +38,41 @@ ConvertDepthToRadiusOperation::ConvertDepthToRadiusOperation() : NodeOperation() float ConvertDepthToRadiusOperation::determineFocalDistance() { - - if (this->m_cameraObject == NULL || this->m_cameraObject->type != OB_CAMERA) { - return 10.0f; - } - else { + if (this->m_cameraObject && this->m_cameraObject->type == OB_CAMERA) { Camera *camera = (Camera *)this->m_cameraObject->data; this->m_cam_lens = camera->lens; - if (camera->dof_ob) { - /* too simple, better to return the distance on the view axis only - * return len_v3v3(ob->obmat[3], cam->dof_ob->obmat[3]); */ - float mat[4][4], imat[4][4], obmat[4][4]; - - copy_m4_m4(obmat, this->m_cameraObject->obmat); - normalize_m4(obmat); - invert_m4_m4(imat, obmat); - mult_m4_m4m4(mat, imat, camera->dof_ob->obmat); - return (float)fabs(mat[3][2]); - } - return camera->YF_dofdist; + return BKE_camera_object_dof_distance(this->m_cameraObject); + } + else { + return 10.0f; } } void ConvertDepthToRadiusOperation::initExecution() { + float cam_sensor = DEFAULT_SENSOR_WIDTH; + Camera *camera = NULL; + + if (this->m_cameraObject && this->m_cameraObject->type == OB_CAMERA) { + camera = (Camera *)this->m_cameraObject->data; + cam_sensor = BKE_camera_sensor_size(camera->sensor_fit, camera->sensor_x, camera->sensor_y); + } + this->m_inputOperation = this->getInputSocketReader(0); float focalDistance = determineFocalDistance(); if (focalDistance == 0.0f) focalDistance = 1e10f; /* if the dof is 0.0 then set it be be far away */ - this->m_inverseFocalDistance = 1.f / focalDistance; + this->m_inverseFocalDistance = 1.0f / focalDistance; this->m_aspect = (this->getWidth() > this->getHeight()) ? (this->getHeight() / (float)this->getWidth()) : (this->getWidth() / (float)this->getHeight()); - this->m_aperture = 0.5f * (this->m_cam_lens / (this->m_aspect * 32.0f)) / this->m_fStop; - float minsz = MIN2(getWidth(), getHeight()); - this->m_dof_sp = (float)minsz / (16.f / this->m_cam_lens); // <- == aspect * MIN2(img->x, img->y) / tan(0.5f * fov); - + this->m_aperture = 0.5f * (this->m_cam_lens / (this->m_aspect * cam_sensor)) / this->m_fStop; + float minsz = min(getWidth(), getHeight()); + this->m_dof_sp = (float)minsz / ((cam_sensor / 2.0f) / this->m_cam_lens); // <- == aspect * MIN2(img->x, img->y) / tan(0.5f * fov); + if (this->m_blurPostOperation) { - m_blurPostOperation->setSigma(m_aperture*128.0f); + m_blurPostOperation->setSigma(min(m_aperture * 128.0f, this->m_maxRadius)); } } -void ConvertDepthToRadiusOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void ConvertDepthToRadiusOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputValue[4]; float z; @@ -87,9 +84,9 @@ void ConvertDepthToRadiusOperation::executePixel(float *outputValue, float x, fl // bug #6656 part 2b, do not rescale #if 0 - bcrad = 0.5f*fabs(aperture*(dof_sp*(cam_invfdist - iZ) - 1.f)); + bcrad = 0.5f * fabs(aperture * (dof_sp * (cam_invfdist - iZ) - 1.0f)); // scale crad back to original maximum and blend - crad->rect[px] = bcrad + wts->rect[px]*(scf*crad->rect[px] - bcrad); + crad->rect[px] = bcrad + wts->rect[px] * (scf * crad->rect[px] - bcrad); #endif radius = 0.5f * fabsf(this->m_aperture * (this->m_dof_sp * (this->m_inverseFocalDistance - iZ) - 1.f)); // 'bug' #6615, limit minimum radius to 1 pixel, not really a solution, but somewhat mitigates the problem @@ -97,9 +94,11 @@ void ConvertDepthToRadiusOperation::executePixel(float *outputValue, float x, fl if (radius > this->m_maxRadius) { radius = this->m_maxRadius; } - outputValue[0] = radius; + output[0] = radius; + } + else { + output[0] = 0.0f; } - else outputValue[0] = 0.0f; } void ConvertDepthToRadiusOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.h b/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.h index 4f80ef69f43..d5a1fd72cbf 100644 --- a/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.h +++ b/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.h @@ -54,7 +54,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_ConvertHSVToRGBOperation.cpp b/source/blender/compositor/operations/COM_ConvertHSVToRGBOperation.cpp index 4b42de26f59..65907a8e537 100644 --- a/source/blender/compositor/operations/COM_ConvertHSVToRGBOperation.cpp +++ b/source/blender/compositor/operations/COM_ConvertHSVToRGBOperation.cpp @@ -35,12 +35,12 @@ void ConvertHSVToRGBOperation::initExecution() this->m_inputOperation = this->getInputSocketReader(0); } -void ConvertHSVToRGBOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void ConvertHSVToRGBOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor[4]; this->m_inputOperation->read(inputColor, x, y, sampler); - hsv_to_rgb(inputColor[0], inputColor[1], inputColor[2], &outputValue[0], &outputValue[1], &outputValue[2]); - outputValue[3] = inputColor[3]; + hsv_to_rgb_v(inputColor, output); + output[3] = inputColor[3]; } void ConvertHSVToRGBOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_ConvertHSVToRGBOperation.h b/source/blender/compositor/operations/COM_ConvertHSVToRGBOperation.h index 28ce70170a0..17419ca2a05 100644 --- a/source/blender/compositor/operations/COM_ConvertHSVToRGBOperation.h +++ b/source/blender/compositor/operations/COM_ConvertHSVToRGBOperation.h @@ -44,7 +44,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_ConvertKeyToPremulOperation.cpp b/source/blender/compositor/operations/COM_ConvertKeyToPremulOperation.cpp index 787b1a4547c..4497db52a0f 100644 --- a/source/blender/compositor/operations/COM_ConvertKeyToPremulOperation.cpp +++ b/source/blender/compositor/operations/COM_ConvertKeyToPremulOperation.cpp @@ -35,7 +35,7 @@ void ConvertKeyToPremulOperation::initExecution() this->m_inputColor = getInputSocketReader(0); } -void ConvertKeyToPremulOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void ConvertKeyToPremulOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputValue[4]; float alpha; @@ -43,10 +43,10 @@ void ConvertKeyToPremulOperation::executePixel(float *outputValue, float x, floa this->m_inputColor->read(inputValue, x, y, sampler); alpha = inputValue[3]; - mul_v3_v3fl(outputValue, inputValue, alpha); + mul_v3_v3fl(output, inputValue, alpha); /* never touches the alpha */ - outputValue[3] = alpha; + output[3] = alpha; } void ConvertKeyToPremulOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_ConvertKeyToPremulOperation.h b/source/blender/compositor/operations/COM_ConvertKeyToPremulOperation.h index a1a8836a690..502674e26db 100644 --- a/source/blender/compositor/operations/COM_ConvertKeyToPremulOperation.h +++ b/source/blender/compositor/operations/COM_ConvertKeyToPremulOperation.h @@ -40,7 +40,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); void initExecution(); void deinitExecution(); diff --git a/source/blender/compositor/operations/COM_ConvertPremulToKeyOperation.cpp b/source/blender/compositor/operations/COM_ConvertPremulToKeyOperation.cpp index 22cfdd2f572..b92da4c324f 100644 --- a/source/blender/compositor/operations/COM_ConvertPremulToKeyOperation.cpp +++ b/source/blender/compositor/operations/COM_ConvertPremulToKeyOperation.cpp @@ -35,7 +35,7 @@ void ConvertPremulToKeyOperation::initExecution() this->m_inputColor = getInputSocketReader(0); } -void ConvertPremulToKeyOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void ConvertPremulToKeyOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputValue[4]; float alpha; @@ -44,14 +44,14 @@ void ConvertPremulToKeyOperation::executePixel(float *outputValue, float x, floa alpha = inputValue[3]; if (fabsf(alpha) < 1e-5f) { - zero_v3(outputValue); + zero_v3(output); } else { - mul_v3_v3fl(outputValue, inputValue, 1.0f / alpha); + mul_v3_v3fl(output, inputValue, 1.0f / alpha); } /* never touches the alpha */ - outputValue[3] = alpha; + output[3] = alpha; } void ConvertPremulToKeyOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_ConvertPremulToKeyOperation.h b/source/blender/compositor/operations/COM_ConvertPremulToKeyOperation.h index fb83a06c25d..04a9965858d 100644 --- a/source/blender/compositor/operations/COM_ConvertPremulToKeyOperation.h +++ b/source/blender/compositor/operations/COM_ConvertPremulToKeyOperation.h @@ -40,7 +40,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); void initExecution(); void deinitExecution(); diff --git a/source/blender/compositor/operations/COM_ConvertRGBToHSVOperation.cpp b/source/blender/compositor/operations/COM_ConvertRGBToHSVOperation.cpp index 8478eac75b0..3c7a9d5fd50 100644 --- a/source/blender/compositor/operations/COM_ConvertRGBToHSVOperation.cpp +++ b/source/blender/compositor/operations/COM_ConvertRGBToHSVOperation.cpp @@ -35,12 +35,12 @@ void ConvertRGBToHSVOperation::initExecution() this->m_inputOperation = this->getInputSocketReader(0); } -void ConvertRGBToHSVOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void ConvertRGBToHSVOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor[4]; this->m_inputOperation->read(inputColor, x, y, sampler); - rgb_to_hsv(inputColor[0], inputColor[1], inputColor[2], &outputValue[0], &outputValue[1], &outputValue[2]); - outputValue[3] = inputColor[3]; + rgb_to_hsv_v(inputColor, output); + output[3] = inputColor[3]; } void ConvertRGBToHSVOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_ConvertRGBToHSVOperation.h b/source/blender/compositor/operations/COM_ConvertRGBToHSVOperation.h index 09f6c7e48a6..fdc8dfed31b 100644 --- a/source/blender/compositor/operations/COM_ConvertRGBToHSVOperation.h +++ b/source/blender/compositor/operations/COM_ConvertRGBToHSVOperation.h @@ -44,7 +44,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_ConvertRGBToYCCOperation.cpp b/source/blender/compositor/operations/COM_ConvertRGBToYCCOperation.cpp index 52aa1d7a123..6f6dffdc72b 100644 --- a/source/blender/compositor/operations/COM_ConvertRGBToYCCOperation.cpp +++ b/source/blender/compositor/operations/COM_ConvertRGBToYCCOperation.cpp @@ -50,7 +50,7 @@ void ConvertRGBToYCCOperation::setMode(int mode) } } -void ConvertRGBToYCCOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void ConvertRGBToYCCOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor[4]; float color[3]; @@ -60,8 +60,8 @@ void ConvertRGBToYCCOperation::executePixel(float *outputValue, float x, float y /* divided by 255 to normalize for viewing in */ /* R,G,B --> Y,Cb,Cr */ - mul_v3_v3fl(outputValue, color, 1.0f / 255.0f); - outputValue[3] = inputColor[3]; + mul_v3_v3fl(output, color, 1.0f / 255.0f); + output[3] = inputColor[3]; } void ConvertRGBToYCCOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_ConvertRGBToYCCOperation.h b/source/blender/compositor/operations/COM_ConvertRGBToYCCOperation.h index 7f4eb6d7318..3f85555f3bb 100644 --- a/source/blender/compositor/operations/COM_ConvertRGBToYCCOperation.h +++ b/source/blender/compositor/operations/COM_ConvertRGBToYCCOperation.h @@ -48,7 +48,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_ConvertRGBToYUVOperation.cpp b/source/blender/compositor/operations/COM_ConvertRGBToYUVOperation.cpp index 2206a066a37..8ce9e150080 100644 --- a/source/blender/compositor/operations/COM_ConvertRGBToYUVOperation.cpp +++ b/source/blender/compositor/operations/COM_ConvertRGBToYUVOperation.cpp @@ -34,12 +34,12 @@ void ConvertRGBToYUVOperation::initExecution() this->m_inputOperation = this->getInputSocketReader(0); } -void ConvertRGBToYUVOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void ConvertRGBToYUVOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor[4]; this->m_inputOperation->read(inputColor, x, y, sampler); - rgb_to_yuv(inputColor[0], inputColor[1], inputColor[2], &outputValue[0], &outputValue[1], &outputValue[2]); - outputValue[3] = inputColor[3]; + rgb_to_yuv(inputColor[0], inputColor[1], inputColor[2], &output[0], &output[1], &output[2]); + output[3] = inputColor[3]; } void ConvertRGBToYUVOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_ConvertRGBToYUVOperation.h b/source/blender/compositor/operations/COM_ConvertRGBToYUVOperation.h index f7b3da800b3..97d57f657ec 100644 --- a/source/blender/compositor/operations/COM_ConvertRGBToYUVOperation.h +++ b/source/blender/compositor/operations/COM_ConvertRGBToYUVOperation.h @@ -43,7 +43,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_ConvertValueToColorProg.cpp b/source/blender/compositor/operations/COM_ConvertValueToColorProg.cpp index 330ffd00acb..98e7650aa56 100644 --- a/source/blender/compositor/operations/COM_ConvertValueToColorProg.cpp +++ b/source/blender/compositor/operations/COM_ConvertValueToColorProg.cpp @@ -33,14 +33,12 @@ void ConvertValueToColorProg::initExecution() this->m_inputProgram = this->getInputSocketReader(0); } -void ConvertValueToColorProg::executePixel(float *color, float x, float y, PixelSampler sampler) +void ConvertValueToColorProg::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputValue[4]; this->m_inputProgram->read(inputValue, x, y, sampler); - color[0] = inputValue[0]; - color[1] = inputValue[0]; - color[2] = inputValue[0]; - color[3] = 1.0f; + output[0] = output[1] = output[2] = inputValue[0]; + output[3] = 1.0f; } void ConvertValueToColorProg::deinitExecution() diff --git a/source/blender/compositor/operations/COM_ConvertValueToColorProg.h b/source/blender/compositor/operations/COM_ConvertValueToColorProg.h index 2fa5edcf09b..f0f6cfb8fd2 100644 --- a/source/blender/compositor/operations/COM_ConvertValueToColorProg.h +++ b/source/blender/compositor/operations/COM_ConvertValueToColorProg.h @@ -37,7 +37,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_ConvertValueToVectorOperation.cpp b/source/blender/compositor/operations/COM_ConvertValueToVectorOperation.cpp index 54a5b0dbd0e..411409d263c 100644 --- a/source/blender/compositor/operations/COM_ConvertValueToVectorOperation.cpp +++ b/source/blender/compositor/operations/COM_ConvertValueToVectorOperation.cpp @@ -34,14 +34,14 @@ void ConvertValueToVectorOperation::initExecution() this->m_inputOperation = this->getInputSocketReader(0); } -void ConvertValueToVectorOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void ConvertValueToVectorOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float input[4]; this->m_inputOperation->read(input, x, y, sampler); - outputValue[0] = input[0]; - outputValue[1] = input[0]; - outputValue[2] = input[0]; - outputValue[3] = 0.0f; + output[0] = input[0]; + output[1] = input[0]; + output[2] = input[0]; + output[3] = 0.0f; } void ConvertValueToVectorOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_ConvertValueToVectorOperation.h b/source/blender/compositor/operations/COM_ConvertValueToVectorOperation.h index c0936a32eb5..da45848ca34 100644 --- a/source/blender/compositor/operations/COM_ConvertValueToVectorOperation.h +++ b/source/blender/compositor/operations/COM_ConvertValueToVectorOperation.h @@ -44,7 +44,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_ConvertVectorToColorOperation.cpp b/source/blender/compositor/operations/COM_ConvertVectorToColorOperation.cpp index 9fb9a2e0705..78cb706c32d 100644 --- a/source/blender/compositor/operations/COM_ConvertVectorToColorOperation.cpp +++ b/source/blender/compositor/operations/COM_ConvertVectorToColorOperation.cpp @@ -34,10 +34,10 @@ void ConvertVectorToColorOperation::initExecution() this->m_inputOperation = this->getInputSocketReader(0); } -void ConvertVectorToColorOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void ConvertVectorToColorOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { - this->m_inputOperation->read(outputValue, x, y, sampler); - outputValue[3] = 1.0f; + this->m_inputOperation->read(output, x, y, sampler); + output[3] = 1.0f; } void ConvertVectorToColorOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_ConvertVectorToColorOperation.h b/source/blender/compositor/operations/COM_ConvertVectorToColorOperation.h index a062c452a91..9ef5f8fece3 100644 --- a/source/blender/compositor/operations/COM_ConvertVectorToColorOperation.h +++ b/source/blender/compositor/operations/COM_ConvertVectorToColorOperation.h @@ -44,7 +44,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_ConvertVectorToValueOperation.cpp b/source/blender/compositor/operations/COM_ConvertVectorToValueOperation.cpp index 23b552f1dbe..a3612414029 100644 --- a/source/blender/compositor/operations/COM_ConvertVectorToValueOperation.cpp +++ b/source/blender/compositor/operations/COM_ConvertVectorToValueOperation.cpp @@ -34,11 +34,11 @@ void ConvertVectorToValueOperation::initExecution() this->m_inputOperation = this->getInputSocketReader(0); } -void ConvertVectorToValueOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void ConvertVectorToValueOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float input[4]; this->m_inputOperation->read(input, x, y, sampler); - outputValue[0] = (input[0] + input[1] + input[2]) / 3.0f; + output[0] = (input[0] + input[1] + input[2]) / 3.0f; } void ConvertVectorToValueOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_ConvertVectorToValueOperation.h b/source/blender/compositor/operations/COM_ConvertVectorToValueOperation.h index b662f3eed6c..e42f235a12b 100644 --- a/source/blender/compositor/operations/COM_ConvertVectorToValueOperation.h +++ b/source/blender/compositor/operations/COM_ConvertVectorToValueOperation.h @@ -44,7 +44,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_ConvertYCCToRGBOperation.cpp b/source/blender/compositor/operations/COM_ConvertYCCToRGBOperation.cpp index 88a7e7dedd9..8f9eaf49ea4 100644 --- a/source/blender/compositor/operations/COM_ConvertYCCToRGBOperation.cpp +++ b/source/blender/compositor/operations/COM_ConvertYCCToRGBOperation.cpp @@ -50,7 +50,7 @@ void ConvertYCCToRGBOperation::setMode(int mode) } } -void ConvertYCCToRGBOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void ConvertYCCToRGBOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor[4]; this->m_inputOperation->read(inputColor, x, y, sampler); @@ -59,8 +59,8 @@ void ConvertYCCToRGBOperation::executePixel(float *outputValue, float x, float y /* R,G,B --> Y,Cb,Cr */ mul_v3_fl(inputColor, 255.0f); - ycc_to_rgb(inputColor[0], inputColor[1], inputColor[2], &outputValue[0], &outputValue[1], &outputValue[2], this->m_mode); - outputValue[3] = inputColor[3]; + ycc_to_rgb(inputColor[0], inputColor[1], inputColor[2], &output[0], &output[1], &output[2], this->m_mode); + output[3] = inputColor[3]; } void ConvertYCCToRGBOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_ConvertYCCToRGBOperation.h b/source/blender/compositor/operations/COM_ConvertYCCToRGBOperation.h index a8e03bcb807..0a8b67e0bee 100644 --- a/source/blender/compositor/operations/COM_ConvertYCCToRGBOperation.h +++ b/source/blender/compositor/operations/COM_ConvertYCCToRGBOperation.h @@ -48,7 +48,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_ConvertYUVToRGBOperation.cpp b/source/blender/compositor/operations/COM_ConvertYUVToRGBOperation.cpp index 1a5e7cbf2a6..197c7f9f043 100644 --- a/source/blender/compositor/operations/COM_ConvertYUVToRGBOperation.cpp +++ b/source/blender/compositor/operations/COM_ConvertYUVToRGBOperation.cpp @@ -34,12 +34,12 @@ void ConvertYUVToRGBOperation::initExecution() this->m_inputOperation = this->getInputSocketReader(0); } -void ConvertYUVToRGBOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void ConvertYUVToRGBOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor[4]; this->m_inputOperation->read(inputColor, x, y, sampler); - yuv_to_rgb(inputColor[0], inputColor[1], inputColor[2], &outputValue[0], &outputValue[1], &outputValue[2]); - outputValue[3] = inputColor[3]; + yuv_to_rgb(inputColor[0], inputColor[1], inputColor[2], &output[0], &output[1], &output[2]); + output[3] = inputColor[3]; } void ConvertYUVToRGBOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_ConvertYUVToRGBOperation.h b/source/blender/compositor/operations/COM_ConvertYUVToRGBOperation.h index 80321ae37d2..ee11ef8df60 100644 --- a/source/blender/compositor/operations/COM_ConvertYUVToRGBOperation.h +++ b/source/blender/compositor/operations/COM_ConvertYUVToRGBOperation.h @@ -43,7 +43,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_ConvolutionEdgeFilterOperation.cpp b/source/blender/compositor/operations/COM_ConvolutionEdgeFilterOperation.cpp index 90bda5c8d2c..657126d458c 100644 --- a/source/blender/compositor/operations/COM_ConvolutionEdgeFilterOperation.cpp +++ b/source/blender/compositor/operations/COM_ConvolutionEdgeFilterOperation.cpp @@ -28,9 +28,9 @@ ConvolutionEdgeFilterOperation::ConvolutionEdgeFilterOperation() : ConvolutionFi /* pass */ } -void ConvolutionEdgeFilterOperation::executePixel(float *color, int x, int y, void *data) +void ConvolutionEdgeFilterOperation::executePixel(float output[4], int x, int y, void *data) { - float in1[4], in2[4], res1[4], res2[4]; + float in1[4], in2[4], res1[4] = {0.0}, res2[4] = {0.0}; int x1 = x - 1; int x2 = x; @@ -48,16 +48,7 @@ void ConvolutionEdgeFilterOperation::executePixel(float *color, int x, int y, vo float value[4]; this->m_inputValueOperation->read(value, x2, y2, NULL); float mval = 1.0f - value[0]; - - res1[0] = 0.0f; - res1[1] = 0.0f; - res1[2] = 0.0f; - res1[3] = 0.0f; - res2[0] = 0.0f; - res2[1] = 0.0f; - res2[2] = 0.0f; - res2[3] = 0.0f; - + this->m_inputOperation->read(in1, x1, y1, NULL); madd_v3_v3fl(res1, in1, this->m_filter[0]); madd_v3_v3fl(res2, in1, this->m_filter[0]); @@ -94,13 +85,13 @@ void ConvolutionEdgeFilterOperation::executePixel(float *color, int x, int y, vo madd_v3_v3fl(res1, in1, this->m_filter[8]); madd_v3_v3fl(res2, in1, this->m_filter[8]); - color[0] = sqrt(res1[0] * res1[0] + res2[0] * res2[0]); - color[1] = sqrt(res1[1] * res1[1] + res2[1] * res2[1]); - color[2] = sqrt(res1[2] * res1[2] + res2[2] * res2[2]); + output[0] = sqrt(res1[0] * res1[0] + res2[0] * res2[0]); + output[1] = sqrt(res1[1] * res1[1] + res2[1] * res2[1]); + output[2] = sqrt(res1[2] * res1[2] + res2[2] * res2[2]); - color[0] = color[0] * value[0] + in2[0] * mval; - color[1] = color[1] * value[0] + in2[1] * mval; - color[2] = color[2] * value[0] + in2[2] * mval; + output[0] = output[0] * value[0] + in2[0] * mval; + output[1] = output[1] * value[0] + in2[1] * mval; + output[2] = output[2] * value[0] + in2[2] * mval; - color[3] = in2[3]; + output[3] = in2[3]; } diff --git a/source/blender/compositor/operations/COM_ConvolutionEdgeFilterOperation.h b/source/blender/compositor/operations/COM_ConvolutionEdgeFilterOperation.h index b96b8785524..c666dc2cd42 100644 --- a/source/blender/compositor/operations/COM_ConvolutionEdgeFilterOperation.h +++ b/source/blender/compositor/operations/COM_ConvolutionEdgeFilterOperation.h @@ -28,7 +28,7 @@ class ConvolutionEdgeFilterOperation : public ConvolutionFilterOperation { public: ConvolutionEdgeFilterOperation(); - void executePixel(float *color, int x, int y, void *data); + void executePixel(float output[4], int x, int y, void *data); }; #endif diff --git a/source/blender/compositor/operations/COM_ConvolutionFilterOperation.cpp b/source/blender/compositor/operations/COM_ConvolutionFilterOperation.cpp index 6c1e434ab41..fd593b39dcd 100644 --- a/source/blender/compositor/operations/COM_ConvolutionFilterOperation.cpp +++ b/source/blender/compositor/operations/COM_ConvolutionFilterOperation.cpp @@ -67,7 +67,7 @@ void ConvolutionFilterOperation::deinitExecution() } -void ConvolutionFilterOperation::executePixel(float *color, int x, int y, void *data) +void ConvolutionFilterOperation::executePixel(float output[4], int x, int y, void *data) { float in1[4]; float in2[4]; @@ -87,30 +87,30 @@ void ConvolutionFilterOperation::executePixel(float *color, int x, int y, void * this->m_inputValueOperation->read(value, x2, y2, NULL); const float mval = 1.0f - value[0]; - zero_v4(color); + zero_v4(output); this->m_inputOperation->read(in1, x1, y1, NULL); - madd_v4_v4fl(color, in1, this->m_filter[0]); + madd_v4_v4fl(output, in1, this->m_filter[0]); this->m_inputOperation->read(in1, x2, y1, NULL); - madd_v4_v4fl(color, in1, this->m_filter[1]); + madd_v4_v4fl(output, in1, this->m_filter[1]); this->m_inputOperation->read(in1, x3, y1, NULL); - madd_v4_v4fl(color, in1, this->m_filter[2]); + madd_v4_v4fl(output, in1, this->m_filter[2]); this->m_inputOperation->read(in1, x1, y2, NULL); - madd_v4_v4fl(color, in1, this->m_filter[3]); + madd_v4_v4fl(output, in1, this->m_filter[3]); this->m_inputOperation->read(in2, x2, y2, NULL); - madd_v4_v4fl(color, in2, this->m_filter[4]); + madd_v4_v4fl(output, in2, this->m_filter[4]); this->m_inputOperation->read(in1, x3, y2, NULL); - madd_v4_v4fl(color, in1, this->m_filter[5]); + madd_v4_v4fl(output, in1, this->m_filter[5]); this->m_inputOperation->read(in1, x1, y3, NULL); - madd_v4_v4fl(color, in1, this->m_filter[6]); + madd_v4_v4fl(output, in1, this->m_filter[6]); this->m_inputOperation->read(in1, x2, y3, NULL); - madd_v4_v4fl(color, in1, this->m_filter[7]); + madd_v4_v4fl(output, in1, this->m_filter[7]); this->m_inputOperation->read(in1, x3, y3, NULL); - madd_v4_v4fl(color, in1, this->m_filter[8]); + madd_v4_v4fl(output, in1, this->m_filter[8]); - color[0] = color[0] * value[0] + in2[0] * mval; - color[1] = color[1] * value[0] + in2[1] * mval; - color[2] = color[2] * value[0] + in2[2] * mval; - color[3] = color[3] * value[0] + in2[3] * mval; + output[0] = output[0] * value[0] + in2[0] * mval; + output[1] = output[1] * value[0] + in2[1] * mval; + output[2] = output[2] * value[0] + in2[2] * mval; + output[3] = output[3] * value[0] + in2[3] * mval; } bool ConvolutionFilterOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) diff --git a/source/blender/compositor/operations/COM_ConvolutionFilterOperation.h b/source/blender/compositor/operations/COM_ConvolutionFilterOperation.h index 88455730c0e..4c192481ba1 100644 --- a/source/blender/compositor/operations/COM_ConvolutionFilterOperation.h +++ b/source/blender/compositor/operations/COM_ConvolutionFilterOperation.h @@ -39,7 +39,7 @@ public: ConvolutionFilterOperation(); void set3x3Filter(float f1, float f2, float f3, float f4, float f5, float f6, float f7, float f8, float f9); bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output); - void executePixel(float *color, int x, int y, void *data); + void executePixel(float output[4], int x, int y, void *data); void initExecution(); void deinitExecution(); diff --git a/source/blender/compositor/operations/COM_CropOperation.cpp b/source/blender/compositor/operations/COM_CropOperation.cpp index efbc331e7d3..c33bd2544ac 100644 --- a/source/blender/compositor/operations/COM_CropOperation.cpp +++ b/source/blender/compositor/operations/COM_CropOperation.cpp @@ -73,13 +73,13 @@ CropOperation::CropOperation() : CropBaseOperation() /* pass */ } -void CropOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void CropOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { if ((x < this->m_xmax && x >= this->m_xmin) && (y < this->m_ymax && y >= this->m_ymin)) { - this->m_inputOperation->read(color, x, y, sampler); + this->m_inputOperation->read(output, x, y, sampler); } else { - zero_v4(color); + zero_v4(output); } } @@ -100,7 +100,7 @@ bool CropImageOperation::determineDependingAreaOfInterest(rcti *input, ReadBuffe return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output); } -void CropImageOperation::determineResolution(unsigned int resolution[], unsigned int preferedResolution[]) +void CropImageOperation::determineResolution(unsigned int resolution[2], unsigned int preferedResolution[2]) { NodeOperation::determineResolution(resolution, preferedResolution); updateArea(); @@ -108,7 +108,7 @@ void CropImageOperation::determineResolution(unsigned int resolution[], unsigned resolution[1] = this->m_ymax - this->m_ymin; } -void CropImageOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void CropImageOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { - this->m_inputOperation->read(color, (x + this->m_xmin), (y + this->m_ymin), sampler); + this->m_inputOperation->read(output, (x + this->m_xmin), (y + this->m_ymin), sampler); } diff --git a/source/blender/compositor/operations/COM_CropOperation.h b/source/blender/compositor/operations/COM_CropOperation.h index 78644536143..ddc7f855bf1 100644 --- a/source/blender/compositor/operations/COM_CropOperation.h +++ b/source/blender/compositor/operations/COM_CropOperation.h @@ -48,7 +48,7 @@ class CropOperation : public CropBaseOperation { private: public: CropOperation(); - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; class CropImageOperation : public CropBaseOperation { @@ -56,8 +56,8 @@ private: public: CropImageOperation(); bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output); - void determineResolution(unsigned int resolution[], unsigned int preferedResolution[]); - void executePixel(float *color, float x, float y, PixelSampler sampler); + void determineResolution(unsigned int resolution[2], unsigned int preferedResolution[2]); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; #endif diff --git a/source/blender/compositor/operations/COM_DifferenceMatteOperation.cpp b/source/blender/compositor/operations/COM_DifferenceMatteOperation.cpp index ed3799fff5e..e23eb26f527 100644 --- a/source/blender/compositor/operations/COM_DifferenceMatteOperation.cpp +++ b/source/blender/compositor/operations/COM_DifferenceMatteOperation.cpp @@ -44,7 +44,7 @@ void DifferenceMatteOperation::deinitExecution() this->m_inputImage2Program = NULL; } -void DifferenceMatteOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void DifferenceMatteOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inColor1[4]; float inColor2[4]; @@ -64,9 +64,9 @@ void DifferenceMatteOperation::executePixel(float *outputValue, float x, float y /* average together the distances */ difference = difference / 3.0f; - /*make 100% transparent*/ + /* make 100% transparent */ if (difference < tolerance) { - outputValue[0] = 0.0f; + output[0] = 0.0f; } /*in the falloff region, make partially transparent */ else if (difference < falloff + tolerance) { @@ -74,15 +74,15 @@ void DifferenceMatteOperation::executePixel(float *outputValue, float x, float y alpha = difference / falloff; /*only change if more transparent than before */ if (alpha < inColor1[3]) { - outputValue[0] = alpha; + output[0] = alpha; } else { /* leave as before */ - outputValue[0] = inColor1[3]; + output[0] = inColor1[3]; } } else { - /*foreground object*/ - outputValue[0] = inColor1[3]; + /* foreground object */ + output[0] = inColor1[3]; } } diff --git a/source/blender/compositor/operations/COM_DifferenceMatteOperation.h b/source/blender/compositor/operations/COM_DifferenceMatteOperation.h index acec6ebf193..e7d881cbbd5 100644 --- a/source/blender/compositor/operations/COM_DifferenceMatteOperation.h +++ b/source/blender/compositor/operations/COM_DifferenceMatteOperation.h @@ -43,7 +43,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); void initExecution(); void deinitExecution(); diff --git a/source/blender/compositor/operations/COM_DilateErodeOperation.cpp b/source/blender/compositor/operations/COM_DilateErodeOperation.cpp index 2752c6a7b90..5e70187557b 100644 --- a/source/blender/compositor/operations/COM_DilateErodeOperation.cpp +++ b/source/blender/compositor/operations/COM_DilateErodeOperation.cpp @@ -60,7 +60,7 @@ void *DilateErodeThresholdOperation::initializeTileData(rcti *rect) return buffer; } -void DilateErodeThresholdOperation::executePixel(float *color, int x, int y, void *data) +void DilateErodeThresholdOperation::executePixel(float output[4], int x, int y, void *data) { float inputValue[4]; const float sw = this->m__switch; @@ -117,28 +117,28 @@ void DilateErodeThresholdOperation::executePixel(float *color, int x, int y, voi const float delta = distance - pixelvalue; if (delta >= 0.0f) { if (delta >= inset) { - color[0] = 1.0f; + output[0] = 1.0f; } else { - color[0] = delta / inset; + output[0] = delta / inset; } } else { - color[0] = 0.0f; + output[0] = 0.0f; } } else { const float delta = -distance + pixelvalue; if (delta < 0.0f) { if (delta < -inset) { - color[0] = 1.0f; + output[0] = 1.0f; } else { - color[0] = (-delta) / inset; + output[0] = (-delta) / inset; } } else { - color[0] = 0.0f; + output[0] = 0.0f; } } } @@ -185,7 +185,7 @@ void *DilateDistanceOperation::initializeTileData(rcti *rect) return buffer; } -void DilateDistanceOperation::executePixel(float *color, int x, int y, void *data) +void DilateDistanceOperation::executePixel(float output[4], int x, int y, void *data) { const float distance = this->m_distance; const float mindist = distance * distance; @@ -214,7 +214,7 @@ void DilateDistanceOperation::executePixel(float *color, int x, int y, void *dat offset += 4; } } - color[0] = value; + output[0] = value; } void DilateDistanceOperation::deinitExecution() @@ -234,7 +234,7 @@ bool DilateDistanceOperation::determineDependingAreaOfInterest(rcti *input, Read return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output); } -void DilateDistanceOperation::executeOpenCL(OpenCLDevice* device, +void DilateDistanceOperation::executeOpenCL(OpenCLDevice *device, MemoryBuffer *outputMemoryBuffer, cl_mem clOutputBuffer, MemoryBuffer **inputMemoryBuffers, list<cl_mem> *clMemToCleanUp, list<cl_kernel> *clKernelsToCleanUp) @@ -259,7 +259,7 @@ ErodeDistanceOperation::ErodeDistanceOperation() : DilateDistanceOperation() /* pass */ } -void ErodeDistanceOperation::executePixel(float *color, int x, int y, void *data) +void ErodeDistanceOperation::executePixel(float output[4], int x, int y, void *data) { const float distance = this->m_distance; const float mindist = distance * distance; @@ -288,10 +288,10 @@ void ErodeDistanceOperation::executePixel(float *color, int x, int y, void *data offset += 4; } } - color[0] = value; + output[0] = value; } -void ErodeDistanceOperation::executeOpenCL(OpenCLDevice* device, +void ErodeDistanceOperation::executeOpenCL(OpenCLDevice *device, MemoryBuffer *outputMemoryBuffer, cl_mem clOutputBuffer, MemoryBuffer **inputMemoryBuffers, list<cl_mem> *clMemToCleanUp, list<cl_kernel> *clKernelsToCleanUp) @@ -374,9 +374,9 @@ void *DilateStepOperation::initializeTileData(rcti *rect) } -void DilateStepOperation::executePixel(float *color, int x, int y, void *data) +void DilateStepOperation::executePixel(float output[4], int x, int y, void *data) { - color[0] = this->m_cached_buffer[y * this->getWidth() + x]; + output[0] = this->m_cached_buffer[y * this->getWidth() + x]; } void DilateStepOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_DilateErodeOperation.h b/source/blender/compositor/operations/COM_DilateErodeOperation.h index 8c3eefb97e4..47480d47c3b 100644 --- a/source/blender/compositor/operations/COM_DilateErodeOperation.h +++ b/source/blender/compositor/operations/COM_DilateErodeOperation.h @@ -47,7 +47,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, int x, int y, void *data); + void executePixel(float output[4], int x, int y, void *data); /** * Initialize the execution @@ -83,7 +83,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, int x, int y, void *data); + void executePixel(float output[4], int x, int y, void *data); /** * Initialize the execution @@ -99,7 +99,7 @@ public: void setDistance(float distance) { this->m_distance = distance; } bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output); - void executeOpenCL(OpenCLDevice* device, + void executeOpenCL(OpenCLDevice *device, MemoryBuffer *outputMemoryBuffer, cl_mem clOutputBuffer, MemoryBuffer **inputMemoryBuffers, list<cl_mem> *clMemToCleanUp, list<cl_kernel> *clKernelsToCleanUp); @@ -111,9 +111,9 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, int x, int y, void *data); + void executePixel(float output[4], int x, int y, void *data); - void executeOpenCL(OpenCLDevice* device, + void executeOpenCL(OpenCLDevice *device, MemoryBuffer *outputMemoryBuffer, cl_mem clOutputBuffer, MemoryBuffer **inputMemoryBuffers, list<cl_mem> *clMemToCleanUp, list<cl_kernel> *clKernelsToCleanUp); @@ -135,7 +135,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, int x, int y, void *data); + void executePixel(float output[4], int x, int y, void *data); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_DirectionalBlurOperation.cpp b/source/blender/compositor/operations/COM_DirectionalBlurOperation.cpp index 5e6ff2c7da1..23289429bfd 100644 --- a/source/blender/compositor/operations/COM_DirectionalBlurOperation.cpp +++ b/source/blender/compositor/operations/COM_DirectionalBlurOperation.cpp @@ -66,7 +66,7 @@ void DirectionalBlurOperation::initExecution() } -void DirectionalBlurOperation::executePixel(float *color, int x, int y, void *data) +void DirectionalBlurOperation::executePixel(float output[4], int x, int y, void *data) { const int iterations = pow(2.0f, this->m_data->iter); float col[4] = {0, 0, 0, 0}; @@ -98,10 +98,10 @@ void DirectionalBlurOperation::executePixel(float *color, int x, int y, void *da lsc += this->m_sc; } - mul_v4_v4fl(color, col2, 1.0f / (iterations+1)); + mul_v4_v4fl(output, col2, 1.0f / (iterations + 1)); } -void DirectionalBlurOperation::executeOpenCL(OpenCLDevice* device, +void DirectionalBlurOperation::executeOpenCL(OpenCLDevice *device, MemoryBuffer *outputMemoryBuffer, cl_mem clOutputBuffer, MemoryBuffer **inputMemoryBuffers, list<cl_mem> *clMemToCleanUp, list<cl_kernel> *clKernelsToCleanUp) diff --git a/source/blender/compositor/operations/COM_DirectionalBlurOperation.h b/source/blender/compositor/operations/COM_DirectionalBlurOperation.h index cc49e947f95..e13a13116db 100644 --- a/source/blender/compositor/operations/COM_DirectionalBlurOperation.h +++ b/source/blender/compositor/operations/COM_DirectionalBlurOperation.h @@ -40,7 +40,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, int x, int y, void *data); + void executePixel(float output[4], int x, int y, void *data); /** * Initialize the execution @@ -56,7 +56,7 @@ public: void setData(NodeDBlurData *data) { this->m_data = data; } - void executeOpenCL(OpenCLDevice* device, + void executeOpenCL(OpenCLDevice *device, MemoryBuffer *outputMemoryBuffer, cl_mem clOutputBuffer, MemoryBuffer **inputMemoryBuffers, list<cl_mem> *clMemToCleanUp, list<cl_kernel> *clKernelsToCleanUp); diff --git a/source/blender/compositor/operations/COM_DisplaceOperation.cpp b/source/blender/compositor/operations/COM_DisplaceOperation.cpp index 018df78cb65..39f0ac7874b 100644 --- a/source/blender/compositor/operations/COM_DisplaceOperation.cpp +++ b/source/blender/compositor/operations/COM_DisplaceOperation.cpp @@ -54,7 +54,7 @@ void DisplaceOperation::initExecution() * in order to take effect */ #define DISPLACE_EPSILON 0.01f -void DisplaceOperation::executePixel(float *color, int x, int y, void *data) +void DisplaceOperation::executePixel(float output[4], int x, int y, void *data) { float inVector[4]; float inScale[4]; @@ -96,7 +96,7 @@ void DisplaceOperation::executePixel(float *color, int x, int y, void *data) dyt = signf(dyt) * maxf(fabsf(dyt), DISPLACE_EPSILON) / this->getHeight(); /* EWA filtering */ - this->m_inputColorProgram->read(color, u, v, dxt, dyt); + this->m_inputColorProgram->read(output, u, v, dxt, dyt); } void DisplaceOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_DisplaceOperation.h b/source/blender/compositor/operations/COM_DisplaceOperation.h index 0e5b042aea5..daf54294aa1 100644 --- a/source/blender/compositor/operations/COM_DisplaceOperation.h +++ b/source/blender/compositor/operations/COM_DisplaceOperation.h @@ -48,7 +48,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, int x, int y, void *data); + void executePixel(float output[4], int x, int y, void *data); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_DisplaceSimpleOperation.cpp b/source/blender/compositor/operations/COM_DisplaceSimpleOperation.cpp index a93e39085c5..560bbbdd244 100644 --- a/source/blender/compositor/operations/COM_DisplaceSimpleOperation.cpp +++ b/source/blender/compositor/operations/COM_DisplaceSimpleOperation.cpp @@ -53,7 +53,7 @@ void DisplaceSimpleOperation::initExecution() * in order to take effect */ #define DISPLACE_EPSILON 0.01f -void DisplaceSimpleOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void DisplaceSimpleOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inVector[4]; float inScale[4]; @@ -82,7 +82,7 @@ void DisplaceSimpleOperation::executePixel(float *color, float x, float y, Pixel CLAMP(u, 0.f, this->getWidth() - 1.f); CLAMP(v, 0.f, this->getHeight() - 1.f); - this->m_inputColorProgram->read(color, u, v, sampler); + this->m_inputColorProgram->read(output, u, v, sampler); } void DisplaceSimpleOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_DisplaceSimpleOperation.h b/source/blender/compositor/operations/COM_DisplaceSimpleOperation.h index 81adc7be366..989cf8a1f67 100644 --- a/source/blender/compositor/operations/COM_DisplaceSimpleOperation.h +++ b/source/blender/compositor/operations/COM_DisplaceSimpleOperation.h @@ -48,7 +48,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_DistanceMatteOperation.cpp b/source/blender/compositor/operations/COM_DistanceMatteOperation.cpp index 197e8b07918..b65b5e0f224 100644 --- a/source/blender/compositor/operations/COM_DistanceMatteOperation.cpp +++ b/source/blender/compositor/operations/COM_DistanceMatteOperation.cpp @@ -44,7 +44,7 @@ void DistanceMatteOperation::deinitExecution() this->m_inputKeyProgram = NULL; } -void DistanceMatteOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void DistanceMatteOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inKey[4]; float inImage[4]; @@ -68,7 +68,7 @@ void DistanceMatteOperation::executePixel(float *outputValue, float x, float y, /*make 100% transparent */ if (distance < tolerance) { - outputValue[0] = 0.f; + output[0] = 0.f; } /*in the falloff region, make partially transparent */ else if (distance < falloff + tolerance) { @@ -76,15 +76,15 @@ void DistanceMatteOperation::executePixel(float *outputValue, float x, float y, alpha = distance / falloff; /*only change if more transparent than before */ if (alpha < inImage[3]) { - outputValue[0] = alpha; + output[0] = alpha; } else { /* leave as before */ - outputValue[0] = inImage[3]; + output[0] = inImage[3]; } } else { /* leave as before */ - outputValue[0] = inImage[3]; + output[0] = inImage[3]; } } diff --git a/source/blender/compositor/operations/COM_DistanceMatteOperation.h b/source/blender/compositor/operations/COM_DistanceMatteOperation.h index 6fe16c7fdff..a176e5da888 100644 --- a/source/blender/compositor/operations/COM_DistanceMatteOperation.h +++ b/source/blender/compositor/operations/COM_DistanceMatteOperation.h @@ -42,7 +42,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); void initExecution(); void deinitExecution(); diff --git a/source/blender/compositor/operations/COM_DotproductOperation.cpp b/source/blender/compositor/operations/COM_DotproductOperation.cpp index 559d97d6056..1439dfa404a 100644 --- a/source/blender/compositor/operations/COM_DotproductOperation.cpp +++ b/source/blender/compositor/operations/COM_DotproductOperation.cpp @@ -45,11 +45,11 @@ void DotproductOperation::deinitExecution() /** @todo: current implementation is the inverse of a dotproduct. not 'logically' correct */ -void DotproductOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void DotproductOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float input1[4]; float input2[4]; this->m_input1Operation->read(input1, x, y, sampler); this->m_input2Operation->read(input2, x, y, sampler); - color[0] = -(input1[0] * input2[0] + input1[1] * input2[1] + input1[2] * input2[2]); + output[0] = -(input1[0] * input2[0] + input1[1] * input2[1] + input1[2] * input2[2]); } diff --git a/source/blender/compositor/operations/COM_DotproductOperation.h b/source/blender/compositor/operations/COM_DotproductOperation.h index 6ff6f622a50..31588207504 100644 --- a/source/blender/compositor/operations/COM_DotproductOperation.h +++ b/source/blender/compositor/operations/COM_DotproductOperation.h @@ -31,7 +31,7 @@ private: SocketReader *m_input2Operation; public: DotproductOperation(); - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); void initExecution(); void deinitExecution(); diff --git a/source/blender/compositor/operations/COM_DoubleEdgeMaskOperation.cpp b/source/blender/compositor/operations/COM_DoubleEdgeMaskOperation.cpp index 7c5614c0de1..d5daace059d 100644 --- a/source/blender/compositor/operations/COM_DoubleEdgeMaskOperation.cpp +++ b/source/blender/compositor/operations/COM_DoubleEdgeMaskOperation.cpp @@ -907,7 +907,7 @@ static void do_createEdgeLocationBuffer(unsigned int t, unsigned int rw, unsigne * or outer edge. * * Allocation is done by requesting 4 bytes "sizeof(int)" per pixel, even - * though gbuf[] is declared as unsigned short* (2 bytes) because we don't + * though gbuf[] is declared as (unsigned short *) (2 bytes) because we don't * store the pixel indexes, we only store x,y location of pixel in buffer. * * This does make the assumption that x and y can fit in 16 unsigned bits @@ -1280,11 +1280,11 @@ void *DoubleEdgeMaskOperation::initializeTileData(rcti *rect) unlockMutex(); return this->m_cachedInstance; } -void DoubleEdgeMaskOperation::executePixel(float *color, int x, int y, void *data) +void DoubleEdgeMaskOperation::executePixel(float output[4], int x, int y, void *data) { float *buffer = (float *)data; int index = (y * this->getWidth() + x); - copy_v4_v4(color, buffer + index); + copy_v4_v4(output, buffer + index); } void DoubleEdgeMaskOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_DoubleEdgeMaskOperation.h b/source/blender/compositor/operations/COM_DoubleEdgeMaskOperation.h index 32e5a07cfdc..528aae7218f 100644 --- a/source/blender/compositor/operations/COM_DoubleEdgeMaskOperation.h +++ b/source/blender/compositor/operations/COM_DoubleEdgeMaskOperation.h @@ -42,7 +42,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, int x, int y, void *data); + void executePixel(float output[4], int x, int y, void *data); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_EllipseMaskOperation.cpp b/source/blender/compositor/operations/COM_EllipseMaskOperation.cpp index c3cbaaaf2fc..9ab21e2d5bd 100644 --- a/source/blender/compositor/operations/COM_EllipseMaskOperation.cpp +++ b/source/blender/compositor/operations/COM_EllipseMaskOperation.cpp @@ -44,7 +44,7 @@ void EllipseMaskOperation::initExecution() this->m_aspectRatio = ((float)this->getWidth()) / this->getHeight(); } -void EllipseMaskOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void EllipseMaskOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputMask[4]; float inputValue[4]; @@ -74,40 +74,40 @@ void EllipseMaskOperation::executePixel(float *color, float x, float y, PixelSam switch (this->m_maskType) { case CMP_NODE_MASKTYPE_ADD: if (inside) { - color[0] = max(inputMask[0], inputValue[0]); + output[0] = max(inputMask[0], inputValue[0]); } else { - color[0] = inputMask[0]; + output[0] = inputMask[0]; } break; case CMP_NODE_MASKTYPE_SUBTRACT: if (inside) { - color[0] = inputMask[0] - inputValue[0]; - CLAMP(color[0], 0, 1); + output[0] = inputMask[0] - inputValue[0]; + CLAMP(output[0], 0, 1); } else { - color[0] = inputMask[0]; + output[0] = inputMask[0]; } break; case CMP_NODE_MASKTYPE_MULTIPLY: if (inside) { - color[0] = inputMask[0] * inputValue[0]; + output[0] = inputMask[0] * inputValue[0]; } else { - color[0] = 0; + output[0] = 0; } break; case CMP_NODE_MASKTYPE_NOT: if (inside) { if (inputMask[0] > 0.0f) { - color[0] = 0; + output[0] = 0; } else { - color[0] = inputValue[0]; + output[0] = inputValue[0]; } } else { - color[0] = inputMask[0]; + output[0] = inputMask[0]; } break; } diff --git a/source/blender/compositor/operations/COM_EllipseMaskOperation.h b/source/blender/compositor/operations/COM_EllipseMaskOperation.h index fce3c93bba6..ed74e6b43db 100644 --- a/source/blender/compositor/operations/COM_EllipseMaskOperation.h +++ b/source/blender/compositor/operations/COM_EllipseMaskOperation.h @@ -45,7 +45,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cpp b/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cpp index 7ef363f5c4a..2b2928c98db 100644 --- a/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cpp +++ b/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cpp @@ -31,10 +31,10 @@ FastGaussianBlurOperation::FastGaussianBlurOperation() : BlurBaseOperation(COM_D this->m_iirgaus = NULL; } -void FastGaussianBlurOperation::executePixel(float *color, int x, int y, void *data) +void FastGaussianBlurOperation::executePixel(float output[4], int x, int y, void *data) { MemoryBuffer *newData = (MemoryBuffer *)data; - newData->read(color, x, y); + newData->read(output, x, y); } bool FastGaussianBlurOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) @@ -233,10 +233,10 @@ FastGaussianBlurValueOperation::FastGaussianBlurValueOperation() : NodeOperation setComplex(true); } -void FastGaussianBlurValueOperation::executePixel(float *color, int x, int y, void *data) +void FastGaussianBlurValueOperation::executePixel(float output[4], int x, int y, void *data) { MemoryBuffer *newData = (MemoryBuffer *)data; - newData->read(color, x, y); + newData->read(output, x, y); } bool FastGaussianBlurValueOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) @@ -277,6 +277,28 @@ void *FastGaussianBlurValueOperation::initializeTileData(rcti *rect) MemoryBuffer *newBuf = (MemoryBuffer *)this->m_inputprogram->initializeTileData(rect); MemoryBuffer *copy = newBuf->duplicate(); FastGaussianBlurOperation::IIR_gauss(copy, this->m_sigma, 0, 3); + + if (this->m_overlay == FAST_GAUSS_OVERLAY_MIN) { + float *src = newBuf->getBuffer(); + float *dst = copy->getBuffer(); + for (int i = copy->getWidth() * copy->getHeight() * COM_NUMBER_OF_CHANNELS; i != 0; i--, src++, dst++) { + if (*src < *dst) { + *dst = *src; + } + } + } + else if (this->m_overlay == FAST_GAUSS_OVERLAY_MAX) { + float *src = newBuf->getBuffer(); + float *dst = copy->getBuffer(); + for (int i = copy->getWidth() * copy->getHeight() * COM_NUMBER_OF_CHANNELS; i != 0; i--, src++, dst++) { + if (*src > *dst) { + *dst = *src; + } + } + } + +// newBuf-> + this->m_iirgaus = copy; } unlockMutex(); diff --git a/source/blender/compositor/operations/COM_FastGaussianBlurOperation.h b/source/blender/compositor/operations/COM_FastGaussianBlurOperation.h index 4560e1b25e3..58bf1d4f596 100644 --- a/source/blender/compositor/operations/COM_FastGaussianBlurOperation.h +++ b/source/blender/compositor/operations/COM_FastGaussianBlurOperation.h @@ -34,7 +34,7 @@ private: public: FastGaussianBlurOperation(); bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output); - void executePixel(float *color, int x, int y, void *data); + void executePixel(float output[4], int x, int y, void *data); static void IIR_gauss(MemoryBuffer *src, float sigma, unsigned int channel, unsigned int xy); void *initializeTileData(rcti *rect); @@ -42,20 +42,35 @@ public: void initExecution(); }; +enum { + FAST_GAUSS_OVERLAY_MIN = -1, + FAST_GAUSS_OVERLAY_NONE = 0, + FAST_GAUSS_OVERLAY_MAX = 1 +}; + class FastGaussianBlurValueOperation : public NodeOperation { private: float m_sigma; MemoryBuffer *m_iirgaus; SocketReader *m_inputprogram; + + /** + * -1: re-mix with darker + * 0: do nothing + * 1 re-mix with lighter */ + int m_overlay; public: FastGaussianBlurValueOperation(); bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output); - void executePixel(float *color, int x, int y, void *data); + void executePixel(float output[4], int x, int y, void *data); void *initializeTileData(rcti *rect); void deinitExecution(); void initExecution(); void setSigma(float sigma) { this->m_sigma = sigma; } + + /* used for DOF blurring ZBuffer */ + void setOverlay(int overlay) { this->m_overlay = overlay; } }; #endif diff --git a/source/blender/compositor/operations/COM_FlipOperation.cpp b/source/blender/compositor/operations/COM_FlipOperation.cpp index 939d05fffbf..526eba34d86 100644 --- a/source/blender/compositor/operations/COM_FlipOperation.cpp +++ b/source/blender/compositor/operations/COM_FlipOperation.cpp @@ -42,12 +42,12 @@ void FlipOperation::deinitExecution() } -void FlipOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void FlipOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float nx = this->m_flipX ? this->getWidth() - 1 - x : x; float ny = this->m_flipY ? this->getHeight() - 1 - y : y; - this->m_inputOperation->read(color, nx, ny, sampler); + this->m_inputOperation->read(output, nx, ny, sampler); } bool FlipOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) diff --git a/source/blender/compositor/operations/COM_FlipOperation.h b/source/blender/compositor/operations/COM_FlipOperation.h index a13f7ecf752..018617cea8a 100644 --- a/source/blender/compositor/operations/COM_FlipOperation.h +++ b/source/blender/compositor/operations/COM_FlipOperation.h @@ -33,7 +33,7 @@ private: public: FlipOperation(); bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output); - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); void initExecution(); void deinitExecution(); diff --git a/source/blender/compositor/operations/COM_GammaCorrectOperation.cpp b/source/blender/compositor/operations/COM_GammaCorrectOperation.cpp index a4cc03ac380..af990f4f3e0 100644 --- a/source/blender/compositor/operations/COM_GammaCorrectOperation.cpp +++ b/source/blender/compositor/operations/COM_GammaCorrectOperation.cpp @@ -34,7 +34,7 @@ void GammaCorrectOperation::initExecution() this->m_inputProgram = this->getInputSocketReader(0); } -void GammaCorrectOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void GammaCorrectOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor[4]; this->m_inputProgram->read(inputColor, x, y, sampler); @@ -45,18 +45,18 @@ void GammaCorrectOperation::executePixel(float *color, float x, float y, PixelSa } /* check for negative to avoid nan's */ - color[0] = inputColor[0] > 0.0f ? inputColor[0] * inputColor[0] : 0.0f; - color[1] = inputColor[1] > 0.0f ? inputColor[1] * inputColor[1] : 0.0f; - color[2] = inputColor[2] > 0.0f ? inputColor[2] * inputColor[2] : 0.0f; + output[0] = inputColor[0] > 0.0f ? inputColor[0] * inputColor[0] : 0.0f; + output[1] = inputColor[1] > 0.0f ? inputColor[1] * inputColor[1] : 0.0f; + output[2] = inputColor[2] > 0.0f ? inputColor[2] * inputColor[2] : 0.0f; inputColor[0] *= inputColor[3]; inputColor[1] *= inputColor[3]; inputColor[2] *= inputColor[3]; - color[0] = inputColor[0]; - color[1] = inputColor[1]; - color[2] = inputColor[2]; - color[3] = inputColor[3]; + output[0] = inputColor[0]; + output[1] = inputColor[1]; + output[2] = inputColor[2]; + output[3] = inputColor[3]; } void GammaCorrectOperation::deinitExecution() @@ -75,7 +75,7 @@ void GammaUncorrectOperation::initExecution() this->m_inputProgram = this->getInputSocketReader(0); } -void GammaUncorrectOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void GammaUncorrectOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor[4]; this->m_inputProgram->read(inputColor, x, y, sampler); @@ -86,18 +86,18 @@ void GammaUncorrectOperation::executePixel(float *color, float x, float y, Pixel inputColor[2] /= inputColor[3]; } - color[0] = inputColor[0] > 0.0f ? sqrtf(inputColor[0]) : 0.0f; - color[1] = inputColor[1] > 0.0f ? sqrtf(inputColor[1]) : 0.0f; - color[2] = inputColor[2] > 0.0f ? sqrtf(inputColor[2]) : 0.0f; + output[0] = inputColor[0] > 0.0f ? sqrtf(inputColor[0]) : 0.0f; + output[1] = inputColor[1] > 0.0f ? sqrtf(inputColor[1]) : 0.0f; + output[2] = inputColor[2] > 0.0f ? sqrtf(inputColor[2]) : 0.0f; inputColor[0] *= inputColor[3]; inputColor[1] *= inputColor[3]; inputColor[2] *= inputColor[3]; - color[0] = inputColor[0]; - color[1] = inputColor[1]; - color[2] = inputColor[2]; - color[3] = inputColor[3]; + output[0] = inputColor[0]; + output[1] = inputColor[1]; + output[2] = inputColor[2]; + output[3] = inputColor[3]; } void GammaUncorrectOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_GammaCorrectOperation.h b/source/blender/compositor/operations/COM_GammaCorrectOperation.h index 2d4f2ea89d9..514855b4f56 100644 --- a/source/blender/compositor/operations/COM_GammaCorrectOperation.h +++ b/source/blender/compositor/operations/COM_GammaCorrectOperation.h @@ -38,7 +38,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution @@ -64,7 +64,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_GammaOperation.cpp b/source/blender/compositor/operations/COM_GammaOperation.cpp index 40c2ee0a1d4..326031c5984 100644 --- a/source/blender/compositor/operations/COM_GammaOperation.cpp +++ b/source/blender/compositor/operations/COM_GammaOperation.cpp @@ -37,7 +37,7 @@ void GammaOperation::initExecution() this->m_inputGammaProgram = this->getInputSocketReader(1); } -void GammaOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void GammaOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputValue[4]; float inputGamma[4]; @@ -46,11 +46,11 @@ void GammaOperation::executePixel(float *color, float x, float y, PixelSampler s this->m_inputGammaProgram->read(inputGamma, x, y, sampler); const float gamma = inputGamma[0]; /* check for negative to avoid nan's */ - color[0] = inputValue[0] > 0.0f ? powf(inputValue[0], gamma) : inputValue[0]; - color[1] = inputValue[1] > 0.0f ? powf(inputValue[1], gamma) : inputValue[1]; - color[2] = inputValue[2] > 0.0f ? powf(inputValue[2], gamma) : inputValue[2]; + output[0] = inputValue[0] > 0.0f ? powf(inputValue[0], gamma) : inputValue[0]; + output[1] = inputValue[1] > 0.0f ? powf(inputValue[1], gamma) : inputValue[1]; + output[2] = inputValue[2] > 0.0f ? powf(inputValue[2], gamma) : inputValue[2]; - color[3] = inputValue[3]; + output[3] = inputValue[3]; } void GammaOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_GammaOperation.h b/source/blender/compositor/operations/COM_GammaOperation.h index 8fc2599cba9..4482f7be34a 100644 --- a/source/blender/compositor/operations/COM_GammaOperation.h +++ b/source/blender/compositor/operations/COM_GammaOperation.h @@ -39,7 +39,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.cpp b/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.cpp index 9865c87cb07..935bfcac6c7 100644 --- a/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.cpp +++ b/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.cpp @@ -90,7 +90,7 @@ BLI_INLINE float finv_test(const float f, const bool test) return (LIKELY(test == false)) ? f : 1.0f - f; } -void GaussianAlphaXBlurOperation::executePixel(float *color, int x, int y, void *data) +void GaussianAlphaXBlurOperation::executePixel(float output[4], int x, int y, void *data) { const bool do_invert = this->m_do_subtract; MemoryBuffer *inputBuffer = (MemoryBuffer *)data; @@ -148,7 +148,7 @@ void GaussianAlphaXBlurOperation::executePixel(float *color, int x, int y, void /* blend between the max value and gauss blue - gives nice feather */ const float value_blur = alpha_accum / multiplier_accum; const float value_final = (value_max * distfacinv_max) + (value_blur * (1.0f - distfacinv_max)); - color[0] = finv_test(value_final, do_invert); + output[0] = finv_test(value_final, do_invert); } void GaussianAlphaXBlurOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.h b/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.h index 6ea8b7e4371..21e80c5daf5 100644 --- a/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.h +++ b/source/blender/compositor/operations/COM_GaussianAlphaXBlurOperation.h @@ -40,7 +40,7 @@ public: /** * @brief the inner loop of this program */ - void executePixel(float *color, int x, int y, void *data); + void executePixel(float output[4], int x, int y, void *data); /** * @brief initialize the execution diff --git a/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.cpp b/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.cpp index 323a381c869..375f1bcf07c 100644 --- a/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.cpp +++ b/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.cpp @@ -90,7 +90,7 @@ BLI_INLINE float finv_test(const float f, const bool test) return (LIKELY(test == false)) ? f : 1.0f - f; } -void GaussianAlphaYBlurOperation::executePixel(float *color, int x, int y, void *data) +void GaussianAlphaYBlurOperation::executePixel(float output[4], int x, int y, void *data) { const bool do_invert = this->m_do_subtract; MemoryBuffer *inputBuffer = (MemoryBuffer *)data; @@ -148,7 +148,7 @@ void GaussianAlphaYBlurOperation::executePixel(float *color, int x, int y, void /* blend between the max value and gauss blue - gives nice feather */ const float value_blur = alpha_accum / multiplier_accum; const float value_final = (value_max * distfacinv_max) + (value_blur * (1.0f - distfacinv_max)); - color[0] = finv_test(value_final, do_invert); + output[0] = finv_test(value_final, do_invert); } void GaussianAlphaYBlurOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.h b/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.h index 050b0c384cb..cb8b2e048ce 100644 --- a/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.h +++ b/source/blender/compositor/operations/COM_GaussianAlphaYBlurOperation.h @@ -40,7 +40,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, int x, int y, void *data); + void executePixel(float output[4], int x, int y, void *data); /** * @brief initialize the execution diff --git a/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cpp b/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cpp index fd70d0d329a..d97d2f15ded 100644 --- a/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cpp +++ b/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.cpp @@ -112,7 +112,7 @@ void GaussianBokehBlurOperation::updateGauss() } } -void GaussianBokehBlurOperation::executePixel(float *color, int x, int y, void *data) +void GaussianBokehBlurOperation::executePixel(float output[4], int x, int y, void *data) { float tempColor[4]; tempColor[0] = 0; @@ -152,7 +152,7 @@ void GaussianBokehBlurOperation::executePixel(float *color, int x, int y, void * } } - mul_v4_v4fl(color, tempColor, 1.0f / multiplier_accum); + mul_v4_v4fl(output, tempColor, 1.0f / multiplier_accum); } void GaussianBokehBlurOperation::deinitExecution() @@ -257,14 +257,14 @@ void GaussianBlurReferenceOperation::updateGauss() { int i; int x = MAX2(m_radx, m_rady); - this->m_maintabs = (float**)MEM_mallocN(x * sizeof(float *), "gauss array"); + this->m_maintabs = (float **)MEM_mallocN(x * sizeof(float *), "gauss array"); for (i = 0; i < x; i++) m_maintabs[i] = make_gausstab(i + 1); } -void GaussianBlurReferenceOperation::executePixel(float *color, int x, int y, void *data) +void GaussianBlurReferenceOperation::executePixel(float output[4], int x, int y, void *data) { - MemoryBuffer *memorybuffer = (MemoryBuffer*)data; + MemoryBuffer *memorybuffer = (MemoryBuffer *)data; float *buffer = memorybuffer->getBuffer(); float *gausstabx, *gausstabcenty; float *gausstaby, *gausstabcentx; @@ -285,8 +285,9 @@ void GaussianBlurReferenceOperation::executePixel(float *color, int x, int y, vo else if (refrady < 1) refrady = 1; if (refradx == 1 && refrady == 1) { - memorybuffer->readNoCheck(color, x, y); - } else { + memorybuffer->readNoCheck(output, x, y); + } + else { int minxr = x - refradx < 0 ? -x : -refradx; int maxxr = x + refradx > imgx ? imgx - x : refradx; int minyr = y - refrady < 0 ? -y : -refrady; @@ -313,10 +314,10 @@ void GaussianBlurReferenceOperation::executePixel(float *color, int x, int y, vo } } sum = 1.0f / sum; - color[0] = rval * sum; - color[1] = gval * sum; - color[2] = bval * sum; - color[3] = aval * sum; + output[0] = rval * sum; + output[1] = gval * sum; + output[2] = bval * sum; + output[3] = aval * sum; } } diff --git a/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.h b/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.h index 45140855464..9fcf1e10e6a 100644 --- a/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.h +++ b/source/blender/compositor/operations/COM_GaussianBokehBlurOperation.h @@ -39,7 +39,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, int x, int y, void *data); + void executePixel(float output[4], int x, int y, void *data); /** * Deinitialize the execution @@ -66,7 +66,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, int x, int y, void *data); + void executePixel(float output[4], int x, int y, void *data); /** * Deinitialize the execution diff --git a/source/blender/compositor/operations/COM_GaussianXBlurOperation.cpp b/source/blender/compositor/operations/COM_GaussianXBlurOperation.cpp index 1cf675a769a..01c85738822 100644 --- a/source/blender/compositor/operations/COM_GaussianXBlurOperation.cpp +++ b/source/blender/compositor/operations/COM_GaussianXBlurOperation.cpp @@ -73,7 +73,7 @@ void GaussianXBlurOperation::updateGauss() } } -void GaussianXBlurOperation::executePixel(float *color, int x, int y, void *data) +void GaussianXBlurOperation::executePixel(float output[4], int x, int y, void *data) { float color_accum[4] = {0.0f, 0.0f, 0.0f, 0.0f}; float multiplier_accum = 0.0f; @@ -101,7 +101,7 @@ void GaussianXBlurOperation::executePixel(float *color, int x, int y, void *data multiplier_accum += multiplier; bufferindex += offsetadd; } - mul_v4_v4fl(color, color_accum, 1.0f / multiplier_accum); + mul_v4_v4fl(output, color_accum, 1.0f / multiplier_accum); } void GaussianXBlurOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_GaussianXBlurOperation.h b/source/blender/compositor/operations/COM_GaussianXBlurOperation.h index a4a0dc655e2..4c3786b0810 100644 --- a/source/blender/compositor/operations/COM_GaussianXBlurOperation.h +++ b/source/blender/compositor/operations/COM_GaussianXBlurOperation.h @@ -36,7 +36,7 @@ public: /** * @brief the inner loop of this program */ - void executePixel(float *color, int x, int y, void *data); + void executePixel(float output[4], int x, int y, void *data); /** * @brief initialize the execution diff --git a/source/blender/compositor/operations/COM_GaussianYBlurOperation.cpp b/source/blender/compositor/operations/COM_GaussianYBlurOperation.cpp index 135dcf60872..298b4660c6a 100644 --- a/source/blender/compositor/operations/COM_GaussianYBlurOperation.cpp +++ b/source/blender/compositor/operations/COM_GaussianYBlurOperation.cpp @@ -73,7 +73,7 @@ void GaussianYBlurOperation::updateGauss() } } -void GaussianYBlurOperation::executePixel(float *color, int x, int y, void *data) +void GaussianYBlurOperation::executePixel(float output[4], int x, int y, void *data) { float color_accum[4] = {0.0f, 0.0f, 0.0f, 0.0f}; float multiplier_accum = 0.0f; @@ -102,7 +102,7 @@ void GaussianYBlurOperation::executePixel(float *color, int x, int y, void *data madd_v4_v4fl(color_accum, &buffer[bufferindex], multiplier); multiplier_accum += multiplier; } - mul_v4_v4fl(color, color_accum, 1.0f / multiplier_accum); + mul_v4_v4fl(output, color_accum, 1.0f / multiplier_accum); } void GaussianYBlurOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_GaussianYBlurOperation.h b/source/blender/compositor/operations/COM_GaussianYBlurOperation.h index e3e0d8891d3..69dcb7e48fb 100644 --- a/source/blender/compositor/operations/COM_GaussianYBlurOperation.h +++ b/source/blender/compositor/operations/COM_GaussianYBlurOperation.h @@ -36,7 +36,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, int x, int y, void *data); + void executePixel(float output[4], int x, int y, void *data); /** * @brief initialize the execution diff --git a/source/blender/compositor/operations/COM_GlareThresholdOperation.cpp b/source/blender/compositor/operations/COM_GlareThresholdOperation.cpp index 7f32618d2af..1c7d2659c39 100644 --- a/source/blender/compositor/operations/COM_GlareThresholdOperation.cpp +++ b/source/blender/compositor/operations/COM_GlareThresholdOperation.cpp @@ -30,7 +30,7 @@ GlareThresholdOperation::GlareThresholdOperation() : NodeOperation() this->m_inputProgram = NULL; } -void GlareThresholdOperation::determineResolution(unsigned int resolution[], unsigned int preferredResolution[]) +void GlareThresholdOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]) { NodeOperation::determineResolution(resolution, preferredResolution); resolution[0] = resolution[0] / (1 << this->m_settings->quality); @@ -42,19 +42,19 @@ void GlareThresholdOperation::initExecution() this->m_inputProgram = this->getInputSocketReader(0); } -void GlareThresholdOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void GlareThresholdOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { const float threshold = this->m_settings->threshold; - this->m_inputProgram->read(color, x, y, sampler); - if (rgb_to_luma_y(color) >= threshold) { - color[0] -= threshold, color[1] -= threshold, color[2] -= threshold; - color[0] = MAX2(color[0], 0.0f); - color[1] = MAX2(color[1], 0.0f); - color[2] = MAX2(color[2], 0.0f); + this->m_inputProgram->read(output, x, y, sampler); + if (rgb_to_luma_y(output) >= threshold) { + output[0] -= threshold, output[1] -= threshold, output[2] -= threshold; + output[0] = max(output[0], 0.0f); + output[1] = max(output[1], 0.0f); + output[2] = max(output[2], 0.0f); } else { - zero_v3(color); + zero_v3(output); } } diff --git a/source/blender/compositor/operations/COM_GlareThresholdOperation.h b/source/blender/compositor/operations/COM_GlareThresholdOperation.h index faba6c6c47c..44f9db6a483 100644 --- a/source/blender/compositor/operations/COM_GlareThresholdOperation.h +++ b/source/blender/compositor/operations/COM_GlareThresholdOperation.h @@ -42,7 +42,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution @@ -58,6 +58,6 @@ public: this->m_settings = settings; } - void determineResolution(unsigned int resolution[], unsigned int preferredResolution[]); + void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]); }; #endif diff --git a/source/blender/compositor/operations/COM_HueSaturationValueCorrectOperation.cpp b/source/blender/compositor/operations/COM_HueSaturationValueCorrectOperation.cpp index df3d00278c3..57d43f67c9b 100644 --- a/source/blender/compositor/operations/COM_HueSaturationValueCorrectOperation.cpp +++ b/source/blender/compositor/operations/COM_HueSaturationValueCorrectOperation.cpp @@ -45,7 +45,7 @@ void HueSaturationValueCorrectOperation::initExecution() this->m_inputProgram = this->getInputSocketReader(0); } -void HueSaturationValueCorrectOperation::executePixel(float *output, float x, float y, PixelSampler sampler) +void HueSaturationValueCorrectOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float hsv[4], f; diff --git a/source/blender/compositor/operations/COM_HueSaturationValueCorrectOperation.h b/source/blender/compositor/operations/COM_HueSaturationValueCorrectOperation.h index ba565a9f752..5e57d09a51e 100644 --- a/source/blender/compositor/operations/COM_HueSaturationValueCorrectOperation.h +++ b/source/blender/compositor/operations/COM_HueSaturationValueCorrectOperation.h @@ -37,7 +37,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *Vector, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_IDMaskOperation.cpp b/source/blender/compositor/operations/COM_IDMaskOperation.cpp index daa2ac9299e..4b9bcb118e7 100644 --- a/source/blender/compositor/operations/COM_IDMaskOperation.cpp +++ b/source/blender/compositor/operations/COM_IDMaskOperation.cpp @@ -33,13 +33,13 @@ void IDMaskOperation::initExecution() this->m_inputProgram = this->getInputSocketReader(0); } -void IDMaskOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void IDMaskOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputValue[4]; this->m_inputProgram->read(inputValue, x, y, sampler); const float a = (inputValue[0] == this->m_objectIndex) ? 1.0f : 0.0f; - color[0] = a; + output[0] = a; } void IDMaskOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_IDMaskOperation.h b/source/blender/compositor/operations/COM_IDMaskOperation.h index 9d356536499..68c5cf4c1dc 100644 --- a/source/blender/compositor/operations/COM_IDMaskOperation.h +++ b/source/blender/compositor/operations/COM_IDMaskOperation.h @@ -39,7 +39,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_ImageOperation.cpp b/source/blender/compositor/operations/COM_ImageOperation.cpp index 36cc6ca8d6d..4ec5643c0bb 100644 --- a/source/blender/compositor/operations/COM_ImageOperation.cpp +++ b/source/blender/compositor/operations/COM_ImageOperation.cpp @@ -94,7 +94,7 @@ void BaseImageOperation::deinitExecution() this->m_imageBuffer = NULL; } -void BaseImageOperation::determineResolution(unsigned int resolution[], unsigned int preferredResolution[]) +void BaseImageOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]) { ImBuf *stackbuf = getImBuf(); @@ -107,32 +107,32 @@ void BaseImageOperation::determineResolution(unsigned int resolution[], unsigned } } -void ImageOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void ImageOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { if (this->m_imageBuffer == NULL || x < 0 || y < 0 || x >= this->getWidth() || y >= this->getHeight() ) { - zero_v4(color); + zero_v4(output); } else { switch (sampler) { case COM_PS_NEAREST: - neareast_interpolation_color(this->m_buffer, NULL, color, x, y); + neareast_interpolation_color(this->m_buffer, NULL, output, x, y); break; case COM_PS_BILINEAR: - bilinear_interpolation_color(this->m_buffer, NULL, color, x, y); + bilinear_interpolation_color(this->m_buffer, NULL, output, x, y); break; case COM_PS_BICUBIC: - bicubic_interpolation_color(this->m_buffer, NULL, color, x, y); + bicubic_interpolation_color(this->m_buffer, NULL, output, x, y); break; } } } -void ImageAlphaOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void ImageAlphaOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float tempcolor[4]; if (this->m_imageBuffer == NULL || x < 0 || y < 0 || x >= this->getWidth() || y >= this->getHeight() ) { - color[0] = 0.0f; + output[0] = 0.0f; } else { tempcolor[3] = 1.0f; @@ -147,17 +147,17 @@ void ImageAlphaOperation::executePixel(float *color, float x, float y, PixelSamp bicubic_interpolation_color(this->m_buffer, NULL, tempcolor, x, y); break; } - color[0] = tempcolor[3]; + output[0] = tempcolor[3]; } } -void ImageDepthOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void ImageDepthOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { if (this->m_depthBuffer == NULL || x < 0 || y < 0 || x >= this->getWidth() || y >= this->getHeight() ) { - color[0] = 0.0f; + output[0] = 0.0f; } else { int offset = y * this->m_width + x; - color[0] = this->m_depthBuffer[offset]; + output[0] = this->m_depthBuffer[offset]; } } diff --git a/source/blender/compositor/operations/COM_ImageOperation.h b/source/blender/compositor/operations/COM_ImageOperation.h index ed7b10cd4f5..e75e7daa186 100644 --- a/source/blender/compositor/operations/COM_ImageOperation.h +++ b/source/blender/compositor/operations/COM_ImageOperation.h @@ -53,7 +53,7 @@ protected: /** * Determine the output resolution. The resolution is retrieved from the Renderer */ - void determineResolution(unsigned int resolution[], unsigned int preferredResolution[]); + void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]); virtual ImBuf *getImBuf(); @@ -72,7 +72,7 @@ public: * Constructor */ ImageOperation(); - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; class ImageAlphaOperation : public BaseImageOperation { public: @@ -80,7 +80,7 @@ public: * Constructor */ ImageAlphaOperation(); - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; class ImageDepthOperation : public BaseImageOperation { public: @@ -88,6 +88,6 @@ public: * Constructor */ ImageDepthOperation(); - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; #endif diff --git a/source/blender/compositor/operations/COM_InpaintOperation.cpp b/source/blender/compositor/operations/COM_InpaintOperation.cpp new file mode 100644 index 00000000000..e586dded8db --- /dev/null +++ b/source/blender/compositor/operations/COM_InpaintOperation.cpp @@ -0,0 +1,287 @@ +/* + * Copyright 2011, Blender Foundation. + * + * 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. + * + * Contributor: Peter Schlaile + * Jeroen Bakker + * Monique Dewanchand + */ + +#include "MEM_guardedalloc.h" + +#include "COM_InpaintOperation.h" +#include "COM_OpenCLDevice.h" + +#include "BLI_math.h" + +#define ASSERT_XY_RANGE(x, y) \ + BLI_assert(x >= 0 && x < this->getWidth() && \ + y >= 0 && y < this->getHeight()) + + +// Inpaint (simple convolve using average of known pixels) +InpaintSimpleOperation::InpaintSimpleOperation() : NodeOperation() +{ + this->addInputSocket(COM_DT_COLOR); + this->addOutputSocket(COM_DT_COLOR); + this->setComplex(true); + this->m_inputImageProgram = NULL; + this->m_pixelorder = NULL; + this->m_manhatten_distance = NULL; + this->m_cached_buffer = NULL; + this->m_cached_buffer_ready = false; +} +void InpaintSimpleOperation::initExecution() +{ + this->m_inputImageProgram = this->getInputSocketReader(0); + + this->m_cached_buffer = NULL; + this->m_pixelorder = NULL; + this->m_manhatten_distance = NULL; + this->m_cached_buffer = NULL; + this->m_cached_buffer_ready = false; + + this->initMutex(); +} + +void InpaintSimpleOperation::clamp_xy(int & x, int & y) +{ + int width = this->getWidth(); + int height = this->getHeight(); + + if (x < 0) { + x = 0; + } + else if (x >= width) { + x = width - 1; + } + + if (y < 0) { + y = 0; + } + else if (y >= height) { + y = height - 1; + } +} + +float *InpaintSimpleOperation::get_pixel(int x, int y) +{ + int width = this->getWidth(); + + ASSERT_XY_RANGE(x, y); + + return &this->m_cached_buffer[ + y * width * COM_NUMBER_OF_CHANNELS + + x * COM_NUMBER_OF_CHANNELS]; +} + +int InpaintSimpleOperation::mdist(int x, int y) +{ + int width = this->getWidth(); + + ASSERT_XY_RANGE(x, y); + + return this->m_manhatten_distance[y * width + x]; +} + +bool InpaintSimpleOperation::next_pixel(int & x, int & y, int & curr, int iters) +{ + int width = this->getWidth(); + + if (curr >= this->m_area_size) { + return false; + } + + int r = this->m_pixelorder[curr++]; + + x = r % width; + y = r / width; + + if (mdist(x, y) > iters) { + return false; + } + + return true; +} + +void InpaintSimpleOperation::calc_manhatten_distance() +{ + int width = this->getWidth(); + int height = this->getHeight(); + short *m = this->m_manhatten_distance = new short[width * height]; + int *offsets; + + offsets = (int *)MEM_callocN(sizeof(int) * (width + height + 1), "InpaintSimpleOperation offsets"); + + for (int j = 0; j < height; j++) { + for (int i = 0; i < width; i++) { + int r = 0; + /* no need to clamp here */ + if (this->get_pixel(i, j)[3] < 1.0f) { + r = width + height; + if (i > 0) + r = mini(r, m[j * width + i - 1] + 1); + if (j > 0) + r = mini(r, m[(j - 1) * width + i] + 1); + } + m[j * width + i] = r; + } + } + + for (int j = height - 1; j >= 0; j--) { + for (int i = width; i >= 0; i--) { + int r = m[j * width + i]; + + if (i + 1 < width) + r = mini(r, m[j * width + i + 1] + 1); + if (j + 1 < height) + r = mini(r, m[(j + 1) * width + i] + 1); + + m[j * width + i] = r; + + offsets[r]++; + } + } + + offsets[0] = 0; + + for (int i = 1; i < width + height + 1; i++) { + offsets[i] += offsets[i - 1]; + } + + this->m_area_size = offsets[width + height]; + this->m_pixelorder = new int[this->m_area_size]; + + for (int i = 0; i < width * height; i++) { + if (m[i] > 0) { + this->m_pixelorder[offsets[m[i] - 1]++] = i; + } + } + + MEM_freeN(offsets); +} + +void InpaintSimpleOperation::pix_step(int x, int y) +{ + int d = this->mdist(x, y); + + float n = 0; + + float pix[3] = {0.0f, 0.0f, 0.0f}; + + for (int dx = -1; dx <= 1; dx++) { + for (int dy = -1; dy <= 1; dy++) { + if (dx != 0 && dy != 0) { + + int x_ofs = x + dx; + int y_ofs = y + dy; + + this->clamp_xy(x_ofs, y_ofs); + + if (this->mdist(x_ofs, y_ofs) < d) { + + float weight; + + if (dx == 0 || dy == 0) { + weight = 1.0f; + } + else { + weight = M_SQRT1_2; /* 1.0f / sqrt(2) */ + } + + madd_v3_v3fl(pix, this->get_pixel(x_ofs, y_ofs), weight); + n += weight; + } + } + } + } + + mul_v3_v3fl(this->get_pixel(x, y), pix, 1.0f / n); +} + +void *InpaintSimpleOperation::initializeTileData(rcti *rect) +{ + if (this->m_cached_buffer_ready) { + return this->m_cached_buffer; + } + lockMutex(); + if (!this->m_cached_buffer_ready) { + MemoryBuffer *buf = (MemoryBuffer *)this->m_inputImageProgram->initializeTileData(rect); + + this->m_cached_buffer = new float[this->getWidth() * this->getHeight() * COM_NUMBER_OF_CHANNELS]; + memcpy(this->m_cached_buffer, buf->getBuffer(), this->getWidth() * this->getHeight() * COM_NUMBER_OF_CHANNELS * sizeof(float)); + + calc_manhatten_distance(); + + int curr = 0; + int x, y; + + + while (next_pixel(x, y, curr, this->m_iterations)) { + pix_step(x, y); + } + this->m_cached_buffer_ready = true; + } + + unlockMutex(); + return this->m_cached_buffer; +} + +void InpaintSimpleOperation::executePixel(float output[4], int x, int y, void *data) +{ + this->clamp_xy(x, y); + copy_v3_v3(output, this->get_pixel(x, y)); + output[3] = 1.0f; +} + +void InpaintSimpleOperation::deinitExecution() +{ + this->m_inputImageProgram = NULL; + this->deinitMutex(); + if (this->m_cached_buffer) { + delete [] this->m_cached_buffer; + this->m_cached_buffer = NULL; + } + + if (this->m_pixelorder) { + delete [] this->m_pixelorder; + this->m_pixelorder = NULL; + } + + if (this->m_manhatten_distance) { + delete [] this->m_manhatten_distance; + this->m_manhatten_distance = NULL; + } + this->m_cached_buffer_ready = false; +} + +bool InpaintSimpleOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) +{ + if (this->m_cached_buffer_ready) { + return false; + } + else { + rcti newInput; + + newInput.xmax = getWidth(); + newInput.xmin = 0; + newInput.ymax = getHeight(); + newInput.ymin = 0; + + return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output); + } +} + diff --git a/source/blender/compositor/operations/COM_InpaintOperation.h b/source/blender/compositor/operations/COM_InpaintOperation.h new file mode 100644 index 00000000000..59465ed3432 --- /dev/null +++ b/source/blender/compositor/operations/COM_InpaintOperation.h @@ -0,0 +1,75 @@ +/* + * Copyright 2011, Blender Foundation. + * + * 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. + * + * Contributor: Peter Schlaile + * Jeroen Bakker + * Monique Dewanchand + */ + +#ifndef _COM_InpaintOperation_h +#define _COM_InpaintOperation_h +#include "COM_NodeOperation.h" + +class InpaintSimpleOperation : public NodeOperation { +protected: + /** + * Cached reference to the inputProgram + */ + SocketReader *m_inputImageProgram; + + int m_iterations; + + float *m_cached_buffer; + bool m_cached_buffer_ready; + + int *m_pixelorder; + int m_area_size; + short *m_manhatten_distance; +public: + InpaintSimpleOperation(); + + /** + * the inner loop of this program + */ + void executePixel(float output[4], int x, int y, void *data); + + /** + * Initialize the execution + */ + void initExecution(); + + void *initializeTileData(rcti *rect); + /** + * Deinitialize the execution + */ + void deinitExecution(); + + void setIterations(int iterations) { this->m_iterations = iterations; } + + bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output); + +private: + void calc_manhatten_distance(); + void clamp_xy(int &x, int &y); + float *get_pixel(int x, int y); + int mdist(int x, int y); + bool next_pixel(int &x, int &y, int &curr, int iters); + void pix_step(int x, int y); +}; + + +#endif diff --git a/source/blender/compositor/operations/COM_InvertOperation.cpp b/source/blender/compositor/operations/COM_InvertOperation.cpp index 0802d2d2523..9c2dd825709 100644 --- a/source/blender/compositor/operations/COM_InvertOperation.cpp +++ b/source/blender/compositor/operations/COM_InvertOperation.cpp @@ -39,7 +39,7 @@ void InvertOperation::initExecution() this->m_inputColorProgram = this->getInputSocketReader(1); } -void InvertOperation::executePixel(float *out, float x, float y, PixelSampler sampler) +void InvertOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputValue[4]; float inputColor[4]; @@ -50,18 +50,18 @@ void InvertOperation::executePixel(float *out, float x, float y, PixelSampler sa const float invertedValue = 1.0f - value; if (this->m_color) { - out[0] = (1.0f - inputColor[0]) * value + inputColor[0] * invertedValue; - out[1] = (1.0f - inputColor[1]) * value + inputColor[1] * invertedValue; - out[2] = (1.0f - inputColor[2]) * value + inputColor[2] * invertedValue; + output[0] = (1.0f - inputColor[0]) * value + inputColor[0] * invertedValue; + output[1] = (1.0f - inputColor[1]) * value + inputColor[1] * invertedValue; + output[2] = (1.0f - inputColor[2]) * value + inputColor[2] * invertedValue; } else { - copy_v3_v3(out, inputColor); + copy_v3_v3(output, inputColor); } if (this->m_alpha) - out[3] = (1.0f - inputColor[3]) * value + inputColor[3] * invertedValue; + output[3] = (1.0f - inputColor[3]) * value + inputColor[3] * invertedValue; else - out[3] = inputColor[3]; + output[3] = inputColor[3]; } diff --git a/source/blender/compositor/operations/COM_InvertOperation.h b/source/blender/compositor/operations/COM_InvertOperation.h index 46a5d80b04a..7fded7bb1e4 100644 --- a/source/blender/compositor/operations/COM_InvertOperation.h +++ b/source/blender/compositor/operations/COM_InvertOperation.h @@ -42,7 +42,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_KeyingBlurOperation.cpp b/source/blender/compositor/operations/COM_KeyingBlurOperation.cpp index 00ea5877d63..9fb9efe4fc7 100644 --- a/source/blender/compositor/operations/COM_KeyingBlurOperation.cpp +++ b/source/blender/compositor/operations/COM_KeyingBlurOperation.cpp @@ -46,7 +46,7 @@ void *KeyingBlurOperation::initializeTileData(rcti *rect) return buffer; } -void KeyingBlurOperation::executePixel(float *color, int x, int y, void *data) +void KeyingBlurOperation::executePixel(float output[4], int x, int y, void *data) { MemoryBuffer *inputBuffer = (MemoryBuffer *)data; float *buffer = inputBuffer->getBuffer(); @@ -85,7 +85,7 @@ void KeyingBlurOperation::executePixel(float *color, int x, int y, void *data) average /= (float) count; - color[0] = average; + output[0] = average; } bool KeyingBlurOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) diff --git a/source/blender/compositor/operations/COM_KeyingBlurOperation.h b/source/blender/compositor/operations/COM_KeyingBlurOperation.h index aaacf66a656..a1c56cc9c07 100644 --- a/source/blender/compositor/operations/COM_KeyingBlurOperation.h +++ b/source/blender/compositor/operations/COM_KeyingBlurOperation.h @@ -47,7 +47,7 @@ public: void *initializeTileData(rcti *rect); - void executePixel(float *color, int x, int y, void *data); + void executePixel(float output[4], int x, int y, void *data); bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output); }; diff --git a/source/blender/compositor/operations/COM_KeyingClipOperation.cpp b/source/blender/compositor/operations/COM_KeyingClipOperation.cpp index d8afaceb37b..909eeed8937 100644 --- a/source/blender/compositor/operations/COM_KeyingClipOperation.cpp +++ b/source/blender/compositor/operations/COM_KeyingClipOperation.cpp @@ -51,7 +51,7 @@ void *KeyingClipOperation::initializeTileData(rcti *rect) return buffer; } -void KeyingClipOperation::executePixel(float *color, int x, int y, void *data) +void KeyingClipOperation::executePixel(float output[4], int x, int y, void *data) { const int delta = this->m_kernelRadius; const float tolerance = this->m_kernelTolerance; @@ -92,20 +92,20 @@ void KeyingClipOperation::executePixel(float *color, int x, int y, void *data) if (this->m_isEdgeMatte) { if (ok) - color[0] = 0.0f; + output[0] = 0.0f; else - color[0] = 1.0f; + output[0] = 1.0f; } else { - color[0] = value; + output[0] = value; if (ok) { - if (color[0] < this->m_clipBlack) - color[0] = 0.0f; - else if (color[0] >= this->m_clipWhite) - color[0] = 1.0f; + if (output[0] < this->m_clipBlack) + output[0] = 0.0f; + else if (output[0] >= this->m_clipWhite) + output[0] = 1.0f; else - color[0] = (color[0] - this->m_clipBlack) / (this->m_clipWhite - this->m_clipBlack); + output[0] = (output[0] - this->m_clipBlack) / (this->m_clipWhite - this->m_clipBlack); } } } diff --git a/source/blender/compositor/operations/COM_KeyingClipOperation.h b/source/blender/compositor/operations/COM_KeyingClipOperation.h index eacbccc0818..d79bd14b900 100644 --- a/source/blender/compositor/operations/COM_KeyingClipOperation.h +++ b/source/blender/compositor/operations/COM_KeyingClipOperation.h @@ -51,7 +51,7 @@ public: void *initializeTileData(rcti *rect); - void executePixel(float *color, int x, int y, void *data); + void executePixel(float output[4], int x, int y, void *data); bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output); }; diff --git a/source/blender/compositor/operations/COM_KeyingDespillOperation.cpp b/source/blender/compositor/operations/COM_KeyingDespillOperation.cpp index 2f3fa2bd72a..4426666f100 100644 --- a/source/blender/compositor/operations/COM_KeyingDespillOperation.cpp +++ b/source/blender/compositor/operations/COM_KeyingDespillOperation.cpp @@ -65,7 +65,7 @@ void KeyingDespillOperation::deinitExecution() this->m_screenReader = NULL; } -void KeyingDespillOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void KeyingDespillOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float pixelColor[4]; float screenColor[4]; @@ -85,12 +85,9 @@ void KeyingDespillOperation::executePixel(float *color, float x, float y, PixelS average_value = this->m_colorBalance * pixelColor[min_channel] + (1.0f - this->m_colorBalance) * pixelColor[max_channel]; amount = (pixelColor[screen_primary_channel] - average_value); - color[0] = pixelColor[0]; - color[1] = pixelColor[1]; - color[2] = pixelColor[2]; - color[3] = pixelColor[3]; + copy_v4_v4(output, pixelColor); if (this->m_despillFactor * amount > 0) { - color[screen_primary_channel] = pixelColor[screen_primary_channel] - this->m_despillFactor * amount; + output[screen_primary_channel] = pixelColor[screen_primary_channel] - this->m_despillFactor * amount; } } diff --git a/source/blender/compositor/operations/COM_KeyingDespillOperation.h b/source/blender/compositor/operations/COM_KeyingDespillOperation.h index c6e489057c3..18e771b14f1 100644 --- a/source/blender/compositor/operations/COM_KeyingDespillOperation.h +++ b/source/blender/compositor/operations/COM_KeyingDespillOperation.h @@ -45,7 +45,7 @@ public: void setDespillFactor(float value) {this->m_despillFactor = value;} void setColorBalance(float value) {this->m_colorBalance = value;} - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; #endif diff --git a/source/blender/compositor/operations/COM_KeyingOperation.cpp b/source/blender/compositor/operations/COM_KeyingOperation.cpp index ed9e4f1df16..35138cf0b92 100644 --- a/source/blender/compositor/operations/COM_KeyingOperation.cpp +++ b/source/blender/compositor/operations/COM_KeyingOperation.cpp @@ -77,7 +77,7 @@ void KeyingOperation::deinitExecution() this->m_screenReader = NULL; } -void KeyingOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void KeyingOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float pixelColor[4]; float screenColor[4]; @@ -93,7 +93,7 @@ void KeyingOperation::executePixel(float *color, float x, float y, PixelSampler * because saturation and falloff calculation is based on the fact * that pixels are not overexposured */ - color[0] = 1.0f; + output[0] = 1.0f; } else { float saturation = get_pixel_saturation(pixelColor, this->m_screenBalance, primary_channel); @@ -103,19 +103,19 @@ void KeyingOperation::executePixel(float *color, float x, float y, PixelSampler /* means main channel of pixel is different from screen, * assume this is completely a foreground */ - color[0] = 1.0f; + output[0] = 1.0f; } else if (saturation >= screen_saturation) { /* matched main channels and higher saturation on pixel * is treated as completely background */ - color[0] = 0.0f; + output[0] = 0.0f; } else { /* nice alpha falloff on edges */ float distance = 1.0f - saturation / screen_saturation; - color[0] = distance; + output[0] = distance; } } } diff --git a/source/blender/compositor/operations/COM_KeyingOperation.h b/source/blender/compositor/operations/COM_KeyingOperation.h index 5ca4db7fc75..fcff9243dfc 100644 --- a/source/blender/compositor/operations/COM_KeyingOperation.h +++ b/source/blender/compositor/operations/COM_KeyingOperation.h @@ -49,7 +49,7 @@ public: void setScreenBalance(float value) {this->m_screenBalance = value;} - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; #endif diff --git a/source/blender/compositor/operations/COM_KeyingScreenOperation.cpp b/source/blender/compositor/operations/COM_KeyingScreenOperation.cpp index 33bdd892fe8..c9b129d8dcf 100644 --- a/source/blender/compositor/operations/COM_KeyingScreenOperation.cpp +++ b/source/blender/compositor/operations/COM_KeyingScreenOperation.cpp @@ -78,7 +78,7 @@ KeyingScreenOperation::TriangulationData *KeyingScreenOperation::buildVoronoiTri TriangulationData *triangulation; MovieTracking *tracking = &this->m_movieClip->tracking; MovieTrackingTrack *track; - VoronoiSite *sites; + VoronoiSite *sites, *site; ImBuf *ibuf; ListBase *tracksbase; ListBase edges = {NULL, NULL}; @@ -131,9 +131,8 @@ KeyingScreenOperation::TriangulationData *KeyingScreenOperation::buildVoronoiTri sites = (VoronoiSite *) MEM_callocN(sizeof(VoronoiSite) * sites_total, "keyingscreen voronoi sites"); track = (MovieTrackingTrack *) tracksbase->first; - for (track = (MovieTrackingTrack *) tracksbase->first, i = 0; track; track = track->next, i++) { + for (track = (MovieTrackingTrack *) tracksbase->first, site = sites; track; track = track->next) { MovieTrackingMarker *marker = BKE_tracking_marker_get(track, clip_frame); - VoronoiSite *site; ImBuf *pattern_ibuf; int j; float pos[2]; @@ -149,8 +148,6 @@ KeyingScreenOperation::TriangulationData *KeyingScreenOperation::buildVoronoiTri continue; } - site = &sites[i]; - pattern_ibuf = BKE_tracking_get_pattern_imbuf(ibuf, track, marker, TRUE, FALSE); zero_v3(site->color); @@ -172,6 +169,8 @@ KeyingScreenOperation::TriangulationData *KeyingScreenOperation::buildVoronoiTri site->co[0] = pos[0] * width; site->co[1] = pos[1] * height; + + site++; } IMB_freeImBuf(ibuf); @@ -281,7 +280,7 @@ void KeyingScreenOperation::deinitializeTileData(rcti *rect, void *data) MEM_freeN(tile_data); } -void KeyingScreenOperation::determineResolution(unsigned int resolution[], unsigned int preferredResolution[]) +void KeyingScreenOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]) { resolution[0] = 0; resolution[1] = 0; @@ -299,12 +298,12 @@ void KeyingScreenOperation::determineResolution(unsigned int resolution[], unsig } } -void KeyingScreenOperation::executePixel(float *color, int x, int y, void *data) +void KeyingScreenOperation::executePixel(float output[4], int x, int y, void *data) { - color[0] = 0.0f; - color[1] = 0.0f; - color[2] = 0.0f; - color[3] = 1.0f; + output[0] = 0.0f; + output[1] = 0.0f; + output[2] = 0.0f; + output[3] = 1.0f; if (this->m_movieClip && data) { TriangulationData *triangulation = this->m_cachedTriangulation; @@ -325,9 +324,9 @@ void KeyingScreenOperation::executePixel(float *color, int x, int y, void *data) if (barycentric_coords_v2(a->co, b->co, c->co, co, w)) { if (barycentric_inside_triangle_v2(w)) { - color[0] = a->color[0] * w[0] + b->color[0] * w[1] + c->color[0] * w[2]; - color[1] = a->color[1] * w[0] + b->color[1] * w[1] + c->color[1] * w[2]; - color[2] = a->color[2] * w[0] + b->color[2] * w[1] + c->color[2] * w[2]; + output[0] = a->color[0] * w[0] + b->color[0] * w[1] + c->color[0] * w[2]; + output[1] = a->color[1] * w[0] + b->color[1] * w[1] + c->color[1] * w[2]; + output[2] = a->color[2] * w[0] + b->color[2] * w[1] + c->color[2] * w[2]; break; } diff --git a/source/blender/compositor/operations/COM_KeyingScreenOperation.h b/source/blender/compositor/operations/COM_KeyingScreenOperation.h index 04e47e6e77f..8b1128a4da3 100644 --- a/source/blender/compositor/operations/COM_KeyingScreenOperation.h +++ b/source/blender/compositor/operations/COM_KeyingScreenOperation.h @@ -62,7 +62,7 @@ protected: /** * Determine the output resolution. The resolution is retrieved from the Renderer */ - void determineResolution(unsigned int resolution[], unsigned int preferredResolution[]); + void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]); TriangulationData *buildVoronoiTriangulation(); @@ -79,7 +79,7 @@ public: void setTrackingObject(const char *object) {strncpy(this->m_trackingObject, object, sizeof(this->m_trackingObject));} void setFramenumber(int framenumber) {this->m_framenumber = framenumber;} - void executePixel(float *color, int x, int y, void *data); + void executePixel(float output[4], int x, int y, void *data); }; #endif diff --git a/source/blender/compositor/operations/COM_LuminanceMatteOperation.cpp b/source/blender/compositor/operations/COM_LuminanceMatteOperation.cpp index 7f637c127c1..4c65113ee70 100644 --- a/source/blender/compositor/operations/COM_LuminanceMatteOperation.cpp +++ b/source/blender/compositor/operations/COM_LuminanceMatteOperation.cpp @@ -40,7 +40,7 @@ void LuminanceMatteOperation::deinitExecution() this->m_inputImageProgram = NULL; } -void LuminanceMatteOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void LuminanceMatteOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inColor[4]; @@ -52,10 +52,10 @@ void LuminanceMatteOperation::executePixel(float *outputValue, float x, float y, this->m_inputImageProgram->read(inColor, x, y, sampler); /* one line thread-friend algorithm: - * outputValue[0] = max(inputValue[3], min(high, max(low, ((inColor[0]-low)/(high-low)))) + * output[0] = max(inputValue[3], min(high, max(low, ((inColor[0]-low)/(high-low)))) */ - /* test range*/ + /* test range */ if (inColor[0] > high) { alpha = 1.f; } @@ -73,11 +73,11 @@ void LuminanceMatteOperation::executePixel(float *outputValue, float x, float y, /* don't make something that was more transparent less transparent */ if (alpha < inColor[3]) { - outputValue[0] = alpha; + output[0] = alpha; } else { /* leave now it was before */ - outputValue[0] = inColor[3]; + output[0] = inColor[3]; } } diff --git a/source/blender/compositor/operations/COM_LuminanceMatteOperation.h b/source/blender/compositor/operations/COM_LuminanceMatteOperation.h index c1ab628f787..009a1e8825e 100644 --- a/source/blender/compositor/operations/COM_LuminanceMatteOperation.h +++ b/source/blender/compositor/operations/COM_LuminanceMatteOperation.h @@ -41,7 +41,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); void initExecution(); void deinitExecution(); diff --git a/source/blender/compositor/operations/COM_MapUVOperation.cpp b/source/blender/compositor/operations/COM_MapUVOperation.cpp index a5f503a669b..1a441b0ac9a 100644 --- a/source/blender/compositor/operations/COM_MapUVOperation.cpp +++ b/source/blender/compositor/operations/COM_MapUVOperation.cpp @@ -40,7 +40,7 @@ void MapUVOperation::initExecution() this->m_inputUVProgram = this->getInputSocketReader(1); } -void MapUVOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void MapUVOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputUV[4]; float uv_a[4], uv_b[4]; @@ -52,7 +52,7 @@ void MapUVOperation::executePixel(float *color, float x, float y, PixelSampler s this->m_inputUVProgram->read(inputUV, x, y, sampler); if (inputUV[2] == 0.f) { - zero_v4(color); + zero_v4(output); return; } /* adaptive sampling, red (U) channel */ @@ -107,11 +107,11 @@ void MapUVOperation::executePixel(float *color, float x, float y, PixelSampler s u = inputUV[0] * this->m_inputColorProgram->getWidth(); v = inputUV[1] * this->m_inputColorProgram->getHeight(); - this->m_inputColorProgram->read(color, u, v, dx, dy); + this->m_inputColorProgram->read(output, u, v, dx, dy); /* "premul" */ if (alpha < 1.0f) { - mul_v4_fl(color, alpha); + mul_v4_fl(output, alpha); } } diff --git a/source/blender/compositor/operations/COM_MapUVOperation.h b/source/blender/compositor/operations/COM_MapUVOperation.h index ae042f60789..c8356c1a7ad 100644 --- a/source/blender/compositor/operations/COM_MapUVOperation.h +++ b/source/blender/compositor/operations/COM_MapUVOperation.h @@ -45,7 +45,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_MapValueOperation.cpp b/source/blender/compositor/operations/COM_MapValueOperation.cpp index 96e586ccef8..7acc431f7b5 100644 --- a/source/blender/compositor/operations/COM_MapValueOperation.cpp +++ b/source/blender/compositor/operations/COM_MapValueOperation.cpp @@ -34,7 +34,7 @@ void MapValueOperation::initExecution() this->m_inputOperation = this->getInputSocketReader(0); } -void MapValueOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MapValueOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float src[4]; this->m_inputOperation->read(src, x, y, sampler); @@ -47,7 +47,7 @@ void MapValueOperation::executePixel(float *outputValue, float x, float y, Pixel if (value > texmap->max[0]) value = texmap->max[0]; - outputValue[0] = value; + output[0] = value; } void MapValueOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_MapValueOperation.h b/source/blender/compositor/operations/COM_MapValueOperation.h index a2664c32a4e..418d6d9bf4d 100644 --- a/source/blender/compositor/operations/COM_MapValueOperation.h +++ b/source/blender/compositor/operations/COM_MapValueOperation.h @@ -45,7 +45,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_MaskOperation.cpp b/source/blender/compositor/operations/COM_MaskOperation.cpp index 1812b7372bb..a156dfc1d99 100644 --- a/source/blender/compositor/operations/COM_MaskOperation.cpp +++ b/source/blender/compositor/operations/COM_MaskOperation.cpp @@ -109,7 +109,7 @@ void MaskOperation::deinitExecution() } } -void MaskOperation::determineResolution(unsigned int resolution[], unsigned int preferredResolution[]) +void MaskOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]) { if (this->m_maskWidth == 0 || this->m_maskHeight == 0) { NodeOperation::determineResolution(resolution, preferredResolution); @@ -127,29 +127,30 @@ void MaskOperation::determineResolution(unsigned int resolution[], unsigned int } } -void MaskOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void MaskOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { - const float xy[2] = {x * this->m_maskWidthInv, y * this->m_maskHeightInv}; + const float xy[2] = {x * this->m_maskWidthInv, + y * this->m_maskHeightInv}; if (this->m_rasterMaskHandleTot == 1) { if (this->m_rasterMaskHandles[0]) { - color[0] = BKE_maskrasterize_handle_sample(this->m_rasterMaskHandles[0], xy); + output[0] = BKE_maskrasterize_handle_sample(this->m_rasterMaskHandles[0], xy); } else { - color[0] = 0.0f; + output[0] = 0.0f; } } else { /* incase loop below fails */ - color[0] = 0.0f; + output[0] = 0.0f; for (unsigned int i = 0; i < this->m_rasterMaskHandleTot; i++) { if (this->m_rasterMaskHandles[i]) { - color[0] += BKE_maskrasterize_handle_sample(this->m_rasterMaskHandles[i], xy); + output[0] += BKE_maskrasterize_handle_sample(this->m_rasterMaskHandles[i], xy); } } /* until we get better falloff */ - color[0] /= this->m_rasterMaskHandleTot; + output[0] /= this->m_rasterMaskHandleTot; } } diff --git a/source/blender/compositor/operations/COM_MaskOperation.h b/source/blender/compositor/operations/COM_MaskOperation.h index 6e1735bcf9d..2de71afcfa7 100644 --- a/source/blender/compositor/operations/COM_MaskOperation.h +++ b/source/blender/compositor/operations/COM_MaskOperation.h @@ -56,7 +56,7 @@ protected: /** * Determine the output resolution. The resolution is retrieved from the Renderer */ - void determineResolution(unsigned int resolution[], unsigned int preferredResolution[]); + void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]); public: MaskOperation(); @@ -83,7 +83,7 @@ public: void setMotionBlurSamples(int samples) { this->m_rasterMaskHandleTot = min(max(1, samples), CMP_NODE_MASK_MBLUR_SAMPLES_MAX); } void setMotionBlurShutter(float shutter) { this->m_frame_shutter = shutter; } - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; #endif diff --git a/source/blender/compositor/operations/COM_MathBaseOperation.cpp b/source/blender/compositor/operations/COM_MathBaseOperation.cpp index 6c0c27c2522..7039689aa5f 100644 --- a/source/blender/compositor/operations/COM_MathBaseOperation.cpp +++ b/source/blender/compositor/operations/COM_MathBaseOperation.cpp @@ -32,6 +32,7 @@ MathBaseOperation::MathBaseOperation() : NodeOperation() this->addOutputSocket(COM_DT_VALUE); this->m_inputValue1Operation = NULL; this->m_inputValue2Operation = NULL; + this->m_useClamp = false; } void MathBaseOperation::initExecution() @@ -47,10 +48,10 @@ void MathBaseOperation::deinitExecution() this->m_inputValue2Operation = NULL; } -void MathBaseOperation::determineResolution(unsigned int resolution[], unsigned int preferredResolution[]) +void MathBaseOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]) { InputSocket *socket; - unsigned int tempPreferredResolution[] = {0, 0}; + unsigned int tempPreferredResolution[2] = {0, 0}; unsigned int tempResolution[2]; socket = this->getInputSocket(0); @@ -71,7 +72,7 @@ void MathBaseOperation::clampIfNeeded(float *color) } } -void MathAddOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MathAddOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputValue1[4]; float inputValue2[4]; @@ -79,12 +80,12 @@ void MathAddOperation::executePixel(float *outputValue, float x, float y, PixelS this->m_inputValue1Operation->read(&inputValue1[0], x, y, sampler); this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler); - outputValue[0] = inputValue1[0] + inputValue2[0]; + output[0] = inputValue1[0] + inputValue2[0]; - clampIfNeeded(outputValue); + clampIfNeeded(output); } -void MathSubtractOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MathSubtractOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputValue1[4]; float inputValue2[4]; @@ -92,12 +93,12 @@ void MathSubtractOperation::executePixel(float *outputValue, float x, float y, P this->m_inputValue1Operation->read(&inputValue1[0], x, y, sampler); this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler); - outputValue[0] = inputValue1[0] - inputValue2[0]; + output[0] = inputValue1[0] - inputValue2[0]; - clampIfNeeded(outputValue); + clampIfNeeded(output); } -void MathMultiplyOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MathMultiplyOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputValue1[4]; float inputValue2[4]; @@ -105,12 +106,12 @@ void MathMultiplyOperation::executePixel(float *outputValue, float x, float y, P this->m_inputValue1Operation->read(&inputValue1[0], x, y, sampler); this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler); - outputValue[0] = inputValue1[0] * inputValue2[0]; + output[0] = inputValue1[0] * inputValue2[0]; - clampIfNeeded(outputValue); + clampIfNeeded(output); } -void MathDivideOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MathDivideOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputValue1[4]; float inputValue2[4]; @@ -119,14 +120,14 @@ void MathDivideOperation::executePixel(float *outputValue, float x, float y, Pix this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler); if (inputValue2[0] == 0) /* We don't want to divide by zero. */ - outputValue[0] = 0.0; + output[0] = 0.0; else - outputValue[0] = inputValue1[0] / inputValue2[0]; + output[0] = inputValue1[0] / inputValue2[0]; - clampIfNeeded(outputValue); + clampIfNeeded(output); } -void MathSineOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MathSineOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputValue1[4]; float inputValue2[4]; @@ -134,12 +135,12 @@ void MathSineOperation::executePixel(float *outputValue, float x, float y, Pixel this->m_inputValue1Operation->read(&inputValue1[0], x, y, sampler); this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler); - outputValue[0] = sin(inputValue1[0]); + output[0] = sin(inputValue1[0]); - clampIfNeeded(outputValue); + clampIfNeeded(output); } -void MathCosineOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MathCosineOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputValue1[4]; float inputValue2[4]; @@ -147,12 +148,12 @@ void MathCosineOperation::executePixel(float *outputValue, float x, float y, Pix this->m_inputValue1Operation->read(&inputValue1[0], x, y, sampler); this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler); - outputValue[0] = cos(inputValue1[0]); + output[0] = cos(inputValue1[0]); - clampIfNeeded(outputValue); + clampIfNeeded(output); } -void MathTangentOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MathTangentOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputValue1[4]; float inputValue2[4]; @@ -160,12 +161,12 @@ void MathTangentOperation::executePixel(float *outputValue, float x, float y, Pi this->m_inputValue1Operation->read(&inputValue1[0], x, y, sampler); this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler); - outputValue[0] = tan(inputValue1[0]); + output[0] = tan(inputValue1[0]); - clampIfNeeded(outputValue); + clampIfNeeded(output); } -void MathArcSineOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MathArcSineOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputValue1[4]; float inputValue2[4]; @@ -174,14 +175,14 @@ void MathArcSineOperation::executePixel(float *outputValue, float x, float y, Pi this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler); if (inputValue1[0] <= 1 && inputValue1[0] >= -1) - outputValue[0] = asin(inputValue1[0]); + output[0] = asin(inputValue1[0]); else - outputValue[0] = 0.0; + output[0] = 0.0; - clampIfNeeded(outputValue); + clampIfNeeded(output); } -void MathArcCosineOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MathArcCosineOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputValue1[4]; float inputValue2[4]; @@ -190,14 +191,14 @@ void MathArcCosineOperation::executePixel(float *outputValue, float x, float y, this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler); if (inputValue1[0] <= 1 && inputValue1[0] >= -1) - outputValue[0] = acos(inputValue1[0]); + output[0] = acos(inputValue1[0]); else - outputValue[0] = 0.0; + output[0] = 0.0; - clampIfNeeded(outputValue); + clampIfNeeded(output); } -void MathArcTangentOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MathArcTangentOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputValue1[4]; float inputValue2[4]; @@ -205,12 +206,12 @@ void MathArcTangentOperation::executePixel(float *outputValue, float x, float y, this->m_inputValue1Operation->read(&inputValue1[0], x, y, sampler); this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler); - outputValue[0] = atan(inputValue1[0]); + output[0] = atan(inputValue1[0]); - clampIfNeeded(outputValue); + clampIfNeeded(output); } -void MathPowerOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MathPowerOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputValue1[4]; float inputValue2[4]; @@ -219,23 +220,23 @@ void MathPowerOperation::executePixel(float *outputValue, float x, float y, Pixe this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler); if (inputValue1[0] >= 0) { - outputValue[0] = pow(inputValue1[0], inputValue2[0]); + output[0] = pow(inputValue1[0], inputValue2[0]); } else { float y_mod_1 = fmod(inputValue2[0], 1); /* if input value is not nearly an integer, fall back to zero, nicer than straight rounding */ if (y_mod_1 > 0.999f || y_mod_1 < 0.001f) { - outputValue[0] = pow(inputValue1[0], floorf(inputValue2[0] + 0.5f)); + output[0] = pow(inputValue1[0], floorf(inputValue2[0] + 0.5f)); } else { - outputValue[0] = 0.0; + output[0] = 0.0; } } - clampIfNeeded(outputValue); + clampIfNeeded(output); } -void MathLogarithmOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MathLogarithmOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputValue1[4]; float inputValue2[4]; @@ -244,14 +245,14 @@ void MathLogarithmOperation::executePixel(float *outputValue, float x, float y, this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler); if (inputValue1[0] > 0 && inputValue2[0] > 0) - outputValue[0] = log(inputValue1[0]) / log(inputValue2[0]); + output[0] = log(inputValue1[0]) / log(inputValue2[0]); else - outputValue[0] = 0.0; + output[0] = 0.0; - clampIfNeeded(outputValue); + clampIfNeeded(output); } -void MathMinimumOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MathMinimumOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputValue1[4]; float inputValue2[4]; @@ -259,12 +260,12 @@ void MathMinimumOperation::executePixel(float *outputValue, float x, float y, Pi this->m_inputValue1Operation->read(&inputValue1[0], x, y, sampler); this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler); - outputValue[0] = min(inputValue1[0], inputValue2[0]); + output[0] = min(inputValue1[0], inputValue2[0]); - clampIfNeeded(outputValue); + clampIfNeeded(output); } -void MathMaximumOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MathMaximumOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputValue1[4]; float inputValue2[4]; @@ -272,12 +273,12 @@ void MathMaximumOperation::executePixel(float *outputValue, float x, float y, Pi this->m_inputValue1Operation->read(&inputValue1[0], x, y, sampler); this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler); - outputValue[0] = max(inputValue1[0], inputValue2[0]); + output[0] = max(inputValue1[0], inputValue2[0]); - clampIfNeeded(outputValue); + clampIfNeeded(output); } -void MathRoundOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MathRoundOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputValue1[4]; float inputValue2[4]; @@ -285,12 +286,12 @@ void MathRoundOperation::executePixel(float *outputValue, float x, float y, Pixe this->m_inputValue1Operation->read(&inputValue1[0], x, y, sampler); this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler); - outputValue[0] = round(inputValue1[0]); + output[0] = round(inputValue1[0]); - clampIfNeeded(outputValue); + clampIfNeeded(output); } -void MathLessThanOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MathLessThanOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputValue1[4]; float inputValue2[4]; @@ -298,12 +299,12 @@ void MathLessThanOperation::executePixel(float *outputValue, float x, float y, P this->m_inputValue1Operation->read(&inputValue1[0], x, y, sampler); this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler); - outputValue[0] = inputValue1[0] < inputValue2[0] ? 1.0f : 0.0f; + output[0] = inputValue1[0] < inputValue2[0] ? 1.0f : 0.0f; - clampIfNeeded(outputValue); + clampIfNeeded(output); } -void MathGreaterThanOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MathGreaterThanOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputValue1[4]; float inputValue2[4]; @@ -311,9 +312,9 @@ void MathGreaterThanOperation::executePixel(float *outputValue, float x, float y this->m_inputValue1Operation->read(&inputValue1[0], x, y, sampler); this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler); - outputValue[0] = inputValue1[0] > inputValue2[0] ? 1.0f : 0.0f; + output[0] = inputValue1[0] > inputValue2[0] ? 1.0f : 0.0f; - clampIfNeeded(outputValue); + clampIfNeeded(output); } diff --git a/source/blender/compositor/operations/COM_MathBaseOperation.h b/source/blender/compositor/operations/COM_MathBaseOperation.h index 8fc6c762b16..b492d06a697 100644 --- a/source/blender/compositor/operations/COM_MathBaseOperation.h +++ b/source/blender/compositor/operations/COM_MathBaseOperation.h @@ -50,7 +50,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler) = 0; + void executePixel(float output[4], float x, float y, PixelSampler sampler) = 0; /** * Initialize the execution @@ -65,7 +65,7 @@ public: /** * Determine resolution */ - void determineResolution(unsigned int resolution[], unsigned int preferredResolution[]); + void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]); void setUseClamp(bool value) { this->m_useClamp = value; } }; @@ -73,88 +73,88 @@ public: class MathAddOperation : public MathBaseOperation { public: MathAddOperation() : MathBaseOperation() {} - void executePixel(float *outputValue, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; class MathSubtractOperation : public MathBaseOperation { public: MathSubtractOperation() : MathBaseOperation() {} - void executePixel(float *outputValue, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; class MathMultiplyOperation : public MathBaseOperation { public: MathMultiplyOperation() : MathBaseOperation() {} - void executePixel(float *outputValue, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; class MathDivideOperation : public MathBaseOperation { public: MathDivideOperation() : MathBaseOperation() {} - void executePixel(float *outputValue, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; class MathSineOperation : public MathBaseOperation { public: MathSineOperation() : MathBaseOperation() {} - void executePixel(float *outputValue, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; class MathCosineOperation : public MathBaseOperation { public: MathCosineOperation() : MathBaseOperation() {} - void executePixel(float *outputValue, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; class MathTangentOperation : public MathBaseOperation { public: MathTangentOperation() : MathBaseOperation() {} - void executePixel(float *outputValue, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; class MathArcSineOperation : public MathBaseOperation { public: MathArcSineOperation() : MathBaseOperation() {} - void executePixel(float *outputValue, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; class MathArcCosineOperation : public MathBaseOperation { public: MathArcCosineOperation() : MathBaseOperation() {} - void executePixel(float *outputValue, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; class MathArcTangentOperation : public MathBaseOperation { public: MathArcTangentOperation() : MathBaseOperation() {} - void executePixel(float *outputValue, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; class MathPowerOperation : public MathBaseOperation { public: MathPowerOperation() : MathBaseOperation() {} - void executePixel(float *outputValue, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; class MathLogarithmOperation : public MathBaseOperation { public: MathLogarithmOperation() : MathBaseOperation() {} - void executePixel(float *outputValue, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; class MathMinimumOperation : public MathBaseOperation { public: MathMinimumOperation() : MathBaseOperation() {} - void executePixel(float *outputValue, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; class MathMaximumOperation : public MathBaseOperation { public: MathMaximumOperation() : MathBaseOperation() {} - void executePixel(float *outputValue, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; class MathRoundOperation : public MathBaseOperation { public: MathRoundOperation() : MathBaseOperation() {} - void executePixel(float *outputValue, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; class MathLessThanOperation : public MathBaseOperation { public: MathLessThanOperation() : MathBaseOperation() {} - void executePixel(float *outputValue, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; class MathGreaterThanOperation : public MathBaseOperation { public: MathGreaterThanOperation() : MathBaseOperation() {} - void executePixel(float *outputValue, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; #endif diff --git a/source/blender/compositor/operations/COM_MixAddOperation.cpp b/source/blender/compositor/operations/COM_MixAddOperation.cpp index b49c65cc010..be737f22280 100644 --- a/source/blender/compositor/operations/COM_MixAddOperation.cpp +++ b/source/blender/compositor/operations/COM_MixAddOperation.cpp @@ -27,7 +27,7 @@ MixAddOperation::MixAddOperation() : MixBaseOperation() /* pass */ } -void MixAddOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MixAddOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor1[4]; float inputColor2[4]; @@ -42,11 +42,11 @@ void MixAddOperation::executePixel(float *outputValue, float x, float y, PixelSa if (this->useValueAlphaMultiply()) { value *= inputColor2[3]; } - outputValue[0] = inputColor1[0] + value * inputColor2[0]; - outputValue[1] = inputColor1[1] + value * inputColor2[1]; - outputValue[2] = inputColor1[2] + value * inputColor2[2]; - outputValue[3] = inputColor1[3]; + output[0] = inputColor1[0] + value * inputColor2[0]; + output[1] = inputColor1[1] + value * inputColor2[1]; + output[2] = inputColor1[2] + value * inputColor2[2]; + output[3] = inputColor1[3]; - clampIfNeeded(outputValue); + clampIfNeeded(output); } diff --git a/source/blender/compositor/operations/COM_MixAddOperation.h b/source/blender/compositor/operations/COM_MixAddOperation.h index 8fc41706073..5a52846e847 100644 --- a/source/blender/compositor/operations/COM_MixAddOperation.h +++ b/source/blender/compositor/operations/COM_MixAddOperation.h @@ -39,7 +39,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; #endif diff --git a/source/blender/compositor/operations/COM_MixBaseOperation.cpp b/source/blender/compositor/operations/COM_MixBaseOperation.cpp index 9f9c432895e..2d40629e764 100644 --- a/source/blender/compositor/operations/COM_MixBaseOperation.cpp +++ b/source/blender/compositor/operations/COM_MixBaseOperation.cpp @@ -42,7 +42,7 @@ void MixBaseOperation::initExecution() this->m_inputColor2Operation = this->getInputSocketReader(2); } -void MixBaseOperation::executePixel(float *outputColor, float x, float y, PixelSampler sampler) +void MixBaseOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor1[4]; float inputColor2[4]; @@ -57,10 +57,10 @@ void MixBaseOperation::executePixel(float *outputColor, float x, float y, PixelS value *= inputColor2[3]; } float valuem = 1.0f - value; - outputColor[0] = valuem * (inputColor1[0]) + value * (inputColor2[0]); - outputColor[1] = valuem * (inputColor1[1]) + value * (inputColor2[1]); - outputColor[2] = valuem * (inputColor1[2]) + value * (inputColor2[2]); - outputColor[3] = inputColor1[3]; + output[0] = valuem * (inputColor1[0]) + value * (inputColor2[0]); + output[1] = valuem * (inputColor1[1]) + value * (inputColor2[1]); + output[2] = valuem * (inputColor1[2]) + value * (inputColor2[2]); + output[3] = inputColor1[3]; } void MixBaseOperation::deinitExecution() @@ -70,10 +70,10 @@ void MixBaseOperation::deinitExecution() this->m_inputColor2Operation = NULL; } -void MixBaseOperation::determineResolution(unsigned int resolution[], unsigned int preferredResolution[]) +void MixBaseOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]) { InputSocket *socket; - unsigned int tempPreferredResolution[] = {0, 0}; + unsigned int tempPreferredResolution[2] = {0, 0}; unsigned int tempResolution[2]; socket = this->getInputSocket(1); diff --git a/source/blender/compositor/operations/COM_MixBaseOperation.h b/source/blender/compositor/operations/COM_MixBaseOperation.h index 0a8ed4fa0e1..4b466d193d6 100644 --- a/source/blender/compositor/operations/COM_MixBaseOperation.h +++ b/source/blender/compositor/operations/COM_MixBaseOperation.h @@ -59,7 +59,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution @@ -71,7 +71,7 @@ public: */ void deinitExecution(); - void determineResolution(unsigned int resolution[], unsigned int preferredResolution[]); + void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]); void setUseValueAlphaMultiply(const bool value) { this->m_valueAlphaMultiply = value; } bool useValueAlphaMultiply() { return this->m_valueAlphaMultiply; } diff --git a/source/blender/compositor/operations/COM_MixBlendOperation.cpp b/source/blender/compositor/operations/COM_MixBlendOperation.cpp index 090343e8450..0ca7d460064 100644 --- a/source/blender/compositor/operations/COM_MixBlendOperation.cpp +++ b/source/blender/compositor/operations/COM_MixBlendOperation.cpp @@ -27,7 +27,7 @@ MixBlendOperation::MixBlendOperation() : MixBaseOperation() /* pass */ } -void MixBlendOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MixBlendOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor1[4]; float inputColor2[4]; @@ -43,10 +43,10 @@ void MixBlendOperation::executePixel(float *outputValue, float x, float y, Pixel value *= inputColor2[3]; } float valuem = 1.0f - value; - outputValue[0] = valuem * (inputColor1[0]) + value * (inputColor2[0]); - outputValue[1] = valuem * (inputColor1[1]) + value * (inputColor2[1]); - outputValue[2] = valuem * (inputColor1[2]) + value * (inputColor2[2]); - outputValue[3] = inputColor1[3]; + output[0] = valuem * (inputColor1[0]) + value * (inputColor2[0]); + output[1] = valuem * (inputColor1[1]) + value * (inputColor2[1]); + output[2] = valuem * (inputColor1[2]) + value * (inputColor2[2]); + output[3] = inputColor1[3]; - clampIfNeeded(outputValue); + clampIfNeeded(output); } diff --git a/source/blender/compositor/operations/COM_MixBlendOperation.h b/source/blender/compositor/operations/COM_MixBlendOperation.h index 6073ca1fc52..ce3f187a5e2 100644 --- a/source/blender/compositor/operations/COM_MixBlendOperation.h +++ b/source/blender/compositor/operations/COM_MixBlendOperation.h @@ -39,7 +39,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; #endif diff --git a/source/blender/compositor/operations/COM_MixBurnOperation.cpp b/source/blender/compositor/operations/COM_MixBurnOperation.cpp index fbb3cb7b27b..5cfe38766bc 100644 --- a/source/blender/compositor/operations/COM_MixBurnOperation.cpp +++ b/source/blender/compositor/operations/COM_MixBurnOperation.cpp @@ -27,7 +27,7 @@ MixBurnOperation::MixBurnOperation() : MixBaseOperation() /* pass */ } -void MixBurnOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MixBurnOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor1[4]; float inputColor2[4]; @@ -45,45 +45,45 @@ void MixBurnOperation::executePixel(float *outputValue, float x, float y, PixelS tmp = valuem + value * inputColor2[0]; if (tmp <= 0.0f) - outputValue[0] = 0.0f; + output[0] = 0.0f; else { tmp = 1.0f - (1.0f - inputColor1[0]) / tmp; if (tmp < 0.0f) - outputValue[0] = 0.0f; + output[0] = 0.0f; else if (tmp > 1.0f) - outputValue[0] = 1.0f; + output[0] = 1.0f; else - outputValue[0] = tmp; + output[0] = tmp; } tmp = valuem + value * inputColor2[1]; if (tmp <= 0.0f) - outputValue[1] = 0.0f; + output[1] = 0.0f; else { tmp = 1.0f - (1.0f - inputColor1[1]) / tmp; if (tmp < 0.0f) - outputValue[1] = 0.0f; + output[1] = 0.0f; else if (tmp > 1.0f) - outputValue[1] = 1.0f; + output[1] = 1.0f; else - outputValue[1] = tmp; + output[1] = tmp; } tmp = valuem + value * inputColor2[2]; if (tmp <= 0.0f) - outputValue[2] = 0.0f; + output[2] = 0.0f; else { tmp = 1.0f - (1.0f - inputColor1[2]) / tmp; if (tmp < 0.0f) - outputValue[2] = 0.0f; + output[2] = 0.0f; else if (tmp > 1.0f) - outputValue[2] = 1.0f; + output[2] = 1.0f; else - outputValue[2] = tmp; + output[2] = tmp; } - outputValue[3] = inputColor1[3]; + output[3] = inputColor1[3]; - clampIfNeeded(outputValue); + clampIfNeeded(output); } diff --git a/source/blender/compositor/operations/COM_MixBurnOperation.h b/source/blender/compositor/operations/COM_MixBurnOperation.h index 88435f05503..131ccfa2130 100644 --- a/source/blender/compositor/operations/COM_MixBurnOperation.h +++ b/source/blender/compositor/operations/COM_MixBurnOperation.h @@ -39,7 +39,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; #endif diff --git a/source/blender/compositor/operations/COM_MixColorOperation.cpp b/source/blender/compositor/operations/COM_MixColorOperation.cpp index 378cfbd9b6c..f8aca92abc7 100644 --- a/source/blender/compositor/operations/COM_MixColorOperation.cpp +++ b/source/blender/compositor/operations/COM_MixColorOperation.cpp @@ -31,7 +31,7 @@ MixColorOperation::MixColorOperation() : MixBaseOperation() /* pass */ } -void MixColorOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MixColorOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor1[4]; float inputColor2[4]; @@ -53,12 +53,12 @@ void MixColorOperation::executePixel(float *outputValue, float x, float y, Pixel float tmpr, tmpg, tmpb; rgb_to_hsv(inputColor1[0], inputColor1[1], inputColor1[2], &rH, &rS, &rV); hsv_to_rgb(colH, colS, rV, &tmpr, &tmpg, &tmpb); - outputValue[0] = valuem * (inputColor1[0]) + value * tmpr; - outputValue[1] = valuem * (inputColor1[1]) + value * tmpg; - outputValue[2] = valuem * (inputColor1[2]) + value * tmpb; + output[0] = valuem * (inputColor1[0]) + value * tmpr; + output[1] = valuem * (inputColor1[1]) + value * tmpg; + output[2] = valuem * (inputColor1[2]) + value * tmpb; } - outputValue[3] = inputColor1[3]; + output[3] = inputColor1[3]; - clampIfNeeded(outputValue); + clampIfNeeded(output); } diff --git a/source/blender/compositor/operations/COM_MixColorOperation.h b/source/blender/compositor/operations/COM_MixColorOperation.h index fb91a426f40..1409d726f03 100644 --- a/source/blender/compositor/operations/COM_MixColorOperation.h +++ b/source/blender/compositor/operations/COM_MixColorOperation.h @@ -39,7 +39,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; #endif diff --git a/source/blender/compositor/operations/COM_MixDarkenOperation.cpp b/source/blender/compositor/operations/COM_MixDarkenOperation.cpp index 68f9c023733..5b79f4c95ac 100644 --- a/source/blender/compositor/operations/COM_MixDarkenOperation.cpp +++ b/source/blender/compositor/operations/COM_MixDarkenOperation.cpp @@ -27,7 +27,7 @@ MixDarkenOperation::MixDarkenOperation() : MixBaseOperation() /* pass */ } -void MixDarkenOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MixDarkenOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor1[4]; float inputColor2[4]; @@ -43,17 +43,17 @@ void MixDarkenOperation::executePixel(float *outputValue, float x, float y, Pixe float valuem = 1.0f - value; float tmp; tmp = inputColor2[0] + ((1.0f - inputColor2[0]) * valuem); - if (tmp < inputColor1[0]) outputValue[0] = tmp; - else outputValue[0] = inputColor1[0]; + if (tmp < inputColor1[0]) output[0] = tmp; + else output[0] = inputColor1[0]; tmp = inputColor2[1] + ((1.0f - inputColor2[1]) * valuem); - if (tmp < inputColor1[1]) outputValue[1] = tmp; - else outputValue[1] = inputColor1[1]; + if (tmp < inputColor1[1]) output[1] = tmp; + else output[1] = inputColor1[1]; tmp = inputColor2[2] + ((1.0f - inputColor2[2]) * valuem); - if (tmp < inputColor1[2]) outputValue[2] = tmp; - else outputValue[2] = inputColor1[2]; + if (tmp < inputColor1[2]) output[2] = tmp; + else output[2] = inputColor1[2]; - outputValue[3] = inputColor1[3]; + output[3] = inputColor1[3]; - clampIfNeeded(outputValue); + clampIfNeeded(output); } diff --git a/source/blender/compositor/operations/COM_MixDarkenOperation.h b/source/blender/compositor/operations/COM_MixDarkenOperation.h index 8b5afaecbd5..f9c35fa364b 100644 --- a/source/blender/compositor/operations/COM_MixDarkenOperation.h +++ b/source/blender/compositor/operations/COM_MixDarkenOperation.h @@ -39,7 +39,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; #endif diff --git a/source/blender/compositor/operations/COM_MixDifferenceOperation.cpp b/source/blender/compositor/operations/COM_MixDifferenceOperation.cpp index 48964e8b78b..d2c1e5e428f 100644 --- a/source/blender/compositor/operations/COM_MixDifferenceOperation.cpp +++ b/source/blender/compositor/operations/COM_MixDifferenceOperation.cpp @@ -28,7 +28,7 @@ MixDifferenceOperation::MixDifferenceOperation() : MixBaseOperation() /* pass */ } -void MixDifferenceOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MixDifferenceOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor1[4]; float inputColor2[4]; @@ -42,11 +42,11 @@ void MixDifferenceOperation::executePixel(float *outputValue, float x, float y, value *= inputColor2[3]; } float valuem = 1.0f - value; - outputValue[0] = valuem * inputColor1[0] + value *fabsf(inputColor1[0] - inputColor2[0]); - outputValue[1] = valuem * inputColor1[1] + value *fabsf(inputColor1[1] - inputColor2[1]); - outputValue[2] = valuem * inputColor1[2] + value *fabsf(inputColor1[2] - inputColor2[2]); - outputValue[3] = inputColor1[3]; + output[0] = valuem * inputColor1[0] + value *fabsf(inputColor1[0] - inputColor2[0]); + output[1] = valuem * inputColor1[1] + value *fabsf(inputColor1[1] - inputColor2[1]); + output[2] = valuem * inputColor1[2] + value *fabsf(inputColor1[2] - inputColor2[2]); + output[3] = inputColor1[3]; - clampIfNeeded(outputValue); + clampIfNeeded(output); } diff --git a/source/blender/compositor/operations/COM_MixDifferenceOperation.h b/source/blender/compositor/operations/COM_MixDifferenceOperation.h index f4ad5d07586..7e4bf3c675c 100644 --- a/source/blender/compositor/operations/COM_MixDifferenceOperation.h +++ b/source/blender/compositor/operations/COM_MixDifferenceOperation.h @@ -39,7 +39,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; #endif diff --git a/source/blender/compositor/operations/COM_MixDivideOperation.cpp b/source/blender/compositor/operations/COM_MixDivideOperation.cpp index d9d2383001b..fdb1618b6e6 100644 --- a/source/blender/compositor/operations/COM_MixDivideOperation.cpp +++ b/source/blender/compositor/operations/COM_MixDivideOperation.cpp @@ -27,7 +27,7 @@ MixDivideOperation::MixDivideOperation() : MixBaseOperation() /* pass */ } -void MixDivideOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MixDivideOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor1[4]; float inputColor2[4]; @@ -43,20 +43,20 @@ void MixDivideOperation::executePixel(float *outputValue, float x, float y, Pixe float valuem = 1.0f - value; if (inputColor2[0] != 0.0f) - outputValue[0] = valuem * (inputColor1[0]) + value * (inputColor1[0]) / inputColor2[0]; + output[0] = valuem * (inputColor1[0]) + value * (inputColor1[0]) / inputColor2[0]; else - outputValue[0] = 0.0f; + output[0] = 0.0f; if (inputColor2[1] != 0.0f) - outputValue[1] = valuem * (inputColor1[1]) + value * (inputColor1[1]) / inputColor2[1]; + output[1] = valuem * (inputColor1[1]) + value * (inputColor1[1]) / inputColor2[1]; else - outputValue[1] = 0.0f; + output[1] = 0.0f; if (inputColor2[2] != 0.0f) - outputValue[2] = valuem * (inputColor1[2]) + value * (inputColor1[2]) / inputColor2[2]; + output[2] = valuem * (inputColor1[2]) + value * (inputColor1[2]) / inputColor2[2]; else - outputValue[2] = 0.0f; + output[2] = 0.0f; - outputValue[3] = inputColor1[3]; + output[3] = inputColor1[3]; - clampIfNeeded(outputValue); + clampIfNeeded(output); } diff --git a/source/blender/compositor/operations/COM_MixDivideOperation.h b/source/blender/compositor/operations/COM_MixDivideOperation.h index 8f94fc2d510..f543265075b 100644 --- a/source/blender/compositor/operations/COM_MixDivideOperation.h +++ b/source/blender/compositor/operations/COM_MixDivideOperation.h @@ -39,7 +39,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; #endif diff --git a/source/blender/compositor/operations/COM_MixDodgeOperation.cpp b/source/blender/compositor/operations/COM_MixDodgeOperation.cpp index 34c6e4043f2..87f60df8e1b 100644 --- a/source/blender/compositor/operations/COM_MixDodgeOperation.cpp +++ b/source/blender/compositor/operations/COM_MixDodgeOperation.cpp @@ -27,7 +27,7 @@ MixDodgeOperation::MixDodgeOperation() : MixBaseOperation() /* pass */ } -void MixDodgeOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MixDodgeOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor1[4]; float inputColor2[4]; @@ -45,50 +45,50 @@ void MixDodgeOperation::executePixel(float *outputValue, float x, float y, Pixel if (inputColor1[0] != 0.0f) { tmp = 1.0f - value * inputColor2[0]; if (tmp <= 0.0f) - outputValue[0] = 1.0f; + output[0] = 1.0f; else { tmp = inputColor1[0] / tmp; if (tmp > 1.0f) - outputValue[0] = 1.0f; + output[0] = 1.0f; else - outputValue[0] = tmp; + output[0] = tmp; } } else - outputValue[0] = 0.0f; + output[0] = 0.0f; if (inputColor1[1] != 0.0f) { tmp = 1.0f - value * inputColor2[1]; if (tmp <= 0.0f) - outputValue[1] = 1.0f; + output[1] = 1.0f; else { tmp = inputColor1[1] / tmp; if (tmp > 1.0f) - outputValue[1] = 1.0f; + output[1] = 1.0f; else - outputValue[1] = tmp; + output[1] = tmp; } } else - outputValue[1] = 0.0f; + output[1] = 0.0f; if (inputColor1[2] != 0.0f) { tmp = 1.0f - value * inputColor2[2]; if (tmp <= 0.0f) - outputValue[2] = 1.0f; + output[2] = 1.0f; else { tmp = inputColor1[2] / tmp; if (tmp > 1.0f) - outputValue[2] = 1.0f; + output[2] = 1.0f; else - outputValue[2] = tmp; + output[2] = tmp; } } else - outputValue[2] = 0.0f; + output[2] = 0.0f; - outputValue[3] = inputColor1[3]; + output[3] = inputColor1[3]; - clampIfNeeded(outputValue); + clampIfNeeded(output); } diff --git a/source/blender/compositor/operations/COM_MixDodgeOperation.h b/source/blender/compositor/operations/COM_MixDodgeOperation.h index f99a82dca8d..9a285c675c5 100644 --- a/source/blender/compositor/operations/COM_MixDodgeOperation.h +++ b/source/blender/compositor/operations/COM_MixDodgeOperation.h @@ -39,7 +39,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; #endif diff --git a/source/blender/compositor/operations/COM_MixGlareOperation.cpp b/source/blender/compositor/operations/COM_MixGlareOperation.cpp index 4a569404ddc..b6a9aa3da3c 100644 --- a/source/blender/compositor/operations/COM_MixGlareOperation.cpp +++ b/source/blender/compositor/operations/COM_MixGlareOperation.cpp @@ -27,7 +27,7 @@ MixGlareOperation::MixGlareOperation() : MixBaseOperation() /* pass */ } -void MixGlareOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MixGlareOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor1[4]; float inputColor2[4]; @@ -40,10 +40,10 @@ void MixGlareOperation::executePixel(float *outputValue, float x, float y, Pixel value = inputValue[0]; float mf = 2.f - 2.f * fabsf(value - 0.5f); - outputValue[0] = mf * ((inputColor1[0]) + value * (inputColor2[0] - inputColor1[0])); - outputValue[1] = mf * ((inputColor1[1]) + value * (inputColor2[1] - inputColor1[1])); - outputValue[2] = mf * ((inputColor1[2]) + value * (inputColor2[2] - inputColor1[2])); - outputValue[3] = inputColor1[3]; + output[0] = mf * ((inputColor1[0]) + value * (inputColor2[0] - inputColor1[0])); + output[1] = mf * ((inputColor1[1]) + value * (inputColor2[1] - inputColor1[1])); + output[2] = mf * ((inputColor1[2]) + value * (inputColor2[2] - inputColor1[2])); + output[3] = inputColor1[3]; - clampIfNeeded(outputValue); + clampIfNeeded(output); } diff --git a/source/blender/compositor/operations/COM_MixGlareOperation.h b/source/blender/compositor/operations/COM_MixGlareOperation.h index 23b9f2420a0..99d478e347d 100644 --- a/source/blender/compositor/operations/COM_MixGlareOperation.h +++ b/source/blender/compositor/operations/COM_MixGlareOperation.h @@ -39,7 +39,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; #endif diff --git a/source/blender/compositor/operations/COM_MixHueOperation.cpp b/source/blender/compositor/operations/COM_MixHueOperation.cpp index 3745f502709..5688d6b26f0 100644 --- a/source/blender/compositor/operations/COM_MixHueOperation.cpp +++ b/source/blender/compositor/operations/COM_MixHueOperation.cpp @@ -31,7 +31,7 @@ MixHueOperation::MixHueOperation() : MixBaseOperation() /* pass */ } -void MixHueOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MixHueOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor1[4]; float inputColor2[4]; @@ -53,11 +53,11 @@ void MixHueOperation::executePixel(float *outputValue, float x, float y, PixelSa float tmpr, tmpg, tmpb; rgb_to_hsv(inputColor1[0], inputColor1[1], inputColor1[2], &rH, &rS, &rV); hsv_to_rgb(colH, rS, rV, &tmpr, &tmpg, &tmpb); - outputValue[0] = valuem * (inputColor1[0]) + value * tmpr; - outputValue[1] = valuem * (inputColor1[1]) + value * tmpg; - outputValue[2] = valuem * (inputColor1[2]) + value * tmpb; + output[0] = valuem * (inputColor1[0]) + value * tmpr; + output[1] = valuem * (inputColor1[1]) + value * tmpg; + output[2] = valuem * (inputColor1[2]) + value * tmpb; } - outputValue[3] = inputColor1[3]; + output[3] = inputColor1[3]; - clampIfNeeded(outputValue); + clampIfNeeded(output); } diff --git a/source/blender/compositor/operations/COM_MixHueOperation.h b/source/blender/compositor/operations/COM_MixHueOperation.h index 1c8eadabbbd..d9864bbe3dc 100644 --- a/source/blender/compositor/operations/COM_MixHueOperation.h +++ b/source/blender/compositor/operations/COM_MixHueOperation.h @@ -39,7 +39,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; #endif diff --git a/source/blender/compositor/operations/COM_MixLightenOperation.cpp b/source/blender/compositor/operations/COM_MixLightenOperation.cpp index 868459db8bf..9eb45a783f8 100644 --- a/source/blender/compositor/operations/COM_MixLightenOperation.cpp +++ b/source/blender/compositor/operations/COM_MixLightenOperation.cpp @@ -27,7 +27,7 @@ MixLightenOperation::MixLightenOperation() : MixBaseOperation() /* pass */ } -void MixLightenOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MixLightenOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor1[4]; float inputColor2[4]; @@ -42,16 +42,16 @@ void MixLightenOperation::executePixel(float *outputValue, float x, float y, Pix } float tmp; tmp = value * inputColor2[0]; - if (tmp > inputColor1[0]) outputValue[0] = tmp; - else outputValue[0] = inputColor1[0]; + if (tmp > inputColor1[0]) output[0] = tmp; + else output[0] = inputColor1[0]; tmp = value * inputColor2[1]; - if (tmp > inputColor1[1]) outputValue[1] = tmp; - else outputValue[1] = inputColor1[1]; + if (tmp > inputColor1[1]) output[1] = tmp; + else output[1] = inputColor1[1]; tmp = value * inputColor2[2]; - if (tmp > inputColor1[2]) outputValue[2] = tmp; - else outputValue[2] = inputColor1[2]; - outputValue[3] = inputColor1[3]; + if (tmp > inputColor1[2]) output[2] = tmp; + else output[2] = inputColor1[2]; + output[3] = inputColor1[3]; - clampIfNeeded(outputValue); + clampIfNeeded(output); } diff --git a/source/blender/compositor/operations/COM_MixLightenOperation.h b/source/blender/compositor/operations/COM_MixLightenOperation.h index d03ab317035..5f08a067e11 100644 --- a/source/blender/compositor/operations/COM_MixLightenOperation.h +++ b/source/blender/compositor/operations/COM_MixLightenOperation.h @@ -39,6 +39,6 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; #endif diff --git a/source/blender/compositor/operations/COM_MixLinearLightOperation.cpp b/source/blender/compositor/operations/COM_MixLinearLightOperation.cpp index 2fff05fbbc9..ee7dcc9fe28 100644 --- a/source/blender/compositor/operations/COM_MixLinearLightOperation.cpp +++ b/source/blender/compositor/operations/COM_MixLinearLightOperation.cpp @@ -27,7 +27,7 @@ MixLinearLightOperation::MixLinearLightOperation() : MixBaseOperation() /* pass */ } -void MixLinearLightOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MixLinearLightOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor1[4]; float inputColor2[4]; @@ -41,19 +41,19 @@ void MixLinearLightOperation::executePixel(float *outputValue, float x, float y, value *= inputColor2[3]; } if (inputColor2[0] > 0.5f) - outputValue[0] = inputColor1[0] + value * (2.0f * (inputColor2[0] - 0.5f)); + output[0] = inputColor1[0] + value * (2.0f * (inputColor2[0] - 0.5f)); else - outputValue[0] = inputColor1[0] + value * (2.0f * (inputColor2[0]) - 1.0f); + output[0] = inputColor1[0] + value * (2.0f * (inputColor2[0]) - 1.0f); if (inputColor2[1] > 0.5f) - outputValue[1] = inputColor1[1] + value * (2.0f * (inputColor2[1] - 0.5f)); + output[1] = inputColor1[1] + value * (2.0f * (inputColor2[1] - 0.5f)); else - outputValue[1] = inputColor1[1] + value * (2.0f * (inputColor2[1]) - 1.0f); + output[1] = inputColor1[1] + value * (2.0f * (inputColor2[1]) - 1.0f); if (inputColor2[2] > 0.5f) - outputValue[2] = inputColor1[2] + value * (2.0f * (inputColor2[2] - 0.5f)); + output[2] = inputColor1[2] + value * (2.0f * (inputColor2[2] - 0.5f)); else - outputValue[2] = inputColor1[2] + value * (2.0f * (inputColor2[2]) - 1.0f); + output[2] = inputColor1[2] + value * (2.0f * (inputColor2[2]) - 1.0f); - outputValue[3] = inputColor1[3]; + output[3] = inputColor1[3]; - clampIfNeeded(outputValue); + clampIfNeeded(output); } diff --git a/source/blender/compositor/operations/COM_MixLinearLightOperation.h b/source/blender/compositor/operations/COM_MixLinearLightOperation.h index 7a9acbe00b0..35451a9f3db 100644 --- a/source/blender/compositor/operations/COM_MixLinearLightOperation.h +++ b/source/blender/compositor/operations/COM_MixLinearLightOperation.h @@ -39,7 +39,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; #endif diff --git a/source/blender/compositor/operations/COM_MixMultiplyOperation.cpp b/source/blender/compositor/operations/COM_MixMultiplyOperation.cpp index 911c0c83b90..e53addb7041 100644 --- a/source/blender/compositor/operations/COM_MixMultiplyOperation.cpp +++ b/source/blender/compositor/operations/COM_MixMultiplyOperation.cpp @@ -27,7 +27,7 @@ MixMultiplyOperation::MixMultiplyOperation() : MixBaseOperation() /* pass */ } -void MixMultiplyOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MixMultiplyOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor1[4]; float inputColor2[4]; @@ -42,11 +42,11 @@ void MixMultiplyOperation::executePixel(float *outputValue, float x, float y, Pi value *= inputColor2[3]; } float valuem = 1.0f - value; - outputValue[0] = inputColor1[0] * (valuem + value * inputColor2[0]); - outputValue[1] = inputColor1[1] * (valuem + value * inputColor2[1]); - outputValue[2] = inputColor1[2] * (valuem + value * inputColor2[2]); - outputValue[3] = inputColor1[3]; + output[0] = inputColor1[0] * (valuem + value * inputColor2[0]); + output[1] = inputColor1[1] * (valuem + value * inputColor2[1]); + output[2] = inputColor1[2] * (valuem + value * inputColor2[2]); + output[3] = inputColor1[3]; - clampIfNeeded(outputValue); + clampIfNeeded(output); } diff --git a/source/blender/compositor/operations/COM_MixMultiplyOperation.h b/source/blender/compositor/operations/COM_MixMultiplyOperation.h index ab7d06aecf6..cdd56bd2f39 100644 --- a/source/blender/compositor/operations/COM_MixMultiplyOperation.h +++ b/source/blender/compositor/operations/COM_MixMultiplyOperation.h @@ -39,7 +39,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; #endif diff --git a/source/blender/compositor/operations/COM_MixOverlayOperation.cpp b/source/blender/compositor/operations/COM_MixOverlayOperation.cpp index ba7a86a80a7..09a9d3cbc4f 100644 --- a/source/blender/compositor/operations/COM_MixOverlayOperation.cpp +++ b/source/blender/compositor/operations/COM_MixOverlayOperation.cpp @@ -27,7 +27,7 @@ MixOverlayOperation::MixOverlayOperation() : MixBaseOperation() /* pass */ } -void MixOverlayOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MixOverlayOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor1[4]; float inputColor2[4]; @@ -44,25 +44,25 @@ void MixOverlayOperation::executePixel(float *outputValue, float x, float y, Pix float valuem = 1.0f - value; if (inputColor1[0] < 0.5f) { - outputValue[0] = inputColor1[0] * (valuem + 2.0f * value * inputColor2[0]); + output[0] = inputColor1[0] * (valuem + 2.0f * value * inputColor2[0]); } else { - outputValue[0] = 1.0f - (valuem + 2.0f * value * (1.0f - inputColor2[0])) * (1.0f - inputColor1[0]); + output[0] = 1.0f - (valuem + 2.0f * value * (1.0f - inputColor2[0])) * (1.0f - inputColor1[0]); } if (inputColor1[1] < 0.5f) { - outputValue[1] = inputColor1[1] * (valuem + 2.0f * value * inputColor2[1]); + output[1] = inputColor1[1] * (valuem + 2.0f * value * inputColor2[1]); } else { - outputValue[1] = 1.0f - (valuem + 2.0f * value * (1.0f - inputColor2[1])) * (1.0f - inputColor1[1]); + output[1] = 1.0f - (valuem + 2.0f * value * (1.0f - inputColor2[1])) * (1.0f - inputColor1[1]); } if (inputColor1[2] < 0.5f) { - outputValue[2] = inputColor1[2] * (valuem + 2.0f * value * inputColor2[2]); + output[2] = inputColor1[2] * (valuem + 2.0f * value * inputColor2[2]); } else { - outputValue[2] = 1.0f - (valuem + 2.0f * value * (1.0f - inputColor2[2])) * (1.0f - inputColor1[2]); + output[2] = 1.0f - (valuem + 2.0f * value * (1.0f - inputColor2[2])) * (1.0f - inputColor1[2]); } - outputValue[3] = inputColor1[3]; + output[3] = inputColor1[3]; - clampIfNeeded(outputValue); + clampIfNeeded(output); } diff --git a/source/blender/compositor/operations/COM_MixOverlayOperation.h b/source/blender/compositor/operations/COM_MixOverlayOperation.h index d31396f471b..4f2c08ce95f 100644 --- a/source/blender/compositor/operations/COM_MixOverlayOperation.h +++ b/source/blender/compositor/operations/COM_MixOverlayOperation.h @@ -39,7 +39,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; #endif diff --git a/source/blender/compositor/operations/COM_MixSaturationOperation.cpp b/source/blender/compositor/operations/COM_MixSaturationOperation.cpp index 403dac57615..401ad8d4247 100644 --- a/source/blender/compositor/operations/COM_MixSaturationOperation.cpp +++ b/source/blender/compositor/operations/COM_MixSaturationOperation.cpp @@ -31,7 +31,7 @@ MixSaturationOperation::MixSaturationOperation() : MixBaseOperation() /* pass */ } -void MixSaturationOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MixSaturationOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor1[4]; float inputColor2[4]; @@ -51,9 +51,9 @@ void MixSaturationOperation::executePixel(float *outputValue, float x, float y, if (rS != 0.0f) { float colH, colS, colV; rgb_to_hsv(inputColor2[0], inputColor2[1], inputColor2[2], &colH, &colS, &colV); - hsv_to_rgb(rH, (valuem * rS + value * colS), rV, &outputValue[0], &outputValue[1], &outputValue[2]); + hsv_to_rgb(rH, (valuem * rS + value * colS), rV, &output[0], &output[1], &output[2]); } - outputValue[3] = inputColor1[3]; + output[3] = inputColor1[3]; - clampIfNeeded(outputValue); + clampIfNeeded(output); } diff --git a/source/blender/compositor/operations/COM_MixSaturationOperation.h b/source/blender/compositor/operations/COM_MixSaturationOperation.h index f89f03c0e18..c690db38daf 100644 --- a/source/blender/compositor/operations/COM_MixSaturationOperation.h +++ b/source/blender/compositor/operations/COM_MixSaturationOperation.h @@ -39,7 +39,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; #endif diff --git a/source/blender/compositor/operations/COM_MixScreenOperation.cpp b/source/blender/compositor/operations/COM_MixScreenOperation.cpp index 781bc87ece7..671ffd3303c 100644 --- a/source/blender/compositor/operations/COM_MixScreenOperation.cpp +++ b/source/blender/compositor/operations/COM_MixScreenOperation.cpp @@ -27,7 +27,7 @@ MixScreenOperation::MixScreenOperation() : MixBaseOperation() /* pass */ } -void MixScreenOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MixScreenOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor1[4]; float inputColor2[4]; @@ -43,11 +43,11 @@ void MixScreenOperation::executePixel(float *outputValue, float x, float y, Pixe } float valuem = 1.0f - value; - outputValue[0] = 1.0f - (valuem + value * (1.0f - inputColor2[0])) * (1.0f - inputColor1[0]); - outputValue[1] = 1.0f - (valuem + value * (1.0f - inputColor2[1])) * (1.0f - inputColor1[1]); - outputValue[2] = 1.0f - (valuem + value * (1.0f - inputColor2[2])) * (1.0f - inputColor1[2]); - outputValue[3] = inputColor1[3]; + output[0] = 1.0f - (valuem + value * (1.0f - inputColor2[0])) * (1.0f - inputColor1[0]); + output[1] = 1.0f - (valuem + value * (1.0f - inputColor2[1])) * (1.0f - inputColor1[1]); + output[2] = 1.0f - (valuem + value * (1.0f - inputColor2[2])) * (1.0f - inputColor1[2]); + output[3] = inputColor1[3]; - clampIfNeeded(outputValue); + clampIfNeeded(output); } diff --git a/source/blender/compositor/operations/COM_MixScreenOperation.h b/source/blender/compositor/operations/COM_MixScreenOperation.h index 843adc870f8..5ba3cf769bb 100644 --- a/source/blender/compositor/operations/COM_MixScreenOperation.h +++ b/source/blender/compositor/operations/COM_MixScreenOperation.h @@ -39,6 +39,6 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; #endif diff --git a/source/blender/compositor/operations/COM_MixSoftLightOperation.cpp b/source/blender/compositor/operations/COM_MixSoftLightOperation.cpp index b1374aa7f32..604881ae47f 100644 --- a/source/blender/compositor/operations/COM_MixSoftLightOperation.cpp +++ b/source/blender/compositor/operations/COM_MixSoftLightOperation.cpp @@ -27,7 +27,7 @@ MixSoftLightOperation::MixSoftLightOperation() : MixBaseOperation() /* pass */ } -void MixSoftLightOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) \ +void MixSoftLightOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) \ { float inputColor1[4]; float inputColor2[4]; @@ -48,11 +48,11 @@ void MixSoftLightOperation::executePixel(float *outputValue, float x, float y, P scg = 1.0f - (1.0f - inputColor2[1]) * (1.0f - inputColor1[1]); scb = 1.0f - (1.0f - inputColor2[2]) * (1.0f - inputColor1[2]); - outputValue[0] = valuem * (inputColor1[0]) + value * (((1.0f - inputColor1[0]) * inputColor2[0] * (inputColor1[0])) + (inputColor1[0] * scr)); - outputValue[1] = valuem * (inputColor1[1]) + value * (((1.0f - inputColor1[1]) * inputColor2[1] * (inputColor1[1])) + (inputColor1[1] * scg)); - outputValue[2] = valuem * (inputColor1[2]) + value * (((1.0f - inputColor1[2]) * inputColor2[2] * (inputColor1[2])) + (inputColor1[2] * scb)); - outputValue[3] = inputColor1[3]; + output[0] = valuem * (inputColor1[0]) + value * (((1.0f - inputColor1[0]) * inputColor2[0] * (inputColor1[0])) + (inputColor1[0] * scr)); + output[1] = valuem * (inputColor1[1]) + value * (((1.0f - inputColor1[1]) * inputColor2[1] * (inputColor1[1])) + (inputColor1[1] * scg)); + output[2] = valuem * (inputColor1[2]) + value * (((1.0f - inputColor1[2]) * inputColor2[2] * (inputColor1[2])) + (inputColor1[2] * scb)); + output[3] = inputColor1[3]; - clampIfNeeded(outputValue); + clampIfNeeded(output); } diff --git a/source/blender/compositor/operations/COM_MixSoftLightOperation.h b/source/blender/compositor/operations/COM_MixSoftLightOperation.h index 570cf2cb6ef..55f6a70791a 100644 --- a/source/blender/compositor/operations/COM_MixSoftLightOperation.h +++ b/source/blender/compositor/operations/COM_MixSoftLightOperation.h @@ -39,7 +39,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; #endif diff --git a/source/blender/compositor/operations/COM_MixSubtractOperation.cpp b/source/blender/compositor/operations/COM_MixSubtractOperation.cpp index f7b558e5c7a..a446dfe4e54 100644 --- a/source/blender/compositor/operations/COM_MixSubtractOperation.cpp +++ b/source/blender/compositor/operations/COM_MixSubtractOperation.cpp @@ -27,7 +27,7 @@ MixSubtractOperation::MixSubtractOperation() : MixBaseOperation() /* pass */ } -void MixSubtractOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MixSubtractOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor1[4]; float inputColor2[4]; @@ -40,11 +40,11 @@ void MixSubtractOperation::executePixel(float *outputValue, float x, float y, Pi if (this->useValueAlphaMultiply()) { value *= inputColor2[3]; } - outputValue[0] = inputColor1[0] - value * (inputColor2[0]); - outputValue[1] = inputColor1[1] - value * (inputColor2[1]); - outputValue[2] = inputColor1[2] - value * (inputColor2[2]); - outputValue[3] = inputColor1[3]; + output[0] = inputColor1[0] - value * (inputColor2[0]); + output[1] = inputColor1[1] - value * (inputColor2[1]); + output[2] = inputColor1[2] - value * (inputColor2[2]); + output[3] = inputColor1[3]; - clampIfNeeded(outputValue); + clampIfNeeded(output); } diff --git a/source/blender/compositor/operations/COM_MixSubtractOperation.h b/source/blender/compositor/operations/COM_MixSubtractOperation.h index a9198cf3400..046d8d4949b 100644 --- a/source/blender/compositor/operations/COM_MixSubtractOperation.h +++ b/source/blender/compositor/operations/COM_MixSubtractOperation.h @@ -39,7 +39,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; #endif diff --git a/source/blender/compositor/operations/COM_MixValueOperation.cpp b/source/blender/compositor/operations/COM_MixValueOperation.cpp index 8f8d3305ee9..caefdf024cc 100644 --- a/source/blender/compositor/operations/COM_MixValueOperation.cpp +++ b/source/blender/compositor/operations/COM_MixValueOperation.cpp @@ -31,7 +31,7 @@ MixValueOperation::MixValueOperation() : MixBaseOperation() /* pass */ } -void MixValueOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MixValueOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float inputColor1[4]; float inputColor2[4]; @@ -50,8 +50,8 @@ void MixValueOperation::executePixel(float *outputValue, float x, float y, Pixel float colH, colS, colV; rgb_to_hsv(inputColor1[0], inputColor1[1], inputColor1[2], &rH, &rS, &rV); rgb_to_hsv(inputColor2[0], inputColor2[1], inputColor2[2], &colH, &colS, &colV); - hsv_to_rgb(rH, rS, (valuem * rV + value * colV), &outputValue[0], &outputValue[1], &outputValue[2]); - outputValue[3] = inputColor1[3]; + hsv_to_rgb(rH, rS, (valuem * rV + value * colV), &output[0], &output[1], &output[2]); + output[3] = inputColor1[3]; - clampIfNeeded(outputValue); + clampIfNeeded(output); } diff --git a/source/blender/compositor/operations/COM_MixValueOperation.h b/source/blender/compositor/operations/COM_MixValueOperation.h index 06316afcd73..6c3f3ce8072 100644 --- a/source/blender/compositor/operations/COM_MixValueOperation.h +++ b/source/blender/compositor/operations/COM_MixValueOperation.h @@ -39,6 +39,6 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; #endif diff --git a/source/blender/compositor/operations/COM_MovieClipAttributeOperation.cpp b/source/blender/compositor/operations/COM_MovieClipAttributeOperation.cpp index 14d7fa7e649..0d2de47bc4f 100644 --- a/source/blender/compositor/operations/COM_MovieClipAttributeOperation.cpp +++ b/source/blender/compositor/operations/COM_MovieClipAttributeOperation.cpp @@ -33,7 +33,7 @@ MovieClipAttributeOperation::MovieClipAttributeOperation() : NodeOperation() this->m_attribute = MCA_X; } -void MovieClipAttributeOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void MovieClipAttributeOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { if (!this->m_valueSet) { float loc[2], scale, angle; @@ -61,10 +61,10 @@ void MovieClipAttributeOperation::executePixel(float *outputValue, float x, floa } this->m_valueSet = true; } - outputValue[0] = this->m_value; + output[0] = this->m_value; } -void MovieClipAttributeOperation::determineResolution(unsigned int resolution[], unsigned int preferredResolution[]) +void MovieClipAttributeOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]) { resolution[0] = preferredResolution[0]; resolution[1] = preferredResolution[1]; diff --git a/source/blender/compositor/operations/COM_MovieClipAttributeOperation.h b/source/blender/compositor/operations/COM_MovieClipAttributeOperation.h index 28028ab6fd4..f894626d534 100644 --- a/source/blender/compositor/operations/COM_MovieClipAttributeOperation.h +++ b/source/blender/compositor/operations/COM_MovieClipAttributeOperation.h @@ -51,8 +51,8 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); - void determineResolution(unsigned int resolution[], unsigned int preferredResolution[]); + void executePixel(float output[4], float x, float y, PixelSampler sampler); + void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]); void setMovieClip(MovieClip *clip) { this->m_clip = clip; } void setFramenumber(int framenumber) { this->m_framenumber = framenumber; } diff --git a/source/blender/compositor/operations/COM_MovieClipOperation.cpp b/source/blender/compositor/operations/COM_MovieClipOperation.cpp index ea267830b86..b73db74b061 100644 --- a/source/blender/compositor/operations/COM_MovieClipOperation.cpp +++ b/source/blender/compositor/operations/COM_MovieClipOperation.cpp @@ -76,7 +76,7 @@ void MovieClipOperation::deinitExecution() } } -void MovieClipOperation::determineResolution(unsigned int resolution[], unsigned int preferredResolution[]) +void MovieClipOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]) { resolution[0] = 0; resolution[1] = 0; @@ -91,21 +91,21 @@ void MovieClipOperation::determineResolution(unsigned int resolution[], unsigned } } -void MovieClipOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void MovieClipOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { if (this->m_movieClipBuffer == NULL || x < 0 || y < 0 || x >= this->getWidth() || y >= this->getHeight() ) { - zero_v4(color); + zero_v4(output); } else { switch (sampler) { case COM_PS_NEAREST: - neareast_interpolation_color(this->m_movieClipBuffer, NULL, color, x, y); + neareast_interpolation_color(this->m_movieClipBuffer, NULL, output, x, y); break; case COM_PS_BILINEAR: - bilinear_interpolation_color(this->m_movieClipBuffer, NULL, color, x, y); + bilinear_interpolation_color(this->m_movieClipBuffer, NULL, output, x, y); break; case COM_PS_BICUBIC: - bicubic_interpolation_color(this->m_movieClipBuffer, NULL, color, x, y); + bicubic_interpolation_color(this->m_movieClipBuffer, NULL, output, x, y); break; } } diff --git a/source/blender/compositor/operations/COM_MovieClipOperation.h b/source/blender/compositor/operations/COM_MovieClipOperation.h index 6ca10e2fa9d..7cce42f6727 100644 --- a/source/blender/compositor/operations/COM_MovieClipOperation.h +++ b/source/blender/compositor/operations/COM_MovieClipOperation.h @@ -47,7 +47,7 @@ protected: /** * Determine the output resolution. The resolution is retrieved from the Renderer */ - void determineResolution(unsigned int resolution[], unsigned int preferredResolution[]); + void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]); public: MovieClipOperation(); @@ -59,7 +59,7 @@ public: void setCacheFrame(bool value) { this->m_cacheFrame = value; } void setFramenumber(int framenumber) { this->m_framenumber = framenumber; } - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; #endif diff --git a/source/blender/compositor/operations/COM_MovieDistortionOperation.cpp b/source/blender/compositor/operations/COM_MovieDistortionOperation.cpp index 964d4352bc0..8150e3eda75 100644 --- a/source/blender/compositor/operations/COM_MovieDistortionOperation.cpp +++ b/source/blender/compositor/operations/COM_MovieDistortionOperation.cpp @@ -78,16 +78,16 @@ void MovieDistortionOperation::deinitExecution() } -void MovieDistortionOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void MovieDistortionOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { if (this->m_cache != NULL) { float u, v; this->m_cache->getUV(&this->m_movieClip->tracking, x, y, &u, &v); - this->m_inputOperation->read(color, u, v, sampler); + this->m_inputOperation->read(output, u, v, sampler); } else { - this->m_inputOperation->read(color, x, y, sampler); + this->m_inputOperation->read(output, x, y, sampler); } } diff --git a/source/blender/compositor/operations/COM_MovieDistortionOperation.h b/source/blender/compositor/operations/COM_MovieDistortionOperation.h index 8cd9e98da2d..a58349f9324 100644 --- a/source/blender/compositor/operations/COM_MovieDistortionOperation.h +++ b/source/blender/compositor/operations/COM_MovieDistortionOperation.h @@ -130,7 +130,7 @@ protected: public: MovieDistortionOperation(bool distortion); bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output); - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); void initExecution(); void deinitExecution(); diff --git a/source/blender/compositor/operations/COM_MultilayerImageOperation.cpp b/source/blender/compositor/operations/COM_MultilayerImageOperation.cpp index 27214acd0d4..af0d5161835 100644 --- a/source/blender/compositor/operations/COM_MultilayerImageOperation.cpp +++ b/source/blender/compositor/operations/COM_MultilayerImageOperation.cpp @@ -43,59 +43,56 @@ ImBuf *MultilayerBaseOperation::getImBuf() return NULL; } -void MultilayerColorOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void MultilayerColorOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { int yi = y; int xi = x; if (this->m_imageBuffer == NULL || xi < 0 || yi < 0 || (unsigned int)xi >= this->getWidth() || (unsigned int)yi >= this->getHeight() ) { - color[0] = 0.0f; - color[1] = 0.0f; - color[2] = 0.0f; - color[3] = 0.0f; + zero_v4(output); } else { if (this->m_numberOfChannels == 4) { switch (sampler) { case COM_PS_NEAREST: - neareast_interpolation_color(this->m_buffer, NULL, color, x, y); + neareast_interpolation_color(this->m_buffer, NULL, output, x, y); break; case COM_PS_BILINEAR: - bilinear_interpolation_color(this->m_buffer, NULL, color, x, y); + bilinear_interpolation_color(this->m_buffer, NULL, output, x, y); break; case COM_PS_BICUBIC: - bicubic_interpolation_color(this->m_buffer, NULL, color, x, y); + bicubic_interpolation_color(this->m_buffer, NULL, output, x, y); break; } } else { int offset = (yi * this->getWidth() + xi) * 3; - copy_v3_v3(color, &this->m_imageBuffer[offset]); + copy_v3_v3(output, &this->m_imageBuffer[offset]); } } } -void MultilayerValueOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void MultilayerValueOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { int yi = y; int xi = x; if (this->m_imageBuffer == NULL || xi < 0 || yi < 0 || (unsigned int)xi >= this->getWidth() || (unsigned int)yi >= this->getHeight() ) { - color[0] = 0.0f; + output[0] = 0.0f; } else { float result = this->m_imageBuffer[yi * this->getWidth() + xi]; - color[0] = result; + output[0] = result; } } -void MultilayerVectorOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void MultilayerVectorOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { int yi = y; int xi = x; if (this->m_imageBuffer == NULL || xi < 0 || yi < 0 || (unsigned int)xi >= this->getWidth() || (unsigned int)yi >= this->getHeight() ) { - color[0] = 0.0f; + output[0] = 0.0f; } else { int offset = (yi * this->getWidth() + xi) * 3; - copy_v3_v3(color, &this->m_imageBuffer[offset]); + copy_v3_v3(output, &this->m_imageBuffer[offset]); } } diff --git a/source/blender/compositor/operations/COM_MultilayerImageOperation.h b/source/blender/compositor/operations/COM_MultilayerImageOperation.h index 82bd8c455df..3c498e962b5 100644 --- a/source/blender/compositor/operations/COM_MultilayerImageOperation.h +++ b/source/blender/compositor/operations/COM_MultilayerImageOperation.h @@ -46,7 +46,7 @@ public: MultilayerColorOperation(int pass) : MultilayerBaseOperation(pass) { this->addOutputSocket(COM_DT_COLOR); } - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; class MultilayerValueOperation : public MultilayerBaseOperation { @@ -54,7 +54,7 @@ public: MultilayerValueOperation(int pass) : MultilayerBaseOperation(pass) { this->addOutputSocket(COM_DT_VALUE); } - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; class MultilayerVectorOperation : public MultilayerBaseOperation { @@ -62,7 +62,7 @@ public: MultilayerVectorOperation(int pass) : MultilayerBaseOperation(pass) { this->addOutputSocket(COM_DT_VECTOR); } - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; #endif diff --git a/source/blender/compositor/operations/COM_NormalizeOperation.cpp b/source/blender/compositor/operations/COM_NormalizeOperation.cpp index 02ea7f2b257..5f7ac6bb9ca 100644 --- a/source/blender/compositor/operations/COM_NormalizeOperation.cpp +++ b/source/blender/compositor/operations/COM_NormalizeOperation.cpp @@ -35,15 +35,14 @@ void NormalizeOperation::initExecution() NodeOperation::initMutex(); } -void NormalizeOperation::executePixel(float *color, int x, int y, void *data) +void NormalizeOperation::executePixel(float output[4], int x, int y, void *data) { /* using generic two floats struct to store x: min y: mult */ NodeTwoFloats *minmult = (NodeTwoFloats *)data; - float output[4]; this->m_imageReader->read(output, x, y, NULL); - color[0] = (output[0] - minmult->x) * minmult->y; + output[0] = (output[0] - minmult->x) * minmult->y; } void NormalizeOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_NormalizeOperation.h b/source/blender/compositor/operations/COM_NormalizeOperation.h index f36d69a3018..32f39a4d9ca 100644 --- a/source/blender/compositor/operations/COM_NormalizeOperation.h +++ b/source/blender/compositor/operations/COM_NormalizeOperation.h @@ -47,7 +47,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, int x, int y, void *data); + void executePixel(float output[4], int x, int y, void *data); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_OpenCLKernels.cl b/source/blender/compositor/operations/COM_OpenCLKernels.cl index 4f43650370d..7366db19444 100644 --- a/source/blender/compositor/operations/COM_OpenCLKernels.cl +++ b/source/blender/compositor/operations/COM_OpenCLKernels.cl @@ -78,7 +78,7 @@ __kernel void bokehBlurKernel(__read_only image2d_t boundingBox, __read_only ima __kernel void defocusKernel(__read_only image2d_t inputImage, __read_only image2d_t bokehImage, __read_only image2d_t inputSize, __write_only image2d_t output, int2 offsetInput, int2 offsetOutput, - int step, int maxBlur, float threshold, int2 dimension, int2 offset) + int step, int maxBlurScalar, float threshold, int2 dimension, int2 offset, float scalar) { float4 color = {1.0f, 0.0f, 0.0f, 1.0f}; int2 coords = {get_global_id(0), get_global_id(1)}; @@ -86,22 +86,24 @@ __kernel void defocusKernel(__read_only image2d_t inputImage, __read_only image2 const int2 realCoordinate = coords + offsetOutput; float4 readColor; + float4 tempColor; float4 bokeh; - float tempSize; + float size; float4 multiplier_accum = {1.0f, 1.0f, 1.0f, 1.0f}; float4 color_accum; - int minx = max(realCoordinate.s0 - maxBlur, 0); - int miny = max(realCoordinate.s1 - maxBlur, 0); - int maxx = min(realCoordinate.s0 + maxBlur, dimension.s0); - int maxy = min(realCoordinate.s1 + maxBlur, dimension.s1); + int minx = max(realCoordinate.s0 - maxBlurScalar, 0); + int miny = max(realCoordinate.s1 - maxBlurScalar, 0); + int maxx = min(realCoordinate.s0 + maxBlurScalar, dimension.s0); + int maxy = min(realCoordinate.s1 + maxBlurScalar, dimension.s1); { int2 inputCoordinate = realCoordinate - offsetInput; - float size = read_imagef(inputSize, SAMPLER_NEAREST, inputCoordinate).s0; + float size_center = read_imagef(inputSize, SAMPLER_NEAREST, inputCoordinate).s0 * scalar; color_accum = read_imagef(inputImage, SAMPLER_NEAREST, inputCoordinate); + readColor = color_accum; - if (size > threshold) { + if (size_center > threshold) { for (int ny = miny; ny < maxy; ny += step) { inputCoordinate.s1 = ny - offsetInput.s1; float dy = ny - realCoordinate.s1; @@ -109,13 +111,14 @@ __kernel void defocusKernel(__read_only image2d_t inputImage, __read_only image2 float dx = nx - realCoordinate.s0; if (dx != 0 || dy != 0) { inputCoordinate.s0 = nx - offsetInput.s0; - tempSize = read_imagef(inputSize, SAMPLER_NEAREST, inputCoordinate).s0; - if (tempSize > threshold) { - if (tempSize >= fabs(dx) && tempSize >= fabs(dy)) { - float2 uv = { 256.0f + dx * 255.0f / tempSize, 256.0f + dy * 255.0f / tempSize}; + size = read_imagef(inputSize, SAMPLER_NEAREST, inputCoordinate).s0 * scalar; + if (size > threshold) { + if (size >= fabs(dx) && size >= fabs(dy)) { + float2 uv = {256.0f + dx * 255.0f / size, + 256.0f + dy * 255.0f / size}; bokeh = read_imagef(bokehImage, SAMPLER_NEAREST, uv); - readColor = read_imagef(inputImage, SAMPLER_NEAREST, inputCoordinate); - color_accum += bokeh*readColor; + tempColor = read_imagef(inputImage, SAMPLER_NEAREST, inputCoordinate); + color_accum += bokeh * tempColor; multiplier_accum += bokeh; } } @@ -123,10 +126,20 @@ __kernel void defocusKernel(__read_only image2d_t inputImage, __read_only image2 } } } - } - color = color_accum * (1.0f / multiplier_accum); - write_imagef(output, coords, color); + color = color_accum * (1.0f / multiplier_accum); + + /* blend in out values over the threshold, otherwise we get sharp, ugly transitions */ + if ((size_center > threshold) && + (size_center < threshold * 2.0f)) + { + /* factor from 0-1 */ + float fac = (size_center - threshold) / threshold; + color = (readColor * (1.0f - fac)) + (color * fac); + } + + write_imagef(output, coords, color); + } } @@ -150,7 +163,7 @@ __kernel void dilateKernel(__read_only image2d_t inputImage, __write_only image const float deltaY = (realCoordinate.y - ny); for (nx = minXY.x, inputXy.x = nx - offsetInput.x; nx < maxXY.x ; nx ++, inputXy.x++) { const float deltaX = (realCoordinate.x - nx); - const float measuredDistance = deltaX*deltaX+deltaY*deltaY; + const float measuredDistance = deltaX * deltaX + deltaY * deltaY; if (measuredDistance <= distanceSquared) { value = max(value, read_imagef(inputImage, SAMPLER_NEAREST, inputXy).s0); } @@ -181,7 +194,7 @@ __kernel void erodeKernel(__read_only image2d_t inputImage, __write_only image2 for (nx = minXY.x, inputXy.x = nx - offsetInput.x; nx < maxXY.x ; nx ++, inputXy.x++) { const float deltaX = (realCoordinate.x - nx); const float deltaY = (realCoordinate.y - ny); - const float measuredDistance = deltaX*deltaX+deltaY*deltaY; + const float measuredDistance = deltaX * deltaX+deltaY * deltaY; if (measuredDistance <= distanceSquared) { value = min(value, read_imagef(inputImage, SAMPLER_NEAREST, inputXy).s0); } diff --git a/source/blender/compositor/operations/COM_OpenCLKernels.cl.h b/source/blender/compositor/operations/COM_OpenCLKernels.cl.h deleted file mode 100644 index cc18039c5b1..00000000000 --- a/source/blender/compositor/operations/COM_OpenCLKernels.cl.h +++ /dev/null @@ -1,237 +0,0 @@ -/* clkernelstoh output of file <COM_OpenCLKernels_cl> */ - -const char * clkernelstoh_COM_OpenCLKernels_cl = "/*\n" \ -" * Copyright 2011, Blender Foundation.\n" \ -" *\n" \ -" * This program is free software; you can redistribute it and/or\n" \ -" * modify it under the terms of the GNU General Public License\n" \ -" * as published by the Free Software Foundation; either version 2\n" \ -" * of the License, or (at your option) any later version.\n" \ -" *\n" \ -" * This program is distributed in the hope that it will be useful,\n" \ -" * but WITHOUT ANY WARRANTY; without even the implied warranty of\n" \ -" * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" \ -" * GNU General Public License for more details.\n" \ -" *\n" \ -" * You should have received a copy of the GNU General Public License\n" \ -" * along with this program; if not, write to the Free Software Foundation,\n" \ -" * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n" \ -" *\n" \ -" * Contributor:\n" \ -" * Jeroen Bakker\n" \ -" * Monique Dewanchand\n" \ -" */\n" \ -"\n" \ -"/// This file contains all opencl kernels for node-operation implementations\n" \ -"\n" \ -"// Global SAMPLERS\n" \ -"const sampler_t SAMPLER_NEAREST = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP_TO_EDGE | CLK_FILTER_NEAREST;\n" \ -"const sampler_t SAMPLER_NEAREST_CLAMP = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST;\n" \ -"\n" \ -"__constant const int2 zero = {0,0};\n" \ -"\n" \ -"// KERNEL --- BOKEH BLUR ---\n" \ -"__kernel void bokehBlurKernel(__read_only image2d_t boundingBox, __read_only image2d_t inputImage,\n" \ -" __read_only image2d_t bokehImage, __write_only image2d_t output,\n" \ -" int2 offsetInput, int2 offsetOutput, int radius, int step, int2 dimension, int2 offset)\n" \ -"{\n" \ -" int2 coords = {get_global_id(0), get_global_id(1)};\n" \ -" coords += offset;\n" \ -" float tempBoundingBox;\n" \ -" float4 color = {0.0f,0.0f,0.0f,0.0f};\n" \ -" float4 multiplyer = {0.0f,0.0f,0.0f,0.0f};\n" \ -" float4 bokeh;\n" \ -" const float radius2 = radius*2.0f;\n" \ -" const int2 realCoordinate = coords + offsetOutput;\n" \ -"\n" \ -" tempBoundingBox = read_imagef(boundingBox, SAMPLER_NEAREST, coords).s0;\n" \ -"\n" \ -" if (tempBoundingBox > 0.0f && radius > 0 ) {\n" \ -" const int2 bokehImageDim = get_image_dim(bokehImage);\n" \ -" const int2 bokehImageCenter = bokehImageDim/2;\n" \ -" const int2 minXY = max(realCoordinate - radius, zero);\n" \ -" const int2 maxXY = min(realCoordinate + radius, dimension);\n" \ -" int nx, ny;\n" \ -"\n" \ -" float2 uv;\n" \ -" int2 inputXy;\n" \ -"\n" \ -" for (ny = minXY.y, inputXy.y = ny - offsetInput.y ; ny < maxXY.y ; ny +=step, inputXy.y+=step) {\n" \ -" uv.y = ((realCoordinate.y-ny)/radius2)*bokehImageDim.y+bokehImageCenter.y;\n" \ -"\n" \ -" for (nx = minXY.x, inputXy.x = nx - offsetInput.x; nx < maxXY.x ; nx +=step, inputXy.x+=step) {\n" \ -" uv.x = ((realCoordinate.x-nx)/radius2)*bokehImageDim.x+bokehImageCenter.x;\n" \ -" bokeh = read_imagef(bokehImage, SAMPLER_NEAREST, uv);\n" \ -" color += bokeh * read_imagef(inputImage, SAMPLER_NEAREST, inputXy);\n" \ -" multiplyer += bokeh;\n" \ -" }\n" \ -" }\n" \ -" color /= multiplyer;\n" \ -"\n" \ -" } else {\n" \ -" int2 imageCoordinates = realCoordinate - offsetInput;\n" \ -" color = read_imagef(inputImage, SAMPLER_NEAREST, imageCoordinates);\n" \ -" }\n" \ -"\n" \ -" write_imagef(output, coords, color);\n" \ -"}\n" \ -"\n" \ -"//KERNEL --- DEFOCUS /VARIABLESIZEBOKEHBLUR ---\n" \ -"__kernel void defocusKernel(__read_only image2d_t inputImage, __read_only image2d_t bokehImage,\n" \ -" __read_only image2d_t inputSize,\n" \ -" __write_only image2d_t output, int2 offsetInput, int2 offsetOutput,\n" \ -" int step, int maxBlur, float threshold, int2 dimension, int2 offset)\n" \ -"{\n" \ -" float4 color = {1.0f, 0.0f, 0.0f, 1.0f};\n" \ -" int2 coords = {get_global_id(0), get_global_id(1)};\n" \ -" coords += offset;\n" \ -" const int2 realCoordinate = coords + offsetOutput;\n" \ -"\n" \ -" float4 readColor;\n" \ -" float4 bokeh;\n" \ -" float tempSize;\n" \ -" float4 multiplier_accum = {1.0f, 1.0f, 1.0f, 1.0f};\n" \ -" float4 color_accum;\n" \ -"\n" \ -" int minx = max(realCoordinate.s0 - maxBlur, 0);\n" \ -" int miny = max(realCoordinate.s1 - maxBlur, 0);\n" \ -" int maxx = min(realCoordinate.s0 + maxBlur, dimension.s0);\n" \ -" int maxy = min(realCoordinate.s1 + maxBlur, dimension.s1);\n" \ -"\n" \ -" {\n" \ -" int2 inputCoordinate = realCoordinate - offsetInput;\n" \ -" float size = read_imagef(inputSize, SAMPLER_NEAREST, inputCoordinate).s0;\n" \ -" color_accum = read_imagef(inputImage, SAMPLER_NEAREST, inputCoordinate);\n" \ -"\n" \ -" if (size > threshold) {\n" \ -" for (int ny = miny; ny < maxy; ny += step) {\n" \ -" inputCoordinate.s1 = ny - offsetInput.s1;\n" \ -" float dy = ny - realCoordinate.s1;\n" \ -" for (int nx = minx; nx < maxx; nx += step) {\n" \ -" float dx = nx - realCoordinate.s0;\n" \ -" if (dx != 0 || dy != 0) {\n" \ -" inputCoordinate.s0 = nx - offsetInput.s0;\n" \ -" tempSize = read_imagef(inputSize, SAMPLER_NEAREST, inputCoordinate).s0;\n" \ -" if (tempSize > threshold) {\n" \ -" if (tempSize >= fabs(dx) && tempSize >= fabs(dy)) {\n" \ -" float2 uv = { 256.0f + dx * 256.0f / tempSize, 256.0f + dy * 256.0f / tempSize};\n" \ -" bokeh = read_imagef(bokehImage, SAMPLER_NEAREST, uv);\n" \ -" readColor = read_imagef(inputImage, SAMPLER_NEAREST, inputCoordinate);\n" \ -" color_accum += bokeh*readColor;\n" \ -" multiplier_accum += bokeh;\n" \ -" }\n" \ -" }\n" \ -" }\n" \ -" }\n" \ -" }\n" \ -" }\n" \ -" }\n" \ -"\n" \ -" color = color_accum * (1.0f / multiplier_accum);\n" \ -" write_imagef(output, coords, color);\n" \ -"}\n" \ -"\n" \ -"\n" \ -"// KERNEL --- DILATE ---\n" \ -"__kernel void dilateKernel(__read_only image2d_t inputImage, __write_only image2d_t output,\n" \ -" int2 offsetInput, int2 offsetOutput, int scope, int distanceSquared, int2 dimension,\n" \ -" int2 offset)\n" \ -"{\n" \ -" int2 coords = {get_global_id(0), get_global_id(1)};\n" \ -" coords += offset;\n" \ -" const int2 realCoordinate = coords + offsetOutput;\n" \ -"\n" \ -" const int2 minXY = max(realCoordinate - scope, zero);\n" \ -" const int2 maxXY = min(realCoordinate + scope, dimension);\n" \ -"\n" \ -" float value = 0.0f;\n" \ -" int nx, ny;\n" \ -" int2 inputXy;\n" \ -"\n" \ -" for (ny = minXY.y, inputXy.y = ny - offsetInput.y ; ny < maxXY.y ; ny ++, inputXy.y++) {\n" \ -" const float deltaY = (realCoordinate.y - ny);\n" \ -" for (nx = minXY.x, inputXy.x = nx - offsetInput.x; nx < maxXY.x ; nx ++, inputXy.x++) {\n" \ -" const float deltaX = (realCoordinate.x - nx);\n" \ -" const float measuredDistance = deltaX*deltaX+deltaY*deltaY;\n" \ -" if (measuredDistance <= distanceSquared) {\n" \ -" value = max(value, read_imagef(inputImage, SAMPLER_NEAREST, inputXy).s0);\n" \ -" }\n" \ -" }\n" \ -" }\n" \ -"\n" \ -" float4 color = {value,0.0f,0.0f,0.0f};\n" \ -" write_imagef(output, coords, color);\n" \ -"}\n" \ -"\n" \ -"// KERNEL --- DILATE ---\n" \ -"__kernel void erodeKernel(__read_only image2d_t inputImage, __write_only image2d_t output,\n" \ -" int2 offsetInput, int2 offsetOutput, int scope, int distanceSquared, int2 dimension,\n" \ -" int2 offset)\n" \ -"{\n" \ -" int2 coords = {get_global_id(0), get_global_id(1)};\n" \ -" coords += offset;\n" \ -" const int2 realCoordinate = coords + offsetOutput;\n" \ -"\n" \ -" const int2 minXY = max(realCoordinate - scope, zero);\n" \ -" const int2 maxXY = min(realCoordinate + scope, dimension);\n" \ -"\n" \ -" float value = 1.0f;\n" \ -" int nx, ny;\n" \ -" int2 inputXy;\n" \ -"\n" \ -" for (ny = minXY.y, inputXy.y = ny - offsetInput.y ; ny < maxXY.y ; ny ++, inputXy.y++) {\n" \ -" for (nx = minXY.x, inputXy.x = nx - offsetInput.x; nx < maxXY.x ; nx ++, inputXy.x++) {\n" \ -" const float deltaX = (realCoordinate.x - nx);\n" \ -" const float deltaY = (realCoordinate.y - ny);\n" \ -" const float measuredDistance = deltaX*deltaX+deltaY*deltaY;\n" \ -" if (measuredDistance <= distanceSquared) {\n" \ -" value = min(value, read_imagef(inputImage, SAMPLER_NEAREST, inputXy).s0);\n" \ -" }\n" \ -" }\n" \ -" }\n" \ -"\n" \ -" float4 color = {value,0.0f,0.0f,0.0f};\n" \ -" write_imagef(output, coords, color);\n" \ -"}\n" \ -"\n" \ -"// KERNEL --- DIRECTIONAL BLUR ---\n" \ -"__kernel void directionalBlurKernel(__read_only image2d_t inputImage, __write_only image2d_t output,\n" \ -" int2 offsetOutput, int iterations, float scale, float rotation, float2 translate,\n" \ -" float2 center, int2 offset)\n" \ -"{\n" \ -" int2 coords = {get_global_id(0), get_global_id(1)};\n" \ -" coords += offset;\n" \ -" const int2 realCoordinate = coords + offsetOutput;\n" \ -"\n" \ -" float4 col;\n" \ -" float2 ltxy = translate;\n" \ -" float lsc = scale;\n" \ -" float lrot = rotation;\n" \ -"\n" \ -" col = read_imagef(inputImage, SAMPLER_NEAREST, realCoordinate);\n" \ -"\n" \ -" /* blur the image */\n" \ -" for (int i = 0; i < iterations; ++i) {\n" \ -" const float cs = cos(lrot), ss = sin(lrot);\n" \ -" const float isc = 1.0f / (1.0f + lsc);\n" \ -"\n" \ -" const float v = isc * (realCoordinate.s1 - center.s1) + ltxy.s1;\n" \ -" const float u = isc * (realCoordinate.s0 - center.s0) + ltxy.s0;\n" \ -" float2 uv = {\n" \ -" cs * u + ss * v + center.s0,\n" \ -" cs * v - ss * u + center.s1\n" \ -" };\n" \ -"\n" \ -" col += read_imagef(inputImage, SAMPLER_NEAREST_CLAMP, uv);\n" \ -"\n" \ -" /* double transformations */\n" \ -" ltxy += translate;\n" \ -" lrot += rotation;\n" \ -" lsc += scale;\n" \ -" }\n" \ -"\n" \ -" col *= (1.0f/(iterations+1));\n" \ -"\n" \ -" write_imagef(output, coords, col);\n" \ -"}\n" \ -"\0"; diff --git a/source/blender/compositor/operations/COM_PreviewOperation.cpp b/source/blender/compositor/operations/COM_PreviewOperation.cpp index a400402417b..aff374cdded 100644 --- a/source/blender/compositor/operations/COM_PreviewOperation.cpp +++ b/source/blender/compositor/operations/COM_PreviewOperation.cpp @@ -110,7 +110,7 @@ bool PreviewOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferO return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output); } -void PreviewOperation::determineResolution(unsigned int resolution[], unsigned int preferredResolution[]) +void PreviewOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]) { NodeOperation::determineResolution(resolution, preferredResolution); int width = resolution[0]; diff --git a/source/blender/compositor/operations/COM_PreviewOperation.h b/source/blender/compositor/operations/COM_PreviewOperation.h index 7183ea64fff..ffd80ff27af 100644 --- a/source/blender/compositor/operations/COM_PreviewOperation.h +++ b/source/blender/compositor/operations/COM_PreviewOperation.h @@ -45,7 +45,7 @@ public: const CompositorPriority getRenderPriority() const; void executeRegion(rcti *rect, unsigned int tileNumber); - void determineResolution(unsigned int resolution[], unsigned int preferredResolution[]); + void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]); void setbNode(bNode *node) { this->m_node = node; } bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output); bool isPreviewOperation() { return true; } diff --git a/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.cpp b/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.cpp index e28e77a5f5e..7e854f01213 100644 --- a/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.cpp +++ b/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.cpp @@ -47,7 +47,7 @@ void *ProjectorLensDistortionOperation::initializeTileData(rcti *rect) return buffer; } -void ProjectorLensDistortionOperation::executePixel(float *color, int x, int y, void *data) +void ProjectorLensDistortionOperation::executePixel(float output[4], int x, int y, void *data) { float inputValue[4]; const float height = this->getHeight(); @@ -56,12 +56,12 @@ void ProjectorLensDistortionOperation::executePixel(float *color, int x, int y, const float u = (x + 0.5f) / width; MemoryBuffer *inputBuffer = (MemoryBuffer *)data; inputBuffer->readCubic(inputValue, (u * width + this->m_kr2) - 0.5f, v * height - 0.5f); - color[0] = inputValue[0]; + output[0] = inputValue[0]; inputBuffer->read(inputValue, x, y); - color[1] = inputValue[1]; + output[1] = inputValue[1]; inputBuffer->readCubic(inputValue, (u * width - this->m_kr2) - 0.5f, v * height - 0.5f); - color[2] = inputValue[2]; - color[3] = 1.0f; + output[2] = inputValue[2]; + output[3] = 1.0f; } void ProjectorLensDistortionOperation::deinitExecution() @@ -78,11 +78,12 @@ bool ProjectorLensDistortionOperation::determineDependingAreaOfInterest(rcti *in newInput.ymin = input->ymin; newInput.xmin = input->xmin - this->m_kr2 - 2; newInput.xmax = input->xmax + this->m_kr2 + 2; - } else { - newInput.xmin = input->xmin - 7; //(0.25f*20*1)+2 == worse case dispersion + } + else { + newInput.xmin = input->xmin - 7; /* (0.25f * 20 * 1) + 2 == worse case dispersion */ newInput.ymin = input->ymin; newInput.ymax = input->ymax; - newInput.xmax = input->xmax + 7; //(0.25f*20*1)+2 == worse case dispersion + newInput.xmax = input->xmax + 7; /* (0.25f * 20 * 1) + 2 == worse case dispersion */ } return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output); } diff --git a/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.h b/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.h index ac64b35ed32..3c910815efc 100644 --- a/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.h +++ b/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.h @@ -44,7 +44,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, int x, int y, void *data); + void executePixel(float output[4], int x, int y, void *data); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_ReadBufferOperation.cpp b/source/blender/compositor/operations/COM_ReadBufferOperation.cpp index 2473ad8303e..a2385f79c04 100644 --- a/source/blender/compositor/operations/COM_ReadBufferOperation.cpp +++ b/source/blender/compositor/operations/COM_ReadBufferOperation.cpp @@ -36,7 +36,7 @@ void *ReadBufferOperation::initializeTileData(rcti *rect) return m_buffer; } -void ReadBufferOperation::determineResolution(unsigned int resolution[], unsigned int preferredResolution[]) +void ReadBufferOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]) { if (this->m_memoryProxy != NULL) { WriteBufferOperation *operation = this->m_memoryProxy->getWriteBufferOperation(); @@ -49,19 +49,19 @@ void ReadBufferOperation::determineResolution(unsigned int resolution[], unsigne } } } -void ReadBufferOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void ReadBufferOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { if (sampler == COM_PS_NEAREST) { - m_buffer->read(color, x, y); + m_buffer->read(output, x, y); } else { - m_buffer->readCubic(color, x, y); + m_buffer->readCubic(output, x, y); } } -void ReadBufferOperation::executePixel(float *color, float x, float y, float dx, float dy) +void ReadBufferOperation::executePixel(float output[4], float x, float y, float dx, float dy) { - m_buffer->readEWA(color, x, y, dx, dy); + m_buffer->readEWA(output, x, y, dx, dy); } bool ReadBufferOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) diff --git a/source/blender/compositor/operations/COM_ReadBufferOperation.h b/source/blender/compositor/operations/COM_ReadBufferOperation.h index f52b732b076..7958a4aee6b 100644 --- a/source/blender/compositor/operations/COM_ReadBufferOperation.h +++ b/source/blender/compositor/operations/COM_ReadBufferOperation.h @@ -36,11 +36,11 @@ public: int isBufferOperation() { return true; } void setMemoryProxy(MemoryProxy *memoryProxy) { this->m_memoryProxy = memoryProxy; } MemoryProxy *getMemoryProxy() { return this->m_memoryProxy; } - void determineResolution(unsigned int resolution[], unsigned int preferredResolution[]); + void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]); void *initializeTileData(rcti *rect); - void executePixel(float *color, float x, float y, PixelSampler sampler); - void executePixel(float *color, float x, float y, float dx, float dy); + void executePixel(float output[4], float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, float dx, float dy); const bool isReadBufferOperation() const { return true; } void setOffset(unsigned int offset) { this->m_offset = offset; } unsigned int getOffset() { return this->m_offset; } diff --git a/source/blender/compositor/operations/COM_RenderLayersAlphaProg.cpp b/source/blender/compositor/operations/COM_RenderLayersAlphaProg.cpp index 908c3d11b06..74cb506d264 100644 --- a/source/blender/compositor/operations/COM_RenderLayersAlphaProg.cpp +++ b/source/blender/compositor/operations/COM_RenderLayersAlphaProg.cpp @@ -27,7 +27,7 @@ RenderLayersAlphaProg::RenderLayersAlphaProg() : RenderLayersBaseProg(SCE_PASS_C this->addOutputSocket(COM_DT_VALUE); } -void RenderLayersAlphaProg::executePixel(float *output, float x, float y, PixelSampler sampler) +void RenderLayersAlphaProg::executePixel(float output[4], float x, float y, PixelSampler sampler) { int ix = x; int iy = y; diff --git a/source/blender/compositor/operations/COM_RenderLayersAlphaProg.h b/source/blender/compositor/operations/COM_RenderLayersAlphaProg.h index 1733f3bd3ba..36668bc9338 100644 --- a/source/blender/compositor/operations/COM_RenderLayersAlphaProg.h +++ b/source/blender/compositor/operations/COM_RenderLayersAlphaProg.h @@ -28,7 +28,7 @@ class RenderLayersAlphaProg : public RenderLayersBaseProg { public: RenderLayersAlphaProg(); - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; diff --git a/source/blender/compositor/operations/COM_RenderLayersBaseProg.cpp b/source/blender/compositor/operations/COM_RenderLayersBaseProg.cpp index a036e8e7231..a4015c6283f 100644 --- a/source/blender/compositor/operations/COM_RenderLayersBaseProg.cpp +++ b/source/blender/compositor/operations/COM_RenderLayersBaseProg.cpp @@ -69,7 +69,7 @@ void RenderLayersBaseProg::initExecution() } } -void RenderLayersBaseProg::executePixel(float *output, float x, float y, PixelSampler sampler) +void RenderLayersBaseProg::executePixel(float output[4], float x, float y, PixelSampler sampler) { int ix = x; int iy = y; @@ -100,7 +100,7 @@ void RenderLayersBaseProg::deinitExecution() this->m_inputBuffer = NULL; } -void RenderLayersBaseProg::determineResolution(unsigned int resolution[], unsigned int preferredResolution[]) +void RenderLayersBaseProg::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]) { Scene *sce = this->getScene(); Render *re = (sce) ? RE_GetRender(sce->id.name) : NULL; diff --git a/source/blender/compositor/operations/COM_RenderLayersBaseProg.h b/source/blender/compositor/operations/COM_RenderLayersBaseProg.h index ead1eb183b3..ea57d4bc421 100644 --- a/source/blender/compositor/operations/COM_RenderLayersBaseProg.h +++ b/source/blender/compositor/operations/COM_RenderLayersBaseProg.h @@ -73,7 +73,7 @@ protected: /** * Determine the output resolution. The resolution is retrieved from the Renderer */ - void determineResolution(unsigned int resolution[], unsigned int preferredResolution[]); + void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]); /** * retrieve the reference to the float buffer of the renderer. @@ -92,7 +92,7 @@ public: short getLayerId() { return this->m_layerId; } void initExecution(); void deinitExecution(); - void executePixel(float *output, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; #endif diff --git a/source/blender/compositor/operations/COM_RotateOperation.cpp b/source/blender/compositor/operations/COM_RotateOperation.cpp index a39828e4560..422c5b93484 100644 --- a/source/blender/compositor/operations/COM_RotateOperation.cpp +++ b/source/blender/compositor/operations/COM_RotateOperation.cpp @@ -68,14 +68,14 @@ inline void RotateOperation::ensureDegree() } -void RotateOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void RotateOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { ensureDegree(); const float dy = y - this->m_centerY; const float dx = x - this->m_centerX; const float nx = this->m_centerX + (this->m_cosine * dx + this->m_sine * dy); const float ny = this->m_centerY + (-this->m_sine * dx + this->m_cosine * dy); - this->m_imageSocket->read(color, nx, ny, sampler); + this->m_imageSocket->read(output, nx, ny, sampler); } bool RotateOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) diff --git a/source/blender/compositor/operations/COM_RotateOperation.h b/source/blender/compositor/operations/COM_RotateOperation.h index d011ac0ecc9..292f0743a44 100644 --- a/source/blender/compositor/operations/COM_RotateOperation.h +++ b/source/blender/compositor/operations/COM_RotateOperation.h @@ -38,7 +38,7 @@ private: public: RotateOperation(); bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output); - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); void initExecution(); void deinitExecution(); void setDoDegree2RadConversion(bool abool) { this->m_doDegree2RadConversion = abool; } diff --git a/source/blender/compositor/operations/COM_ScaleOperation.cpp b/source/blender/compositor/operations/COM_ScaleOperation.cpp index 642d1878049..276b2f54b6e 100644 --- a/source/blender/compositor/operations/COM_ScaleOperation.cpp +++ b/source/blender/compositor/operations/COM_ScaleOperation.cpp @@ -22,9 +22,12 @@ #include "COM_ScaleOperation.h" -#define USE_FORCE_BICUBIC +#define USE_FORCE_BILINEAR /* XXX - ignore input and use default from old compositor, - * could become an option like the transform node - campbell */ + * could become an option like the transform node - campbell + * + * note: use bilinear because bicubic makes fuzzy even when not scaling at all (1:1) + */ ScaleOperation::ScaleOperation() : NodeOperation() { @@ -54,10 +57,10 @@ void ScaleOperation::deinitExecution() } -void ScaleOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void ScaleOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { -#ifdef USE_FORCE_BICUBIC - sampler = COM_PS_BICUBIC; +#ifdef USE_FORCE_BILINEAR + sampler = COM_PS_BILINEAR; #endif float scaleX[4]; @@ -71,7 +74,7 @@ void ScaleOperation::executePixel(float *color, float x, float y, PixelSampler s float nx = this->m_centerX + (x - this->m_centerX) / scx; float ny = this->m_centerY + (y - this->m_centerY) / scy; - this->m_inputOperation->read(color, nx, ny, sampler); + this->m_inputOperation->read(output, nx, ny, sampler); } bool ScaleOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) @@ -124,10 +127,10 @@ void ScaleAbsoluteOperation::deinitExecution() } -void ScaleAbsoluteOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void ScaleAbsoluteOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { -#ifdef USE_FORCE_BICUBIC - sampler = COM_PS_BICUBIC; +#ifdef USE_FORCE_BILINEAR + sampler = COM_PS_BILINEAR; #endif float scaleX[4]; @@ -148,7 +151,7 @@ void ScaleAbsoluteOperation::executePixel(float *color, float x, float y, PixelS float nx = this->m_centerX + (x - this->m_centerX) / relativeXScale; float ny = this->m_centerY + (y - this->m_centerY) / relativeYScale; - this->m_inputOperation->read(color, nx, ny, sampler); + this->m_inputOperation->read(output, nx, ny, sampler); } bool ScaleAbsoluteOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) @@ -245,19 +248,19 @@ void ScaleFixedSizeOperation::deinitExecution() } -void ScaleFixedSizeOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void ScaleFixedSizeOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { -#ifdef USE_FORCE_BICUBIC - sampler = COM_PS_BICUBIC; +#ifdef USE_FORCE_BILINEAR + sampler = COM_PS_BILINEAR; #endif if (this->m_is_offset) { float nx = ((x - this->m_offsetX) * this->m_relX); float ny = ((y - this->m_offsetY) * this->m_relY); - this->m_inputOperation->read(color, nx, ny, sampler); + this->m_inputOperation->read(output, nx, ny, sampler); } else { - this->m_inputOperation->read(color, x * this->m_relX, y * this->m_relY, sampler); + this->m_inputOperation->read(output, x * this->m_relX, y * this->m_relY, sampler); } } @@ -273,7 +276,7 @@ bool ScaleFixedSizeOperation::determineDependingAreaOfInterest(rcti *input, Read return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output); } -void ScaleFixedSizeOperation::determineResolution(unsigned int resolution[], unsigned int preferredResolution[]) +void ScaleFixedSizeOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]) { unsigned int nr[2]; nr[0] = this->m_newWidth; diff --git a/source/blender/compositor/operations/COM_ScaleOperation.h b/source/blender/compositor/operations/COM_ScaleOperation.h index 075fb6e7064..4239ff063fb 100644 --- a/source/blender/compositor/operations/COM_ScaleOperation.h +++ b/source/blender/compositor/operations/COM_ScaleOperation.h @@ -35,7 +35,7 @@ private: public: ScaleOperation(); bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output); - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); void initExecution(); void deinitExecution(); @@ -51,7 +51,7 @@ class ScaleAbsoluteOperation : public NodeOperation { public: ScaleAbsoluteOperation(); bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output); - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); void initExecution(); void deinitExecution(); @@ -75,8 +75,8 @@ class ScaleFixedSizeOperation : public NodeOperation { public: ScaleFixedSizeOperation(); bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output); - void determineResolution(unsigned int resolution[], unsigned int preferredResolution[]); - void executePixel(float *color, float x, float y, PixelSampler sampler); + void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]); + void executePixel(float output[4], float x, float y, PixelSampler sampler); void initExecution(); void deinitExecution(); diff --git a/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cpp b/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cpp index f8628be3ff8..584d3049f6b 100644 --- a/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cpp +++ b/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cpp @@ -55,7 +55,7 @@ void *ScreenLensDistortionOperation::initializeTileData(rcti *rect) return buffer; } -void ScreenLensDistortionOperation::executePixel(float *outputColor, int x, int y, void *data) +void ScreenLensDistortionOperation::executePixel(float output[4], int x, int y, void *data) { const float height = this->getHeight(); const float width = this->getWidth(); @@ -126,18 +126,15 @@ void ScreenLensDistortionOperation::executePixel(float *outputColor, int x, int } } - if (dr) outputColor[0] = 2.0f * tc[0] / (float)dr; - if (dg) outputColor[1] = 2.0f * tc[1] / (float)dg; - if (db) outputColor[2] = 2.0f * tc[2] / (float)db; + if (dr) output[0] = 2.0f * tc[0] / (float)dr; + if (dg) output[1] = 2.0f * tc[1] / (float)dg; + if (db) output[2] = 2.0f * tc[2] / (float)db; /* set alpha */ - outputColor[3] = 1.0f; + output[3] = 1.0f; } else { - outputColor[0] = 0.0f; - outputColor[1] = 0.0f; - outputColor[2] = 0.0f; - outputColor[3] = 0.0f; + zero_v4(output); } } diff --git a/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.h b/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.h index a88717a116e..cfbdaacb41e 100644 --- a/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.h +++ b/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.h @@ -49,7 +49,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, int x, int y, void *data); + void executePixel(float output[4], int x, int y, void *data); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_SeparateChannelOperation.cpp b/source/blender/compositor/operations/COM_SeparateChannelOperation.cpp index 0b080dcc426..9fc266cce86 100644 --- a/source/blender/compositor/operations/COM_SeparateChannelOperation.cpp +++ b/source/blender/compositor/operations/COM_SeparateChannelOperation.cpp @@ -39,9 +39,9 @@ void SeparateChannelOperation::deinitExecution() } -void SeparateChannelOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void SeparateChannelOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float input[4]; this->m_inputOperation->read(input, x, y, sampler); - color[0] = input[this->m_channel]; + output[0] = input[this->m_channel]; } diff --git a/source/blender/compositor/operations/COM_SeparateChannelOperation.h b/source/blender/compositor/operations/COM_SeparateChannelOperation.h index 01fee3ca57d..f964df5df02 100644 --- a/source/blender/compositor/operations/COM_SeparateChannelOperation.h +++ b/source/blender/compositor/operations/COM_SeparateChannelOperation.h @@ -31,7 +31,7 @@ private: int m_channel; public: SeparateChannelOperation(); - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); void initExecution(); void deinitExecution(); diff --git a/source/blender/compositor/operations/COM_SetAlphaOperation.cpp b/source/blender/compositor/operations/COM_SetAlphaOperation.cpp index 0f707473f9d..fc6cfa455f3 100644 --- a/source/blender/compositor/operations/COM_SetAlphaOperation.cpp +++ b/source/blender/compositor/operations/COM_SetAlphaOperation.cpp @@ -38,14 +38,14 @@ void SetAlphaOperation::initExecution() this->m_inputAlpha = getInputSocketReader(1); } -void SetAlphaOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void SetAlphaOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float alphaInput[4]; - this->m_inputColor->read(outputValue, x, y, sampler); + this->m_inputColor->read(output, x, y, sampler); this->m_inputAlpha->read(alphaInput, x, y, sampler); - outputValue[3] = alphaInput[0]; + output[3] = alphaInput[0]; } void SetAlphaOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_SetAlphaOperation.h b/source/blender/compositor/operations/COM_SetAlphaOperation.h index 3d8eb5b9493..1ec4a7aeacf 100644 --- a/source/blender/compositor/operations/COM_SetAlphaOperation.h +++ b/source/blender/compositor/operations/COM_SetAlphaOperation.h @@ -43,7 +43,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); void initExecution(); void deinitExecution(); diff --git a/source/blender/compositor/operations/COM_SetColorOperation.cpp b/source/blender/compositor/operations/COM_SetColorOperation.cpp index 0665073840c..7aa2a8a27cd 100644 --- a/source/blender/compositor/operations/COM_SetColorOperation.cpp +++ b/source/blender/compositor/operations/COM_SetColorOperation.cpp @@ -27,15 +27,15 @@ SetColorOperation::SetColorOperation() : NodeOperation() this->addOutputSocket(COM_DT_COLOR); } -void SetColorOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void SetColorOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { - outputValue[0] = this->m_channel1; - outputValue[1] = this->m_channel2; - outputValue[2] = this->m_channel3; - outputValue[3] = this->m_channel4; + output[0] = this->m_channel1; + output[1] = this->m_channel2; + output[2] = this->m_channel3; + output[3] = this->m_channel4; } -void SetColorOperation::determineResolution(unsigned int resolution[], unsigned int preferredResolution[]) +void SetColorOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]) { resolution[0] = preferredResolution[0]; resolution[1] = preferredResolution[1]; diff --git a/source/blender/compositor/operations/COM_SetColorOperation.h b/source/blender/compositor/operations/COM_SetColorOperation.h index 72708800f1e..374390b45a4 100644 --- a/source/blender/compositor/operations/COM_SetColorOperation.h +++ b/source/blender/compositor/operations/COM_SetColorOperation.h @@ -61,9 +61,9 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); - void determineResolution(unsigned int resolution[], unsigned int preferredResolution[]); + void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]); const bool isSetOperation() const { return true; } }; diff --git a/source/blender/compositor/operations/COM_SetSamplerOperation.cpp b/source/blender/compositor/operations/COM_SetSamplerOperation.cpp index f7c1ef8f6f5..343b5973f7e 100644 --- a/source/blender/compositor/operations/COM_SetSamplerOperation.cpp +++ b/source/blender/compositor/operations/COM_SetSamplerOperation.cpp @@ -37,7 +37,7 @@ void SetSamplerOperation::deinitExecution() this->m_reader = NULL; } -void SetSamplerOperation::executePixel(float *output, float x, float y, PixelSampler sampler) +void SetSamplerOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { this->m_reader->read(output, x, y, this->m_sampler); } diff --git a/source/blender/compositor/operations/COM_SetSamplerOperation.h b/source/blender/compositor/operations/COM_SetSamplerOperation.h index 7b53cd8d38e..c94e174fc81 100644 --- a/source/blender/compositor/operations/COM_SetSamplerOperation.h +++ b/source/blender/compositor/operations/COM_SetSamplerOperation.h @@ -44,7 +44,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); void initExecution(); void deinitExecution(); }; diff --git a/source/blender/compositor/operations/COM_SetValueOperation.cpp b/source/blender/compositor/operations/COM_SetValueOperation.cpp index d88257226f5..c5ce3e4c09c 100644 --- a/source/blender/compositor/operations/COM_SetValueOperation.cpp +++ b/source/blender/compositor/operations/COM_SetValueOperation.cpp @@ -27,12 +27,12 @@ SetValueOperation::SetValueOperation() : NodeOperation() this->addOutputSocket(COM_DT_VALUE); } -void SetValueOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void SetValueOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { - outputValue[0] = this->m_value; + output[0] = this->m_value; } -void SetValueOperation::determineResolution(unsigned int resolution[], unsigned int preferredResolution[]) +void SetValueOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]) { resolution[0] = preferredResolution[0]; resolution[1] = preferredResolution[1]; diff --git a/source/blender/compositor/operations/COM_SetValueOperation.h b/source/blender/compositor/operations/COM_SetValueOperation.h index a2c3e8eaa0b..3ddc667bc7e 100644 --- a/source/blender/compositor/operations/COM_SetValueOperation.h +++ b/source/blender/compositor/operations/COM_SetValueOperation.h @@ -46,8 +46,8 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); - void determineResolution(unsigned int resolution[], unsigned int preferredResolution[]); + void executePixel(float output[4], float x, float y, PixelSampler sampler); + void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]); const bool isSetOperation() const { return true; } }; diff --git a/source/blender/compositor/operations/COM_SetVectorOperation.cpp b/source/blender/compositor/operations/COM_SetVectorOperation.cpp index 651add0453f..d5c665e81f5 100644 --- a/source/blender/compositor/operations/COM_SetVectorOperation.cpp +++ b/source/blender/compositor/operations/COM_SetVectorOperation.cpp @@ -28,15 +28,15 @@ SetVectorOperation::SetVectorOperation() : NodeOperation() this->addOutputSocket(COM_DT_VECTOR); } -void SetVectorOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void SetVectorOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { - outputValue[0] = this->m_x; - outputValue[1] = this->m_y; - outputValue[2] = this->m_z; - outputValue[3] = this->m_w; + output[0] = this->m_x; + output[1] = this->m_y; + output[2] = this->m_z; + output[3] = this->m_w; } -void SetVectorOperation::determineResolution(unsigned int resolution[], unsigned int preferredResolution[]) +void SetVectorOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]) { resolution[0] = preferredResolution[0]; resolution[1] = preferredResolution[1]; diff --git a/source/blender/compositor/operations/COM_SetVectorOperation.h b/source/blender/compositor/operations/COM_SetVectorOperation.h index 0868213a109..e9d6a163e9f 100644 --- a/source/blender/compositor/operations/COM_SetVectorOperation.h +++ b/source/blender/compositor/operations/COM_SetVectorOperation.h @@ -54,9 +54,9 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); - void determineResolution(unsigned int resolution[], unsigned int preferredResolution[]); + void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]); const bool isSetOperation() const { return true; } void setVector(float vector[3]) { diff --git a/source/blender/compositor/operations/COM_SocketProxyOperation.cpp b/source/blender/compositor/operations/COM_SocketProxyOperation.cpp index 0e670d9268e..ac2cee8eb44 100644 --- a/source/blender/compositor/operations/COM_SocketProxyOperation.cpp +++ b/source/blender/compositor/operations/COM_SocketProxyOperation.cpp @@ -39,9 +39,9 @@ void SocketProxyOperation::deinitExecution() this->m_inputOperation = NULL; } -void SocketProxyOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void SocketProxyOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { if (this->m_inputOperation) { - this->m_inputOperation->read(color, x, y, sampler); + this->m_inputOperation->read(output, x, y, sampler); } } diff --git a/source/blender/compositor/operations/COM_SocketProxyOperation.h b/source/blender/compositor/operations/COM_SocketProxyOperation.h index 219483aa92d..a37384455ca 100644 --- a/source/blender/compositor/operations/COM_SocketProxyOperation.h +++ b/source/blender/compositor/operations/COM_SocketProxyOperation.h @@ -30,7 +30,7 @@ private: SocketReader *m_inputOperation; public: SocketProxyOperation(DataType type); - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); void initExecution(); void deinitExecution(); diff --git a/source/blender/compositor/operations/COM_TextureOperation.cpp b/source/blender/compositor/operations/COM_TextureOperation.cpp index 5a32bcb76ac..f8d6c0cfc01 100644 --- a/source/blender/compositor/operations/COM_TextureOperation.cpp +++ b/source/blender/compositor/operations/COM_TextureOperation.cpp @@ -53,7 +53,7 @@ void TextureBaseOperation::deinitExecution() this->m_inputOffset = NULL; } -void TextureBaseOperation::determineResolution(unsigned int resolution[], unsigned int preferredResolution[]) +void TextureBaseOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]) { if (preferredResolution[0] == 0 || preferredResolution[1] == 0) { int width = this->m_rd->xsch * this->m_rd->size / 100; @@ -67,16 +67,16 @@ void TextureBaseOperation::determineResolution(unsigned int resolution[], unsign } } -void TextureAlphaOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void TextureAlphaOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { - TextureBaseOperation::executePixel(color, x, y, sampler); - color[0] = color[3]; - color[1] = 0.0f; - color[2] = 0.0f; - color[3] = 0.0f; + TextureBaseOperation::executePixel(output, x, y, sampler); + output[0] = output[3]; + output[1] = 0.0f; + output[2] = 0.0f; + output[3] = 0.0f; } -void TextureBaseOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void TextureBaseOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { TexResult texres = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0, NULL}; float textureSize[4]; @@ -98,14 +98,16 @@ void TextureBaseOperation::executePixel(float *color, float x, float y, PixelSam retval = multitex_ext(this->m_texture, vec, NULL, NULL, 0, &texres); if (texres.talpha) - color[3] = texres.ta; + output[3] = texres.ta; else - color[3] = texres.tin; + output[3] = texres.tin; if ((retval & TEX_RGB)) { - color[0] = texres.tr; - color[1] = texres.tg; - color[2] = texres.tb; + output[0] = texres.tr; + output[1] = texres.tg; + output[2] = texres.tb; + } + else { + output[0] = output[1] = output[2] = output[3]; } - else color[0] = color[1] = color[2] = color[3]; } diff --git a/source/blender/compositor/operations/COM_TextureOperation.h b/source/blender/compositor/operations/COM_TextureOperation.h index 3631f8d24ff..f8435ecdaa2 100644 --- a/source/blender/compositor/operations/COM_TextureOperation.h +++ b/source/blender/compositor/operations/COM_TextureOperation.h @@ -51,7 +51,7 @@ protected: /** * Determine the output resolution. The resolution is retrieved from the Renderer */ - void determineResolution(unsigned int resolution[], unsigned int preferredResolution[]); + void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]); /** * Constructor @@ -59,7 +59,7 @@ protected: TextureBaseOperation(); public: - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); void setTexture(Tex *texture) { this->m_texture = texture; } void initExecution(); @@ -75,7 +75,7 @@ public: class TextureAlphaOperation : public TextureBaseOperation { public: TextureAlphaOperation(); - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; diff --git a/source/blender/compositor/operations/COM_TonemapOperation.cpp b/source/blender/compositor/operations/COM_TonemapOperation.cpp index 0dc30ebfcb9..2d944b70f75 100644 --- a/source/blender/compositor/operations/COM_TonemapOperation.cpp +++ b/source/blender/compositor/operations/COM_TonemapOperation.cpp @@ -41,11 +41,10 @@ void TonemapOperation::initExecution() NodeOperation::initMutex(); } -void TonemapOperation::executePixel(float *color, int x, int y, void *data) +void TonemapOperation::executePixel(float output[4], int x, int y, void *data) { AvgLogLum *avg = (AvgLogLum *)data; - float output[4]; this->m_imageReader->read(output, x, y, NULL); mul_v3_fl(output, avg->al); float dr = output[0] + this->m_data->offset; @@ -56,14 +55,12 @@ void TonemapOperation::executePixel(float *color, int x, int y, void *data) output[2] /= ((db == 0.f) ? 1.0f : db); const float igm = avg->igm; if (igm != 0.0f) { - output[0] = powf(MAX2(output[0], 0.0f), igm); - output[1] = powf(MAX2(output[1], 0.0f), igm); - output[2] = powf(MAX2(output[2], 0.0f), igm); + output[0] = powf(max(output[0], 0.0f), igm); + output[1] = powf(max(output[1], 0.0f), igm); + output[2] = powf(max(output[2], 0.0f), igm); } - - copy_v4_v4(color, output); } -void PhotoreceptorTonemapOperation::executePixel(float *color, int x, int y, void *data) +void PhotoreceptorTonemapOperation::executePixel(float output[4], int x, int y, void *data) { AvgLogLum *avg = (AvgLogLum *)data; NodeTonemap *ntm = this->m_data; @@ -72,7 +69,6 @@ void PhotoreceptorTonemapOperation::executePixel(float *color, int x, int y, voi const float m = (ntm->m > 0.0f) ? ntm->m : (0.3f + 0.7f * powf(avg->auto_key, 1.4f)); const float ic = 1.0f - ntm->c, ia = 1.0f - ntm->a; - float output[4]; this->m_imageReader->read(output, x, y, NULL); const float L = rgb_to_luma_y(output); @@ -88,8 +84,6 @@ void PhotoreceptorTonemapOperation::executePixel(float *color, int x, int y, voi I_g = avg->cav[2] + ic * (avg->lav - avg->cav[2]); I_a = I_l + ia * (I_g - I_l); output[2] /= (output[2] + powf(f * I_a, m)); - - copy_v4_v4(color, output); } void TonemapOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_TonemapOperation.h b/source/blender/compositor/operations/COM_TonemapOperation.h index 4e591276c76..843bf89dc92 100644 --- a/source/blender/compositor/operations/COM_TonemapOperation.h +++ b/source/blender/compositor/operations/COM_TonemapOperation.h @@ -64,7 +64,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, int x, int y, void *data); + void executePixel(float output[4], int x, int y, void *data); /** * Initialize the execution @@ -97,7 +97,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, int x, int y, void *data); + void executePixel(float output[4], int x, int y, void *data); }; #endif diff --git a/source/blender/compositor/operations/COM_TrackPositionOperation.cpp b/source/blender/compositor/operations/COM_TrackPositionOperation.cpp index 869ec71614a..d41d1c128da 100644 --- a/source/blender/compositor/operations/COM_TrackPositionOperation.cpp +++ b/source/blender/compositor/operations/COM_TrackPositionOperation.cpp @@ -101,17 +101,17 @@ void TrackPositionOperation::initExecution() } } -void TrackPositionOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +void TrackPositionOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { - outputValue[0] = this->m_markerPos[this->m_axis] - this->m_relativePos[this->m_axis]; + output[0] = this->m_markerPos[this->m_axis] - this->m_relativePos[this->m_axis]; if (this->m_axis == 0) - outputValue[0] *= this->m_width; + output[0] *= this->m_width; else - outputValue[0] *= this->m_height; + output[0] *= this->m_height; } -void TrackPositionOperation::determineResolution(unsigned int resolution[], unsigned int preferredResolution[]) +void TrackPositionOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]) { resolution[0] = preferredResolution[0]; resolution[1] = preferredResolution[1]; diff --git a/source/blender/compositor/operations/COM_TrackPositionOperation.h b/source/blender/compositor/operations/COM_TrackPositionOperation.h index fe4f703d26c..3a9e6f25cd9 100644 --- a/source/blender/compositor/operations/COM_TrackPositionOperation.h +++ b/source/blender/compositor/operations/COM_TrackPositionOperation.h @@ -60,7 +60,7 @@ protected: /** * Determine the output resolution. The resolution is retrieved from the Renderer */ - void determineResolution(unsigned int resolution[], unsigned int preferredResolution[]); + void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]); public: TrackPositionOperation(); @@ -75,7 +75,7 @@ public: void initExecution(); - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); const bool isSetOperation() const { return true; } }; diff --git a/source/blender/compositor/operations/COM_TranslateOperation.cpp b/source/blender/compositor/operations/COM_TranslateOperation.cpp index fda50ac24d1..761f55a1455 100644 --- a/source/blender/compositor/operations/COM_TranslateOperation.cpp +++ b/source/blender/compositor/operations/COM_TranslateOperation.cpp @@ -50,10 +50,10 @@ void TranslateOperation::deinitExecution() } -void TranslateOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void TranslateOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { ensureDelta(); - this->m_inputOperation->read(color, x - this->getDeltaX(), y - this->getDeltaY(), sampler); + this->m_inputOperation->read(output, x - this->getDeltaX(), y - this->getDeltaY(), sampler); } bool TranslateOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) diff --git a/source/blender/compositor/operations/COM_TranslateOperation.h b/source/blender/compositor/operations/COM_TranslateOperation.h index 83e3befdfeb..faaadb1ced2 100644 --- a/source/blender/compositor/operations/COM_TranslateOperation.h +++ b/source/blender/compositor/operations/COM_TranslateOperation.h @@ -36,7 +36,7 @@ private: public: TranslateOperation(); bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output); - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); void initExecution(); void deinitExecution(); diff --git a/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp b/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp index 66d7e9d4d99..7ccc91072bc 100644 --- a/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp +++ b/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp @@ -45,6 +45,7 @@ VariableSizeBokehBlurOperation::VariableSizeBokehBlurOperation() : NodeOperation this->m_inputSizeProgram = NULL; this->m_maxBlur = 32.0f; this->m_threshold = 1.0f; + this->m_do_size_scale = false; #ifdef COM_DEFOCUS_SEARCH this->m_inputSearchProgram = NULL; #endif @@ -63,47 +64,57 @@ void VariableSizeBokehBlurOperation::initExecution() } struct VariableSizeBokehBlurTileData { - MemoryBuffer* color; - MemoryBuffer* bokeh; - MemoryBuffer* size; - int maxBlur; + MemoryBuffer *color; + MemoryBuffer *bokeh; + MemoryBuffer *size; + int maxBlurScalar; }; void *VariableSizeBokehBlurOperation::initializeTileData(rcti *rect) { VariableSizeBokehBlurTileData *data = new VariableSizeBokehBlurTileData(); - data->color = (MemoryBuffer*)this->m_inputProgram->initializeTileData(rect); - data->bokeh = (MemoryBuffer*)this->m_inputBokehProgram->initializeTileData(rect); - data->size = (MemoryBuffer*)this->m_inputSizeProgram->initializeTileData(rect); + data->color = (MemoryBuffer *)this->m_inputProgram->initializeTileData(rect); + data->bokeh = (MemoryBuffer *)this->m_inputBokehProgram->initializeTileData(rect); + data->size = (MemoryBuffer *)this->m_inputSizeProgram->initializeTileData(rect); rcti rect2; - this->determineDependingAreaOfInterest(rect, (ReadBufferOperation*)this->m_inputSizeProgram, &rect2); - data->maxBlur = (int)data->size->getMaximumValue(&rect2); - CLAMP(data->maxBlur, 1.0f, this->m_maxBlur); + this->determineDependingAreaOfInterest(rect, (ReadBufferOperation *)this->m_inputSizeProgram, &rect2); + + const float max_dim = max(m_width, m_height); + const float scalar = this->m_do_size_scale ? (max_dim / 100.0f) : 1.0f; + + data->maxBlurScalar = (int)(data->size->getMaximumValue(&rect2) * scalar); + CLAMP(data->maxBlurScalar, 1.0f, this->m_maxBlur); return data; } void VariableSizeBokehBlurOperation::deinitializeTileData(rcti *rect, void *data) { - VariableSizeBokehBlurTileData* result = (VariableSizeBokehBlurTileData*)data; + VariableSizeBokehBlurTileData *result = (VariableSizeBokehBlurTileData *)data; delete result; } -void VariableSizeBokehBlurOperation::executePixel(float *color, int x, int y, void *data) +void VariableSizeBokehBlurOperation::executePixel(float output[4], int x, int y, void *data) { - VariableSizeBokehBlurTileData* tileData = (VariableSizeBokehBlurTileData*)data; - MemoryBuffer* inputProgramBuffer = tileData->color; - MemoryBuffer* inputBokehBuffer = tileData->bokeh; - MemoryBuffer* inputSizeBuffer = tileData->size; - float* inputSizeFloatBuffer = inputSizeBuffer->getBuffer(); - float* inputProgramFloatBuffer = inputProgramBuffer->getBuffer(); + VariableSizeBokehBlurTileData *tileData = (VariableSizeBokehBlurTileData *)data; + MemoryBuffer *inputProgramBuffer = tileData->color; + MemoryBuffer *inputBokehBuffer = tileData->bokeh; + MemoryBuffer *inputSizeBuffer = tileData->size; + float *inputSizeFloatBuffer = inputSizeBuffer->getBuffer(); + float *inputProgramFloatBuffer = inputProgramBuffer->getBuffer(); float readColor[4]; float bokeh[4]; float tempSize[4]; - float multiplier_accum[4] = {0.0f, 0.0f, 0.0f, 0.0f}; - float color_accum[4] = {0.0f, 0.0f, 0.0f, 0.0f}; - int maxBlur = tileData->maxBlur; + float multiplier_accum[4]; + float color_accum[4]; + + const float max_dim = max(m_width, m_height); + const float scalar = this->m_do_size_scale ? (max_dim / 100.0f) : 1.0f; + int maxBlurScalar = tileData->maxBlurScalar; + + BLI_assert(inputBokehBuffer->getWidth() == COM_BLUR_BOKEH_PIXELS); + BLI_assert(inputBokehBuffer->getHeight() == COM_BLUR_BOKEH_PIXELS); #ifdef COM_DEFOCUS_SEARCH float search[4]; @@ -113,37 +124,36 @@ void VariableSizeBokehBlurOperation::executePixel(float *color, int x, int y, vo int maxx = search[2]; int maxy = search[3]; #else - int minx = MAX2(x - maxBlur, 0.0f); - int miny = MAX2(y - maxBlur, 0.0f); - int maxx = MIN2(x + maxBlur, m_width); - int maxy = MIN2(y + maxBlur, m_height); + int minx = max(x - maxBlurScalar, 0); + int miny = max(y - maxBlurScalar, 0); + int maxx = min(x + maxBlurScalar, (int)m_width); + int maxy = min(y + maxBlurScalar, (int)m_height); #endif { inputSizeBuffer->readNoCheck(tempSize, x, y); inputProgramBuffer->readNoCheck(readColor, x, y); - add_v4_v4(color_accum, readColor); - add_v4_fl(multiplier_accum, 1.0f); - float sizeCenter = tempSize[0]; + copy_v4_v4(color_accum, readColor); + copy_v4_fl(multiplier_accum, 1.0f); + float size_center = tempSize[0] * scalar; - const int addXStep = QualityStepHelper::getStep()*COM_NUMBER_OF_CHANNELS; + const int addXStep = QualityStepHelper::getStep() * COM_NUMBER_OF_CHANNELS; - if (sizeCenter > this->m_threshold) { + if (size_center > this->m_threshold) { for (int ny = miny; ny < maxy; ny += QualityStepHelper::getStep()) { float dy = ny - y; int offsetNy = ny * inputSizeBuffer->getWidth() * COM_NUMBER_OF_CHANNELS; - int offsetNxNy = offsetNy + (minx*COM_NUMBER_OF_CHANNELS); + int offsetNxNy = offsetNy + (minx * COM_NUMBER_OF_CHANNELS); for (int nx = minx; nx < maxx; nx += QualityStepHelper::getStep()) { - if (nx != x || ny != y) - { - float size = inputSizeFloatBuffer[offsetNxNy]; + if (nx != x || ny != y) { + float size = inputSizeFloatBuffer[offsetNxNy] * scalar; if (size > this->m_threshold) { - float fsize = fabsf(size); float dx = nx - x; - if (fsize > fabsf(dx) && fsize > fabsf(dy)) { - float u = (256.0f + (dx/size) * 255.0f); - float v = (256.0f + (dy/size) * 255.0f); - inputBokehBuffer->readNoCheck(bokeh, u, v); + if (size > fabsf(dx) && size > fabsf(dy)) { + float uv[2] = { + (float)(COM_BLUR_BOKEH_PIXELS / 2) + (dx / size) * (float)((COM_BLUR_BOKEH_PIXELS / 2) - 1), + (float)(COM_BLUR_BOKEH_PIXELS / 2) + (dy / size) * (float)((COM_BLUR_BOKEH_PIXELS / 2) - 1)}; + inputBokehBuffer->readNoCheck(bokeh, uv[0], uv[1]); madd_v4_v4v4(color_accum, bokeh, &inputProgramFloatBuffer[offsetNxNy]); add_v4_v4(multiplier_accum, bokeh); } @@ -154,15 +164,24 @@ void VariableSizeBokehBlurOperation::executePixel(float *color, int x, int y, vo } } - color[0] = color_accum[0] / multiplier_accum[0]; - color[1] = color_accum[1] / multiplier_accum[1]; - color[2] = color_accum[2] / multiplier_accum[2]; - color[3] = color_accum[3] / multiplier_accum[3]; + output[0] = color_accum[0] / multiplier_accum[0]; + output[1] = color_accum[1] / multiplier_accum[1]; + output[2] = color_accum[2] / multiplier_accum[2]; + output[3] = color_accum[3] / multiplier_accum[3]; + + /* blend in out values over the threshold, otherwise we get sharp, ugly transitions */ + if ((size_center > this->m_threshold) && + (size_center < this->m_threshold * 2.0f)) + { + /* factor from 0-1 */ + float fac = (size_center - this->m_threshold) / this->m_threshold; + interp_v4_v4v4(output, readColor, output, fac); + } } } -void VariableSizeBokehBlurOperation::executeOpenCL(OpenCLDevice* device, +void VariableSizeBokehBlurOperation::executeOpenCL(OpenCLDevice *device, MemoryBuffer *outputMemoryBuffer, cl_mem clOutputBuffer, MemoryBuffer **inputMemoryBuffers, list<cl_mem> *clMemToCleanUp, list<cl_kernel> *clKernelsToCleanUp) @@ -174,7 +193,11 @@ void VariableSizeBokehBlurOperation::executeOpenCL(OpenCLDevice* device, cl_float threshold = this->m_threshold; MemoryBuffer *sizeMemoryBuffer = (MemoryBuffer *)this->m_inputSizeProgram->getInputMemoryBuffer(inputMemoryBuffers); - maxBlur = (cl_int)sizeMemoryBuffer->getMaximumValue(); + + const float max_dim = max(m_width, m_height); + cl_float scalar = this->m_do_size_scale ? (max_dim / 100.0f) : 1.0f; + + maxBlur = (cl_int)sizeMemoryBuffer->getMaximumValue() * scalar; maxBlur = MIN2(maxBlur, this->m_maxBlur); device->COM_clAttachMemoryBufferToKernelParameter(defocusKernel, 0, -1, clMemToCleanUp, inputMemoryBuffers, this->m_inputProgram); @@ -185,9 +208,10 @@ void VariableSizeBokehBlurOperation::executeOpenCL(OpenCLDevice* device, clSetKernelArg(defocusKernel, 6, sizeof(cl_int), &step); clSetKernelArg(defocusKernel, 7, sizeof(cl_int), &maxBlur); clSetKernelArg(defocusKernel, 8, sizeof(cl_float), &threshold); - device->COM_clAttachSizeToKernelParameter(defocusKernel, 9, this); + clSetKernelArg(defocusKernel, 9, sizeof(cl_float), &scalar); + device->COM_clAttachSizeToKernelParameter(defocusKernel, 10, this); - device->COM_clEnqueueRange(defocusKernel, outputMemoryBuffer, 10, this); + device->COM_clEnqueueRange(defocusKernel, outputMemoryBuffer, 11, this); } void VariableSizeBokehBlurOperation::deinitExecution() @@ -205,13 +229,17 @@ bool VariableSizeBokehBlurOperation::determineDependingAreaOfInterest(rcti *inpu rcti newInput; rcti bokehInput; - newInput.xmax = input->xmax + this->m_maxBlur + 2; - newInput.xmin = input->xmin - this->m_maxBlur + 2; - newInput.ymax = input->ymax + this->m_maxBlur - 2; - newInput.ymin = input->ymin - this->m_maxBlur - 2; - bokehInput.xmax = 512; + const float max_dim = max(m_width, m_height); + const float scalar = this->m_do_size_scale ? (max_dim / 100.0f) : 1.0f; + int maxBlurScalar = this->m_maxBlur * scalar; + + newInput.xmax = input->xmax + maxBlurScalar + 2; + newInput.xmin = input->xmin - maxBlurScalar + 2; + newInput.ymax = input->ymax + maxBlurScalar - 2; + newInput.ymin = input->ymin - maxBlurScalar - 2; + bokehInput.xmax = COM_BLUR_BOKEH_PIXELS; bokehInput.xmin = 0; - bokehInput.ymax = 512; + bokehInput.ymax = COM_BLUR_BOKEH_PIXELS; bokehInput.ymin = 0; @@ -256,10 +284,10 @@ void InverseSearchRadiusOperation::initExecution() this->m_inputRadius = this->getInputSocketReader(0); } -void* InverseSearchRadiusOperation::initializeTileData(rcti *rect) +voi *InverseSearchRadiusOperation::initializeTileData(rcti *rect) { MemoryBuffer * data = new MemoryBuffer(NULL, rect); - float* buffer = data->getBuffer(); + float *buffer = data->getBuffer(); int x, y; int width = this->m_inputRadius->getWidth(); int height = this->m_inputRadius->getHeight(); @@ -310,16 +338,16 @@ void* InverseSearchRadiusOperation::initializeTileData(rcti *rect) return data; } -void InverseSearchRadiusOperation::executePixel(float *color, int x, int y, void *data) +void InverseSearchRadiusOperation::executePixel(float output[4], int x, int y, void *data) { - MemoryBuffer *buffer = (MemoryBuffer*)data; + MemoryBuffer *buffer = (MemoryBuffer *)data; buffer->readNoCheck(color, x, y); } void InverseSearchRadiusOperation::deinitializeTileData(rcti *rect, void *data) { if (data) { - MemoryBuffer* mb = (MemoryBuffer*)data; + MemoryBuffer *mb = (MemoryBuffer *)data; delete mb; } } @@ -329,7 +357,7 @@ void InverseSearchRadiusOperation::deinitExecution() this->m_inputRadius = NULL; } -void InverseSearchRadiusOperation::determineResolution(unsigned int resolution[], unsigned int preferredResolution[]) +void InverseSearchRadiusOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]) { NodeOperation::determineResolution(resolution, preferredResolution); resolution[0] = resolution[0] / DIVIDER; @@ -339,10 +367,10 @@ void InverseSearchRadiusOperation::determineResolution(unsigned int resolution[] bool InverseSearchRadiusOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) { rcti newRect; - newRect.ymin = input->ymin*DIVIDER - m_maxBlur; - newRect.ymax = input->ymax*DIVIDER + m_maxBlur; - newRect.xmin = input->xmin*DIVIDER - m_maxBlur; - newRect.xmax = input->xmax*DIVIDER + m_maxBlur; + newRect.ymin = input->ymin * DIVIDER - m_maxBlur; + newRect.ymax = input->ymax * DIVIDER + m_maxBlur; + newRect.xmin = input->xmin * DIVIDER - m_maxBlur; + newRect.xmax = input->xmax * DIVIDER + m_maxBlur; return NodeOperation::determineDependingAreaOfInterest(&newRect, readOperation, output); } #endif diff --git a/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.h b/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.h index e5430545323..d4025692549 100644 --- a/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.h +++ b/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.h @@ -31,6 +31,7 @@ class VariableSizeBokehBlurOperation : public NodeOperation, public QualityStepH private: int m_maxBlur; float m_threshold; + bool m_do_size_scale; /* scale size, matching 'BokehBlurNode' */ SocketReader *m_inputProgram; SocketReader *m_inputBokehProgram; SocketReader *m_inputSizeProgram; @@ -44,7 +45,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, int x, int y, void *data); + void executePixel(float output[4], int x, int y, void *data); /** * Initialize the execution @@ -66,7 +67,9 @@ public: void setThreshold(float threshold) { this->m_threshold = threshold; } - void executeOpenCL(OpenCLDevice* device, MemoryBuffer *outputMemoryBuffer, cl_mem clOutputBuffer, MemoryBuffer **inputMemoryBuffers, list<cl_mem> *clMemToCleanUp, list<cl_kernel> *clKernelsToCleanUp); + void setDoScaleSize(bool scale_size) { this->m_do_size_scale = scale_size; } + + void executeOpenCL(OpenCLDevice *device, MemoryBuffer *outputMemoryBuffer, cl_mem clOutputBuffer, MemoryBuffer **inputMemoryBuffers, list<cl_mem> *clMemToCleanUp, list<cl_kernel> *clKernelsToCleanUp); }; #ifdef COM_DEFOCUS_SEARCH @@ -82,13 +85,13 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, int x, int y, MemoryBuffer * inputBuffers[], void *data); + void executePixel(float output[4], int x, int y, MemoryBuffer *inputBuffers[], void *data); /** * Initialize the execution */ void initExecution(); - void* initializeTileData(rcti *rect); + void *initializeTileData(rcti *rect); void deinitializeTileData(rcti *rect, void *data); /** @@ -97,7 +100,7 @@ public: void deinitExecution(); bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output); - void determineResolution(unsigned int resolution[], unsigned int preferredResolution[]); + void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]); void setMaxBlur(int maxRadius) { this->m_maxBlur = maxRadius; } }; diff --git a/source/blender/compositor/operations/COM_VectorBlurOperation.cpp b/source/blender/compositor/operations/COM_VectorBlurOperation.cpp index 134597531c2..ebf3b772b3b 100644 --- a/source/blender/compositor/operations/COM_VectorBlurOperation.cpp +++ b/source/blender/compositor/operations/COM_VectorBlurOperation.cpp @@ -52,11 +52,11 @@ void VectorBlurOperation::initExecution() } -void VectorBlurOperation::executePixel(float *color, int x, int y, void *data) +void VectorBlurOperation::executePixel(float output[4], int x, int y, void *data) { float *buffer = (float *) data; int index = (y * this->getWidth() + x) * COM_NUMBER_OF_CHANNELS; - copy_v4_v4(color, &buffer[index]); + copy_v4_v4(output, &buffer[index]); } void VectorBlurOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_VectorBlurOperation.h b/source/blender/compositor/operations/COM_VectorBlurOperation.h index 2743baf8500..4c6fca3cf83 100644 --- a/source/blender/compositor/operations/COM_VectorBlurOperation.h +++ b/source/blender/compositor/operations/COM_VectorBlurOperation.h @@ -48,7 +48,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, int x, int y, void *data); + void executePixel(float output[4], int x, int y, void *data); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_VectorCurveOperation.cpp b/source/blender/compositor/operations/COM_VectorCurveOperation.cpp index ed86c842fc9..d0a077fed61 100644 --- a/source/blender/compositor/operations/COM_VectorCurveOperation.cpp +++ b/source/blender/compositor/operations/COM_VectorCurveOperation.cpp @@ -43,7 +43,7 @@ void VectorCurveOperation::initExecution() this->m_inputProgram = this->getInputSocketReader(0); } -void VectorCurveOperation::executePixel(float *output, float x, float y, PixelSampler sampler) +void VectorCurveOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float input[4]; diff --git a/source/blender/compositor/operations/COM_VectorCurveOperation.h b/source/blender/compositor/operations/COM_VectorCurveOperation.h index b76f8880fc6..6a1f916c60b 100644 --- a/source/blender/compositor/operations/COM_VectorCurveOperation.h +++ b/source/blender/compositor/operations/COM_VectorCurveOperation.h @@ -37,7 +37,7 @@ public: /** * the inner loop of this program */ - void executePixel(float *Vector, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); /** * Initialize the execution diff --git a/source/blender/compositor/operations/COM_WriteBufferOperation.cpp b/source/blender/compositor/operations/COM_WriteBufferOperation.cpp index 0a31a6e170b..273c10b60ac 100644 --- a/source/blender/compositor/operations/COM_WriteBufferOperation.cpp +++ b/source/blender/compositor/operations/COM_WriteBufferOperation.cpp @@ -40,9 +40,9 @@ WriteBufferOperation::~WriteBufferOperation() } } -void WriteBufferOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void WriteBufferOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { - this->m_input->read(color, x, y, sampler); + this->m_input->read(output, x, y, sampler); } void WriteBufferOperation::initExecution() @@ -110,7 +110,7 @@ void WriteBufferOperation::executeRegion(rcti *rect, unsigned int tileNumber) memoryBuffer->setCreatedState(); } -void WriteBufferOperation::executeOpenCLRegion(OpenCLDevice* device, rcti *rect, unsigned int chunkNumber, MemoryBuffer **inputMemoryBuffers, MemoryBuffer *outputBuffer) +void WriteBufferOperation::executeOpenCLRegion(OpenCLDevice *device, rcti *rect, unsigned int chunkNumber, MemoryBuffer **inputMemoryBuffers, MemoryBuffer *outputBuffer) { float *outputFloatBuffer = outputBuffer->getBuffer(); cl_int error; diff --git a/source/blender/compositor/operations/COM_WriteBufferOperation.h b/source/blender/compositor/operations/COM_WriteBufferOperation.h index 1aa93c658cb..d89444045d4 100644 --- a/source/blender/compositor/operations/COM_WriteBufferOperation.h +++ b/source/blender/compositor/operations/COM_WriteBufferOperation.h @@ -38,13 +38,13 @@ public: ~WriteBufferOperation(); int isBufferOperation() { return true; } MemoryProxy *getMemoryProxy() { return this->m_memoryProxy; } - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); const bool isWriteBufferOperation() const { return true; } void executeRegion(rcti *rect, unsigned int tileNumber); void initExecution(); void deinitExecution(); - void executeOpenCLRegion(OpenCLDevice* device, rcti *rect, unsigned int chunkNumber, MemoryBuffer **memoryBuffers, MemoryBuffer *outputBuffer); + void executeOpenCLRegion(OpenCLDevice *device, rcti *rect, unsigned int chunkNumber, MemoryBuffer **memoryBuffers, MemoryBuffer *outputBuffer); void readResolutionFromInputSocket(); inline NodeOperation *getInput() { return m_input; diff --git a/source/blender/compositor/operations/COM_ZCombineOperation.cpp b/source/blender/compositor/operations/COM_ZCombineOperation.cpp index 28dbcd9f017..7e23e7290f8 100644 --- a/source/blender/compositor/operations/COM_ZCombineOperation.cpp +++ b/source/blender/compositor/operations/COM_ZCombineOperation.cpp @@ -46,7 +46,7 @@ void ZCombineOperation::initExecution() this->m_depth2Reader = this->getInputSocketReader(3); } -void ZCombineOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void ZCombineOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float depth1[4]; float depth2[4]; @@ -54,13 +54,13 @@ void ZCombineOperation::executePixel(float *color, float x, float y, PixelSample this->m_depth1Reader->read(depth1, x, y, sampler); this->m_depth2Reader->read(depth2, x, y, sampler); if (depth1[0] < depth2[0]) { - this->m_image1Reader->read(color, x, y, sampler); + this->m_image1Reader->read(output, x, y, sampler); } else { - this->m_image2Reader->read(color, x, y, sampler); + this->m_image2Reader->read(output, x, y, sampler); } } -void ZCombineAlphaOperation::executePixel(float *color, float x, float y, PixelSampler sampler) +void ZCombineAlphaOperation::executePixel(float output[4], float x, float y, PixelSampler sampler) { float depth1[4]; float depth2[4]; @@ -79,10 +79,10 @@ void ZCombineAlphaOperation::executePixel(float *color, float x, float y, PixelS } float fac = color1[3]; float ifac = 1.0f - fac; - color[0] = color1[0] + ifac * color2[0]; - color[1] = color1[1] + ifac * color2[1]; - color[2] = color1[2] + ifac * color2[2]; - color[3] = MAX2(color1[3], color2[3]); + output[0] = color1[0] + ifac * color2[0]; + output[1] = color1[1] + ifac * color2[1]; + output[2] = color1[2] + ifac * color2[2]; + output[3] = MAX2(color1[3], color2[3]); } void ZCombineOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_ZCombineOperation.h b/source/blender/compositor/operations/COM_ZCombineOperation.h index 9ee0899ee28..61ceca340f7 100644 --- a/source/blender/compositor/operations/COM_ZCombineOperation.h +++ b/source/blender/compositor/operations/COM_ZCombineOperation.h @@ -47,11 +47,11 @@ public: /** * the inner loop of this program */ - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; class ZCombineAlphaOperation : public ZCombineOperation { - void executePixel(float *color, float x, float y, PixelSampler sampler); + void executePixel(float output[4], float x, float y, PixelSampler sampler); }; #endif diff --git a/source/blender/editors/animation/anim_channels_edit.c b/source/blender/editors/animation/anim_channels_edit.c index 3b0234b5424..ee31276a8c4 100644 --- a/source/blender/editors/animation/anim_channels_edit.c +++ b/source/blender/editors/animation/anim_channels_edit.c @@ -290,10 +290,10 @@ void ANIM_deselect_anim_channels(bAnimContext *ac, void *data, short datatype, s { Base *base = (Base *)ale->data; Object *ob = base->object; - + ACHANNEL_SET_FLAG(base, sel, SELECT); ACHANNEL_SET_FLAG(ob, sel, SELECT); - + if (ob->adt) { ACHANNEL_SET_FLAG(ob, sel, ADT_UI_SELECTED); } @@ -364,11 +364,11 @@ void ANIM_deselect_anim_channels(bAnimContext *ac, void *data, short datatype, s ACHANNEL_SET_FLAG(gpl, sel, GP_LAYER_SELECT); } break; - + case ANIMTYPE_MASKLAYER: { MaskLayer *masklay = (MaskLayer *)ale->data; - + ACHANNEL_SET_FLAG(masklay, sel, MASK_LAYERFLAG_SELECT); } break; @@ -1934,10 +1934,7 @@ static int animchannels_borderselect_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; /* get settings from operator */ - rect.xmin = RNA_int_get(op->ptr, "xmin"); - rect.ymin = RNA_int_get(op->ptr, "ymin"); - rect.xmax = RNA_int_get(op->ptr, "xmax"); - rect.ymax = RNA_int_get(op->ptr, "ymax"); + WM_operator_properties_border_to_rcti(op, &rect); gesture_mode = RNA_int_get(op->ptr, "gesture_mode"); extend = RNA_boolean_get(op->ptr, "extend"); @@ -2156,7 +2153,7 @@ static int mouse_anim_channels(bAnimContext *ac, float UNUSED(x), int channel_in } else { Base *b; - + /* deselect all */ /* TODO: should this deselect all other types of channels too? */ for (b = sce->base.first; b; b = b->next) { @@ -2247,6 +2244,8 @@ static int mouse_anim_channels(bAnimContext *ac, float UNUSED(x), int channel_in /* if group is selected now, make group the 'active' one in the visible list */ if (agrp->flag & AGRP_SELECTED) ANIM_set_active_channel(ac, ac->data, ac->datatype, filter, agrp, ANIMTYPE_GROUP); + else + ANIM_set_active_channel(ac, ac->data, ac->datatype, filter, NULL, ANIMTYPE_GROUP); notifierFlags |= (ND_ANIMCHAN | NA_SELECTED); } @@ -2324,19 +2323,19 @@ static int mouse_anim_channels(bAnimContext *ac, float UNUSED(x), int channel_in case ANIMTYPE_MASKDATABLOCK: { Mask *mask = (Mask *)ale->data; - + /* toggle expand * - although the triangle widget already allows this, the whole channel can also be used for this purpose */ mask->flag ^= MASK_ANIMF_EXPAND; - + notifierFlags |= (ND_ANIMCHAN | NA_EDITED); } break; case ANIMTYPE_MASKLAYER: { MaskLayer *masklay = (MaskLayer *)ale->data; - + /* select/deselect */ if (selectmode == SELECT_INVERT) { /* invert selection status of this layer only */ @@ -2347,7 +2346,7 @@ static int mouse_anim_channels(bAnimContext *ac, float UNUSED(x), int channel_in ANIM_deselect_anim_channels(ac, ac->data, ac->datatype, 0, ACHANNEL_SETFLAG_CLEAR); masklay->flag |= MASK_LAYERFLAG_SELECT; } - + notifierFlags |= (ND_ANIMCHAN | NA_EDITED); } break; @@ -2412,6 +2411,8 @@ static int animchannels_mouseclick_invoke(bContext *C, wmOperator *op, wmEvent * static void ANIM_OT_channels_click(wmOperatorType *ot) { + PropertyRNA *prop; + /* identifiers */ ot->name = "Mouse Click on Channels"; ot->idname = "ANIM_OT_channels_click"; @@ -2424,9 +2425,13 @@ static void ANIM_OT_channels_click(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - /* id-props */ - RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", ""); // SHIFTKEY - RNA_def_boolean(ot->srna, "children_only", 0, "Select Children Only", ""); // CTRLKEY|SHIFTKEY + /* properties */ + /* NOTE: don't save settings, otherwise, can end up with some weird behaviour (sticky extend) */ + prop = RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", ""); // SHIFTKEY + RNA_def_property_flag(prop, PROP_SKIP_SAVE); + + prop = RNA_def_boolean(ot->srna, "children_only", 0, "Select Children Only", ""); // CTRLKEY|SHIFTKEY + RNA_def_property_flag(prop, PROP_SKIP_SAVE); } /* ************************************************************************** */ diff --git a/source/blender/editors/animation/anim_deps.c b/source/blender/editors/animation/anim_deps.c index 50bdbd6673c..3cc39238713 100644 --- a/source/blender/editors/animation/anim_deps.c +++ b/source/blender/editors/animation/anim_deps.c @@ -202,7 +202,7 @@ static void animchan_sync_fcurve(bAnimContext *UNUSED(ac), bAnimListElem *ale) /* get strip name, and check if this strip is selected */ seq_name = BLI_str_quoted_substrN(fcu->rna_path, "sequences_all["); - seq = get_seq_by_name(ed->seqbasep, seq_name, FALSE); + seq = BKE_sequwnce_get_by_name(ed->seqbasep, seq_name, FALSE); if (seq_name) MEM_freeN(seq_name); /* can only add this F-Curve if it is selected */ diff --git a/source/blender/editors/animation/anim_draw.c b/source/blender/editors/animation/anim_draw.c index 0d48bf19c9e..620f5de9db7 100644 --- a/source/blender/editors/animation/anim_draw.c +++ b/source/blender/editors/animation/anim_draw.c @@ -100,7 +100,7 @@ void ANIM_timecode_string_from_frame(char *str, Scene *scene, int power, short t } else { /* seconds (with pixel offset rounding) */ - seconds = (int)floor(cfra + 0.375f); + seconds = (int)floor(cfra + GLA_PIXEL_OFS); } switch (U.timecode_style) { @@ -150,7 +150,7 @@ void ANIM_timecode_string_from_frame(char *str, Scene *scene, int power, short t /* only show the original seconds display */ /* round to whole numbers if power is >= 1 (i.e. scale is coarse) */ if (power <= 0) sprintf(str, "%.*f", 1 - power, raw_seconds); - else sprintf(str, "%d", (int)floor(raw_seconds + 0.375f)); + else sprintf(str, "%d", (int)floor(raw_seconds + GLA_PIXEL_OFS)); } break; @@ -166,7 +166,7 @@ void ANIM_timecode_string_from_frame(char *str, Scene *scene, int power, short t else { /* round to whole numbers if power is >= 1 (i.e. scale is coarse) */ if (power <= 0) sprintf(str, "%.*f", 1 - power, cfra); - else sprintf(str, "%d", (int)floor(cfra + 0.375f)); + else sprintf(str, "%d", (int)floor(cfra + GLA_PIXEL_OFS)); } } @@ -283,7 +283,7 @@ AnimData *ANIM_nla_mapping_get(bAnimContext *ac, bAnimListElem *ale) return NULL; /* abort if rendering - we may get some race condition issues... */ - if (G.rendering) return NULL; + if (G.is_rendering) return NULL; /* handling depends on the type of animation-context we've got */ if (ale) @@ -422,7 +422,7 @@ void ANIM_unit_mapping_apply_fcurve(Scene *scene, ID *id, FCurve *fcu, short fla float fac; /* abort if rendering - we may get some race condition issues... */ - if (G.rendering) return; + if (G.is_rendering) return; /* calculate mapping factor, and abort if nothing to change */ fac = ANIM_unit_mapping_get_factor(scene, id, fcu, (flag & ANIM_UNITCONV_RESTORE)); diff --git a/source/blender/editors/animation/anim_filter.c b/source/blender/editors/animation/anim_filter.c index d6f9049ef01..a771053bc3d 100644 --- a/source/blender/editors/animation/anim_filter.c +++ b/source/blender/editors/animation/anim_filter.c @@ -931,7 +931,7 @@ static short skip_fcurve_selected_data(bDopeSheet *ads, FCurve *fcu, ID *owner_i /* get strip name, and check if this strip is selected */ seq_name = BLI_str_quoted_substrN(fcu->rna_path, "sequences_all["); - seq = get_seq_by_name(ed->seqbasep, seq_name, FALSE); + seq = BKE_sequwnce_get_by_name(ed->seqbasep, seq_name, FALSE); if (seq_name) MEM_freeN(seq_name); /* can only add this F-Curve if it is selected */ diff --git a/source/blender/editors/animation/anim_markers.c b/source/blender/editors/animation/anim_markers.c index 96044e2408e..a8daf852dda 100644 --- a/source/blender/editors/animation/anim_markers.c +++ b/source/blender/editors/animation/anim_markers.c @@ -1146,14 +1146,13 @@ static int ed_marker_border_select_exec(bContext *C, wmOperator *op) TimeMarker *marker; float xminf, xmaxf, yminf, ymaxf; int gesture_mode = RNA_int_get(op->ptr, "gesture_mode"); - int xmin = RNA_int_get(op->ptr, "xmin"); - int xmax = RNA_int_get(op->ptr, "xmax"); - int ymin = RNA_int_get(op->ptr, "ymin"); - int ymax = RNA_int_get(op->ptr, "ymax"); int extend = RNA_boolean_get(op->ptr, "extend"); + rcti rect; - UI_view2d_region_to_view(v2d, xmin, ymin, &xminf, &yminf); - UI_view2d_region_to_view(v2d, xmax, ymax, &xmaxf, &ymaxf); + WM_operator_properties_border_to_rcti(op, &rect); + + UI_view2d_region_to_view(v2d, rect.xmin, rect.ymin, &xminf, &yminf); + UI_view2d_region_to_view(v2d, rect.xmax, rect.ymax, &xmaxf, &ymaxf); if (markers == NULL) return 0; diff --git a/source/blender/editors/animation/anim_ops.c b/source/blender/editors/animation/anim_ops.c index 13741a99d99..e24a4d49a05 100644 --- a/source/blender/editors/animation/anim_ops.c +++ b/source/blender/editors/animation/anim_ops.c @@ -65,7 +65,7 @@ static int change_frame_poll(bContext *C) ScrArea *curarea = CTX_wm_area(C); /* XXX temp? prevent changes during render */ - if (G.rendering) return 0; + if (G.is_rendering) return 0; /* as long as there is an active area, and it isn't a Graph Editor * (since the Graph Editor has its own version which does extra stuff), @@ -185,15 +185,14 @@ static int previewrange_define_exec(bContext *C, wmOperator *op) Scene *scene = CTX_data_scene(C); ARegion *ar = CTX_wm_region(C); float sfra, efra; - int xmin, xmax; + rcti rect; /* get min/max values from border select rect (already in region coordinates, not screen) */ - xmin = RNA_int_get(op->ptr, "xmin"); - xmax = RNA_int_get(op->ptr, "xmax"); + WM_operator_properties_border_to_rcti(op, &rect); /* convert min/max values to frames (i.e. region to 'tot' rect) */ - UI_view2d_region_to_view(&ar->v2d, xmin, 0, &sfra, NULL); - UI_view2d_region_to_view(&ar->v2d, xmax, 0, &efra, NULL); + UI_view2d_region_to_view(&ar->v2d, rect.xmin, 0, &sfra, NULL); + UI_view2d_region_to_view(&ar->v2d, rect.xmax, 0, &efra, NULL); /* set start/end frames for preview-range * - must clamp within allowable limits @@ -232,12 +231,11 @@ static void ANIM_OT_previewrange_set(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* rna */ - /* used to define frame range */ - RNA_def_int(ot->srna, "xmin", 0, INT_MIN, INT_MAX, "X Min", "", INT_MIN, INT_MAX); - RNA_def_int(ot->srna, "xmax", 0, INT_MIN, INT_MAX, "X Max", "", INT_MIN, INT_MAX); - /* these are not used, but are needed by borderselect gesture operator stuff */ - RNA_def_int(ot->srna, "ymin", 0, INT_MIN, INT_MAX, "Y Min", "", INT_MIN, INT_MAX); - RNA_def_int(ot->srna, "ymax", 0, INT_MIN, INT_MAX, "Y Max", "", INT_MIN, INT_MAX); + /* used to define frame range. + * + * note: border Y values are not used, + * but are needed by borderselect gesture operator stuff */ + WM_operator_properties_border(ot); } /* ****************** clear preview range operator ****************************/ diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c index e0aa33d0207..dd2400ca302 100644 --- a/source/blender/editors/armature/editarmature.c +++ b/source/blender/editors/armature/editarmature.c @@ -4775,7 +4775,7 @@ static void envelope_bone_weighting(Object *ob, Mesh *mesh, float (*verts)[3], i distance = distfactor_to_bone(verts[i], root[j], tip[j], bone->rad_head * scale, bone->rad_tail * scale, bone->dist * scale); - /* add the vert to the deform group if weight!=0.0 */ + /* add the vert to the deform group if (weight != 0.0) */ if (distance != 0.0f) ED_vgroup_vert_add(ob, dgroup, i, distance, WEIGHT_REPLACE); else diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index a9646aaabf4..bc154de9691 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -1427,8 +1427,8 @@ void CURVE_OT_separate(wmOperatorType *ot) static short isNurbselUV(Nurb *nu, int *u, int *v, int flag) { - /* return u!=-1: 1 row in u-direction selected. U has value between 0-pntsv - * return v!=-1: 1 column in v-direction selected. V has value between 0-pntsu + /* return (u != -1): 1 row in u-direction selected. U has value between 0-pntsv + * return (v != -1): 1 column in v-direction selected. V has value between 0-pntsu */ BPoint *bp; int a, b, sel; diff --git a/source/blender/editors/curve/editfont.c b/source/blender/editors/curve/editfont.c index bb66b1f4347..b11d640256c 100644 --- a/source/blender/editors/curve/editfont.c +++ b/source/blender/editors/curve/editfont.c @@ -422,7 +422,8 @@ void FONT_OT_file_paste(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ - WM_operator_properties_filesel(ot, FOLDERFILE | TEXTFILE, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY); + WM_operator_properties_filesel(ot, FOLDERFILE | TEXTFILE, FILE_SPECIAL, FILE_OPENFILE, + WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY); } /******************* text to object operator ********************/ @@ -1665,7 +1666,7 @@ static int font_open_exec(bContext *C, wmOperator *op) static int open_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) { - VFont *font = NULL; + VFont *vfont = NULL; char *path; PointerRNA idptr; @@ -1678,10 +1679,10 @@ static int open_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) if (pprop->prop) { idptr = RNA_property_pointer_get((PointerRNA *)pprop, pprop->prop); - font = idptr.id.data; + vfont = idptr.id.data; } - path = (font && strcmp(font->name, FO_BUILTIN_NAME) != 0) ? font->name : U.fontdir; + path = (vfont && !BKE_vfont_is_builtin(vfont)) ? vfont->name : U.fontdir; if (RNA_struct_property_is_set(op->ptr, "filepath")) return font_open_exec(C, op); @@ -1708,7 +1709,8 @@ void FONT_OT_open(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ - WM_operator_properties_filesel(ot, FOLDERFILE | FTFONTFILE, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH, FILE_DEFAULTDISPLAY); + WM_operator_properties_filesel(ot, FOLDERFILE | FTFONTFILE, FILE_SPECIAL, FILE_OPENFILE, + WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH, FILE_DEFAULTDISPLAY); } /******************* delete operator *********************/ diff --git a/source/blender/editors/include/BIF_gl.h b/source/blender/editors/include/BIF_gl.h index a5e5d7ce2e0..479e0b65177 100644 --- a/source/blender/editors/include/BIF_gl.h +++ b/source/blender/editors/include/BIF_gl.h @@ -50,5 +50,7 @@ #define glMultMatrixf(x) glMultMatrixf( (float *)(x)) #define glLoadMatrixf(x) glLoadMatrixf( (float *)(x)) +#define GLA_PIXEL_OFS 0.375f + #endif /* #ifdef __BIF_GL_H__ */ diff --git a/source/blender/editors/include/BIF_glutil.h b/source/blender/editors/include/BIF_glutil.h index b939ae47ead..577113927d1 100644 --- a/source/blender/editors/include/BIF_glutil.h +++ b/source/blender/editors/include/BIF_glutil.h @@ -116,8 +116,8 @@ void glaRasterPosSafe2f(float x, float y, float known_good_x, float known_good_y * * \attention This routine makes many assumptions: the rect data * is expected to be in RGBA unsigned byte format, the coordinate - * (0.375, 0.375) is assumed to be within the view frustum, and the - * modelview and projection matrices are assumed to define a + * (GLA_PIXEL_OFS, GLA_PIXEL_OFS) is assumed to be within the view frustum, + * and the modelview and projection matrices are assumed to define a * 1-to-1 mapping to screen space. * \attention Furthermore, in the case of zoomed or unpixel aligned * images extending outside the view frustum, but still within the diff --git a/source/blender/editors/include/ED_node.h b/source/blender/editors/include/ED_node.h index ca468a15771..b6a1fd0f979 100644 --- a/source/blender/editors/include/ED_node.h +++ b/source/blender/editors/include/ED_node.h @@ -41,6 +41,7 @@ struct bNodeTree; struct bNode; struct bNodeTree; struct ScrArea; +struct Scene; struct View2D; typedef enum { @@ -73,6 +74,8 @@ int ED_node_select_check(ListBase *lb); void ED_node_post_apply_transform(struct bContext *C, struct bNodeTree *ntree); void ED_node_set_active(struct Main *bmain, struct bNodeTree *ntree, struct bNode *node); +void ED_node_composite_job(const bContext *C, struct bNodeTree *nodetree, struct Scene *scene_owner); + /* node ops.c */ void ED_operatormacros_node(void); diff --git a/source/blender/editors/include/ED_screen_types.h b/source/blender/editors/include/ED_screen_types.h index 6b9d8385ac3..527ebb6c3ef 100644 --- a/source/blender/editors/include/ED_screen_types.h +++ b/source/blender/editors/include/ED_screen_types.h @@ -98,7 +98,7 @@ typedef struct AZone { } AZone; /* actionzone type */ -#define AZONE_AREA 1 -#define AZONE_REGION 2 +#define AZONE_AREA 1 /* corner widgets for splitting areas */ +#define AZONE_REGION 2 /* when a region is collapsed, draw a handle to expose */ #endif /* __ED_SCREEN_TYPES_H__ */ diff --git a/source/blender/editors/interface/interface_anim.c b/source/blender/editors/interface/interface_anim.c index 28d18f6a3dd..5d62ef768d2 100644 --- a/source/blender/editors/interface/interface_anim.c +++ b/source/blender/editors/interface/interface_anim.c @@ -217,7 +217,8 @@ void ui_but_anim_clear_keyframe(bContext *C) /* this operator calls uiContextActiveProperty */ WM_operator_name_call(C, "ANIM_OT_keyframe_clear_button", WM_OP_INVOKE_DEFAULT, NULL); } - void ui_but_anim_add_driver(bContext *C) + +void ui_but_anim_add_driver(bContext *C) { /* this operator calls uiContextActiveProperty */ WM_operator_name_call(C, "ANIM_OT_driver_button_add", WM_OP_INVOKE_DEFAULT, NULL); diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c index d8eb1b011bd..f7eff2cb22b 100644 --- a/source/blender/editors/interface/interface_draw.c +++ b/source/blender/editors/interface/interface_draw.c @@ -479,7 +479,7 @@ static void ui_draw_but_CHARTAB(uiBut *but) int charmax = G.charmax; /* FO_BUILTIN_NAME font in use. There are TTF FO_BUILTIN_NAME and non-TTF FO_BUILTIN_NAME fonts */ - if (!strcmp(G.selfont->name, FO_BUILTIN_NAME)) { + if (BKE_vfont_is_builtin(G.selfont)) { if (G.ui_international == TRUE) { charmax = 0xff; } @@ -508,7 +508,7 @@ static void ui_draw_but_CHARTAB(uiBut *but) cs = G.charstart; /* Set the font, in case it is not FO_BUILTIN_NAME font */ - if (G.selfont && strcmp(G.selfont->name, FO_BUILTIN_NAME)) { + if (G.selfont && BKE_vfont_is_builtin(G.selfont) == FALSE) { /* Is the font file packed, if so then use the packed file */ if (G.selfont->packedfile) { pf = G.selfont->packedfile; @@ -559,7 +559,7 @@ static void ui_draw_but_CHARTAB(uiBut *but) /* Set the font to be either unicode or FO_BUILTIN_NAME */ wstr[0] = cs; - if (strcmp(G.selfont->name, FO_BUILTIN_NAME)) { + if (BKE_vfont_is_builtin(G.selfont) == FALSE) { BLI_strncpy_wchar_as_utf8((char *)ustr, (wchar_t *)wstr, sizeof(ustr)); } else { @@ -572,8 +572,8 @@ static void ui_draw_but_CHARTAB(uiBut *but) } } - if ((G.selfont && strcmp(G.selfont->name, FO_BUILTIN_NAME)) || - (G.selfont && !strcmp(G.selfont->name, FO_BUILTIN_NAME) && G.ui_international == TRUE)) + if ((G.selfont && (BKE_vfont_is_builtin(G.selfont) == FALSE)) || + (G.selfont && (BKE_vfont_is_builtin(G.selfont) == TRUE) && G.ui_international == TRUE)) { float wid; float llx, lly, llz, urx, ury, urz; diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 733c88c0980..f08a5b8a6fe 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -2563,7 +2563,7 @@ static void do_running_jobs(bContext *C, void *UNUSED(arg), int event) { switch (event) { case B_STOPRENDER: - G.afbreek = 1; + G.is_break = TRUE; break; case B_STOPCAST: WM_jobs_stop(CTX_wm_manager(C), CTX_wm_screen(C), NULL); diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c index 729f2b031e2..566c323cec5 100644 --- a/source/blender/editors/interface/resources.c +++ b/source/blender/editors/interface/resources.c @@ -1969,9 +1969,6 @@ void init_userdef_do_versions(void) if (U.dbl_click_time == 0) { U.dbl_click_time = 350; } - if (U.anim_player_preset == 0) { - U.anim_player_preset = 1; - } if (U.scrcastfps == 0) { U.scrcastfps = 10; U.scrcastwait = 50; diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c index a693e9eb627..8ae08c08693 100644 --- a/source/blender/editors/interface/view2d.c +++ b/source/blender/editors/interface/view2d.c @@ -980,7 +980,7 @@ void UI_view2d_view_ortho(View2D *v2d) rctf curmasked; float xofs, yofs; - /* pixel offsets (-0.375f) are needed to get 1:1 correspondence with pixels for smooth UI drawing, + /* pixel offsets (-GLA_PIXEL_OFS) are needed to get 1:1 correspondence with pixels for smooth UI drawing, * but only applied where requested */ /* XXX brecht: instead of zero at least use a tiny offset, otherwise @@ -1019,12 +1019,12 @@ void UI_view2d_view_orthoSpecial(ARegion *ar, View2D *v2d, short xaxis) rctf curmasked; float xofs, yofs; - /* pixel offsets (-0.375f) are needed to get 1:1 correspondence with pixels for smooth UI drawing, + /* pixel offsets (-GLA_PIXEL_OFS) are needed to get 1:1 correspondence with pixels for smooth UI drawing, * but only applied where requested */ /* XXX temp (ton) */ - xofs = 0.0f; // (v2d->flag & V2D_PIXELOFS_X) ? 0.375f : 0.0f; - yofs = 0.0f; // (v2d->flag & V2D_PIXELOFS_Y) ? 0.375f : 0.0f; + xofs = 0.0f; // (v2d->flag & V2D_PIXELOFS_X) ? GLA_PIXEL_OFS : 0.0f; + yofs = 0.0f; // (v2d->flag & V2D_PIXELOFS_Y) ? GLA_PIXEL_OFS : 0.0f; /* apply mask-based adjustments to cur rect (due to scrollers), to eliminate scaling artifacts */ view2d_map_cur_using_mask(v2d, &curmasked); diff --git a/source/blender/editors/interface/view2d_ops.c b/source/blender/editors/interface/view2d_ops.c index 244a4ea15de..c70f661cb14 100644 --- a/source/blender/editors/interface/view2d_ops.c +++ b/source/blender/editors/interface/view2d_ops.c @@ -1178,11 +1178,7 @@ static void VIEW2D_OT_zoom_border(wmOperatorType *ot) ot->poll = view_zoom_poll; /* rna */ - RNA_def_int(ot->srna, "gesture_mode", 0, INT_MIN, INT_MAX, "Gesture Mode", "", INT_MIN, INT_MAX); - RNA_def_int(ot->srna, "xmin", 0, INT_MIN, INT_MAX, "X Min", "", INT_MIN, INT_MAX); - RNA_def_int(ot->srna, "xmax", 0, INT_MIN, INT_MAX, "X Max", "", INT_MIN, INT_MAX); - RNA_def_int(ot->srna, "ymin", 0, INT_MIN, INT_MAX, "Y Min", "", INT_MIN, INT_MAX); - RNA_def_int(ot->srna, "ymax", 0, INT_MIN, INT_MAX, "Y Max", "", INT_MIN, INT_MAX); + WM_operator_properties_gesture_border(ot, FALSE); } /* ********************************************************* */ diff --git a/source/blender/editors/io/io_collada.c b/source/blender/editors/io/io_collada.c index 6e4da6b7e88..ebfc0522f17 100644 --- a/source/blender/editors/io/io_collada.c +++ b/source/blender/editors/io/io_collada.c @@ -242,7 +242,8 @@ void WM_OT_collada_export(wmOperatorType *ot) ot->ui = wm_collada_export_draw; - WM_operator_properties_filesel(ot, FOLDERFILE | COLLADAFILE, FILE_BLENDER, FILE_SAVE, WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY); + WM_operator_properties_filesel(ot, FOLDERFILE | COLLADAFILE, FILE_BLENDER, FILE_SAVE, + WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY); RNA_def_boolean(ot->srna, "apply_modifiers", 0, "Apply Modifiers", @@ -319,6 +320,7 @@ void WM_OT_collada_import(wmOperatorType *ot) ot->exec = wm_collada_import_exec; ot->poll = WM_operator_winactive; - WM_operator_properties_filesel(ot, FOLDERFILE | COLLADAFILE, FILE_BLENDER, FILE_OPENFILE, WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY); + WM_operator_properties_filesel(ot, FOLDERFILE | COLLADAFILE, FILE_BLENDER, FILE_OPENFILE, + WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY); } #endif diff --git a/source/blender/editors/mask/mask_add.c b/source/blender/editors/mask/mask_add.c index c928e90b422..e9b31b8df1a 100644 --- a/source/blender/editors/mask/mask_add.c +++ b/source/blender/editors/mask/mask_add.c @@ -91,13 +91,14 @@ static int find_nearest_diff_point(const bContext *C, Mask *mask, const float no i++, cur_point++) { float *diff_points; - int tot_diff_point; + unsigned int tot_diff_point; diff_points = BKE_mask_point_segment_diff_with_resolution(spline, cur_point, width, height, &tot_diff_point); if (diff_points) { - int i, tot_feather_point, tot_point; + int i, tot_point; + unsigned int tot_feather_point; float *feather_points = NULL, *points; if (feather) { @@ -320,6 +321,7 @@ static void finSelectedSplinePoint(MaskLayer *masklay, MaskSpline **spline, Mask *point = NULL; if (check_active) { + /* TODO, having an active point but no active spline is possible, why? */ if (masklay->act_spline && masklay->act_point && MASKPOINT_ISSEL_ANY(masklay->act_point)) { *spline = masklay->act_spline; *point = masklay->act_point; @@ -561,7 +563,8 @@ static int add_vertex_exec(bContext *C, wmOperator *op) RNA_float_get_array(op->ptr, "location", co); - if (masklay && masklay->act_point && MASKPOINT_ISSEL_ANY(masklay->act_point)) { + /* TODO, having an active point but no active spline is possible, why? */ + if (masklay && masklay->act_spline && masklay->act_point && MASKPOINT_ISSEL_ANY(masklay->act_point)) { /* cheap trick - double click for cyclic */ MaskSpline *spline = masklay->act_spline; @@ -643,7 +646,7 @@ void MASK_OT_add_vertex(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ - RNA_def_float_vector(ot->srna, "location", 2, NULL, -FLT_MIN, FLT_MAX, + RNA_def_float_vector(ot->srna, "location", 2, NULL, -FLT_MAX, FLT_MAX, "Location", "Location of vertex in normalized space", -1.0f, 1.0f); } @@ -717,6 +720,6 @@ void MASK_OT_add_feather_vertex(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ - RNA_def_float_vector(ot->srna, "location", 2, NULL, -FLT_MIN, FLT_MAX, + RNA_def_float_vector(ot->srna, "location", 2, NULL, -FLT_MAX, FLT_MAX, "Location", "Location of vertex in normalized space", -1.0f, 1.0f); } diff --git a/source/blender/editors/mask/mask_draw.c b/source/blender/editors/mask/mask_draw.c index 2f5a918a488..703ae70eb0f 100644 --- a/source/blender/editors/mask/mask_draw.c +++ b/source/blender/editors/mask/mask_draw.c @@ -368,6 +368,7 @@ static void draw_spline_curve(MaskLayer *masklay, MaskSpline *spline, const short is_spline_sel = (spline->flag & SELECT) && (masklay->restrictflag & MASK_RESTRICT_SELECT) == 0; const short is_smooth = (draw_flag & MASK_DRAWFLAG_SMOOTH); + const short is_fill = (spline->flag & MASK_SPLINE_NOFILL) == 0; int tot_diff_point; float (*diff_points)[2]; @@ -394,7 +395,25 @@ static void draw_spline_curve(MaskLayer *masklay, MaskSpline *spline, TRUE, is_smooth, is_active, rgb_tmp, draw_type); - /* TODO, draw mirror values when MASK_SPLINE_NOFILL is set */ + if (!is_fill) { + + float *fp = &diff_points[0][0]; + float *fp_feather = &feather_points[0][0]; + float tvec[2]; + int i; + + BLI_assert(tot_diff_point == tot_feather_point); + + for (i = 0; i < tot_diff_point; i++, fp += 2, fp_feather += 2) { + sub_v2_v2v2(tvec, fp, fp_feather); + add_v2_v2v2(fp_feather, fp, tvec); + } + + /* same as above */ + mask_draw_curve_type(spline, feather_points, tot_feather_point, + TRUE, is_smooth, is_active, + rgb_tmp, draw_type); + } MEM_freeN(feather_points); diff --git a/source/blender/editors/mask/mask_select.c b/source/blender/editors/mask/mask_select.c index e746f4258a5..285306ce12f 100644 --- a/source/blender/editors/mask/mask_select.c +++ b/source/blender/editors/mask/mask_select.c @@ -392,7 +392,7 @@ void MASK_OT_select(wmOperatorType *ot) /* properties */ WM_operator_properties_mouse_select(ot); - RNA_def_float_vector(ot->srna, "location", 2, NULL, -FLT_MIN, FLT_MAX, + RNA_def_float_vector(ot->srna, "location", 2, NULL, -FLT_MAX, FLT_MAX, "Location", "Location of vertex in normalized space", -1.0f, 1.0f); } @@ -414,10 +414,7 @@ static int border_select_exec(bContext *C, wmOperator *op) int change = FALSE, mode, extend; /* get rectangle from operator */ - rect.xmin = RNA_int_get(op->ptr, "xmin"); - rect.ymin = RNA_int_get(op->ptr, "ymin"); - rect.xmax = RNA_int_get(op->ptr, "xmax"); - rect.ymax = RNA_int_get(op->ptr, "ymax"); + WM_operator_properties_border_to_rcti(op, &rect); ED_mask_point_pos(sa, ar, rect.xmin, rect.ymin, &rectf.xmin, &rectf.ymin); ED_mask_point_pos(sa, ar, rect.xmax, rect.ymax, &rectf.xmax, &rectf.ymax); diff --git a/source/blender/editors/mesh/editface.c b/source/blender/editors/mesh/editface.c index addd0b14916..bce69cb7d1d 100644 --- a/source/blender/editors/mesh/editface.c +++ b/source/blender/editors/mesh/editface.c @@ -502,7 +502,7 @@ void seam_mark_clear_tface(Scene *scene, short mode) BLI_edgehash_free(ehash2, NULL); } -// XXX if (G.rt == 8) +// XXX if (G.debug_value == 8) // unwrap_lscm(1); me->drawflag |= ME_DRAWSEAMS; diff --git a/source/blender/editors/mesh/editmesh_knife.c b/source/blender/editors/mesh/editmesh_knife.c index 8a3cf87e96a..229bbdbefb7 100644 --- a/source/blender/editors/mesh/editmesh_knife.c +++ b/source/blender/editors/mesh/editmesh_knife.c @@ -339,14 +339,13 @@ static KnifeVert *get_bm_knife_vert(KnifeTool_OpData *kcd, BMVert *v) return kfv; } -/** - * get a KnifeEdge wrapper for an existing BMEdge - * \note #knife_get_face_kedges / #get_bm_knife_edge are called recursively - KEEP STACK MEM USAGE LOW */ +/* get a KnifeEdge wrapper for an existing BMEdge */ static KnifeEdge *get_bm_knife_edge(KnifeTool_OpData *kcd, BMEdge *e) { KnifeEdge *kfe = BLI_ghash_lookup(kcd->origedgemap, e); if (!kfe) { - BMLoop *l_iter, *l_first; + BMIter bmiter; + BMFace *f; kfe = new_knife_edge(kcd); kfe->e = e; @@ -357,17 +356,9 @@ static KnifeEdge *get_bm_knife_edge(KnifeTool_OpData *kcd, BMEdge *e) BLI_ghash_insert(kcd->origedgemap, e, kfe); - /* avoid BM_ITER because of stack memory usage - * otherwise we could use BM_FACES_OF_EDGE */ - l_iter = l_first = e->l; - do { - knife_append_list(kcd, &kfe->faces, l_iter->f); - - /* ensures the kedges lst for this f is initialized, - * it automatically adds kfe by itself */ - knife_get_face_kedges(kcd, l_iter->f); - - } while ((l_iter = l_iter->radial_next) != l_first); + BM_ITER_ELEM(f, &bmiter, e, BM_FACES_OF_EDGE) { + knife_append_list(kcd, &kfe->faces, f); + } } return kfe; @@ -397,23 +388,19 @@ static void knife_start_cut(KnifeTool_OpData *kcd) } } -/** - * \note #knife_get_face_kedges / #get_bm_knife_edge are called recursively - KEEP STACK MEM USAGE LOW */ static ListBase *knife_get_face_kedges(KnifeTool_OpData *kcd, BMFace *f) { ListBase *lst = BLI_ghash_lookup(kcd->kedgefacemap, f); if (!lst) { - BMLoop *l_iter, *l_first; + BMIter bmiter; + BMEdge *e; lst = knife_empty_list(kcd); - /* avoid BM_ITER because of stack memory usage - * otherwise we could use BM_EDGES_OF_FACE */ - l_iter = l_first = BM_FACE_FIRST_LOOP(f); - do { - knife_append_list(kcd, lst, get_bm_knife_edge(kcd, l_iter->e)); - } while ((l_iter = l_iter->next) != l_first); + BM_ITER_ELEM(e, &bmiter, f, BM_EDGES_OF_FACE) { + knife_append_list(kcd, lst, get_bm_knife_edge(kcd, e)); + } BLI_ghash_insert(kcd->kedgefacemap, f, lst); } @@ -1092,9 +1079,9 @@ static BMEdgeHit *knife_edge_tri_isect(KnifeTool_OpData *kcd, BMBVHTree *bmtree, BLI_array_declare(edges); BVHTreeOverlap *results, *result; BMLoop **ls; - float cos[9], uv[3], lambda; + float cos[9], lambda; unsigned int tot = 0; - int i, j; + int i; /* for comparing distances, error of intersection depends on triangle scale. * need to scale down before squaring for accurate comparison */ @@ -1112,105 +1099,107 @@ static BMEdgeHit *knife_edge_tri_isect(KnifeTool_OpData *kcd, BMBVHTree *bmtree, for (i = 0; i < tot; i++, result++) { float p[3]; + BMLoop *l1; + BMFace *hitf; + ListBase *lst; + Ref *ref; ls = (BMLoop **)kcd->em->looptris[result->indexA]; - for (j = 0; j < 3; j++) { - BMLoop *l1 = ls[j]; - BMFace *hitf; - ListBase *lst = knife_get_face_kedges(kcd, l1->f); - Ref *ref; + l1 = ls[0]; + lst = knife_get_face_kedges(kcd, l1->f); - for (ref = lst->first; ref; ref = ref->next) { - KnifeEdge *kfe = ref->ref; + for (ref = lst->first; ref; ref = ref->next) { + KnifeEdge *kfe = ref->ref; - //if (kfe == kcd->cur.edge || kfe == kcd->prev.edge) - // continue; + if (BLI_smallhash_haskey(ehash, (intptr_t)kfe)) { + continue; // We already found a hit on this knife edge + } - if (isect_line_tri_v3(kfe->v1->cageco, kfe->v2->cageco, v1, v2, v3, &lambda, uv)) { - float no[3], view[3], sp[3]; + if (isect_line_tri_v3(kfe->v1->cageco, kfe->v2->cageco, v1, v2, v3, &lambda, NULL)) { + float no[3], view[3], sp[3]; - interp_v3_v3v3(p, kfe->v1->cageco, kfe->v2->cageco, lambda); + interp_v3_v3v3(p, kfe->v1->cageco, kfe->v2->cageco, lambda); - if (kcd->cur.vert && len_squared_v3v3(kcd->cur.vert->cageco, p) < depsilon_squared) - continue; - if (kcd->prev.vert && len_squared_v3v3(kcd->prev.vert->cageco, p) < depsilon_squared) - continue; - if (len_squared_v3v3(kcd->prev.cage, p) < depsilon_squared || - len_squared_v3v3(kcd->cur.cage, p) < depsilon_squared) - { - continue; + if (kcd->cur.vert && len_squared_v3v3(kcd->cur.vert->cageco, p) < depsilon_squared) + continue; + if (kcd->prev.vert && len_squared_v3v3(kcd->prev.vert->cageco, p) < depsilon_squared) + continue; + if (len_squared_v3v3(kcd->prev.cage, p) < depsilon_squared || + len_squared_v3v3(kcd->cur.cage, p) < depsilon_squared) + continue; + + knife_project_v3(kcd, p, sp); + view3d_unproject(mats, view, sp[0], sp[1], 0.0f); + mul_m4_v3(kcd->ob->imat, view); + + if (kcd->cut_through) { + hitf = FALSE; + } else { + /* check if this point is visible in the viewport */ + float p1[3], lambda1; + + /* if face isn't planer, p may be behind the current tesselated tri, + so move it onto that and then a little towards eye */ + if (isect_line_tri_v3(p, view, ls[0]->v->co, ls[1]->v->co, ls[2]->v->co, &lambda1, NULL)) { + interp_v3_v3v3(p1, p, view, lambda1); + } else { + copy_v3_v3(p1, p); } + sub_v3_v3(view, p1); + normalize_v3(view); - knife_project_v3(kcd, p, sp); - view3d_unproject(mats, view, sp[0], sp[1], 0.0f); - mul_m4_v3(kcd->ob->imat, view); + copy_v3_v3(no, view); + mul_v3_fl(no, 0.003); - if (kcd->cut_through) { - hitf = FALSE; - } - else { - /* check if this point is visible in the viewport */ - sub_v3_v3(view, p); - normalize_v3(view); + /* go towards view a bit */ + add_v3_v3(p1, no); + + /* ray cast */ + hitf = BMBVH_RayCast(bmtree, p1, no, NULL, NULL); + } - copy_v3_v3(no, view); - mul_v3_fl(no, 0.003); + /* ok, if visible add the new point */ + if (!hitf && !BLI_smallhash_haskey(ehash, (intptr_t)kfe)) { + BMEdgeHit hit; + + if (len_squared_v3v3(p, kcd->cur.co) < depsilon_squared || + len_squared_v3v3(p, kcd->prev.co) < depsilon_squared) + continue; - /* go towards view a bit */ - add_v3_v3(p, no); + hit.kfe = kfe; + hit.v = NULL; - /* ray cast */ - hitf = BMBVH_RayCast(bmtree, p, no, NULL, NULL); - } + knife_find_basef(kfe); + hit.f = kfe->basef; + hit.perc = len_v3v3(p, kfe->v1->cageco) / len_v3v3(kfe->v1->cageco, kfe->v2->cageco); + copy_v3_v3(hit.cagehit, p); - /* ok, if visible add the new point */ - if (!hitf && !BLI_smallhash_haskey(ehash, (intptr_t)kfe)) { - BMEdgeHit hit; - - if (len_squared_v3v3(p, kcd->cur.co) < depsilon_squared || - len_squared_v3v3(p, kcd->prev.co) < depsilon_squared) - { - continue; - } + interp_v3_v3v3(p, kfe->v1->co, kfe->v2->co, hit.perc); + copy_v3_v3(hit.realhit, p); - hit.kfe = kfe; - hit.v = NULL; - - knife_find_basef(kfe); - hit.f = kfe->basef; - hit.perc = len_v3v3(p, kfe->v1->cageco) / len_v3v3(kfe->v1->cageco, kfe->v2->cageco); - copy_v3_v3(hit.cagehit, p); - - interp_v3_v3v3(p, kfe->v1->co, kfe->v2->co, hit.perc); - copy_v3_v3(hit.realhit, p); - - /* BMESH_TODO: should also snap to vertices */ - if (kcd->snap_midpoints) { - float perc = hit.perc; - - /* select the closest from the edge endpoints or the midpoint */ - if (perc < 0.25f) { - perc = 0.0f; - } - else if (perc < 0.75f) { - perc = 0.5f; - } - else { - perc = 1.0f; - } - - interp_v3_v3v3(hit.hit, kfe->v1->co, kfe->v2->co, perc); - interp_v3_v3v3(hit.cagehit, kfe->v1->cageco, kfe->v2->cageco, perc); - } - else { - copy_v3_v3(hit.hit, p); + /* BMESH_TODO: should also snap to vertices */ + if (kcd->snap_midpoints) { + float perc = hit.perc; + + /* select the closest from the edge endpoints or the midpoint */ + if (perc < 0.25f) { + perc = 0.0f; + } else if (perc < 0.75f) { + perc = 0.5f; + } else { + perc = 1.0f; } - knife_project_v3(kcd, hit.cagehit, hit.schit); - BLI_array_append(edges, hit); - BLI_smallhash_insert(ehash, (intptr_t)kfe, NULL); + interp_v3_v3v3(hit.hit, kfe->v1->co, kfe->v2->co, perc); + interp_v3_v3v3(hit.cagehit, kfe->v1->cageco, kfe->v2->cageco, perc); + } else { + copy_v3_v3(hit.hit, p); } + knife_project_v3(kcd, hit.cagehit, hit.schit); + + BLI_array_append(edges, hit); + BLI_smallhash_insert(ehash, (intptr_t)kfe, NULL); } } } diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c index 34b281a1c1e..c50726ca9c2 100644 --- a/source/blender/editors/mesh/editmesh_select.c +++ b/source/blender/editors/mesh/editmesh_select.c @@ -2347,7 +2347,7 @@ static int edbm_select_sharp_edges_exec(bContext *C, wmOperator *op) /* edge has exactly two neighboring faces, check angle */ angle = angle_normalized_v3v3(l1->f->no, l2->f->no); - if (fabsf(angle) > sharp) { + if (fabsf(angle) < sharp) { BM_edge_select_set(em->bm, e, TRUE); } diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index 82b218c966b..b701c46a4b2 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -5301,7 +5301,7 @@ void MESH_OT_convex_hull(wmOperatorType *ot) /* api callbacks */ ot->exec = edbm_convex_hull_exec; - ot->poll = EM_view3d_poll; + ot->poll = ED_operator_editmesh; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index 21eab5bd4dc..d90735ca5ac 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -105,6 +105,8 @@ #include "UI_interface.h" #include "UI_resources.h" +#include "GPU_material.h" + #include "object_intern.h" /* this is an exact copy of the define in rna_lamp.c @@ -893,12 +895,24 @@ void OBJECT_OT_group_instance_add(wmOperatorType *ot) /**************************** Delete Object *************************/ +static void object_delete_check_glsl_update(Object *ob) +{ + /* some objects could affect on GLSL shading, make sure GLSL settings + * are being tagged to be updated when object is removing from scene + */ + if (ob->type == OB_LAMP) { + if (ob->gpulamp.first) + GPU_lamp_free(ob); + } +} + /* remove base from a specific scene */ /* note: now unlinks constraints as well */ void ED_base_object_free_and_unlink(Main *bmain, Scene *scene, Base *base) { DAG_id_type_tag(bmain, ID_OB); BLI_remlink(&scene->base, base); + object_delete_check_glsl_update(base->object); BKE_libblock_free_us(&bmain->object, base->object); if (scene->basact == base) scene->basact = NULL; MEM_freeN(base); diff --git a/source/blender/editors/object/object_bake.c b/source/blender/editors/object/object_bake.c index e1c715952d1..2e28db8ad8e 100644 --- a/source/blender/editors/object/object_bake.c +++ b/source/blender/editors/object/object_bake.c @@ -358,7 +358,7 @@ static int multiresbake_test_break(MultiresBakeRender *bkr) return 0; } - return G.afbreek; + return G.is_break; } static void do_multires_bake(MultiresBakeRender *bkr, Image *ima, MPassKnownData passKnownData, @@ -1260,7 +1260,7 @@ static int multiresbake_image_exec(bContext *C, wmOperator *op) WM_jobs_timer(steve, 0.2, NC_IMAGE, 0); /* TODO - only draw bake image, can we enforce this */ WM_jobs_callbacks(steve, multiresbake_startjob, NULL, NULL, NULL); - G.afbreek = 0; + G.is_break = FALSE; WM_jobs_start(CTX_wm_manager(C), steve); WM_cursor_wait(0); @@ -1276,7 +1276,7 @@ static int multiresbake_image_exec(bContext *C, wmOperator *op) /* threaded break test */ static int thread_break(void *UNUSED(arg)) { - return G.afbreek; + return G.is_break; } typedef struct BakeRender { @@ -1401,7 +1401,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.afbreek = 0; /* blender_test_break uses this global */ + G.is_break = FALSE; /* blender_test_break uses this global */ RE_Database_Baking(bkr->re, bmain, scene, scene->lay, scene->r.bake_mode, bkr->actob); @@ -1431,7 +1431,7 @@ static void bake_freejob(void *bkv) BKE_report(bkr->reports, RPT_WARNING, "Feedback loop detected"); MEM_freeN(bkr); - G.rendering = 0; + G.is_rendering = FALSE; } /* catch esc */ @@ -1487,8 +1487,8 @@ static int objects_bake_render_invoke(bContext *C, wmOperator *op, wmEvent *UNUS WM_jobs_timer(steve, 0.2, NC_IMAGE, 0); /* TODO - only draw bake image, can we enforce this */ WM_jobs_callbacks(steve, bake_startjob, NULL, bake_update, NULL); - G.afbreek = 0; - G.rendering = 1; + G.is_break = FALSE; + G.is_rendering = TRUE; WM_jobs_start(CTX_wm_manager(C), steve); @@ -1528,7 +1528,7 @@ static int bake_image_exec(bContext *C, wmOperator *op) bkr.reports = op->reports; RE_test_break_cb(bkr.re, NULL, thread_break); - G.afbreek = 0; /* blender_test_break uses this global */ + G.is_break = FALSE; /* 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); diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c index 81639d05d6a..b47269097fb 100644 --- a/source/blender/editors/object/object_modifier.c +++ b/source/blender/editors/object/object_modifier.c @@ -1361,7 +1361,8 @@ void OBJECT_OT_multires_external_save(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL; - WM_operator_properties_filesel(ot, FOLDERFILE | BTXFILE, FILE_SPECIAL, FILE_SAVE, WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH, FILE_DEFAULTDISPLAY); + WM_operator_properties_filesel(ot, FOLDERFILE | BTXFILE, FILE_SPECIAL, FILE_SAVE, + WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH, FILE_DEFAULTDISPLAY); edit_modifier_properties(ot); } @@ -2059,7 +2060,7 @@ static int oceanbake_breakjob(void *UNUSED(customdata)) /* this is not nice yet, need to make the jobs list template better * for identifying/acting upon various different jobs */ /* but for now we'll reuse the render break... */ - return (G.afbreek); + return (G.is_break); } /* called by oceanbake, wmJob sends notifier */ @@ -2082,7 +2083,7 @@ static void oceanbake_startjob(void *customdata, short *stop, short *do_update, oj->do_update = do_update; oj->progress = progress; - G.afbreek = 0; /* XXX shared with render - replace with job 'stop' switch */ + G.is_break = FALSE; /* XXX shared with render - replace with job 'stop' switch */ BKE_bake_ocean(oj->ocean, oj->och, oceanbake_update, (void *)oj); diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c index 28a8b4f3b2d..561ebafc0d7 100644 --- a/source/blender/editors/object/object_relations.c +++ b/source/blender/editors/object/object_relations.c @@ -47,6 +47,7 @@ #include "DNA_speaker_types.h" #include "DNA_world_types.h" #include "DNA_object_types.h" +#include "DNA_vfont_types.h" #include "BLI_math.h" #include "BLI_listbase.h" @@ -1284,20 +1285,21 @@ enum { MAKE_LINKS_ANIMDATA, MAKE_LINKS_GROUP, MAKE_LINKS_DUPLIGROUP, - MAKE_LINKS_MODIFIERS + MAKE_LINKS_MODIFIERS, + MAKE_LINKS_FONTS }; /* Return 1 if make link data is allow, zero otherwise */ -static int allow_make_links_data(const int type, Object *ob, Object *obt) +static int allow_make_links_data(const int type, Object *ob_src, Object *ob_dst) { switch (type) { case MAKE_LINKS_OBDATA: - if (ob->type == obt->type && ob->type != OB_EMPTY) + if (ob_src->type == ob_dst->type && ob_src->type != OB_EMPTY) return 1; break; case MAKE_LINKS_MATERIALS: - if (OB_TYPE_SUPPORT_MATERIAL(ob->type) && - OB_TYPE_SUPPORT_MATERIAL(obt->type)) + if (OB_TYPE_SUPPORT_MATERIAL(ob_src->type) && + OB_TYPE_SUPPORT_MATERIAL(ob_dst->type)) { return 1; } @@ -1307,9 +1309,17 @@ static int allow_make_links_data(const int type, Object *ob, Object *obt) case MAKE_LINKS_DUPLIGROUP: return 1; case MAKE_LINKS_MODIFIERS: - if (ob->type != OB_EMPTY && obt->type != OB_EMPTY) + if (ob_src->type != OB_EMPTY && ob_dst->type != OB_EMPTY) return 1; break; + case MAKE_LINKS_FONTS: + if ((ob_src->data != ob_dst->data) && + (ob_src->type == OB_FONT) && + (ob_dst->type == OB_FONT)) + { + return 1; + } + break; } return 0; } @@ -1393,6 +1403,27 @@ static int make_links_data_exec(bContext *C, wmOperator *op) BKE_object_link_modifiers(ob_dst, ob_src); ob_dst->recalc |= OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME; break; + case MAKE_LINKS_FONTS: + { + Curve *cu_src = ob_src->data; + Curve *cu_dst = ob_dst->data; + + if (cu_dst->vfont) cu_dst->vfont->id.us--; + cu_dst->vfont = cu_src->vfont; + id_us_plus((ID *)cu_dst->vfont); + if (cu_dst->vfontb) cu_dst->vfontb->id.us--; + cu_dst->vfontb = cu_src->vfontb; + id_us_plus((ID *)cu_dst->vfontb); + if (cu_dst->vfonti) cu_dst->vfonti->id.us--; + cu_dst->vfonti = cu_src->vfonti; + id_us_plus((ID *)cu_dst->vfonti); + if (cu_dst->vfontbi) cu_dst->vfontbi->id.us--; + cu_dst->vfontbi = cu_src->vfontbi; + id_us_plus((ID *)cu_dst->vfontbi); + + ob_dst->recalc |= OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME; + break; + } } } } @@ -1449,6 +1480,7 @@ void OBJECT_OT_make_links_data(wmOperatorType *ot) {MAKE_LINKS_GROUP, "GROUPS", 0, "Group", ""}, {MAKE_LINKS_DUPLIGROUP, "DUPLIGROUP", 0, "DupliGroup", ""}, {MAKE_LINKS_MODIFIERS, "MODIFIERS", 0, "Modifiers", ""}, + {MAKE_LINKS_FONTS, "FONTS", 0, "Fonts", ""}, {0, NULL, 0, NULL, NULL}}; /* identifiers */ diff --git a/source/blender/editors/object/object_select.c b/source/blender/editors/object/object_select.c index c83331a8eb7..ac3210348de 100644 --- a/source/blender/editors/object/object_select.c +++ b/source/blender/editors/object/object_select.c @@ -236,11 +236,13 @@ static int object_select_all_by_obdata(bContext *C, void *obdata) CTX_DATA_BEGIN (C, Base *, base, visible_bases) { - if (base->object->data == obdata) { - base->flag |= SELECT; - base->object->flag = base->flag; + if ((base->flag & SELECT) == 0) { + if (base->object->data == obdata) { + base->flag |= SELECT; + base->object->flag = base->flag; - changed = TRUE; + changed = TRUE; + } } } CTX_DATA_END; @@ -254,50 +256,56 @@ static int object_select_all_by_material_texture(bContext *C, int use_texture, M CTX_DATA_BEGIN (C, Base *, base, visible_bases) { - Object *ob = base->object; - Material *mat1; - int a, b; + if ((base->flag & SELECT) == 0) { + Object *ob = base->object; + Material *mat1; + int a, b; - for (a = 1; a <= ob->totcol; a++) { - mat1 = give_current_material(ob, a); + for (a = 1; a <= ob->totcol; a++) { + mat1 = give_current_material(ob, a); - if (!use_texture) { - if (mat1 == mat) { - base->flag |= SELECT; - changed = TRUE; + if (!use_texture) { + if (mat1 == mat) { + base->flag |= SELECT; + changed = TRUE; + } } - } - else if (mat1 && use_texture) { - for (b = 0; b < MAX_MTEX; b++) { - if (mat1->mtex[b]) { - if (tex == mat1->mtex[b]->tex) { - base->flag |= SELECT; - changed = TRUE; - break; + else if (mat1 && use_texture) { + for (b = 0; b < MAX_MTEX; b++) { + if (mat1->mtex[b]) { + if (tex == mat1->mtex[b]->tex) { + base->flag |= SELECT; + changed = TRUE; + break; + } } } } } - } - base->object->flag = base->flag; + base->object->flag = base->flag; + } } CTX_DATA_END; return changed; } -static int object_select_all_by_dup_group(bContext *C, Group *dup_group) +static int object_select_all_by_dup_group(bContext *C, Object *ob) { int changed = FALSE; + Group *dup_group = (ob->transflag & OB_DUPLIGROUP) ? ob->dup_group : NULL; CTX_DATA_BEGIN (C, Base *, base, visible_bases) { - if (base->object->dup_group == dup_group) { - base->flag |= SELECT; - base->object->flag = base->flag; + if ((base->flag & SELECT) == 0) { + Group *dup_group_other = (base->object->transflag & OB_DUPLIGROUP) ? base->object->dup_group : NULL; + if (dup_group == dup_group_other) { + base->flag |= SELECT; + base->object->flag = base->flag; - changed = TRUE; + changed = TRUE; + } } } CTX_DATA_END; @@ -311,25 +319,27 @@ static int object_select_all_by_particle(bContext *C, Object *ob) CTX_DATA_BEGIN (C, Base *, base, visible_bases) { - /* loop through other, then actives particles*/ - ParticleSystem *psys; - ParticleSystem *psys_act; - - for (psys = base->object->particlesystem.first; psys; psys = psys->next) { - for (psys_act = ob->particlesystem.first; psys_act; psys_act = psys_act->next) { - if (psys->part == psys_act->part) { - base->flag |= SELECT; - changed = TRUE; + if ((base->flag & SELECT) == 0) { + /* loop through other, then actives particles*/ + ParticleSystem *psys; + ParticleSystem *psys_act; + + for (psys = base->object->particlesystem.first; psys; psys = psys->next) { + for (psys_act = ob->particlesystem.first; psys_act; psys_act = psys_act->next) { + if (psys->part == psys_act->part) { + base->flag |= SELECT; + changed = TRUE; + break; + } + } + + if (base->flag & SELECT) { break; } } - if (base->flag & SELECT) { - break; - } + base->object->flag = base->flag; } - - base->object->flag = base->flag; } CTX_DATA_END; @@ -342,11 +352,13 @@ static int object_select_all_by_library(bContext *C, Library *lib) CTX_DATA_BEGIN (C, Base *, base, visible_bases) { - if (lib == base->object->id.lib) { - base->flag |= SELECT; - base->object->flag = base->flag; + if ((base->flag & SELECT) == 0) { + if (lib == base->object->id.lib) { + base->flag |= SELECT; + base->object->flag = base->flag; - changed = TRUE; + changed = TRUE; + } } } CTX_DATA_END; @@ -360,11 +372,13 @@ static int object_select_all_by_library_obdata(bContext *C, Library *lib) CTX_DATA_BEGIN (C, Base *, base, visible_bases) { - if (base->object->data && lib == ((ID *)base->object->data)->lib) { - base->flag |= SELECT; - base->object->flag = base->flag; + if ((base->flag & SELECT) == 0) { + if (base->object->data && lib == ((ID *)base->object->data)->lib) { + base->flag |= SELECT; + base->object->flag = base->flag; - changed = TRUE; + changed = TRUE; + } } } CTX_DATA_END; @@ -416,7 +430,7 @@ static int object_select_linked_exec(bContext *C, wmOperator *op) if (nr == OBJECT_SELECT_LINKED_IPO) { // XXX old animation system - //if (ob->ipo==0) return OPERATOR_CANCELLED; + //if (ob->ipo == 0) return OPERATOR_CANCELLED; //object_select_all_by_ipo(C, ob->ipo) return OPERATOR_CANCELLED; } @@ -446,7 +460,7 @@ static int object_select_linked_exec(bContext *C, wmOperator *op) if (ob->dup_group == NULL) return OPERATOR_CANCELLED; - changed = object_select_all_by_dup_group(C, ob->dup_group); + changed = object_select_all_by_dup_group(C, ob); } else if (nr == OBJECT_SELECT_LINKED_PARTICLE) { if (ob->particlesystem.first == NULL) diff --git a/source/blender/editors/physics/dynamicpaint_ops.c b/source/blender/editors/physics/dynamicpaint_ops.c index ea8718f0e66..bc09df734a6 100644 --- a/source/blender/editors/physics/dynamicpaint_ops.c +++ b/source/blender/editors/physics/dynamicpaint_ops.c @@ -369,7 +369,7 @@ static int dynamicPaint_initBake(struct bContext *C, struct wmOperator *op) /* Set state to baking and init surface */ canvas->error[0] = '\0'; canvas->flags |= MOD_DPAINT_BAKING; - G.afbreek= 0; /* reset blender_test_break*/ + G.is_break = FALSE; /* reset blender_test_break*/ /* Bake Dynamic Paint */ status = dynamicPaint_bakeImageSequence(C, surface, ob); diff --git a/source/blender/editors/physics/physics_fluid.c b/source/blender/editors/physics/physics_fluid.c index dc2f70189e7..1c4a4314d45 100644 --- a/source/blender/editors/physics/physics_fluid.c +++ b/source/blender/editors/physics/physics_fluid.c @@ -745,7 +745,7 @@ static int fluidbake_breakjob(void *customdata) /* this is not nice yet, need to make the jobs list template better * for identifying/acting upon various different jobs */ /* but for now we'll reuse the render break... */ - return (G.afbreek); + return (G.is_break); } /* called by fluidbake, wmJob sends notifier */ @@ -765,7 +765,7 @@ static void fluidbake_startjob(void *customdata, short *stop, short *do_update, fb->do_update = do_update; fb->progress = progress; - G.afbreek= 0; /* XXX shared with render - replace with job 'stop' switch */ + G.is_break = FALSE; /* XXX shared with render - replace with job 'stop' switch */ elbeemSimulate(); *do_update = TRUE; diff --git a/source/blender/editors/physics/physics_pointcache.c b/source/blender/editors/physics/physics_pointcache.c index c935cb7da82..6e772f66a6a 100644 --- a/source/blender/editors/physics/physics_pointcache.c +++ b/source/blender/editors/physics/physics_pointcache.c @@ -61,7 +61,7 @@ static int cache_break_test(void *UNUSED(cbd)) { - return G.afbreek==1; + return (G.is_break == TRUE); } static int ptcache_bake_all_poll(bContext *C) { diff --git a/source/blender/editors/render/render_internal.c b/source/blender/editors/render/render_internal.c index b1776894959..8a61af61239 100644 --- a/source/blender/editors/render/render_internal.c +++ b/source/blender/editors/render/render_internal.c @@ -213,7 +213,7 @@ static int screen_render_exec(bContext *C, wmOperator *op) re = RE_NewRender(scene->id.name); lay = (v3d) ? v3d->lay : scene->lay; - G.afbreek = 0; + G.is_break = FALSE; RE_test_break_cb(re, NULL, (int (*)(void *))blender_test_break); ima = BKE_image_verify_viewer(IMA_TYPE_R_RESULT, "Render Result"); @@ -224,7 +224,7 @@ static int screen_render_exec(bContext *C, wmOperator *op) * otherwise, invalidated cache entries can make their way into * the output rendering. We can't put that into RE_BlenderFrame, * since sequence rendering can call that recursively... (peter) */ - seq_stripelem_cache_cleanup(); + BKE_sequencer_cache_cleanup(); RE_SetReports(re, op->reports); @@ -427,7 +427,7 @@ static void render_endjob(void *rjv) } /* XXX render stability hack */ - G.rendering = 0; + G.is_rendering = FALSE; WM_main_add_notifier(NC_WINDOW, NULL); } @@ -436,7 +436,7 @@ static int render_breakjob(void *rjv) { RenderJob *rj = rjv; - if (G.afbreek) + if (G.is_break) return 1; if (rj->stop && *(rj->stop)) return 1; @@ -505,7 +505,7 @@ static int screen_render_invoke(bContext *C, wmOperator *op, wmEvent *event) WM_jobs_stop_all(CTX_wm_manager(C)); /* get main */ - if (G.rt == 101) { + if (G.debug_value == 101) { /* thread-safety experiment, copy main from the undo buffer */ mainp = BKE_undo_get_main(&scene); } @@ -526,7 +526,7 @@ static int screen_render_invoke(bContext *C, wmOperator *op, wmEvent *event) * otherwise, invalidated cache entries can make their way into * the output rendering. We can't put that into RE_BlenderFrame, * since sequence rendering can call that recursively... (peter) */ - seq_stripelem_cache_cleanup(); + BKE_sequencer_cache_cleanup(); /* get editmode results */ ED_object_exit_editmode(C, 0); /* 0 = does not exit editmode */ @@ -584,7 +584,7 @@ static int screen_render_invoke(bContext *C, wmOperator *op, wmEvent *event) RE_progress_cb(re, rj, render_progress_update); rj->re = re; - G.afbreek = 0; + G.is_break = FALSE; /* store actual owner of job, so modal operator could check for it, * the reason of this is that active scene could change when rendering @@ -597,10 +597,10 @@ static int screen_render_invoke(bContext *C, wmOperator *op, wmEvent *event) WM_cursor_wait(0); WM_event_add_notifier(C, NC_SCENE | ND_RENDER_RESULT, scene); - /* we set G.rendering here already instead of only in the job, this ensure + /* we set G.is_rendering here already instead of only in the job, this ensure * main loop or other scene updates are disabled in time, since they may * have started before the job thread */ - G.rendering = 1; + G.is_rendering = TRUE; /* add modal handler for ESC */ WM_event_add_modal_handler(C, op); diff --git a/source/blender/editors/render/render_opengl.c b/source/blender/editors/render/render_opengl.c index 12f1e09f5be..d705799b1d8 100644 --- a/source/blender/editors/render/render_opengl.c +++ b/source/blender/editors/render/render_opengl.c @@ -138,9 +138,9 @@ static void screen_opengl_render_apply(OGLRender *oglrender) SeqRenderData context; int chanshown = oglrender->sseq ? oglrender->sseq->chanshown : 0; - context = seq_new_render_data(oglrender->bmain, scene, oglrender->sizex, oglrender->sizey, 100.0f); + context = BKE_sequencer_new_render_data(oglrender->bmain, scene, oglrender->sizex, oglrender->sizey, 100.0f); - ibuf = give_ibuf_seq(context, CFRA, chanshown); + ibuf = BKE_sequencer_give_ibuf(context, CFRA, chanshown); if (ibuf) { BLI_assert((oglrender->sizex == ibuf->x) && (oglrender->sizey == ibuf->y)); diff --git a/source/blender/editors/render/render_preview.c b/source/blender/editors/render/render_preview.c index 6357cb48a3d..c7f48154970 100644 --- a/source/blender/editors/render/render_preview.c +++ b/source/blender/editors/render/render_preview.c @@ -683,7 +683,7 @@ static void shader_preview_render(ShaderPreview *sp, ID *id, int split, int firs if (ELEM(sp->pr_method, PR_BUTS_RENDER, PR_NODE_RENDER)) { RE_display_draw_cb(re, sp, shader_preview_draw); } - /* set this for all previews, default is react to G.afbreek still */ + /* set this for all previews, default is react to G.is_break still */ RE_test_break_cb(re, sp, shader_preview_break); /* lens adjust */ @@ -705,7 +705,7 @@ static void shader_preview_render(ShaderPreview *sp, ID *id, int split, int firs } else { /* validate owner */ - //if (ri->rect==NULL) + //if (ri->rect == NULL) // ri->rect= MEM_mallocN(sizeof(int)*ri->pr_rectx*ri->pr_recty, "BIF_previewrender"); //RE_ResultGet32(re, ri->rect); } diff --git a/source/blender/editors/render/render_shading.c b/source/blender/editors/render/render_shading.c index 53f395f494b..b1b27e1424a 100644 --- a/source/blender/editors/render/render_shading.c +++ b/source/blender/editors/render/render_shading.c @@ -1365,7 +1365,8 @@ void TEXTURE_OT_envmap_save(wmOperatorType *ot) prop = RNA_def_float_array(ot->srna, "layout", 12, default_envmap_layout, 0.0f, 0.0f, "File layout", "Flat array describing the X,Y position of each cube face in the output image, where 1 is the size of a face - order is [+Z -Z +Y -X -Y +X] (use -1 to skip a face)", 0.0f, 0.0f); RNA_def_property_flag(prop, PROP_HIDDEN); - WM_operator_properties_filesel(ot, FOLDERFILE | IMAGEFILE | MOVIEFILE, FILE_SPECIAL, FILE_SAVE, WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY); + WM_operator_properties_filesel(ot, FOLDERFILE | IMAGEFILE | MOVIEFILE, FILE_SPECIAL, FILE_SAVE, + WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY); } static int envmap_clear_exec(bContext *C, wmOperator *UNUSED(op)) diff --git a/source/blender/editors/render/render_view.c b/source/blender/editors/render/render_view.c index 0d902722183..01c0169eb50 100644 --- a/source/blender/editors/render/render_view.c +++ b/source/blender/editors/render/render_view.c @@ -297,7 +297,7 @@ static int render_view_show_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent /* determine if render already shows */ if (sa) { /* but don't close it when rendering */ - if (!G.rendering) { + if (G.is_rendering == FALSE) { SpaceImage *sima = sa->spacedata.first; if (sima->flag & SI_PREVSPACE) { diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c index f8ca150e28e..293af4357d4 100644 --- a/source/blender/editors/screen/area.c +++ b/source/blender/editors/screen/area.c @@ -107,7 +107,7 @@ void ED_region_pixelspace(ARegion *ar) int width = ar->winrct.xmax - ar->winrct.xmin + 1; int height = ar->winrct.ymax - ar->winrct.ymin + 1; - wmOrtho2(-0.375f, (float)width - 0.375f, -0.375f, (float)height - 0.375f); + wmOrtho2(-GLA_PIXEL_OFS, (float)width - GLA_PIXEL_OFS, -GLA_PIXEL_OFS, (float)height - GLA_PIXEL_OFS); glLoadIdentity(); } @@ -167,6 +167,9 @@ void ED_area_overdraw_flush(ScrArea *sa, ARegion *ar) } } +/** + * \brief Corner widgets use for dragging and splitting the view. + */ static void area_draw_azone(short x1, short y1, short x2, short y2) { int dx = x2 - x1; @@ -372,11 +375,11 @@ void ED_area_overdraw(bContext *C) if (az->ar) { /* only display tab or icons when the region is hidden */ if (az->ar->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)) { - if (G.rt == 3) + if (G.debug_value == 3) region_draw_azone_icon(az); - else if (G.rt == 2) + else if (G.debug_value == 2) region_draw_azone_tria(az); - else if (G.rt == 1) + else if (G.debug_value == 1) region_draw_azone_tab(az); else region_draw_azone_tab_plus(az); @@ -592,13 +595,17 @@ void ED_area_headerprint(ScrArea *sa, const char *str) /* ************************************************************ */ -static void area_azone_initialize(ScrArea *sa) +static void area_azone_initialize(bScreen *screen, ScrArea *sa) { AZone *az; /* reinitalize entirely, regions add azones too */ BLI_freelistN(&sa->actionzones); - + + if (screen->full != SCREENNORMAL) { + return; + } + /* set area action zones */ az = (AZone *)MEM_callocN(sizeof(AZone), "actionzone"); BLI_addtail(&(sa->actionzones), az); @@ -858,11 +865,11 @@ static void region_azone_initialize(ScrArea *sa, ARegion *ar, AZEdge edge) az->edge = edge; if (ar->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)) { - if (G.rt == 3) + if (G.debug_value == 3) region_azone_icon(sa, az, ar); - else if (G.rt == 2) + else if (G.debug_value == 2) region_azone_tria(sa, az, ar); - else if (G.rt == 1) + else if (G.debug_value == 1) region_azone_tab(sa, az, ar); else region_azone_tab_plus(sa, az, ar); @@ -1113,7 +1120,7 @@ static void region_rect_recursive(ScrArea *sa, ARegion *ar, rcti *remainder, int static void area_calc_totrct(ScrArea *sa, int sizex, int sizey) { - short rt = 0; // CLAMPIS(G.rt, 0, 16); + short rt = 0; // CLAMPIS(G.debug_value, 0, 16); if (sa->v1->vec.x > 0) sa->totrct.xmin = sa->v1->vec.x + 1 + rt; else sa->totrct.xmin = sa->v1->vec.x; @@ -1219,7 +1226,7 @@ void ED_area_initialize(wmWindowManager *wm, wmWindow *win, ScrArea *sa) area_calc_totrct(sa, win->sizex, win->sizey); /* clear all azones, add the area triange widgets */ - area_azone_initialize(sa); + area_azone_initialize(win->screen, sa); /* region rect sizes */ rect = sa->totrct; @@ -1297,7 +1304,7 @@ void area_copy_data(ScrArea *sa1, ScrArea *sa2, int swap_space) if (swap_space == 1) { SWAP(ListBase, sa1->spacedata, sa2->spacedata); /* exception: ensure preview is reset */ -// if (sa1->spacetype==SPACE_VIEW3D) +// if (sa1->spacetype == SPACE_VIEW3D) // XXX BIF_view3d_previewrender_free(sa1->spacedata.first); } else if (swap_space == 2) { diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c index 5296c8615ab..a534124d2c0 100644 --- a/source/blender/editors/screen/glutil.c +++ b/source/blender/editors/screen/glutil.c @@ -674,7 +674,7 @@ void glaDefine2DArea(rcti *screen_rect) glViewport(screen_rect->xmin, screen_rect->ymin, sc_w, sc_h); glScissor(screen_rect->xmin, screen_rect->ymin, sc_w, sc_h); - /* The 0.375 magic number is to shift the matrix so that + /* The GLA_PIXEL_OFS magic number is to shift the matrix so that * both raster and vertex integer coordinates fall at pixel * centers properly. For a longer discussion see the OpenGL * Programming Guide, Appendix H, Correctness Tips. @@ -683,7 +683,7 @@ void glaDefine2DArea(rcti *screen_rect) glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, sc_w, 0.0, sc_h, -1, 1); - glTranslatef(0.375, 0.375, 0.0); + glTranslatef(GLA_PIXEL_OFS, GLA_PIXEL_OFS, 0.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); diff --git a/source/blender/editors/screen/screen_edit.c b/source/blender/editors/screen/screen_edit.c index 48532c83e4c..d1458fec94b 100644 --- a/source/blender/editors/screen/screen_edit.c +++ b/source/blender/editors/screen/screen_edit.c @@ -913,7 +913,7 @@ static void drawscredge_area(ScrArea *sa, int sizex, int sizey, int center) short y2 = sa->v3->vec.y; short a, rt; - rt = 0; // CLAMPIS(G.rt, 0, 16); + rt = 0; // CLAMPIS(G.debug_value, 0, 16); if (center == 0) { cpack(0x505050); @@ -1483,7 +1483,7 @@ void ED_screen_set_scene(bContext *C, bScreen *screen, Scene *scene) if (!v3d->camera || !BKE_scene_base_find(scene, v3d->camera)) { v3d->camera = BKE_scene_camera_find(sc->scene); - // XXX if (sc==curscreen) handle_view3d_lock(); + // XXX if (sc == curscreen) handle_view3d_lock(); if (!v3d->camera) { ARegion *ar; for (ar = v3d->regionbase.first; ar; ar = ar->next) { diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index 36353c43cbd..e92f7b7a3c2 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -119,7 +119,7 @@ int ED_operator_screenactive(bContext *C) /* XXX added this to prevent anim state to change during renders */ static int ED_operator_screenactive_norender(bContext *C) { - if (G.rendering) return 0; + if (G.is_rendering) return 0; if (CTX_wm_window(C) == NULL) return 0; if (CTX_wm_screen(C) == NULL) return 0; return 1; @@ -3262,11 +3262,7 @@ static void SCREEN_OT_border_select(wmOperatorType *ot) /* rna */ RNA_def_int(ot->srna, "event_type", 0, INT_MIN, INT_MAX, "Event Type", "", INT_MIN, INT_MAX); - RNA_def_int(ot->srna, "xmin", 0, INT_MIN, INT_MAX, "X Min", "", INT_MIN, INT_MAX); - RNA_def_int(ot->srna, "xmax", 0, INT_MIN, INT_MAX, "X Max", "", INT_MIN, INT_MAX); - RNA_def_int(ot->srna, "ymin", 0, INT_MIN, INT_MAX, "Y Min", "", INT_MIN, INT_MAX); - RNA_def_int(ot->srna, "ymax", 0, INT_MIN, INT_MAX, "Y Max", "", INT_MIN, INT_MAX); - + WM_operator_properties_border(ot); } #endif diff --git a/source/blender/editors/screen/screendump.c b/source/blender/editors/screen/screendump.c index 77289360f98..79ff516b362 100644 --- a/source/blender/editors/screen/screendump.c +++ b/source/blender/editors/screen/screendump.c @@ -266,7 +266,8 @@ void SCREEN_OT_screenshot(wmOperatorType *ot) ot->flag = 0; - WM_operator_properties_filesel(ot, FOLDERFILE | IMAGEFILE, FILE_SPECIAL, FILE_SAVE, WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY); + WM_operator_properties_filesel(ot, FOLDERFILE | IMAGEFILE, FILE_SPECIAL, FILE_SAVE, + WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY); RNA_def_boolean(ot->srna, "full", 1, "Full Screen", "Screenshot the whole Blender window"); } diff --git a/source/blender/editors/sculpt_paint/paint_hide.c b/source/blender/editors/sculpt_paint/paint_hide.c index 89c328e71d8..e809267d076 100644 --- a/source/blender/editors/sculpt_paint/paint_hide.c +++ b/source/blender/editors/sculpt_paint/paint_hide.c @@ -398,8 +398,5 @@ void PAINT_OT_hide_show(struct wmOperatorType *ot) RNA_def_enum(ot->srna, "area", area_items, PARTIALVIS_INSIDE, "Area", "Which vertices to hide or show"); - RNA_def_int(ot->srna, "xmin", 0, INT_MIN, INT_MAX, "X Min", "", INT_MIN, INT_MAX); - RNA_def_int(ot->srna, "xmax", 0, INT_MIN, INT_MAX, "X Max", "", INT_MIN, INT_MAX); - RNA_def_int(ot->srna, "ymin", 0, INT_MIN, INT_MAX, "Y Min", "", INT_MIN, INT_MAX); - RNA_def_int(ot->srna, "ymax", 0, INT_MIN, INT_MAX, "Y Max", "", INT_MIN, INT_MAX); + WM_operator_properties_border(ot); } diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index 306724de301..05cc958aa43 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -801,7 +801,7 @@ static int project_paint_PickColor(const ProjPaintState *ps, float pt[2], float if (rgba_fp) { if (ibuf->rect_float) { - copy_v4_v4(rgba_fp, ((float *)ibuf->rect_float + ((xi + yi * ibuf->x) * 4))); + copy_v4_v4(rgba_fp, (ibuf->rect_float + ((xi + yi * ibuf->x) * 4))); } else { char *tmp_ch = ((char *)ibuf->rect) + ((xi + yi * ibuf->x) * 4); @@ -1461,7 +1461,7 @@ static float project_paint_uvpixel_mask( /* This only works when the opacity dosnt change while painting, stylus pressure messes with this * so don't use it. */ - // if (ps->is_airbrush==0) mask *= BKE_brush_alpha_get(ps->brush); + // if (ps->is_airbrush == 0) mask *= BKE_brush_alpha_get(ps->brush); return mask; } @@ -1503,7 +1503,7 @@ static ProjPixel *project_paint_uvpixel_init( //memset(projPixel, 0, size); if (ibuf->rect_float) { - projPixel->pixel.f_pt = (float *)ibuf->rect_float + ((x_px + y_px * ibuf->x) * 4); + projPixel->pixel.f_pt = ibuf->rect_float + ((x_px + y_px * ibuf->x) * 4); projPixel->origColor.f[0] = projPixel->newColor.f[0] = projPixel->pixel.f_pt[0]; projPixel->origColor.f[1] = projPixel->newColor.f[1] = projPixel->pixel.f_pt[1]; projPixel->origColor.f[2] = projPixel->newColor.f[2] = projPixel->pixel.f_pt[2]; diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c index 3f9e0051d2e..99bc192042c 100644 --- a/source/blender/editors/sculpt_paint/paint_utils.c +++ b/source/blender/editors/sculpt_paint/paint_utils.c @@ -13,7 +13,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. * All rights reserved. @@ -177,15 +177,10 @@ float paint_calc_object_space_radius(ViewContext *vc, const float center[3], float paint_get_tex_pixel(Brush *br, float u, float v) { - TexResult texres; - float co[3]; + TexResult texres = {0}; + float co[3] = {u, v, 0.0f}; int hasrgb; - co[0] = u; - co[1] = v; - co[2] = 0; - - memset(&texres, 0, sizeof(TexResult)); hasrgb = multitex_ext(br->mtex.tex, co, NULL, NULL, 0, &texres); if (hasrgb & TEX_RGB) diff --git a/source/blender/editors/sound/sound_ops.c b/source/blender/editors/sound/sound_ops.c index 9827ffdc324..aaa1328f9f6 100644 --- a/source/blender/editors/sound/sound_ops.c +++ b/source/blender/editors/sound/sound_ops.c @@ -186,7 +186,8 @@ static void SOUND_OT_open(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ - WM_operator_properties_filesel(ot, FOLDERFILE | SOUNDFILE | MOVIEFILE, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH, FILE_DEFAULTDISPLAY); + WM_operator_properties_filesel(ot, FOLDERFILE | SOUNDFILE | MOVIEFILE, FILE_SPECIAL, FILE_OPENFILE, + WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH, FILE_DEFAULTDISPLAY); RNA_def_boolean(ot->srna, "cache", FALSE, "Cache", "Cache the sound in memory"); RNA_def_boolean(ot->srna, "mono", FALSE, "Mono", "Mixdown the sound to mono"); } @@ -207,7 +208,8 @@ static void SOUND_OT_open_mono(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ - WM_operator_properties_filesel(ot, FOLDERFILE | SOUNDFILE | MOVIEFILE, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH, FILE_DEFAULTDISPLAY); + WM_operator_properties_filesel(ot, FOLDERFILE | SOUNDFILE | MOVIEFILE, FILE_SPECIAL, FILE_OPENFILE, + WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH, FILE_DEFAULTDISPLAY); RNA_def_boolean(ot->srna, "cache", FALSE, "Cache", "Cache the sound in memory"); RNA_def_boolean(ot->srna, "mono", TRUE, "Mono", "Mixdown the sound to mono"); } @@ -659,7 +661,8 @@ static void SOUND_OT_mixdown(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER; /* properties */ - WM_operator_properties_filesel(ot, FOLDERFILE | SOUNDFILE, FILE_SPECIAL, FILE_SAVE, WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH, FILE_DEFAULTDISPLAY); + WM_operator_properties_filesel(ot, FOLDERFILE | SOUNDFILE, FILE_SPECIAL, FILE_SAVE, + WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH, FILE_DEFAULTDISPLAY); #ifdef WITH_AUDASPACE RNA_def_int(ot->srna, "accuracy", 1024, 1, 16777216, "Accuracy", "Sample accuracy, important for animation data (the lower the value, the more accurate)", 1, 16777216); RNA_def_enum(ot->srna, "container", container_items, AUD_CONTAINER_FLAC, "Container", "File format"); @@ -698,7 +701,7 @@ static int sound_pack_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; sound->packedfile = newPackedFile(op->reports, sound->name, ID_BLEND_PATH(bmain, &sound->id)); - sound_load(CTX_data_main(C), sound); + sound_load(bmain, sound); return OPERATOR_FINISHED; } @@ -722,6 +725,7 @@ static void SOUND_OT_pack(wmOperatorType *ot) static int sound_unpack_exec(bContext *C, wmOperator *op) { + Main *bmain = CTX_data_main(C); int method = RNA_enum_get(op->ptr, "method"); bSound *sound = NULL; @@ -729,7 +733,7 @@ static int sound_unpack_exec(bContext *C, wmOperator *op) if (RNA_struct_property_is_set(op->ptr, "id")) { char sndname[MAX_ID_NAME - 2]; RNA_string_get(op->ptr, "id", sndname); - sound = BLI_findstring(&CTX_data_main(C)->sound, sndname, offsetof(ID, name) + 2); + sound = BLI_findstring(&bmain->sound, sndname, offsetof(ID, name) + 2); } if (!sound || !sound->packedfile) @@ -738,7 +742,7 @@ static int sound_unpack_exec(bContext *C, wmOperator *op) if (G.fileflags & G_AUTOPACK) BKE_report(op->reports, RPT_WARNING, "AutoPack is enabled, so image will be packed again on file save"); - unpackSound(CTX_data_main(C), op->reports, sound, method); + unpackSound(bmain, op->reports, sound, method); return OPERATOR_FINISHED; } diff --git a/source/blender/editors/space_action/action_select.c b/source/blender/editors/space_action/action_select.c index b42c6406362..6b61990d485 100644 --- a/source/blender/editors/space_action/action_select.c +++ b/source/blender/editors/space_action/action_select.c @@ -184,6 +184,7 @@ void ACTION_OT_select_all_toggle(wmOperatorType *ot) /* props */ ot->prop = RNA_def_boolean(ot->srna, "invert", 0, "Invert", ""); + RNA_def_property_flag(ot->prop, PROP_SKIP_SAVE); } /* ******************** Border Select Operator **************************** */ @@ -293,10 +294,7 @@ static int actkeys_borderselect_exec(bContext *C, wmOperator *op) deselect_action_keys(&ac, 1, SELECT_SUBTRACT); /* get settings from operator */ - rect.xmin = RNA_int_get(op->ptr, "xmin"); - rect.ymin = RNA_int_get(op->ptr, "ymin"); - rect.xmax = RNA_int_get(op->ptr, "xmax"); - rect.ymax = RNA_int_get(op->ptr, "ymax"); + WM_operator_properties_border_to_rcti(op, &rect); gesture_mode = RNA_int_get(op->ptr, "gesture_mode"); if (gesture_mode == GESTURE_MODAL_SELECT) @@ -881,6 +879,8 @@ static int actkeys_select_leftright_invoke(bContext *C, wmOperator *op, wmEvent void ACTION_OT_select_leftright(wmOperatorType *ot) { + PropertyRNA *prop; + /* identifiers */ ot->name = "Select Left/Right"; ot->idname = "ACTION_OT_select_leftright"; @@ -894,9 +894,12 @@ void ACTION_OT_select_leftright(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - /* id-props */ + /* properties */ ot->prop = RNA_def_enum(ot->srna, "mode", prop_actkeys_leftright_select_types, ACTKEYS_LRSEL_TEST, "Mode", ""); - RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", ""); + RNA_def_property_flag(ot->prop, PROP_SKIP_SAVE); + + prop = RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", ""); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); } /* ******************** Mouse-Click Select Operator *********************** */ @@ -1233,6 +1236,8 @@ static int actkeys_clickselect_invoke(bContext *C, wmOperator *op, wmEvent *even void ACTION_OT_clickselect(wmOperatorType *ot) { + PropertyRNA *prop; + /* identifiers */ ot->name = "Mouse Select Keys"; ot->idname = "ACTION_OT_clickselect"; @@ -1245,9 +1250,11 @@ void ACTION_OT_clickselect(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - /* id-props */ - RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", ""); // SHIFTKEY - RNA_def_boolean(ot->srna, "column", 0, "Column Select", ""); // ALTKEY + /* properties */ + prop = RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", ""); // SHIFTKEY + RNA_def_property_flag(prop, PROP_SKIP_SAVE); + prop = RNA_def_boolean(ot->srna, "column", 0, "Column Select", ""); // ALTKEY + RNA_def_property_flag(prop, PROP_SKIP_SAVE); } /* ************************************************************************** */ diff --git a/source/blender/editors/space_buttons/buttons_ops.c b/source/blender/editors/space_buttons/buttons_ops.c index c29a8c3934e..c8cf69e3e17 100644 --- a/source/blender/editors/space_buttons/buttons_ops.c +++ b/source/blender/editors/space_buttons/buttons_ops.c @@ -230,7 +230,8 @@ void BUTTONS_OT_file_browse(wmOperatorType *ot) ot->cancel = file_browse_cancel; /* properties */ - WM_operator_properties_filesel(ot, 0, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH, FILE_DEFAULTDISPLAY); + WM_operator_properties_filesel(ot, 0, FILE_SPECIAL, FILE_OPENFILE, + WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH, FILE_DEFAULTDISPLAY); } /* second operator, only difference from BUTTONS_OT_file_browse is WM_FILESEL_DIRECTORY */ @@ -247,5 +248,6 @@ void BUTTONS_OT_directory_browse(wmOperatorType *ot) ot->cancel = file_browse_cancel; /* properties */ - WM_operator_properties_filesel(ot, 0, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_DIRECTORY | WM_FILESEL_RELPATH, FILE_DEFAULTDISPLAY); + WM_operator_properties_filesel(ot, 0, FILE_SPECIAL, FILE_OPENFILE, + WM_FILESEL_DIRECTORY | WM_FILESEL_RELPATH, FILE_DEFAULTDISPLAY); } diff --git a/source/blender/editors/space_clip/clip_graph_ops.c b/source/blender/editors/space_clip/clip_graph_ops.c index c0b11dda5c7..a2cb812d51c 100644 --- a/source/blender/editors/space_clip/clip_graph_ops.c +++ b/source/blender/editors/space_clip/clip_graph_ops.c @@ -353,10 +353,7 @@ static int border_select_graph_exec(bContext *C, wmOperator *op) rcti rect; /* get rectangle from operator */ - rect.xmin = RNA_int_get(op->ptr, "xmin"); - rect.ymin = RNA_int_get(op->ptr, "ymin"); - rect.xmax = RNA_int_get(op->ptr, "xmax"); - rect.ymax = RNA_int_get(op->ptr, "ymax"); + WM_operator_properties_border_to_rcti(op, &rect); UI_view2d_region_to_view(&ar->v2d, rect.xmin, rect.ymin, &userdata.rect.xmin, &userdata.rect.ymin); UI_view2d_region_to_view(&ar->v2d, rect.xmax, rect.ymax, &userdata.rect.xmax, &userdata.rect.ymax); diff --git a/source/blender/editors/space_clip/clip_ops.c b/source/blender/editors/space_clip/clip_ops.c index 20d47063cd4..2313b176073 100644 --- a/source/blender/editors/space_clip/clip_ops.c +++ b/source/blender/editors/space_clip/clip_ops.c @@ -275,8 +275,7 @@ void CLIP_OT_open(wmOperatorType *ot) /* properties */ WM_operator_properties_filesel(ot, FOLDERFILE | IMAGEFILE | MOVIEFILE, FILE_SPECIAL, FILE_OPENFILE, - WM_FILESEL_RELPATH | WM_FILESEL_FILES | WM_FILESEL_DIRECTORY, - FILE_DEFAULTDISPLAY); + WM_FILESEL_RELPATH | WM_FILESEL_FILES | WM_FILESEL_DIRECTORY, FILE_DEFAULTDISPLAY); } /******************* reload clip operator *********************/ @@ -804,7 +803,7 @@ void CLIP_OT_view_selected(wmOperatorType *ot) static int change_frame_poll(bContext *C) { /* prevent changes during render */ - if (G.rendering) + if (G.is_rendering) return 0; return ED_space_clip_poll(C); @@ -1001,7 +1000,7 @@ static void proxy_startjob(void *pjv, short *stop, short *do_update, float *prog BKE_movieclip_build_proxy_frame(clip, pj->clip_flag, distortion, cfra, build_undistort_sizes, build_undistort_count, 1); - if (*stop || G.afbreek) + if (*stop || G.is_break) break; *do_update = TRUE; @@ -1059,7 +1058,7 @@ static int clip_rebuild_proxy_exec(bContext *C, wmOperator *UNUSED(op)) WM_jobs_timer(steve, 0.2, NC_MOVIECLIP | ND_DISPLAY, 0); WM_jobs_callbacks(steve, proxy_startjob, NULL, NULL, proxy_endjob); - G.afbreek = 0; + G.is_break = FALSE; WM_jobs_start(CTX_wm_manager(C), steve); ED_area_tag_redraw(CTX_wm_area(C)); diff --git a/source/blender/editors/space_clip/tracking_ops.c b/source/blender/editors/space_clip/tracking_ops.c index 153287eecdd..4283c6f77c7 100644 --- a/source/blender/editors/space_clip/tracking_ops.c +++ b/source/blender/editors/space_clip/tracking_ops.c @@ -952,7 +952,7 @@ typedef struct TrackMarkersJob { static int track_markers_testbreak(void) { - return G.afbreek; + return G.is_break; } static int track_count_markers(SpaceClip *sc, MovieClip *clip) @@ -1275,7 +1275,7 @@ static int track_markers_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(eve WM_jobs_callbacks(steve, track_markers_startjob, NULL, track_markers_updatejob, NULL); - G.afbreek = 0; + G.is_break = FALSE; WM_jobs_start(CTX_wm_manager(C), steve); WM_cursor_wait(0); @@ -1497,7 +1497,7 @@ static int solve_camera_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(even WM_jobs_timer(steve, 0.1, NC_MOVIECLIP | NA_EVALUATED, 0); WM_jobs_callbacks(steve, solve_camera_startjob, NULL, solve_camera_updatejob, NULL); - G.afbreek = 0; + G.is_break = FALSE; WM_jobs_start(CTX_wm_manager(C), steve); WM_cursor_wait(0); diff --git a/source/blender/editors/space_clip/tracking_select.c b/source/blender/editors/space_clip/tracking_select.c index 559fe8c840d..ea3d1226937 100644 --- a/source/blender/editors/space_clip/tracking_select.c +++ b/source/blender/editors/space_clip/tracking_select.c @@ -348,10 +348,7 @@ static int border_select_exec(bContext *C, wmOperator *op) int framenr = ED_space_clip_get_clip_frame_number(sc); /* get rectangle from operator */ - rect.xmin = RNA_int_get(op->ptr, "xmin"); - rect.ymin = RNA_int_get(op->ptr, "ymin"); - rect.xmax = RNA_int_get(op->ptr, "xmax"); - rect.ymax = RNA_int_get(op->ptr, "ymax"); + WM_operator_properties_border_to_rcti(op, &rect); ED_clip_point_stable_pos(sc, ar, rect.xmin, rect.ymin, &rectf.xmin, &rectf.ymin); ED_clip_point_stable_pos(sc, ar, rect.xmax, rect.ymax, &rectf.xmax, &rectf.ymax); diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 7630143acd1..01962853556 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -243,10 +243,7 @@ static int file_border_select_modal(bContext *C, wmOperator *op, wmEvent *event) if (result == OPERATOR_RUNNING_MODAL) { - rect.xmin = RNA_int_get(op->ptr, "xmin"); - rect.ymin = RNA_int_get(op->ptr, "ymin"); - rect.xmax = RNA_int_get(op->ptr, "xmax"); - rect.ymax = RNA_int_get(op->ptr, "ymax"); + WM_operator_properties_border_to_rcti(op, &rect); BLI_rcti_isect(&(ar->v2d.mask), &rect, &rect); @@ -277,10 +274,7 @@ static int file_border_select_exec(bContext *C, wmOperator *op) int extend = RNA_boolean_get(op->ptr, "extend"); short select = (RNA_int_get(op->ptr, "gesture_mode") == GESTURE_MODAL_SELECT); - rect.xmin = RNA_int_get(op->ptr, "xmin"); - rect.ymin = RNA_int_get(op->ptr, "ymin"); - rect.xmax = RNA_int_get(op->ptr, "xmax"); - rect.ymax = RNA_int_get(op->ptr, "ymax"); + WM_operator_properties_border_to_rcti(op, &rect); if (!extend) { SpaceFile *sfile = CTX_wm_space_file(C); diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index ec16fa539e9..e550c83a2ec 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -383,6 +383,9 @@ void filelist_init_icons(void) short x, y, k; ImBuf *bbuf; ImBuf *ibuf; + + BLI_assert(G.background == FALSE); + #ifdef WITH_HEADLESS bbuf = NULL; #else @@ -408,6 +411,9 @@ void filelist_init_icons(void) void filelist_free_icons(void) { int i; + + BLI_assert(G.background == FALSE); + for (i = 0; i < SPECIAL_IMG_MAX; ++i) { IMB_freeImBuf(gSpecialFileImages[i]); gSpecialFileImages[i] = NULL; @@ -615,7 +621,10 @@ short filelist_changed(struct FileList *filelist) ImBuf *filelist_getimage(struct FileList *filelist, int index) { ImBuf *ibuf = NULL; - int fidx = 0; + int fidx = 0; + + BLI_assert(G.background == FALSE); + if ( (index < 0) || (index >= filelist->numfiltered) ) { return NULL; } @@ -629,7 +638,10 @@ ImBuf *filelist_geticon(struct FileList *filelist, int index) { ImBuf *ibuf = NULL; struct direntry *file = NULL; - int fidx = 0; + int fidx = 0; + + BLI_assert(G.background == FALSE); + if ( (index < 0) || (index >= filelist->numfiltered) ) { return NULL; } diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c index 95d5483b42c..17669dfa8f9 100644 --- a/source/blender/editors/space_file/space_file.c +++ b/source/blender/editors/space_file/space_file.c @@ -48,6 +48,7 @@ #include "BKE_context.h" #include "BKE_screen.h" +#include "BKE_global.h" #include "ED_space_api.h" #include "ED_screen.h" @@ -624,12 +625,18 @@ void ED_file_init(void) fsmenu_read_bookmarks(fsmenu_get(), name); } - filelist_init_icons(); + if (G.background == FALSE) { + filelist_init_icons(); + } + IMB_thumb_makedirs(); } void ED_file_exit(void) { fsmenu_free(fsmenu_get()); - filelist_free_icons(); + + if (G.background == FALSE) { + filelist_free_icons(); + } } diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c index b1e1b6e411a..55dca725131 100644 --- a/source/blender/editors/space_graph/graph_edit.c +++ b/source/blender/editors/space_graph/graph_edit.c @@ -1214,7 +1214,8 @@ void GRAPH_OT_sound_bake(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ - WM_operator_properties_filesel(ot, FOLDERFILE | SOUNDFILE | MOVIEFILE, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY); + WM_operator_properties_filesel(ot, FOLDERFILE | SOUNDFILE | MOVIEFILE, FILE_SPECIAL, FILE_OPENFILE, + WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY); RNA_def_float(ot->srna, "low", 0.0f, 0.0, 100000.0, "Lowest frequency", "", 0.1, 1000.00); RNA_def_float(ot->srna, "high", 100000.0, 0.0, 100000.0, "Highest frequency", "", 0.1, 1000.00); RNA_def_float(ot->srna, "attack", 0.005, 0.0, 2.0, "Attack time", "", 0.01, 0.1); diff --git a/source/blender/editors/space_graph/graph_ops.c b/source/blender/editors/space_graph/graph_ops.c index 62aebcb4edc..d54e3694f07 100644 --- a/source/blender/editors/space_graph/graph_ops.c +++ b/source/blender/editors/space_graph/graph_ops.c @@ -179,7 +179,7 @@ static void GRAPH_OT_cursor_set(wmOperatorType *ot) /* rna */ RNA_def_int(ot->srna, "frame", 0, MINAFRAME, MAXFRAME, "Frame", "", MINAFRAME, MAXFRAME); - RNA_def_float(ot->srna, "value", 0, FLT_MIN, FLT_MAX, "Value", "", -100.0f, 100.0f); + RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Value", "", -100.0f, 100.0f); } /* ************************** registration - operator types **********************************/ diff --git a/source/blender/editors/space_graph/graph_select.c b/source/blender/editors/space_graph/graph_select.c index 52a7f9b115c..781099f6a68 100644 --- a/source/blender/editors/space_graph/graph_select.c +++ b/source/blender/editors/space_graph/graph_select.c @@ -316,10 +316,7 @@ static int graphkeys_borderselect_exec(bContext *C, wmOperator *op) incl_handles = RNA_boolean_get(op->ptr, "include_handles"); /* get settings from operator */ - rect.xmin = RNA_int_get(op->ptr, "xmin"); - rect.ymin = RNA_int_get(op->ptr, "ymin"); - rect.xmax = RNA_int_get(op->ptr, "xmax"); - rect.ymax = RNA_int_get(op->ptr, "ymax"); + WM_operator_properties_border_to_rcti(op, &rect); /* selection 'mode' depends on whether borderselect region only matters on one axis */ if (RNA_boolean_get(op->ptr, "axis_range")) { @@ -848,6 +845,8 @@ static int graphkeys_select_leftright_invoke(bContext *C, wmOperator *op, wmEven void GRAPH_OT_select_leftright(wmOperatorType *ot) { + PropertyRNA *prop; + /* identifiers */ ot->name = "Select Left/Right"; ot->idname = "GRAPH_OT_select_leftright"; @@ -863,7 +862,10 @@ void GRAPH_OT_select_leftright(wmOperatorType *ot) /* id-props */ ot->prop = RNA_def_enum(ot->srna, "mode", prop_graphkeys_leftright_select_types, GRAPHKEYS_LRSEL_TEST, "Mode", ""); - RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", ""); + RNA_def_property_flag(ot->prop, PROP_SKIP_SAVE); + + prop = RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", ""); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); } /* ******************** Mouse-Click Select Operator *********************** */ @@ -1333,6 +1335,8 @@ static int graphkeys_clickselect_invoke(bContext *C, wmOperator *op, wmEvent *ev void GRAPH_OT_clickselect(wmOperatorType *ot) { + PropertyRNA *prop; + /* identifiers */ ot->name = "Mouse Select Keys"; ot->idname = "GRAPH_OT_clickselect"; @@ -1342,10 +1346,17 @@ void GRAPH_OT_clickselect(wmOperatorType *ot) ot->invoke = graphkeys_clickselect_invoke; ot->poll = graphop_visible_keyframes_poll; - /* id-props */ - RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", ""); // SHIFTKEY - RNA_def_boolean(ot->srna, "column", 0, "Column Select", "Select all keyframes that occur on the same frame as the one under the mouse"); // ALTKEY - RNA_def_boolean(ot->srna, "curves", 0, "Only Curves", "Select all the keyframes in the curve"); // CTRLKEY + ALTKEY + /* properties */ + prop = RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", ""); // SHIFTKEY + RNA_def_property_flag(prop, PROP_SKIP_SAVE); + + prop = RNA_def_boolean(ot->srna, "column", 0, "Column Select", + "Select all keyframes that occur on the same frame as the one under the mouse"); // ALTKEY + RNA_def_property_flag(prop, PROP_SKIP_SAVE); + + prop = RNA_def_boolean(ot->srna, "curves", 0, "Only Curves", + "Select all the keyframes in the curve"); // CTRLKEY + ALTKEY + RNA_def_property_flag(prop, PROP_SKIP_SAVE); } /* ************************************************************************** */ diff --git a/source/blender/editors/space_graph/space_graph.c b/source/blender/editors/space_graph/space_graph.c index f4cb4ec3d05..a4611cf1453 100644 --- a/source/blender/editors/space_graph/space_graph.c +++ b/source/blender/editors/space_graph/space_graph.c @@ -488,7 +488,7 @@ static void graph_listener(ScrArea *sa, wmNotifier *wmn) // XXX: restore the case below if not enough updates occur... //default: - // if (wmn->data==ND_KEYS) + // if (wmn->data == ND_KEYS) // ED_area_tag_redraw(sa); } } diff --git a/source/blender/editors/space_image/image_buttons.c b/source/blender/editors/space_image/image_buttons.c index a736cc4cb73..51bd4e16d06 100644 --- a/source/blender/editors/space_image/image_buttons.c +++ b/source/blender/editors/space_image/image_buttons.c @@ -238,7 +238,7 @@ void image_preview_event(int event) ntreeCompositTagGenerators(G.scene->nodetree); - G.afbreek = 0; + G.is_break = FALSE; G.scene->nodetree->timecursor = set_timecursor; G.scene->nodetree->test_break = blender_test_break; diff --git a/source/blender/editors/space_image/image_edit.c b/source/blender/editors/space_image/image_edit.c index c0b6dc656c2..58e6a1aa94a 100644 --- a/source/blender/editors/space_image/image_edit.c +++ b/source/blender/editors/space_image/image_edit.c @@ -371,7 +371,7 @@ int ED_space_image_maskedit_poll(bContext *C) { SpaceImage *sima = CTX_wm_space_image(C); - if (sima && sima->image) { + if (sima) { Scene *scene = CTX_data_scene(C); return ED_space_image_check_show_maskedit(scene, sima); } @@ -382,13 +382,8 @@ int ED_space_image_maskedit_poll(bContext *C) int ED_space_image_maskedit_mask_poll(bContext *C) { if (ED_space_image_maskedit_poll(C)) { - Image *ima = CTX_data_edit_image(C); - - if (ima) { - SpaceImage *sima = CTX_wm_space_image(C); - - return sima->mask_info.mask != NULL; - } + SpaceImage *sima = CTX_wm_space_image(C); + return sima->mask_info.mask != NULL; } return FALSE; diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index aa44caac0af..38a2e9725ff 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -961,7 +961,8 @@ void IMAGE_OT_open(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ - WM_operator_properties_filesel(ot, FOLDERFILE | IMAGEFILE | MOVIEFILE, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH, FILE_DEFAULTDISPLAY); + WM_operator_properties_filesel(ot, FOLDERFILE | IMAGEFILE | MOVIEFILE, FILE_SPECIAL, FILE_OPENFILE, + WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH, FILE_DEFAULTDISPLAY); } /******************** Match movie length operator ********************/ @@ -1073,7 +1074,8 @@ void IMAGE_OT_replace(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ - WM_operator_properties_filesel(ot, FOLDERFILE | IMAGEFILE | MOVIEFILE, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH, FILE_DEFAULTDISPLAY); + WM_operator_properties_filesel(ot, FOLDERFILE | IMAGEFILE | MOVIEFILE, FILE_SPECIAL, FILE_OPENFILE, + WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH, FILE_DEFAULTDISPLAY); } /******************** save image as operator ********************/ @@ -1417,7 +1419,8 @@ void IMAGE_OT_save_as(wmOperatorType *ot) /* properties */ RNA_def_boolean(ot->srna, "copy", 0, "Copy", "Create a new image file without modifying the current image in blender"); - WM_operator_properties_filesel(ot, FOLDERFILE | IMAGEFILE | MOVIEFILE, FILE_SPECIAL, FILE_SAVE, WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH, FILE_DEFAULTDISPLAY); + WM_operator_properties_filesel(ot, FOLDERFILE | IMAGEFILE | MOVIEFILE, FILE_SPECIAL, FILE_SAVE, + WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH, FILE_DEFAULTDISPLAY); } /******************** save image operator ********************/ diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c index f97813d3dd3..cc8940201e2 100644 --- a/source/blender/editors/space_image/space_image.c +++ b/source/blender/editors/space_image/space_image.c @@ -46,12 +46,14 @@ #include "BKE_screen.h" #include "BKE_tessmesh.h" #include "BKE_sequencer.h" +#include "BKE_node.h" #include "IMB_imbuf_types.h" #include "ED_image.h" #include "ED_mask.h" #include "ED_mesh.h" +#include "ED_node.h" #include "ED_space_api.h" #include "ED_screen.h" #include "ED_uvedit.h" @@ -316,6 +318,19 @@ static void image_keymap(struct wmKeyConfig *keyconf) RNA_string_set(kmi->ptr, "data_path", "space_data.image.render_slot"); RNA_int_set(kmi->ptr, "value", i); } + + /* pivot */ + kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", COMMAKEY, KM_PRESS, 0, 0); + RNA_string_set(kmi->ptr, "data_path", "space_data.pivot_point"); + RNA_string_set(kmi->ptr, "value", "CENTER"); + + kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", COMMAKEY, KM_PRESS, KM_CTRL, 0); + RNA_string_set(kmi->ptr, "data_path", "space_data.pivot_point"); + RNA_string_set(kmi->ptr, "value", "MEDIAN"); + + kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", PERIODKEY, KM_PRESS, 0, 0); + RNA_string_set(kmi->ptr, "data_path", "space_data.pivot_point"); + RNA_string_set(kmi->ptr, "value", "CURSOR"); } /* dropboxes */ @@ -341,11 +356,14 @@ static void image_dropboxes(void) WM_dropbox_add(lb, "IMAGE_OT_open", image_drop_poll, image_drop_copy); } - -static void image_refresh(const bContext *C, ScrArea *UNUSED(sa)) +/** + * \note take care not to get into feedback loop here, + * calling composite job causes viewer to refresh. + */ +static void image_refresh(const bContext *C, ScrArea *sa) { Scene *scene = CTX_data_scene(C); - SpaceImage *sima = CTX_wm_space_image(C); + SpaceImage *sima = sa->spacedata.first; Object *obedit = CTX_data_edit_object(C); Image *ima; @@ -354,7 +372,19 @@ static void image_refresh(const bContext *C, ScrArea *UNUSED(sa)) BKE_image_user_check_frame_calc(&sima->iuser, scene->r.cfra, 0); /* check if we have to set the image from the editmesh */ - if (ima && (ima->source == IMA_SRC_VIEWER || sima->pin)) ; + if (ima && (ima->source == IMA_SRC_VIEWER && sima->mode == SI_MODE_MASK)) { + if (sima->lock) { + if (scene->nodetree) { + Mask *mask = ED_space_image_get_mask(sima); + if (mask) { + ED_node_composite_job(C, scene->nodetree, scene); + } + } + } + } + else if (ima && (ima->source == IMA_SRC_VIEWER || sima->pin)) { + /* pass */ + } else if (obedit && obedit->type == OB_MESH) { Mesh *me = (Mesh *)obedit->data; struct BMEditMesh *em = me->edit_btmesh; @@ -404,15 +434,14 @@ static void image_listener(ScrArea *sa, wmNotifier *wmn) case ND_FRAME: image_scopes_tag_refresh(sa); ED_area_tag_refresh(sa); - ED_area_tag_redraw(sa); + ED_area_tag_redraw(sa); break; case ND_MODE: case ND_RENDER_RESULT: case ND_COMPO_RESULT: if (ED_space_image_show_render(sima)) image_scopes_tag_refresh(sa); - ED_area_tag_refresh(sa); - ED_area_tag_redraw(sa); + ED_area_tag_redraw(sa); break; } break; @@ -436,9 +465,13 @@ static void image_listener(ScrArea *sa, wmNotifier *wmn) if (sima->mode == SI_MODE_MASK) { switch (wmn->data) { case ND_SELECT: + ED_area_tag_redraw(sa); + break; case ND_DATA: case ND_DRAW: + /* causes node-recalc */ ED_area_tag_redraw(sa); + ED_area_tag_refresh(sa); break; } switch (wmn->action) { @@ -446,7 +479,9 @@ static void image_listener(ScrArea *sa, wmNotifier *wmn) ED_area_tag_redraw(sa); break; case NA_EDITED: + /* causes node-recalc */ ED_area_tag_redraw(sa); + ED_area_tag_refresh(sa); break; } } diff --git a/source/blender/editors/space_info/info_ops.c b/source/blender/editors/space_info/info_ops.c index 33a2d5c18c5..805ff1794c9 100644 --- a/source/blender/editors/space_info/info_ops.c +++ b/source/blender/editors/space_info/info_ops.c @@ -315,7 +315,8 @@ void FILE_OT_find_missing_files(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ - WM_operator_properties_filesel(ot, 0, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY); + WM_operator_properties_filesel(ot, 0, FILE_SPECIAL, FILE_OPENFILE, + WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY); } /********************* report box operator *********************/ diff --git a/source/blender/editors/space_info/info_report.c b/source/blender/editors/space_info/info_report.c index 46cd2530063..2324f735a33 100644 --- a/source/blender/editors/space_info/info_report.c +++ b/source/blender/editors/space_info/info_report.c @@ -231,10 +231,7 @@ static int borderselect_exec(bContext *C, wmOperator *op) short selecting = (RNA_int_get(op->ptr, "gesture_mode") == GESTURE_MODAL_SELECT); //int mval[2]; - rect.xmin = RNA_int_get(op->ptr, "xmin"); - rect.ymin = RNA_int_get(op->ptr, "ymin"); - rect.xmax = RNA_int_get(op->ptr, "xmax"); - rect.ymax = RNA_int_get(op->ptr, "ymax"); + WM_operator_properties_border_to_rcti(op, &rect); #if 0 mval[0] = rect.xmin; diff --git a/source/blender/editors/space_logic/logic_window.c b/source/blender/editors/space_logic/logic_window.c index 08842698214..915e5c20e99 100644 --- a/source/blender/editors/space_logic/logic_window.c +++ b/source/blender/editors/space_logic/logic_window.c @@ -4783,7 +4783,7 @@ void logic_buttons(bContext *C, ARegion *ar) * pin so changing states dosnt hide the logic brick */ char pin; - if (G.rt == 0) { + if (G.debug_value == 0) { logic_buttons_new(C, ar); return; } diff --git a/source/blender/editors/space_nla/nla_channels.c b/source/blender/editors/space_nla/nla_channels.c index b92fe315d1c..89a5e9feeef 100644 --- a/source/blender/editors/space_nla/nla_channels.c +++ b/source/blender/editors/space_nla/nla_channels.c @@ -344,6 +344,8 @@ static int nlachannels_mouseclick_invoke(bContext *C, wmOperator *op, wmEvent *e void NLA_OT_channels_click(wmOperatorType *ot) { + PropertyRNA *prop; + /* identifiers */ ot->name = "Mouse Click on NLA Channels"; ot->idname = "NLA_OT_channels_click"; @@ -356,8 +358,9 @@ void NLA_OT_channels_click(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - /* id-props */ - RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", ""); // SHIFTKEY + /* props */ + prop = RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", ""); // SHIFTKEY + RNA_def_property_flag(prop, PROP_SKIP_SAVE); } /* *********************************************** */ diff --git a/source/blender/editors/space_nla/nla_select.c b/source/blender/editors/space_nla/nla_select.c index 1ba15d529e8..b6bef651af3 100644 --- a/source/blender/editors/space_nla/nla_select.c +++ b/source/blender/editors/space_nla/nla_select.c @@ -198,7 +198,8 @@ void NLA_OT_select_all_toggle(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER /*|OPTYPE_UNDO*/; /* props */ - RNA_def_boolean(ot->srna, "invert", 0, "Invert", ""); + ot->prop = RNA_def_boolean(ot->srna, "invert", 0, "Invert", ""); + RNA_def_property_flag(ot->prop, PROP_SKIP_SAVE); } /* ******************** Border Select Operator **************************** */ @@ -294,10 +295,7 @@ static int nlaedit_borderselect_exec(bContext *C, wmOperator *op) deselect_nla_strips(&ac, DESELECT_STRIPS_TEST, SELECT_SUBTRACT); /* get settings from operator */ - rect.xmin = RNA_int_get(op->ptr, "xmin"); - rect.ymin = RNA_int_get(op->ptr, "ymin"); - rect.xmax = RNA_int_get(op->ptr, "xmax"); - rect.ymax = RNA_int_get(op->ptr, "ymax"); + WM_operator_properties_border_to_rcti(op, &rect); if (RNA_int_get(op->ptr, "gesture_mode") == GESTURE_MODAL_SELECT) selectmode = SELECT_ADD; @@ -483,6 +481,8 @@ static int nlaedit_select_leftright_invoke(bContext *C, wmOperator *op, wmEvent void NLA_OT_select_leftright(wmOperatorType *ot) { + PropertyRNA *prop; + /* identifiers */ ot->name = "Select Left/Right"; ot->idname = "NLA_OT_select_leftright"; @@ -496,9 +496,12 @@ void NLA_OT_select_leftright(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - /* id-props */ + /* properties */ ot->prop = RNA_def_enum(ot->srna, "mode", prop_nlaedit_leftright_select_types, NLAEDIT_LRSEL_TEST, "Mode", ""); - RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", ""); + RNA_def_property_flag(ot->prop, PROP_SKIP_SAVE); + + prop = RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", ""); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); } @@ -645,6 +648,8 @@ static int nlaedit_clickselect_invoke(bContext *C, wmOperator *op, wmEvent *even void NLA_OT_click_select(wmOperatorType *ot) { + PropertyRNA *prop; + /* identifiers */ ot->name = "Mouse Select"; ot->idname = "NLA_OT_click_select"; @@ -657,8 +662,9 @@ void NLA_OT_click_select(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - /* id-props */ - RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", ""); // SHIFTKEY + /* properties */ + prop = RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", ""); // SHIFTKEY + RNA_def_property_flag(prop, PROP_SKIP_SAVE); } /* *********************************************** */ diff --git a/source/blender/editors/space_node/CMakeLists.txt b/source/blender/editors/space_node/CMakeLists.txt index 793a167b929..996c6fb530f 100644 --- a/source/blender/editors/space_node/CMakeLists.txt +++ b/source/blender/editors/space_node/CMakeLists.txt @@ -47,12 +47,12 @@ set(SRC node_draw.c node_edit.c node_group.c - node_relationships.c node_header.c node_ops.c + node_relationships.c node_select.c - node_state.c node_templates.c + node_view.c space_node.c node_intern.h diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index c3d9336ae64..d489b6f97ed 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -30,26 +30,17 @@ * \brief lower level node drawing for nodes (boarders, headers etc), also node layout. */ -#include <math.h> -#include <stdio.h> -#include <string.h> - #include "BLI_blenlib.h" #include "BLI_math.h" -#include "BLI_utildefines.h" #include "DNA_node_types.h" -#include "DNA_material_types.h" #include "DNA_object_types.h" -#include "DNA_scene_types.h" #include "DNA_space_types.h" #include "DNA_screen_types.h" #include "BKE_context.h" #include "BKE_curve.h" -#include "BKE_global.h" #include "BKE_image.h" -#include "BKE_library.h" #include "BKE_main.h" #include "BKE_node.h" #include "BKE_tracking.h" @@ -57,17 +48,12 @@ #include "BLF_api.h" #include "BLF_translation.h" -#include "NOD_composite.h" -#include "NOD_shader.h" #include "BIF_gl.h" #include "BIF_glutil.h" -#include "BLF_api.h" - #include "MEM_guardedalloc.h" - #include "RNA_access.h" #include "ED_node.h" @@ -75,13 +61,12 @@ #include "WM_api.h" #include "WM_types.h" -#include "UI_interface.h" #include "UI_resources.h" #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" -#include "node_intern.h" +#include "node_intern.h" /* own include */ /* XXX interface.h */ extern void ui_dropshadow(rctf *rct, float radius, float aspect, float alpha, int select); @@ -353,8 +338,8 @@ static void node_buts_curvevec(uiLayout *layout, bContext *UNUSED(C), PointerRNA uiTemplateCurveMapping(layout, ptr, "mapping", 'v', 0, 0); } -static float _sample_col[4]; /* bad bad, 2.5 will do better?... no it won't... */ #define SAMPLE_FLT_ISNONE FLT_MAX +static float _sample_col[4] = {SAMPLE_FLT_ISNONE}; /* bad bad, 2.5 will do better?... no it won't... */ void ED_node_sample_set(const float col[4]) { if (col) { @@ -1011,9 +996,7 @@ static void node_draw_frame(const bContext *C, ARegion *ar, SpaceNode *snode, bN float alpha; /* skip if out of view */ - if (node->totr.xmax < ar->v2d.cur.xmin || node->totr.xmin > ar->v2d.cur.xmax || - node->totr.ymax < ar->v2d.cur.ymin || node->totr.ymin > ar->v2d.cur.ymax) { - + if (BLI_rctf_isect(&node->totr, &ar->v2d.cur, NULL) == FALSE) { uiEndBlock(C, node->block); node->block = NULL; return; @@ -1150,7 +1133,7 @@ static void node_draw_reroute(const bContext *C, ARegion *ar, SpaceNode *UNUSED( glDisable(GL_BLEND); /* outline active and selected emphasis */ - if (node->flag & (NODE_ACTIVE | SELECT)) { + if (node->flag & SELECT) { glEnable(GL_BLEND); glEnable(GL_LINE_SMOOTH); /* using different shades of TH_TEXT_HI for the empasis, like triangle */ @@ -1824,6 +1807,11 @@ static void node_composit_buts_dilateerode(uiLayout *layout, bContext *UNUSED(C) } } +static void node_composit_buts_inpaint(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) +{ + uiItemR(layout, ptr, "distance", 0, NULL, ICON_NONE); +} + static void node_composit_buts_diff_matte(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) { uiLayout *col; @@ -2552,7 +2540,7 @@ static void node_composit_buts_keying(uiLayout *layout, bContext *UNUSED(C), Poi static void node_composit_buts_trackpos(uiLayout *layout, bContext *C, PointerRNA *ptr) { - bNode *node= ptr->data; + bNode *node = ptr->data; uiTemplateID(layout, C, ptr, "clip", NULL, "CLIP_OT_open", NULL); @@ -2676,6 +2664,9 @@ static void node_composit_set_butfunc(bNodeType *ntype) case CMP_NODE_DILATEERODE: ntype->uifunc = node_composit_buts_dilateerode; break; + case CMP_NODE_INPAINT: + ntype->uifunc = node_composit_buts_inpaint; + break; case CMP_NODE_OUTPUT_FILE: ntype->uifunc = node_composit_buts_file_output; ntype->uifuncbut = node_composit_buts_file_output_details; @@ -3040,7 +3031,7 @@ void draw_nodespace_back_pix(ARegion *ar, SpaceNode *snode, int color_manage) glaDefine2DArea(&ar->winrct); /* ortho at pixel level curarea */ - wmOrtho2(-0.375, ar->winx - 0.375, -0.375, ar->winy - 0.375); + wmOrtho2(-GLA_PIXEL_OFS, ar->winx - GLA_PIXEL_OFS, -GLA_PIXEL_OFS, ar->winy - GLA_PIXEL_OFS); x = (ar->winx - snode->zoom * ibuf->x) / 2 + snode->xof; y = (ar->winy - snode->zoom * ibuf->y) / 2 + snode->yof; @@ -3194,8 +3185,7 @@ int node_link_bezier_points(View2D *v2d, SpaceNode *snode, bNodeLink *link, floa } else { if (snode == NULL) return 0; - vec[0][0] = snode->mx; - vec[0][1] = snode->my; + copy_v2_v2(vec[0], snode->cursor); fromreroute = 0; } if (link->tosock) { @@ -3205,8 +3195,7 @@ int node_link_bezier_points(View2D *v2d, SpaceNode *snode, bNodeLink *link, floa } else { if (snode == NULL) return 0; - vec[3][0] = snode->mx; - vec[3][1] = snode->my; + copy_v2_v2(vec[3], snode->cursor); toreroute = 0; } @@ -3292,7 +3281,7 @@ void node_draw_link_bezier(View2D *v2d, SpaceNode *snode, bNodeLink *link, sub_v2_v2v2(d_xy, coord_array[LINK_ARROW], coord_array[LINK_ARROW - 1]); len = len_v2(d_xy); - mul_v2_fl(d_xy, 1.0f / (len * ARROW_SIZE)); + mul_v2_fl(d_xy, ARROW_SIZE / len); arrow1[0] = coord_array[LINK_ARROW][0] - d_xy[0] + d_xy[1]; arrow1[1] = coord_array[LINK_ARROW][1] - d_xy[1] - d_xy[0]; arrow2[0] = coord_array[LINK_ARROW][0] - d_xy[0] - d_xy[1]; diff --git a/source/blender/editors/space_node/node_add.c b/source/blender/editors/space_node/node_add.c index 5e58737606f..7d007d024ab 100644 --- a/source/blender/editors/space_node/node_add.c +++ b/source/blender/editors/space_node/node_add.c @@ -29,54 +29,21 @@ * \ingroup spnode */ -#include <stdio.h> -#include <stdlib.h> -#include <math.h> -#include <string.h> #include <errno.h> -#include "MEM_guardedalloc.h" - -#include "DNA_ID.h" -#include "DNA_lamp_types.h" -#include "DNA_material_types.h" #include "DNA_node_types.h" -#include "DNA_object_types.h" -#include "DNA_particle_types.h" -#include "DNA_scene_types.h" -#include "DNA_world_types.h" -#include "DNA_action_types.h" -#include "DNA_anim_types.h" #include "BLI_math.h" -#include "BLI_blenlib.h" -#include "BLI_utildefines.h" -#include "BKE_action.h" -#include "BKE_animsys.h" #include "BKE_context.h" -#include "BKE_depsgraph.h" -#include "BKE_global.h" #include "BKE_image.h" #include "BKE_library.h" #include "BKE_main.h" #include "BKE_node.h" -#include "BKE_material.h" -#include "BKE_modifier.h" -#include "BKE_paint.h" -#include "BKE_scene.h" -#include "BKE_screen.h" -#include "BKE_texture.h" #include "BKE_report.h" -#include "RE_pipeline.h" - -#include "IMB_imbuf_types.h" - -#include "ED_node.h" -#include "ED_image.h" +#include "ED_node.h" /* own include */ #include "ED_screen.h" -#include "ED_space_api.h" #include "ED_render.h" #include "RNA_access.h" @@ -86,19 +53,9 @@ #include "WM_api.h" #include "WM_types.h" -#include "UI_interface.h" -#include "UI_resources.h" #include "UI_view2d.h" -#include "IMB_imbuf.h" - -#include "RNA_enum_types.h" - -#include "GPU_material.h" - -#include "node_intern.h" -#include "NOD_socket.h" - +#include "node_intern.h" /* own include */ /* can be called from menus too, but they should do own undopush and redraws */ bNode *node_add_node(SpaceNode *snode, Main *bmain, Scene *scene, @@ -198,13 +155,14 @@ static int add_reroute_exec(bContext *C, wmOperator *op) bNodeLink *link; float insertPoint[2]; - ED_preview_kill_jobs(C); - for (link = snode->edittree->links.first; link; link = link->next) { if (add_reroute_intersect_check(link, mcoords, i, insertPoint)) { bNodeTemplate ntemp; bNode *rerouteNode; + /* always first */ + ED_preview_kill_jobs(C); + node_deselect_all(snode); ntemp.type = NODE_REROUTE; @@ -221,15 +179,17 @@ static int add_reroute_exec(bContext *C, wmOperator *op) link->fromnode = rerouteNode; link->fromsock = rerouteNode->outputs.first; - break; // add one reroute at the time. + /* always last */ + ntreeUpdateTree(snode->edittree); + snode_notify(C, snode); + snode_dag_update(C, snode); + + return OPERATOR_FINISHED; // add one reroute at the time. } } - ntreeUpdateTree(snode->edittree); - snode_notify(C, snode); - snode_dag_update(C, snode); + return OPERATOR_CANCELLED; - return OPERATOR_FINISHED; } return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH; @@ -313,7 +273,7 @@ static int node_add_file_exec(bContext *C, wmOperator *op) ED_preview_kill_jobs(C); - node = node_add_node(snode, bmain, scene, &ntemp, snode->mx, snode->my); + node = node_add_node(snode, bmain, scene, &ntemp, snode->cursor[0], snode->cursor[1]); if (!node) { BKE_report(op->reports, RPT_WARNING, "Could not add an image node"); @@ -336,7 +296,7 @@ static int node_add_file_invoke(bContext *C, wmOperator *op, wmEvent *event) /* convert mouse coordinates to v2d space */ UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], - &snode->mx, &snode->my); + &snode->cursor[0], &snode->cursor[1]); if (RNA_struct_property_is_set(op->ptr, "filepath") || RNA_struct_property_is_set(op->ptr, "name")) return node_add_file_exec(C, op); @@ -359,7 +319,8 @@ void NODE_OT_add_file(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - WM_operator_properties_filesel(ot, FOLDERFILE | IMAGEFILE, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY); //XXX TODO, relative_path + WM_operator_properties_filesel(ot, FOLDERFILE | IMAGEFILE, FILE_SPECIAL, FILE_OPENFILE, + WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY); //XXX TODO, relative_path RNA_def_string(ot->srna, "name", "Image", MAX_ID_NAME - 2, "Name", "Datablock name to assign"); } diff --git a/source/blender/editors/space_node/node_buttons.c b/source/blender/editors/space_node/node_buttons.c index bc4c391720a..e50b1dc4ba6 100644 --- a/source/blender/editors/space_node/node_buttons.c +++ b/source/blender/editors/space_node/node_buttons.c @@ -28,21 +28,12 @@ * \ingroup spnode */ - -#include <string.h> -#include <stdio.h> -#include <math.h> -#include <float.h> - #include "MEM_guardedalloc.h" #include "DNA_node_types.h" -#include "DNA_scene_types.h" #include "BLI_math.h" #include "BLI_blenlib.h" -#include "BLI_rand.h" -#include "BLI_utildefines.h" #include "BLF_translation.h" @@ -59,10 +50,9 @@ #include "ED_gpencil.h" #include "ED_screen.h" -#include "UI_interface.h" #include "UI_resources.h" -#include "node_intern.h" // own include +#include "node_intern.h" /* own include */ /* ******************* node space & buttons ************** */ @@ -70,7 +60,7 @@ /* poll for active nodetree */ static int active_nodetree_poll(const bContext *C, PanelType *UNUSED(pt)) { - SpaceNode *snode= CTX_wm_space_node(C); + SpaceNode *snode = CTX_wm_space_node(C); return (snode && snode->nodetree); } @@ -78,7 +68,7 @@ static int active_nodetree_poll(const bContext *C, PanelType *UNUSED(pt)) /* poll callback for active node */ static int active_node_poll(const bContext *C, PanelType *UNUSED(pt)) { - SpaceNode *snode= CTX_wm_space_node(C); + SpaceNode *snode = CTX_wm_space_node(C); return (snode && snode->edittree && nodeGetActive(snode->edittree)); } @@ -86,8 +76,8 @@ static int active_node_poll(const bContext *C, PanelType *UNUSED(pt)) /* active node */ static void active_node_panel(const bContext *C, Panel *pa) { - SpaceNode *snode= CTX_wm_space_node(C); - bNodeTree *ntree= (snode) ? snode->edittree : NULL; + SpaceNode *snode = CTX_wm_space_node(C); + bNodeTree *ntree = (snode) ? snode->edittree : NULL; bNode *node = (ntree) ? nodeGetActive(ntree) : NULL; // xxx... for editing group nodes uiLayout *layout, *row, *col, *sub; PointerRNA ptr, opptr; @@ -98,7 +88,7 @@ static void active_node_panel(const bContext *C, Panel *pa) //if (node->id) /* for group nodes */ // RNA_pointer_create(node->id, &RNA_Node, node, &ptr); //else - RNA_pointer_create(&ntree->id, &RNA_Node, node, &ptr); + RNA_pointer_create(&ntree->id, &RNA_Node, node, &ptr); layout = uiLayoutColumn(pa->layout, FALSE); uiLayoutSetContextPointer(layout, "node", &ptr); @@ -144,24 +134,24 @@ static void active_node_panel(const bContext *C, Panel *pa) static int node_sockets_poll(const bContext *C, PanelType *UNUSED(pt)) { - SpaceNode *snode= CTX_wm_space_node(C); + SpaceNode *snode = CTX_wm_space_node(C); - return (snode && snode->nodetree && G.rt == 777); + return (snode && snode->nodetree && G.debug_value == 777); } static void node_sockets_panel(const bContext *C, Panel *pa) { - SpaceNode *snode= CTX_wm_space_node(C); - bNodeTree *ntree= (snode) ? snode->edittree : NULL; + SpaceNode *snode = CTX_wm_space_node(C); + bNodeTree *ntree = (snode) ? snode->edittree : NULL; bNode *node = (ntree) ? nodeGetActive(ntree) : NULL; bNodeSocket *sock; - uiLayout *layout= pa->layout, *split; + uiLayout *layout = pa->layout, *split; char name[UI_MAX_NAME_STR]; if (ELEM(NULL, ntree, node)) return; - for (sock=node->inputs.first; sock; sock=sock->next) { + for (sock = node->inputs.first; sock; sock = sock->next) { BLI_snprintf(name, sizeof(name), "%s:", sock->name); split = uiLayoutSplit(layout, 0.35f, FALSE); @@ -176,33 +166,33 @@ void node_buttons_register(ARegionType *art) { PanelType *pt; - pt= MEM_callocN(sizeof(PanelType), "spacetype node panel active node"); + pt = MEM_callocN(sizeof(PanelType), "spacetype node panel active node"); strcpy(pt->idname, "NODE_PT_item"); strcpy(pt->label, IFACE_("Active Node")); - pt->draw= active_node_panel; - pt->poll= active_node_poll; + pt->draw = active_node_panel; + pt->poll = active_node_poll; BLI_addtail(&art->paneltypes, pt); - pt= MEM_callocN(sizeof(PanelType), "spacetype node panel node sockets"); + pt = MEM_callocN(sizeof(PanelType), "spacetype node panel node sockets"); strcpy(pt->idname, "NODE_PT_sockets"); strcpy(pt->label, "Sockets"); - pt->draw= node_sockets_panel; - pt->poll= node_sockets_poll; + pt->draw = node_sockets_panel; + pt->poll = node_sockets_poll; pt->flag |= PNL_DEFAULT_CLOSED; BLI_addtail(&art->paneltypes, pt); - pt= MEM_callocN(sizeof(PanelType), "spacetype node panel gpencil"); + pt = MEM_callocN(sizeof(PanelType), "spacetype node panel gpencil"); strcpy(pt->idname, "NODE_PT_gpencil"); strcpy(pt->label, "Grease Pencil"); - pt->draw= gpencil_panel_standard; - pt->poll= active_nodetree_poll; + pt->draw = gpencil_panel_standard; + pt->poll = active_nodetree_poll; BLI_addtail(&art->paneltypes, pt); } static int node_properties(bContext *C, wmOperator *UNUSED(op)) { - ScrArea *sa= CTX_wm_area(C); - ARegion *ar= node_has_buttons_region(sa); + ScrArea *sa = CTX_wm_area(C); + ARegion *ar = node_has_buttons_region(sa); if (ar) ED_region_toggle_hidden(C, ar); @@ -213,7 +203,7 @@ static int node_properties(bContext *C, wmOperator *UNUSED(op)) /* non-standard poll operator which doesn't care if there are any nodes */ static int node_properties_poll(bContext *C) { - ScrArea *sa= CTX_wm_area(C); + ScrArea *sa = CTX_wm_area(C); return (sa && (sa->spacetype == SPACE_NODE)); } diff --git a/source/blender/editors/space_node/node_draw.c b/source/blender/editors/space_node/node_draw.c index 92b1fca673d..07b1faecaef 100644 --- a/source/blender/editors/space_node/node_draw.c +++ b/source/blender/editors/space_node/node_draw.c @@ -29,26 +29,13 @@ * \brief higher level node drawing for the node editor. */ -#include <math.h> -#include <stdio.h> -#include <string.h> - -#include "MEM_guardedalloc.h" - #include "DNA_node_types.h" -#include "DNA_lamp_types.h" -#include "DNA_material_types.h" #include "DNA_object_types.h" -#include "DNA_scene_types.h" #include "DNA_space_types.h" #include "DNA_screen_types.h" -#include "DNA_world_types.h" #include "BLI_math.h" #include "BLI_blenlib.h" -#include "BLI_rect.h" -#include "BLI_threads.h" -#include "BLI_utildefines.h" #include "BLF_translation.h" @@ -67,19 +54,12 @@ #include "ED_gpencil.h" #include "ED_space_api.h" -#include "UI_interface.h" -#include "UI_interface_icons.h" #include "UI_resources.h" #include "UI_view2d.h" #include "RNA_access.h" -#include "NOD_composite.h" -#include "NOD_shader.h" - -#include "intern/node_util.h" - -#include "node_intern.h" +#include "node_intern.h" /* own include */ #include "COM_compositor.h" /* width of socket columns in group display */ @@ -701,9 +681,7 @@ static void node_draw_basis(const bContext *C, ARegion *ar, SpaceNode *snode, bN nodeShaderSynchronizeID(node, 0); /* skip if out of view */ - if (node->totr.xmax < ar->v2d.cur.xmin || node->totr.xmin > ar->v2d.cur.xmax || - node->totr.ymax < ar->v2d.cur.ymin || node->totr.ymin > ar->v2d.cur.ymax) - { + if (BLI_rctf_isect(&node->totr, &ar->v2d.cur, NULL) == FALSE) { uiEndBlock(C, node->block); node->block = NULL; return; @@ -901,7 +879,7 @@ static void node_draw_hidden(const bContext *C, ARegion *ar, SpaceNode *snode, b uiRoundBox(rct->xmin, rct->ymin, rct->xmax, rct->ymax, hiddenrad); /* outline active and selected emphasis */ - if (node->flag & (NODE_ACTIVE | SELECT)) { + if (node->flag & SELECT) { glEnable(GL_BLEND); glEnable(GL_LINE_SMOOTH); @@ -1011,11 +989,11 @@ void node_set_cursor(wmWindow *win, SpaceNode *snode) else { /* check nodes front to back */ for (node = ntree->nodes.last; node; node = node->prev) { - if (BLI_in_rctf(&node->totr, snode->mx, snode->my)) + if (BLI_in_rctf(&node->totr, snode->cursor[0], snode->cursor[1])) break; /* first hit on node stops */ } if (node) { - int dir = node->typeinfo->resize_area_func(node, snode->mx, snode->my); + int dir = node->typeinfo->resize_area_func(node, snode->cursor[0], snode->cursor[1]); cursor = node_get_resize_cursor(dir); } } diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c index 481c6544255..11f070b483d 100644 --- a/source/blender/editors/space_node/node_edit.c +++ b/source/blender/editors/space_node/node_edit.c @@ -29,76 +29,48 @@ * \ingroup spnode */ - -#include <stdio.h> -#include <stdlib.h> -#include <math.h> -#include <string.h> -#include <errno.h> - #include "MEM_guardedalloc.h" -#include "DNA_ID.h" #include "DNA_lamp_types.h" #include "DNA_material_types.h" #include "DNA_node_types.h" #include "DNA_object_types.h" -#include "DNA_particle_types.h" -#include "DNA_scene_types.h" #include "DNA_world_types.h" -#include "DNA_action_types.h" -#include "DNA_anim_types.h" #include "BLI_math.h" #include "BLI_blenlib.h" -#include "BLI_utildefines.h" -#include "BKE_action.h" -#include "BKE_animsys.h" #include "BKE_context.h" #include "BKE_depsgraph.h" #include "BKE_global.h" #include "BKE_image.h" #include "BKE_library.h" #include "BKE_main.h" -#include "BKE_node.h" #include "BKE_material.h" -#include "BKE_modifier.h" +#include "BKE_node.h" #include "BKE_paint.h" +#include "BKE_report.h" #include "BKE_scene.h" -#include "BKE_screen.h" #include "BKE_texture.h" -#include "BKE_report.h" #include "RE_pipeline.h" -#include "IMB_imbuf_types.h" -#include "ED_node.h" -#include "ED_image.h" +#include "ED_node.h" /* own include */ #include "ED_screen.h" -#include "ED_space_api.h" #include "ED_render.h" #include "RNA_access.h" #include "RNA_define.h" -#include "RNA_enum_types.h" #include "WM_api.h" #include "WM_types.h" -#include "UI_interface.h" -#include "UI_resources.h" #include "UI_view2d.h" -#include "IMB_imbuf.h" - -#include "RNA_enum_types.h" - #include "GPU_material.h" -#include "node_intern.h" -#include "NOD_socket.h" +#include "node_intern.h" /* own include */ /* ***************** composite job manager ********************** */ @@ -192,26 +164,36 @@ static void compo_startjob(void *cjv, short *stop, short *do_update, float *prog } -void snode_composite_job(const bContext *C, ScrArea *sa) +/** + * \param sa_owner is the owner of the job, + * we don't use it for anything else currently so could also be a void pointer, + * but for now keep it an 'Scene' for consistency. + * + * \note only call from spaces `refresh` callbacks, not direct! - use with care. + */ +void ED_node_composite_job(const bContext *C, struct bNodeTree *nodetree, Scene *scene_owner) { - SpaceNode *snode = sa->spacedata.first; wmJob *steve; CompoJob *cj; - steve = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), sa, "Compositing", WM_JOB_EXCL_RENDER | WM_JOB_PROGRESS); + /* to fix bug: [#32272] */ + if (G.is_rendering) { + return; + } + + steve = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), scene_owner, "Compositing", WM_JOB_EXCL_RENDER | WM_JOB_PROGRESS); cj = MEM_callocN(sizeof(CompoJob), "compo job"); - + /* customdata for preview thread */ cj->scene = CTX_data_scene(C); - cj->ntree = snode->nodetree; - + cj->ntree = nodetree; + /* setup job */ WM_jobs_customdata(steve, cj, compo_freejob); WM_jobs_timer(steve, 0.1, NC_SCENE, NC_SCENE | ND_COMPO_RESULT); WM_jobs_callbacks(steve, compo_startjob, compo_initjob, compo_updatejob, NULL); - + WM_jobs_start(CTX_wm_manager(C), steve); - } /* ***************************************** */ @@ -786,7 +768,7 @@ static void edit_node_properties_get(wmOperator *op, bNodeTree *ntree, bNode **r /* ************************** Node generic ************** */ /* is rct in visible part of node? */ -static bNode *visible_node(SpaceNode *snode, rctf *rct) +static bNode *visible_node(SpaceNode *snode, const rctf *rct) { bNode *node; @@ -797,317 +779,6 @@ static bNode *visible_node(SpaceNode *snode, rctf *rct) return node; } -/* **************************** */ - -typedef struct NodeViewMove { - int mvalo[2]; - int xmin, ymin, xmax, ymax; -} NodeViewMove; - -static int snode_bg_viewmove_modal(bContext *C, wmOperator *op, wmEvent *event) -{ - SpaceNode *snode = CTX_wm_space_node(C); - ARegion *ar = CTX_wm_region(C); - NodeViewMove *nvm = op->customdata; - - switch (event->type) { - case MOUSEMOVE: - - snode->xof -= (nvm->mvalo[0] - event->mval[0]); - snode->yof -= (nvm->mvalo[1] - event->mval[1]); - nvm->mvalo[0] = event->mval[0]; - nvm->mvalo[1] = event->mval[1]; - - /* prevent dragging image outside of the window and losing it! */ - CLAMP(snode->xof, nvm->xmin, nvm->xmax); - CLAMP(snode->yof, nvm->ymin, nvm->ymax); - - ED_region_tag_redraw(ar); - - break; - - case LEFTMOUSE: - case MIDDLEMOUSE: - case RIGHTMOUSE: - - MEM_freeN(nvm); - op->customdata = NULL; - - return OPERATOR_FINISHED; - } - - return OPERATOR_RUNNING_MODAL; -} - -static int snode_bg_viewmove_invoke(bContext *C, wmOperator *op, wmEvent *event) -{ - SpaceNode *snode = CTX_wm_space_node(C); - ARegion *ar = CTX_wm_region(C); - NodeViewMove *nvm; - Image *ima; - ImBuf *ibuf; - const float pad = 32.0f; /* better be bigger then scrollbars */ - - void *lock; - - ima = BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node"); - ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); - - if (ibuf == NULL) { - BKE_image_release_ibuf(ima, lock); - return OPERATOR_CANCELLED; - } - - nvm = MEM_callocN(sizeof(NodeViewMove), "NodeViewMove struct"); - op->customdata = nvm; - nvm->mvalo[0] = event->mval[0]; - nvm->mvalo[1] = event->mval[1]; - - nvm->xmin = -(ar->winx / 2) - (ibuf->x * (0.5f * snode->zoom)) + pad; - nvm->xmax = (ar->winx / 2) + (ibuf->x * (0.5f * snode->zoom)) - pad; - nvm->ymin = -(ar->winy / 2) - (ibuf->y * (0.5f * snode->zoom)) + pad; - nvm->ymax = (ar->winy / 2) + (ibuf->y * (0.5f * snode->zoom)) - pad; - - BKE_image_release_ibuf(ima, lock); - - /* add modal handler */ - WM_event_add_modal_handler(C, op); - - return OPERATOR_RUNNING_MODAL; -} - -static int snode_bg_viewmove_cancel(bContext *UNUSED(C), wmOperator *op) -{ - MEM_freeN(op->customdata); - op->customdata = NULL; - - return OPERATOR_CANCELLED; -} - -void NODE_OT_backimage_move(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Background Image Move"; - ot->description = "Move Node backdrop"; - ot->idname = "NODE_OT_backimage_move"; - - /* api callbacks */ - ot->invoke = snode_bg_viewmove_invoke; - ot->modal = snode_bg_viewmove_modal; - ot->poll = composite_node_active; - ot->cancel = snode_bg_viewmove_cancel; - - /* flags */ - ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_POINTER; -} - -static int backimage_zoom(bContext *C, wmOperator *op) -{ - SpaceNode *snode = CTX_wm_space_node(C); - ARegion *ar = CTX_wm_region(C); - float fac = RNA_float_get(op->ptr, "factor"); - - snode->zoom *= fac; - ED_region_tag_redraw(ar); - - return OPERATOR_FINISHED; -} - - -void NODE_OT_backimage_zoom(wmOperatorType *ot) -{ - - /* identifiers */ - ot->name = "Background Image Zoom"; - ot->idname = "NODE_OT_backimage_zoom"; - ot->description = "Zoom in/out the background image"; - - /* api callbacks */ - ot->exec = backimage_zoom; - ot->poll = composite_node_active; - - /* flags */ - ot->flag = OPTYPE_BLOCKING; - - /* internal */ - RNA_def_float(ot->srna, "factor", 1.2f, 0.0f, 10.0f, "Factor", "", 0.0f, 10.0f); -} - -/******************** sample backdrop operator ********************/ - -typedef struct ImageSampleInfo { - ARegionType *art; - void *draw_handle; - int x, y; - int channels; - int color_manage; - - unsigned char col[4]; - float colf[4]; - - int draw; -} ImageSampleInfo; - -static void sample_draw(const bContext *C, ARegion *ar, void *arg_info) -{ - Scene *scene = CTX_data_scene(C); - ImageSampleInfo *info = arg_info; - - if (info->draw) { - ED_image_draw_info(ar, (scene->r.color_mgt_flag & R_COLOR_MANAGEMENT), info->channels, - info->x, info->y, info->col, info->colf, - NULL, NULL /* zbuf - unused for nodes */ - ); - } -} - -static void sample_apply(bContext *C, wmOperator *op, wmEvent *event) -{ - SpaceNode *snode = CTX_wm_space_node(C); - ARegion *ar = CTX_wm_region(C); - ImageSampleInfo *info = op->customdata; - void *lock; - Image *ima; - ImBuf *ibuf; - float fx, fy, bufx, bufy; - - ima = BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node"); - ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); - if (!ibuf) { - info->draw = 0; - return; - } - - if (!ibuf->rect) { - if (info->color_manage) - ibuf->profile = IB_PROFILE_LINEAR_RGB; - else - ibuf->profile = IB_PROFILE_NONE; - IMB_rect_from_float(ibuf); - } - - /* map the mouse coords to the backdrop image space */ - bufx = ibuf->x * snode->zoom; - bufy = ibuf->y * snode->zoom; - fx = (bufx > 0.0f ? ((float)event->mval[0] - 0.5f * ar->winx - snode->xof) / bufx + 0.5f : 0.0f); - fy = (bufy > 0.0f ? ((float)event->mval[1] - 0.5f * ar->winy - snode->yof) / bufy + 0.5f : 0.0f); - - if (fx >= 0.0f && fy >= 0.0f && fx < 1.0f && fy < 1.0f) { - float *fp; - char *cp; - int x = (int)(fx * ibuf->x), y = (int)(fy * ibuf->y); - - CLAMP(x, 0, ibuf->x - 1); - CLAMP(y, 0, ibuf->y - 1); - - info->x = x; - info->y = y; - info->draw = 1; - info->channels = ibuf->channels; - - if (ibuf->rect) { - cp = (char *)(ibuf->rect + y * ibuf->x + x); - - info->col[0] = cp[0]; - info->col[1] = cp[1]; - info->col[2] = cp[2]; - info->col[3] = cp[3]; - - info->colf[0] = (float)cp[0] / 255.0f; - info->colf[1] = (float)cp[1] / 255.0f; - info->colf[2] = (float)cp[2] / 255.0f; - info->colf[3] = (float)cp[3] / 255.0f; - } - if (ibuf->rect_float) { - fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x)); - - info->colf[0] = fp[0]; - info->colf[1] = fp[1]; - info->colf[2] = fp[2]; - info->colf[3] = fp[3]; - } - - ED_node_sample_set(info->colf); - } - else { - info->draw = 0; - ED_node_sample_set(NULL); - } - - BKE_image_release_ibuf(ima, lock); - - ED_area_tag_redraw(CTX_wm_area(C)); -} - -static void sample_exit(bContext *C, wmOperator *op) -{ - ImageSampleInfo *info = op->customdata; - - ED_node_sample_set(NULL); - ED_region_draw_cb_exit(info->art, info->draw_handle); - ED_area_tag_redraw(CTX_wm_area(C)); - MEM_freeN(info); -} - -static int sample_invoke(bContext *C, wmOperator *op, wmEvent *event) -{ - SpaceNode *snode = CTX_wm_space_node(C); - ARegion *ar = CTX_wm_region(C); - ImageSampleInfo *info; - - if (snode->treetype != NTREE_COMPOSIT || !(snode->flag & SNODE_BACKDRAW)) - return OPERATOR_CANCELLED; - - info = MEM_callocN(sizeof(ImageSampleInfo), "ImageSampleInfo"); - info->art = ar->type; - info->draw_handle = ED_region_draw_cb_activate(ar->type, sample_draw, info, REGION_DRAW_POST_PIXEL); - op->customdata = info; - - sample_apply(C, op, event); - - WM_event_add_modal_handler(C, op); - - return OPERATOR_RUNNING_MODAL; -} - -static int sample_modal(bContext *C, wmOperator *op, wmEvent *event) -{ - switch (event->type) { - case LEFTMOUSE: - case RIGHTMOUSE: // XXX hardcoded - sample_exit(C, op); - return OPERATOR_CANCELLED; - case MOUSEMOVE: - sample_apply(C, op, event); - break; - } - - return OPERATOR_RUNNING_MODAL; -} - -static int sample_cancel(bContext *C, wmOperator *op) -{ - sample_exit(C, op); - return OPERATOR_CANCELLED; -} - -void NODE_OT_backimage_sample(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Backimage Sample"; - ot->idname = "NODE_OT_backimage_sample"; - ot->description = "Use mouse to sample background image"; - - /* api callbacks */ - ot->invoke = sample_invoke; - ot->modal = sample_modal; - ot->cancel = sample_cancel; - ot->poll = ED_operator_node_active; - - /* flags */ - ot->flag = OPTYPE_BLOCKING; -} - /* ********************** size widget operator ******************** */ typedef struct NodeSizeWidget { @@ -1126,8 +797,8 @@ static void node_resize_init(bContext *C, wmOperator *op, wmEvent *UNUSED(event) NodeSizeWidget *nsw = MEM_callocN(sizeof(NodeSizeWidget), "size widget op data"); op->customdata = nsw; - nsw->mxstart = snode->mx; - nsw->mystart = snode->my; + nsw->mxstart = snode->cursor[0]; + nsw->mystart = snode->cursor[1]; /* store old */ nsw->oldlocx = node->locx; @@ -1265,8 +936,8 @@ static int node_resize_invoke(bContext *C, wmOperator *op, wmEvent *event) if (node) { /* convert mouse coordinates to v2d space */ UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], - &snode->mx, &snode->my); - dir = node->typeinfo->resize_area_func(node, snode->mx, snode->my); + &snode->cursor[0], &snode->cursor[1]); + dir = node->typeinfo->resize_area_func(node, snode->cursor[0], snode->cursor[1]); if (dir != 0) { node_resize_init(C, op, event, node, dir); return OPERATOR_RUNNING_MODAL; @@ -1380,10 +1051,10 @@ int node_find_indicated_socket(SpaceNode *snode, bNode **nodep, bNodeSocket **so /* check if we click in a socket */ for (node = snode->edittree->nodes.first; node; node = node->next) { - rect.xmin = snode->mx - (NODE_SOCKSIZE + 4); - rect.ymin = snode->my - (NODE_SOCKSIZE + 4); - rect.xmax = snode->mx + (NODE_SOCKSIZE + 4); - rect.ymax = snode->my + (NODE_SOCKSIZE + 4); + rect.xmin = snode->cursor[0] - (NODE_SOCKSIZE + 4); + rect.ymin = snode->cursor[1] - (NODE_SOCKSIZE + 4); + rect.xmax = snode->cursor[0] + (NODE_SOCKSIZE + 4); + rect.ymax = snode->cursor[1] + (NODE_SOCKSIZE + 4); if (!(node->flag & NODE_HIDDEN)) { /* extra padding inside and out - allow dragging on the text areas too */ @@ -2237,3 +1908,191 @@ void NODE_OT_node_copy_color(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } + +/* ****************** Copy to clipboard ******************* */ + +static int node_clipboard_copy_exec(bContext *C, wmOperator *UNUSED(op)) +{ + SpaceNode *snode = CTX_wm_space_node(C); + bNodeTree *ntree = snode->edittree; + bNode *gnode = node_tree_get_editgroup(snode->nodetree); + float gnode_x = 0.0f, gnode_y = 0.0f; + bNode *node, *new_node; + bNodeLink *link, *newlink; + + ED_preview_kill_jobs(C); + + /* clear current clipboard */ + BKE_node_clipboard_clear(); + BKE_node_clipboard_init(ntree); + + /* get group node offset */ + if (gnode) + nodeToView(gnode, 0.0f, 0.0f, &gnode_x, &gnode_y); + + for (node = ntree->nodes.first; node; node = node->next) { + if (node->flag & SELECT) { + new_node = nodeCopyNode(NULL, node); + BKE_node_clipboard_add_node(new_node); + } + } + + for (node = ntree->nodes.first; node; node = node->next) { + if (node->flag & SELECT) { + bNode *new_node = node->new_node; + + /* ensure valid pointers */ + if (new_node->parent) { + /* parent pointer must be redirected to new node or detached if parent is not copied */ + if (new_node->parent->flag & NODE_SELECT) { + new_node->parent = new_node->parent->new_node; + } + else { + nodeDetachNode(new_node); + } + } + + /* transform to basic view space. child node location is relative to parent */ + if (!new_node->parent) { + new_node->locx += gnode_x; + new_node->locy += gnode_y; + } + } + } + + /* copy links between selected nodes + * NB: this depends on correct node->new_node and sock->new_sock pointers from above copy! + */ + for (link = ntree->links.first; link; link = link->next) { + /* This creates new links between copied nodes. */ + if (link->tonode && (link->tonode->flag & NODE_SELECT) && + link->fromnode && (link->fromnode->flag & NODE_SELECT)) + { + newlink = MEM_callocN(sizeof(bNodeLink), "bNodeLink"); + newlink->flag = link->flag; + newlink->tonode = link->tonode->new_node; + newlink->tosock = link->tosock->new_sock; + newlink->fromnode = link->fromnode->new_node; + newlink->fromsock = link->fromsock->new_sock; + + BKE_node_clipboard_add_link(newlink); + } + } + + return OPERATOR_FINISHED; +} + +void NODE_OT_clipboard_copy(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Copy to clipboard"; + ot->description = "Copies selected nodes to the clipboard"; + ot->idname = "NODE_OT_clipboard_copy"; + + /* api callbacks */ + ot->exec = node_clipboard_copy_exec; + ot->poll = ED_operator_node_active; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} + +/* ****************** Paste from clipboard ******************* */ + +static int node_clipboard_paste_exec(bContext *C, wmOperator *op) +{ + SpaceNode *snode = CTX_wm_space_node(C); + bNodeTree *ntree = snode->edittree; + bNode *gnode = node_tree_get_editgroup(snode->nodetree); + float gnode_x = 0.0f, gnode_y = 0.0f; + bNode *node; + bNodeLink *link; + int num_nodes; + float centerx, centery; + + if (BKE_node_clipboard_get_type() != ntree->type) { + BKE_report(op->reports, RPT_ERROR, "Clipboard nodes are an incompatible type"); + return OPERATOR_CANCELLED; + } + + ED_preview_kill_jobs(C); + + /* deselect old nodes */ + node_deselect_all(snode); + + /* get group node offset */ + if (gnode) + nodeToView(gnode, 0.0f, 0.0f, &gnode_x, &gnode_y); + + /* calculate "barycenter" for placing on mouse cursor */ + num_nodes = 0; + centerx = centery = 0.0f; + for (node = BKE_node_clipboard_get_nodes()->first; node; node = node->next) { + ++num_nodes; + centerx += 0.5f * (node->totr.xmin + node->totr.xmax); + centery += 0.5f * (node->totr.ymin + node->totr.ymax); + } + centerx /= num_nodes; + centery /= num_nodes; + + /* copy nodes from clipboard */ + for (node = BKE_node_clipboard_get_nodes()->first; node; node = node->next) { + bNode *new_node = nodeCopyNode(ntree, node); + + /* pasted nodes are selected */ + node_select(new_node); + } + + /* reparent copied nodes */ + for (node = BKE_node_clipboard_get_nodes()->first; node; node = node->next) { + bNode *new_node = node->new_node; + if (new_node->parent) + new_node->parent = new_node->parent->new_node; + + + /* place nodes around the mouse cursor. child nodes locations are relative to parent */ + if (!new_node->parent) { + new_node->locx += snode->cursor[0] - centerx - gnode_x; + new_node->locy += snode->cursor[1] - centery - gnode_y; + } + } + + for (link = BKE_node_clipboard_get_links()->first; link; link = link->next) { + nodeAddLink(ntree, link->fromnode->new_node, link->fromsock->new_sock, + link->tonode->new_node, link->tosock->new_sock); + } + + ntreeUpdateTree(snode->edittree); + + snode_notify(C, snode); + snode_dag_update(C, snode); + + return OPERATOR_FINISHED; +} + +static int node_clipboard_paste_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + ARegion *ar = CTX_wm_region(C); + SpaceNode *snode = CTX_wm_space_node(C); + + /* convert mouse coordinates to v2d space */ + UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &snode->cursor[0], &snode->cursor[1]); + + return node_clipboard_paste_exec(C, op); +} + +void NODE_OT_clipboard_paste(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Paste from clipboard"; + ot->description = "Pastes nodes from the clipboard to the active node tree"; + ot->idname = "NODE_OT_clipboard_paste"; + + /* api callbacks */ + ot->exec = node_clipboard_paste_exec; + ot->invoke = node_clipboard_paste_invoke; + ot->poll = ED_operator_node_active; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} diff --git a/source/blender/editors/space_node/node_group.c b/source/blender/editors/space_node/node_group.c index 41924d926d2..efd2378bf31 100644 --- a/source/blender/editors/space_node/node_group.c +++ b/source/blender/editors/space_node/node_group.c @@ -29,55 +29,24 @@ * \ingroup spnode */ - -#include <stdio.h> -#include <stdlib.h> -#include <math.h> -#include <string.h> -#include <errno.h> - #include "MEM_guardedalloc.h" -#include "DNA_ID.h" -#include "DNA_lamp_types.h" -#include "DNA_material_types.h" #include "DNA_node_types.h" #include "DNA_object_types.h" -#include "DNA_particle_types.h" -#include "DNA_scene_types.h" -#include "DNA_world_types.h" -#include "DNA_action_types.h" #include "DNA_anim_types.h" -#include "BLI_math.h" #include "BLI_blenlib.h" -#include "BLI_utildefines.h" #include "BKE_action.h" #include "BKE_animsys.h" #include "BKE_context.h" -#include "BKE_depsgraph.h" #include "BKE_global.h" -#include "BKE_image.h" #include "BKE_library.h" #include "BKE_main.h" -#include "BKE_node.h" -#include "BKE_material.h" -#include "BKE_modifier.h" -#include "BKE_paint.h" -#include "BKE_scene.h" -#include "BKE_screen.h" -#include "BKE_texture.h" #include "BKE_report.h" -#include "RE_pipeline.h" - -#include "IMB_imbuf_types.h" - -#include "ED_node.h" -#include "ED_image.h" +#include "ED_node.h" /* own include */ #include "ED_screen.h" -#include "ED_space_api.h" #include "ED_render.h" #include "RNA_access.h" @@ -87,17 +56,9 @@ #include "WM_api.h" #include "WM_types.h" -#include "UI_interface.h" #include "UI_resources.h" -#include "UI_view2d.h" - -#include "IMB_imbuf.h" -#include "RNA_enum_types.h" - -#include "GPU_material.h" - -#include "node_intern.h" +#include "node_intern.h" /* own include */ #include "NOD_socket.h" static EnumPropertyItem socket_in_out_items[] = { @@ -670,45 +631,50 @@ static int node_group_separate_selected(bNodeTree *ntree, bNode *gnode, int make /* add selected nodes into the ntree */ for (node = ngroup->nodes.first; node; node = node_next) { node_next = node->next; - if (!(node->flag & NODE_SELECT)) - continue; - - if (make_copy) { - /* make a copy */ - newnode = nodeCopyNode(ngroup, node); + if (node->flag & NODE_SELECT) { + + if (make_copy) { + /* make a copy */ + newnode = nodeCopyNode(ngroup, node); + } + else { + /* use the existing node */ + newnode = node; + } + + /* keep track of this node's RNA "base" path (the part of the path identifying the node) + * if the old nodetree has animation data which potentially covers this node + */ + if (ngroup->adt) { + PointerRNA ptr; + char *path; + + RNA_pointer_create(&ngroup->id, &RNA_Node, newnode, &ptr); + path = RNA_path_from_ID_to_struct(&ptr); + + if (path) + BLI_addtail(&anim_basepaths, BLI_genericNodeN(path)); + } + + /* ensure valid parent pointers, detach if parent stays inside the group */ + if (newnode->parent && !(newnode->parent->flag & NODE_SELECT)) + nodeDetachNode(newnode); + + /* migrate node */ + BLI_remlink(&ngroup->nodes, newnode); + BLI_addtail(&ntree->nodes, newnode); + + /* ensure unique node name in the node tree */ + nodeUniqueName(ntree, newnode); + + newnode->locx += gnode->locx; + newnode->locy += gnode->locy; } else { - /* use the existing node */ - newnode = node; - } - - /* keep track of this node's RNA "base" path (the part of the path identifying the node) - * if the old nodetree has animation data which potentially covers this node - */ - if (ngroup->adt) { - PointerRNA ptr; - char *path; - - RNA_pointer_create(&ngroup->id, &RNA_Node, newnode, &ptr); - path = RNA_path_from_ID_to_struct(&ptr); - - if (path) - BLI_addtail(&anim_basepaths, BLI_genericNodeN(path)); + /* ensure valid parent pointers, detach if child stays inside the group */ + if (node->parent && (node->parent->flag & NODE_SELECT)) + nodeDetachNode(node); } - - /* ensure valid parent pointers, detach if parent stays inside the group */ - if (newnode->parent && !(newnode->parent->flag & NODE_SELECT)) - nodeDetachNode(newnode); - - /* migrate node */ - BLI_remlink(&ngroup->nodes, newnode); - BLI_addtail(&ntree->nodes, newnode); - - /* ensure unique node name in the node tree */ - nodeUniqueName(ntree, newnode); - - newnode->locx += gnode->locx; - newnode->locy += gnode->locy; } /* add internal links to the ntree */ @@ -952,6 +918,11 @@ static int node_group_make_insert_selected(bNodeTree *ntree, bNode *gnode) node->locx -= 0.5f * (min[0] + max[0]); node->locy -= 0.5f * (min[1] + max[1]); } + else { + /* if the parent is to be inserted but not the child, detach properly */ + if (node->parent && (node->parent->flag & NODE_SELECT)) + nodeDetachNode(node); + } } /* move animation data over */ diff --git a/source/blender/editors/space_node/node_header.c b/source/blender/editors/space_node/node_header.c index d4cfa2a3ba2..f461174d74f 100644 --- a/source/blender/editors/space_node/node_header.c +++ b/source/blender/editors/space_node/node_header.c @@ -28,13 +28,10 @@ * \ingroup spnode */ - #include <string.h> -#include <stdio.h> #include "DNA_space_types.h" #include "DNA_node_types.h" -#include "DNA_scene_types.h" #include "DNA_screen_types.h" #include "MEM_guardedalloc.h" @@ -51,56 +48,51 @@ #include "BKE_scene.h" #include "BKE_screen.h" -#include "RNA_access.h" - #include "WM_api.h" #include "WM_types.h" -#include "UI_interface.h" -#include "UI_interface_icons.h" -#include "UI_resources.h" #include "UI_view2d.h" -#include "node_intern.h" +#include "node_intern.h" /* own include */ /* ************************ add menu *********************** */ static void do_node_add(bContext *C, bNodeTemplate *ntemp) { - Main *bmain= CTX_data_main(C); - Scene *scene= CTX_data_scene(C); - SpaceNode *snode= CTX_wm_space_node(C); - ScrArea *sa= CTX_wm_area(C); + Main *bmain = CTX_data_main(C); + Scene *scene = CTX_data_scene(C); + SpaceNode *snode = CTX_wm_space_node(C); + ScrArea *sa = CTX_wm_area(C); ARegion *ar; bNode *node; /* get location to add node at mouse */ - for (ar=sa->regionbase.first; ar; ar=ar->next) { + for (ar = sa->regionbase.first; ar; ar = ar->next) { if (ar->regiontype == RGN_TYPE_WINDOW) { - wmWindow *win= CTX_wm_window(C); - int x= win->eventstate->x - ar->winrct.xmin; - int y= win->eventstate->y - ar->winrct.ymin; + wmWindow *win = CTX_wm_window(C); + int x = win->eventstate->x - ar->winrct.xmin; + int y = win->eventstate->y - ar->winrct.ymin; - if (y < 60) y+= 60; - UI_view2d_region_to_view(&ar->v2d, x, y, &snode->mx, &snode->my); + if (y < 60) y += 60; + UI_view2d_region_to_view(&ar->v2d, x, y, &snode->cursor[0], &snode->cursor[1]); } } /* store selection in temp test flag */ - for (node= snode->edittree->nodes.first; node; node= node->next) { + for (node = snode->edittree->nodes.first; node; node = node->next) { if (node->flag & NODE_SELECT) node->flag |= NODE_TEST; else node->flag &= ~NODE_TEST; } - /* node= */ node_add_node(snode, bmain, scene, ntemp, snode->mx, snode->my); + /* node= */ node_add_node(snode, bmain, scene, ntemp, snode->cursor[0], snode->cursor[1]); /* select previous selection before autoconnect */ - for (node= snode->edittree->nodes.first; node; node= node->next) { + for (node = snode->edittree->nodes.first; node; node = node->next) { if (node->flag & NODE_TEST) node->flag |= NODE_SELECT; } /* deselect after autoconnection */ - for (node= snode->edittree->nodes.first; node; node= node->next) { + for (node = snode->edittree->nodes.first; node; node = node->next) { if (node->flag & NODE_TEST) node->flag &= ~NODE_SELECT; } @@ -123,29 +115,29 @@ static void do_node_add_static(bContext *C, void *UNUSED(arg), int event) static void do_node_add_group(bContext *C, void *UNUSED(arg), int event) { - SpaceNode *snode= CTX_wm_space_node(C); + SpaceNode *snode = CTX_wm_space_node(C); Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); bNodeTemplate ntemp; - if (event>=0) { - ntemp.ngroup= BLI_findlink(&G.main->nodetree, event); + if (event >= 0) { + ntemp.ngroup = BLI_findlink(&G.main->nodetree, event); ntemp.type = ntemp.ngroup->nodetype; } else { ntemp.type = -event; switch (ntemp.type) { - case NODE_GROUP: - ntemp.ngroup = ntreeAddTree("Group", snode->treetype, ntemp.type); - break; - case NODE_FORLOOP: - ntemp.ngroup = ntreeAddTree("For Loop", snode->treetype, ntemp.type); - break; - case NODE_WHILELOOP: - ntemp.ngroup = ntreeAddTree("While Loop", snode->treetype, ntemp.type); - break; - default: - ntemp.ngroup = NULL; + case NODE_GROUP: + ntemp.ngroup = ntreeAddTree("Group", snode->treetype, ntemp.type); + break; + case NODE_FORLOOP: + ntemp.ngroup = ntreeAddTree("For Loop", snode->treetype, ntemp.type); + break; + case NODE_WHILELOOP: + ntemp.ngroup = ntreeAddTree("While Loop", snode->treetype, ntemp.type); + break; + default: + ntemp.ngroup = NULL; } } if (!ntemp.ngroup) @@ -159,10 +151,10 @@ static void do_node_add_group(bContext *C, void *UNUSED(arg), int event) static int node_tree_has_type(int treetype, int nodetype) { - bNodeTreeType *ttype= ntreeGetType(treetype); + bNodeTreeType *ttype = ntreeGetType(treetype); bNodeType *ntype; - for (ntype=ttype->node_types.first; ntype; ntype=ntype->next) { - if (ntype->type==nodetype) + for (ntype = ttype->node_types.first; ntype; ntype = ntype->next) { + if (ntype->type == nodetype) return 1; } return 0; @@ -170,12 +162,12 @@ static int node_tree_has_type(int treetype, int nodetype) static void node_add_menu(bContext *C, uiLayout *layout, void *arg_nodeclass) { - Main *bmain= CTX_data_main(C); - Scene *scene= CTX_data_scene(C); - SpaceNode *snode= CTX_wm_space_node(C); + Main *bmain = CTX_data_main(C); + Scene *scene = CTX_data_scene(C); + SpaceNode *snode = CTX_wm_space_node(C); bNodeTree *ntree; - int nodeclass= GET_INT_FROM_POINTER(arg_nodeclass); - int event, compatibility= 0; + int nodeclass = GET_INT_FROM_POINTER(arg_nodeclass); + int event, compatibility = 0; ntree = snode->nodetree; @@ -186,12 +178,12 @@ static void node_add_menu(bContext *C, uiLayout *layout, void *arg_nodeclass) if (ntree->type == NTREE_SHADER) { if (BKE_scene_use_new_shading_nodes(scene)) - compatibility= NODE_NEW_SHADING; + compatibility = NODE_NEW_SHADING; else - compatibility= NODE_OLD_SHADING; + compatibility = NODE_OLD_SHADING; } - if (nodeclass==NODE_CLASS_GROUP) { + if (nodeclass == NODE_CLASS_GROUP) { bNodeTree *ngroup; uiLayoutSetFunc(layout, do_node_add_group, NULL); @@ -205,10 +197,10 @@ static void node_add_menu(bContext *C, uiLayout *layout, void *arg_nodeclass) uiItemV(layout, IFACE_("New While Loop"), 0, -NODE_WHILELOOP); uiItemS(layout); - for (ngroup=bmain->nodetree.first, event=0; ngroup; ngroup= ngroup->id.next, ++event) { + for (ngroup = bmain->nodetree.first, event = 0; ngroup; ngroup = ngroup->id.next, ++event) { /* only use group trees */ - if (ngroup->type==ntree->type && ELEM3(ngroup->nodetype, NODE_GROUP, NODE_FORLOOP, NODE_WHILELOOP)) { - uiItemV(layout, ngroup->id.name+2, 0, event); + if (ngroup->type == ntree->type && ELEM3(ngroup->nodetype, NODE_GROUP, NODE_FORLOOP, NODE_WHILELOOP)) { + uiItemV(layout, ngroup->id.name + 2, 0, event); } } } @@ -217,30 +209,35 @@ static void node_add_menu(bContext *C, uiLayout *layout, void *arg_nodeclass) uiLayoutSetFunc(layout, do_node_add_static, NULL); - for (ntype=ntreeGetType(ntree->type)->node_types.first; ntype; ntype=ntype->next) { - if (ntype->nclass==nodeclass && ntype->name) - if (!compatibility || (ntype->compatibility & compatibility)) + for (ntype = ntreeGetType(ntree->type)->node_types.first; ntype; ntype = ntype->next) { + if (ntype->nclass == nodeclass && ntype->name) { + if (!compatibility || (ntype->compatibility & compatibility)) { uiItemV(layout, IFACE_(ntype->name), 0, ntype->type); + } + } } } } static void node_menu_add_foreach_cb(void *calldata, int nclass, const char *name) { - uiLayout *layout= calldata; + uiLayout *layout = calldata; uiItemMenuF(layout, IFACE_(name), 0, node_add_menu, SET_INT_IN_POINTER(nclass)); } static void node_menu_add(const bContext *C, Menu *menu) { - Scene *scene= CTX_data_scene(C); - SpaceNode *snode= CTX_wm_space_node(C); - uiLayout *layout= menu->layout; - bNodeTreeType *ntreetype= ntreeGetType(snode->treetype); + Scene *scene = CTX_data_scene(C); + SpaceNode *snode = CTX_wm_space_node(C); + uiLayout *layout = menu->layout; + bNodeTreeType *ntreetype = ntreeGetType(snode->treetype); if (!snode->nodetree) uiLayoutSetActive(layout, FALSE); + uiLayoutSetOperatorContext(layout, WM_OP_INVOKE_DEFAULT); + uiItemO(layout, "Search ...", 0, "NODE_OT_add_search"); + if (ntreetype && ntreetype->foreach_nodeclass) ntreetype->foreach_nodeclass(scene, layout, node_menu_add_foreach_cb); } @@ -249,10 +246,9 @@ void node_menus_register(void) { MenuType *mt; - mt= MEM_callocN(sizeof(MenuType), "spacetype node menu add"); + mt = MEM_callocN(sizeof(MenuType), "spacetype node menu add"); strcpy(mt->idname, "NODE_MT_add"); strcpy(mt->label, "Add"); - mt->draw= node_menu_add; + mt->draw = node_menu_add; WM_menutype_add(mt); } - diff --git a/source/blender/editors/space_node/node_intern.h b/source/blender/editors/space_node/node_intern.h index 5c6a91195a6..048e09efab5 100644 --- a/source/blender/editors/space_node/node_intern.h +++ b/source/blender/editors/space_node/node_intern.h @@ -111,13 +111,18 @@ void NODE_OT_select_same_type(struct wmOperatorType *ot); void NODE_OT_select_same_type_next(wmOperatorType *ot); void NODE_OT_select_same_type_prev(wmOperatorType *ot); -/* node_state.c */ +/* node_view.c */ void NODE_OT_view_all(struct wmOperatorType *ot); +void NODE_OT_view_selected(struct wmOperatorType *ot); + +void NODE_OT_backimage_move(struct wmOperatorType *ot); +void NODE_OT_backimage_zoom(struct wmOperatorType *ot); +void NODE_OT_backimage_sample(wmOperatorType *ot); /* drawnode.c */ void node_draw_link(View2D *v2d, SpaceNode *snode, bNodeLink *link); -void node_draw_link_bezier(View2D *v2d, SpaceNode *snode, bNodeLink *link, int th_col1, int do_shaded, int th_col2, int do_triple, int th_col3 ); -int node_link_bezier_points(View2D *v2d, SpaceNode *snode, bNodeLink *link, float coord_array[][2], int resol); +void node_draw_link_bezier(View2D *v2d, SpaceNode *snode, bNodeLink *link, int th_col1, int do_shaded, int th_col2, int do_triple, int th_col3); +int node_link_bezier_points(View2D * v2d, SpaceNode * snode, bNodeLink * link, float coord_array[][2], int resol); // void node_draw_link_straight(View2D *v2d, SpaceNode *snode, bNodeLink *link, int th_col1, int do_shaded, int th_col2, int do_triple, int th_col3 ); void draw_nodespace_back_pix(ARegion *ar, SpaceNode *snode, int color_manage); @@ -165,7 +170,7 @@ void snode_notify(bContext *C, SpaceNode *snode); void snode_dag_update(bContext *C, SpaceNode *snode); void snode_set_context(SpaceNode *snode, Scene *scene); void snode_make_group_editable(SpaceNode *snode, bNode *gnode); -void snode_composite_job(const struct bContext *C, ScrArea *sa); + bNode *node_tree_get_editgroup(bNodeTree *ntree); void snode_update(struct SpaceNode *snode, struct bNode *node); bNode *editnode_get_active(bNodeTree *ntree); @@ -192,31 +197,31 @@ void NODE_OT_read_fullsamplelayers(struct wmOperatorType *ot); void NODE_OT_read_renderlayers(struct wmOperatorType *ot); void NODE_OT_render_changed(struct wmOperatorType *ot); -void NODE_OT_backimage_move(struct wmOperatorType *ot); -void NODE_OT_backimage_zoom(struct wmOperatorType *ot); -void NODE_OT_backimage_sample(wmOperatorType *ot); - void NODE_OT_output_file_add_socket(struct wmOperatorType *ot); void NODE_OT_output_file_remove_active_socket(struct wmOperatorType *ot); void NODE_OT_output_file_move_active_socket(struct wmOperatorType *ot); +/* Note: clipboard_cut is a simple macro of copy + delete */ +void NODE_OT_clipboard_copy(struct wmOperatorType *ot); +void NODE_OT_clipboard_paste(struct wmOperatorType *ot); + extern const char *node_context_dir[]; // XXXXXX // XXX from BSE_node.h -#define HIDDEN_RAD 15.0f -#define BASIS_RAD 8.0f -#define NODE_DYS (U.widget_unit/2) -#define NODE_DY U.widget_unit +#define HIDDEN_RAD 15.0f +#define BASIS_RAD 8.0f +#define NODE_DYS (U.widget_unit / 2) +#define NODE_DY U.widget_unit #define NODE_MARGIN_X 15 -#define NODE_SOCKSIZE 5 +#define NODE_SOCKSIZE 5 #define NODE_LINK_RESOL 12 // XXX button events (butspace) enum { B_NOP = 0, - B_REDR = 1, + B_REDR = 1, B_NODE_USEMAT, B_NODE_USESCENE, B_NODE_USETEX, diff --git a/source/blender/editors/space_node/node_ops.c b/source/blender/editors/space_node/node_ops.c index 0ce72848c56..195dd60b72a 100644 --- a/source/blender/editors/space_node/node_ops.c +++ b/source/blender/editors/space_node/node_ops.c @@ -30,13 +30,12 @@ #include "DNA_node_types.h" -#include "DNA_scene_types.h" #include "BKE_context.h" #include "BLI_utildefines.h" -#include "ED_node.h" +#include "ED_node.h" /* own include */ #include "ED_screen.h" #include "ED_transform.h" @@ -45,7 +44,7 @@ #include "WM_api.h" #include "WM_types.h" -#include "node_intern.h" +#include "node_intern.h" /* own include */ void node_operatortypes(void) { @@ -61,6 +60,7 @@ void node_operatortypes(void) WM_operatortype_append(NODE_OT_select_same_type_prev); WM_operatortype_append(NODE_OT_view_all); + WM_operatortype_append(NODE_OT_view_selected); WM_operatortype_append(NODE_OT_mute_toggle); WM_operatortype_append(NODE_OT_hide_toggle); @@ -113,6 +113,9 @@ void node_operatortypes(void) WM_operatortype_append(NODE_OT_join); WM_operatortype_append(NODE_OT_attach); WM_operatortype_append(NODE_OT_detach); + + WM_operatortype_append(NODE_OT_clipboard_copy); + WM_operatortype_append(NODE_OT_clipboard_paste); } void ED_operatormacros_node(void) @@ -128,14 +131,14 @@ void ED_operatormacros_node(void) ot = WM_operatortype_append_macro("NODE_OT_translate_attach", "Move and Attach", "Move nodes and attach to frame", - OPTYPE_UNDO|OPTYPE_REGISTER); + OPTYPE_UNDO | OPTYPE_REGISTER); mot = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); RNA_boolean_set(mot->ptr, "release_confirm", TRUE); WM_operatortype_macro_define(ot, "NODE_OT_attach"); ot = WM_operatortype_append_macro("NODE_OT_detach_translate_attach", "Detach and Move", "Detach nodes, move and attach to frame", - OPTYPE_UNDO|OPTYPE_REGISTER); + OPTYPE_UNDO | OPTYPE_REGISTER); WM_operatortype_macro_define(ot, "NODE_OT_detach"); mot = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); RNA_boolean_set(mot->ptr, "release_confirm", TRUE); @@ -143,25 +146,25 @@ void ED_operatormacros_node(void) ot = WM_operatortype_append_macro("NODE_OT_duplicate_move", "Duplicate", "Duplicate selected nodes and move them", - OPTYPE_UNDO|OPTYPE_REGISTER); + OPTYPE_UNDO | OPTYPE_REGISTER); WM_operatortype_macro_define(ot, "NODE_OT_duplicate"); WM_operatortype_macro_define(ot, "NODE_OT_translate_attach"); /* modified operator call for duplicating with input links */ ot = WM_operatortype_append_macro("NODE_OT_duplicate_move_keep_inputs", "Duplicate", "Duplicate selected nodes keeping input links and move them", - OPTYPE_UNDO|OPTYPE_REGISTER); + OPTYPE_UNDO | OPTYPE_REGISTER); mot = WM_operatortype_macro_define(ot, "NODE_OT_duplicate"); RNA_boolean_set(mot->ptr, "keep_inputs", TRUE); WM_operatortype_macro_define(ot, "NODE_OT_translate_attach"); ot = WM_operatortype_append_macro("NODE_OT_move_detach_links", "Detach", "Move a node to detach links", - OPTYPE_UNDO|OPTYPE_REGISTER); + OPTYPE_UNDO | OPTYPE_REGISTER); WM_operatortype_macro_define(ot, "NODE_OT_links_detach"); WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); ot = WM_operatortype_append_macro("NODE_OT_move_detach_links_release", "Detach", "Move a node to detach links", - OPTYPE_UNDO|OPTYPE_REGISTER); + OPTYPE_UNDO | OPTYPE_REGISTER); WM_operatortype_macro_define(ot, "NODE_OT_links_detach"); mot = WM_operatortype_macro_define(ot, "NODE_OT_translate_attach"); } @@ -170,18 +173,18 @@ void ED_operatormacros_node(void) static void node_select_keymap(wmKeyMap *keymap, int extend) { /* modifier combinations */ - const int mod_single[] = { 0, KM_CTRL, KM_ALT, KM_CTRL|KM_ALT, + const int mod_single[] = { 0, KM_CTRL, KM_ALT, KM_CTRL | KM_ALT, -1 /* terminator */ - }; - const int mod_extend[] = { KM_SHIFT, KM_SHIFT|KM_CTRL, - KM_SHIFT|KM_ALT, KM_SHIFT|KM_CTRL|KM_ALT, + }; + const int mod_extend[] = { KM_SHIFT, KM_SHIFT | KM_CTRL, + KM_SHIFT | KM_ALT, KM_SHIFT | KM_CTRL | KM_ALT, -1 /* terminator */ - }; + }; const int *mod = (extend ? mod_extend : mod_single); wmKeyMapItem *kmi; int i; - for (i=0; mod[i] >= 0; ++i) { + for (i = 0; mod[i] >= 0; ++i) { kmi = WM_keymap_add_item(keymap, "NODE_OT_select", ACTIONMOUSE, KM_PRESS, mod[i], 0); RNA_boolean_set(kmi->ptr, "extend", extend); kmi = WM_keymap_add_item(keymap, "NODE_OT_select", SELECTMOUSE, KM_PRESS, mod[i], 0); @@ -212,23 +215,23 @@ void node_keymap(struct wmKeyConfig *keyconf) node_select_keymap(keymap, TRUE); kmi = WM_keymap_add_item(keymap, "NODE_OT_select_border", EVT_TWEAK_S, KM_ANY, 0, 0); - RNA_boolean_set(kmi->ptr, "tweak", TRUE); + RNA_boolean_set(kmi->ptr, "tweak", TRUE); /* each of these falls through if not handled... */ WM_keymap_add_item(keymap, "NODE_OT_link", LEFTMOUSE, KM_PRESS, 0, 0); kmi = WM_keymap_add_item(keymap, "NODE_OT_link", LEFTMOUSE, KM_PRESS, KM_CTRL, 0); - RNA_boolean_set(kmi->ptr, "detach", TRUE); + RNA_boolean_set(kmi->ptr, "detach", TRUE); WM_keymap_add_item(keymap, "NODE_OT_resize", LEFTMOUSE, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "NODE_OT_add_reroute", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0); WM_keymap_add_item(keymap, "NODE_OT_links_cut", LEFTMOUSE, KM_PRESS, KM_CTRL, 0); - WM_keymap_add_item(keymap, "NODE_OT_select_link_viewer", LEFTMOUSE, KM_PRESS, KM_SHIFT|KM_CTRL, 0); + WM_keymap_add_item(keymap, "NODE_OT_select_link_viewer", LEFTMOUSE, KM_PRESS, KM_SHIFT | KM_CTRL, 0); WM_keymap_add_item(keymap, "NODE_OT_backimage_move", MIDDLEMOUSE, KM_PRESS, KM_ALT, 0); kmi = WM_keymap_add_item(keymap, "NODE_OT_backimage_zoom", VKEY, KM_PRESS, 0, 0); - RNA_float_set(kmi->ptr, "factor", 0.83333f); + RNA_float_set(kmi->ptr, "factor", 0.83333f); kmi = WM_keymap_add_item(keymap, "NODE_OT_backimage_zoom", VKEY, KM_PRESS, KM_ALT, 0); - RNA_float_set(kmi->ptr, "factor", 1.2f); + RNA_float_set(kmi->ptr, "factor", 1.2f); WM_keymap_add_item(keymap, "NODE_OT_backimage_sample", ACTIONMOUSE, KM_PRESS, KM_ALT, 0); kmi = WM_keymap_add_item(keymap, "NODE_OT_link_make", FKEY, KM_PRESS, 0, 0); @@ -239,7 +242,7 @@ void node_keymap(struct wmKeyConfig *keyconf) WM_keymap_add_menu(keymap, "NODE_MT_add", AKEY, KM_PRESS, KM_SHIFT, 0); WM_keymap_add_item(keymap, "NODE_OT_duplicate_move", DKEY, KM_PRESS, KM_SHIFT, 0); /* modified operator call for duplicating with input links */ - WM_keymap_add_item(keymap, "NODE_OT_duplicate_move_keep_inputs", DKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0); + WM_keymap_add_item(keymap, "NODE_OT_duplicate_move_keep_inputs", DKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0); WM_keymap_add_item(keymap, "NODE_OT_parent_set", PKEY, KM_PRESS, KM_CTRL, 0); WM_keymap_add_item(keymap, "NODE_OT_parent_clear", PKEY, KM_PRESS, KM_ALT, 0); @@ -253,6 +256,7 @@ void node_keymap(struct wmKeyConfig *keyconf) WM_keymap_add_item(keymap, "NODE_OT_show_cyclic_dependencies", CKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "NODE_OT_view_all", HOMEKEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "NODE_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0); kmi = WM_keymap_add_item(keymap, "NODE_OT_select_border", BKEY, KM_PRESS, 0, 0); RNA_boolean_set(kmi->ptr, "tweak", FALSE); @@ -281,5 +285,8 @@ void node_keymap(struct wmKeyConfig *keyconf) WM_keymap_add_item(keymap, "NODE_OT_read_fullsamplelayers", RKEY, KM_PRESS, KM_SHIFT, 0); WM_keymap_add_item(keymap, "NODE_OT_render_changed", ZKEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "NODE_OT_clipboard_copy", CKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_item(keymap, "NODE_OT_clipboard_paste", VKEY, KM_PRESS, KM_CTRL, 0); + transform_keymap_for_space(keyconf, keymap, SPACE_NODE); } diff --git a/source/blender/editors/space_node/node_relationships.c b/source/blender/editors/space_node/node_relationships.c index 4fcc2abece4..6295a568113 100644 --- a/source/blender/editors/space_node/node_relationships.c +++ b/source/blender/editors/space_node/node_relationships.c @@ -29,76 +29,31 @@ * \ingroup spnode */ -#include <stdio.h> -#include <stdlib.h> -#include <math.h> -#include <string.h> -#include <errno.h> - #include "MEM_guardedalloc.h" -#include "DNA_ID.h" -#include "DNA_lamp_types.h" -#include "DNA_material_types.h" #include "DNA_node_types.h" #include "DNA_object_types.h" -#include "DNA_particle_types.h" -#include "DNA_scene_types.h" -#include "DNA_world_types.h" -#include "DNA_action_types.h" -#include "DNA_anim_types.h" #include "BLI_math.h" #include "BLI_blenlib.h" -#include "BLI_utildefines.h" -#include "BKE_action.h" -#include "BKE_animsys.h" #include "BKE_context.h" -#include "BKE_depsgraph.h" -#include "BKE_global.h" -#include "BKE_image.h" -#include "BKE_library.h" #include "BKE_main.h" #include "BKE_node.h" -#include "BKE_material.h" -#include "BKE_modifier.h" -#include "BKE_paint.h" -#include "BKE_scene.h" -#include "BKE_screen.h" -#include "BKE_texture.h" -#include "BKE_report.h" - -#include "RE_pipeline.h" -#include "IMB_imbuf_types.h" - -#include "ED_node.h" -#include "ED_image.h" +#include "ED_node.h" /* own include */ #include "ED_screen.h" -#include "ED_space_api.h" #include "ED_render.h" #include "RNA_access.h" #include "RNA_define.h" -#include "RNA_enum_types.h" #include "WM_api.h" #include "WM_types.h" -#include "UI_interface.h" -#include "UI_resources.h" #include "UI_view2d.h" -#include "IMB_imbuf.h" - -#include "RNA_enum_types.h" - -#include "GPU_material.h" - -#include "node_intern.h" -#include "NOD_socket.h" - +#include "node_intern.h" /* own include */ /* ****************** Add *********************** */ @@ -482,10 +437,10 @@ static int outside_group_rect(SpaceNode *snode) { bNode *gnode = node_tree_get_editgroup(snode->nodetree); if (gnode) { - return (snode->mx < gnode->totr.xmin || - snode->mx >= gnode->totr.xmax || - snode->my < gnode->totr.ymin || - snode->my >= gnode->totr.ymax); + return (snode->cursor[0] < gnode->totr.xmin || + snode->cursor[0] >= gnode->totr.xmax || + snode->cursor[1] < gnode->totr.ymin || + snode->cursor[1] >= gnode->totr.ymax); } return 0; } @@ -507,7 +462,7 @@ static int node_link_modal(bContext *C, wmOperator *op, wmEvent *event) in_out = nldrag->in_out; UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], - &snode->mx, &snode->my); + &snode->cursor[0], &snode->cursor[1]); switch (event->type) { case MOUSEMOVE: @@ -753,7 +708,7 @@ static int node_link_invoke(bContext *C, wmOperator *op, wmEvent *event) int detach = RNA_boolean_get(op->ptr, "detach"); UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], - &snode->mx, &snode->my); + &snode->cursor[0], &snode->cursor[1]); ED_preview_kill_jobs(C); @@ -881,24 +836,35 @@ static int cut_links_exec(bContext *C, wmOperator *op) RNA_END; if (i > 1) { + int found = FALSE; bNodeLink *link, *next; - ED_preview_kill_jobs(C); - for (link = snode->edittree->links.first; link; link = next) { next = link->next; if (cut_links_intersect(link, mcoords, i)) { + + if (found == FALSE) { + ED_preview_kill_jobs(C); + found = TRUE; + } + snode_update(snode, link->tonode); nodeRemLink(snode->edittree, link); } } - ntreeUpdateTree(snode->edittree); - snode_notify(C, snode); - snode_dag_update(C, snode); + if (found) { + ntreeUpdateTree(snode->edittree); + snode_notify(C, snode); + snode_dag_update(C, snode); + + return OPERATOR_FINISHED; + } + else { + return OPERATOR_CANCELLED; + } - return OPERATOR_FINISHED; } return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH; @@ -1173,7 +1139,7 @@ static int node_attach_exec(bContext *C, wmOperator *UNUSED(op)) /* skip selected, those are the nodes we want to attach */ if ((frame->type != NODE_FRAME) || (frame->flag & NODE_SELECT)) continue; - if (BLI_in_rctf(&frame->totr, snode->mx, snode->my)) + if (BLI_in_rctf(&frame->totr, snode->cursor[0], snode->cursor[1])) break; } if (frame) { @@ -1181,17 +1147,26 @@ static int node_attach_exec(bContext *C, wmOperator *UNUSED(op)) for (node = ntree->nodes.last; node; node = node->prev) { if (node->flag & NODE_SELECT) { if (node->parent == NULL) { - /* attach all unparented nodes */ - nodeAttachNode(node, frame); + /* disallow moving a parent into its child */ + if (nodeAttachNodeCheck(frame, node) == FALSE) { + /* attach all unparented nodes */ + nodeAttachNode(node, frame); + } } else { /* attach nodes which share parent with the frame */ - for (parent = frame->parent; parent; parent = parent->parent) - if (parent == node->parent) + for (parent = frame->parent; parent; parent = parent->parent) { + if (parent == node->parent) { break; + } + } + if (parent) { - nodeDetachNode(node); - nodeAttachNode(node, frame); + /* disallow moving a parent into its child */ + if (nodeAttachNodeCheck(frame, node) == FALSE) { + nodeDetachNode(node); + nodeAttachNode(node, frame); + } } } } @@ -1210,7 +1185,7 @@ static int node_attach_invoke(bContext *C, wmOperator *op, wmEvent *event) SpaceNode *snode = CTX_wm_space_node(C); /* convert mouse coordinates to v2d space */ - UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &snode->mx, &snode->my); + UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &snode->cursor[0], &snode->cursor[1]); return node_attach_exec(C, op); } diff --git a/source/blender/editors/space_node/node_select.c b/source/blender/editors/space_node/node_select.c index 603603b9f07..7b90d66c11c 100644 --- a/source/blender/editors/space_node/node_select.c +++ b/source/blender/editors/space_node/node_select.c @@ -28,13 +28,7 @@ * \ingroup spnode */ - -#include <stdio.h> - -#include "BLI_listbase.h" - #include "DNA_node_types.h" -#include "DNA_scene_types.h" #include "BKE_context.h" #include "BKE_main.h" @@ -43,7 +37,7 @@ #include "BLI_rect.h" #include "BLI_utildefines.h" -#include "ED_node.h" +#include "ED_node.h" /* own include */ #include "ED_screen.h" #include "ED_types.h" @@ -55,7 +49,7 @@ #include "UI_view2d.h" -#include "node_intern.h" +#include "node_intern.h" /* own include */ /* ****** helpers ****** */ @@ -63,7 +57,7 @@ static bNode *node_under_mouse_select(bNodeTree *ntree, int mx, int my) { bNode *node; - for (node=ntree->nodes.last; node; node=node->prev) { + for (node = ntree->nodes.last; node; node = node->prev) { if (node->typeinfo->select_area_func) { if (node->typeinfo->select_area_func(node, mx, my)) return node; @@ -76,7 +70,7 @@ static bNode *node_under_mouse_tweak(bNodeTree *ntree, int mx, int my) { bNode *node; - for (node=ntree->nodes.last; node; node=node->prev) { + for (node = ntree->nodes.last; node; node = node->prev) { if (node->typeinfo->tweak_area_func) { if (node->typeinfo->tweak_area_func(node, mx, my)) return node; @@ -97,9 +91,9 @@ void node_deselect(bNode *node) node->flag &= ~SELECT; /* deselect sockets too */ - for (sock=node->inputs.first; sock; sock=sock->next) + for (sock = node->inputs.first; sock; sock = sock->next) sock->flag &= ~SELECT; - for (sock=node->outputs.first; sock; sock=sock->next) + for (sock = node->outputs.first; sock; sock = sock->next) sock->flag &= ~SELECT; } @@ -125,16 +119,16 @@ void node_socket_deselect(bNode *node, bNodeSocket *sock, int deselect_node) sock->flag &= ~SELECT; if (node && deselect_node) { - int sel=0; + int sel = 0; /* if no selected sockets remain, also deselect the node */ - for (sock=node->inputs.first; sock; sock=sock->next) { + for (sock = node->inputs.first; sock; sock = sock->next) { if (sock->flag & SELECT) { sel = 1; break; } } - for (sock=node->outputs.first; sock; sock=sock->next) { + for (sock = node->outputs.first; sock; sock = sock->next) { if (sock->flag & SELECT) { sel = 1; break; @@ -159,7 +153,7 @@ void node_deselect_all(SpaceNode *snode) { bNode *node; - for (node= snode->edittree->nodes.first; node; node= node->next) + for (node = snode->edittree->nodes.first; node; node = node->next) node_deselect(node); } @@ -173,15 +167,15 @@ void node_deselect_all_input_sockets(SpaceNode *snode, int deselect_nodes) * We can do that more efficiently here. */ - for (node= snode->edittree->nodes.first; node; node= node->next) { - int sel=0; + for (node = snode->edittree->nodes.first; node; node = node->next) { + int sel = 0; - for (sock= node->inputs.first; sock; sock=sock->next) + for (sock = node->inputs.first; sock; sock = sock->next) sock->flag &= ~SELECT; /* if no selected sockets remain, also deselect the node */ if (deselect_nodes) { - for (sock= node->outputs.first; sock; sock=sock->next) { + for (sock = node->outputs.first; sock; sock = sock->next) { if (sock->flag & SELECT) { sel = 1; break; @@ -193,7 +187,7 @@ void node_deselect_all_input_sockets(SpaceNode *snode, int deselect_nodes) } } - for (sock= snode->edittree->outputs.first; sock; sock=sock->next) + for (sock = snode->edittree->outputs.first; sock; sock = sock->next) sock->flag &= ~SELECT; } @@ -207,15 +201,15 @@ void node_deselect_all_output_sockets(SpaceNode *snode, int deselect_nodes) * We can do that more efficiently here. */ - for (node= snode->edittree->nodes.first; node; node= node->next) { - int sel=0; + for (node = snode->edittree->nodes.first; node; node = node->next) { + int sel = 0; - for (sock= node->outputs.first; sock; sock=sock->next) + for (sock = node->outputs.first; sock; sock = sock->next) sock->flag &= ~SELECT; /* if no selected sockets remain, also deselect the node */ if (deselect_nodes) { - for (sock= node->inputs.first; sock; sock=sock->next) { + for (sock = node->inputs.first; sock; sock = sock->next) { if (sock->flag & SELECT) { sel = 1; break; @@ -227,7 +221,7 @@ void node_deselect_all_output_sockets(SpaceNode *snode, int deselect_nodes) } } - for (sock= snode->edittree->inputs.first; sock; sock=sock->next) + for (sock = snode->edittree->inputs.first; sock; sock = sock->next) sock->flag &= ~SELECT; } @@ -238,7 +232,7 @@ int node_select_same_type(SpaceNode *snode) int redraw; /* search for the active node. */ - for (nac= snode->edittree->nodes.first; nac; nac= nac->next) { + for (nac = snode->edittree->nodes.first; nac; nac = nac->next) { if (nac->flag & SELECT) break; } @@ -247,16 +241,16 @@ int node_select_same_type(SpaceNode *snode) if (!nac) return(0); - redraw= 0; - for (p= snode->edittree->nodes.first; p; p= p->next) { + redraw = 0; + for (p = snode->edittree->nodes.first; p; p = p->next) { if (p->type != nac->type && p->flag & SELECT) { /* if it's selected but different type, unselect */ - redraw= 1; + redraw = 1; node_deselect(p); } else if (p->type == nac->type && (!(p->flag & SELECT))) { /* if it's the same type and is not selected, select! */ - redraw= 1; + redraw = 1; node_select(p); } } @@ -271,7 +265,7 @@ int node_select_same_type_np(SpaceNode *snode, int dir) bNode *nac, *p, *tnode; /* search the active one. */ - for (nac= snode->edittree->nodes.first; nac; nac= nac->next) { + for (nac = snode->edittree->nodes.first; nac; nac = nac->next) { if (nac->flag & SELECT) break; } @@ -281,9 +275,9 @@ int node_select_same_type_np(SpaceNode *snode, int dir) return(0); if (dir == 0) - p= nac->next; + p = nac->next; else - p= nac->prev; + p = nac->prev; while (p) { /* Now search the next with the same type. */ @@ -291,14 +285,14 @@ int node_select_same_type_np(SpaceNode *snode, int dir) break; if (dir == 0) - p= p->next; + p = p->next; else - p= p->prev; + p = p->prev; } if (p) { - for (tnode=snode->edittree->nodes.first; tnode; tnode=tnode->next) - if (tnode!=p) + for (tnode = snode->edittree->nodes.first; tnode; tnode = tnode->next) + if (tnode != p) node_deselect(tnode); node_select(p); return(1); @@ -308,12 +302,12 @@ int node_select_same_type_np(SpaceNode *snode, int dir) void node_select_single(bContext *C, bNode *node) { - Main *bmain= CTX_data_main(C); - SpaceNode *snode= CTX_wm_space_node(C); + Main *bmain = CTX_data_main(C); + SpaceNode *snode = CTX_wm_space_node(C); bNode *tnode; - for (tnode=snode->edittree->nodes.first; tnode; tnode=tnode->next) - if (tnode!=node) + for (tnode = snode->edittree->nodes.first; tnode; tnode = tnode->next) + if (tnode != node) node_deselect(tnode); node_select(node); @@ -321,7 +315,7 @@ void node_select_single(bContext *C, bNode *node) ED_node_sort(snode->edittree); - WM_event_add_notifier(C, NC_NODE|NA_SELECTED, NULL); + WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL); } /* ****** Click Select ****** */ @@ -336,8 +330,8 @@ static int node_mouse_select(Main *bmain, SpaceNode *snode, ARegion *ar, const i /* get mouse coordinates in view2d space */ UI_view2d_region_to_view(&ar->v2d, mval[0], mval[1], &mx, &my); /* node_find_indicated_socket uses snode->mx/my */ - snode->mx = mx; - snode->my = my; + snode->cursor[0] = mx; + snode->cursor[1] = my; if (extend) { /* first do socket selection, these generally overlap with nodes. @@ -356,7 +350,7 @@ static int node_mouse_select(Main *bmain, SpaceNode *snode, ARegion *ar, const i * allows selecting outputs from different nodes though. */ if (node) { - for (tsock=node->outputs.first; tsock; tsock=tsock->next) + for (tsock = node->outputs.first; tsock; tsock = tsock->next) node_socket_deselect(node, tsock, 1); } node_socket_select(node, sock); @@ -368,20 +362,28 @@ static int node_mouse_select(Main *bmain, SpaceNode *snode, ARegion *ar, const i node = node_under_mouse_select(snode->edittree, mx, my); if (node) { - node_toggle(node); - - ED_node_set_active(bmain, snode->edittree, node); + if ((node->flag & SELECT) && (node->flag & NODE_ACTIVE) == 0) { + /* if node is selected but not active make it active + * before it'll be desleected + */ + ED_node_set_active(bmain, snode->edittree, node); + } + else { + node_toggle(node); + ED_node_set_active(bmain, snode->edittree, node); + } + selected = 1; } } } - else { /* extend==0 */ + else { /* extend==0 */ /* find the closest visible node */ node = node_under_mouse_select(snode->edittree, mx, my); if (node) { - for (tnode=snode->edittree->nodes.first; tnode; tnode=tnode->next) + for (tnode = snode->edittree->nodes.first; tnode; tnode = tnode->next) node_deselect(tnode); node_select(node); ED_node_set_active(bmain, snode->edittree, node); @@ -398,9 +400,9 @@ static int node_mouse_select(Main *bmain, SpaceNode *snode, ARegion *ar, const i static int node_select_exec(bContext *C, wmOperator *op) { - Main *bmain= CTX_data_main(C); - SpaceNode *snode= CTX_wm_space_node(C); - ARegion *ar= CTX_wm_region(C); + Main *bmain = CTX_data_main(C); + SpaceNode *snode = CTX_wm_space_node(C); + ARegion *ar = CTX_wm_region(C); int mval[2]; short extend; @@ -413,14 +415,14 @@ static int node_select_exec(bContext *C, wmOperator *op) /* perform the select */ if (node_mouse_select(bmain, snode, ar, mval, extend)) { /* send notifiers */ - WM_event_add_notifier(C, NC_NODE|NA_SELECTED, NULL); + WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL); /* allow tweak event to work too */ - return OPERATOR_FINISHED|OPERATOR_PASS_THROUGH; + return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH; } else { /* allow tweak event to work too */ - return OPERATOR_CANCELLED|OPERATOR_PASS_THROUGH; + return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH; } } @@ -445,7 +447,7 @@ void NODE_OT_select(wmOperatorType *ot) ot->poll = ED_operator_node_active; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ RNA_def_int(ot->srna, "mouse_x", 0, INT_MIN, INT_MAX, "Mouse X", "", INT_MIN, INT_MAX); @@ -457,25 +459,22 @@ void NODE_OT_select(wmOperatorType *ot) static int node_borderselect_exec(bContext *C, wmOperator *op) { - SpaceNode *snode= CTX_wm_space_node(C); - ARegion *ar= CTX_wm_region(C); + SpaceNode *snode = CTX_wm_space_node(C); + ARegion *ar = CTX_wm_region(C); bNode *node; rcti rect; rctf rectf; - int gesture_mode= RNA_int_get(op->ptr, "gesture_mode"); - int extend= RNA_boolean_get(op->ptr, "extend"); + int gesture_mode = RNA_int_get(op->ptr, "gesture_mode"); + int extend = RNA_boolean_get(op->ptr, "extend"); - rect.xmin = RNA_int_get(op->ptr, "xmin"); - rect.ymin = RNA_int_get(op->ptr, "ymin"); + WM_operator_properties_border_to_rcti(op, &rect); + UI_view2d_region_to_view(&ar->v2d, rect.xmin, rect.ymin, &rectf.xmin, &rectf.ymin); - - rect.xmax = RNA_int_get(op->ptr, "xmax"); - rect.ymax = RNA_int_get(op->ptr, "ymax"); UI_view2d_region_to_view(&ar->v2d, rect.xmax, rect.ymax, &rectf.xmax, &rectf.ymax); - for (node= snode->edittree->nodes.first; node; node= node->next) { + for (node = snode->edittree->nodes.first; node; node = node->next) { if (BLI_rctf_isect(&rectf, &node->totr, NULL)) { - if (gesture_mode==GESTURE_MODAL_SELECT) + if (gesture_mode == GESTURE_MODAL_SELECT) node_select(node); else node_deselect(node); @@ -487,7 +486,7 @@ static int node_borderselect_exec(bContext *C, wmOperator *op) ED_node_sort(snode->edittree); - WM_event_add_notifier(C, NC_NODE|NA_SELECTED, NULL); + WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL); return OPERATOR_FINISHED; } @@ -499,14 +498,14 @@ static int node_border_select_invoke(bContext *C, wmOperator *op, wmEvent *event if (tweak) { /* prevent initiating the border select if the mouse is over a node */ /* this allows border select on empty space, but drag-translate on nodes */ - SpaceNode *snode= CTX_wm_space_node(C); - ARegion *ar= CTX_wm_region(C); + SpaceNode *snode = CTX_wm_space_node(C); + ARegion *ar = CTX_wm_region(C); float mx, my; UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &mx, &my); if (node_under_mouse_tweak(snode->edittree, mx, my)) - return OPERATOR_CANCELLED|OPERATOR_PASS_THROUGH; + return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH; } return WM_border_select_invoke(C, op, event); @@ -528,7 +527,7 @@ void NODE_OT_select_border(wmOperatorType *ot) ot->poll = ED_operator_node_active; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* rna */ WM_operator_properties_gesture_border(ot, TRUE); @@ -567,7 +566,7 @@ static int node_select_all_exec(bContext *C, wmOperator *op) ED_node_sort(snode->edittree); - WM_event_add_notifier(C, NC_NODE|NA_SELECTED, NULL); + WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL); return OPERATOR_FINISHED; } @@ -583,7 +582,7 @@ void NODE_OT_select_all(wmOperatorType *ot) ot->poll = ED_operator_node_active; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; WM_operator_properties_select_all(ot); } @@ -596,22 +595,22 @@ static int node_select_linked_to_exec(bContext *C, wmOperator *UNUSED(op)) bNodeLink *link; bNode *node; - for (node=snode->edittree->nodes.first; node; node=node->next) + for (node = snode->edittree->nodes.first; node; node = node->next) node->flag &= ~NODE_TEST; - for (link=snode->edittree->links.first; link; link=link->next) { + for (link = snode->edittree->links.first; link; link = link->next) { if (link->fromnode && link->tonode && (link->fromnode->flag & NODE_SELECT)) link->tonode->flag |= NODE_TEST; } - for (node=snode->edittree->nodes.first; node; node=node->next) { + for (node = snode->edittree->nodes.first; node; node = node->next) { if (node->flag & NODE_TEST) node_select(node); } ED_node_sort(snode->edittree); - WM_event_add_notifier(C, NC_NODE|NA_SELECTED, NULL); + WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL); return OPERATOR_FINISHED; } @@ -627,7 +626,7 @@ void NODE_OT_select_linked_to(wmOperatorType *ot) ot->poll = ED_operator_node_active; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /* ****** Select Linked From ****** */ @@ -638,22 +637,22 @@ static int node_select_linked_from_exec(bContext *C, wmOperator *UNUSED(op)) bNodeLink *link; bNode *node; - for (node=snode->edittree->nodes.first; node; node=node->next) + for (node = snode->edittree->nodes.first; node; node = node->next) node->flag &= ~NODE_TEST; - for (link=snode->edittree->links.first; link; link=link->next) { + for (link = snode->edittree->links.first; link; link = link->next) { if (link->fromnode && link->tonode && (link->tonode->flag & NODE_SELECT)) link->fromnode->flag |= NODE_TEST; } - for (node=snode->edittree->nodes.first; node; node=node->next) { + for (node = snode->edittree->nodes.first; node; node = node->next) { if (node->flag & NODE_TEST) node_select(node); } ED_node_sort(snode->edittree); - WM_event_add_notifier(C, NC_NODE|NA_SELECTED, NULL); + WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL); return OPERATOR_FINISHED; } @@ -669,7 +668,7 @@ void NODE_OT_select_linked_from(wmOperatorType *ot) ot->poll = ED_operator_node_active; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /* ****** Select Same Type ****** */ @@ -682,7 +681,7 @@ static int node_select_same_type_exec(bContext *C, wmOperator *UNUSED(op)) ED_node_sort(snode->edittree); - WM_event_add_notifier(C, NC_NODE|NA_SELECTED, NULL); + WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL); return OPERATOR_FINISHED; } @@ -698,7 +697,7 @@ void NODE_OT_select_same_type(wmOperatorType *ot) ot->poll = ED_operator_node_active; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /* ****** Select The Next/Prev Node Of The Same Type ****** */ @@ -711,7 +710,7 @@ static int node_select_same_type_next_exec(bContext *C, wmOperator *UNUSED(op)) ED_node_sort(snode->edittree); - WM_event_add_notifier(C, NC_NODE|NA_SELECTED, NULL); + WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL); return OPERATOR_FINISHED; } @@ -728,7 +727,7 @@ void NODE_OT_select_same_type_next(wmOperatorType *ot) ot->poll = ED_operator_node_active; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } static int node_select_same_type_prev_exec(bContext *C, wmOperator *UNUSED(op)) @@ -739,7 +738,7 @@ static int node_select_same_type_prev_exec(bContext *C, wmOperator *UNUSED(op)) ED_node_sort(snode->edittree); - WM_event_add_notifier(C, NC_NODE|NA_SELECTED, NULL); + WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL); return OPERATOR_FINISHED; } @@ -755,5 +754,5 @@ void NODE_OT_select_same_type_prev(wmOperatorType *ot) ot->poll = ED_operator_node_active; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } diff --git a/source/blender/editors/space_node/node_state.c b/source/blender/editors/space_node/node_state.c deleted file mode 100644 index b21d31ad619..00000000000 --- a/source/blender/editors/space_node/node_state.c +++ /dev/null @@ -1,133 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2008 Blender Foundation. - * All rights reserved. - * - * - * Contributor(s): Blender Foundation, Nathan Letwory - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/editors/space_node/node_state.c - * \ingroup spnode - */ - - -#include <stdio.h> - -#include "DNA_node_types.h" -#include "DNA_scene_types.h" - -#include "BLI_rect.h" -#include "BLI_utildefines.h" - -#include "BKE_context.h" -#include "BKE_node.h" - -#include "ED_screen.h" - -#include "RNA_access.h" -#include "RNA_define.h" - -#include "WM_api.h" -#include "WM_types.h" - -#include "UI_view2d.h" - -#include "node_intern.h" - - -/* **************** View All Operator ************** */ - -static void snode_home(ScrArea *UNUSED(sa), ARegion *ar, SpaceNode* snode) -{ - bNode *node; - rctf *cur; - float oldwidth, oldheight, width, height; - int first= 1; - - cur= &ar->v2d.cur; - - oldwidth= cur->xmax - cur->xmin; - oldheight= cur->ymax - cur->ymin; - - cur->xmin = cur->ymin = 0.0f; - cur->xmax=ar->winx; - cur->ymax=ar->winy; - - if (snode->edittree) { - for (node= snode->edittree->nodes.first; node; node= node->next) { - if (first) { - first= 0; - ar->v2d.cur= node->totr; - } - else { - BLI_rctf_union(cur, &node->totr); - } - } - } - - snode->xof= 0; - snode->yof= 0; - width= cur->xmax - cur->xmin; - height= cur->ymax- cur->ymin; - - if (width > height) { - float newheight; - newheight= oldheight * width/oldwidth; - cur->ymin = cur->ymin - newheight/4; - cur->ymax = cur->ymax + newheight/4; - } - else { - float newwidth; - newwidth= oldwidth * height/oldheight; - cur->xmin = cur->xmin - newwidth/4; - cur->xmax = cur->xmax + newwidth/4; - } - - ar->v2d.tot= ar->v2d.cur; - UI_view2d_curRect_validate(&ar->v2d); -} - -static int node_view_all_exec(bContext *C, wmOperator *UNUSED(op)) -{ - ScrArea *sa= CTX_wm_area(C); - ARegion *ar= CTX_wm_region(C); - SpaceNode *snode= CTX_wm_space_node(C); - - snode_home(sa, ar, snode); - ED_region_tag_redraw(ar); - - return OPERATOR_FINISHED; -} - -void NODE_OT_view_all(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "View All"; - ot->idname = "NODE_OT_view_all"; - ot->description = "Resize view so you can see all nodes"; - - /* api callbacks */ - ot->exec = node_view_all_exec; - ot->poll = ED_operator_node_active; - - /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; -} diff --git a/source/blender/editors/space_node/node_templates.c b/source/blender/editors/space_node/node_templates.c index f12c7941e1d..a8fe8318f22 100644 --- a/source/blender/editors/space_node/node_templates.c +++ b/source/blender/editors/space_node/node_templates.c @@ -24,41 +24,32 @@ * \ingroup edinterface */ -#include <stdlib.h> -#include <stddef.h> #include <string.h> #include "MEM_guardedalloc.h" #include "DNA_node_types.h" -#include "DNA_scene_types.h" #include "DNA_screen_types.h" #include "BLI_listbase.h" #include "BLI_string.h" -#include "BLI_utildefines.h" #include "BLF_translation.h" #include "BKE_context.h" -#include "BKE_depsgraph.h" #include "BKE_library.h" #include "BKE_main.h" -#include "BKE_node.h" #include "BKE_scene.h" #include "RNA_access.h" #include "NOD_socket.h" -#include "WM_api.h" -#include "WM_types.h" - #include "UI_interface.h" -#include "UI_resources.h" -#include "../interface/interface_intern.h" +#include "../interface/interface_intern.h" /* XXX bad level */ + +#include "ED_node.h" /* own include */ -#include "ED_node.h" #include "ED_util.h" /************************* Node Socket Manipulation **************************/ diff --git a/source/blender/editors/space_node/node_view.c b/source/blender/editors/space_node/node_view.c new file mode 100644 index 00000000000..7ad283b9869 --- /dev/null +++ b/source/blender/editors/space_node/node_view.c @@ -0,0 +1,501 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2008 Blender Foundation. + * All rights reserved. + * + * + * Contributor(s): Blender Foundation, Nathan Letwory + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/editors/space_node/node_view.c + * \ingroup spnode + */ + +#include "DNA_node_types.h" + +#include "BLI_rect.h" +#include "BLI_utildefines.h" + +#include "BKE_context.h" +#include "BKE_image.h" +#include "BKE_screen.h" +#include "BKE_node.h" + +#include "ED_node.h" /* own include */ +#include "ED_screen.h" +#include "ED_space_api.h" +#include "ED_image.h" + +#include "RNA_access.h" +#include "RNA_define.h" + +#include "WM_api.h" +#include "WM_types.h" + +#include "UI_view2d.h" + +#include "MEM_guardedalloc.h" + +#include "IMB_imbuf.h" +#include "IMB_imbuf_types.h" + +#include "node_intern.h" /* own include */ + + +/* **************** View All Operator ************** */ + +static int space_node_view_flag(SpaceNode *snode, ARegion *ar, const int node_flag) +{ + bNode *node; + rctf cur_new; + float oldwidth, oldheight, width, height; + int tot = 0; + int has_frame = FALSE; + + oldwidth = ar->v2d.cur.xmax - ar->v2d.cur.xmin; + oldheight = ar->v2d.cur.ymax - ar->v2d.cur.ymin; + + BLI_rctf_init_minmax(&cur_new); + + if (snode->edittree) { + for (node = snode->edittree->nodes.first; node; node = node->next) { + if ((node->flag & node_flag) == node_flag) { + BLI_rctf_union(&cur_new, &node->totr); + tot++; + + if (node->type == NODE_FRAME) { + has_frame = TRUE; + } + } + } + } + + if (tot) { + width = cur_new.xmax - cur_new.xmin; + height = cur_new.ymax - cur_new.ymin; + + /* for single non-frame nodes, don't zoom in, just pan view, + * but do allow zooming out, this allows for big nodes to be zoomed out */ + if ((tot == 1) && + (has_frame == FALSE) && + ((oldwidth * oldheight) > (width * height))) + { + /* center, don't zoom */ + BLI_rctf_resize(&cur_new, oldwidth, oldheight); + } + else { + width = cur_new.xmax - cur_new.xmin; + height = cur_new.ymax - cur_new.ymin; + + if (width > height) { + float newheight; + newheight = oldheight * width / oldwidth; + cur_new.ymin = cur_new.ymin - newheight / 4; + cur_new.ymax = cur_new.ymax + newheight / 4; + } + else { + float newwidth; + newwidth = oldwidth * height / oldheight; + cur_new.xmin = cur_new.xmin - newwidth / 4; + cur_new.xmax = cur_new.xmax + newwidth / 4; + } + } + + ar->v2d.tot = ar->v2d.cur = cur_new; + UI_view2d_curRect_validate(&ar->v2d); + } + + return (tot != 0); +} + +static int node_view_all_exec(bContext *C, wmOperator *UNUSED(op)) +{ + ARegion *ar = CTX_wm_region(C); + SpaceNode *snode = CTX_wm_space_node(C); + + /* is this really needed? */ + snode->xof = 0; + snode->yof = 0; + + if (space_node_view_flag(snode, ar, 0)) { + ED_region_tag_redraw(ar); + + return OPERATOR_FINISHED; + } + else { + return OPERATOR_CANCELLED; + } +} + +void NODE_OT_view_all(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "View All"; + ot->idname = "NODE_OT_view_all"; + ot->description = "Resize view so you can see all nodes"; + + /* api callbacks */ + ot->exec = node_view_all_exec; + ot->poll = ED_operator_node_active; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} + +static int node_view_selected_exec(bContext *C, wmOperator *UNUSED(op)) +{ + ARegion *ar = CTX_wm_region(C); + SpaceNode *snode = CTX_wm_space_node(C); + + if (space_node_view_flag(snode, ar, NODE_SELECT)) { + ED_region_tag_redraw(ar); + + return OPERATOR_FINISHED; + } + else { + return OPERATOR_CANCELLED; + } +} + +void NODE_OT_view_selected(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "View Selected"; + ot->idname = "NODE_OT_view_selected"; + ot->description = "Resize view so you can see selected nodes"; + + /* api callbacks */ + ot->exec = node_view_selected_exec; + ot->poll = ED_operator_node_active; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} + +/* **************** Backround Image Operators ************** */ + +typedef struct NodeViewMove { + int mvalo[2]; + int xmin, ymin, xmax, ymax; +} NodeViewMove; + +static int snode_bg_viewmove_modal(bContext *C, wmOperator *op, wmEvent *event) +{ + SpaceNode *snode = CTX_wm_space_node(C); + ARegion *ar = CTX_wm_region(C); + NodeViewMove *nvm = op->customdata; + + switch (event->type) { + case MOUSEMOVE: + + snode->xof -= (nvm->mvalo[0] - event->mval[0]); + snode->yof -= (nvm->mvalo[1] - event->mval[1]); + nvm->mvalo[0] = event->mval[0]; + nvm->mvalo[1] = event->mval[1]; + + /* prevent dragging image outside of the window and losing it! */ + CLAMP(snode->xof, nvm->xmin, nvm->xmax); + CLAMP(snode->yof, nvm->ymin, nvm->ymax); + + ED_region_tag_redraw(ar); + + break; + + case LEFTMOUSE: + case MIDDLEMOUSE: + case RIGHTMOUSE: + + MEM_freeN(nvm); + op->customdata = NULL; + + return OPERATOR_FINISHED; + } + + return OPERATOR_RUNNING_MODAL; +} + +static int snode_bg_viewmove_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + SpaceNode *snode = CTX_wm_space_node(C); + ARegion *ar = CTX_wm_region(C); + NodeViewMove *nvm; + Image *ima; + ImBuf *ibuf; + const float pad = 32.0f; /* better be bigger then scrollbars */ + + void *lock; + + ima = BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node"); + ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); + + if (ibuf == NULL) { + BKE_image_release_ibuf(ima, lock); + return OPERATOR_CANCELLED; + } + + nvm = MEM_callocN(sizeof(NodeViewMove), "NodeViewMove struct"); + op->customdata = nvm; + nvm->mvalo[0] = event->mval[0]; + nvm->mvalo[1] = event->mval[1]; + + nvm->xmin = -(ar->winx / 2) - (ibuf->x * (0.5f * snode->zoom)) + pad; + nvm->xmax = (ar->winx / 2) + (ibuf->x * (0.5f * snode->zoom)) - pad; + nvm->ymin = -(ar->winy / 2) - (ibuf->y * (0.5f * snode->zoom)) + pad; + nvm->ymax = (ar->winy / 2) + (ibuf->y * (0.5f * snode->zoom)) - pad; + + BKE_image_release_ibuf(ima, lock); + + /* add modal handler */ + WM_event_add_modal_handler(C, op); + + return OPERATOR_RUNNING_MODAL; +} + +static int snode_bg_viewmove_cancel(bContext *UNUSED(C), wmOperator *op) +{ + MEM_freeN(op->customdata); + op->customdata = NULL; + + return OPERATOR_CANCELLED; +} + +void NODE_OT_backimage_move(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Background Image Move"; + ot->description = "Move Node backdrop"; + ot->idname = "NODE_OT_backimage_move"; + + /* api callbacks */ + ot->invoke = snode_bg_viewmove_invoke; + ot->modal = snode_bg_viewmove_modal; + ot->poll = composite_node_active; + ot->cancel = snode_bg_viewmove_cancel; + + /* flags */ + ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_POINTER; +} + +static int backimage_zoom(bContext *C, wmOperator *op) +{ + SpaceNode *snode = CTX_wm_space_node(C); + ARegion *ar = CTX_wm_region(C); + float fac = RNA_float_get(op->ptr, "factor"); + + snode->zoom *= fac; + ED_region_tag_redraw(ar); + + return OPERATOR_FINISHED; +} + + +void NODE_OT_backimage_zoom(wmOperatorType *ot) +{ + + /* identifiers */ + ot->name = "Background Image Zoom"; + ot->idname = "NODE_OT_backimage_zoom"; + ot->description = "Zoom in/out the background image"; + + /* api callbacks */ + ot->exec = backimage_zoom; + ot->poll = composite_node_active; + + /* flags */ + ot->flag = OPTYPE_BLOCKING; + + /* internal */ + RNA_def_float(ot->srna, "factor", 1.2f, 0.0f, 10.0f, "Factor", "", 0.0f, 10.0f); +} + +/******************** sample backdrop operator ********************/ + +typedef struct ImageSampleInfo { + ARegionType *art; + void *draw_handle; + int x, y; + int channels; + int color_manage; + + unsigned char col[4]; + float colf[4]; + + int draw; +} ImageSampleInfo; + +static void sample_draw(const bContext *C, ARegion *ar, void *arg_info) +{ + Scene *scene = CTX_data_scene(C); + ImageSampleInfo *info = arg_info; + + if (info->draw) { + ED_image_draw_info(ar, (scene->r.color_mgt_flag & R_COLOR_MANAGEMENT), info->channels, + info->x, info->y, info->col, info->colf, + NULL, NULL /* zbuf - unused for nodes */ + ); + } +} + +static void sample_apply(bContext *C, wmOperator *op, wmEvent *event) +{ + SpaceNode *snode = CTX_wm_space_node(C); + ARegion *ar = CTX_wm_region(C); + ImageSampleInfo *info = op->customdata; + void *lock; + Image *ima; + ImBuf *ibuf; + float fx, fy, bufx, bufy; + + ima = BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node"); + ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); + if (!ibuf) { + info->draw = 0; + return; + } + + if (!ibuf->rect) { + if (info->color_manage) + ibuf->profile = IB_PROFILE_LINEAR_RGB; + else + ibuf->profile = IB_PROFILE_NONE; + IMB_rect_from_float(ibuf); + } + + /* map the mouse coords to the backdrop image space */ + bufx = ibuf->x * snode->zoom; + bufy = ibuf->y * snode->zoom; + fx = (bufx > 0.0f ? ((float)event->mval[0] - 0.5f * ar->winx - snode->xof) / bufx + 0.5f : 0.0f); + fy = (bufy > 0.0f ? ((float)event->mval[1] - 0.5f * ar->winy - snode->yof) / bufy + 0.5f : 0.0f); + + if (fx >= 0.0f && fy >= 0.0f && fx < 1.0f && fy < 1.0f) { + float *fp; + char *cp; + int x = (int)(fx * ibuf->x), y = (int)(fy * ibuf->y); + + CLAMP(x, 0, ibuf->x - 1); + CLAMP(y, 0, ibuf->y - 1); + + info->x = x; + info->y = y; + info->draw = 1; + info->channels = ibuf->channels; + + if (ibuf->rect) { + cp = (char *)(ibuf->rect + y * ibuf->x + x); + + info->col[0] = cp[0]; + info->col[1] = cp[1]; + info->col[2] = cp[2]; + info->col[3] = cp[3]; + + info->colf[0] = (float)cp[0] / 255.0f; + info->colf[1] = (float)cp[1] / 255.0f; + info->colf[2] = (float)cp[2] / 255.0f; + info->colf[3] = (float)cp[3] / 255.0f; + } + if (ibuf->rect_float) { + fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x)); + + info->colf[0] = fp[0]; + info->colf[1] = fp[1]; + info->colf[2] = fp[2]; + info->colf[3] = fp[3]; + } + + ED_node_sample_set(info->colf); + } + else { + info->draw = 0; + ED_node_sample_set(NULL); + } + + BKE_image_release_ibuf(ima, lock); + + ED_area_tag_redraw(CTX_wm_area(C)); +} + +static void sample_exit(bContext *C, wmOperator *op) +{ + ImageSampleInfo *info = op->customdata; + + ED_node_sample_set(NULL); + ED_region_draw_cb_exit(info->art, info->draw_handle); + ED_area_tag_redraw(CTX_wm_area(C)); + MEM_freeN(info); +} + +static int sample_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + SpaceNode *snode = CTX_wm_space_node(C); + ARegion *ar = CTX_wm_region(C); + ImageSampleInfo *info; + + if (snode->treetype != NTREE_COMPOSIT || !(snode->flag & SNODE_BACKDRAW)) + return OPERATOR_CANCELLED; + + info = MEM_callocN(sizeof(ImageSampleInfo), "ImageSampleInfo"); + info->art = ar->type; + info->draw_handle = ED_region_draw_cb_activate(ar->type, sample_draw, info, REGION_DRAW_POST_PIXEL); + op->customdata = info; + + sample_apply(C, op, event); + + WM_event_add_modal_handler(C, op); + + return OPERATOR_RUNNING_MODAL; +} + +static int sample_modal(bContext *C, wmOperator *op, wmEvent *event) +{ + switch (event->type) { + case LEFTMOUSE: + case RIGHTMOUSE: // XXX hardcoded + sample_exit(C, op); + return OPERATOR_CANCELLED; + case MOUSEMOVE: + sample_apply(C, op, event); + break; + } + + return OPERATOR_RUNNING_MODAL; +} + +static int sample_cancel(bContext *C, wmOperator *op) +{ + sample_exit(C, op); + return OPERATOR_CANCELLED; +} + +void NODE_OT_backimage_sample(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Backimage Sample"; + ot->idname = "NODE_OT_backimage_sample"; + ot->description = "Use mouse to sample background image"; + + /* api callbacks */ + ot->invoke = sample_invoke; + ot->modal = sample_modal; + ot->cancel = sample_cancel; + ot->poll = ED_operator_node_active; + + /* flags */ + ot->flag = OPTYPE_BLOCKING; +} diff --git a/source/blender/editors/space_node/space_node.c b/source/blender/editors/space_node/space_node.c index bfc83018dbb..1522528a8ac 100644 --- a/source/blender/editors/space_node/space_node.c +++ b/source/blender/editors/space_node/space_node.c @@ -29,31 +29,24 @@ */ -#include <string.h> -#include <stdio.h> #include "DNA_lamp_types.h" #include "DNA_material_types.h" #include "DNA_node_types.h" -#include "DNA_object_types.h" -#include "DNA_scene_types.h" #include "DNA_world_types.h" #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" #include "BLI_math.h" -#include "BLI_rand.h" -#include "BLI_utildefines.h" #include "BKE_context.h" #include "BKE_screen.h" #include "BKE_node.h" -#include "ED_space_api.h" #include "ED_render.h" #include "ED_screen.h" - +#include "ED_node.h" #include "WM_api.h" #include "WM_types.h" @@ -63,7 +56,7 @@ #include "RNA_access.h" -#include "node_intern.h" // own include +#include "node_intern.h" /* own include */ /* ******************** manage regions ********************* */ @@ -296,8 +289,9 @@ static void node_area_refresh(const struct bContext *C, ScrArea *sa) snode->recalc = 0; node_render_changed_exec((struct bContext *)C, NULL); } - else - snode_composite_job(C, sa); + else { + ED_node_composite_job(C, snode->nodetree, scene); + } } } else if (snode->treetype == NTREE_TEXTURE) { @@ -343,7 +337,7 @@ static void node_cursor(wmWindow *win, ScrArea *sa, ARegion *ar) /* convert mouse coordinates to v2d space */ UI_view2d_region_to_view(&ar->v2d, win->eventstate->x - ar->winrct.xmin, win->eventstate->y - ar->winrct.ymin, - &snode->mx, &snode->my); + &snode->cursor[0], &snode->cursor[1]); node_set_cursor(win, snode); } diff --git a/source/blender/editors/space_outliner/outliner_select.c b/source/blender/editors/space_outliner/outliner_select.c index 096713f9cd3..8b7cf406642 100644 --- a/source/blender/editors/space_outliner/outliner_select.c +++ b/source/blender/editors/space_outliner/outliner_select.c @@ -899,12 +899,9 @@ static int outliner_border_select_exec(bContext *C, wmOperator *op) rctf rectf; int gesture_mode = RNA_int_get(op->ptr, "gesture_mode"); - rect.xmin = RNA_int_get(op->ptr, "xmin"); - rect.ymin = RNA_int_get(op->ptr, "ymin"); - UI_view2d_region_to_view(&ar->v2d, rect.xmin, rect.ymin, &rectf.xmin, &rectf.ymin); + WM_operator_properties_border_to_rcti(op, &rect); - rect.xmax = RNA_int_get(op->ptr, "xmax"); - rect.ymax = RNA_int_get(op->ptr, "ymax"); + UI_view2d_region_to_view(&ar->v2d, rect.xmin, rect.ymin, &rectf.xmin, &rectf.ymin); UI_view2d_region_to_view(&ar->v2d, rect.xmax, rect.ymax, &rectf.xmax, &rectf.ymax); for (te = soops->tree.first; te; te = te->next) { diff --git a/source/blender/editors/space_sequencer/sequencer_add.c b/source/blender/editors/space_sequencer/sequencer_add.c index 26bedd14d6e..7b7170d99e0 100644 --- a/source/blender/editors/space_sequencer/sequencer_add.c +++ b/source/blender/editors/space_sequencer/sequencer_add.c @@ -230,7 +230,7 @@ static int sequencer_add_scene_strip_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - seq = alloc_sequence(ed->seqbasep, start_frame, channel); + seq = BKE_sequence_alloc(ed->seqbasep, start_frame, channel); seq->type = SEQ_TYPE_SCENE; seq->blend_mode = SEQ_TYPE_CROSS; /* so alpha adjustment fade to the strip below */ @@ -242,11 +242,11 @@ static int sequencer_add_scene_strip_exec(bContext *C, wmOperator *op) strip->us = 1; BLI_strncpy(seq->name + 2, sce_seq->id.name + 2, sizeof(seq->name) - 2); - seqbase_unique_name_recursive(&ed->seqbase, seq); + BKE_seqence_base_unique_name_recursive(&ed->seqbase, seq); seq->scene_sound = sound_scene_add_scene_sound(scene, seq, start_frame, start_frame + seq->len, 0); - calc_sequence_disp(scene, seq); + BKE_sequence_calc_disp(scene, seq); BKE_sequencer_sort(scene); if (RNA_boolean_get(op->ptr, "replace_sel")) { @@ -256,7 +256,7 @@ static int sequencer_add_scene_strip_exec(bContext *C, wmOperator *op) } if (RNA_boolean_get(op->ptr, "overlap") == FALSE) { - if (seq_test_overlap(ed->seqbasep, seq)) shuffle_seq(ed->seqbasep, seq, scene); + if (BKE_sequence_test_overlap(ed->seqbasep, seq)) BKE_sequence_base_shuffle(ed->seqbasep, seq, scene); } WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene); @@ -329,7 +329,7 @@ static int sequencer_add_movieclip_strip_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - seq = alloc_sequence(ed->seqbasep, start_frame, channel); + seq = BKE_sequence_alloc(ed->seqbasep, start_frame, channel); seq->type = SEQ_TYPE_MOVIECLIP; seq->blend_mode = SEQ_TYPE_CROSS; seq->clip = clip; @@ -343,9 +343,9 @@ static int sequencer_add_movieclip_strip_exec(bContext *C, wmOperator *op) strip->us = 1; BLI_strncpy(seq->name + 2, clip->id.name + 2, sizeof(seq->name) - 2); - seqbase_unique_name_recursive(&ed->seqbase, seq); + BKE_seqence_base_unique_name_recursive(&ed->seqbase, seq); - calc_sequence_disp(scene, seq); + BKE_sequence_calc_disp(scene, seq); BKE_sequencer_sort(scene); if (RNA_boolean_get(op->ptr, "replace_sel")) { @@ -355,7 +355,7 @@ static int sequencer_add_movieclip_strip_exec(bContext *C, wmOperator *op) } if (RNA_boolean_get(op->ptr, "overlap") == FALSE) { - if (seq_test_overlap(ed->seqbasep, seq)) shuffle_seq(ed->seqbasep, seq, scene); + if (BKE_sequence_test_overlap(ed->seqbasep, seq)) BKE_sequence_base_shuffle(ed->seqbasep, seq, scene); } WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene); @@ -425,7 +425,7 @@ static int sequencer_add_mask_strip_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - seq = alloc_sequence(ed->seqbasep, start_frame, channel); + seq = BKE_sequence_alloc(ed->seqbasep, start_frame, channel); seq->type = SEQ_TYPE_MASK; seq->blend_mode = SEQ_TYPE_CROSS; seq->mask = mask; @@ -439,9 +439,9 @@ static int sequencer_add_mask_strip_exec(bContext *C, wmOperator *op) strip->us = 1; BLI_strncpy(seq->name + 2, mask->id.name + 2, sizeof(seq->name) - 2); - seqbase_unique_name_recursive(&ed->seqbase, seq); + BKE_seqence_base_unique_name_recursive(&ed->seqbase, seq); - calc_sequence_disp(scene, seq); + BKE_sequence_calc_disp(scene, seq); BKE_sequencer_sort(scene); if (RNA_boolean_get(op->ptr, "replace_sel")) { @@ -451,7 +451,7 @@ static int sequencer_add_mask_strip_exec(bContext *C, wmOperator *op) } if (RNA_boolean_get(op->ptr, "overlap") == FALSE) { - if (seq_test_overlap(ed->seqbasep, seq)) shuffle_seq(ed->seqbasep, seq, scene); + if (BKE_sequence_test_overlap(ed->seqbasep, seq)) BKE_sequence_base_shuffle(ed->seqbasep, seq, scene); } WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene); @@ -535,7 +535,7 @@ static int sequencer_add_generic_strip_exec(bContext *C, wmOperator *op, SeqLoad seq = seq_load_func(C, ed->seqbasep, &seq_load); if (seq) { if (overlap == FALSE) { - if (seq_test_overlap(ed->seqbasep, seq)) shuffle_seq(ed->seqbasep, seq, scene); + if (BKE_sequence_test_overlap(ed->seqbasep, seq)) BKE_sequence_base_shuffle(ed->seqbasep, seq, scene); } } } @@ -546,7 +546,8 @@ static int sequencer_add_generic_strip_exec(bContext *C, wmOperator *op, SeqLoad seq = seq_load_func(C, ed->seqbasep, &seq_load); if (seq) { if (overlap == FALSE) { - if (seq_test_overlap(ed->seqbasep, seq)) shuffle_seq(ed->seqbasep, seq, scene); + if (BKE_sequence_test_overlap(ed->seqbasep, seq)) + BKE_sequence_base_shuffle(ed->seqbasep, seq, scene); } } } @@ -557,7 +558,7 @@ static int sequencer_add_generic_strip_exec(bContext *C, wmOperator *op, SeqLoad } BKE_sequencer_sort(scene); - seq_update_muting(ed); + BKE_sequencer_update_muting(ed); WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene); @@ -567,7 +568,7 @@ static int sequencer_add_generic_strip_exec(bContext *C, wmOperator *op, SeqLoad /* add movie operator */ static int sequencer_add_movie_strip_exec(bContext *C, wmOperator *op) { - return sequencer_add_generic_strip_exec(C, op, sequencer_add_movie_strip); + return sequencer_add_generic_strip_exec(C, op, BKE_sequencer_add_movie_strip); } @@ -613,7 +614,8 @@ void SEQUENCER_OT_movie_strip_add(struct wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - WM_operator_properties_filesel(ot, FOLDERFILE | MOVIEFILE, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH | WM_FILESEL_FILES, FILE_DEFAULTDISPLAY); + WM_operator_properties_filesel(ot, FOLDERFILE | MOVIEFILE, FILE_SPECIAL, FILE_OPENFILE, + WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH | WM_FILESEL_FILES, FILE_DEFAULTDISPLAY); sequencer_generic_props__internal(ot, SEQPROP_STARTFRAME); RNA_def_boolean(ot->srna, "sound", TRUE, "Sound", "Load sound with the movie"); } @@ -622,7 +624,7 @@ void SEQUENCER_OT_movie_strip_add(struct wmOperatorType *ot) static int sequencer_add_sound_strip_exec(bContext *C, wmOperator *op) { - return sequencer_add_generic_strip_exec(C, op, sequencer_add_sound_strip); + return sequencer_add_generic_strip_exec(C, op, BKE_sequencer_add_sound_strip); } static int sequencer_add_sound_strip_invoke(bContext *C, wmOperator *op, wmEvent *event) @@ -667,7 +669,8 @@ void SEQUENCER_OT_sound_strip_add(struct wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - WM_operator_properties_filesel(ot, FOLDERFILE | SOUNDFILE, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH | WM_FILESEL_FILES, FILE_DEFAULTDISPLAY); + WM_operator_properties_filesel(ot, FOLDERFILE | SOUNDFILE, FILE_SPECIAL, FILE_OPENFILE, + WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH | WM_FILESEL_FILES, FILE_DEFAULTDISPLAY); sequencer_generic_props__internal(ot, SEQPROP_STARTFRAME); RNA_def_boolean(ot->srna, "cache", FALSE, "Cache", "Cache the sound in memory"); } @@ -698,7 +701,7 @@ static int sequencer_add_image_strip_exec(bContext *C, wmOperator *op) /* main adding function */ - seq = sequencer_add_image_strip(C, ed->seqbasep, &seq_load); + seq = BKE_sequencer_add_image_strip(C, ed->seqbasep, &seq_load); strip = seq->strip; se = strip->stripdata; @@ -717,7 +720,7 @@ static int sequencer_add_image_strip_exec(bContext *C, wmOperator *op) } } - calc_sequence_disp(scene, seq); + BKE_sequence_calc_disp(scene, seq); BKE_sequencer_sort(scene); @@ -725,7 +728,8 @@ static int sequencer_add_image_strip_exec(bContext *C, wmOperator *op) strncpy(ed->act_imagedir, strip->dir, FILE_MAXDIR - 1); if (RNA_boolean_get(op->ptr, "overlap") == FALSE) { - if (seq_test_overlap(ed->seqbasep, seq)) shuffle_seq(ed->seqbasep, seq, scene); + if (BKE_sequence_test_overlap(ed->seqbasep, seq)) + BKE_sequence_base_shuffle(ed->seqbasep, seq, scene); } WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene); @@ -772,7 +776,8 @@ void SEQUENCER_OT_image_strip_add(struct wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - WM_operator_properties_filesel(ot, FOLDERFILE | IMAGEFILE, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_DIRECTORY | WM_FILESEL_RELPATH | WM_FILESEL_FILES, FILE_DEFAULTDISPLAY); + WM_operator_properties_filesel(ot, FOLDERFILE | IMAGEFILE, FILE_SPECIAL, FILE_OPENFILE, + WM_FILESEL_DIRECTORY | WM_FILESEL_RELPATH | WM_FILESEL_FILES, FILE_DEFAULTDISPLAY); sequencer_generic_props__internal(ot, SEQPROP_STARTFRAME | SEQPROP_ENDFRAME); } @@ -811,13 +816,13 @@ static int sequencer_add_effect_strip_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - seq = alloc_sequence(ed->seqbasep, start_frame, channel); + seq = BKE_sequence_alloc(ed->seqbasep, start_frame, channel); seq->type = type; - BLI_strncpy(seq->name + 2, give_seqname(seq), sizeof(seq->name) - 2); - seqbase_unique_name_recursive(&ed->seqbase, seq); + BLI_strncpy(seq->name + 2, BKE_sequence_give_name(seq), sizeof(seq->name) - 2); + BKE_seqence_base_unique_name_recursive(&ed->seqbase, seq); - sh = get_sequence_effect(seq); + sh = BKE_sequence_get_effect(seq); seq->seq1 = seq1; seq->seq2 = seq2; @@ -827,12 +832,12 @@ static int sequencer_add_effect_strip_exec(bContext *C, wmOperator *op) if (!seq1) { /* effect has no deps */ seq->len = 1; - seq_tx_set_final_right(seq, end_frame); + BKE_sequence_tx_set_final_right(seq, end_frame); } seq->flag |= SEQ_USE_EFFECT_DEFAULT_FADE; - calc_sequence(scene, seq); + BKE_sequence_calc(scene, seq); /* basic defaults */ seq->strip = strip = MEM_callocN(sizeof(Strip), "strip"); @@ -861,10 +866,10 @@ static int sequencer_add_effect_strip_exec(bContext *C, wmOperator *op) } if (RNA_boolean_get(op->ptr, "overlap") == FALSE) { - if (seq_test_overlap(ed->seqbasep, seq)) shuffle_seq(ed->seqbasep, seq, scene); + if (BKE_sequence_test_overlap(ed->seqbasep, seq)) BKE_sequence_base_shuffle(ed->seqbasep, seq, scene); } - update_changed_seq_and_deps(scene, seq, 1, 1); /* runs calc_sequence */ + BKE_sequencer_update_changed_seq_and_deps(scene, seq, 1, 1); /* runs calc_sequence */ /* not sure if this is needed with update_changed_seq_and_deps. @@ -902,7 +907,7 @@ static int sequencer_add_effect_strip_invoke(bContext *C, wmOperator *op, wmEven * skip initializing the channel from the mouse. * Instead leave the property unset so exec() initializes it to be * above the strips its applied to. */ - if (get_sequence_effect_num_inputs(type) != 0) { + if (BKE_sequence_effect_get_num_inputs(type) != 0) { prop_flag |= SEQPROP_NOCHAN; } } @@ -928,7 +933,8 @@ void SEQUENCER_OT_effect_strip_add(struct wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - WM_operator_properties_filesel(ot, 0, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH, FILE_DEFAULTDISPLAY); + WM_operator_properties_filesel(ot, 0, FILE_SPECIAL, FILE_OPENFILE, + WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH, FILE_DEFAULTDISPLAY); sequencer_generic_props__internal(ot, SEQPROP_STARTFRAME | SEQPROP_ENDFRAME); RNA_def_enum(ot->srna, "type", sequencer_prop_effect_types, SEQ_TYPE_CROSS, "Type", "Sequencer effect type"); RNA_def_float_vector(ot->srna, "color", 3, NULL, 0.0f, 1.0f, "Color", "Initialize the strip with this color (only used when type='COLOR')", 0.0f, 1.0f); diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index 9cbb9006187..297aeb465a6 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -374,7 +374,7 @@ static void draw_seq_handle(View2D *v2d, Sequence *seq, const float handsize_cla /* draw! */ if (seq->type < SEQ_TYPE_EFFECT || - get_sequence_effect_num_inputs(seq->type) == 0) + BKE_sequence_effect_get_num_inputs(seq->type) == 0) { glEnable(GL_BLEND); @@ -530,7 +530,7 @@ static void draw_seq_text(View2D *v2d, Sequence *seq, float x1, float x2, float /* note, all strings should include 'name' */ if (name[0] == '\0') - name = give_seqname(seq); + name = BKE_sequence_give_name(seq); if (seq->type == SEQ_TYPE_META || seq->type == SEQ_TYPE_ADJUSTMENT) { BLI_snprintf(str, sizeof(str), "%s | %d", name, seq->len); @@ -685,7 +685,7 @@ static void draw_seq_strip(Scene *scene, ARegion *ar, Sequence *seq, int outline const float handsize_clamped = draw_seq_handle_size_get_clamped(seq, pixelx); /* we need to know if this is a single image/color or not for drawing */ - is_single_image = (char)seq_single_check(seq); + is_single_image = (char)BKE_sequence_single_check(seq); /* body */ x1 = (seq->startstill) ? seq->start : seq->startdisp; @@ -700,7 +700,7 @@ static void draw_seq_strip(Scene *scene, ARegion *ar, Sequence *seq, int outline /* draw the main strip body */ if (is_single_image) { /* single image */ - draw_shadedstrip(seq, background_col, seq_tx_get_final_left(seq, 0), y1, seq_tx_get_final_right(seq, 0), y2); + draw_shadedstrip(seq, background_col, BKE_sequence_tx_get_final_left(seq, 0), y1, BKE_sequence_tx_get_final_right(seq, 0), y2); } else { /* normal operation */ draw_shadedstrip(seq, background_col, x1, y1, x2, y2); @@ -849,17 +849,17 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq UI_view2d_curRect_validate(v2d); /* only initialize the preview if a render is in progress */ - if (G.rendering) + if (G.is_rendering) return; - context = seq_new_render_data(bmain, scene, rectx, recty, proxy_size); + context = BKE_sequencer_new_render_data(bmain, scene, rectx, recty, proxy_size); if (special_seq_update) - ibuf = give_ibuf_seq_direct(context, cfra + frame_ofs, special_seq_update); + ibuf = BKE_sequencer_give_ibuf_direct(context, cfra + frame_ofs, special_seq_update); else if (!U.prefetchframes) // XXX || (G.f & G_PLAYANIM) == 0) { - ibuf = give_ibuf_seq(context, cfra + frame_ofs, sseq->chanshown); + ibuf = BKE_sequencer_give_ibuf(context, cfra + frame_ofs, sseq->chanshown); else - ibuf = give_ibuf_seq_threaded(context, cfra + frame_ofs, sseq->chanshown); + ibuf = BKE_sequencer_give_ibuf_threaded(context, cfra + frame_ofs, sseq->chanshown); if (ibuf == NULL) return; diff --git a/source/blender/editors/space_sequencer/sequencer_edit.c b/source/blender/editors/space_sequencer/sequencer_edit.c index 4034c9f98f0..7cc6e279ff2 100644 --- a/source/blender/editors/space_sequencer/sequencer_edit.c +++ b/source/blender/editors/space_sequencer/sequencer_edit.c @@ -151,7 +151,7 @@ static void proxy_startjob(void *pjv, short *stop, short *do_update, float *prog for (link = pj->queue.first; link; link = link->next) { struct SeqIndexBuildContext *context = link->data; - seq_proxy_rebuild(context, stop, do_update, progress); + BKE_sequencer_proxy_rebuild(context, stop, do_update, progress); } if (*stop) { @@ -167,10 +167,10 @@ static void proxy_endjob(void *pjv) LinkData *link; for (link = pj->queue.first; link; link = link->next) { - seq_proxy_rebuild_finish(link->data, pj->stop); + BKE_sequencer_proxy_rebuild_finish(link->data, pj->stop); } - free_imbuf_seq(pj->scene, &ed->seqbase, FALSE, FALSE); + BKE_sequencer_free_imbuf(pj->scene, &ed->seqbase, FALSE, FALSE); WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, pj->scene); } @@ -204,7 +204,7 @@ static void seq_proxy_build_job(const bContext *C) SEQP_BEGIN (ed, seq) { if ((seq->flag & SELECT)) { - context = seq_proxy_rebuild_context(pj->main, pj->scene, seq); + context = BKE_sequencer_proxy_rebuild_context(pj->main, pj->scene, seq); link = BLI_genericNodeN(context); BLI_addtail(&pj->queue, link); } @@ -212,7 +212,7 @@ static void seq_proxy_build_job(const bContext *C) SEQ_END if (!WM_jobs_is_running(steve)) { - G.afbreek = 0; + G.is_break = FALSE; WM_jobs_start(CTX_wm_manager(C), steve); } @@ -383,7 +383,7 @@ Sequence *find_nearest_seq(Scene *scene, View2D *v2d, int *hand, const int mval[ if ( ((seq->startdisp < seq->enddisp) && (seq->startdisp <= x && seq->enddisp >= x)) || ((seq->startdisp > seq->enddisp) && (seq->startdisp >= x && seq->enddisp <= x)) ) { - if (seq_tx_test(seq)) { + if (BKE_sequence_tx_test(seq)) { /* clamp handles to defined size in pixel space */ @@ -505,7 +505,7 @@ int seq_effect_find_selected(Scene *scene, Sequence *activeseq, int type, Sequen for (seq = ed->seqbasep->first; seq; seq = seq->next) { if (seq->flag & SELECT) { - if (seq->type == SEQ_TYPE_SOUND_RAM && get_sequence_effect_num_inputs(type) != 0) { + if (seq->type == SEQ_TYPE_SOUND_RAM && BKE_sequence_effect_get_num_inputs(type) != 0) { *error_str = "Can't apply effects to audio sequence strips"; return 0; } @@ -530,7 +530,7 @@ int seq_effect_find_selected(Scene *scene, Sequence *activeseq, int type, Sequen } - switch (get_sequence_effect_num_inputs(type)) { + switch (BKE_sequence_effect_get_num_inputs(type)) { case 0: *selseq1 = *selseq2 = *selseq3 = NULL; return 1; /* succsess */ @@ -584,7 +584,7 @@ static Sequence *del_seq_find_replace_recurs(Scene *scene, Sequence *seq) seq->seq2 = (seq2) ? seq2 : (seq1) ? seq1 : seq3; seq->seq3 = (seq3) ? seq3 : (seq1) ? seq1 : seq2; - update_changed_seq_and_deps(scene, seq, 1, 1); + BKE_sequencer_update_changed_seq_and_deps(scene, seq, 1, 1); } else seq->flag |= SELECT; /* mark for delete */ @@ -612,7 +612,7 @@ static void recurs_del_seq_flag(Scene *scene, ListBase *lb, short flag, short de BLI_remlink(lb, seq); if (seq == last_seq) BKE_sequencer_active_set(scene, NULL); if (seq->type == SEQ_TYPE_META) recurs_del_seq_flag(scene, &seq->seqbase, flag, 1); - seq_free_sequence(scene, seq); + BKE_sequence_free(scene, seq); } seq = seqn; } @@ -669,12 +669,12 @@ static Sequence *cut_seq_hard(Scene *scene, Sequence *seq, int cutframe) } } - reload_sequence_new_file(scene, seq, FALSE); - calc_sequence(scene, seq); + BKE_sequence_reload_new_file(scene, seq, FALSE); + BKE_sequence_calc(scene, seq); if (!skip_dup) { /* Duplicate AFTER the first change */ - seqn = seq_dupli_recursive(scene, NULL, seq, SEQ_DUPE_UNIQUE_NAME | SEQ_DUPE_ANIM); + seqn = BKE_sequence_dupli_recursive(scene, NULL, seq, SEQ_DUPE_UNIQUE_NAME | SEQ_DUPE_ANIM); } if (seqn) { @@ -709,8 +709,8 @@ static Sequence *cut_seq_hard(Scene *scene, Sequence *seq, int cutframe) seqn->startstill = 0; } - reload_sequence_new_file(scene, seqn, FALSE); - calc_sequence(scene, seqn); + BKE_sequence_reload_new_file(scene, seqn, FALSE); + BKE_sequence_calc(scene, seqn); } return seqn; } @@ -763,11 +763,11 @@ static Sequence *cut_seq_soft(Scene *scene, Sequence *seq, int cutframe) } } - calc_sequence(scene, seq); + BKE_sequence_calc(scene, seq); if (!skip_dup) { /* Duplicate AFTER the first change */ - seqn = seq_dupli_recursive(scene, NULL, seq, SEQ_DUPE_UNIQUE_NAME | SEQ_DUPE_ANIM); + seqn = BKE_sequence_dupli_recursive(scene, NULL, seq, SEQ_DUPE_UNIQUE_NAME | SEQ_DUPE_ANIM); } if (seqn) { @@ -798,7 +798,7 @@ static Sequence *cut_seq_soft(Scene *scene, Sequence *seq, int cutframe) seqn->startstill = 0; } - calc_sequence(scene, seqn); + BKE_sequence_calc(scene, seqn); } return seqn; } @@ -856,7 +856,7 @@ static int insert_gap(Scene *scene, int gap, int cfra) { if (seq->startdisp >= cfra) { seq->start += gap; - calc_sequence(scene, seq); + BKE_sequence_calc(scene, seq); done = TRUE; } } @@ -974,11 +974,11 @@ static void UNUSED_FUNCTION(no_gaps) (Scene * scene) for (cfra = CFRA; cfra <= EFRA; cfra++) { if (first == 0) { - if (evaluate_seq_frame(scene, cfra) ) first = 1; + if (BKE_sequencer_evaluate_frame(scene, cfra) ) first = 1; } else { done = TRUE; - while (evaluate_seq_frame(scene, cfra) == 0) { + while (BKE_sequencer_evaluate_frame(scene, cfra) == 0) { done = insert_gap(scene, -1, cfra); if (done == 0) break; } @@ -1049,24 +1049,24 @@ static int sequencer_snap_exec(bContext *C, wmOperator *op) /* also check metas */ for (seq = ed->seqbasep->first; seq; seq = seq->next) { if (seq->flag & SELECT && !(seq->depth == 0 && seq->flag & SEQ_LOCK) && - seq_tx_test(seq)) + BKE_sequence_tx_test(seq)) { if ((seq->flag & (SEQ_LEFTSEL + SEQ_RIGHTSEL)) == 0) { /* simple but no anim update */ /* seq->start= snap_frame-seq->startofs+seq->startstill; */ - seq_translate(scene, seq, (snap_frame - seq->startofs + seq->startstill) - seq->start); + BKE_sequence_translate(scene, seq, (snap_frame - seq->startofs + seq->startstill) - seq->start); } else { if (seq->flag & SEQ_LEFTSEL) { - seq_tx_set_final_left(seq, snap_frame); + BKE_sequence_tx_set_final_left(seq, snap_frame); } else { /* SEQ_RIGHTSEL */ - seq_tx_set_final_right(seq, snap_frame); + BKE_sequence_tx_set_final_right(seq, snap_frame); } - seq_tx_handle_xlimits(seq, seq->flag & SEQ_LEFTSEL, seq->flag & SEQ_RIGHTSEL); + BKE_sequence_tx_handle_xlimits(seq, seq->flag & SEQ_LEFTSEL, seq->flag & SEQ_RIGHTSEL); } - calc_sequence(scene, seq); + BKE_sequence_calc(scene, seq); } } @@ -1075,17 +1075,17 @@ static int sequencer_snap_exec(bContext *C, wmOperator *op) for (seq = ed->seqbasep->first; seq; seq = seq->next) { if (seq->flag & SELECT && !(seq->depth == 0 && seq->flag & SEQ_LOCK)) { seq->flag &= ~SEQ_OVERLAP; - if (seq_test_overlap(ed->seqbasep, seq) ) { - shuffle_seq(ed->seqbasep, seq, scene); + if (BKE_sequence_test_overlap(ed->seqbasep, seq) ) { + BKE_sequence_base_shuffle(ed->seqbasep, seq, scene); } } else if (seq->type & SEQ_TYPE_EFFECT) { if (seq->seq1 && (seq->seq1->flag & SELECT)) - calc_sequence(scene, seq); + BKE_sequence_calc(scene, seq); else if (seq->seq2 && (seq->seq2->flag & SELECT)) - calc_sequence(scene, seq); + BKE_sequence_calc(scene, seq); else if (seq->seq3 && (seq->seq3->flag & SELECT)) - calc_sequence(scene, seq); + BKE_sequence_calc(scene, seq); } } @@ -1150,7 +1150,7 @@ static int sequencer_mute_exec(bContext *C, wmOperator *op) } } - seq_update_muting(ed); + BKE_sequencer_update_muting(ed); WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene); return OPERATOR_FINISHED; @@ -1197,7 +1197,7 @@ static int sequencer_unmute_exec(bContext *C, wmOperator *op) } } - seq_update_muting(ed); + BKE_sequencer_update_muting(ed); WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene); return OPERATOR_FINISHED; @@ -1297,12 +1297,12 @@ static int sequencer_reload_exec(bContext *C, wmOperator *op) for (seq = ed->seqbasep->first; seq; seq = seq->next) { if (seq->flag & SELECT) { - update_changed_seq_and_deps(scene, seq, 0, 1); - reload_sequence_new_file(scene, seq, !adjust_length); + BKE_sequencer_update_changed_seq_and_deps(scene, seq, 0, 1); + BKE_sequence_reload_new_file(scene, seq, !adjust_length); if (adjust_length) { - if (seq_test_overlap(ed->seqbasep, seq)) - shuffle_seq(ed->seqbasep, seq, scene); + if (BKE_sequence_test_overlap(ed->seqbasep, seq)) + BKE_sequence_base_shuffle(ed->seqbasep, seq, scene); } } } @@ -1339,7 +1339,7 @@ static int sequencer_refresh_all_exec(bContext *C, wmOperator *UNUSED(op)) Scene *scene = CTX_data_scene(C); Editing *ed = BKE_sequencer_editing_get(scene, FALSE); - free_imbuf_seq(scene, &ed->seqbase, FALSE, FALSE); + BKE_sequencer_free_imbuf(scene, &ed->seqbase, FALSE, FALSE); WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene); @@ -1381,7 +1381,7 @@ static int sequencer_reassign_inputs_exec(bContext *C, wmOperator *op) last_seq->seq2 = seq2; last_seq->seq3 = seq3; - update_changed_seq_and_deps(scene, last_seq, 1, 1); + BKE_sequencer_update_changed_seq_and_deps(scene, last_seq, 1, 1); WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene); @@ -1433,7 +1433,7 @@ static int sequencer_swap_inputs_exec(bContext *C, wmOperator *op) last_seq->seq1 = last_seq->seq2; last_seq->seq2 = seq; - update_changed_seq_and_deps(scene, last_seq, 1, 1); + BKE_sequencer_update_changed_seq_and_deps(scene, last_seq, 1, 1); WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene); @@ -1564,8 +1564,8 @@ static int apply_unique_name_cb(Sequence *seq, void *arg_pt) char name[sizeof(seq->name) - 2]; strcpy(name, seq->name + 2); - seqbase_unique_name_recursive(&scene->ed->seqbase, seq); - seq_dupe_animdata(scene, name, seq->name + 2); + BKE_seqence_base_unique_name_recursive(&scene->ed->seqbase, seq); + BKE_sequencer_dupe_animdata(scene, name, seq->name + 2); return 1; } @@ -1580,7 +1580,7 @@ static int sequencer_add_duplicate_exec(bContext *C, wmOperator *UNUSED(op)) if (ed == NULL) return OPERATOR_CANCELLED; - seqbase_dupli_recursive(scene, NULL, &nseqbase, ed->seqbasep, SEQ_DUPE_CONTEXT); + BKE_sequence_base_dupli_recursive(scene, NULL, &nseqbase, ed->seqbasep, SEQ_DUPE_CONTEXT); if (nseqbase.first) { Sequence *seq = nseqbase.first; @@ -1588,7 +1588,7 @@ static int sequencer_add_duplicate_exec(bContext *C, wmOperator *UNUSED(op)) BLI_movelisttolist(ed->seqbasep, &nseqbase); for (; seq; seq = seq->next) - seq_recursive_apply(seq, apply_unique_name_cb, scene); + BKE_sequencer_recursive_apply(seq, apply_unique_name_cb, scene); WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene); return OPERATOR_FINISHED; @@ -1651,14 +1651,14 @@ static int sequencer_delete_exec(bContext *C, wmOperator *UNUSED(op)) /* updates lengths etc */ seq = ed->seqbasep->first; while (seq) { - calc_sequence(scene, seq); + BKE_sequence_calc(scene, seq); seq = seq->next; } /* free parent metas */ ms = ed->metastack.last; while (ms) { - calc_sequence(scene, ms->parseq); + BKE_sequence_calc(scene, ms->parseq); ms = ms->prev; } @@ -1703,14 +1703,14 @@ static int sequencer_offset_clear_exec(bContext *C, wmOperator *UNUSED(op)) /* updates lengths etc */ seq = ed->seqbasep->first; while (seq) { - calc_sequence(scene, seq); + BKE_sequence_calc(scene, seq); seq = seq->next; } for (seq = ed->seqbasep->first; seq; seq = seq->next) { if ((seq->type & SEQ_TYPE_EFFECT) == 0 && (seq->flag & SELECT)) { - if (seq_test_overlap(ed->seqbasep, seq)) { - shuffle_seq(ed->seqbasep, seq, scene); + if (BKE_sequence_test_overlap(ed->seqbasep, seq)) { + BKE_sequence_base_shuffle(ed->seqbasep, seq, scene); } } } @@ -1760,14 +1760,14 @@ static int sequencer_separate_images_exec(bContext *C, wmOperator *op) /* if (seq->ipo) seq->ipo->id.us--; */ /* XXX, remove fcurve and assign to split image strips */ - start_ofs = cfra = seq_tx_get_final_left(seq, 0); - frame_end = seq_tx_get_final_right(seq, 0); + start_ofs = cfra = BKE_sequence_tx_get_final_left(seq, 0); + frame_end = BKE_sequence_tx_get_final_right(seq, 0); while (cfra < frame_end) { /* new seq */ - se = give_stripelem(seq, cfra); + se = BKE_sequencer_give_stripelem(seq, cfra); - seq_new = seq_dupli_recursive(scene, scene, seq, SEQ_DUPE_UNIQUE_NAME); + seq_new = BKE_sequence_dupli_recursive(scene, scene, seq, SEQ_DUPE_UNIQUE_NAME); BLI_addtail(ed->seqbasep, seq_new); seq_new->start = start_ofs; @@ -1782,12 +1782,12 @@ static int sequencer_separate_images_exec(bContext *C, wmOperator *op) /* new stripdata */ se_new = strip_new->stripdata; BLI_strncpy(se_new->name, se->name, sizeof(se_new->name)); - calc_sequence(scene, seq_new); + BKE_sequence_calc(scene, seq_new); if (step > 1) { seq_new->flag &= ~SEQ_OVERLAP; - if (seq_test_overlap(ed->seqbasep, seq_new)) { - shuffle_seq(ed->seqbasep, seq_new, scene); + if (BKE_sequence_test_overlap(ed->seqbasep, seq_new)) { + BKE_sequence_base_shuffle(ed->seqbasep, seq_new, scene); } } @@ -1797,7 +1797,7 @@ static int sequencer_separate_images_exec(bContext *C, wmOperator *op) start_ofs += step; } - seq_free_sequence(scene, seq); + BKE_sequence_free(scene, seq); seq = seq->next; } else { @@ -1869,7 +1869,7 @@ static int sequencer_meta_toggle_exec(bContext *C, wmOperator *UNUSED(op)) /* recalc all: the meta can have effects connected to it */ for (seq = ed->seqbasep->first; seq; seq = seq->next) - calc_sequence(scene, seq); + BKE_sequence_calc(scene, seq); BKE_sequencer_active_set(scene, ms->parseq); @@ -1880,7 +1880,7 @@ static int sequencer_meta_toggle_exec(bContext *C, wmOperator *UNUSED(op)) } - seq_update_muting(ed); + BKE_sequencer_update_muting(ed); WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene); return OPERATOR_FINISHED; @@ -1911,14 +1911,14 @@ static int sequencer_meta_make_exec(bContext *C, wmOperator *op) Sequence *seq, *seqm, *next, *last_seq = BKE_sequencer_active_get(scene); int channel_max = 1; - if (seqbase_isolated_sel_check(ed->seqbasep) == FALSE) { + if (BKE_sequence_base_isolated_sel_check(ed->seqbasep) == FALSE) { BKE_report(op->reports, RPT_ERROR, "Please select all related strips"); return OPERATOR_CANCELLED; } /* remove all selected from main list, and put in meta */ - seqm = alloc_sequence(ed->seqbasep, 1, 1); /* channel number set later */ + seqm = BKE_sequence_alloc(ed->seqbasep, 1, 1); /* channel number set later */ strcpy(seqm->name + 2, "MetaStrip"); seqm->type = SEQ_TYPE_META; seqm->flag = SELECT; @@ -1934,18 +1934,18 @@ static int sequencer_meta_make_exec(bContext *C, wmOperator *op) seq = next; } seqm->machine = last_seq ? last_seq->machine : channel_max; - calc_sequence(scene, seqm); + BKE_sequence_calc(scene, seqm); seqm->strip = MEM_callocN(sizeof(Strip), "metastrip"); seqm->strip->us = 1; BKE_sequencer_active_set(scene, seqm); - if (seq_test_overlap(ed->seqbasep, seqm) ) shuffle_seq(ed->seqbasep, seqm, scene); + if (BKE_sequence_test_overlap(ed->seqbasep, seqm) ) BKE_sequence_base_shuffle(ed->seqbasep, seqm, scene); - seq_update_muting(ed); + BKE_sequencer_update_muting(ed); - seqbase_unique_name_recursive(&scene->ed->seqbase, seqm); + BKE_seqence_base_unique_name_recursive(&scene->ed->seqbase, seqm); WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene); @@ -1995,7 +1995,7 @@ static int sequencer_meta_separate_exec(bContext *C, wmOperator *UNUSED(op)) last_seq->seqbase.last = NULL; BLI_remlink(ed->seqbasep, last_seq); - seq_free_sequence(scene, last_seq); + BKE_sequence_free(scene, last_seq); /* emtpy meta strip, delete all effects depending on it */ for (seq = ed->seqbasep->first; seq; seq = seq->next) @@ -2009,14 +2009,14 @@ static int sequencer_meta_separate_exec(bContext *C, wmOperator *UNUSED(op)) for (seq = ed->seqbasep->first; seq; seq = seq->next) { if (seq->flag & SELECT) { seq->flag &= ~SEQ_OVERLAP; - if (seq_test_overlap(ed->seqbasep, seq)) { - shuffle_seq(ed->seqbasep, seq, scene); + if (BKE_sequence_test_overlap(ed->seqbasep, seq)) { + BKE_sequence_base_shuffle(ed->seqbasep, seq, scene); } } } BKE_sequencer_sort(scene); - seq_update_muting(ed); + BKE_sequencer_update_muting(ed); WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene); @@ -2414,9 +2414,9 @@ static void swap_sequence(Scene *scene, Sequence *seqa, Sequence *seqb) { int gap = seqb->startdisp - seqa->enddisp; seqb->start = (seqb->start - seqb->startdisp) + seqa->startdisp; - calc_sequence(scene, seqb); + BKE_sequence_calc(scene, seqb); seqa->start = (seqa->start - seqa->startdisp) + seqb->enddisp + gap; - calc_sequence(scene, seqa); + BKE_sequence_calc(scene, seqa); } #if 0 @@ -2454,9 +2454,9 @@ static int sequencer_swap_exec(bContext *C, wmOperator *op) if (seq) { /* disallow effect strips */ - if (get_sequence_effect_num_inputs(seq->type) >= 1 && (seq->effectdata || seq->seq1 || seq->seq2 || seq->seq3)) + if (BKE_sequence_effect_get_num_inputs(seq->type) >= 1 && (seq->effectdata || seq->seq1 || seq->seq2 || seq->seq3)) return OPERATOR_CANCELLED; - if ((get_sequence_effect_num_inputs(active_seq->type) >= 1) && (active_seq->effectdata || active_seq->seq1 || active_seq->seq2 || active_seq->seq3)) + if ((BKE_sequence_effect_get_num_inputs(active_seq->type) >= 1) && (active_seq->effectdata || active_seq->seq1 || active_seq->seq2 || active_seq->seq3)) return OPERATOR_CANCELLED; switch (side) { @@ -2471,7 +2471,7 @@ static int sequencer_swap_exec(bContext *C, wmOperator *op) // XXX - should be a generic function for (iseq = scene->ed->seqbasep->first; iseq; iseq = iseq->next) { if ((iseq->type & SEQ_TYPE_EFFECT) && (seq_is_parent(iseq, active_seq) || seq_is_parent(iseq, seq))) { - calc_sequence(scene, iseq); + BKE_sequence_calc(scene, iseq); } } @@ -2479,8 +2479,8 @@ static int sequencer_swap_exec(bContext *C, wmOperator *op) for (iseq = scene->ed->seqbasep->first; iseq; iseq = iseq->next) { if ((iseq->type & SEQ_TYPE_EFFECT) && (seq_is_parent(iseq, active_seq) || seq_is_parent(iseq, seq))) { /* this may now overlap */ - if (seq_test_overlap(ed->seqbasep, iseq) ) { - shuffle_seq(ed->seqbasep, iseq, scene); + if (BKE_sequence_test_overlap(ed->seqbasep, iseq) ) { + BKE_sequence_base_shuffle(ed->seqbasep, iseq, scene); } } } @@ -2529,7 +2529,7 @@ static int sequencer_rendersize_exec(bContext *C, wmOperator *UNUSED(op)) if (active_seq->strip) { switch (active_seq->type) { case SEQ_TYPE_IMAGE: - se = give_stripelem(active_seq, scene->r.cfra); + se = BKE_sequencer_give_stripelem(active_seq, scene->r.cfra); break; case SEQ_TYPE_MOVIE: se = active_seq->strip->stripdata; @@ -2596,14 +2596,14 @@ static int sequencer_copy_exec(bContext *C, wmOperator *op) ListBase nseqbase = {NULL, NULL}; - seq_free_clipboard(); + BKE_sequencer_free_clipboard(); - if (seqbase_isolated_sel_check(ed->seqbasep) == FALSE) { + if (BKE_sequence_base_isolated_sel_check(ed->seqbasep) == FALSE) { BKE_report(op->reports, RPT_ERROR, "Please select all related strips"); return OPERATOR_CANCELLED; } - seqbase_dupli_recursive(scene, NULL, &nseqbase, ed->seqbasep, SEQ_DUPE_UNIQUE_NAME); + BKE_sequence_base_dupli_recursive(scene, NULL, &nseqbase, ed->seqbasep, SEQ_DUPE_UNIQUE_NAME); /* To make sure the copied strips have unique names between each other add * them temporarily to the end of the original seqbase. (bug 25932) @@ -2613,7 +2613,7 @@ static int sequencer_copy_exec(bContext *C, wmOperator *op) BLI_movelisttolist(ed->seqbasep, &nseqbase); for (seq = first_seq; seq; seq = seq->next) - seq_recursive_apply(seq, apply_unique_name_cb, scene); + BKE_sequencer_recursive_apply(seq, apply_unique_name_cb, scene); seqbase_clipboard.first = first_seq; seqbase_clipboard.last = ed->seqbasep->last; @@ -2663,13 +2663,13 @@ static int sequencer_paste_exec(bContext *C, wmOperator *UNUSED(op)) ED_sequencer_deselect_all(scene); ofs = scene->r.cfra - seqbase_clipboard_frame; - seqbase_dupli_recursive(scene, NULL, &nseqbase, &seqbase_clipboard, SEQ_DUPE_UNIQUE_NAME); + BKE_sequence_base_dupli_recursive(scene, NULL, &nseqbase, &seqbase_clipboard, SEQ_DUPE_UNIQUE_NAME); /* transform pasted strips before adding */ if (ofs) { for (iseq = nseqbase.first; iseq; iseq = iseq->next) { - seq_translate(scene, iseq, ofs); - seq_sound_init(scene, iseq); + BKE_sequence_translate(scene, iseq, ofs); + BKE_sequence_sound_init(scene, iseq); } } @@ -2679,7 +2679,7 @@ static int sequencer_paste_exec(bContext *C, wmOperator *UNUSED(op)) /* make sure the pasted strips have unique names between them */ for (; iseq; iseq = iseq->next) { - seq_recursive_apply(iseq, apply_unique_name_cb, scene); + BKE_sequencer_recursive_apply(iseq, apply_unique_name_cb, scene); } WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene); @@ -2716,7 +2716,7 @@ static int sequencer_swap_data_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - if (seq_swap(seq_act, seq_other, &error_msg) == 0) { + if (BKE_sequence_swap(seq_act, seq_other, &error_msg) == 0) { BKE_report(op->reports, RPT_ERROR, error_msg); return OPERATOR_CANCELLED; } @@ -2730,8 +2730,8 @@ static int sequencer_swap_data_exec(bContext *C, wmOperator *op) seq_act->scene_sound = NULL; seq_other->scene_sound = NULL; - calc_sequence(scene, seq_act); - calc_sequence(scene, seq_other); + BKE_sequence_calc(scene, seq_act); + BKE_sequence_calc(scene, seq_other); if (seq_act->sound) sound_add_scene_sound_defaults(scene, seq_act); if (seq_other->sound) sound_add_scene_sound_defaults(scene, seq_other); @@ -2882,10 +2882,10 @@ static int sequencer_change_effect_input_exec(bContext *C, wmOperator *op) SWAP(Sequence *, *seq_1, *seq_2); } - update_changed_seq_and_deps(scene, seq, 0, 1); + BKE_sequencer_update_changed_seq_and_deps(scene, seq, 0, 1); /* important else we don't get the imbuf cache flushed */ - free_imbuf_seq(scene, &ed->seqbase, FALSE, FALSE); + BKE_sequencer_free_imbuf(scene, &ed->seqbase, FALSE, FALSE); WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene); @@ -2925,27 +2925,27 @@ static int sequencer_change_effect_type_exec(bContext *C, wmOperator *op) /* can someone explain the logic behind only allowing to increase this, * copied from 2.4x - campbell */ - if (get_sequence_effect_num_inputs(seq->type) < - get_sequence_effect_num_inputs(new_type)) + if (BKE_sequence_effect_get_num_inputs(seq->type) < + BKE_sequence_effect_get_num_inputs(new_type)) { BKE_report(op->reports, RPT_ERROR, "New effect needs more input strips"); return OPERATOR_CANCELLED; } else { - sh = get_sequence_effect(seq); + sh = BKE_sequence_get_effect(seq); sh.free(seq); seq->type = new_type; - sh = get_sequence_effect(seq); + sh = BKE_sequence_get_effect(seq); sh.init(seq); } /* update */ - update_changed_seq_and_deps(scene, seq, 0, 1); + BKE_sequencer_update_changed_seq_and_deps(scene, seq, 0, 1); /* important else we don't get the imbuf cache flushed */ - free_imbuf_seq(scene, &ed->seqbase, FALSE, FALSE); + BKE_sequencer_free_imbuf(scene, &ed->seqbase, FALSE, FALSE); WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene); @@ -3013,12 +3013,12 @@ static int sequencer_change_path_exec(bContext *C, wmOperator *op) /* correct start/end frames so we don't move * important not to set seq->len= len; allow the function to handle it */ - reload_sequence_new_file(scene, seq, TRUE); + BKE_sequence_reload_new_file(scene, seq, TRUE); - calc_sequence(scene, seq); + BKE_sequence_calc(scene, seq); /* important else we don't get the imbuf cache flushed */ - free_imbuf_seq(scene, &ed->seqbase, FALSE, FALSE); + BKE_sequencer_free_imbuf(scene, &ed->seqbase, FALSE, FALSE); } else { /* lame, set rna filepath */ @@ -3074,6 +3074,8 @@ void SEQUENCER_OT_change_path(struct wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - WM_operator_properties_filesel(ot, FOLDERFILE | IMAGEFILE | MOVIEFILE, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_DIRECTORY | WM_FILESEL_RELPATH | WM_FILESEL_FILEPATH | WM_FILESEL_FILES, FILE_DEFAULTDISPLAY); + WM_operator_properties_filesel(ot, FOLDERFILE | IMAGEFILE | MOVIEFILE, FILE_SPECIAL, FILE_OPENFILE, + WM_FILESEL_DIRECTORY | WM_FILESEL_RELPATH | WM_FILESEL_FILEPATH | WM_FILESEL_FILES, + FILE_DEFAULTDISPLAY); } diff --git a/source/blender/editors/space_sequencer/sequencer_select.c b/source/blender/editors/space_sequencer/sequencer_select.c index 7849f84e777..3d57f2f88ed 100644 --- a/source/blender/editors/space_sequencer/sequencer_select.c +++ b/source/blender/editors/space_sequencer/sequencer_select.c @@ -860,10 +860,7 @@ static int sequencer_borderselect_exec(bContext *C, wmOperator *op) if (ed == NULL) return OPERATOR_CANCELLED; - rect.xmin = RNA_int_get(op->ptr, "xmin"); - rect.ymin = RNA_int_get(op->ptr, "ymin"); - rect.xmax = RNA_int_get(op->ptr, "xmax"); - rect.ymax = RNA_int_get(op->ptr, "ymax"); + WM_operator_properties_border_to_rcti(op, &rect); mval[0] = rect.xmin; mval[1] = rect.ymin; @@ -1112,7 +1109,7 @@ static short select_grouped_effect_link(Editing *ed, Sequence *actseq) actseq->tmp = SET_INT_IN_POINTER(TRUE); - for (seq_begin(ed, &iter, TRUE); iter.valid; seq_next(&iter)) { + for (BKE_seqence_iterator_begin(ed, &iter, TRUE); iter.valid; BKE_seqence_iterator_next(&iter)) { seq = iter.seq; /* Ignore all seqs already selected! */ @@ -1140,8 +1137,8 @@ static short select_grouped_effect_link(Editing *ed, Sequence *actseq) changed = TRUE; /* Unfortunately, we must restart checks from the beginning. */ - seq_end(&iter); - seq_begin(ed, &iter, TRUE); + BKE_seqence_iterator_end(&iter); + BKE_seqence_iterator_begin(ed, &iter, TRUE); } /* Video strips bellow active one, or any strip for audio (order do no matters here!). */ @@ -1150,7 +1147,7 @@ static short select_grouped_effect_link(Editing *ed, Sequence *actseq) changed = TRUE; } } - seq_end(&iter); + BKE_seqence_iterator_end(&iter); return changed; } diff --git a/source/blender/editors/space_text/text_draw.c b/source/blender/editors/space_text/text_draw.c index 8be5b644afb..6240d174575 100644 --- a/source/blender/editors/space_text/text_draw.c +++ b/source/blender/editors/space_text/text_draw.c @@ -50,7 +50,6 @@ #include "BKE_suggestions.h" #include "BKE_text.h" - #include "BIF_gl.h" #include "ED_datafiles.h" @@ -1854,7 +1853,7 @@ void draw_text_main(SpaceText *st, ARegion *ar) /* draw other stuff */ draw_brackets(st, ar); draw_markers(st, ar); - glTranslatef(0.375f, 0.375f, 0.0f); /* XXX scroll requires exact pixel space */ + glTranslatef(GLA_PIXEL_OFS, GLA_PIXEL_OFS, 0.0f); /* XXX scroll requires exact pixel space */ draw_textscroll(st, &scroll, &back); draw_documentation(st, ar); draw_suggestion_list(st, ar); diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index 1eba2deed96..df90ce24dda 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -310,7 +310,8 @@ void TEXT_OT_open(wmOperatorType *ot) ot->flag = OPTYPE_UNDO; /* properties */ - WM_operator_properties_filesel(ot, FOLDERFILE | TEXTFILE | PYSCRIPTFILE, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY); //XXX TODO, relative_path + WM_operator_properties_filesel(ot, FOLDERFILE | TEXTFILE | PYSCRIPTFILE, FILE_SPECIAL, FILE_OPENFILE, + WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY); //XXX TODO, relative_path RNA_def_boolean(ot->srna, "internal", 0, "Make internal", "Make text file internal after loading"); } @@ -570,7 +571,8 @@ void TEXT_OT_save_as(wmOperatorType *ot) ot->poll = text_edit_poll; /* properties */ - WM_operator_properties_filesel(ot, FOLDERFILE | TEXTFILE | PYSCRIPTFILE, FILE_SPECIAL, FILE_SAVE, WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY); //XXX TODO, relative_path + WM_operator_properties_filesel(ot, FOLDERFILE | TEXTFILE | PYSCRIPTFILE, FILE_SPECIAL, FILE_SAVE, + WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY); //XXX TODO, relative_path } /******************* run script operator *********************/ diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 2d3cf72643f..ff1b3e75d08 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -6611,7 +6611,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, const short } /* XXX particles are not safe for simultaneous threaded render */ - if (G.rendering && ob->particlesystem.first) + if (G.is_rendering && ob->particlesystem.first) return; /* xray delay? */ diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 85a4d911df5..199a1751f9d 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -1532,7 +1532,7 @@ exit: /* ************************************************************* */ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d, - const short do_forground, const short do_camera_frame) + const short do_foreground, const short do_camera_frame) { RegionView3D *rv3d = ar->regiondata; BGpic *bgpic; @@ -1541,7 +1541,7 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d, ImBuf *ibuf = NULL, *freeibuf; float vec[4], fac, asp, zoomx, zoomy; float x1, y1, x2, y2, cx, cy; - int fg_flag = do_forground ? V3D_BGPIC_FOREGROUND : 0; + int fg_flag = do_foreground ? V3D_BGPIC_FOREGROUND : 0; for (bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next) { @@ -1592,7 +1592,7 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d, ibuf = BKE_movieclip_get_ibuf(clip, &bgpic->cuser); image_aspect[0] = clip->aspx; - image_aspect[1] = clip->aspx; + image_aspect[1] = clip->aspy; /* working with ibuf from image and clip has got different workflow now. * ibuf acquired from clip is referenced by cache system and should @@ -1772,7 +1772,7 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d, } static void view3d_draw_bgpic_test(Scene *scene, ARegion *ar, View3D *v3d, - const short do_forground, const short do_camera_frame) + const short do_foreground, const short do_camera_frame) { RegionView3D *rv3d = ar->regiondata; @@ -1788,11 +1788,11 @@ static void view3d_draw_bgpic_test(Scene *scene, ARegion *ar, View3D *v3d, if ((rv3d->view == RV3D_VIEW_USER) || (rv3d->persp != RV3D_ORTHO)) { if (rv3d->persp == RV3D_CAMOB) { - view3d_draw_bgpic(scene, ar, v3d, do_forground, do_camera_frame); + view3d_draw_bgpic(scene, ar, v3d, do_foreground, do_camera_frame); } } else { - view3d_draw_bgpic(scene, ar, v3d, do_forground, do_camera_frame); + view3d_draw_bgpic(scene, ar, v3d, do_foreground, do_camera_frame); } } diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index ba665cfb89c..9cda4900c8d 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -434,7 +434,7 @@ static void viewops_data_create(bContext *C, wmOperator *op, wmEvent *event) calculateTransformCenter(C, V3D_CENTROID, lastofs, NULL); negate_v3_v3(vod->dyn_ofs, lastofs); } - else if (U.uiflag & USER_ORBIT_ZBUF) { + else if (U.uiflag & USER_ZBUF_ORBIT) { view3d_operator_needs_opengl(C); /* needed for zbuf drawing */ @@ -2471,10 +2471,7 @@ static int render_border_exec(bContext *C, wmOperator *op) rctf vb; /* get border select values using rna */ - rect.xmin = RNA_int_get(op->ptr, "xmin"); - rect.ymin = RNA_int_get(op->ptr, "ymin"); - rect.xmax = RNA_int_get(op->ptr, "xmax"); - rect.ymax = RNA_int_get(op->ptr, "ymax"); + WM_operator_properties_border_to_rcti(op, &rect); /* calculate range */ ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, &vb, FALSE); @@ -2528,10 +2525,7 @@ void VIEW3D_OT_render_border(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* rna */ - RNA_def_int(ot->srna, "xmin", 0, INT_MIN, INT_MAX, "X Min", "", INT_MIN, INT_MAX); - RNA_def_int(ot->srna, "xmax", 0, INT_MIN, INT_MAX, "X Max", "", INT_MIN, INT_MAX); - RNA_def_int(ot->srna, "ymin", 0, INT_MIN, INT_MAX, "Y Min", "", INT_MIN, INT_MAX); - RNA_def_int(ot->srna, "ymax", 0, INT_MIN, INT_MAX, "Y Max", "", INT_MIN, INT_MAX); + WM_operator_properties_border(ot); } /* ********************* Border Zoom operator ****************** */ @@ -2542,10 +2536,12 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op) View3D *v3d = CTX_wm_view3d(C); RegionView3D *rv3d = CTX_wm_region_view3d(C); Scene *scene = CTX_data_scene(C); + int gesture_mode; /* Zooms in on a border drawn by the user */ rcti rect; - float dvec[3], vb[2], xscale, yscale, scale; + float dvec[3], vb[2], xscale, yscale; + float dist_range_min; /* SMOOTHVIEW */ float new_dist; @@ -2560,10 +2556,10 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op) view3d_operator_needs_opengl(C); /* get border select values using rna */ - rect.xmin = RNA_int_get(op->ptr, "xmin"); - rect.ymin = RNA_int_get(op->ptr, "ymin"); - rect.xmax = RNA_int_get(op->ptr, "xmax"); - rect.ymax = RNA_int_get(op->ptr, "ymax"); + WM_operator_properties_border_to_rcti(op, &rect); + + /* check if zooming in/out view */ + gesture_mode = RNA_int_get(op->ptr, "gesture_mode"); /* Get Z Depths, needed for perspective, nice for ortho */ bgl_get_mats(&mats); @@ -2608,13 +2604,13 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op) dvec[1] = p[1] - p_corner[1]; dvec[2] = p[2] - p_corner[2]; - new_dist = len_v3(dvec); - if (new_dist <= v3d->near * 1.5f) new_dist = v3d->near * 1.5f; - new_ofs[0] = -p[0]; new_ofs[1] = -p[1]; new_ofs[2] = -p[2]; + new_dist = len_v3(dvec); + dist_range_min = v3d->near * 1.5f; + } else { /* othographic */ /* find the current window width and height */ @@ -2649,10 +2645,21 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op) /* work out the ratios, so that everything selected fits when we zoom */ xscale = ((rect.xmax - rect.xmin) / vb[0]); yscale = ((rect.ymax - rect.ymin) / vb[1]); - scale = (xscale >= yscale) ? xscale : yscale; + new_dist *= maxf(xscale, yscale); /* zoom in as required, or as far as we can go */ - new_dist = ((new_dist * scale) >= 0.001f * v3d->grid) ? new_dist * scale : 0.001f * v3d->grid; + dist_range_min = 0.001f * v3d->grid; + } + + if (gesture_mode == GESTURE_MODAL_OUT) { + sub_v3_v3v3(dvec, new_ofs, rv3d->ofs); + new_dist = rv3d->dist * (rv3d->dist / new_dist); + add_v3_v3v3(new_ofs, rv3d->ofs, dvec); + } + + /* clamp after because we may have been zooming out */ + if (new_dist < dist_range_min) { + new_dist = dist_range_min; } smooth_view(C, v3d, ar, NULL, NULL, new_ofs, NULL, &new_dist, NULL); @@ -2678,7 +2685,7 @@ static int view3d_zoom_border_invoke(bContext *C, wmOperator *op, wmEvent *event void VIEW3D_OT_zoom_border(wmOperatorType *ot) { /* identifiers */ - ot->name = "Border Zoom"; + ot->name = "Zoom to Border"; ot->description = "Zoom in the view to the nearest object contained in the border"; ot->idname = "VIEW3D_OT_zoom_border"; @@ -2694,11 +2701,7 @@ void VIEW3D_OT_zoom_border(wmOperatorType *ot) ot->flag = 0; /* rna */ - RNA_def_int(ot->srna, "xmin", 0, INT_MIN, INT_MAX, "X Min", "", INT_MIN, INT_MAX); - RNA_def_int(ot->srna, "xmax", 0, INT_MIN, INT_MAX, "X Max", "", INT_MIN, INT_MAX); - RNA_def_int(ot->srna, "ymin", 0, INT_MIN, INT_MAX, "Y Min", "", INT_MIN, INT_MAX); - RNA_def_int(ot->srna, "ymax", 0, INT_MIN, INT_MAX, "Y Max", "", INT_MIN, INT_MAX); - + WM_operator_properties_gesture_border(ot, FALSE); } /* sets the view to 1:1 camera/render-pixel */ @@ -3309,10 +3312,7 @@ static int view3d_clipping_exec(bContext *C, wmOperator *op) bglMats mats; rcti rect; - rect.xmin = RNA_int_get(op->ptr, "xmin"); - rect.ymin = RNA_int_get(op->ptr, "ymin"); - rect.xmax = RNA_int_get(op->ptr, "xmax"); - rect.ymax = RNA_int_get(op->ptr, "ymax"); + WM_operator_properties_border_to_rcti(op, &rect); rv3d->rflag |= RV3D_CLIPPING; rv3d->clipbb = MEM_callocN(sizeof(BoundBox), "clipbb"); @@ -3365,10 +3365,7 @@ void VIEW3D_OT_clip_border(wmOperatorType *ot) ot->flag = 0; /* rna */ - RNA_def_int(ot->srna, "xmin", 0, INT_MIN, INT_MAX, "X Min", "", INT_MIN, INT_MAX); - RNA_def_int(ot->srna, "xmax", 0, INT_MIN, INT_MAX, "X Max", "", INT_MIN, INT_MAX); - RNA_def_int(ot->srna, "ymin", 0, INT_MIN, INT_MAX, "Y Min", "", INT_MIN, INT_MAX); - RNA_def_int(ot->srna, "ymax", 0, INT_MIN, INT_MAX, "Y Max", "", INT_MIN, INT_MAX); + WM_operator_properties_border(ot); } /* ***************** 3d cursor cursor op ******************* */ @@ -3405,7 +3402,7 @@ static int set_3dcursor_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *eve if (mval[0] != IS_CLIPPED) { short depth_used = 0; - if (U.uiflag & USER_ORBIT_ZBUF) { /* maybe this should be accessed some other way */ + if (U.uiflag & USER_ZBUF_CURSOR) { /* maybe this should be accessed some other way */ view3d_operator_needs_opengl(C); if (ED_view3d_autodist(scene, ar, v3d, event->mval, fp)) depth_used = 1; diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index 39ec7514a88..1a91b0aa085 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -1938,10 +1938,7 @@ static int view3d_borderselect_exec(bContext *C, wmOperator *op) view3d_set_viewcontext(C, &vc); select = (RNA_int_get(op->ptr, "gesture_mode") == GESTURE_MODAL_SELECT); - rect.xmin = RNA_int_get(op->ptr, "xmin"); - rect.ymin = RNA_int_get(op->ptr, "ymin"); - rect.xmax = RNA_int_get(op->ptr, "xmax"); - rect.ymax = RNA_int_get(op->ptr, "ymax"); + WM_operator_properties_border_to_rcti(op, &rect); extend = RNA_boolean_get(op->ptr, "extend"); if (vc.obedit) { diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 303f477503d..d545bfe0417 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -175,7 +175,6 @@ void convertViewVec(TransInfo *t, float r_vec[3], int dx, int dy) if (t->options & CTX_MASK) { convertViewVec2D_mask(t->view, r_vec, dx, dy); - ED_space_image_get_aspect(t->sa->spacedata.first, &aspx, &aspy); } else { @@ -2933,6 +2932,14 @@ int Resize(TransInfo *t, const int mval[2]) for (i = 0, td = t->data; i < t->total; i++, td++) ElementResize(t, td, mat); + + /* In proportional edit it can happen that */ + /* vertices in the radius of the brush end */ + /* outside the clipping area */ + /* XXX HACK - dg */ + if (t->flag & (T_PROP_EDIT | T_PROP_CONNECTED)) { + clipUVData(t); + } } recalcData(t); @@ -3788,9 +3795,18 @@ int Translation(TransInfo *t, const int UNUSED(mval[2])) applyTranslation(t, t->values); /* evil hack - redo translation if clipping needed */ - if (t->flag & T_CLIP_UV && clipUVTransform(t, t->values, 0)) + if (t->flag & T_CLIP_UV && clipUVTransform(t, t->values, 0)) { applyTranslation(t, t->values); + /* In proportional edit it can happen that */ + /* vertices in the radius of the brush end */ + /* outside the clipping area */ + /* XXX HACK - dg */ + if (t->flag & (T_PROP_EDIT | T_PROP_CONNECTED)) { + clipUVData(t); + } + } + recalcData(t); ED_area_headerprint(t->sa, str); diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h index 3ab5bf7bbfb..8a7148aad95 100644 --- a/source/blender/editors/transform/transform.h +++ b/source/blender/editors/transform/transform.h @@ -562,6 +562,7 @@ void remake_graph_transdata(TransInfo *t, struct ListBase *anim_data); void flushTransUVs(TransInfo *t); void flushTransParticles(TransInfo *t); int clipUVTransform(TransInfo *t, float *vec, int resize); +void clipUVData(TransInfo *t); void flushTransNodes(TransInfo *t); void flushTransSeq(TransInfo *t); void flushTransTracking(TransInfo *t); @@ -666,7 +667,7 @@ int initTransInfo(struct bContext *C, TransInfo *t, struct wmOperator *op, struc void postTrans (struct bContext *C, TransInfo *t); void resetTransRestrictions(TransInfo *t); -void drawLine(TransInfo *t, float *center, float *dir, char axis, short options); +void drawLine(TransInfo *t, const float center[3], const float dir[3], char axis, short options); void drawNonPropEdge(const struct bContext *C, TransInfo *t); diff --git a/source/blender/editors/transform/transform_constraints.c b/source/blender/editors/transform/transform_constraints.c index b5b1fbde184..0aa46a36afe 100644 --- a/source/blender/editors/transform/transform_constraints.c +++ b/source/blender/editors/transform/transform_constraints.c @@ -722,7 +722,13 @@ void drawPropCircle(const struct bContext *C, TransInfo *t) else if (t->spacetype == SPACE_IMAGE) { float aspx, aspy; - ED_space_image_get_uv_aspect(t->sa->spacedata.first, &aspx, &aspy); + if (t->options & CTX_MASK) { + /* untested - mask aspect is TODO */ + ED_space_image_get_aspect(t->sa->spacedata.first, &aspx, &aspy); + } + else { + ED_space_image_get_uv_aspect(t->sa->spacedata.first, &aspx, &aspy); + } glScalef(1.0f / aspx, 1.0f / aspy, 1.0); } diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c index 02101b9d02d..c22a645eb53 100644 --- a/source/blender/editors/transform/transform_conversions.c +++ b/source/blender/editors/transform/transform_conversions.c @@ -2189,12 +2189,13 @@ cleanup: void flushTransNodes(TransInfo *t) { int a; - TransData2D *td; + TransData *td; + TransData2D *td2d; /* flush to 2d vector from internally used 3d vector */ - for (a = 0, td = t->data2d; a < t->total; a++, td++) { - td->loc2d[0] = td->loc[0]; - td->loc2d[1] = td->loc[1]; + for (a = 0, td = t->data, td2d = t->data2d; a < t->total; a++, td++, td2d++) { + bNode *node = td->extra; + add_v2_v2v2(&node->locx, td2d->loc, td2d->ih1); } /* handle intersection with noodles */ @@ -2236,7 +2237,7 @@ void flushTransSeq(TransInfo *t) switch (tdsq->sel_flag) { case SELECT: #ifdef SEQ_TX_NESTED_METAS - if ((seq->depth != 0 || seq_tx_test(seq))) /* for meta's, their children move */ + if ((seq->depth != 0 || BKE_sequence_tx_test(seq))) /* for meta's, their children move */ seq->start = new_frame - tdsq->start_offset; #else if (seq->type != SEQ_TYPE_META && (seq->depth != 0 || seq_tx_test(seq))) /* for meta's, their children move */ @@ -2248,14 +2249,14 @@ void flushTransSeq(TransInfo *t) } break; case SEQ_LEFTSEL: /* no vertical transform */ - seq_tx_set_final_left(seq, new_frame); - seq_tx_handle_xlimits(seq, tdsq->flag & SEQ_LEFTSEL, tdsq->flag & SEQ_RIGHTSEL); - seq_single_fix(seq); /* todo - move this into aftertrans update? - old seq tx needed it anyway */ + BKE_sequence_tx_set_final_left(seq, new_frame); + BKE_sequence_tx_handle_xlimits(seq, tdsq->flag & SEQ_LEFTSEL, tdsq->flag & SEQ_RIGHTSEL); + BKE_sequence_single_fix(seq); /* todo - move this into aftertrans update? - old seq tx needed it anyway */ break; case SEQ_RIGHTSEL: /* no vertical transform */ - seq_tx_set_final_right(seq, new_frame); - seq_tx_handle_xlimits(seq, tdsq->flag & SEQ_LEFTSEL, tdsq->flag & SEQ_RIGHTSEL); - seq_single_fix(seq); /* todo - move this into aftertrans update? - old seq tx needed it anyway */ + BKE_sequence_tx_set_final_right(seq, new_frame); + BKE_sequence_tx_handle_xlimits(seq, tdsq->flag & SEQ_LEFTSEL, tdsq->flag & SEQ_RIGHTSEL); + BKE_sequence_single_fix(seq); /* todo - move this into aftertrans update? - old seq tx needed it anyway */ break; } @@ -2264,14 +2265,14 @@ void flushTransSeq(TransInfo *t) /* Calculate this strip and all nested strips * children are ALWAYS transformed first * so we don't need to do this in another loop. */ - calc_sequence(t->scene, seq); + BKE_sequence_calc(t->scene, seq); } else { - calc_sequence_disp(t->scene, seq); + BKE_sequence_calc_disp(t->scene, seq); } if (tdsq->sel_flag == SELECT) - seq_offset_animdata(t->scene, seq, seq->start - old_start); + BKE_sequencer_offset_animdata(t->scene, seq, seq->start - old_start); } seq_prev = seq; } @@ -2283,12 +2284,12 @@ void flushTransSeq(TransInfo *t) /* calc all meta's then effects [#27953] */ for (seq = seqbasep->first; seq; seq = seq->next) { if (seq->type == SEQ_TYPE_META && seq->flag & SELECT) { - calc_sequence(t->scene, seq); + BKE_sequence_calc(t->scene, seq); } } for (seq = seqbasep->first; seq; seq = seq->next) { if (seq->seq1 || seq->seq2 || seq->seq3) { - calc_sequence(t->scene, seq); + BKE_sequence_calc(t->scene, seq); } } } @@ -2305,7 +2306,7 @@ void flushTransSeq(TransInfo *t) if (seq->depth == 0) { /* test overlap, displayes red outline */ seq->flag &= ~SEQ_OVERLAP; - if (seq_test_overlap(seqbasep, seq)) { + if (BKE_sequence_test_overlap(seqbasep, seq)) { seq->flag |= SEQ_OVERLAP; } } @@ -2493,6 +2494,26 @@ int clipUVTransform(TransInfo *t, float *vec, int resize) return (clipx || clipy); } +void clipUVData(TransInfo *t) +{ + TransData *td = NULL; + int a; + float aspx, aspy; + + ED_space_image_get_uv_aspect(t->sa->spacedata.first, &aspx, &aspy); + + for (a = 0, td = t->data; a < t->total; a++, td++) { + if (td->flag & TD_NOACTION) + break; + + if ((td->flag & TD_SKIP) || (!td->loc)) + continue; + + td->loc[0] = minf(maxf(0.0f, td->loc[0]), aspx); + td->loc[1] = minf(maxf(0.0f, td->loc[1]), aspy); + } +} + /* ********************* ANIMATION EDITORS (GENERAL) ************************* */ /* This function tests if a point is on the "mouse" side of the cursor/frame-marking */ @@ -3934,8 +3955,8 @@ static void SeqTransInfo(TransInfo *t, Sequence *seq, int *recursive, int *count Scene *scene = t->scene; int cfra = CFRA; - int left = seq_tx_get_final_left(seq, 1); - int right = seq_tx_get_final_right(seq, 1); + int left = BKE_sequence_tx_get_final_left(seq, 1); + int right = BKE_sequence_tx_get_final_right(seq, 1); if (seq->depth == 0 && ((seq->flag & SELECT) == 0 || (seq->flag & SEQ_LOCK))) { *recursive = FALSE; @@ -4070,16 +4091,16 @@ static TransData *SeqToTransData(TransData *td, TransData2D *td2d, TransDataSeq /* Use seq_tx_get_final_left() and an offset here * so transform has the left hand location of the strip. * tdsq->start_offset is used when flushing the tx data back */ - start_left = seq_tx_get_final_left(seq, 0); + start_left = BKE_sequence_tx_get_final_left(seq, 0); td2d->loc[0] = start_left; tdsq->start_offset = start_left - seq->start; /* use to apply the original location */ break; case SEQ_LEFTSEL: - start_left = seq_tx_get_final_left(seq, 0); + start_left = BKE_sequence_tx_get_final_left(seq, 0); td2d->loc[0] = start_left; break; case SEQ_RIGHTSEL: - td2d->loc[0] = seq_tx_get_final_right(seq, 0); + td2d->loc[0] = BKE_sequence_tx_get_final_right(seq, 0); break; } @@ -4237,7 +4258,7 @@ static void freeSeqData(TransInfo *t) for (a = 0; a < t->total; a++, td++) { seq = ((TransDataSeq *)td->extra)->seq; if ((seq != seq_prev)) { - minframe = MIN2(minframe, seq->startdisp); + minframe = mini(minframe, seq->startdisp); } } @@ -4250,7 +4271,7 @@ static void freeSeqData(TransInfo *t) } } - shuffle_seq_time(seqbasep, t->scene); + BKE_sequence_base_shuffle_time(seqbasep, t->scene); for (seq = seqbasep->first; seq; seq = seq->next) { if (seq->machine >= MAXSEQ * 2) { @@ -4262,10 +4283,10 @@ static void freeSeqData(TransInfo *t) } } - shuffle_seq_time(seqbasep, t->scene); + BKE_sequence_base_shuffle_time(seqbasep, t->scene); } else { - shuffle_seq_time(seqbasep, t->scene); + BKE_sequence_base_shuffle_time(seqbasep, t->scene); } #else shuffle_seq_time(seqbasep, t->scene); @@ -4279,7 +4300,7 @@ static void freeSeqData(TransInfo *t) seq = ((TransDataSeq *)td->extra)->seq; if ((seq != seq_prev)) { if ((seq->type & SEQ_TYPE_EFFECT) && seq->seq1) { - calc_sequence(t->scene, seq); + BKE_sequence_calc(t->scene, seq); } } } @@ -4291,8 +4312,8 @@ static void freeSeqData(TransInfo *t) seq = ((TransDataSeq *)td->extra)->seq; if ((seq != seq_prev)) { if ((seq->type & SEQ_TYPE_EFFECT) && seq->seq1) { - if (seq_test_overlap(seqbasep, seq)) { - shuffle_seq(seqbasep, seq, t->scene); + if (BKE_sequence_test_overlap(seqbasep, seq)) { + BKE_sequence_base_shuffle(seqbasep, seq, t->scene); } } } @@ -4306,9 +4327,9 @@ static void freeSeqData(TransInfo *t) for (seq = seqbasep->first; seq; seq = seq->next) { /* We might want to build a list of effects that need to be updated during transform */ if (seq->type & SEQ_TYPE_EFFECT) { - if (seq->seq1 && seq->seq1->flag & SELECT) calc_sequence(t->scene, seq); - else if (seq->seq2 && seq->seq2->flag & SELECT) calc_sequence(t->scene, seq); - else if (seq->seq3 && seq->seq3->flag & SELECT) calc_sequence(t->scene, seq); + if (seq->seq1 && seq->seq1->flag & SELECT) BKE_sequence_calc(t->scene, seq); + else if (seq->seq2 && seq->seq2->flag & SELECT) BKE_sequence_calc(t->scene, seq); + else if (seq->seq3 && seq->seq3->flag & SELECT) BKE_sequence_calc(t->scene, seq); } } @@ -4319,7 +4340,7 @@ static void freeSeqData(TransInfo *t) for (a = 0; a < t->total; a++, td++) { seq = ((TransDataSeq *)td->extra)->seq; if ((seq != seq_prev) && (seq->depth == 0)) { - calc_sequence_disp(t->scene, seq); + BKE_sequence_calc_disp(t->scene, seq); } seq_prev = seq; } @@ -4983,8 +5004,9 @@ static void special_aftertrans_update__mask(bContext *C, TransInfo *t) if (t->scene->nodetree) { /* tracks can be used for stabilization nodes, * flush update for such nodes */ - nodeUpdateID(t->scene->nodetree, &mask->id); - WM_event_add_notifier(C, NC_SCENE | ND_NODES, NULL); + //if (nodeUpdateID(t->scene->nodetree, &mask->id)) { + WM_event_add_notifier(C, NC_MASK | ND_DATA, &mask->id); + //} } /* TODO - dont key all masks... */ @@ -5524,24 +5546,22 @@ static void createTransObject(bContext *C, TransInfo *t) /* transcribe given node into TransData2D for Transforming */ static void NodeToTransData(TransData *td, TransData2D *td2d, bNode *node) -// static void NodeToTransData(bContext *C, TransInfo *t, TransData2D *td, bNode *node) { - td2d->loc[0] = node->locx; /* hold original location */ - td2d->loc[1] = node->locy; + /* hold original location */ + float locxy[2] = {(node->totr.xmax + node->totr.xmin) / 2.0f, + (node->totr.ymax + node->totr.ymin) / 2.0f}; + + copy_v2_v2(td2d->loc, locxy); td2d->loc[2] = 0.0f; - td2d->loc2d = &node->locx; /* current location */ + td2d->loc2d = td2d->loc; /* current location */ td->flag = 0; - /* exclude nodes whose parent is also transformed */ - if (node->parent && (node->parent->flag & NODE_TRANSFORM)) { - td->flag |= TD_SKIP; - } td->loc = td2d->loc; copy_v3_v3(td->iloc, td->loc); /* use node center instead of origin (top-left corner) */ - td->center[0] = node->locx + 0.5f * (node->totr.xmax - node->totr.xmin); - td->center[1] = node->locy - 0.5f * (node->totr.ymax - node->totr.ymin); /* node height is used negative */ + td->center[0] = locxy[0]; + td->center[1] = locxy[1]; td->center[2] = 0.0f; memset(td->axismtx, 0, sizeof(td->axismtx)); @@ -5555,37 +5575,53 @@ static void NodeToTransData(TransData *td, TransData2D *td2d, bNode *node) unit_m3(td->mtx); unit_m3(td->smtx); + sub_v2_v2v2(td2d->ih1, &node->locx, locxy); + td->extra = node; } -static void createTransNodeData(bContext *C, TransInfo *t) +static int is_node_parent_select(bNode *node) +{ + while ((node = node->parent)) { + if (node->flag & NODE_TRANSFORM) { + return TRUE; + } + } + return FALSE; +} + +static void createTransNodeData(bContext *UNUSED(C), TransInfo *t) { TransData *td; TransData2D *td2d; SpaceNode *snode = t->sa->spacedata.first; bNode *node; + t->total = 0; + if (!snode->edittree) { - t->total = 0; return; } /* set transform flags on nodes */ for (node = snode->edittree->nodes.first; node; node = node->next) { - if ((node->flag & NODE_SELECT) || (node->parent && (node->parent->flag & NODE_TRANSFORM))) + if (node->flag & NODE_SELECT && is_node_parent_select(node) == FALSE) { node->flag |= NODE_TRANSFORM; - else + t->total++; + } + else { node->flag &= ~NODE_TRANSFORM; + } } - t->total = CTX_DATA_COUNT(C, selected_nodes); - td = t->data = MEM_callocN(t->total * sizeof(TransData), "TransNode TransData"); td2d = t->data2d = MEM_callocN(t->total * sizeof(TransData2D), "TransNode TransData2D"); - CTX_DATA_BEGIN(C, bNode *, selnode, selected_nodes) - NodeToTransData(td++, td2d++, selnode); - CTX_DATA_END + for (node = snode->edittree->nodes.first; node; node = node->next) { + if (node->flag & NODE_TRANSFORM) { + NodeToTransData(td++, td2d++, node); + } + } } /* *** CLIP EDITOR *** */ diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c index ff18b23dc91..8e73fb8b8cb 100644 --- a/source/blender/editors/transform/transform_generics.c +++ b/source/blender/editors/transform/transform_generics.c @@ -620,7 +620,10 @@ static void recalcData_mask_common(TransInfo *t) /* helper for recalcData() - for Image Editor transforms */ static void recalcData_image(TransInfo *t) { - if (t->obedit && t->obedit->type == OB_MESH) { + if (t->options & CTX_MASK) { + recalcData_mask_common(t); + } + else if (t->obedit && t->obedit->type == OB_MESH) { SpaceImage *sima = t->sa->spacedata.first; flushTransUVs(t); @@ -629,9 +632,6 @@ static void recalcData_image(TransInfo *t) DAG_id_tag_update(t->obedit->data, 0); } - else if (t->options & CTX_MASK) { - recalcData_mask_common(t); - } } /* helper for recalcData() - for Movie Clip transforms */ @@ -923,7 +923,7 @@ void recalcData(TransInfo *t) } } -void drawLine(TransInfo *t, float *center, float *dir, char axis, short options) +void drawLine(TransInfo *t, const float center[3], const float dir[3], char axis, short options) { float v1[3], v2[3], v3[3]; unsigned char col[3], col2[3]; @@ -1017,15 +1017,10 @@ int initTransInfo(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event) t->total = 0; t->val = 0.0f; - - t->vec[0] = - t->vec[1] = - t->vec[2] = 0.0f; - t->center[0] = - t->center[1] = - t->center[2] = 0.0f; - + zero_v3(t->vec); + zero_v3(t->center); + unit_m3(t->mat); /* if there's an event, we're modal */ @@ -1113,7 +1108,7 @@ int initTransInfo(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event) t->view = &ar->v2d; t->around = sima->around; - if (t->obedit) { + if (ED_space_image_show_uvedit(sima, t->obedit)) { /* UV transform */ } else if (sima->mode == SI_MODE_MASK) { @@ -1445,7 +1440,12 @@ void calculateCenterCursor2D(TransInfo *t) if (t->spacetype == SPACE_IMAGE) { SpaceImage *sima = (SpaceImage *)t->sa->spacedata.first; /* only space supported right now but may change */ - ED_space_image_get_uv_aspect(sima, &aspx, &aspy); + if (t->options & CTX_MASK) { + ED_space_image_get_aspect(sima, &aspx, &aspy); + } + else { + ED_space_image_get_uv_aspect(sima, &aspx, &aspy); + } cursor = sima->cursor; } diff --git a/source/blender/editors/transform/transform_manipulator.c b/source/blender/editors/transform/transform_manipulator.c index 31250e3a50c..a89ba06c1af 100644 --- a/source/blender/editors/transform/transform_manipulator.c +++ b/source/blender/editors/transform/transform_manipulator.c @@ -855,7 +855,7 @@ static void draw_manipulator_rotate(View3D *v3d, RegionView3D *rv3d, int moving, float size, unitmat[4][4]; float cywid = 0.33f * 0.01f * (float)U.tw_handlesize; float cusize = cywid * 0.65f; - int arcs = (G.rt != 2); + int arcs = (G.debug_value != 2); int colcode; int ortho; @@ -1517,7 +1517,7 @@ void BIF_draw_manipulator(const bContext *C) glEnable(GL_BLEND); if (v3d->twtype & V3D_MANIP_ROTATE) { - if (G.rt == 3) { + if (G.debug_value == 3) { if (G.moving) draw_manipulator_rotate_cyl(v3d, rv3d, 1, drawflags, v3d->twtype, MAN_MOVECOL); else draw_manipulator_rotate_cyl(v3d, rv3d, 0, drawflags, v3d->twtype, MAN_RGB); } @@ -1561,7 +1561,7 @@ static int manipulator_selectbuf(ScrArea *sa, ARegion *ar, const int mval[2], fl /* do the drawing */ if (v3d->twtype & V3D_MANIP_ROTATE) { - if (G.rt == 3) draw_manipulator_rotate_cyl(v3d, rv3d, 0, MAN_ROT_C & rv3d->twdrawflag, v3d->twtype, MAN_RGB); + if (G.debug_value == 3) draw_manipulator_rotate_cyl(v3d, rv3d, 0, MAN_ROT_C & rv3d->twdrawflag, v3d->twtype, MAN_RGB); else draw_manipulator_rotate(v3d, rv3d, 0, MAN_ROT_C & rv3d->twdrawflag, v3d->twtype); } if (v3d->twtype & V3D_MANIP_SCALE) diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c index 278acb72511..fcb857be4e0 100644 --- a/source/blender/editors/transform/transform_snap.c +++ b/source/blender/editors/transform/transform_snap.c @@ -2135,7 +2135,12 @@ static void applyGrid(TransInfo *t, float *val, int max_index, float fac[3], Gea /* evil hack - snapping needs to be adapted for image aspect ratio */ if ((t->spacetype == SPACE_IMAGE) && (t->mode == TFM_TRANSLATION)) { - ED_space_image_get_uv_aspect(t->sa->spacedata.first, asp, asp + 1); + if (t->options & CTX_MASK) { + ED_space_image_get_aspect(t->sa->spacedata.first, asp, asp + 1); + } + else { + ED_space_image_get_uv_aspect(t->sa->spacedata.first, asp, asp + 1); + } } for (i = 0; i <= max_index; i++) { diff --git a/source/blender/editors/uvedit/uvedit_ops.c b/source/blender/editors/uvedit/uvedit_ops.c index 0e129cb4dcb..38fd3fe5c68 100644 --- a/source/blender/editors/uvedit/uvedit_ops.c +++ b/source/blender/editors/uvedit/uvedit_ops.c @@ -165,6 +165,8 @@ void ED_object_assign_active_image(Main *bmain, Object *ob, int mat_nr, Image *i /************************* assign image ************************/ +//#define USE_SWITCH_ASPECT + void ED_uvedit_assign_image(Main *bmain, Scene *scene, Object *obedit, Image *ima, Image *previma) { BMEditMesh *em; @@ -196,6 +198,7 @@ void ED_uvedit_assign_image(Main *bmain, Scene *scene, Object *obedit, Image *im } else { /* old shading system, assign image to selected faces */ +#ifdef USE_SWITCH_ASPECT float prev_aspect[2], fprev_aspect; float aspect[2], faspect; @@ -204,6 +207,7 @@ void ED_uvedit_assign_image(Main *bmain, Scene *scene, Object *obedit, Image *im fprev_aspect = prev_aspect[0]/prev_aspect[1]; faspect = aspect[0]/aspect[1]; +#endif /* ensure we have a uv map */ if (!CustomData_has_layer(&em->bm->pdata, CD_MTEXPOLY)) { @@ -223,8 +227,12 @@ void ED_uvedit_assign_image(Main *bmain, Scene *scene, Object *obedit, Image *im if (ima->id.us == 0) id_us_plus(&ima->id); else id_lib_extern(&ima->id); +#ifdef USE_SWITCH_ASPECT /* we also need to correct the aspect of uvs */ - if(tf->unwrap & TF_CORRECT_ASPECT) { + if (scene->toolsettings->uvcalc_flag & UVCALC_NO_ASPECT_CORRECT) { + /* do nothing */ + } + else { BMIter liter; BMLoop *l; @@ -235,6 +243,7 @@ void ED_uvedit_assign_image(Main *bmain, Scene *scene, Object *obedit, Image *im luv->uv[0] /= faspect; } } +#endif } else { tf->tpage = NULL; @@ -2209,6 +2218,88 @@ static void UV_OT_select_linked_pick(wmOperatorType *ot) "Location", "Mouse location in normalized coordinates, 0.0 to 1.0 is within the image bounds", -100.0f, 100.0f); } +/* note: this is based on similar use case to MESH_OT_split(), which has a similar effect + * but in this case they are not joined to begin with (only having the behavior of being joined) + * so its best to call this select_split() instead of just split(), but assigned to the same key + * as MESH_OT_split - Campbell */ +static int select_split_exec(bContext *C, wmOperator *op) +{ + Scene *scene = CTX_data_scene(C); + ToolSettings *ts = scene->toolsettings; + Image *ima = CTX_data_edit_image(C); + Object *obedit = CTX_data_edit_object(C); + BMesh *bm = BMEdit_FromObject(obedit)->bm; + + BMFace *efa; + BMLoop *l; + BMIter iter, liter; + MTexPoly *tf; + MLoopUV *luv; + short change = FALSE; + + if (ts->uv_flag & UV_SYNC_SELECTION) { + BKE_report(op->reports, RPT_ERROR, "Can't split selection when sync selection is enabled"); + return OPERATOR_CANCELLED; + } + + + BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) { + int is_sel = FALSE; + int is_unsel = FALSE; + tf = CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_MTEXPOLY); + + if (!uvedit_face_visible_test(scene, ima, efa, tf)) + continue; + + /* are we all selected? */ + BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { + luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); + + if (luv->flag & MLOOPUV_VERTSEL) { + is_sel = TRUE; + } + else { + is_unsel = TRUE; + } + + /* we have mixed selection, bail out */ + if (is_sel && is_unsel) { + break; + } + } + + if (is_sel && is_unsel) { + BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { + luv = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MLOOPUV); + luv->flag &= ~MLOOPUV_VERTSEL; + } + + change = TRUE; + } + } + + if (change) { + return OPERATOR_FINISHED; + } + else { + return OPERATOR_CANCELLED; + } +} + + +static void UV_OT_select_split(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Select Split"; + ot->description = "Select only entirely selected faces"; + ot->idname = "UV_OT_select_split"; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + /* api callbacks */ + ot->exec = select_split_exec; + ot->poll = ED_operator_uvedit; /* requires space image */; +} + /* ******************** unlink selection operator **************** */ static int unlink_selection_exec(bContext *C, wmOperator *op) @@ -2444,10 +2535,7 @@ static int border_select_exec(bContext *C, wmOperator *op) int change, pinned, select, faces, extend; /* get rectangle from operator */ - rect.xmin = RNA_int_get(op->ptr, "xmin"); - rect.ymin = RNA_int_get(op->ptr, "ymin"); - rect.xmax = RNA_int_get(op->ptr, "xmax"); - rect.ymax = RNA_int_get(op->ptr, "ymax"); + WM_operator_properties_border_to_rcti(op, &rect); UI_view2d_region_to_view(&ar->v2d, rect.xmin, rect.ymin, &rectf.xmin, &rectf.ymin); UI_view2d_region_to_view(&ar->v2d, rect.xmax, rect.ymax, &rectf.xmax, &rectf.ymax); @@ -3674,6 +3762,7 @@ void ED_operatortypes_uvedit(void) WM_operatortype_append(UV_OT_select_loop); WM_operatortype_append(UV_OT_select_linked); WM_operatortype_append(UV_OT_select_linked_pick); + WM_operatortype_append(UV_OT_select_split); WM_operatortype_append(UV_OT_unlink_selected); WM_operatortype_append(UV_OT_select_pinned); WM_operatortype_append(UV_OT_select_border); @@ -3729,6 +3818,7 @@ void ED_keymap_uvedit(wmKeyConfig *keyconf) RNA_boolean_set(WM_keymap_add_item(keymap, "UV_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "extend", TRUE); RNA_boolean_set(WM_keymap_add_item(keymap, "UV_OT_select_loop", SELECTMOUSE, KM_PRESS, KM_ALT, 0)->ptr, "extend", FALSE); RNA_boolean_set(WM_keymap_add_item(keymap, "UV_OT_select_loop", SELECTMOUSE, KM_PRESS, KM_SHIFT | KM_ALT, 0)->ptr, "extend", TRUE); + WM_keymap_add_item(keymap, "UV_OT_select_split", YKEY, KM_PRESS, 0, 0); /* border/circle selection */ kmi = WM_keymap_add_item(keymap, "UV_OT_select_border", BKEY, KM_PRESS, 0, 0); @@ -3788,19 +3878,6 @@ void ED_keymap_uvedit(wmKeyConfig *keyconf) WM_keymap_add_menu(keymap, "IMAGE_MT_uvs_snap", SKEY, KM_PRESS, KM_SHIFT, 0); WM_keymap_add_menu(keymap, "IMAGE_MT_uvs_select_mode", TABKEY, KM_PRESS, KM_CTRL, 0); - /* pivot */ - kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", COMMAKEY, KM_PRESS, 0, 0); - RNA_string_set(kmi->ptr, "data_path", "space_data.uv_editor.pivot_point"); - RNA_string_set(kmi->ptr, "value", "CENTER"); - - kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", COMMAKEY, KM_PRESS, KM_CTRL, 0); - RNA_string_set(kmi->ptr, "data_path", "space_data.uv_editor.pivot_point"); - RNA_string_set(kmi->ptr, "value", "MEDIAN"); - - kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", PERIODKEY, KM_PRESS, 0, 0); - RNA_string_set(kmi->ptr, "data_path", "space_data.uv_editor.pivot_point"); - RNA_string_set(kmi->ptr, "value", "CURSOR"); - ED_keymap_proportional_cycle(keyconf, keymap); ED_keymap_proportional_editmode(keyconf, keymap, FALSE); diff --git a/source/blender/editors/uvedit/uvedit_parametrizer.c b/source/blender/editors/uvedit/uvedit_parametrizer.c index c6ded2a91cf..2161d4989db 100644 --- a/source/blender/editors/uvedit/uvedit_parametrizer.c +++ b/source/blender/editors/uvedit/uvedit_parametrizer.c @@ -145,8 +145,6 @@ typedef struct PFace { struct PEdge *edge; unsigned char flag; - short *unwrap_flag; - } PFace; enum PVertFlag { @@ -236,9 +234,6 @@ typedef struct PHandle { char do_aspect; } PHandle; -/* duplicate, to avoid including DNA_mesh_types.h */ -#define TF_CORRECT_ASPECT 256 - /* PHash * - special purpose hash that keeps all its elements in a single linked list. * - after construction, this hash is thrown away, and the list remains. @@ -650,7 +645,6 @@ static void p_vert_load_pin_select_uvs(PHandle *handle, PVert *v) static void p_flush_uvs(PHandle *handle, PChart *chart) { PEdge *e; - PFace *f; for (e = chart->edges; e; e = e->nextlink) { if (e->orig_uv) { @@ -658,16 +652,6 @@ static void p_flush_uvs(PHandle *handle, PChart *chart) e->orig_uv[1] = e->vert->uv[1] / handle->aspy; } } - - for (f = chart->faces; f; f = f->nextlink) { - if(f->unwrap_flag) { - if (handle->do_aspect) { - *f->unwrap_flag |= TF_CORRECT_ASPECT; - } else { - *f->unwrap_flag &= ~TF_CORRECT_ASPECT; - } - } - } } static void p_flush_uvs_blend(PHandle *handle, PChart *chart, float blend) @@ -1057,7 +1041,6 @@ static PFace *p_face_add(PHandle *handle) /* allocate */ f = (PFace *)BLI_memarena_alloc(handle->arena, sizeof *f); f->flag = 0; // init ! - f->unwrap_flag = NULL; e1 = (PEdge *)BLI_memarena_alloc(handle->arena, sizeof *e1); e2 = (PEdge *)BLI_memarena_alloc(handle->arena, sizeof *e2); @@ -1084,7 +1067,7 @@ static PFace *p_face_add(PHandle *handle) static PFace *p_face_add_construct(PHandle *handle, ParamKey key, ParamKey *vkeys, float *co[3], float *uv[3], int i1, int i2, int i3, - ParamBool *pin, ParamBool *select, short *unwrap_flag) + ParamBool *pin, ParamBool *select) { PFace *f = p_face_add(handle); PEdge *e1 = f->edge, *e2 = e1->next, *e3 = e2->next; @@ -1111,7 +1094,6 @@ static PFace *p_face_add_construct(PHandle *handle, ParamKey key, ParamKey *vkey /* insert into hash */ f->u.key = key; - f->unwrap_flag = unwrap_flag; phash_insert(handle->hash_faces, (PHashLink *)f); e1->u.key = PHASH_edge(vkeys[i1], vkeys[i2]); @@ -4150,7 +4132,7 @@ void param_delete(ParamHandle *handle) void param_face_add(ParamHandle *handle, ParamKey key, int nverts, ParamKey *vkeys, float **co, float **uv, - ParamBool *pin, ParamBool *select, short *unwrap_flag) + ParamBool *pin, ParamBool *select) { PHandle *phandle = (PHandle *)handle; @@ -4160,16 +4142,16 @@ void param_face_add(ParamHandle *handle, ParamKey key, int nverts, if (nverts == 4) { if (p_quad_split_direction(phandle, co, vkeys)) { - p_face_add_construct(phandle, key, vkeys, co, uv, 0, 1, 2, pin, select, unwrap_flag); - p_face_add_construct(phandle, key, vkeys, co, uv, 0, 2, 3, pin, select, unwrap_flag); + p_face_add_construct(phandle, key, vkeys, co, uv, 0, 1, 2, pin, select); + p_face_add_construct(phandle, key, vkeys, co, uv, 0, 2, 3, pin, select); } else { - p_face_add_construct(phandle, key, vkeys, co, uv, 0, 1, 3, pin, select, unwrap_flag); - p_face_add_construct(phandle, key, vkeys, co, uv, 1, 2, 3, pin, select, unwrap_flag); + p_face_add_construct(phandle, key, vkeys, co, uv, 0, 1, 3, pin, select); + p_face_add_construct(phandle, key, vkeys, co, uv, 1, 2, 3, pin, select); } } else if (!p_face_exists(phandle, vkeys, 0, 1, 2)) { - p_face_add_construct(phandle, key, vkeys, co, uv, 0, 1, 2, pin, select, unwrap_flag); + p_face_add_construct(phandle, key, vkeys, co, uv, 0, 1, 2, pin, select); } } diff --git a/source/blender/editors/uvedit/uvedit_parametrizer.h b/source/blender/editors/uvedit/uvedit_parametrizer.h index 9a2fea0d7f9..4c23d49428b 100644 --- a/source/blender/editors/uvedit/uvedit_parametrizer.h +++ b/source/blender/editors/uvedit/uvedit_parametrizer.h @@ -56,16 +56,16 @@ ParamHandle *param_construct_begin(void); void param_aspect_ratio(ParamHandle *handle, float aspx, float aspy); void param_face_add(ParamHandle *handle, - ParamKey key, - int nverts, - ParamKey *vkeys, - float **co, - float **uv, - ParamBool *pin, - ParamBool *select, short *unwrap_flag); + ParamKey key, + int nverts, + ParamKey *vkeys, + float **co, + float **uv, + ParamBool *pin, + ParamBool *select); void param_edge_set_seam(ParamHandle *handle, - ParamKey *vkeys); + ParamKey *vkeys); void param_construct_end(ParamHandle *handle, ParamBool fill, ParamBool impl); void param_delete(ParamHandle *chart); diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c b/source/blender/editors/uvedit/uvedit_unwrap_ops.c index 4b6c0ef0e7b..682b35072f6 100644 --- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c +++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c @@ -213,7 +213,6 @@ static ParamHandle *construct_param_handle(Scene *scene, BMEditMesh *em, BLI_srand(0); BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { - MTexPoly *tf; ScanFillVert *sf_vert, *sf_vert_last, *sf_vert_first; ScanFillFace *sf_tri; ParamKey key, vkeys[4]; @@ -257,7 +256,7 @@ static ParamHandle *construct_param_handle(Scene *scene, BMEditMesh *em, i++; } - param_face_add(handle, key, i, vkeys, co, uv, pin, select, &tf->unwrap); + param_face_add(handle, key, i, vkeys, co, uv, pin, select); } else { /* ngon - scanfill time! */ @@ -302,7 +301,7 @@ static ParamHandle *construct_param_handle(Scene *scene, BMEditMesh *em, select[i] = uvedit_uv_select_test(em, scene, ls[i]) != 0; } - param_face_add(handle, key, 3, vkeys, co, uv, pin, select, &tf->unwrap); + param_face_add(handle, key, 3, vkeys, co, uv, pin, select); } BLI_scanfill_end(&sf_ctx); @@ -446,7 +445,6 @@ static ParamHandle *construct_param_handle_subsurfed(Scene *scene, BMEditMesh *e float *co[4]; float *uv[4]; BMFace *origFace = faceMap[i]; - MTexPoly *tf; face = subsurfedFaces + i; @@ -459,8 +457,6 @@ static ParamHandle *construct_param_handle_subsurfed(Scene *scene, BMEditMesh *e continue; } - tf = CustomData_bmesh_get(&em->bm->pdata, origFace->head.data, CD_MTEXPOLY); - /* We will not check for v4 here. Subsurfed mfaces always have 4 vertices. */ key = (ParamKey)face; vkeys[0] = (ParamKey)face->v1; @@ -480,7 +476,7 @@ static ParamHandle *construct_param_handle_subsurfed(Scene *scene, BMEditMesh *e texface_from_original_index(origFace, origVertIndices[face->v3], &uv[2], &pin[2], &select[2], scene, em); texface_from_original_index(origFace, origVertIndices[face->v4], &uv[3], &pin[3], &select[3], scene, em); - param_face_add(handle, key, 4, vkeys, co, uv, pin, select, &tf->unwrap); + param_face_add(handle, key, 4, vkeys, co, uv, pin, select); } /* these are calculated from original mesh too */ diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c index 0ad271e90bd..3c2d3e11197 100644 --- a/source/blender/gpu/intern/gpu_draw.c +++ b/source/blender/gpu/intern/gpu_draw.c @@ -678,7 +678,8 @@ void GPU_create_gl_tex(unsigned int *bind, unsigned int *pix, float * frect, int glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, rectw, recth, 0, GL_RGBA, GL_UNSIGNED_BYTE, pix); glGenerateMipmapEXT(GL_TEXTURE_2D); - } else { + } + else { if (use_high_bit_depth) gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA16, rectw, recth, GL_RGBA, GL_FLOAT, frect); else diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h index 1a68d3c1f09..8d7c4bd55bf 100644 --- a/source/blender/imbuf/IMB_imbuf.h +++ b/source/blender/imbuf/IMB_imbuf.h @@ -498,5 +498,11 @@ void imb_freemipmapImBuf(struct ImBuf *ibuf); short imb_addtilesImBuf(struct ImBuf *ibuf); void imb_freetilesImBuf(struct ImBuf *ibuf); +/* threaded processors */ +void IMB_processor_apply_threaded(int buffer_lines, int handle_size, void *init_customdata, + void (init_handle) (void *handle, int start_line, int tot_line, + void *customdata), + void *(do_thread) (void *)); + #endif diff --git a/source/blender/imbuf/IMB_moviecache.h b/source/blender/imbuf/IMB_moviecache.h index 5e52563a89e..00d3368ae5f 100644 --- a/source/blender/imbuf/IMB_moviecache.h +++ b/source/blender/imbuf/IMB_moviecache.h @@ -60,6 +60,9 @@ void IMB_moviecache_set_priority_callback(struct MovieCache *cache, MovieCacheGe void IMB_moviecache_put(struct MovieCache *cache, void *userkey, struct ImBuf *ibuf); struct ImBuf* IMB_moviecache_get(struct MovieCache *cache, void *userkey); void IMB_moviecache_free(struct MovieCache *cache); + +void IMB_moviecache_cleanup(struct MovieCache *cache, int (cleanup_check_cb) (void *userkey, void *userdata), void *userdata); + void IMB_moviecache_get_cache_segments(struct MovieCache *cache, int proxy, int render_flags, int *totseg_r, int **points_r); #endif diff --git a/source/blender/imbuf/intern/IMB_indexer.h b/source/blender/imbuf/intern/IMB_indexer.h index dc16b4d7e36..16d10a5c41c 100644 --- a/source/blender/imbuf/intern/IMB_indexer.h +++ b/source/blender/imbuf/intern/IMB_indexer.h @@ -63,7 +63,7 @@ struct anim_index { char name[1024]; int num_entries; - struct anim_index_entry * entries; + struct anim_index_entry *entries; }; struct anim_index_builder; @@ -77,9 +77,9 @@ typedef struct anim_index_builder { void (*delete_priv_data)(struct anim_index_builder * idx); void (*proc_frame)(struct anim_index_builder * idx, - unsigned char * buffer, + unsigned char *buffer, int data_size, - struct anim_index_entry * entry); + struct anim_index_entry *entry); } anim_index_builder; anim_index_builder * IMB_index_builder_create(const char * name); @@ -99,15 +99,15 @@ void IMB_index_builder_proc_frame( void IMB_index_builder_finish(anim_index_builder * fp, int rollback); -struct anim_index * IMB_indexer_open(const char * name); +struct anim_index *IMB_indexer_open(const char * name); unsigned long long IMB_indexer_get_seek_pos( - struct anim_index * idx, int frameno_index); + struct anim_index *idx, int frameno_index); unsigned long long IMB_indexer_get_seek_pos_dts( - struct anim_index * idx, int frameno_index); + struct anim_index *idx, int frameno_index); int IMB_indexer_get_frame_index(struct anim_index * idx, int frameno); -unsigned long long IMB_indexer_get_pts(struct anim_index * idx, - int frame_index); +unsigned long long IMB_indexer_get_pts(struct anim_index *idx, + int frame_index); int IMB_indexer_get_duration(struct anim_index * idx); int IMB_indexer_can_scan(struct anim_index * idx, @@ -118,12 +118,12 @@ void IMB_indexer_close(struct anim_index * idx); void IMB_free_indices(struct anim * anim); int IMB_anim_index_get_frame_index( - struct anim * anim, IMB_Timecode_Type tc, int position); + struct anim *anim, IMB_Timecode_Type tc, int position); -struct anim * IMB_anim_open_proxy( - struct anim * anim, IMB_Proxy_Size preview_size); +struct anim *IMB_anim_open_proxy( + struct anim *anim, IMB_Proxy_Size preview_size); struct anim_index * IMB_anim_open_index( - struct anim * anim, IMB_Timecode_Type tc); + struct anim *anim, IMB_Timecode_Type tc); int IMB_proxy_size_to_array_index(IMB_Proxy_Size pr_size); int IMB_timecode_to_array_index(IMB_Timecode_Type tc); diff --git a/source/blender/imbuf/intern/anim_movie.c b/source/blender/imbuf/intern/anim_movie.c index a27aae815da..9367511522d 100644 --- a/source/blender/imbuf/intern/anim_movie.c +++ b/source/blender/imbuf/intern/anim_movie.c @@ -394,7 +394,9 @@ static ImBuf *avi_fetchibuf(struct anim *anim, int position) int *tmp; int y; - if (anim == NULL) return (NULL); + if (anim == NULL) { + return NULL; + } #if defined(_WIN32) && !defined(FREE_WINDOWS) if (anim->avistreams) { @@ -418,7 +420,7 @@ static ImBuf *avi_fetchibuf(struct anim *anim, int position) AVI_get_stream(anim->avi, AVIST_VIDEO, 0)); if (tmp == NULL) { - printf("Error reading frame from AVI"); + printf("Error reading frame from AVI: '%s'\n", anim->name); IMB_freeImBuf(ibuf); return NULL; } diff --git a/source/blender/imbuf/intern/filter.c b/source/blender/imbuf/intern/filter.c index 7804ee1fdf1..678b2908b96 100644 --- a/source/blender/imbuf/intern/filter.c +++ b/source/blender/imbuf/intern/filter.c @@ -226,24 +226,24 @@ void IMB_filterN(ImBuf *out, ImBuf *in) for (x = 0; x < rowlen; x++) { if (x == 0) { r11 = row1; - r21 = row1; - r31 = row1; + r21 = row2; + r31 = row3; } else { r11 = row1 - 4; - r21 = row1 - 4; - r31 = row1 - 4; + r21 = row2 - 4; + r31 = row3 - 4; } if (x == rowlen - 1) { r13 = row1; - r23 = row1; - r33 = row1; + r23 = row2; + r33 = row3; } else { r13 = row1 + 4; - r23 = row1 + 4; - r33 = row1 + 4; + r23 = row2 + 4; + r33 = row3 + 4; } cp[0] = (r11[0] + 2 * row1[0] + r13[0] + 2 * r21[0] + 4 * row2[0] + 2 * r23[0] + r31[0] + 2 * row3[0] + r33[0]) >> 4; diff --git a/source/blender/imbuf/intern/imageprocess.c b/source/blender/imbuf/intern/imageprocess.c index 5c389925274..3fd06a7c34d 100644 --- a/source/blender/imbuf/intern/imageprocess.c +++ b/source/blender/imbuf/intern/imageprocess.c @@ -38,7 +38,11 @@ #include <stdlib.h> +#include "MEM_guardedalloc.h" + #include "BLI_utildefines.h" +#include "BLI_threads.h" +#include "BLI_listbase.h" #include "IMB_imbuf_types.h" #include "IMB_imbuf.h" @@ -88,7 +92,7 @@ static void pixel_from_buffer(struct ImBuf *ibuf, unsigned char **outI, float ** *outI = (unsigned char *)ibuf->rect + offset; if (ibuf->rect_float) - *outF = (float *)ibuf->rect_float + offset; + *outF = ibuf->rect_float + offset; } /************************************************************************** @@ -258,16 +262,16 @@ void bilinear_interpolation_color(struct ImBuf *in, unsigned char *outI, float * if (outF) { /* sample including outside of edges of image */ if (x1 < 0 || y1 < 0) row1 = empty; - else row1 = (float *)in->rect_float + in->x * y1 * 4 + 4 * x1; + else row1 = in->rect_float + in->x * y1 * 4 + 4 * x1; if (x1 < 0 || y2 > in->y - 1) row2 = empty; - else row2 = (float *)in->rect_float + in->x * y2 * 4 + 4 * x1; + else row2 = in->rect_float + in->x * y2 * 4 + 4 * x1; if (x2 > in->x - 1 || y1 < 0) row3 = empty; - else row3 = (float *)in->rect_float + in->x * y1 * 4 + 4 * x2; + else row3 = in->rect_float + in->x * y1 * 4 + 4 * x2; if (x2 > in->x - 1 || y2 > in->y - 1) row4 = empty; - else row4 = (float *)in->rect_float + in->x * y2 * 4 + 4 * x2; + else row4 = in->rect_float + in->x * y2 * 4 + 4 * x2; a = u - floorf(u); b = v - floorf(v); @@ -338,10 +342,10 @@ void bilinear_interpolation_color_wrap(struct ImBuf *in, unsigned char *outI, fl if (outF) { /* sample including outside of edges of image */ - row1 = (float *)in->rect_float + in->x * y1 * 4 + 4 * x1; - row2 = (float *)in->rect_float + in->x * y2 * 4 + 4 * x1; - row3 = (float *)in->rect_float + in->x * y1 * 4 + 4 * x2; - row4 = (float *)in->rect_float + in->x * y2 * 4 + 4 * x2; + row1 = in->rect_float + in->x * y1 * 4 + 4 * x1; + row2 = in->rect_float + in->x * y2 * 4 + 4 * x1; + row3 = in->rect_float + in->x * y1 * 4 + 4 * x2; + row4 = in->rect_float + in->x * y2 * 4 + 4 * x2; a = u - floorf(u); b = v - floorf(v); @@ -446,3 +450,49 @@ void neareast_interpolation(ImBuf *in, ImBuf *out, float x, float y, int xout, i neareast_interpolation_color(in, outI, outF, x, y); } + +/*********************** Threaded image processing *************************/ + +void IMB_processor_apply_threaded(int buffer_lines, int handle_size, void *init_customdata, + void (init_handle) (void *handle, int start_line, int tot_line, + void *customdata), + void *(do_thread) (void *)) +{ + void *handles; + ListBase threads; + + int i, tot_thread = BLI_system_thread_count(); + int start_line, tot_line; + + handles = MEM_callocN(handle_size * tot_thread, "processor apply threaded handles"); + + if (tot_thread > 1) + BLI_init_threads(&threads, do_thread, tot_thread); + + start_line = 0; + tot_line = ((float)(buffer_lines / tot_thread)) + 0.5f; + + for (i = 0; i < tot_thread; i++) { + int cur_tot_line; + void *handle = ((char *) handles) + handle_size * i; + + if (i < tot_thread - 1) + cur_tot_line = tot_line; + else + cur_tot_line = buffer_lines - start_line; + + init_handle(handle, start_line, cur_tot_line, init_customdata); + + if (tot_thread > 1) + BLI_insert_thread(&threads, handle); + + start_line += tot_line; + } + + if (tot_thread > 1) + BLI_end_threads(&threads); + else + do_thread(handles); + + MEM_freeN(handles); +} diff --git a/source/blender/imbuf/intern/jpeg.c b/source/blender/imbuf/intern/jpeg.c index aea120cd841..d49080d8741 100644 --- a/source/blender/imbuf/intern/jpeg.c +++ b/source/blender/imbuf/intern/jpeg.c @@ -200,7 +200,7 @@ static void memory_source(j_decompress_ptr cinfo, unsigned char *buffer, size_t #define MAKESTMT(stuff) do { stuff } while (0) #define INPUT_VARS(cinfo) \ - struct jpeg_source_mgr * datasrc = (cinfo)->src; \ + struct jpeg_source_mgr *datasrc = (cinfo)->src; \ const JOCTET * next_input_byte = datasrc->next_input_byte; \ size_t bytes_in_buffer = datasrc->bytes_in_buffer diff --git a/source/blender/imbuf/intern/moviecache.c b/source/blender/imbuf/intern/moviecache.c index 671c79a0659..71eae6c6c21 100644 --- a/source/blender/imbuf/intern/moviecache.c +++ b/source/blender/imbuf/intern/moviecache.c @@ -393,6 +393,32 @@ void IMB_moviecache_free(MovieCache *cache) MEM_freeN(cache); } +void IMB_moviecache_cleanup(MovieCache *cache, int (cleanup_check_cb) (void *userkey, void *userdata), void *userdata) +{ + GHashIterator *iter; + + iter = BLI_ghashIterator_new(cache->hash); + while (!BLI_ghashIterator_isDone(iter)) { + MovieCacheKey *key = BLI_ghashIterator_getKey(iter); + int remove; + + BLI_ghashIterator_step(iter); + + remove = cleanup_check_cb(key->userkey, userdata); + + if (remove) { + MovieCacheItem *item = BLI_ghashIterator_getValue(iter); + (void) item; /* silence unused variable when not using debug */ + + PRINT("%s: cache '%s' remove item %p\n", __func__, cache->name, item); + + BLI_ghash_remove(cache->hash, key, moviecache_keyfree, moviecache_valfree); + } + } + + BLI_ghashIterator_free(iter); +} + /* get segments of cached frames. useful for debugging cache policies */ void IMB_moviecache_get_cache_segments(MovieCache *cache, int proxy, int render_flags, int *totseg_r, int **points_r) { diff --git a/source/blender/imbuf/intern/radiance_hdr.c b/source/blender/imbuf/intern/radiance_hdr.c index 2ba1ebf90b5..4cd50484a64 100644 --- a/source/blender/imbuf/intern/radiance_hdr.c +++ b/source/blender/imbuf/intern/radiance_hdr.c @@ -213,7 +213,7 @@ struct ImBuf *imb_loadhdr(unsigned char *mem, size_t size, int flags) /* read in and decode the actual data */ sline = (RGBE *)MEM_mallocN(sizeof(RGBE) * width, "radhdr_read_tmpscan"); - rect_float = (float *)ibuf->rect_float; + rect_float = ibuf->rect_float; for (y = 0; y < height; y++) { ptr = freadcolrs(sline, ptr, width); diff --git a/source/blender/imbuf/intern/scaling.c b/source/blender/imbuf/intern/scaling.c index 810cb88c06e..ea1d483090c 100644 --- a/source/blender/imbuf/intern/scaling.c +++ b/source/blender/imbuf/intern/scaling.c @@ -295,9 +295,7 @@ struct ImBuf *IMB_double_y(struct ImBuf *ibuf1) /* result in ibuf2, scaling should be done correctly */ void imb_onehalf_no_alloc(struct ImBuf *ibuf2, struct ImBuf *ibuf1) { - uchar *p1, *p2 = NULL, *dest; - float *p1f, *destf, *p2f = NULL; - int x, y; + int x, y; const short do_rect = (ibuf1->rect != NULL); const short do_float = (ibuf1->rect_float != NULL) && (ibuf2->rect_float != NULL); @@ -305,16 +303,14 @@ void imb_onehalf_no_alloc(struct ImBuf *ibuf2, struct ImBuf *ibuf1) imb_addrectImBuf(ibuf2); } - p1f = ibuf1->rect_float; - destf = ibuf2->rect_float; - p1 = (uchar *) ibuf1->rect; - dest = (uchar *) ibuf2->rect; - - for (y = ibuf2->y; y > 0; y--) { - if (do_rect) p2 = p1 + (ibuf1->x << 2); - if (do_float) p2f = p1f + (ibuf1->x << 2); - for (x = ibuf2->x; x > 0; x--) { - if (do_rect) { + if (do_rect) { + char *p1, *p2, *dest; + + p1 = (char *) ibuf1->rect; + dest = (char *) ibuf2->rect; + for (y = ibuf2->y; y > 0; y--) { + p2 = p1 + (ibuf1->x << 2); + for (x = ibuf2->x; x > 0; x--) { dest[0] = (p1[0] + p2[0] + p1[4] + p2[4]) >> 2; dest[1] = (p1[1] + p2[1] + p1[5] + p2[5]) >> 2; dest[2] = (p1[2] + p2[2] + p1[6] + p2[6]) >> 2; @@ -323,24 +319,31 @@ void imb_onehalf_no_alloc(struct ImBuf *ibuf2, struct ImBuf *ibuf1) p2 += 8; dest += 4; } - if (do_float) { - destf[0] = 0.25f * (p1f[0] + p2f[0] + p1f[4] + p2f[4]); - destf[1] = 0.25f * (p1f[1] + p2f[1] + p1f[5] + p2f[5]); - destf[2] = 0.25f * (p1f[2] + p2f[2] + p1f[6] + p2f[6]); - destf[3] = 0.25f * (p1f[3] + p2f[3] + p1f[7] + p2f[7]); - p1f += 8; - p2f += 8; - destf += 4; - } - } - if (do_rect) p1 = p2; - if (do_float) p1f = p2f; - if (ibuf1->x & 1) { - if (do_rect) p1 += 4; - if (do_float) p1f += 4; + p1 = p2; + if (ibuf1->x & 1) p1 += 4; } } + if (do_float) { + float *p1f, *p2f, *destf; + + p1f = ibuf1->rect_float; + destf = ibuf2->rect_float; + for (y = ibuf2->y; y > 0; y--) { + p2f = p1f + (ibuf1->x << 2); + for (x = ibuf2->x; x > 0; x--) { + destf[0] = 0.25f * (p1f[0] + p2f[0] + p1f[4] + p2f[4]); + destf[1] = 0.25f * (p1f[1] + p2f[1] + p1f[5] + p2f[5]); + destf[2] = 0.25f * (p1f[2] + p2f[2] + p1f[6] + p2f[6]); + destf[3] = 0.25f * (p1f[3] + p2f[3] + p1f[7] + p2f[7]); + p1f += 8; + p2f += 8; + destf += 4; + } + p1f = p2f; + if (ibuf1->x & 1) p1f += 4; + } + } } ImBuf *IMB_onehalf(struct ImBuf *ibuf1) @@ -1313,7 +1316,7 @@ static ImBuf *scaleupy(struct ImBuf *ibuf, int newy) rect += 2 * skipx; } if (do_float) { - rectf = ((float *)ibuf->rect_float) + 4 * (x - 1); + rectf = ibuf->rect_float + 4 * (x - 1); newrectf = _newrectf + 4 * (x - 1); val_af = rectf[0]; diff --git a/source/blender/makesdna/DNA_constraint_types.h b/source/blender/makesdna/DNA_constraint_types.h index b6036840401..8d953079bdb 100644 --- a/source/blender/makesdna/DNA_constraint_types.h +++ b/source/blender/makesdna/DNA_constraint_types.h @@ -415,7 +415,8 @@ typedef struct bShrinkwrapConstraint { typedef struct bFollowTrackConstraint { struct MovieClip *clip; char track[64]; /* MAX_NAME */ - int flag, pad; + int flag; + int frame_method; char object[64]; /* MAX_NAME */ struct Object *camera; struct Object *depth_ob; @@ -780,6 +781,12 @@ typedef enum eFollowTrack_Flags { FOLLOWTRACK_USE_3D_POSITION = (1<<1) } eFollowTrack_Flags; +typedef enum eFollowTrack_FrameMethod { + FOLLOWTRACK_FRAME_STRETCH = 0, + FOLLOWTRACK_FRAME_FIT = 1, + FOLLOWTRACK_FRAME_CROP = 2 +} eFollowTrack_FrameMethod; + /* CameraSolver Constraint -> flag */ typedef enum eCameraSolver_Flags { CAMERASOLVER_ACTIVECLIP = (1<<0) diff --git a/source/blender/makesdna/DNA_mask_types.h b/source/blender/makesdna/DNA_mask_types.h index e7322263a6b..b34a6c9b12f 100644 --- a/source/blender/makesdna/DNA_mask_types.h +++ b/source/blender/makesdna/DNA_mask_types.h @@ -141,7 +141,8 @@ typedef struct MaskLayer { /* reserve (1 << 0) for SELECT */ enum { MASK_SPLINE_CYCLIC = (1 << 1), - MASK_SPLINE_NOFILL = (1 << 2) + MASK_SPLINE_NOFILL = (1 << 2), + MASK_SPLINE_NOINTERSECT = (1 << 3) }; /* MaskSpline->weight_interp */ diff --git a/source/blender/makesdna/DNA_material_types.h b/source/blender/makesdna/DNA_material_types.h index 6952f1a9da7..1f185731e91 100644 --- a/source/blender/makesdna/DNA_material_types.h +++ b/source/blender/makesdna/DNA_material_types.h @@ -154,7 +154,7 @@ typedef struct Material { struct bNodeTree *nodetree; struct Ipo *ipo DNA_DEPRECATED; /* old animation system, deprecated for 2.5 */ struct Group *group; /* light group */ - struct PreviewImage * preview; + struct PreviewImage *preview; /* dynamic properties */ float friction, fh, reflect; diff --git a/source/blender/makesdna/DNA_meshdata_types.h b/source/blender/makesdna/DNA_meshdata_types.h index c4258c0870e..c3b11fed613 100644 --- a/source/blender/makesdna/DNA_meshdata_types.h +++ b/source/blender/makesdna/DNA_meshdata_types.h @@ -95,7 +95,7 @@ typedef struct MLoop { typedef struct MTexPoly { struct Image *tpage; char flag, transp; - short mode, tile, unwrap; + short mode, tile, pad; } MTexPoly; /* can copy from/to MTexPoly/MTFace */ @@ -106,8 +106,7 @@ typedef struct MTexPoly { (dst)->transp = (src)->transp; \ (dst)->mode = (src)->mode; \ (dst)->tile = (src)->tile; \ - (dst)->unwrap = (src)->unwrap; \ -} +} (void)0 typedef struct MLoopUV { float uv[2]; @@ -370,6 +369,5 @@ typedef struct MVertSkin { #define TF_PIN2 32 #define TF_PIN3 64 #define TF_PIN4 128 -#define TF_CORRECT_ASPECT 256 #endif diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index 731f44d2564..d0c2a5c9925 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -375,6 +375,10 @@ enum { }; enum { + CMP_NODE_INPAINT_SIMPLE = 0 +}; + +enum { CMP_NODEFLAG_MASK_AA = (1 << 0), CMP_NODEFLAG_MASK_NO_FEATHER = (1 << 1), CMP_NODEFLAG_MASK_MOTION_BLUR = (1 << 2), diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index 10939ecbdc4..4c7273b914d 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -293,7 +293,7 @@ typedef struct ImageFormatData { #define R_IMF_IMTYPE_AVIRAW 15 #define R_IMF_IMTYPE_AVIJPEG 16 #define R_IMF_IMTYPE_PNG 17 -#define R_IMF_IMTYPE_AVICODEC 18 +/* #define R_IMF_IMTYPE_AVICODEC 18 */ /* avicodec is nomore */ #define R_IMF_IMTYPE_QUICKTIME 19 #define R_IMF_IMTYPE_BMP 20 #define R_IMF_IMTYPE_RADHDR 21 diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h index b9603e2cdb1..2ac85a0d16e 100644 --- a/source/blender/makesdna/DNA_space_types.h +++ b/source/blender/makesdna/DNA_space_types.h @@ -879,7 +879,7 @@ typedef struct SpaceNode { float xof, yof; /* offset for drawing the backdrop */ float zoom; /* zoom for backdrop */ - float mx, my; /* mousepos for drawing socketless link */ + float cursor[2]; /* mouse pos for drawing socketless link and adding nodes */ struct bNodeTree *nodetree, *edittree; int treetype; /* treetype: as same nodetree->type */ diff --git a/source/blender/makesdna/DNA_texture_types.h b/source/blender/makesdna/DNA_texture_types.h index 5257fb6e2cf..9fdd9216549 100644 --- a/source/blender/makesdna/DNA_texture_types.h +++ b/source/blender/makesdna/DNA_texture_types.h @@ -244,7 +244,7 @@ typedef struct Tex { struct Image *ima; struct ColorBand *coba; struct EnvMap *env; - struct PreviewImage * preview; + struct PreviewImage *preview; struct PointDensity *pd; struct VoxelData *vd; struct OceanTex *ot; diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h index af24cfbad70..cbfc1134679 100644 --- a/source/blender/makesdna/DNA_userdef_types.h +++ b/source/blender/makesdna/DNA_userdef_types.h @@ -483,11 +483,10 @@ extern UserDef U; /* from blenkernel blender.c */ #define USER_TOOLTIPS_PYTHON (1 << 26) /* helper macro for checking frame clamping */ -#define FRAMENUMBER_MIN_CLAMP(cfra) \ - { \ - if ((U.flag & USER_NONEGFRAMES) && (cfra < 0)) \ - cfra = 0; \ - } +#define FRAMENUMBER_MIN_CLAMP(cfra) { \ + if ((U.flag & USER_NONEGFRAMES) && (cfra < 0)) \ + cfra = 0; \ + } (void)0 /* viewzom */ #define USER_ZOOM_CONT 0 @@ -505,13 +504,12 @@ extern UserDef U; /* from blenkernel blender.c */ /*#define USER_FLIPFULLSCREEN (1 << 7)*/ /* deprecated */ #define USER_ALLWINCODECS (1 << 8) #define USER_MENUOPENAUTO (1 << 9) -/*#define USER_PANELPINNED (1 << 10) deprecated */ +#define USER_ZBUF_CURSOR (1 << 10) #define USER_AUTOPERSP (1 << 11) #define USER_LOCKAROUND (1 << 12) #define USER_GLOBALUNDO (1 << 13) #define USER_ORBIT_SELECTION (1 << 14) -// old flag for #define USER_KEYINSERTAVAI (1 << 15) -#define USER_ORBIT_ZBUF (1 << 15) +#define USER_ZBUF_ORBIT (1 << 15) #define USER_HIDE_DOT (1 << 16) #define USER_SHOW_ROTVIEWICON (1 << 17) #define USER_SHOW_VIEWPORTNAME (1 << 18) @@ -522,7 +520,7 @@ extern UserDef U; /* from blenkernel blender.c */ #define USER_MENUFIXEDORDER (1 << 23) #define USER_CONTINUOUS_MOUSE (1 << 24) #define USER_ZOOM_INVERT (1 << 25) -#define USER_ZOOM_HORIZ (1 << 26) /* for CONTINUE and DOLLY zoom */ +#define USER_ZOOM_HORIZ (1 << 26) /* for CONTINUE and DOLLY zoom */ #define USER_SPLASH_DISABLE (1 << 27) #define USER_HIDE_RECENT (1 << 28) #define USER_SHOW_THUMBNAILS (1 << 29) diff --git a/source/blender/makesdna/DNA_vfont_types.h b/source/blender/makesdna/DNA_vfont_types.h index 299a6540f40..3cccfe6a19f 100644 --- a/source/blender/makesdna/DNA_vfont_types.h +++ b/source/blender/makesdna/DNA_vfont_types.h @@ -45,7 +45,7 @@ typedef struct VFont { char name[1024]; /* 1024 = FILE_MAX */ struct VFontData *data; - struct PackedFile * packedfile; + struct PackedFile *packedfile; } VFont; /* *************** FONT ****************** */ diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index ac1dd3e74b4..ac7a5a748e9 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -138,6 +138,7 @@ extern StructRNA RNA_CompositorNodeHueSat; extern StructRNA RNA_CompositorNodeIDMask; extern StructRNA RNA_CompositorNodeDoubleEdgeMask; extern StructRNA RNA_CompositorNodeImage; +extern StructRNA RNA_CompositorNodeInpaint; extern StructRNA RNA_CompositorNodeInvert; extern StructRNA RNA_CompositorNodeLensdist; extern StructRNA RNA_CompositorNodeLevels; diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c index e007db62f58..4a27761b8d2 100644 --- a/source/blender/makesrna/intern/rna_ID.c +++ b/source/blender/makesrna/intern/rna_ID.c @@ -77,6 +77,7 @@ EnumPropertyItem id_type_items[] = { #ifdef RNA_RUNTIME +#include "BKE_font.h" #include "BKE_idprop.h" #include "BKE_library.h" #include "BKE_animsys.h" @@ -110,12 +111,12 @@ static int rna_ID_name_editable(PointerRNA *ptr) ID *id = (ID *)ptr->data; if (GS(id->name) == ID_VF) { - VFont *vf = (VFont *)id; - if (strcmp(vf->name, FO_BUILTIN_NAME) == 0) - return 0; + VFont *vfont = (VFont *)id; + if (BKE_vfont_is_builtin(vfont)) + return FALSE; } - return 1; + return TRUE; } short RNA_type_to_ID_code(StructRNA *type) diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 5b5367654eb..ec4da311686 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -1031,7 +1031,7 @@ void RNA_property_float_ui_range(PointerRNA *ptr, PropertyRNA *prop, float *soft IDProperty *item; item = IDP_GetPropertyTypeFromGroup(idp_ui, "soft_min", IDP_DOUBLE); - *softmin = item ? (float)IDP_Double(item) : FLT_MIN; + *softmin = item ? (float)IDP_Double(item) : -FLT_MAX; item = IDP_GetPropertyTypeFromGroup(idp_ui, "soft_max", IDP_DOUBLE); *softmax = item ? (float)IDP_Double(item) : FLT_MAX; diff --git a/source/blender/makesrna/intern/rna_constraint.c b/source/blender/makesrna/intern/rna_constraint.c index 8d718715e5b..770bdb68e38 100644 --- a/source/blender/makesrna/intern/rna_constraint.c +++ b/source/blender/makesrna/intern/rna_constraint.c @@ -2207,6 +2207,13 @@ static void rna_def_constraint_follow_track(BlenderRNA *brna) StructRNA *srna; PropertyRNA *prop; + static const EnumPropertyItem frame_method_items[] = { + {FOLLOWTRACK_FRAME_STRETCH, "STRETCH", 0, "Stretch", ""}, + {FOLLOWTRACK_FRAME_FIT, "FIT", 0, "Fit", ""}, + {FOLLOWTRACK_FRAME_CROP, "CROP", 0, "Crop", ""}, + {0, NULL, 0, NULL, NULL} + }; + srna = RNA_def_struct(brna, "FollowTrackConstraint", "Constraint"); RNA_def_struct_ui_text(srna, "Follow Track Constraint", "Lock motion to the target motion track"); RNA_def_struct_sdna_from(srna, "bFollowTrackConstraint", "data"); @@ -2261,6 +2268,13 @@ static void rna_def_constraint_follow_track(BlenderRNA *brna) RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_dependency_update"); RNA_def_property_pointer_funcs(prop, NULL, "rna_Constraint_followTrack_depthObject_set", NULL, "rna_Constraint_followTrack_depthObject_poll"); + + /* frame method */ + prop = RNA_def_property(srna, "frame_method", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_bitflag_sdna(prop, NULL, "frame_method"); + RNA_def_property_enum_items(prop, frame_method_items); + RNA_def_property_ui_text(prop, "Frame Method", "How the footage fits in the camera frame"); + RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_dependency_update"); } static void rna_def_constraint_camera_solver(BlenderRNA *brna) diff --git a/source/blender/makesrna/intern/rna_mask.c b/source/blender/makesrna/intern/rna_mask.c index 9ee2bb99b4e..f197bf8391d 100644 --- a/source/blender/makesrna/intern/rna_mask.c +++ b/source/blender/makesrna/intern/rna_mask.c @@ -568,6 +568,13 @@ static void rna_def_maskSpline(BlenderRNA *brna) RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", MASK_SPLINE_NOFILL); RNA_def_property_ui_text(prop, "Fill", "Make this spline filled"); RNA_def_property_update(prop, NC_MASK | NA_EDITED, "rna_Mask_update_data"); + + /* self-intersection check */ + prop = RNA_def_property(srna, "use_self_intersection_check", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", MASK_SPLINE_NOINTERSECT); + RNA_def_property_ui_text(prop, "Self Intersection Check", "Prevent feather from self-intersections"); + RNA_def_property_update(prop, NC_MASK | NA_EDITED, "rna_Mask_update_data"); } static void rna_def_mask_layer(BlenderRNA *brna) diff --git a/source/blender/makesrna/intern/rna_movieclip.c b/source/blender/makesrna/intern/rna_movieclip.c index 573e27b52c2..8b2b741b83e 100644 --- a/source/blender/makesrna/intern/rna_movieclip.c +++ b/source/blender/makesrna/intern/rna_movieclip.c @@ -287,7 +287,7 @@ static void rna_def_movieclip(BlenderRNA *brna) RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL); /* start_frame */ - prop = RNA_def_property(srna, "start_frame", PROP_INT, PROP_NONE); + prop = RNA_def_property(srna, "frame_start", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "start_frame"); RNA_def_property_ui_text(prop, "Start Frame", "Global scene frame number at which this movie starts playing " "(affects all data associated with a clip)"); diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index 472b0693ae5..a0e15b48e23 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -439,6 +439,15 @@ static void rna_NodeGroup_update(Main *bmain, Scene *scene, PointerRNA *ptr) node_update(bmain, scene, ntree, node); } +static int rna_NodeGroup_node_tree_poll(PointerRNA *ptr, const PointerRNA value) +{ + bNodeTree *ntree = (bNodeTree *)ptr->id.data; + bNodeTree *ngroup = (bNodeTree *)value.data; + + /* only allow node trees of the same type as the group node's tree */ + return (ngroup->type == ntree->type); +} + static void rna_Node_name_set(PointerRNA *ptr, const char *value) { bNodeTree *ntree = (bNodeTree *)ptr->id.data; @@ -1129,6 +1138,7 @@ static void def_group(StructRNA *srna) prop = RNA_def_property(srna, "node_tree", PROP_POINTER, PROP_NONE); RNA_def_property_pointer_sdna(prop, NULL, "id"); RNA_def_property_struct_type(prop, "NodeTree"); + RNA_def_property_pointer_funcs(prop, NULL, NULL, NULL, "rna_NodeGroup_node_tree_poll"); RNA_def_property_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Node Tree", ""); RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeGroup_update"); @@ -2103,6 +2113,26 @@ static void def_cmp_dilate_erode(StructRNA *srna) RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); } +static void def_cmp_inpaint(StructRNA *srna) +{ + PropertyRNA *prop; + +/* + prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE); + + RNA_def_property_enum_sdna(prop, NULL, "custom1"); + RNA_def_property_enum_items(prop, type_items); + RNA_def_property_ui_text(prop, "Type", "Type of inpaint algorithm"); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); +*/ + + prop = RNA_def_property(srna, "distance", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "custom2"); + RNA_def_property_range(prop, 1, 10000); + RNA_def_property_ui_text(prop, "Distance", "Distance to inpaint (number of iterations)"); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); +} + static void def_cmp_scale(StructRNA *srna) { PropertyRNA *prop; diff --git a/source/blender/makesrna/intern/rna_nodetree_types.h b/source/blender/makesrna/intern/rna_nodetree_types.h index a4837a88b17..c70dd01cd57 100644 --- a/source/blender/makesrna/intern/rna_nodetree_types.h +++ b/source/blender/makesrna/intern/rna_nodetree_types.h @@ -121,6 +121,7 @@ DefNode( CompositorNode, CMP_NODE_TRANSLATE, 0, "TRANS DefNode( CompositorNode, CMP_NODE_ZCOMBINE, def_cmp_zcombine, "ZCOMBINE", Zcombine, "Z Combine", "" ) DefNode( CompositorNode, CMP_NODE_COMBRGBA, 0, "COMBRGBA", CombRGBA, "Combine RGBA", "" ) DefNode( CompositorNode, CMP_NODE_DILATEERODE, def_cmp_dilate_erode, "DILATEERODE", DilateErode, "Dilate/Erode", "" ) +DefNode( CompositorNode, CMP_NODE_INPAINT, def_cmp_inpaint, "INPAINT", Inpaint, "Inpaint", "" ) DefNode( CompositorNode, CMP_NODE_ROTATE, def_cmp_rotate, "ROTATE", Rotate, "Rotate", "" ) DefNode( CompositorNode, CMP_NODE_SCALE, def_cmp_scale, "SCALE", Scale, "Scale", "" ) DefNode( CompositorNode, CMP_NODE_SEPYCCA, def_cmp_ycc, "SEPYCCA", SepYCCA, "Separate YCCA", "" ) diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c index 5cabc328778..7ab359661c5 100644 --- a/source/blender/makesrna/intern/rna_object_api.c +++ b/source/blender/makesrna/intern/rna_object_api.c @@ -347,10 +347,10 @@ void rna_Object_create_duplilist(Object *ob, ReportList *reports, Scene *sce) free_object_duplilist(ob->duplilist); ob->duplilist = NULL; } - if (G.rendering) + if (G.is_rendering) dupli_render_particle_set(sce, ob, 0, 1); ob->duplilist = object_duplilist(sce, ob); - if (G.rendering) + if (G.is_rendering) dupli_render_particle_set(sce, ob, 0, 0); /* ob->duplilist should now be freed with Object.free_duplilist */ } diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 653743ccd90..2c387ad3f55 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -239,10 +239,6 @@ EnumPropertyItem image_type_items[] = { IMAGE_TYPE_ITEMS_IMAGE_ONLY {0, "", 0, N_("Movie"), NULL}, -#ifdef _WIN32 - /* XXX Missing codec menu */ - {R_IMF_IMTYPE_AVICODEC, "AVICODEC", ICON_FILE_MOVIE, "AVI Codec", "Output video in AVI format"}, -#endif {R_IMF_IMTYPE_AVIJPEG, "AVI_JPEG", ICON_FILE_MOVIE, "AVI JPEG", "Output video in AVI JPEG format"}, {R_IMF_IMTYPE_AVIRAW, "AVI_RAW", ICON_FILE_MOVIE, "AVI Raw", "Output video in AVI Raw format"}, #ifdef WITH_FRAMESERVER @@ -482,7 +478,7 @@ static void rna_Scene_layer_update(Main *bmain, Scene *scene, PointerRNA *ptr) static void rna_Scene_fps_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNUSED(ptr)) { sound_update_fps(scene); - seq_update_sound_bounds_all(scene); + BKE_sequencer_update_sound_bounds_all(scene); } static void rna_Scene_listener_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNUSED(ptr)) diff --git a/source/blender/makesrna/intern/rna_screen.c b/source/blender/makesrna/intern/rna_screen.c index d405cba6607..a6d4e473df4 100644 --- a/source/blender/makesrna/intern/rna_screen.c +++ b/source/blender/makesrna/intern/rna_screen.c @@ -57,6 +57,8 @@ EnumPropertyItem region_type_items[] = { #include "BKE_global.h" +#include "UI_view2d.h" + static void rna_Screen_scene_set(PointerRNA *ptr, PointerRNA value) { bScreen *sc = (bScreen *)ptr->data; @@ -138,6 +140,19 @@ static void rna_Area_type_update(bContext *C, PointerRNA *ptr) } } +void rna_View2D_region_to_view(struct View2D *v2d, int x, int y, float result[2]) +{ + UI_view2d_region_to_view(v2d, x, y, &result[0], &result[1]); +} + +void rna_View2D_view_to_region(struct View2D *v2d, float x, float y, int clip, int result[2]) +{ + if (clip) + UI_view2d_view_to_region(v2d, x, y, &result[0], &result[1]); + else + UI_view2d_to_region_no_clip(v2d, x, y, &result[0], &result[1]); +} + #else /* Area.spaces */ @@ -220,6 +235,50 @@ static void rna_def_area(BlenderRNA *brna) RNA_def_string(func, "text", NULL, 0, "Text", "New string for the header, no argument clears the text"); } +static void rna_def_view2d_api(StructRNA *srna) +{ + FunctionRNA *func; + PropertyRNA *parm; + + static const float view_default[2] = {0.0f, 0.0f}; + static const int region_default[2] = {0.0f, 0.0f}; + + func = RNA_def_function(srna, "region_to_view", "rna_View2D_region_to_view"); + RNA_def_function_ui_description(func, "Transform region coordinates to 2D view"); + parm = RNA_def_int(func, "x", 0, INT_MIN, INT_MAX, "x", "Region x coordinate", -10000, 10000); + RNA_def_property_flag(parm, PROP_REQUIRED); + parm = RNA_def_int(func, "y", 0, INT_MIN, INT_MAX, "y", "Region y coordinate", -10000, 10000); + RNA_def_property_flag(parm, PROP_REQUIRED); + parm = RNA_def_float_array(func, "result", 2, view_default, -FLT_MAX, FLT_MAX, "Result", "View coordinates", -10000.0f, 10000.0f); + RNA_def_property_flag(parm, PROP_THICK_WRAP); + RNA_def_function_output(func, parm); + + func = RNA_def_function(srna, "view_to_region", "rna_View2D_view_to_region"); + RNA_def_function_ui_description(func, "Transform 2D view coordinates to region"); + parm = RNA_def_float(func, "x", 0.0f, -FLT_MAX, FLT_MAX, "x", "2D View x coordinate", -10000.0f, 10000.0f); + RNA_def_property_flag(parm, PROP_REQUIRED); + parm = RNA_def_float(func, "y", 0.0f, -FLT_MAX, FLT_MAX, "y", "2D View y coordinate", -10000.0f, 10000.0f); + RNA_def_property_flag(parm, PROP_REQUIRED); + RNA_def_boolean(func, "clip", 1, "Clip", "Clip coordinates to the visible region"); + parm = RNA_def_int_array(func, "result", 2, region_default, INT_MIN, INT_MAX, "Result", "Region coordinates", -10000, 10000); + RNA_def_property_flag(parm, PROP_THICK_WRAP); + RNA_def_function_output(func, parm); +} + +static void rna_def_view2d(BlenderRNA *brna) +{ + StructRNA *srna; + /* PropertyRNA *prop; */ + + srna = RNA_def_struct(brna, "View2D", NULL); + RNA_def_struct_ui_text(srna, "View2D", "Scroll and zoom for a 2D region"); + RNA_def_struct_sdna(srna, "View2D"); + + /* TODO more View2D properties could be exposed here (read-only) */ + + rna_def_view2d_api(srna); +} + static void rna_def_region(BlenderRNA *brna) { StructRNA *srna; @@ -260,6 +319,12 @@ static void rna_def_region(BlenderRNA *brna) RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Height", "Region height"); + prop = RNA_def_property(srna, "view2d", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, NULL, "v2d"); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_flag(prop, PROP_NEVER_NULL); + RNA_def_property_ui_text(prop, "View2D", "2D view of the region"); + RNA_def_function(srna, "tag_redraw", "ED_region_tag_redraw"); } @@ -345,6 +410,7 @@ void RNA_def_screen(BlenderRNA *brna) rna_def_screen(brna); rna_def_area(brna); rna_def_region(brna); + rna_def_view2d(brna); } #endif diff --git a/source/blender/makesrna/intern/rna_sequencer.c b/source/blender/makesrna/intern/rna_sequencer.c index 5c851550cc6..8c0c87e5696 100644 --- a/source/blender/makesrna/intern/rna_sequencer.c +++ b/source/blender/makesrna/intern/rna_sequencer.c @@ -59,6 +59,11 @@ typedef struct EffectInfo { #ifdef RNA_RUNTIME +typedef struct SequenceSearchData { + Sequence *seq; + void *data; +} SequenceSearchData; + /* build a temp reference to the parent */ static void meta_tmp_ref(Sequence *seq_par, Sequence *seq) { @@ -126,11 +131,11 @@ static void rna_SequenceEditor_elements_begin(CollectionPropertyIterator *iter, static void rna_Sequence_frame_change_update(Scene *scene, Sequence *seq) { Editing *ed = BKE_sequencer_editing_get(scene, FALSE); - ListBase *seqbase = seq_seqbase(&ed->seqbase, seq); - calc_sequence_disp(scene, seq); + ListBase *seqbase = BKE_sequence_seqbase(&ed->seqbase, seq); + BKE_sequence_calc_disp(scene, seq); - if (seq_test_overlap(seqbase, seq)) { - shuffle_seq(seqbase, seq, scene); /* XXX - BROKEN!, uses context seqbasep */ + if (BKE_sequence_test_overlap(seqbase, seq)) { + BKE_sequence_base_shuffle(seqbase, seq, scene); /* XXX - BROKEN!, uses context seqbasep */ } BKE_sequencer_sort(scene); } @@ -140,7 +145,7 @@ static void rna_Sequence_start_frame_set(PointerRNA *ptr, int value) Sequence *seq = (Sequence *)ptr->data; Scene *scene = (Scene *)ptr->id.data; - seq_translate(scene, seq, value - seq->start); + BKE_sequence_translate(scene, seq, value - seq->start); rna_Sequence_frame_change_update(scene, seq); } @@ -149,8 +154,8 @@ static void rna_Sequence_start_frame_final_set(PointerRNA *ptr, int value) Sequence *seq = (Sequence *)ptr->data; Scene *scene = (Scene *)ptr->id.data; - seq_tx_set_final_left(seq, value); - seq_single_fix(seq); + BKE_sequence_tx_set_final_left(seq, value); + BKE_sequence_single_fix(seq); rna_Sequence_frame_change_update(scene, seq); } @@ -159,8 +164,8 @@ static void rna_Sequence_end_frame_final_set(PointerRNA *ptr, int value) Sequence *seq = (Sequence *)ptr->data; Scene *scene = (Scene *)ptr->id.data; - seq_tx_set_final_right(seq, value); - seq_single_fix(seq); + BKE_sequence_tx_set_final_right(seq, value); + BKE_sequence_single_fix(seq); rna_Sequence_frame_change_update(scene, seq); } @@ -171,7 +176,7 @@ static void rna_Sequence_anim_startofs_final_set(PointerRNA *ptr, int value) seq->anim_startofs = MIN2(value, seq->len + seq->anim_startofs); - reload_sequence_new_file(scene, seq, FALSE); + BKE_sequence_reload_new_file(scene, seq, FALSE); rna_Sequence_frame_change_update(scene, seq); } @@ -182,7 +187,7 @@ static void rna_Sequence_anim_endofs_final_set(PointerRNA *ptr, int value) seq->anim_endofs = MIN2(value, seq->len + seq->anim_endofs); - reload_sequence_new_file(scene, seq, FALSE); + BKE_sequence_reload_new_file(scene, seq, FALSE); rna_Sequence_frame_change_update(scene, seq); } @@ -191,21 +196,21 @@ static void rna_Sequence_frame_length_set(PointerRNA *ptr, int value) Sequence *seq = (Sequence *)ptr->data; Scene *scene = (Scene *)ptr->id.data; - seq_tx_set_final_right(seq, seq->start + value); + BKE_sequence_tx_set_final_right(seq, seq->start + value); rna_Sequence_frame_change_update(scene, seq); } static int rna_Sequence_frame_length_get(PointerRNA *ptr) { Sequence *seq = (Sequence *)ptr->data; - return seq_tx_get_final_right(seq, 0) - seq_tx_get_final_left(seq, 0); + return BKE_sequence_tx_get_final_right(seq, 0) - BKE_sequence_tx_get_final_left(seq, 0); } static int rna_Sequence_frame_editable(PointerRNA *ptr) { Sequence *seq = (Sequence *)ptr->data; /* Effect sequences' start frame and length must be readonly! */ - return (get_sequence_effect_num_inputs(seq->type)) ? 0 : PROP_EDITABLE; + return (BKE_sequence_effect_get_num_inputs(seq->type)) ? 0 : PROP_EDITABLE; } static void rna_Sequence_channel_set(PointerRNA *ptr, int value) @@ -213,12 +218,12 @@ static void rna_Sequence_channel_set(PointerRNA *ptr, int value) Sequence *seq = (Sequence *)ptr->data; Scene *scene = (Scene *)ptr->id.data; Editing *ed = BKE_sequencer_editing_get(scene, FALSE); - ListBase *seqbase = seq_seqbase(&ed->seqbase, seq); + ListBase *seqbase = BKE_sequence_seqbase(&ed->seqbase, seq); seq->machine = value; - if (seq_test_overlap(seqbase, seq) ) { - shuffle_seq(seqbase, seq, scene); /* XXX - BROKEN!, uses context seqbasep */ + if (BKE_sequence_test_overlap(seqbase, seq) ) { + BKE_sequence_base_shuffle(seqbase, seq, scene); /* XXX - BROKEN!, uses context seqbasep */ } BKE_sequencer_sort(scene); } @@ -292,28 +297,33 @@ static void rna_Sequence_use_crop_set(PointerRNA *ptr, int value) static int transform_seq_cmp_cb(Sequence *seq, void *arg_pt) { - struct { Sequence *seq; void *transform; } *data = arg_pt; + SequenceSearchData *data = arg_pt; - if (seq->strip && seq->strip->transform == data->transform) { + if (seq->strip && seq->strip->transform == data->data) { data->seq = seq; return -1; /* done so bail out */ } return 1; } -static char *rna_SequenceTransform_path(PointerRNA *ptr) +static Sequence *sequence_get_by_transform(Editing *ed, StripTransform *transform) { - Scene *scene = ptr->id.data; - Editing *ed = BKE_sequencer_editing_get(scene, FALSE); - Sequence *seq; + SequenceSearchData data; - struct { Sequence *seq; void *transform; } data; data.seq = NULL; - data.transform = ptr->data; + data.data = transform; /* irritating we need to search for our sequence! */ - seqbase_recursive_apply(&ed->seqbase, transform_seq_cmp_cb, &data); - seq = data.seq; + BKE_sequencer_base_recursive_apply(&ed->seqbase, transform_seq_cmp_cb, &data); + + return data.seq; +} + +static char *rna_SequenceTransform_path(PointerRNA *ptr) +{ + Scene *scene = ptr->id.data; + Editing *ed = BKE_sequencer_editing_get(scene, FALSE); + Sequence *seq = sequence_get_by_transform(ed, ptr->data); if (seq && seq->name + 2) return BLI_sprintfN("sequence_editor.sequences_all[\"%s\"].transform", seq->name + 2); @@ -321,30 +331,43 @@ static char *rna_SequenceTransform_path(PointerRNA *ptr) return BLI_strdup(""); } +static void rna_SequenceTransform_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *ptr) +{ + Editing *ed = BKE_sequencer_editing_get(scene, FALSE); + Sequence *seq = sequence_get_by_transform(ed, ptr->data); + + BKE_sequence_invalidate_cache(scene, seq); +} + static int crop_seq_cmp_cb(Sequence *seq, void *arg_pt) { - struct { Sequence *seq; void *crop; } *data = arg_pt; + SequenceSearchData *data = arg_pt; - if (seq->strip && seq->strip->crop == data->crop) { + if (seq->strip && seq->strip->crop == data->data) { data->seq = seq; return -1; /* done so bail out */ } return 1; } -static char *rna_SequenceCrop_path(PointerRNA *ptr) +static Sequence *sequence_get_by_crop(Editing *ed, StripCrop *crop) { - Scene *scene = ptr->id.data; - Editing *ed = BKE_sequencer_editing_get(scene, FALSE); - Sequence *seq; + SequenceSearchData data; - struct { Sequence *seq; void *crop; } data; data.seq = NULL; - data.crop = ptr->data; + data.data = crop; /* irritating we need to search for our sequence! */ - seqbase_recursive_apply(&ed->seqbase, crop_seq_cmp_cb, &data); - seq = data.seq; + BKE_sequencer_base_recursive_apply(&ed->seqbase, crop_seq_cmp_cb, &data); + + return data.seq; +} + +static char *rna_SequenceCrop_path(PointerRNA *ptr) +{ + Scene *scene = ptr->id.data; + Editing *ed = BKE_sequencer_editing_get(scene, FALSE); + Sequence *seq = sequence_get_by_crop(ed, ptr->data); if (seq && seq->name + 2) return BLI_sprintfN("sequence_editor.sequences_all[\"%s\"].crop", seq->name + 2); @@ -352,6 +375,13 @@ static char *rna_SequenceCrop_path(PointerRNA *ptr) return BLI_strdup(""); } +static void rna_SequenceCrop_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *ptr) +{ + Editing *ed = BKE_sequencer_editing_get(scene, FALSE); + Sequence *seq = sequence_get_by_crop(ed, ptr->data); + + BKE_sequence_invalidate_cache(scene, seq); +} /* name functions that ignore the first two characters */ static void rna_Sequence_name_get(PointerRNA *ptr, char *value) @@ -380,7 +410,7 @@ static void rna_Sequence_name_set(PointerRNA *ptr, const char *value) BLI_strncpy_utf8(seq->name + 2, value, sizeof(seq->name) - 2); /* make sure the name is unique */ - seqbase_unique_name_recursive(&scene->ed->seqbase, seq); + BKE_seqence_base_unique_name_recursive(&scene->ed->seqbase, seq); /* fix all the animation data which may link to this */ @@ -557,7 +587,7 @@ static int rna_Sequence_input_count_get(PointerRNA *ptr) { Sequence *seq = (Sequence *)(ptr->data); - return get_sequence_effect_num_inputs(seq->type); + return BKE_sequence_effect_get_num_inputs(seq->type); } #if 0 @@ -575,68 +605,82 @@ static void rna_SequenceElement_filename_set(PointerRNA *ptr, const char *value) } #endif -static void rna_Sequence_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNUSED(ptr)) +static void rna_Sequence_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *ptr) { Editing *ed = BKE_sequencer_editing_get(scene, FALSE); - if (ed) - free_imbuf_seq(scene, &ed->seqbase, FALSE, TRUE); + if (ed) { + Sequence *seq = (Sequence *) ptr->data; + + BKE_sequence_invalidate_cache(scene, seq); + } } static void rna_Sequence_update_reopen_files(Main *UNUSED(bmain), Scene *scene, PointerRNA *ptr) { Editing *ed = BKE_sequencer_editing_get(scene, FALSE); - free_imbuf_seq(scene, &ed->seqbase, FALSE, FALSE); + BKE_sequencer_free_imbuf(scene, &ed->seqbase, FALSE, FALSE); if (RNA_struct_is_a(ptr->type, &RNA_SoundSequence)) - seq_update_sound_bounds(scene, ptr->data); + BKE_sequencer_update_sound_bounds(scene, ptr->data); } static void rna_Sequence_mute_update(Main *bmain, Scene *scene, PointerRNA *ptr) { Editing *ed = BKE_sequencer_editing_get(scene, FALSE); - seq_update_muting(ed); + BKE_sequencer_update_muting(ed); rna_Sequence_update(bmain, scene, ptr); } static void rna_Sequence_filepath_update(Main *bmain, Scene *scene, PointerRNA *ptr) { Sequence *seq = (Sequence *)(ptr->data); - reload_sequence_new_file(scene, seq, TRUE); - calc_sequence(scene, seq); + BKE_sequence_reload_new_file(scene, seq, TRUE); + BKE_sequence_calc(scene, seq); rna_Sequence_update(bmain, scene, ptr); } static int seqproxy_seq_cmp_cb(Sequence *seq, void *arg_pt) { - struct { Sequence *seq; void *seq_proxy; } *data = arg_pt; + SequenceSearchData *data = arg_pt; - if (seq->strip && seq->strip->proxy == data->seq_proxy) { + if (seq->strip && seq->strip->proxy == data->data) { data->seq = seq; return -1; /* done so bail out */ } return 1; } -static void rna_Sequence_tcindex_update(Main *bmain, Scene *scene, PointerRNA *ptr) +static Sequence *sequence_get_by_proxy(Editing *ed, StripProxy *proxy) { - Editing *ed = BKE_sequencer_editing_get(scene, FALSE); - Sequence *seq; - - struct { Sequence *seq; void *seq_proxy; } data; + SequenceSearchData data; data.seq = NULL; - data.seq_proxy = ptr->data; + data.data = proxy; - seqbase_recursive_apply(&ed->seqbase, seqproxy_seq_cmp_cb, &data); - seq = data.seq; + BKE_sequencer_base_recursive_apply(&ed->seqbase, seqproxy_seq_cmp_cb, &data); + return data.seq; +} - reload_sequence_new_file(scene, seq, FALSE); +static void rna_Sequence_tcindex_update(Main *bmain, Scene *scene, PointerRNA *ptr) +{ + Editing *ed = BKE_sequencer_editing_get(scene, FALSE); + Sequence *seq = sequence_get_by_proxy(ed, ptr->data); + + BKE_sequence_reload_new_file(scene, seq, FALSE); rna_Sequence_frame_change_update(scene, seq); } +static void rna_SequenceProxy_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *ptr) +{ + Editing *ed = BKE_sequencer_editing_get(scene, FALSE); + Sequence *seq = sequence_get_by_proxy(ed, ptr->data); + + BKE_sequence_invalidate_cache(scene, seq); +} + /* do_versions? */ static float rna_Sequence_opacity_get(PointerRNA *ptr) { @@ -650,30 +694,35 @@ static void rna_Sequence_opacity_set(PointerRNA *ptr, float value) seq->blend_opacity = value * 100.0f; } - static int colbalance_seq_cmp_cb(Sequence *seq, void *arg_pt) { - struct { Sequence *seq; void *color_balance; } *data = arg_pt; + SequenceSearchData *data = arg_pt; - if (seq->strip && seq->strip->color_balance == data->color_balance) { + if (seq->strip && seq->strip->color_balance == data->data) { data->seq = seq; return -1; /* done so bail out */ } return 1; } -static char *rna_SequenceColorBalance_path(PointerRNA *ptr) + +static Sequence *sequence_get_by_colorbalance(Editing *ed, StripColorBalance *cb) { - Scene *scene = ptr->id.data; - Editing *ed = BKE_sequencer_editing_get(scene, FALSE); - Sequence *seq; + SequenceSearchData data; - struct { Sequence *seq; void *color_balance; } data; data.seq = NULL; - data.color_balance = ptr->data; + data.data = cb; /* irritating we need to search for our sequence! */ - seqbase_recursive_apply(&ed->seqbase, colbalance_seq_cmp_cb, &data); - seq = data.seq; + BKE_sequencer_base_recursive_apply(&ed->seqbase, colbalance_seq_cmp_cb, &data); + + return data.seq; +} + +static char *rna_SequenceColorBalance_path(PointerRNA *ptr) +{ + Scene *scene = ptr->id.data; + Editing *ed = BKE_sequencer_editing_get(scene, FALSE); + Sequence *seq = sequence_get_by_colorbalance(ed, ptr->data); if (seq && seq->name + 2) return BLI_sprintfN("sequence_editor.sequences_all[\"%s\"].color_balance", seq->name + 2); @@ -681,6 +730,14 @@ static char *rna_SequenceColorBalance_path(PointerRNA *ptr) return BLI_strdup(""); } +static void rna_SequenceColorBalance_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *ptr) +{ + Editing *ed = BKE_sequencer_editing_get(scene, FALSE); + Sequence *seq = sequence_get_by_colorbalance(ed, ptr->data); + + BKE_sequence_invalidate_cache(scene, seq); +} + static void rna_SequenceEditor_overlay_lock_set(PointerRNA *ptr, int value) { Scene *scene = ptr->id.data; @@ -787,25 +844,25 @@ static void rna_def_strip_crop(BlenderRNA *brna) RNA_def_property_int_sdna(prop, NULL, "top"); RNA_def_property_ui_text(prop, "Top", ""); RNA_def_property_ui_range(prop, 0, 4096, 1, 0); - RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update"); + RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_SequenceCrop_update"); prop = RNA_def_property(srna, "min_y", PROP_INT, PROP_UNSIGNED); RNA_def_property_int_sdna(prop, NULL, "bottom"); RNA_def_property_ui_text(prop, "Bottom", ""); RNA_def_property_ui_range(prop, 0, 4096, 1, 0); - RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update"); + RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_SequenceCrop_update"); prop = RNA_def_property(srna, "min_x", PROP_INT, PROP_UNSIGNED); RNA_def_property_int_sdna(prop, NULL, "left"); RNA_def_property_ui_text(prop, "Left", ""); RNA_def_property_ui_range(prop, 0, 4096, 1, 0); - RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update"); + RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_SequenceCrop_update"); prop = RNA_def_property(srna, "max_x", PROP_INT, PROP_UNSIGNED); RNA_def_property_int_sdna(prop, NULL, "right"); RNA_def_property_ui_text(prop, "Right", ""); RNA_def_property_ui_range(prop, 0, 4096, 1, 0); - RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update"); + RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_SequenceCrop_update"); RNA_def_struct_path_func(srna, "rna_SequenceCrop_path"); } @@ -823,13 +880,13 @@ static void rna_def_strip_transform(BlenderRNA *brna) RNA_def_property_int_sdna(prop, NULL, "xofs"); RNA_def_property_ui_text(prop, "Offset X", ""); RNA_def_property_ui_range(prop, -4096, 4096, 1, 0); - RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update"); + RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_SequenceTransform_update"); prop = RNA_def_property(srna, "offset_y", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "yofs"); RNA_def_property_ui_text(prop, "Offset Y", ""); RNA_def_property_ui_range(prop, -4096, 4096, 1, 0); - RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update"); + RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_SequenceTransform_update"); RNA_def_struct_path_func(srna, "rna_SequenceTransform_path"); @@ -862,14 +919,14 @@ static void rna_def_strip_proxy(BlenderRNA *brna) prop = RNA_def_property(srna, "directory", PROP_STRING, PROP_DIRPATH); RNA_def_property_string_sdna(prop, NULL, "dir"); RNA_def_property_ui_text(prop, "Directory", "Location to store the proxy files"); - RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update"); + RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_SequenceProxy_update"); prop = RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH); RNA_def_property_ui_text(prop, "Path", "Location of custom proxy file"); RNA_def_property_string_funcs(prop, "rna_Sequence_proxy_filepath_get", "rna_Sequence_proxy_filepath_length", "rna_Sequence_proxy_filepath_set"); - RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update"); + RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_SequenceProxy_update"); prop = RNA_def_property(srna, "build_25", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "build_size_flags", SEQ_PROXY_IMAGE_SIZE_25); @@ -924,32 +981,32 @@ static void rna_def_strip_color_balance(BlenderRNA *brna) prop = RNA_def_property(srna, "lift", PROP_FLOAT, PROP_COLOR); RNA_def_property_ui_text(prop, "Lift", "Color balance lift (shadows)"); RNA_def_property_ui_range(prop, 0, 2, 0.1, 3); - RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update"); + RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_SequenceColorBalance_update"); prop = RNA_def_property(srna, "gamma", PROP_FLOAT, PROP_COLOR); RNA_def_property_ui_text(prop, "Gamma", "Color balance gamma (midtones)"); RNA_def_property_ui_range(prop, 0, 2, 0.1, 3); - RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update"); + RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_SequenceColorBalance_update"); prop = RNA_def_property(srna, "gain", PROP_FLOAT, PROP_COLOR); RNA_def_property_ui_text(prop, "Gain", "Color balance gain (highlights)"); RNA_def_property_ui_range(prop, 0, 2, 0.1, 3); - RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update"); + RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_SequenceColorBalance_update"); prop = RNA_def_property(srna, "invert_gain", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", SEQ_COLOR_BALANCE_INVERSE_GAIN); RNA_def_property_ui_text(prop, "Inverse Gain", ""); - RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update"); + RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_SequenceColorBalance_update"); prop = RNA_def_property(srna, "invert_gamma", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", SEQ_COLOR_BALANCE_INVERSE_GAMMA); RNA_def_property_ui_text(prop, "Inverse Gamma", ""); - RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update"); + RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_SequenceColorBalance_update"); prop = RNA_def_property(srna, "invert_lift", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", SEQ_COLOR_BALANCE_INVERSE_LIFT); RNA_def_property_ui_text(prop, "Inverse Lift", ""); - RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update"); + RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_SequenceColorBalance_update"); RNA_def_struct_path_func(srna, "rna_SequenceColorBalance_path"); @@ -958,12 +1015,12 @@ static void rna_def_strip_color_balance(BlenderRNA *brna) prop = RNA_def_property(srna, "exposure", PROP_FLOAT, PROP_NONE); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Exposure", ""); - RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update"); + RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_ColorBabalnce_update"); prop = RNA_def_property(srna, "saturation", PROP_FLOAT, PROP_NONE); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Saturation", ""); - RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update"); + RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_ColorBabalnce_update"); #endif } @@ -1151,6 +1208,7 @@ static void rna_def_sequence(BlenderRNA *brna) prop = RNA_def_property(srna, "effect_fader", PROP_FLOAT, PROP_NONE); RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.1, 3); RNA_def_property_float_sdna(prop, NULL, "effect_fader"); RNA_def_property_ui_text(prop, "Effect fader position", ""); RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_update"); diff --git a/source/blender/makesrna/intern/rna_sequencer_api.c b/source/blender/makesrna/intern/rna_sequencer_api.c index 6c54b7c2cf3..549868e5ed0 100644 --- a/source/blender/makesrna/intern/rna_sequencer_api.c +++ b/source/blender/makesrna/intern/rna_sequencer_api.c @@ -68,7 +68,7 @@ static void rna_Sequence_swap_internal(Sequence *seq_self, ReportList *reports, { const char *error_msg; - if (seq_swap(seq_self, seq_other, &error_msg) == 0) + if (BKE_sequence_swap(seq_self, seq_other, &error_msg) == 0) BKE_report(reports, RPT_ERROR, error_msg); } @@ -79,11 +79,11 @@ static Sequence *alloc_generic_sequence(Editing *ed, const char *name, int start Strip *strip; StripElem *se; - seq = alloc_sequence(ed->seqbasep, start_frame, channel); + seq = BKE_sequence_alloc(ed->seqbasep, start_frame, channel); seq->type = type; BLI_strncpy(seq->name + 2, name, sizeof(seq->name) - 2); - seqbase_unique_name_recursive(&ed->seqbase, seq); + BKE_seqence_base_unique_name_recursive(&ed->seqbase, seq); seq->strip = strip = MEM_callocN(sizeof(Strip), "strip"); seq->strip->us = 1; @@ -111,7 +111,7 @@ static Sequence *rna_Sequences_new_clip(ID *id, Editing *ed, seq->len = BKE_movieclip_get_duration(clip); id_us_plus((ID *)clip); - calc_sequence_disp(scene, seq); + BKE_sequence_calc_disp(scene, seq); WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, scene); @@ -130,7 +130,7 @@ static Sequence *rna_Sequences_new_mask(ID *id, Editing *ed, seq->len = BKE_mask_get_duration(mask); id_us_plus((ID *)mask); - calc_sequence_disp(scene, seq); + BKE_sequence_calc_disp(scene, seq); WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, scene); @@ -150,7 +150,7 @@ static Sequence *rna_Sequences_new_scene(ID *id, Editing *ed, seq->scene_sound = sound_scene_add_scene_sound(scene, seq, start_frame, start_frame + seq->len, 0); id_us_plus((ID *)sce_seq); - calc_sequence_disp(scene, seq); + BKE_sequence_calc_disp(scene, seq); WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, scene); @@ -170,11 +170,11 @@ static Sequence *rna_Sequences_new_image(ID *id, Editing *ed, ReportList *report if (seq->strip->stripdata->name[0] == '\0') { BKE_report(reports, RPT_ERROR, "Sequences.new_image: unable to open image file"); BLI_remlink(&ed->seqbase, seq); - seq_free_sequence(scene, seq); + BKE_sequence_free(scene, seq); return NULL; } - calc_sequence_disp(scene, seq); + BKE_sequence_calc_disp(scene, seq); WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, scene); @@ -200,7 +200,7 @@ static Sequence *rna_Sequences_new_movie(ID *id, Editing *ed, ReportList *report seq->anim_preseek = IMB_anim_get_preseek(an); seq->len = IMB_anim_get_duration(an, IMB_TC_RECORD_RUN); - calc_sequence_disp(scene, seq); + BKE_sequence_calc_disp(scene, seq); WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, scene); @@ -227,7 +227,7 @@ static Sequence *rna_Sequences_new_sound(ID *id, Editing *ed, Main *bmain, Repor seq->scene_sound = sound_add_scene_sound(scene, seq, start_frame, start_frame + seq->len, 0); - calc_sequence_disp(scene, seq); + BKE_sequence_calc_disp(scene, seq); WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, scene); @@ -251,7 +251,7 @@ static Sequence *rna_Sequences_new_effect(ID *id, Editing *ed, ReportList *repor Sequence *seq; struct SeqEffectHandle sh; - switch (get_sequence_effect_num_inputs(type)) { + switch (BKE_sequence_effect_get_num_inputs(type)) { case 0: if (end_frame <= start_frame) { BKE_report(reports, RPT_ERROR, @@ -282,13 +282,13 @@ static Sequence *rna_Sequences_new_effect(ID *id, Editing *ed, ReportList *repor break; default: BKE_report(reports, RPT_ERROR, - "Sequences.new_effect: get_sequence_effect_num_inputs() > 3 (should never happen)"); + "Sequences.new_effect: BKE_sequence_effect_get_num_inputs() > 3 (should never happen)"); return NULL; } seq = alloc_generic_sequence(ed, name, start_frame, channel, type, NULL); - sh = get_sequence_effect(seq); + sh = BKE_sequence_get_effect(seq); seq->seq1 = seq1; seq->seq2 = seq2; @@ -298,12 +298,12 @@ static Sequence *rna_Sequences_new_effect(ID *id, Editing *ed, ReportList *repor if (!seq1) { /* effect has no deps */ seq->len = 1; - seq_tx_set_final_right(seq, end_frame); + BKE_sequence_tx_set_final_right(seq, end_frame); } seq->flag |= SEQ_USE_EFFECT_DEFAULT_FADE; - calc_sequence(scene, seq); + BKE_sequence_calc_disp(scene, seq); WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, scene); @@ -315,7 +315,7 @@ static void rna_Sequences_remove(ID *id, Editing *ed, Sequence *seq) Scene *scene = (Scene *)id; BLI_remlink(&ed->seqbase, seq); - seq_free_sequence(scene, seq); + BKE_sequence_free(scene, seq); WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, scene); } @@ -330,7 +330,7 @@ static StripElem *rna_SequenceElements_push(ID *id, Sequence *seq, const char *f BLI_strncpy(se->name, filename, sizeof(se->name)); seq->len++; - calc_sequence_disp(scene, seq); + BKE_sequence_calc_disp(scene, seq); WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, scene); @@ -370,7 +370,7 @@ static void rna_SequenceElements_pop(ID *id, Sequence *seq, ReportList *reports, MEM_freeN(seq->strip->stripdata); seq->strip->stripdata = new_seq; - calc_sequence_disp(scene, seq); + BKE_sequence_calc_disp(scene, seq); WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, scene); } @@ -383,7 +383,7 @@ void RNA_api_sequence_strip(StructRNA *srna) FunctionRNA *func; PropertyRNA *parm; - func = RNA_def_function(srna, "getStripElem", "give_stripelem"); + func = RNA_def_function(srna, "getStripElem", "BKE_sequencer_give_stripelem"); RNA_def_function_ui_description(func, "Return the strip element from a given frame or None"); parm = RNA_def_int(func, "frame", 0, -MAXFRAME, MAXFRAME, "Frame", "The frame to get the strip element from", -MAXFRAME, MAXFRAME); diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index 793eb2b7185..e325619dc0c 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -1165,13 +1165,6 @@ static void rna_def_space_image_uv(BlenderRNA *brna) {0, NULL, 0, NULL, NULL} }; - static EnumPropertyItem pivot_items[] = { - {V3D_CENTER, "CENTER", ICON_ROTATE, "Bounding Box Center", ""}, - {V3D_CENTROID, "MEDIAN", ICON_ROTATECENTER, "Median Point", ""}, - {V3D_CURSOR, "CURSOR", ICON_CURSOR, "2D Cursor", ""}, - {0, NULL, 0, NULL, NULL} - }; - srna = RNA_def_struct(brna, "SpaceUVEditor", NULL); RNA_def_struct_sdna(srna, "SpaceImage"); RNA_def_struct_nested(brna, srna, "SpaceImageEditor"); @@ -1231,13 +1224,6 @@ static void rna_def_space_image_uv(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Draw Faces", "Draw faces over the image"); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_IMAGE, NULL); - prop = RNA_def_property(srna, "cursor_location", PROP_FLOAT, PROP_XYZ); - RNA_def_property_array(prop, 2); - RNA_def_property_float_funcs(prop, "rna_SpaceImageEditor_cursor_location_get", - "rna_SpaceImageEditor_cursor_location_set", NULL); - RNA_def_property_ui_text(prop, "2D Cursor Location", "2D cursor location for this view"); - RNA_def_property_update(prop, NC_SPACE | ND_SPACE_IMAGE, NULL); - /* todo: move edge and face drawing options here from G.f */ prop = RNA_def_property(srna, "use_snap_to_pixels", PROP_BOOLEAN, PROP_NONE); @@ -1256,12 +1242,6 @@ static void rna_def_space_image_uv(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Live Unwrap", "Continuously unwrap the selected UV island while transforming pinned vertices"); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_IMAGE, NULL); - - prop = RNA_def_property(srna, "pivot_point", PROP_ENUM, PROP_NONE); - RNA_def_property_enum_sdna(prop, NULL, "around"); - RNA_def_property_enum_items(prop, pivot_items); - RNA_def_property_ui_text(prop, "Pivot", "Rotation/Scaling Pivot"); - RNA_def_property_update(prop, NC_SPACE | ND_SPACE_IMAGE, NULL); } static void rna_def_space_outliner(BlenderRNA *brna) @@ -1977,6 +1957,13 @@ static void rna_def_space_image(BlenderRNA *brna) {0, NULL, 0, NULL, NULL} }; + static EnumPropertyItem pivot_items[] = { + {V3D_CENTER, "CENTER", ICON_ROTATE, "Bounding Box Center", ""}, + {V3D_CENTROID, "MEDIAN", ICON_ROTATECENTER, "Median Point", ""}, + {V3D_CURSOR, "CURSOR", ICON_CURSOR, "2D Cursor", ""}, + {0, NULL, 0, NULL, NULL} + }; + StructRNA *srna; PropertyRNA *prop; @@ -2053,6 +2040,20 @@ static void rna_def_space_image(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Mode", "Editing context being displayed"); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_IMAGE, "rna_SpaceImageEditor_mode_update"); + /* transform */ + prop = RNA_def_property(srna, "cursor_location", PROP_FLOAT, PROP_XYZ); + RNA_def_property_array(prop, 2); + RNA_def_property_float_funcs(prop, "rna_SpaceImageEditor_cursor_location_get", + "rna_SpaceImageEditor_cursor_location_set", NULL); + RNA_def_property_ui_text(prop, "2D Cursor Location", "2D cursor location for this view"); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_IMAGE, NULL); + + prop = RNA_def_property(srna, "pivot_point", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "around"); + RNA_def_property_enum_items(prop, pivot_items); + RNA_def_property_ui_text(prop, "Pivot", "Rotation/Scaling Pivot"); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_IMAGE, NULL); + /* grease pencil */ prop = RNA_def_property(srna, "grease_pencil", PROP_POINTER, PROP_NONE); RNA_def_property_pointer_sdna(prop, NULL, "gpd"); @@ -2960,9 +2961,14 @@ static void rna_def_space_node(BlenderRNA *brna) RNA_def_property_pointer_sdna(prop, NULL, "nodetree"); RNA_def_property_pointer_funcs(prop, NULL, NULL, NULL, "rna_SpaceNodeEditor_node_tree_poll"); RNA_def_property_flag(prop, PROP_EDITABLE); - RNA_def_property_ui_text(prop, "Node Tree", "Node tree being displayed and edited"); + RNA_def_property_ui_text(prop, "Node Tree", "Node tree being displayed"); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_NODE, "rna_SpaceNodeEditor_node_tree_update"); + prop = RNA_def_property(srna, "edit_tree", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, NULL, "edittree"); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Edit Tree", "Edited node tree"); + prop = RNA_def_property(srna, "show_backdrop", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", SNODE_BACKDRAW); RNA_def_property_ui_text(prop, "Backdrop", "Use active Viewer Node output as backdrop for compositing nodes"); @@ -3006,6 +3012,12 @@ static void rna_def_space_node(BlenderRNA *brna) RNA_def_property_boolean_sdna(prop, NULL, "flag", SNODE_USE_HIDDEN_PREVIEW); RNA_def_property_ui_text(prop, "Hide Preview", "Hide preview for newly creating nodes"); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_NODE_VIEW, NULL); + + /* the mx/my "cursor" in the node editor is used only by operators to store the mouse position */ + prop = RNA_def_property(srna, "cursor_location", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "cursor"); + RNA_def_property_ui_text(prop, "Cursor Location", "Location for adding new nodes"); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_NODE_VIEW, NULL); } static void rna_def_space_logic(BlenderRNA *brna) diff --git a/source/blender/makesrna/intern/rna_tracking.c b/source/blender/makesrna/intern/rna_tracking.c index 63e650d5867..0898ba5608f 100644 --- a/source/blender/makesrna/intern/rna_tracking.c +++ b/source/blender/makesrna/intern/rna_tracking.c @@ -382,6 +382,17 @@ static void rna_tracking_markerSearch_update(Main *UNUSED(bmain), Scene *UNUSED( BKE_tracking_marker_clamp(marker, CLAMP_SEARCH_DIM); } +static void rna_tracking_markerPattern_boundbox_get(PointerRNA *ptr, float *values) +{ + MovieTrackingMarker *marker = (MovieTrackingMarker *)ptr->data; + float min[2], max[2]; + + BKE_tracking_marker_pattern_minmax(marker, min, max); + + copy_v2_v2(values, min); + copy_v2_v2(values + 2, max); +} + static void rna_trackingDopesheet_tagUpdate(Main *UNUSED(bmain), Scene *scene, PointerRNA *ptr) { MovieClip *clip = (MovieClip *)ptr->id.data; @@ -443,9 +454,12 @@ void rna_trackingObject_remove(MovieTracking *tracking, MovieTrackingObject *obj WM_main_add_notifier(NC_MOVIECLIP | NA_EDITED, NULL); } -static MovieTrackingMarker *rna_trackingMarkers_find_frame(MovieTrackingTrack *track, int framenr) +static MovieTrackingMarker *rna_trackingMarkers_find_frame(MovieTrackingTrack *track, int framenr, int exact) { - return BKE_tracking_marker_get_exact(track, framenr); + if (exact) + return BKE_tracking_marker_get_exact(track, framenr); + else + return BKE_tracking_marker_get(track, framenr); } static MovieTrackingMarker *rna_trackingMarkers_insert_frame(MovieTrackingTrack *track, int framenr, float *co) @@ -646,19 +660,19 @@ static void rna_def_trackingSettings(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Motion model", "Default motion model to use for tracking"); /* default_use_brute */ - prop = RNA_def_property(srna, "default_use_brute", PROP_BOOLEAN, PROP_NONE); + prop = RNA_def_property(srna, "use_default_brute", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "default_algorithm_flag", TRACK_ALGORITHM_FLAG_USE_BRUTE); RNA_def_property_ui_text(prop, "Prepass", "Use a brute-force translation-only initialization when tracking"); RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL); /* default_use_brute */ - prop = RNA_def_property(srna, "default_use_mask", PROP_BOOLEAN, PROP_NONE); + prop = RNA_def_property(srna, "use_default_mask", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "default_algorithm_flag", TRACK_ALGORITHM_FLAG_USE_MASK); RNA_def_property_ui_text(prop, "Use Mask", "Use a grease pencil datablock as a mask to use only specified areas of pattern when tracking"); RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL); /* default_use_normalization */ - prop = RNA_def_property(srna, "default_use_normalization", PROP_BOOLEAN, PROP_NONE); + prop = RNA_def_property(srna, "use_default_normalization", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "default_algorithm_flag", TRACK_ALGORITHM_FLAG_USE_NORMALIZATION); RNA_def_property_ui_text(prop, "Normalize", "Normalize light intensities while tracking (slower)"); RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL); @@ -814,6 +828,8 @@ static void rna_def_trackingMarker(BlenderRNA *brna) StructRNA *srna; PropertyRNA *prop; + static int boundbox_dimsize[] = {2, 2}; + srna = RNA_def_struct(brna, "MovieTrackingMarker", NULL); RNA_def_struct_ui_text(srna, "Movie tracking marker data", "Match-moving marker data for tracking"); @@ -849,6 +865,12 @@ static void rna_def_trackingMarker(BlenderRNA *brna) "normalized coordinates relative to marker position"); RNA_def_property_update(prop, NC_MOVIECLIP | NA_EDITED, "rna_tracking_markerPattern_update"); + prop = RNA_def_property(srna, "pattern_bound_box", PROP_FLOAT, PROP_NONE); + RNA_def_property_multi_array(prop, 2, boundbox_dimsize); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_float_funcs(prop, "rna_tracking_markerPattern_boundbox_get", NULL, NULL); + RNA_def_property_ui_text(prop, "Pattern Bounding Box", "Pattern area bounding box in normalized coordinates"); + /* search */ prop = RNA_def_property(srna, "search_min", PROP_FLOAT, PROP_TRANSLATION); RNA_def_property_array(prop, 2); @@ -887,6 +909,8 @@ static void rna_def_trackingMarkers(BlenderRNA *brna, PropertyRNA *cprop) parm = RNA_def_int(func, "frame", 1, MINFRAME, MAXFRAME, "Frame", "Frame number to find marker for", MINFRAME, MAXFRAME); RNA_def_property_flag(parm, PROP_REQUIRED); + parm = RNA_def_boolean(func, "exact", TRUE, "Exact", + "Get marker at exact frame number rather than get estimated marker"); parm = RNA_def_pointer(func, "marker", "MovieTrackingMarker", "", "Marker for specified frame"); RNA_def_function_return(func, parm); diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index 119c37484f0..4d4e520d5b2 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -2552,11 +2552,16 @@ static void rna_def_userdef_view(BlenderRNA *brna) RNA_def_property_boolean_sdna(prop, NULL, "uiflag", USER_LOCKAROUND); RNA_def_property_ui_text(prop, "Global Pivot", "Lock the same rotation/scaling pivot in all 3D Views"); - prop = RNA_def_property(srna, "use_mouse_auto_depth", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "uiflag", USER_ORBIT_ZBUF); + prop = RNA_def_property(srna, "use_mouse_depth_navigate", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "uiflag", USER_ZBUF_ORBIT); RNA_def_property_ui_text(prop, "Auto Depth", "Use the depth under the mouse to improve view pan/rotate/zoom functionality"); + prop = RNA_def_property(srna, "use_mouse_depth_cursor", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "uiflag", USER_ZBUF_CURSOR); + RNA_def_property_ui_text(prop, "Cursor Depth", + "Use the depth under the mouse when placing the cursor"); + prop = RNA_def_property(srna, "use_camera_lock_parent", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_negative_sdna(prop, NULL, "uiflag", USER_CAM_LOCK_NO_PARENT); RNA_def_property_ui_text(prop, "Camera Parent Lock", @@ -3460,7 +3465,7 @@ static void rna_def_userdef_filepaths(BlenderRNA *brna) StructRNA *srna; static EnumPropertyItem anim_player_presets[] = { - /*{0, "INTERNAL", 0, "Internal", "Built-in animation player"}, *//* doesn't work yet! */ + {0, "INTERNAL", 0, "Internal", "Built-in animation player"}, {1, "BLENDER24", 0, "Blender 2.4", "Blender command line animation playback - path to Blender 2.4"}, {2, "DJV", 0, "Djv", "Open source frame player: http://djv.sourceforge.net"}, {3, "FRAMECYCLER", 0, "FrameCycler", "Frame player from IRIDAS"}, diff --git a/source/blender/makesrna/intern/rna_vfont.c b/source/blender/makesrna/intern/rna_vfont.c index aca25252d2e..ff9469550d9 100644 --- a/source/blender/makesrna/intern/rna_vfont.c +++ b/source/blender/makesrna/intern/rna_vfont.c @@ -24,7 +24,6 @@ * \ingroup RNA */ - #include <stdlib.h> #include "RNA_define.h" @@ -33,8 +32,37 @@ #include "DNA_vfont_types.h" +#include "WM_types.h" + + #ifdef RNA_RUNTIME +#include "BKE_font.h" +#include "BKE_depsgraph.h" +#include "DNA_object_types.h" + +#include "WM_api.h" + +/* matching fnction in rna_ID.c */ +static int rna_VectorFont_filepath_editable(PointerRNA *ptr) +{ + VFont *vfont = ptr->id.data; + if (BKE_vfont_is_builtin(vfont)) { + return FALSE; + } + return TRUE; +} + +static void rna_VectorFont_reload_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr) +{ + VFont *vf = ptr->id.data; + BKE_vfont_free_data(vf); + + /* update */ + WM_main_add_notifier(NC_GEOM | ND_DATA, NULL); + DAG_id_tag_update(&vf->id, OB_RECALC_OB | OB_RECALC_DATA); +} + #else void RNA_def_vfont(BlenderRNA *brna) @@ -48,9 +76,10 @@ void RNA_def_vfont(BlenderRNA *brna) RNA_def_struct_ui_icon(srna, ICON_FILE_FONT); prop = RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH); - RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_string_sdna(prop, NULL, "name"); + RNA_def_property_editable_func(prop, "rna_VectorFont_filepath_editable"); RNA_def_property_ui_text(prop, "File Path", ""); + RNA_def_property_update(prop, NC_GEOM | ND_DATA, "rna_VectorFont_reload_update"); prop = RNA_def_property(srna, "packed_file", PROP_POINTER, PROP_NONE); RNA_def_property_pointer_sdna(prop, NULL, "packedfile"); @@ -58,4 +87,3 @@ void RNA_def_vfont(BlenderRNA *brna) } #endif - diff --git a/source/blender/modifiers/intern/MOD_cloth.c b/source/blender/modifiers/intern/MOD_cloth.c index 2c38bc42a8f..dc6fef9b617 100644 --- a/source/blender/modifiers/intern/MOD_cloth.c +++ b/source/blender/modifiers/intern/MOD_cloth.c @@ -169,7 +169,7 @@ static void freeData(ModifierData *md) ClothModifierData *clmd = (ClothModifierData *) md; if (clmd) { - if (G.rt > 0) + if (G.debug_value > 0) printf("clothModifier_freeData\n"); cloth_free_modifier_extern(clmd); diff --git a/source/blender/modifiers/intern/MOD_collision.c b/source/blender/modifiers/intern/MOD_collision.c index 45296e322b5..b9384e6208e 100644 --- a/source/blender/modifiers/intern/MOD_collision.c +++ b/source/blender/modifiers/intern/MOD_collision.c @@ -132,7 +132,7 @@ static void deformVerts(ModifierData *md, Object *ob, current_time = BKE_scene_frame_get(md->scene); - if (G.rt > 0) + if (G.debug_value > 0) printf("current_time %f, collmd->time_xnew %f\n", current_time, collmd->time_xnew); numverts = dm->getNumVerts(dm); diff --git a/source/blender/modifiers/intern/MOD_meshdeform.c b/source/blender/modifiers/intern/MOD_meshdeform.c index 12209fd69fb..aafb21b3c34 100644 --- a/source/blender/modifiers/intern/MOD_meshdeform.c +++ b/source/blender/modifiers/intern/MOD_meshdeform.c @@ -274,7 +274,7 @@ static void meshdeformModifier_do( /* get cage vertex in world space with binding transform */ copy_v3_v3(co, cagecos[a]); - if (G.rt != 527) { + if (G.debug_value != 527) { mul_m4_v3(mmd->bindmat, co); /* compute difference with world space bind coord */ sub_v3_v3v3(dco[a], co, bindcagecos[a]); @@ -324,7 +324,7 @@ static void meshdeformModifier_do( if (totweight > 0.0f) { mul_v3_fl(co, fac / totweight); mul_m3_v3(icagemat, co); - if (G.rt != 527) + if (G.debug_value != 527) add_v3_v3(vertexCos[b], co); else copy_v3_v3(vertexCos[b], co); diff --git a/source/blender/modifiers/intern/MOD_skin.c b/source/blender/modifiers/intern/MOD_skin.c index 0eacfd392b9..222f13185ea 100644 --- a/source/blender/modifiers/intern/MOD_skin.c +++ b/source/blender/modifiers/intern/MOD_skin.c @@ -69,6 +69,7 @@ #include "BLI_heap.h" #include "BLI_listbase.h" #include "BLI_math.h" +#include "BLI_stack.h" #include "BLI_string.h" #include "BKE_cdderivedmesh.h" @@ -634,71 +635,107 @@ static void calc_edge_mat(float mat[3][3], const float a[3], const float b[3]) } } -static void build_emats_rec(int *visited_e, EMat *emat, - const MeshElemMap *emap, const MEdge *medge, - const MVertSkin *vs, const MVert *mvert, - int parent_v, float parent_mat[3][3]) +typedef struct { + float mat[3][3]; + int parent_v; + int e; +} EdgeStackElem; + +static void build_emats_stack(BLI_Stack *stack, int *visited_e, EMat *emat, + const MeshElemMap *emap, const MEdge *medge, + const MVertSkin *vs, const MVert *mvert) { + EdgeStackElem stack_elem; float axis[3], angle; - int i, e, v, parent_is_branch; + int i, e, v, parent_v, parent_is_branch; - parent_is_branch = ((emap[parent_v].count > 2) || - (vs[parent_v].flag & MVERT_SKIN_ROOT)); + BLI_stack_pop(stack, &stack_elem); + parent_v = stack_elem.parent_v; + e = stack_elem.e; - for (i = 0; i < emap[parent_v].count; i++) { - e = emap[parent_v].indices[i]; + /* Skip if edge already visited */ + if (visited_e[e]) + return; - /* Ignore edge if already visited */ - if (visited_e[e]) continue; - visited_e[e] = 1; + /* Mark edge as visited */ + visited_e[e] = TRUE; + + /* Process edge */ - v = BKE_mesh_edge_other_vert(&medge[e], parent_v); - emat[e].origin = parent_v; + parent_is_branch = ((emap[parent_v].count > 2) || + (vs[parent_v].flag & MVERT_SKIN_ROOT)); - /* If parent is a branch node, start a new edge chain */ - if (parent_is_branch) { - calc_edge_mat(emat[e].mat, mvert[parent_v].co, - mvert[v].co); - } - else { - /* Build edge matrix guided by parent matrix */ - sub_v3_v3v3(emat[e].mat[0], mvert[v].co, mvert[parent_v].co); - normalize_v3(emat[e].mat[0]); - angle = angle_normalized_v3v3(parent_mat[0], emat[e].mat[0]); - cross_v3_v3v3(axis, parent_mat[0], emat[e].mat[0]); - normalize_v3(axis); - rotate_normalized_v3_v3v3fl(emat[e].mat[1], parent_mat[1], axis, angle); - rotate_normalized_v3_v3v3fl(emat[e].mat[2], parent_mat[2], axis, angle); - } + v = BKE_mesh_edge_other_vert(&medge[e], parent_v); + emat[e].origin = parent_v; + + /* If parent is a branch node, start a new edge chain */ + if (parent_is_branch) { + calc_edge_mat(emat[e].mat, mvert[parent_v].co, + mvert[v].co); + } + else { + /* Build edge matrix guided by parent matrix */ + sub_v3_v3v3(emat[e].mat[0], mvert[v].co, mvert[parent_v].co); + normalize_v3(emat[e].mat[0]); + angle = angle_normalized_v3v3(stack_elem.mat[0], emat[e].mat[0]); + cross_v3_v3v3(axis, stack_elem.mat[0], emat[e].mat[0]); + normalize_v3(axis); + rotate_normalized_v3_v3v3fl(emat[e].mat[1], stack_elem.mat[1], axis, angle); + rotate_normalized_v3_v3v3fl(emat[e].mat[2], stack_elem.mat[2], axis, angle); + } - build_emats_rec(visited_e, emat, emap, medge, - vs, mvert, v, emat[e].mat); + /* Add neighbors to stack */ + for (i = 0; i < emap[v].count; i++) { + /* Add neighbors to stack */ + memcpy(stack_elem.mat, emat[e].mat, sizeof(float) * 3 * 3); + stack_elem.e = emap[v].indices[i]; + stack_elem.parent_v = v; + BLI_stack_push(stack, &stack_elem); } } -static EMat *build_edge_mats(MVertSkin *vs, MVert *mvert, int totvert, - MEdge *medge, MeshElemMap *emap, int totedge) +static EMat *build_edge_mats(const MVertSkin *vs, + const MVert *mvert, + int totvert, + const MEdge *medge, + const MeshElemMap *emap, + int totedge) { + BLI_Stack *stack; EMat *emat; - float mat[3][3]; - int *visited_e, v; + EdgeStackElem stack_elem; + int *visited_e, i, v; + + stack = BLI_stack_new(sizeof(stack_elem), "build_edge_mats.stack"); visited_e = MEM_callocN(sizeof(int) * totedge, "build_edge_mats.visited_e"); emat = MEM_callocN(sizeof(EMat) * totedge, "build_edge_mats.emat"); - /* Build edge matrices recursively from the root nodes */ + /* Edge matrices are built from the root nodes, add all roots with + * children to the stack */ for (v = 0; v < totvert; v++) { if (vs[v].flag & MVERT_SKIN_ROOT) { if (emap[v].count >= 1) { const MEdge *e = &medge[emap[v].indices[0]]; - calc_edge_mat(mat, mvert[v].co, + calc_edge_mat(stack_elem.mat, mvert[v].co, mvert[BKE_mesh_edge_other_vert(e, v)].co); - build_emats_rec(visited_e, emat, emap, medge, vs, mvert, v, mat); + stack_elem.parent_v = v; + + /* Add adjacent edges to stack */ + for (i = 0; i < emap[v].count; i++) { + stack_elem.e = emap[v].indices[i]; + BLI_stack_push(stack, &stack_elem); + } } } } + while (!BLI_stack_empty(stack)) { + build_emats_stack(stack, visited_e, emat, emap, medge, vs, mvert); + } + MEM_freeN(visited_e); + BLI_stack_free(stack); return emat; } diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt index e8dd4acb63b..d95751af82f 100644 --- a/source/blender/nodes/CMakeLists.txt +++ b/source/blender/nodes/CMakeLists.txt @@ -74,6 +74,7 @@ set(SRC composite/nodes/node_composite_huecorrect.c composite/nodes/node_composite_idMask.c composite/nodes/node_composite_image.c + composite/nodes/node_composite_inpaint.c composite/nodes/node_composite_invert.c composite/nodes/node_composite_keyingscreen.c composite/nodes/node_composite_keying.c diff --git a/source/blender/nodes/NOD_composite.h b/source/blender/nodes/NOD_composite.h index 3b4fa49ea05..92e547288c9 100644 --- a/source/blender/nodes/NOD_composite.h +++ b/source/blender/nodes/NOD_composite.h @@ -80,6 +80,7 @@ void register_node_type_cmp_dblur(struct bNodeTreeType *ttype); void register_node_type_cmp_bilateralblur(struct bNodeTreeType *ttype); void register_node_type_cmp_vecblur(struct bNodeTreeType *ttype); void register_node_type_cmp_dilateerode(struct bNodeTreeType *ttype); +void register_node_type_cmp_inpaint(struct bNodeTreeType *ttype); void register_node_type_cmp_defocus(struct bNodeTreeType *ttype); void register_node_type_cmp_valtorgb(struct bNodeTreeType *ttype); diff --git a/source/blender/nodes/composite/node_composite_tree.c b/source/blender/nodes/composite/node_composite_tree.c index 18ab3b7d6d1..c6ad97c31da 100644 --- a/source/blender/nodes/composite/node_composite_tree.c +++ b/source/blender/nodes/composite/node_composite_tree.c @@ -50,6 +50,7 @@ #include "BKE_tracking.h" #include "BKE_utildefines.h" +#include "node_common.h" #include "node_exec.h" #include "node_util.h" @@ -247,6 +248,8 @@ static void local_merge(bNodeTree *localtree, bNodeTree *ntree) static void update(bNodeTree *ntree) { ntreeSetOutput(ntree); + + ntree_update_reroute_nodes(ntree); } bNodeTreeType ntreeType_Composite = { @@ -689,7 +692,7 @@ void *COM_linker_hack = NULL; void ntreeCompositExecTree(bNodeTree *ntree, RenderData *rd, int rendering, int do_preview) { #ifdef WITH_COMPOSITOR - if (G.rt == 200) + if (G.debug_value == 200) ntreeCompositExecTreeOld(ntree, rd, do_preview); else COM_execute(rd, ntree, rendering); diff --git a/source/blender/nodes/composite/nodes/node_composite_defocus.c b/source/blender/nodes/composite/nodes/node_composite_defocus.c index d9ee067efe3..280ff56be12 100644 --- a/source/blender/nodes/composite/nodes/node_composite_defocus.c +++ b/source/blender/nodes/composite/nodes/node_composite_defocus.c @@ -166,17 +166,17 @@ static void IIR_gauss_single(CompBuf *buf, float sigma) // see "Recursive Gabor Filtering" by Young/VanVliet // all factors here in double.prec. Required, because for single.prec it seems to blow up if sigma > ~200 if (sigma >= 3.556f) - q = 0.9804f*(sigma - 3.556f) + 2.5091f; + q = 0.9804f * (sigma - 3.556f) + 2.5091f; else // sigma >= 0.5 - q = (0.0561f*sigma + 0.5784f)*sigma - 0.2568f; - q2 = q*q; - sc = (1.1668 + q)*(3.203729649 + (2.21566 + q)*q); + q = (0.0561f * sigma + 0.5784f) * sigma - 0.2568f; + q2 = q * q; + sc = (1.1668 + q) * (3.203729649 + (2.21566 + q) * q); // no gabor filtering here, so no complex multiplies, just the regular coefs. // all negated here, so as not to have to recalc Triggs/Sdika matrix - cf[1] = q*(5.788961737 + (6.76492 + 3.0*q)*q)/ sc; - cf[2] = -q2*(3.38246 + 3.0*q)/sc; + cf[1] = q * (5.788961737 + (6.76492 + 3.0 * q) * q) / sc; + cf[2] = -q2 * (3.38246 + 3.0 * q) / sc; // 0 & 3 unchanged - cf[3] = q2*q/sc; + cf[3] = q2 * q / sc; cf[0] = 1.0 - cf[1] - cf[2] - cf[3]; // Triggs/Sdika border corrections, @@ -254,6 +254,7 @@ static void defocus_blur(bNode *node, CompBuf *new, CompBuf *img, CompBuf *zbuf, BokehCoeffs BKH[8]; // bokeh shape data, here never > 8 pts. float bkh_b[4] = {0}; // shape 2D bound float cam_fdist=1, cam_invfdist=1, cam_lens=35; + float cam_sensor = DEFAULT_SENSOR_WIDTH; float dof_sp, maxfgc, bk_hn_theta=0, inradsq=0; int y, len_bkh=0, ydone = FALSE; float aspect, aperture; @@ -268,17 +269,17 @@ static void defocus_blur(bNode *node, CompBuf *new, CompBuf *img, CompBuf *zbuf, Camera* cam = (Camera*)camob->data; cam_lens = cam->lens; cam_fdist = BKE_camera_object_dof_distance(camob); - if (cam_fdist==0.0f) cam_fdist = 1e10f; /* if the dof is 0.0 then set it be be far away */ - cam_invfdist = 1.f/cam_fdist; + cam_sensor = BKE_camera_sensor_size(cam->sensor_fit, cam->sensor_x, cam->sensor_y); + if (cam_fdist == 0.0f) cam_fdist = 1e10f; /* if the dof is 0.0 then set it be be far away */ + cam_invfdist = 1.f / cam_fdist; } - // guess work here.. best match with raytraced result minsz = MIN2(img->x, img->y); - dof_sp = (float)minsz / (16.f / cam_lens); // <- == aspect * MIN2(img->x, img->y) / tan(0.5f * fov); + dof_sp = (float)minsz / ((cam_sensor / 2.0f) / cam_lens); // <- == aspect * MIN2(img->x, img->y) / tan(0.5f * fov); // aperture aspect = (img->x > img->y) ? (img->y / (float)img->x) : (img->x / (float)img->y); - aperture = 0.5f*(cam_lens / (aspect*32.f)) / nqd->fstop; + aperture = 0.5f * (cam_lens / (aspect * cam_sensor)) / nqd->fstop; // if not disk, make bokeh coefficients and other needed data if (nqd->bktype!=0) { @@ -336,7 +337,7 @@ static void defocus_blur(bNode *node, CompBuf *new, CompBuf *img, CompBuf *zbuf, // fast blur... // bug #6656 part 1, probably when previous node_composite.c was split into separate files, it was not properly updated // to include recent cvs commits (well, at least not defocus node), so this part was missing... - wt = aperture*128.f; + wt = minf(nqd->maxblur, aperture * 128.0f); IIR_gauss_single(crad, wt); IIR_gauss_single(wts, wt); diff --git a/source/blender/nodes/composite/nodes/node_composite_inpaint.c b/source/blender/nodes/composite/nodes/node_composite_inpaint.c new file mode 100644 index 00000000000..dc4177bd2a4 --- /dev/null +++ b/source/blender/nodes/composite/nodes/node_composite_inpaint.c @@ -0,0 +1,61 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2006 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/nodes/composite/nodes/node_composite_inpaint.c + * \ingroup cmpnodes + */ + + +#include "node_composite_util.h" + + +/* **************** Inpaint/ ******************** */ + +static bNodeSocketTemplate cmp_node_inpaint_in[] = { + {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, + { -1, 0, "" } +}; +static bNodeSocketTemplate cmp_node_inpaint_out[] = { + {SOCK_RGBA, 0, N_("Image")}, + { -1, 0, "" } +}; + +static void node_composit_exec_inpaint(void *UNUSED(data), bNode *UNUSED(node), bNodeStack **UNUSED(in), bNodeStack **UNUSED(out)) +{ +} + +void register_node_type_cmp_inpaint(bNodeTreeType *ttype) +{ + static bNodeType ntype; + + node_type_base(ttype, &ntype, CMP_NODE_INPAINT, "Inpaint", NODE_CLASS_OP_FILTER, NODE_OPTIONS); + node_type_socket_templates(&ntype, cmp_node_inpaint_in, cmp_node_inpaint_out); + node_type_size(&ntype, 130, 100, 320); + node_type_exec(&ntype, node_composit_exec_inpaint); + + nodeRegisterType(ttype, &ntype); +} diff --git a/source/blender/nodes/composite/nodes/node_composite_outputFile.c b/source/blender/nodes/composite/nodes/node_composite_outputFile.c index fd312d71f2c..8a0d7200079 100644 --- a/source/blender/nodes/composite/nodes/node_composite_outputFile.c +++ b/source/blender/nodes/composite/nodes/node_composite_outputFile.c @@ -391,7 +391,7 @@ static void exec_output_file(void *data, bNode *node, bNodeStack **in, bNodeStac RenderData *rd= data; NodeImageMultiFile *nimf= node->storage; - if (!G.rendering) { + if (G.is_rendering == FALSE) { /* only output files when rendering a sequence - * otherwise, it overwrites the output files just * scrubbing through the timeline when the compositor updates */ diff --git a/source/blender/nodes/intern/node_common.c b/source/blender/nodes/intern/node_common.c index 150bede4b7c..8e550ef3d4b 100644 --- a/source/blender/nodes/intern/node_common.c +++ b/source/blender/nodes/intern/node_common.c @@ -547,15 +547,6 @@ void register_node_type_frame(bNodeTreeType *ttype) /* **************** REROUTE ******************** */ -static bNodeSocketTemplate node_reroute_in[]= { - { SOCK_RGBA, 1, "Input", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; -static bNodeSocketTemplate node_reroute_out[]= { - { SOCK_RGBA, 0, "Output", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, - { -1, 0, "" } -}; - /* simple, only a single input and output here */ static ListBase node_reroute_internal_connect(bNodeTree *ntree, bNode *node) { @@ -580,33 +571,83 @@ static ListBase node_reroute_internal_connect(bNodeTree *ntree, bNode *node) return ret; } -static void node_reroute_update(bNodeTree *UNUSED(ntree), bNode *node) +static void node_reroute_init(bNodeTree *ntree, bNode* node, bNodeTemplate *UNUSED(ntemp)) +{ + /* Note: Cannot use socket templates for this, since it would reset the socket type + * on each file read via the template verification procedure. + */ + nodeAddSocket(ntree, node, SOCK_IN, "Input", SOCK_RGBA); + nodeAddSocket(ntree, node, SOCK_OUT, "Output", SOCK_RGBA); +} + +void register_node_type_reroute(bNodeTreeType *ttype) +{ + /* frame type is used for all tree types, needs dynamic allocation */ + bNodeType *ntype= MEM_callocN(sizeof(bNodeType), "frame node type"); + + node_type_base(ttype, ntype, NODE_REROUTE, "Reroute", NODE_CLASS_LAYOUT, 0); + node_type_init(ntype, node_reroute_init); + node_type_internal_connect(ntype, node_reroute_internal_connect); + + ntype->needs_free = 1; + nodeRegisterType(ttype, ntype); +} + +static void node_reroute_inherit_type_recursive(bNodeTree *ntree, bNode *node) { bNodeSocket *input = node->inputs.first; bNodeSocket *output = node->outputs.first; int type = SOCK_FLOAT; + bNodeLink *link; + + /* XXX it would be a little bit more efficient to restrict actual updates + * to rerout nodes connected to an updated node, but there's no reliable flag + * to indicate updated nodes (node->update is not set on linking). + */ + + node->done = 1; + + /* recursive update */ + for (link = ntree->links.first; link; link = link->next) + { + bNode *fromnode = link->fromnode; + bNode *tonode = link->tonode; + if (!tonode || !fromnode) + continue; + + if (tonode == node && fromnode->type == NODE_REROUTE && !fromnode->done) + node_reroute_inherit_type_recursive(ntree, fromnode); + + if (fromnode == node && tonode->type == NODE_REROUTE && !tonode->done) + node_reroute_inherit_type_recursive(ntree, tonode); + } /* determine socket type from unambiguous input/output connection if possible */ if (input->limit==1 && input->link) type = input->link->fromsock->type; else if (output->limit==1 && output->link) - type = output->link->tosock->type; + type = output->link->tosock->type; - /* same type for input/output */ - nodeSocketSetType(input, type); - nodeSocketSetType(output, type); + /* arbitrary, could also test output->type, both are the same */ + if (input->type != type) { + /* same type for input/output */ + nodeSocketSetType(input, type); + nodeSocketSetType(output, type); + } } -void register_node_type_reroute(bNodeTreeType *ttype) +/* Global update function for Reroute node types. + * This depends on connected nodes, so must be done as a tree-wide update. + */ +void ntree_update_reroute_nodes(bNodeTree *ntree) { - /* frame type is used for all tree types, needs dynamic allocation */ - bNodeType *ntype= MEM_callocN(sizeof(bNodeType), "frame node type"); + bNode *node; - node_type_base(ttype, ntype, NODE_REROUTE, "Reroute", NODE_CLASS_LAYOUT, 0); - node_type_socket_templates(ntype, node_reroute_in, node_reroute_out); - node_type_internal_connect(ntype, node_reroute_internal_connect); - node_type_update(ntype, node_reroute_update, NULL); + /* clear tags */ + for (node = ntree->nodes.first; node; node = node->next) + node->done = 0; - ntype->needs_free = 1; - nodeRegisterType(ttype, ntype); + for (node = ntree->nodes.first; node; node = node->next) + if (node->type == NODE_REROUTE && !node->done) + node_reroute_inherit_type_recursive(ntree, node); } diff --git a/source/blender/nodes/intern/node_common.h b/source/blender/nodes/intern/node_common.h index f1bb837e483..00f72469b0f 100644 --- a/source/blender/nodes/intern/node_common.h +++ b/source/blender/nodes/intern/node_common.h @@ -59,4 +59,6 @@ void node_group_edit_clear(bNode *node); void node_loop_update_tree(struct bNodeTree *ngroup); +void ntree_update_reroute_nodes(struct bNodeTree *ntree); + #endif diff --git a/source/blender/nodes/intern/node_util.c b/source/blender/nodes/intern/node_util.c index 548a21ee35b..8f9214fa1b2 100644 --- a/source/blender/nodes/intern/node_util.c +++ b/source/blender/nodes/intern/node_util.c @@ -29,6 +29,7 @@ * \ingroup nodes */ +#include <limits.h> #include "DNA_action_types.h" #include "DNA_node_types.h" @@ -116,42 +117,58 @@ ListBase node_internal_connect_default(bNodeTree *ntree, bNode *node) return ret; for (datatype=0; datatype < NUM_SOCKET_TYPES; ++datatype) { - bNodeSocket *fromsock=NULL, *tosock=NULL; + bNodeSocket *fromsock, *tosock; + int fromindex, toindex; bNodeLink *link; /* Connect the first input of each type with outputs of the same type. */ + fromindex = INT_MAX; + fromsock = NULL; for (link=ntree->links.first; link; link=link->next) { if (link->tonode == node && link->tosock->type == datatype) { - fromsock = link->tosock; - ++num_links_in; - if (!fromsock_first) - fromsock_first = fromsock; - break; + int index = BLI_findindex(&node->inputs, link->tosock); + if (index < fromindex) { + fromindex = index; + fromsock = link->tosock; + } } } + if (fromsock) { + ++num_links_in; + if (!fromsock_first) + fromsock_first = fromsock; + } + toindex = INT_MAX; + tosock = NULL; for (link=ntree->links.first; link; link=link->next) { if (link->fromnode == node && link->fromsock->type == datatype) { - tosock = link->fromsock; - ++num_links_out; - if (!tosock_first) - tosock_first = tosock; - - if (fromsock) { - bNodeLink *ilink = MEM_callocN(sizeof(bNodeLink), "internal node link"); - ilink->fromnode = node; - ilink->fromsock = fromsock; - ilink->tonode = node; - ilink->tosock = tosock; - /* internal link is always valid */ - ilink->flag |= NODE_LINK_VALID; - BLI_addtail(&ret, ilink); - - ++num_reconnect; + int index = BLI_findindex(&node->outputs, link->fromsock); + if (index < toindex) { + toindex = index; + tosock = link->fromsock; } } } + if (tosock) { + ++num_links_out; + if (!tosock_first) + tosock_first = tosock; + + if (fromsock) { + bNodeLink *ilink = MEM_callocN(sizeof(bNodeLink), "internal node link"); + ilink->fromnode = node; + ilink->fromsock = fromsock; + ilink->tonode = node; + ilink->tosock = tosock; + /* internal link is always valid */ + ilink->flag |= NODE_LINK_VALID; + BLI_addtail(&ret, ilink); + + ++num_reconnect; + } + } } /* if there is one input and one output link, but no reconnections by type, diff --git a/source/blender/nodes/shader/node_shader_tree.c b/source/blender/nodes/shader/node_shader_tree.c index a1d873231e7..fa623eaad3d 100644 --- a/source/blender/nodes/shader/node_shader_tree.c +++ b/source/blender/nodes/shader/node_shader_tree.c @@ -55,6 +55,7 @@ #include "RE_shader_ext.h" +#include "node_common.h" #include "node_exec.h" #include "node_util.h" #include "node_shader_util.h" @@ -133,6 +134,8 @@ static void local_sync(bNodeTree *localtree, bNodeTree *ntree) static void update(bNodeTree *ntree) { ntreeSetOutput(ntree); + + ntree_update_reroute_nodes(ntree); } bNodeTreeType ntreeType_Shader = { diff --git a/source/blender/nodes/texture/node_texture_tree.c b/source/blender/nodes/texture/node_texture_tree.c index 1a11a7075b8..063cc31e6f6 100644 --- a/source/blender/nodes/texture/node_texture_tree.c +++ b/source/blender/nodes/texture/node_texture_tree.c @@ -45,6 +45,7 @@ #include "BKE_main.h" #include "BKE_node.h" +#include "node_common.h" #include "node_exec.h" #include "node_util.h" #include "NOD_texture.h" @@ -112,6 +113,11 @@ static void local_sync(bNodeTree *localtree, bNodeTree *ntree) } } +static void update(bNodeTree *ntree) +{ + ntree_update_reroute_nodes(ntree); +} + bNodeTreeType ntreeType_Texture = { /* type */ NTREE_TEXTURE, /* id_name */ "NTTexture Nodetree", @@ -125,7 +131,7 @@ bNodeTreeType ntreeType_Texture = { /* localize */ localize, /* local_sync */ local_sync, /* local_merge */ NULL, - /* update */ NULL, + /* update */ update, /* update_node */ NULL, /* validate_link */ NULL, /* internal_connect */ node_internal_connect_default diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c index 2867cba8129..9270aec8d95 100644 --- a/source/blender/python/bmesh/bmesh_py_types.c +++ b/source/blender/python/bmesh/bmesh_py_types.c @@ -2155,10 +2155,10 @@ static PyObject *bpy_bmelemseq_sort(BPy_BMElemSeq *self, PyObject *args, PyObjec BPY_BM_CHECK_OBJ(self); if (args != NULL) { - if(!PyArg_ParseTupleAndKeywords(args, kw, - "|Oi:BMElemSeq.sort", - (char **)kwlist, - &keyfunc, &reverse)) + if (!PyArg_ParseTupleAndKeywords(args, kw, + "|Oi:BMElemSeq.sort", + (char **)kwlist, + &keyfunc, &reverse)) return NULL; } diff --git a/source/blender/python/intern/bpy_app.c b/source/blender/python/intern/bpy_app.c index 44979700d94..ccce0d8c5ae 100644 --- a/source/blender/python/intern/bpy_app.c +++ b/source/blender/python/intern/bpy_app.c @@ -195,7 +195,7 @@ PyDoc_STRVAR(bpy_app_debug_value_doc, ); static PyObject *bpy_app_debug_value_get(PyObject *UNUSED(self), void *UNUSED(closure)) { - return PyLong_FromSsize_t(G.rt); + return PyLong_FromSsize_t(G.debug_value); } static int bpy_app_debug_value_set(PyObject *UNUSED(self), PyObject *value, void *UNUSED(closure)) @@ -207,7 +207,7 @@ static int bpy_app_debug_value_set(PyObject *UNUSED(self), PyObject *value, void return -1; } - G.rt = param; + G.debug_value = param; return 0; } diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index 93f49fd72c9..aa9d81389da 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -639,7 +639,7 @@ void BPY_modules_load_user(bContext *C) bpy_context_set(C, &gilstate); - for (text = CTX_data_main(C)->text.first; text; text = text->id.next) { + for (text = bmain->text.first; text; text = text->id.next) { if (text->flags & TXT_ISSCRIPT && BLI_testextensie(text->id.name + 2, ".py")) { if (!(G.f & G_SCRIPT_AUTOEXEC)) { printf("scripts disabled for \"%s\", skipping '%s'\n", bmain->name, text->id.name + 2); diff --git a/source/blender/python/intern/bpy_props.c b/source/blender/python/intern/bpy_props.c index a781dbb33b5..abf609cd235 100644 --- a/source/blender/python/intern/bpy_props.c +++ b/source/blender/python/intern/bpy_props.c @@ -1298,9 +1298,8 @@ static PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw) eitems = enum_items_from_py(items_fast, def, &defvalue, (opts & PROP_ENUM_FLAG) != 0); - Py_DECREF(items_fast); - if (!eitems) { + Py_DECREF(items_fast); return NULL; } } @@ -1327,6 +1326,10 @@ static PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw) RNA_def_property_duplicate_pointers(srna, prop); if (is_itemf == FALSE) { + /* note: this must be postponed until after #RNA_def_property_duplicate_pointers + * otherwise if this is a generator it may free the strings before we copy them */ + Py_DECREF(items_fast); + MEM_freeN(eitems); } } diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 03e20322a59..bd660ae0001 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -435,7 +435,7 @@ static int mathutils_rna_vector_set(BaseMathObject *bmo, int subtype) RNA_property_float_range(&self->ptr, self->prop, &min, &max); - if (min != FLT_MIN || max != FLT_MAX) { + if (min != -FLT_MAX || max != FLT_MAX) { int i, len = RNA_property_array_length(&self->ptr, self->prop); for (i = 0; i < len; i++) { CLAMP(bmo->data[i], min, max); diff --git a/source/blender/render/extern/include/RE_render_ext.h b/source/blender/render/extern/include/RE_render_ext.h index 9d7393f9414..604cd940fab 100644 --- a/source/blender/render/extern/include/RE_render_ext.h +++ b/source/blender/render/extern/include/RE_render_ext.h @@ -58,7 +58,7 @@ void texture_rgb_blend(float in[3], const float tex[3], const float out[3], floa float texture_value_blend(float tex, float out, float fact, float facg, int blendtype); /* node_composite.c */ -void ibuf_sample(struct ImBuf *ibuf, float fx, float fy, float dx, float dy, float *result); +void ibuf_sample(struct ImBuf *ibuf, float fx, float fy, float dx, float dy, float result[4]); void antialias_tagbuf(int xsize, int ysize, char *rectmove); /* dynamicpaint.c */ diff --git a/source/blender/render/intern/include/texture.h b/source/blender/render/intern/include/texture.h index 1c8a2552482..e8f171fe383 100644 --- a/source/blender/render/intern/include/texture.h +++ b/source/blender/render/intern/include/texture.h @@ -78,7 +78,7 @@ void render_realtime_texture(struct ShadeInput *shi, struct Image *ima); int imagewraposa(struct Tex *tex, struct Image *ima, struct ImBuf *ibuf, const float texvec[3], const float dxt[3], const float dyt[3], struct TexResult *texres); int imagewrap(struct Tex *tex, struct Image *ima, struct ImBuf *ibuf, const float texvec[3], struct TexResult *texres); -void image_sample(struct Image *ima, float fx, float fy, float dx, float dy, float *result); +void image_sample(struct Image *ima, float fx, float fy, float dx, float dy, float result[4]); #endif /* __TEXTURE_H__ */ diff --git a/source/blender/render/intern/include/zbuf.h b/source/blender/render/intern/include/zbuf.h index 99bde3fe02b..e4ee19d8ed2 100644 --- a/source/blender/render/intern/include/zbuf.h +++ b/source/blender/render/intern/include/zbuf.h @@ -55,7 +55,7 @@ int testclip(const float v[3]); void zbuffer_shadow(struct Render *re, float winmat[][4], struct LampRen *lar, int *rectz, int size, float jitx, float jity); void zbuffer_abuf_shadow(struct Render *re, struct LampRen *lar, float winmat[][4], struct APixstr *APixbuf, struct APixstrand *apixbuf, struct ListBase *apsmbase, int size, int samples, float (*jit)[2]); -void zbuffer_solid(struct RenderPart *pa, struct RenderLayer *rl, void (*fillfunc)(struct RenderPart*, struct ZSpan*, int, void*), void *data); +void zbuffer_solid(struct RenderPart *pa, struct RenderLayer *rl, void (*fillfunc)(struct RenderPart *, struct ZSpan *, int, void*), void *data); unsigned short *zbuffer_transp_shade(struct RenderPart *pa, struct RenderLayer *rl, float *pass, struct ListBase *psmlist); void zbuffer_sss(RenderPart *pa, unsigned int lay, void *handle, void (*func)(void*, int, int, int, int, int)); diff --git a/source/blender/render/intern/raytrace/bvh.h b/source/blender/render/intern/raytrace/bvh.h index a0d730c5b8a..103c04a590f 100644 --- a/source/blender/render/intern/raytrace/bvh.h +++ b/source/blender/render/intern/raytrace/bvh.h @@ -133,7 +133,7 @@ static void bvh_bb(Tree *obj, float *min, float *max) template<class Tree> static float bvh_cost(Tree *obj) { - assert(obj->cost >= 0.0); + assert(obj->cost >= 0.0f); return obj->cost; } diff --git a/source/blender/render/intern/raytrace/rayobject.cpp b/source/blender/render/intern/raytrace/rayobject.cpp index ca74367dd37..6f14c6153f9 100644 --- a/source/blender/render/intern/raytrace/rayobject.cpp +++ b/source/blender/render/intern/raytrace/rayobject.cpp @@ -369,12 +369,12 @@ int RE_rayobject_raycast(RayObject *r, Isect *isec) /* setup vars used on raycast */ for (i = 0; i < 3; i++) { - isec->idot_axis[i] = 1.0f / isec->dir[i]; + isec->idot_axis[i] = 1.0f / isec->dir[i]; - isec->bv_index[2 * i] = isec->idot_axis[i] < 0.0 ? 1 : 0; + isec->bv_index[2 * i] = isec->idot_axis[i] < 0.0f ? 1 : 0; isec->bv_index[2 * i + 1] = 1 - isec->bv_index[2 * i]; - isec->bv_index[2 * i] = i + 3 * isec->bv_index[2 * i]; + isec->bv_index[2 * i] = i + 3 * isec->bv_index[2 * i]; isec->bv_index[2 * i + 1] = i + 3 * isec->bv_index[2 * i + 1]; } diff --git a/source/blender/render/intern/raytrace/rayobject_instance.cpp b/source/blender/render/intern/raytrace/rayobject_instance.cpp index bfbc1c64133..c3e761ae069 100644 --- a/source/blender/render/intern/raytrace/rayobject_instance.cpp +++ b/source/blender/render/intern/raytrace/rayobject_instance.cpp @@ -118,7 +118,7 @@ static int RE_rayobject_instance_intersect(RayObject *o, Isect *isec) for (i = 0; i < 3; i++) { isec->idot_axis[i] = 1.0f / isec->dir[i]; - isec->bv_index[2 * i] = isec->idot_axis[i] < 0.0 ? 1 : 0; + isec->bv_index[2 * i] = isec->idot_axis[i] < 0.0f ? 1 : 0; isec->bv_index[2 * i + 1] = 1 - isec->bv_index[2 * i]; isec->bv_index[2 * i] = i + 3 * isec->bv_index[2 * i]; @@ -161,7 +161,7 @@ static int RE_rayobject_instance_intersect(RayObject *o, Isect *isec) // restore bv_index for (i = 0; i < 3; i++) { - isec->bv_index[2 * i] = isec->idot_axis[i] < 0.0 ? 1 : 0; + isec->bv_index[2 * i] = isec->idot_axis[i] < 0.0f ? 1 : 0; isec->bv_index[2 * i + 1] = 1 - isec->bv_index[2 * i]; isec->bv_index[2 * i] = i + 3 * isec->bv_index[2 * i]; diff --git a/source/blender/render/intern/source/convertblender.c b/source/blender/render/intern/source/convertblender.c index 451f16fc6ee..4a35c075a50 100644 --- a/source/blender/render/intern/source/convertblender.c +++ b/source/blender/render/intern/source/convertblender.c @@ -233,7 +233,7 @@ void RE_make_stars(Render *re, Scene *scenev3d, void (*initfunc)(void), obr= RE_addRenderObject(re, NULL, NULL, 0, 0, 0); for (x = sx, fx = sx * stargrid; x <= ex; x++, fx += stargrid) { - for (y = sy, fy = sy * stargrid; y <= ey ; y++, fy += stargrid) { + for (y = sy, fy = sy * stargrid; y <= ey; y++, fy += stargrid) { for (z = sz, fz = sz * stargrid; z <= ez; z++, fz += stargrid) { BLI_srand((hash[z & 0xff] << 24) + (hash[y & 0xff] << 16) + (hash[x & 0xff] << 8)); @@ -310,7 +310,7 @@ void RE_make_stars(Render *re, Scene *scenev3d, void (*initfunc)(void), totstar++; } /* do not call blender_test_break() here, since it is used in UI as well, confusing the callback system */ - /* main cause is G.afbreek of course, a global again... (ton) */ + /* main cause is G.is_break of course, a global again... (ton) */ } } if (termfunc) termfunc(); @@ -1614,7 +1614,7 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem if (part->type==PART_HAIR && !psys->childcache) totchild= 0; - if (G.rendering == 0) { /* preview render */ + if (G.is_rendering == FALSE) { /* preview render */ totchild = (int)((float)totchild * (float)part->disp / 100.0f); } @@ -3919,7 +3919,7 @@ static GroupObject *add_render_lamp(Render *re, Object *ob) if (la->mtex[c]->mapto & LAMAP_SHAD) lar->mode |= LA_SHAD_TEX; - if (G.rendering) { + if (G.is_rendering) { if (re->osa) { if (la->mtex[c]->tex->type==TEX_IMAGE) lar->mode |= LA_OSATEX; } @@ -4710,7 +4710,7 @@ void RE_Database_Free(Render *re) LampRen *lar; /* statistics for debugging render memory usage */ - if ((G.debug & G_DEBUG) && (G.rendering)) { + if ((G.debug & G_DEBUG) && (G.is_rendering)) { if ((re->r.scemode & R_PREVIEWBUTS)==0) { BKE_image_print_memlist(); MEM_printmemlist_stats(); diff --git a/source/blender/render/intern/source/envmap.c b/source/blender/render/intern/source/envmap.c index 5879a9bd66d..26bd482af69 100644 --- a/source/blender/render/intern/source/envmap.c +++ b/source/blender/render/intern/source/envmap.c @@ -476,7 +476,7 @@ static void render_envmap(Render *re, EnvMap *env) ibuf->profile = IB_PROFILE_LINEAR_RGB; /* envmap renders without alpha */ - alpha = ((float *)ibuf->rect_float) + 3; + alpha = ibuf->rect_float + 3; for (y = ibuf->x * ibuf->y - 1; y >= 0; y--, alpha += 4) *alpha = 1.0; diff --git a/source/blender/render/intern/source/external_engine.c b/source/blender/render/intern/source/external_engine.c index 1180e74d391..487271ea1f7 100644 --- a/source/blender/render/intern/source/external_engine.c +++ b/source/blender/render/intern/source/external_engine.c @@ -331,7 +331,7 @@ int RE_engine_render(Render *re, int do_all) RE_engine_free(engine); if (BKE_reports_contain(re->reports, RPT_ERROR)) - G.afbreek = 1; + G.is_break = TRUE; return 1; } diff --git a/source/blender/render/intern/source/imagetexture.c b/source/blender/render/intern/source/imagetexture.c index c4c89bd06a6..0a90a55b3bc 100644 --- a/source/blender/render/intern/source/imagetexture.c +++ b/source/blender/render/intern/source/imagetexture.c @@ -1779,11 +1779,8 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const } /* de-premul, this is being premulled in shade_input_do_shade() */ - if (texres->ta!=1.0f && texres->ta>1e-4f) { - fx= 1.0f/texres->ta; - texres->tr*= fx; - texres->tg*= fx; - texres->tb*= fx; + if (texres->ta != 1.0f && texres->ta > 1e-4f) { + mul_v3_fl(&texres->tr, 1.0f / texres->ta); } BRICONTRGB; @@ -1791,25 +1788,22 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const return retval; } -void image_sample(Image *ima, float fx, float fy, float dx, float dy, float *result) +void image_sample(Image *ima, float fx, float fy, float dx, float dy, float result[4]) { TexResult texres; ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL); - if (ibuf==NULL) { - result[0]= result[1]= result[2]= result[3]= 0.0f; + if (UNLIKELY(ibuf == NULL)) { + zero_v4(result); return; } if ( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) ) ibuf->rect+= (ibuf->x*ibuf->y); - texres.talpha= 1; /* boxsample expects to be initialized */ - boxsample(ibuf, fx, fy, fx+dx, fy+dy, &texres, 0, 1); - result[0]= texres.tr; - result[1]= texres.tg; - result[2]= texres.tb; - result[3]= texres.ta; + texres.talpha = TRUE; /* boxsample expects to be initialized */ + boxsample(ibuf, fx, fy, fx + dx, fy + dy, &texres, 0, 1); + copy_v4_v4(result, &texres.tr); if ( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) ) ibuf->rect-= (ibuf->x*ibuf->y); @@ -1817,15 +1811,11 @@ void image_sample(Image *ima, float fx, float fy, float dx, float dy, float *res ima->flag|= IMA_USED_FOR_RENDER; } -void ibuf_sample(ImBuf *ibuf, float fx, float fy, float dx, float dy, float *result) +void ibuf_sample(ImBuf *ibuf, float fx, float fy, float dx, float dy, float result[4]) { - TexResult texres; + TexResult texres = {0}; afdata_t AFD; - - if (ibuf==NULL) { - return; - } - + AFD.dxt[0] = dx; AFD.dxt[1] = dx; AFD.dyt[0] = dy; AFD.dyt[1] = dy; //copy_v2_v2(AFD.dxt, dx); @@ -1833,13 +1823,8 @@ void ibuf_sample(ImBuf *ibuf, float fx, float fy, float dx, float dy, float *res AFD.intpol = 1; AFD.extflag = TXC_EXTD; - - memset(&texres, 0, sizeof(texres)); + ewa_eval(&texres, ibuf, fx, fy, &AFD); - - result[0]= texres.tr; - result[1]= texres.tg; - result[2]= texres.tb; - result[3]= texres.ta; + copy_v4_v4(result, &texres.tr); } diff --git a/source/blender/render/intern/source/pipeline.c b/source/blender/render/intern/source/pipeline.c index 7b5a5054432..e91953a890b 100644 --- a/source/blender/render/intern/source/pipeline.c +++ b/source/blender/render/intern/source/pipeline.c @@ -141,7 +141,7 @@ static void result_nothing(void *UNUSED(arg), RenderResult *UNUSED(rr)) {} static void result_rcti_nothing(void *UNUSED(arg), RenderResult *UNUSED(rr), volatile struct rcti *UNUSED(rect)) {} static void stats_nothing(void *UNUSED(arg), RenderStats *UNUSED(rs)) {} static void float_nothing(void *UNUSED(arg), float UNUSED(val)) {} -static int default_break(void *UNUSED(arg)) {return G.afbreek == 1;} +static int default_break(void *UNUSED(arg)) { return G.is_break == TRUE; } static void stats_background(void *UNUSED(arg), RenderStats *rs) { @@ -1209,7 +1209,7 @@ static void do_render_fields_blur_3d(Render *re) /* also check for camera here */ if (camera == NULL) { printf("ERROR: Cannot render, no camera\n"); - G.afbreek = 1; + G.is_break = TRUE; return; } @@ -1574,7 +1574,7 @@ void RE_MergeFullSample(Render *re, Main *bmain, Scene *sce, bNodeTree *ntree) bNode *node; /* default start situation */ - G.afbreek = 0; + G.is_break = FALSE; re->main = bmain; re->scene = sce; @@ -1744,17 +1744,17 @@ static void do_render_seq(Render *re) if ((re->r.mode & R_BORDER) && (re->r.mode & R_CROP) == 0) { /* if border rendering is used and cropping is disabled, final buffer should * be as large as the whole frame */ - context = seq_new_render_data(re->main, re->scene, + context = BKE_sequencer_new_render_data(re->main, re->scene, re->winx, re->winy, 100); } else { - context = seq_new_render_data(re->main, re->scene, + context = BKE_sequencer_new_render_data(re->main, re->scene, re->result->rectx, re->result->recty, 100); } - ibuf = give_ibuf_seq(context, cfra, 0); + ibuf = BKE_sequencer_give_ibuf(context, cfra, 0); recurs_depth--; @@ -1769,7 +1769,7 @@ static void do_render_seq(Render *re) if (recurs_depth == 0) { /* with nested scenes, only free on toplevel... */ Editing *ed = re->scene->ed; if (ed) - free_imbuf_seq(re->scene, &ed->seqbase, TRUE, TRUE); + BKE_sequencer_free_imbuf(re->scene, &ed->seqbase, TRUE, TRUE); } IMB_freeImBuf(ibuf); } @@ -1896,8 +1896,11 @@ static int node_tree_has_composite_output(bNodeTree *ntree) return TRUE; } else if (node->type == NODE_GROUP) { - if (node_tree_has_composite_output((bNodeTree *)node->id)) - return TRUE; + if (node->id) { + if (node_tree_has_composite_output((bNodeTree *)node->id)) { + return TRUE; + } + } } } @@ -2112,7 +2115,7 @@ void RE_SetReports(Render *re, ReportList *reports) void RE_BlenderFrame(Render *re, Main *bmain, Scene *scene, SceneRenderLayer *srl, Object *camera_override, unsigned int lay, int frame, const short write_still) { /* ugly global still... is to prevent preview events and signal subsurfs etc to make full resol */ - G.rendering = 1; + G.is_rendering = TRUE; scene->r.cfra = frame; @@ -2123,7 +2126,7 @@ void RE_BlenderFrame(Render *re, Main *bmain, Scene *scene, SceneRenderLayer *sr do_render_all_options(re); - if (write_still && !G.afbreek) { + if (write_still && !G.is_break) { if (BKE_imtype_is_movie(scene->r.im_format.imtype)) { /* operator checks this but in case its called from elsewhere */ printf("Error: cant write single images with a movie format!\n"); @@ -2140,10 +2143,10 @@ void RE_BlenderFrame(Render *re, Main *bmain, Scene *scene, SceneRenderLayer *sr BLI_callback_exec(re->main, (ID *)scene, BLI_CB_EVT_RENDER_POST); /* keep after file save */ } - BLI_callback_exec(re->main, (ID *)scene, G.afbreek ? BLI_CB_EVT_RENDER_CANCEL : BLI_CB_EVT_RENDER_COMPLETE); + BLI_callback_exec(re->main, (ID *)scene, G.is_break ? BLI_CB_EVT_RENDER_CANCEL : BLI_CB_EVT_RENDER_COMPLETE); /* UGLY WARNING */ - G.rendering = 0; + G.is_rendering = FALSE; } void RE_RenderFreestyleStrokes(Render *re, Main *bmain, Scene *scene) @@ -2248,16 +2251,16 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri /* ugly global still... is to prevent renderwin events and signal subsurfs etc to make full resol */ /* is also set by caller renderwin.c */ - G.rendering = 1; + G.is_rendering = TRUE; re->flag |= R_ANIMATION; if (BKE_imtype_is_movie(scene->r.im_format.imtype)) if (!mh->start_movie(scene, &re->r, re->rectx, re->recty, re->reports)) - G.afbreek = 1; + G.is_break = TRUE; if (mh->get_next_frame) { - while (!(G.afbreek == 1)) { + while (!(G.is_break == 1)) { int nf = mh->get_next_frame(&re->r, re->reports); if (nf >= 0 && nf >= scene->r.sfra && nf <= scene->r.efra) { scene->r.cfra = re->r.cfra = nf; @@ -2269,16 +2272,17 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri if (re->test_break(re->tbh) == 0) { if (!do_write_image_or_movie(re, bmain, scene, mh, NULL)) - G.afbreek = 1; + G.is_break = TRUE; } - if (G.afbreek == 0) { + if (G.is_break == FALSE) { BLI_callback_exec(re->main, (ID *)scene, BLI_CB_EVT_RENDER_POST); /* keep after file save */ } } else { - if (re->test_break(re->tbh)) - G.afbreek = 1; + if (re->test_break(re->tbh)) { + G.is_break = TRUE; + } } } } @@ -2334,14 +2338,14 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri totrendered++; if (re->test_break(re->tbh) == 0) { - if (!G.afbreek) + if (!G.is_break) if (!do_write_image_or_movie(re, bmain, scene, mh, NULL)) - G.afbreek = 1; + G.is_break = TRUE; } else - G.afbreek = 1; + G.is_break = TRUE; - if (G.afbreek == 1) { + if (G.is_break == TRUE) { /* remove touched file */ if (BKE_imtype_is_movie(scene->r.im_format.imtype) == 0) { if (scene->r.mode & R_TOUCH && BLI_exists(name) && BLI_file_size(name) == 0) { @@ -2352,7 +2356,7 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri break; } - if (G.afbreek == 0) { + if (G.is_break == FALSE) { BLI_callback_exec(re->main, (ID *)scene, BLI_CB_EVT_RENDER_POST); /* keep after file save */ } } @@ -2369,10 +2373,10 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri re->flag &= ~R_ANIMATION; - BLI_callback_exec(re->main, (ID *)scene, G.afbreek ? BLI_CB_EVT_RENDER_CANCEL : BLI_CB_EVT_RENDER_COMPLETE); + BLI_callback_exec(re->main, (ID *)scene, G.is_break ? BLI_CB_EVT_RENDER_CANCEL : BLI_CB_EVT_RENDER_COMPLETE); /* UGLY WARNING */ - G.rendering = 0; + G.is_rendering = FALSE; } void RE_PreviewRender(Render *re, Main *bmain, Scene *sce) diff --git a/source/blender/render/intern/source/render_texture.c b/source/blender/render/intern/source/render_texture.c index e5bbb212def..3d0816e048d 100644 --- a/source/blender/render/intern/source/render_texture.c +++ b/source/blender/render/intern/source/render_texture.c @@ -112,7 +112,7 @@ static void init_render_texture(Render *re, Tex *tex) tex->extend= TEX_EXTEND; /* only free envmap when rendermode was set to render envmaps, for previewrender */ - if (G.rendering && re) { + if (G.is_rendering && re) { if (re->r.mode & R_ENVMAP) if (tex->env->stype==ENV_ANIM) BKE_free_envmapdata(tex->env); diff --git a/source/blender/render/intern/source/shadbuf.c b/source/blender/render/intern/source/shadbuf.c index 4c90c3b4a6f..90876610f1a 100644 --- a/source/blender/render/intern/source/shadbuf.c +++ b/source/blender/render/intern/source/shadbuf.c @@ -848,7 +848,7 @@ void threaded_makeshadowbufs(Render *re) int (*test_break)(void *); /* count number of threads to use */ - if (G.rendering) { + if (G.is_rendering) { for (lar=re->lampren.first; lar; lar= lar->next) if (lar->shb) totthread++; diff --git a/source/blender/render/intern/source/texture_ocean.c b/source/blender/render/intern/source/texture_ocean.c index 5071303dff7..b842cab1d29 100644 --- a/source/blender/render/intern/source/texture_ocean.c +++ b/source/blender/render/intern/source/texture_ocean.c @@ -88,7 +88,7 @@ int ocean_texture(Tex *tex, float *texvec, TexResult *texres) } else { /* non-cached */ - if (G.rendering) + if (G.is_rendering) BKE_ocean_eval_uv_catrom(omd->ocean, &ocr, u, v); else BKE_ocean_eval_uv(omd->ocean, &ocr, u, v); diff --git a/source/blender/render/intern/source/zbuf.c b/source/blender/render/intern/source/zbuf.c index 8d228473de7..de9572bf57b 100644 --- a/source/blender/render/intern/source/zbuf.c +++ b/source/blender/render/intern/source/zbuf.c @@ -3975,9 +3975,9 @@ unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pas if (R.test_break(R.tbh)) return NULL; - if (R.osa>16) { /* MAX_OSA */ + if (R.osa > 16) { /* MAX_OSA */ printf("zbuffer_transp_shade: osa too large\n"); - G.afbreek= 1; + G.is_break = TRUE; return NULL; } diff --git a/source/blender/windowmanager/CMakeLists.txt b/source/blender/windowmanager/CMakeLists.txt index 7f7321f6f29..c7546196af8 100644 --- a/source/blender/windowmanager/CMakeLists.txt +++ b/source/blender/windowmanager/CMakeLists.txt @@ -54,6 +54,7 @@ set(INC_SYS set(SRC intern/wm.c + intern/wm_playanim.c intern/wm_cursors.c intern/wm_dragdrop.c intern/wm_draw.c diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 60efc3b3541..ee7b44fb1e9 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -208,6 +208,8 @@ void WM_operator_properties_create(struct PointerRNA *ptr, const char *opstring void WM_operator_properties_create_ptr(struct PointerRNA *ptr, struct wmOperatorType *ot); void WM_operator_properties_free(struct PointerRNA *ptr); void WM_operator_properties_filesel(struct wmOperatorType *ot, int filter, short type, short action, short flag, short display); +void WM_operator_properties_border(struct wmOperatorType *ot); +void WM_operator_properties_border_to_rcti(struct wmOperator *op, struct rcti *rect); void WM_operator_properties_gesture_border(struct wmOperatorType *ot, int extend); void WM_operator_properties_mouse_select(struct wmOperatorType *ot); void WM_operator_properties_gesture_straightline(struct wmOperatorType *ot, int cursor); diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index 72d2bf9d1f1..bcba7a76ec8 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -28,6 +28,73 @@ * \ingroup wm */ +/* + * Overview of WM structs + * ====================== + * + * > wmWindowManager (window manager stores a list of windows) + * > > wmWindow (window has an active screen) + * > > > bScreen (link to ScrAreas via 'areabase') + * > > > > ScrArea (stores multiple spaces via space links via 'spacedata') + * > > > > > SpaceLink (base struct for space data for all different space types) + * > > > > ScrArea (stores multiple regions via 'regionbase') + * > > > > > ARegion + * + * + * Window Layout + * ============= + * + * wmWindow -> bScreen + * +----------------------------------------------------------+ + * |+-----------------------------------------+-------------+ | + * ||ScrArea (links to 3D view) |ScrArea | | + * ||+-------++----------+-------------------+|(links to | | + * |||ARegion|| |ARegion (quad view)|| properties) | | + * |||(tools)|| | || | | + * ||| || | || | | + * ||| || | || | | + * ||| || | || | | + * ||| |+----------+-------------------+| | | + * ||| || | || | | + * ||| || | || | | + * ||| || | || | | + * ||| || | || | | + * ||| || | || | | + * ||+-------++----------+-------------------+| | | + * |+-----------------------------------------+-------------+ | + * +----------------------------------------------------------+ + * + * + * Space Data + * ========== + * + * ScrArea's store a list of space data (SpaceLinks), each of unique type. + * The first one is the displayed in the UI, others are added as needed. + * + * +----------------------------+ <-- sa->spacedata.first; + * | | + * | |---+ <-- other inactive SpaceLink's stored. + * | | | + * | | |---+ + * | | | | + * | | | | + * | | | | + * | | | | + * +----------------------------+ | | + * | | | + * +-----------------------------+ | + * | | + * +------------------------------+ + * + * A common way to get the space from the ScrArea: + * + * if (sa->spacetype == SPACE_VIEW3D) { + * View3D *v3d = sa->spacedata.first; + * ... + * } + * + */ + #ifndef __WM_TYPES_H__ #define __WM_TYPES_H__ diff --git a/source/blender/windowmanager/intern/wm_draw.c b/source/blender/windowmanager/intern/wm_draw.c index 8652870e280..66bb321e832 100644 --- a/source/blender/windowmanager/intern/wm_draw.c +++ b/source/blender/windowmanager/intern/wm_draw.c @@ -45,10 +45,11 @@ #include "BLI_utildefines.h" #include "BLI_math_base.h" +#include "BIF_gl.h" + #include "BKE_context.h" #include "BKE_global.h" - #include "GHOST_C-api.h" #include "ED_screen.h" @@ -505,8 +506,8 @@ static void wm_triple_draw_textures(wmWindow *win, wmDrawTriple *triple) /* wmOrtho for the screen has this same offset */ ratiox = sizex; ratioy = sizey; - halfx = 0.375f; - halfy = 0.375f; + halfx = GLA_PIXEL_OFS; + halfy = GLA_PIXEL_OFS; /* texture rectangle has unnormalized coordinates */ if (triple->target == GL_TEXTURE_2D) { diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 2c641b217a8..e3ad425d0f8 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -242,7 +242,7 @@ void wm_event_do_notifiers(bContext *C) /* XXX, quick frame changes can cause a crash if framechange and rendering * collide (happens on slow scenes), BKE_scene_update_for_newframe can be called * twice which can depgraph update the same object at once */ - if (!G.rendering) { + if (G.is_rendering == FALSE) { /* depsgraph gets called, might send more notifiers */ ED_update_for_newframe(CTX_data_main(C), win->screen->scene, 1); @@ -301,7 +301,7 @@ void wm_event_do_notifiers(bContext *C) } /* XXX make lock in future, or separated derivedmesh users in scene */ - if (!G.rendering) { + if (G.is_rendering == FALSE) { /* depsgraph & animation: update tagged datablocks */ Main *bmain = CTX_data_main(C); @@ -2906,7 +2906,7 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, int U /* if test_break set, it catches this. XXX Keep global for now? */ if (event.type == ESCKEY) - G.afbreek = 1; + G.is_break = TRUE; wm_event_add(win, &event); diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index 04035598a89..36e2cbae296 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -382,6 +382,8 @@ void WM_read_file(bContext *C, const char *filepath, ReportList *reports) /* assume automated tasks with background, don't write recent file list */ const int do_history = (G.background == FALSE) && (CTX_wm_manager(C)->op_undo_depth == 0); + BKE_vfont_free_global_ttf(); + /* put aside screens to match with persistent windows later */ /* also exit screens and editors */ wm_window_match_init(C, &wmbase); @@ -492,7 +494,7 @@ int WM_read_homefile(bContext *C, ReportList *UNUSED(reports), short from_memory char tstr[FILE_MAX]; int success = 0; - BKE_vfont_free_global_ttf(); /* still weird... what does it here? */ + BKE_vfont_free_global_ttf(); G.relbase_valid = 0; if (!from_memory) { diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index 5bf6c34cfb3..8ea644d6e5c 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -58,6 +58,7 @@ #include "BKE_library.h" #include "BKE_main.h" #include "BKE_mball.h" +#include "BKE_node.h" #include "BKE_report.h" #include "BKE_packedFile.h" @@ -334,10 +335,10 @@ static void free_openrecent(void) /* bad stuff*/ // XXX copy/paste buffer stuff... -extern void free_anim_copybuf(void); -extern void free_anim_drivers_copybuf(void); -extern void free_fmodifiers_copybuf(void); -extern void free_posebuf(void); +extern void free_anim_copybuf(void); +extern void free_anim_drivers_copybuf(void); +extern void free_fmodifiers_copybuf(void); +extern void free_posebuf(void); #if WIN32 /* Read console events until there is a key event. Also returns on any error. */ @@ -346,7 +347,7 @@ static void wait_for_console_key(void) HANDLE hConsoleInput = GetStdHandle(STD_INPUT_HANDLE); if (!ELEM(hConsoleInput, NULL, INVALID_HANDLE_VALUE) && FlushConsoleInputBuffer(hConsoleInput)) { - for(;;) { + for (;;) { INPUT_RECORD buffer; DWORD ignored; @@ -410,7 +411,7 @@ void WM_exit_ext(bContext *C, const short do_python) if (C && CTX_wm_manager(C)) wm_free_reports(C); /* before free_blender! - since the ListBases get freed there */ - seq_free_clipboard(); /* sequencer.c */ + BKE_sequencer_free_clipboard(); /* sequencer.c */ BKE_tracking_clipboard_free(); free_blender(); /* blender.c, does entire library and spacetypes */ @@ -419,6 +420,7 @@ void WM_exit_ext(bContext *C, const short do_python) free_anim_drivers_copybuf(); free_fmodifiers_copybuf(); free_posebuf(); + BKE_node_clipboard_clear(); BLF_exit(); @@ -495,5 +497,5 @@ void WM_exit_ext(bContext *C, const short do_python) void WM_exit(bContext *C) { WM_exit_ext(C, 1); - exit(G.afbreek == 1); + exit(G.is_break == TRUE); } diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index a55efc0b216..52436b6564c 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -906,16 +906,31 @@ void WM_operator_properties_select_all(wmOperatorType *ot) RNA_def_enum(ot->srna, "action", select_all_actions, SEL_TOGGLE, "Action", "Selection action to execute"); } -void WM_operator_properties_gesture_border(wmOperatorType *ot, int extend) +void WM_operator_properties_border(wmOperatorType *ot) { - RNA_def_int(ot->srna, "gesture_mode", 0, INT_MIN, INT_MAX, "Gesture Mode", "", INT_MIN, INT_MAX); RNA_def_int(ot->srna, "xmin", 0, INT_MIN, INT_MAX, "X Min", "", INT_MIN, INT_MAX); RNA_def_int(ot->srna, "xmax", 0, INT_MIN, INT_MAX, "X Max", "", INT_MIN, INT_MAX); RNA_def_int(ot->srna, "ymin", 0, INT_MIN, INT_MAX, "Y Min", "", INT_MIN, INT_MAX); RNA_def_int(ot->srna, "ymax", 0, INT_MIN, INT_MAX, "Y Max", "", INT_MIN, INT_MAX); +} + +void WM_operator_properties_border_to_rcti(struct wmOperator *op, rcti *rect) +{ + rect->xmin = RNA_int_get(op->ptr, "xmin"); + rect->ymin = RNA_int_get(op->ptr, "ymin"); + rect->xmax = RNA_int_get(op->ptr, "xmax"); + rect->ymax = RNA_int_get(op->ptr, "ymax"); +} + +void WM_operator_properties_gesture_border(wmOperatorType *ot, int extend) +{ + RNA_def_int(ot->srna, "gesture_mode", 0, INT_MIN, INT_MAX, "Gesture Mode", "", INT_MIN, INT_MAX); + + WM_operator_properties_border(ot); - if (extend) + if (extend) { RNA_def_boolean(ot->srna, "extend", 1, "Extend", "Extend selection instead of deselecting everything first"); + } } void WM_operator_properties_mouse_select(wmOperatorType *ot) @@ -1194,7 +1209,7 @@ int WM_operator_redo_popup(bContext *C, wmOperator *op) static int wm_debug_menu_exec(bContext *C, wmOperator *op) { - G.rt = RNA_int_get(op->ptr, "debug_value"); + G.debug_value = RNA_int_get(op->ptr, "debug_value"); ED_screen_refresh(CTX_wm_manager(C), CTX_wm_window(C)); WM_event_add_notifier(C, NC_WINDOW, NULL); @@ -1203,7 +1218,7 @@ static int wm_debug_menu_exec(bContext *C, wmOperator *op) static int wm_debug_menu_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) { - RNA_int_set(op->ptr, "debug_value", G.rt); + RNA_int_set(op->ptr, "debug_value", G.debug_value); return WM_operator_props_dialog_popup(C, op, 9 * UI_UNIT_X, UI_UNIT_Y); } @@ -1862,9 +1877,9 @@ static void WM_OT_link_append(wmOperatorType *ot) ot->flag |= OPTYPE_UNDO; WM_operator_properties_filesel( - ot, FOLDERFILE | BLENDERFILE, FILE_LOADLIB, FILE_OPENFILE, - WM_FILESEL_FILEPATH | WM_FILESEL_DIRECTORY | WM_FILESEL_FILENAME | WM_FILESEL_RELPATH | WM_FILESEL_FILES, - FILE_DEFAULTDISPLAY); + ot, FOLDERFILE | BLENDERFILE, FILE_LOADLIB, FILE_OPENFILE, + WM_FILESEL_FILEPATH | WM_FILESEL_DIRECTORY | WM_FILESEL_FILENAME | WM_FILESEL_RELPATH | WM_FILESEL_FILES, + FILE_DEFAULTDISPLAY); RNA_def_boolean(ot->srna, "link", 1, "Link", "Link the objects or datablocks rather than appending"); RNA_def_boolean(ot->srna, "autoselect", 1, "Select", "Select the linked objects"); @@ -1945,20 +1960,21 @@ static void WM_OT_recover_auto_save(wmOperatorType *ot) ot->invoke = wm_recover_auto_save_invoke; ot->poll = WM_operator_winactive; - WM_operator_properties_filesel(ot, BLENDERFILE, FILE_BLENDER, FILE_OPENFILE, WM_FILESEL_FILEPATH, FILE_LONGDISPLAY); + WM_operator_properties_filesel(ot, BLENDERFILE, FILE_BLENDER, FILE_OPENFILE, + WM_FILESEL_FILEPATH, FILE_LONGDISPLAY); } /* *************** save file as **************** */ -static void untitled(char *name) +static void untitled(char *filepath) { - if (G.save_over == 0 && strlen(name) < FILE_MAX - 16) { - char *c = BLI_last_slash(name); + if (G.save_over == 0 && strlen(filepath) < FILE_MAX - 16) { + char *c = BLI_last_slash(filepath); if (c) strcpy(&c[1], "untitled.blend"); else - strcpy(name, "untitled.blend"); + strcpy(filepath, "untitled.blend"); } } @@ -2065,8 +2081,8 @@ static void WM_OT_save_as_mainfile(wmOperatorType *ot) ot->check = blend_save_check; /* ommit window poll so this can work in background mode */ - WM_operator_properties_filesel(ot, FOLDERFILE | BLENDERFILE, FILE_BLENDER, FILE_SAVE, WM_FILESEL_FILEPATH, - FILE_DEFAULTDISPLAY); + WM_operator_properties_filesel(ot, FOLDERFILE | BLENDERFILE, FILE_BLENDER, FILE_SAVE, + WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY); RNA_def_boolean(ot->srna, "compress", 0, "Compress", "Write compressed .blend file"); RNA_def_boolean(ot->srna, "relative_remap", 1, "Remap Relative", "Remap relative paths when saving in a different directory"); @@ -2137,7 +2153,8 @@ static void WM_OT_save_mainfile(wmOperatorType *ot) ot->check = blend_save_check; /* ommit window poll so this can work in background mode */ - WM_operator_properties_filesel(ot, FOLDERFILE | BLENDERFILE, FILE_BLENDER, FILE_SAVE, WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY); + WM_operator_properties_filesel(ot, FOLDERFILE | BLENDERFILE, FILE_BLENDER, FILE_SAVE, + WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY); RNA_def_boolean(ot->srna, "compress", 0, "Compress", "Write compressed .blend file"); RNA_def_boolean(ot->srna, "relative_remap", 0, "Remap Relative", "Remap relative paths when saving in a different directory"); } diff --git a/source/blender/windowmanager/intern/wm_playanim.c b/source/blender/windowmanager/intern/wm_playanim.c new file mode 100644 index 00000000000..3c791cb6e5d --- /dev/null +++ b/source/blender/windowmanager/intern/wm_playanim.c @@ -0,0 +1,1136 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Campbell Barton + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/windowmanager/intern/wm_playanim.c + * \ingroup wm + * + * \note This file uses ghost directly and none of the WM definitions. + * this could be made into its own module, alongside creator/ + */ + +#include <sys/types.h> +#include <fcntl.h> +#include <stdlib.h> +#include <string.h> +#include <math.h> + +#ifndef WIN32 +# include <unistd.h> +# include <sys/times.h> +# include <sys/wait.h> +#else +# include <io.h> +#endif +#include "MEM_guardedalloc.h" + +#include "PIL_time.h" + +#include "BLI_listbase.h" +#include "BLI_string.h" +#include "BLI_path_util.h" +#include "BLI_fileops.h" +#include "BLI_rect.h" + +#include "IMB_imbuf_types.h" +#include "IMB_imbuf.h" + +#include "BKE_blender.h" +#include "BKE_global.h" +#include "BKE_utildefines.h" + +#include "BIF_gl.h" +#include "BIF_glutil.h" + +#ifdef WITH_QUICKTIME +# ifdef _WIN32 +# include <QTML.h> +# include <Movies.h> +# elif defined(__APPLE__) +# include <QuickTime/Movies.h> +# endif /* __APPLE__ */ +#endif /* WITH_QUICKTIME */ + +#include "DNA_scene_types.h" +#include "BLI_utildefines.h" +#include "ED_datafiles.h" /* for fonts */ +#include "wm_event_types.h" +#include "GHOST_C-api.h" +#include "BLF_api.h" + + +typedef struct PlayState { + + /* playback state */ + short direction; + short next; + short once; + short turbo; + short pingpong; + short noskip; + short sstep; + short pause; + short wait2; + short stopped; + short go; + + /* current picture */ + struct PlayAnimPict *picture; + + /* set once at the start */ + int ibufx, ibufy; + int fontid; + + /* saves passing args */ + struct ImBuf *curframe_ibuf; +} PlayState; + +/* for debugging */ +#if 0 +void print_ps(PlayState *ps) +{ + printf("ps:\n"); + printf(" direction=%d,\n", (int)ps->direction); + printf(" next=%d,\n", ps->next); + printf(" once=%d,\n", ps->once); + printf(" turbo=%d,\n", ps->turbo); + printf(" pingpong=%d,\n", ps->pingpong); + printf(" noskip=%d,\n", ps->noskip); + printf(" sstep=%d,\n", ps->sstep); + printf(" pause=%d,\n", ps->pause); + printf(" wait2=%d,\n", ps->wait2); + printf(" stopped=%d,\n", ps->stopped); + printf(" go=%d,\n\n", ps->go); + fflush(stdout); +} +#endif + +/* global for window and events */ +typedef enum eWS_Qual { + WS_QUAL_LSHIFT = (1 << 0), + WS_QUAL_RSHIFT = (1 << 1), + WS_QUAL_SHIFT = (WS_QUAL_LSHIFT | WS_QUAL_RSHIFT), + WS_QUAL_LALT = (1 << 2), + WS_QUAL_RALT = (1 << 3), + WS_QUAL_ALT = (WS_QUAL_LALT | WS_QUAL_RALT), + WS_QUAL_LCTRL = (1 << 4), + WS_QUAL_RCTRL = (1 << 5), + WS_QUAL_LMOUSE = (1 << 16), + WS_QUAL_MMOUSE = (1 << 17), + WS_QUAL_RMOUSE = (1 << 18), + WS_QUAL_MOUSE = (WS_QUAL_LMOUSE | WS_QUAL_MMOUSE | WS_QUAL_RMOUSE) +} eWS_Qual; + +static struct WindowStateGlobal { + GHOST_SystemHandle ghost_system; + void *ghost_window; + + /* events */ + eWS_Qual qual; +} g_WS = {NULL}; + +void playanim_window_get_size(int *width_r, int *height_r) +{ + GHOST_RectangleHandle bounds = GHOST_GetClientBounds(g_WS.ghost_window); + *width_r = GHOST_GetWidthRectangle(bounds); + *height_r = GHOST_GetHeightRectangle(bounds); + GHOST_DisposeRectangle(bounds); +} + +/* implementation */ +static void playanim_event_qual_update(void) +{ + int val; + + /* Shift */ + GHOST_GetModifierKeyState(g_WS.ghost_system, GHOST_kModifierKeyLeftShift, &val); + if (val) g_WS.qual |= WS_QUAL_LSHIFT; + else g_WS.qual &= ~WS_QUAL_LSHIFT; + + GHOST_GetModifierKeyState(g_WS.ghost_system, GHOST_kModifierKeyRightShift, &val); + if (val) g_WS.qual |= WS_QUAL_RSHIFT; + else g_WS.qual &= ~WS_QUAL_RSHIFT; + + /* Control */ + GHOST_GetModifierKeyState(g_WS.ghost_system, GHOST_kModifierKeyLeftControl, &val); + if (val) g_WS.qual |= WS_QUAL_LCTRL; + else g_WS.qual &= ~WS_QUAL_LCTRL; + + GHOST_GetModifierKeyState(g_WS.ghost_system, GHOST_kModifierKeyRightControl, &val); + if (val) g_WS.qual |= WS_QUAL_RCTRL; + else g_WS.qual &= ~WS_QUAL_RCTRL; + + /* Alt */ + GHOST_GetModifierKeyState(g_WS.ghost_system, GHOST_kModifierKeyLeftAlt, &val); + if (val) g_WS.qual |= WS_QUAL_LCTRL; + else g_WS.qual &= ~WS_QUAL_LCTRL; + + GHOST_GetModifierKeyState(g_WS.ghost_system, GHOST_kModifierKeyRightAlt, &val); + if (val) g_WS.qual |= WS_QUAL_RCTRL; + else g_WS.qual &= ~WS_QUAL_RCTRL; + + /* LMB */ + GHOST_GetButtonState(g_WS.ghost_system, GHOST_kButtonMaskLeft, &val); + if (val) g_WS.qual |= WS_QUAL_LMOUSE; + else g_WS.qual &= ~WS_QUAL_LMOUSE; + + /* MMB */ + GHOST_GetButtonState(g_WS.ghost_system, GHOST_kButtonMaskMiddle, &val); + if (val) g_WS.qual |= WS_QUAL_MMOUSE; + else g_WS.qual &= ~WS_QUAL_MMOUSE; + + /* RMB */ + GHOST_GetButtonState(g_WS.ghost_system, GHOST_kButtonMaskRight, &val); + if (val) g_WS.qual |= WS_QUAL_RMOUSE; + else g_WS.qual &= ~WS_QUAL_RMOUSE; +} + +typedef struct PlayAnimPict { + struct PlayAnimPict *next, *prev; + char *mem; + int size; + char *name; + struct ImBuf *ibuf; + struct anim *anim; + int frame; + int IB_flags; +} PlayAnimPict; + +static struct ListBase picsbase = {NULL, NULL}; +static int fromdisk = FALSE; +static int fstep = 1; +static float zoomx = 1.0, zoomy = 1.0; +static double ptottime = 0.0, swaptime = 0.04; + +static int pupdate_time(void) +{ + static double ltime; + double time; + + time = PIL_check_seconds_timer(); + + ptottime += (time - ltime); + ltime = time; + return (ptottime < 0); +} + +static void playanim_toscreen(PlayAnimPict *picture, struct ImBuf *ibuf, int fontid) +{ + + if (ibuf == NULL) { + printf("no ibuf !\n"); + return; + } + if (ibuf->rect == NULL && ibuf->rect_float) { + IMB_rect_from_float(ibuf); + imb_freerectfloatImBuf(ibuf); + } + if (ibuf->rect == NULL) + return; + + GHOST_ActivateWindowDrawingContext(g_WS.ghost_window); + + glRasterPos2f(0.0f, 0.0f); + + glDrawPixels(ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect); + + pupdate_time(); + + if (picture && (g_WS.qual & (WS_QUAL_SHIFT | WS_QUAL_LMOUSE)) && (fontid != -1)) { + int sizex, sizey; + float fsizex_inv, fsizey_inv; + char str[32 + FILE_MAX]; + cpack(-1); + BLI_snprintf(str, sizeof(str), "%s | %.2f frames/s", picture->name, fstep / swaptime); + + playanim_window_get_size(&sizex, &sizey); + fsizex_inv = 1.0f / sizex; + fsizey_inv = 1.0f / sizey; + + BLF_enable(fontid, BLF_ASPECT); + BLF_aspect(fontid, fsizex_inv, fsizey_inv, 1.0f); + BLF_position(fontid, 10.0f * fsizex_inv, 10.0f * fsizey_inv, 0.0f); + BLF_draw(fontid, str, sizeof(str)); + } + + GHOST_SwapWindowBuffers(g_WS.ghost_window); +} + +static void build_pict_list(char *first, int totframes, int fstep, int fontid) +{ + char *mem, filepath[FILE_MAX]; +// short val; + PlayAnimPict *picture = NULL; + struct ImBuf *ibuf = NULL; + char str[32 + FILE_MAX]; + struct anim *anim; + + if (IMB_isanim(first)) { + anim = IMB_open_anim(first, IB_rect, 0); + if (anim) { + int pic; + ibuf = IMB_anim_absolute(anim, 0, IMB_TC_NONE, IMB_PROXY_NONE); + if (ibuf) { + playanim_toscreen(NULL, ibuf, fontid); + IMB_freeImBuf(ibuf); + } + + for (pic = 0; pic < IMB_anim_get_duration(anim, IMB_TC_NONE); pic++) { + picture = (PlayAnimPict *)MEM_callocN(sizeof(PlayAnimPict), "Pict"); + picture->anim = anim; + picture->frame = pic; + picture->IB_flags = IB_rect; + BLI_snprintf(str, sizeof(str), "%s : %4.d", first, pic + 1); + picture->name = strdup(str); + BLI_addtail(&picsbase, picture); + } + } + else { + printf("couldn't open anim %s\n", first); + } + } + else { + int count = 0; + + BLI_strncpy(filepath, first, sizeof(filepath)); + + pupdate_time(); + ptottime = 1.0; + + /* O_DIRECT + * + * If set, all reads and writes on the resulting file descriptor will + * be performed directly to or from the user program buffer, provided + * appropriate size and alignment restrictions are met. Refer to the + * F_SETFL and F_DIOINFO commands in the fcntl(2) manual entry for + * information about how to determine the alignment constraints. + * O_DIRECT is a Silicon Graphics extension and is only supported on + * local EFS and XFS file systems. + */ + + while (IMB_ispic(filepath) && totframes) { + size_t size; + int file; + + file = open(filepath, O_BINARY | O_RDONLY, 0); + if (file < 0) return; + picture = (PlayAnimPict *)MEM_callocN(sizeof(PlayAnimPict), "picture"); + if (picture == NULL) { + printf("Not enough memory for pict struct '%s'\n", filepath); + close(file); + return; + } + size = BLI_file_descriptor_size(file); + + if (size < 1) { + close(file); + MEM_freeN(picture); + return; + } + + picture->size = size; + picture->IB_flags = IB_rect; + + if (fromdisk == FALSE) { + mem = (char *)MEM_mallocN(size, "build pic list"); + if (mem == NULL) { + printf("Couldn't get memory\n"); + close(file); + MEM_freeN(picture); + return; + } + + if (read(file, mem, size) != size) { + printf("Error while reading %s\n", filepath); + close(file); + MEM_freeN(picture); + MEM_freeN(mem); + return; + } + } + else { + mem = NULL; + } + + picture->mem = mem; + picture->name = strdup(filepath); + close(file); + BLI_addtail(&picsbase, picture); + count++; + + pupdate_time(); + + if (ptottime > 1.0) { + if (picture->mem) { + ibuf = IMB_ibImageFromMemory((unsigned char *)picture->mem, picture->size, + picture->IB_flags, picture->name); + } + else { + ibuf = IMB_loadiffname(picture->name, picture->IB_flags); + } + if (ibuf) { + playanim_toscreen(picture, ibuf, fontid); + IMB_freeImBuf(ibuf); + } + pupdate_time(); + ptottime = 0.0; + } + + BLI_newname(filepath, +fstep); + +#if 0 // XXX25 + while (qtest()) { + switch (qreadN(&val)) { + case ESCKEY: + if (val) return; + break; + } + } +#endif + totframes--; + } + } + return; +} + +static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr ps_void) +{ + PlayState *ps = (PlayState *)ps_void; + GHOST_TEventType type = GHOST_GetEventType(evt); + int val; + + // print_ps(ps); + + playanim_event_qual_update(); + + /* convert ghost event into value keyboard or mouse */ + val = ELEM(type, GHOST_kEventKeyDown, GHOST_kEventButtonDown); + + if (ps->wait2 && ps->stopped) { + ps->stopped = FALSE; + } + + switch (type) { + case GHOST_kEventKeyDown: + case GHOST_kEventKeyUp: + { + GHOST_TEventKeyData *key_data; + + key_data = (GHOST_TEventKeyData *)GHOST_GetEventData(evt); + switch (key_data->key) { + case GHOST_kKeyA: + if (val) ps->noskip = !ps->noskip; + break; + case GHOST_kKeyP: + if (val) ps->pingpong = !ps->pingpong; + break; + case GHOST_kKeyNumpad1: + if (val) swaptime = fstep / 60.0; + break; + case GHOST_kKeyNumpad2: + if (val) swaptime = fstep / 50.0; + break; + case GHOST_kKeyNumpad3: + if (val) swaptime = fstep / 30.0; + break; + case GHOST_kKeyNumpad4: + if (g_WS.qual & WS_QUAL_SHIFT) + swaptime = fstep / 24.0; + else + swaptime = fstep / 25.0; + break; + case GHOST_kKeyNumpad5: + if (val) swaptime = fstep / 20.0; + break; + case GHOST_kKeyNumpad6: + if (val) swaptime = fstep / 15.0; + break; + case GHOST_kKeyNumpad7: + if (val) swaptime = fstep / 12.0; + break; + case GHOST_kKeyNumpad8: + if (val) swaptime = fstep / 10.0; + break; + case GHOST_kKeyNumpad9: + if (val) swaptime = fstep / 6.0; + break; + case GHOST_kKeyLeftArrow: + if (val) { + ps->sstep = TRUE; + ps->wait2 = FALSE; + if (g_WS.qual & WS_QUAL_SHIFT) { + ps->picture = picsbase.first; + ps->next = 0; + } + else { + ps->next = -1; + } + } + break; + case GHOST_kKeyDownArrow: + if (val) { + ps->wait2 = FALSE; + if (g_WS.qual & WS_QUAL_SHIFT) { + ps->next = ps->direction = -1; + } + else { + ps->next = -10; + ps->sstep = TRUE; + } + } + break; + case GHOST_kKeyRightArrow: + if (val) { + ps->sstep = TRUE; + ps->wait2 = FALSE; + if (g_WS.qual & WS_QUAL_SHIFT) { + ps->picture = picsbase.last; + ps->next = 0; + } + else { + ps->next = 1; + } + } + break; + case GHOST_kKeyUpArrow: + if (val) { + ps->wait2 = FALSE; + if (g_WS.qual & WS_QUAL_SHIFT) { + ps->next = ps->direction = 1; + } + else { + ps->next = 10; + ps->sstep = TRUE; + } + } + break; + + case GHOST_kKeySlash: + case GHOST_kKeyNumpadSlash: + if (val) { + if (g_WS.qual & WS_QUAL_SHIFT) { + if (ps->curframe_ibuf) + printf(" Name: %s | Speed: %.2f frames/s\n", ps->curframe_ibuf->name, fstep / swaptime); + } + else { + swaptime = fstep / 5.0; + } + } + break; + case GHOST_kKeyEqual: + if (val) { + if (g_WS.qual & WS_QUAL_SHIFT) { + ps->pause++; + printf("pause:%d\n", ps->pause); + } + else { + swaptime /= 1.1; + } + } + break; + case GHOST_kKeyMinus: + if (val) { + if (g_WS.qual & WS_QUAL_SHIFT) { + ps->pause--; + printf("pause:%d\n", ps->pause); + } + else { + swaptime *= 1.1; + } + } + break; + case GHOST_kKeyNumpad0: + if (val) { + if (ps->once) { + ps->once = ps->wait2 = FALSE; + } + else { + ps->picture = NULL; + ps->once = TRUE; + ps->wait2 = FALSE; + } + } + break; + case GHOST_kKeyEnter: + case GHOST_kKeyNumpadEnter: + if (val) { + ps->wait2 = ps->sstep = FALSE; + } + break; + case GHOST_kKeyNumpadPeriod: + if (val) { + if (ps->sstep) ps->wait2 = FALSE; + else { + ps->sstep = TRUE; + ps->wait2 = !ps->wait2; + } + } + break; + case GHOST_kKeyNumpadPlus: + if (val == 0) break; + zoomx += 2.0; + zoomy += 2.0; + /* no break??? - is this intentional? - campbell XXX25 */ + case GHOST_kKeyNumpadMinus: + { + int sizex, sizey; + /* int ofsx, ofsy; */ /* UNUSED */ + + if (val == 0) break; + if (zoomx > 1.0) zoomx -= 1.0; + if (zoomy > 1.0) zoomy -= 1.0; + // playanim_window_get_position(&ofsx, &ofsy); + playanim_window_get_size(&sizex, &sizey); + /* ofsx += sizex / 2; */ /* UNUSED */ + /* ofsy += sizey / 2; */ /* UNUSED */ + sizex = zoomx * ps->ibufx; + sizey = zoomy * ps->ibufy; + /* ofsx -= sizex / 2; */ /* UNUSED */ + /* ofsy -= sizey / 2; */ /* UNUSED */ + // window_set_position(g_WS.ghost_window,sizex,sizey); + GHOST_SetClientSize(g_WS.ghost_window, sizex, sizey); + break; + } + case GHOST_kKeyEsc: + ps->go = FALSE; + break; + default: + break; + } + break; + } + case GHOST_kEventCursorMove: + { + if (g_WS.qual & WS_QUAL_LMOUSE) { + int sizex, sizey; + int i; + + GHOST_TEventCursorData *cd = GHOST_GetEventData(evt); + int cx, cy; + + GHOST_ScreenToClient(g_WS.ghost_window, cd->x, cd->y, &cx, &cy); + + playanim_window_get_size(&sizex, &sizey); + ps->picture = picsbase.first; + /* TODO - store in ps direct? */ + i = 0; + while (ps->picture) { + i++; + ps->picture = ps->picture->next; + } + i = (i * cx) / sizex; + ps->picture = picsbase.first; + for (; i > 0; i--) { + if (ps->picture->next == NULL) break; + ps->picture = ps->picture->next; + } + ps->sstep = TRUE; + ps->wait2 = FALSE; + ps->next = 0; + } + break; + } + case GHOST_kEventWindowSize: + case GHOST_kEventWindowMove: + { + int sizex, sizey; + + playanim_window_get_size(&sizex, &sizey); + GHOST_ActivateWindowDrawingContext(g_WS.ghost_window); + + glViewport(0, 0, sizex, sizey); + glScissor(0, 0, sizex, sizey); + + zoomx = (float) sizex / ps->ibufx; + zoomy = (float) sizey / ps->ibufy; + zoomx = floor(zoomx + 0.5); + zoomy = floor(zoomy + 0.5); + if (zoomx < 1.0) zoomx = 1.0; + if (zoomy < 1.0) zoomy = 1.0; + + sizex = zoomx * ps->ibufx; + sizey = zoomy * ps->ibufy; + + glPixelZoom(zoomx, zoomy); + glEnable(GL_DITHER); + ptottime = 0.0; + playanim_toscreen(ps->picture, ps->curframe_ibuf, ps->fontid); + + break; + } + case GHOST_kEventQuit: + case GHOST_kEventWindowClose: + { + ps->go = FALSE; + break; + } + default: + /* quiet warnings */ + break; + } + + return 1; +} + +void playanim_window_open(const char *title, int posx, int posy, int sizex, int sizey, int start_maximized) +{ + GHOST_TWindowState inital_state; + GHOST_TUns32 scr_w, scr_h; + + GHOST_GetMainDisplayDimensions(g_WS.ghost_system, &scr_w, &scr_h); + + posy = (scr_h - posy - sizey); + + if (start_maximized == G_WINDOWSTATE_FULLSCREEN) + inital_state = start_maximized ? GHOST_kWindowStateFullScreen : GHOST_kWindowStateNormal; + else + inital_state = start_maximized ? GHOST_kWindowStateMaximized : GHOST_kWindowStateNormal; +#if defined(__APPLE__) && !defined(GHOST_COCOA) + { + extern int macPrefState; /* creator.c */ + initial_state += macPrefState; + } +#endif + + g_WS.ghost_window = GHOST_CreateWindow(g_WS.ghost_system, + title, + posx, posy, sizex, sizey, + inital_state, + GHOST_kDrawingContextTypeOpenGL, + FALSE /* no stereo */, FALSE); + + //if (ghostwin) { + //if (win) { + // GHOST_SetWindowUserData(ghostwin, win); + //} else { + // GHOST_DisposeWindow(g_WS.ghost_system, ghostwin); + //} + //} +} + + +void playanim(int argc, const char **argv) +{ + struct ImBuf *ibuf = NULL; + char filepath[FILE_MAX]; + GHOST_TUns32 maxwinx, maxwiny; + /* short c233 = FALSE, yuvx = FALSE; */ /* UNUSED */ + int i; + /* This was done to disambiguate the name for use under c++. */ + struct anim *anim = NULL; + int start_x = 0, start_y = 0; + int sfra = -1; + int efra = -1; + int totblock; + + PlayState ps = {0}; + + /* ps.doubleb = TRUE;*/ /* UNUSED */ + ps.go = TRUE; + ps.direction = TRUE; + ps.next = TRUE; + ps.once = FALSE; + ps.turbo = FALSE; + ps.pingpong = FALSE; + ps.noskip = FALSE; + ps.sstep = FALSE; + ps.pause = FALSE; + ps.wait2 = FALSE; + ps.stopped = FALSE; + ps.picture = NULL; + /* resetmap = FALSE */ + + ps.fontid = -1; + + while (argc > 1) { + if (argv[1][0] == '-') { + switch (argv[1][1]) { + case 'm': + fromdisk = TRUE; + break; + case 'p': + if (argc > 3) { + start_x = atoi(argv[2]); + start_y = atoi(argv[3]); + argc -= 2; + argv += 2; + } + else { + printf("too few arguments for -p (need 2): skipping\n"); + } + break; + case 'f': + if (argc > 3) { + double fps = atof(argv[2]); + double fps_base = atof(argv[3]); + if (fps == 0.0) { + fps = 1; + printf("invalid fps," + "forcing 1\n"); + } + swaptime = fps_base / fps; + argc -= 2; + argv += 2; + } + else { + printf("too few arguments for -f (need 2): skipping\n"); + } + break; + case 's': + sfra = MIN2(MAXFRAME, MAX2(1, atoi(argv[2]) )); + argc--; + argv++; + break; + case 'e': + efra = MIN2(MAXFRAME, MAX2(1, atoi(argv[2]) )); + argc--; + argv++; + break; + case 'j': + fstep = MIN2(MAXFRAME, MAX2(1, atoi(argv[2]))); + swaptime *= fstep; + argc--; + argv++; + break; + default: + printf("unknown option '%c': skipping\n", argv[1][1]); + break; + } + argc--; + argv++; + } + else { + break; + } + } + +#ifdef WITH_QUICKTIME +#if defined(_WIN32) || defined(__APPLE__) && !defined(GHOST_COCOA) + /* Initialize QuickTime */ +#ifndef noErr +#define noErr 0 +#endif + +#ifdef _WIN32 + if (InitializeQTML(0) != noErr) + G.have_quicktime = FALSE; + else + G.have_quicktime = TRUE; +#endif /* _WIN32 */ + if (EnterMovies() != noErr) + G.have_quicktime = FALSE; + else +#endif /* _WIN32 || __APPLE__ && !defined(GHOST_COCOA)*/ + G.have_quicktime = TRUE; +#endif /* WITH_QUICKTIME */ + + if (argc > 1) { + BLI_strncpy(filepath, argv[1], sizeof(filepath)); + } + else { + BLI_current_working_dir(filepath, sizeof(filepath)); + BLI_add_slash(filepath); + } + + if (IMB_isanim(filepath)) { + anim = IMB_open_anim(filepath, IB_rect, 0); + if (anim) { + ibuf = IMB_anim_absolute(anim, 0, IMB_TC_NONE, IMB_PROXY_NONE); + IMB_close_anim(anim); + anim = NULL; + } + } + else if (!IMB_ispic(filepath)) { + exit(1); + } + + if (ibuf == NULL) { + ibuf = IMB_loadiffname(filepath, IB_rect); + } + + if (ibuf == NULL) { + printf("couldn't open %s\n", filepath); + exit(1); + } + +#if 0 //XXX25 + #if !defined(WIN32) && !defined(__APPLE__) + if (fork()) exit(0); + #endif +#endif //XXX25 + + /* XXX, fixme zr */ + { +// extern void add_to_mainqueue(wmWindow *win, void *user_data, short evt, short val, char ascii); + + GHOST_EventConsumerHandle consumer = GHOST_CreateEventConsumer(ghost_event_proc, &ps); + + g_WS.ghost_system = GHOST_CreateSystem(); + GHOST_AddEventConsumer(g_WS.ghost_system, consumer); + + + + playanim_window_open("Blender:Anim", start_x, start_y, ibuf->x, ibuf->y, 0); +//XXX25 window_set_handler(g_WS.ghost_window, add_to_mainqueue, NULL); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f); + glMatrixMode(GL_MODELVIEW); + } + + GHOST_GetMainDisplayDimensions(g_WS.ghost_system, &maxwinx, &maxwiny); + + //GHOST_ActivateWindowDrawingContext(g_WS.ghost_window); + + /* initialize the font */ + BLF_init(11, 72); + ps.fontid = BLF_load_mem("monospace", (unsigned char *)datatoc_bmonofont_ttf, datatoc_bmonofont_ttf_size); + BLF_size(ps.fontid, 11, 72); + + ps.ibufx = ibuf->x; + ps.ibufy = ibuf->y; + + if (maxwinx % ibuf->x) maxwinx = ibuf->x * (1 + (maxwinx / ibuf->x)); + if (maxwiny % ibuf->y) maxwiny = ibuf->y * (1 + (maxwiny / ibuf->y)); + + glClearColor(0.0, 0.0, 0.0, 0.0); + glClear(GL_COLOR_BUFFER_BIT); + + GHOST_SwapWindowBuffers(g_WS.ghost_window); + + if (sfra == -1 || efra == -1) { + /* one of the frames was invalid, just use all images */ + sfra = 1; + efra = MAXFRAME; + } + + build_pict_list(filepath, (efra - sfra) + 1, fstep, ps.fontid); + + for (i = 2; i < argc; i++) { + BLI_strncpy(filepath, argv[i], sizeof(filepath)); + build_pict_list(filepath, (efra - sfra) + 1, fstep, ps.fontid); + } + + IMB_freeImBuf(ibuf); + ibuf = NULL; + + pupdate_time(); + ptottime = 0; + + /* newly added in 2.6x, without this images never get freed */ +#define USE_IMB_CACHE + + while (ps.go) { + if (ps.pingpong) + ps.direction = -ps.direction; + + if (ps.direction == 1) { + ps.picture = picsbase.first; + } + else { + ps.picture = picsbase.last; + } + + if (ps.picture == NULL) { + printf("couldn't find pictures\n"); + ps.go = FALSE; + } + if (ps.pingpong) { + if (ps.direction == 1) { + ps.picture = ps.picture->next; + } + else { + ps.picture = ps.picture->prev; + } + } + if (ptottime > 0.0) ptottime = 0.0; + + while (ps.picture) { +#ifndef USE_IMB_CACHE + if (ibuf != NULL && ibuf->ftype == 0) IMB_freeImBuf(ibuf); +#endif + if (ps.picture->ibuf) { + ibuf = ps.picture->ibuf; + } + else if (ps.picture->anim) { + ibuf = IMB_anim_absolute(ps.picture->anim, ps.picture->frame, IMB_TC_NONE, IMB_PROXY_NONE); + } + else if (ps.picture->mem) { + ibuf = IMB_ibImageFromMemory((unsigned char *) ps.picture->mem, ps.picture->size, + ps.picture->IB_flags, ps.picture->name); + } + else { + ibuf = IMB_loadiffname(ps.picture->name, ps.picture->IB_flags); + } + + if (ibuf) { + +#ifdef USE_IMB_CACHE + ps.picture->ibuf = ibuf; +#endif + + BLI_strncpy(ibuf->name, ps.picture->name, sizeof(ibuf->name)); + + /* why only windows? (from 2.4x) - campbell */ +#ifdef _WIN32 + GHOST_SetTitle(g_WS.ghost_window, ps.picture->name); +#endif + + while (pupdate_time()) PIL_sleep_ms(1); + ptottime -= swaptime; + playanim_toscreen(ps.picture, ibuf, ps.fontid); + } /* else deleten */ + else { + printf("error: can't play this image type\n"); + exit(0); + } + + if (ps.once) { + if (ps.picture->next == NULL) { + ps.wait2 = TRUE; + } + else if (ps.picture->prev == NULL) { + ps.wait2 = TRUE; + } + } + + ps.next = ps.direction; + + + { + int hasevent = GHOST_ProcessEvents(g_WS.ghost_system, 0); + if (hasevent) { + GHOST_DispatchEvents(g_WS.ghost_system); + } + } + + /* XXX25 - we should not have to do this, but it makes scrubbing functional! */ + if (g_WS.qual & WS_QUAL_LMOUSE) { + ps.next = 0; + } + else { + ps.sstep = 0; + } + + ps.wait2 = ps.sstep; + + if (ps.wait2 == 0 && ps.stopped == 0) { + ps.stopped = TRUE; + } + + pupdate_time(); + + if (ps.picture && ps.next) { + /* always at least set one step */ + while (ps.picture) { + if (ps.next < 0) { + ps.picture = ps.picture->prev; + } + else { + ps.picture = ps.picture->next; + } + + if (ps.once && ps.picture != NULL) { + if (ps.picture->next == NULL) { + ps.wait2 = TRUE; + } + else if (ps.picture->prev == NULL) { + ps.wait2 = TRUE; + } + } + + if (ps.wait2 || ptottime < swaptime || ps.turbo || ps.noskip) break; + ptottime -= swaptime; + } + if (ps.picture == NULL && ps.sstep) { + if (ps.next < 0) { + ps.picture = picsbase.last; + } + else if (ps.next > 0) { + ps.picture = picsbase.first; + } + } + } + if (ps.go == FALSE) { + break; + } + } + } + ps.picture = picsbase.first; + anim = NULL; + while (ps.picture) { + if (ps.picture && ps.picture->anim && (anim != ps.picture->anim)) { + // to prevent divx crashes + anim = ps.picture->anim; + IMB_close_anim(anim); + } + + if (ps.picture->ibuf) { + IMB_freeImBuf(ps.picture->ibuf); + } + if (ps.picture->mem) { + MEM_freeN(ps.picture->mem); + } + + ps.picture = ps.picture->next; + } +#ifdef WITH_QUICKTIME +#if defined(_WIN32) || defined(__APPLE__) && !defined(GHOST_COCOA) + if (G.have_quicktime) { + ExitMovies(); +#ifdef _WIN32 + TerminateQTML(); +#endif /* _WIN32 */ + } +#endif /* _WIN32 || __APPLE__ && !defined(GHOST_COCOA) */ +#endif /* WITH_QUICKTIME */ + + /* cleanup */ +#ifndef USE_IMB_CACHE + if (ibuf) IMB_freeImBuf(ibuf); +#endif + + BLI_freelistN(&picsbase); +#if 0 // XXX25 + free_blender(); +#else + /* we still miss freeing a lot!, + * but many areas could skip initialization too for anim play */ + IMB_exit(); + BLF_exit(); +#endif + GHOST_DisposeWindow(g_WS.ghost_system, g_WS.ghost_window); + + totblock = MEM_get_memory_blocks_in_use(); + if (totblock != 0) { + /* prints many bAKey, bArgument's which are tricky to fix */ +#if 0 + printf("Error Totblock: %d\n", totblock); + MEM_printmemlist(); +#endif + } +} diff --git a/source/blender/windowmanager/intern/wm_subwindow.c b/source/blender/windowmanager/intern/wm_subwindow.c index 0b9dc441227..529910d220e 100644 --- a/source/blender/windowmanager/intern/wm_subwindow.c +++ b/source/blender/windowmanager/intern/wm_subwindow.c @@ -141,7 +141,7 @@ void wm_subwindow_getmatrix(wmWindow *win, int swinid, float mat[][4]) int width, height; wm_subwindow_getsize(win, swin->swinid, &width, &height); - orthographic_m4(mat, -0.375f, (float)width - 0.375f, -0.375f, (float)height - 0.375f, -100, 100); + orthographic_m4(mat, -GLA_PIXEL_OFS, (float)width - GLA_PIXEL_OFS, -GLA_PIXEL_OFS, (float)height - GLA_PIXEL_OFS, -100, 100); } else glGetFloatv(GL_PROJECTION_MATRIX, (float *)mat); @@ -175,7 +175,7 @@ int wm_subwindow_open(wmWindow *win, rcti *winrct) /* extra service */ wm_subwindow_getsize(win, swin->swinid, &width, &height); - wmOrtho2(-0.375f, (float)width - 0.375f, -0.375f, (float)height - 0.375f); + wmOrtho2(-GLA_PIXEL_OFS, (float)width - GLA_PIXEL_OFS, -GLA_PIXEL_OFS, (float)height - GLA_PIXEL_OFS); glLoadIdentity(); return swin->swinid; @@ -229,7 +229,7 @@ void wm_subwindow_position(wmWindow *win, int swinid, rcti *winrct) /* extra service */ wmSubWindowSet(win, swinid); wm_subwindow_getsize(win, swinid, &width, &height); - wmOrtho2(-0.375f, (float)width - 0.375f, -0.375f, (float)height - 0.375f); + wmOrtho2(-GLA_PIXEL_OFS, (float)width - GLA_PIXEL_OFS, -GLA_PIXEL_OFS, (float)height - GLA_PIXEL_OFS); } else { printf("%s: Internal error, bad winid: %d\n", __func__, swinid); @@ -268,7 +268,7 @@ void wmSubWindowScissorSet(wmWindow *win, int swinid, rcti *srct) else glScissor(_curswin->winrct.xmin, _curswin->winrct.ymin, width, height); - wmOrtho2(-0.375f, (float)width - 0.375f, -0.375f, (float)height - 0.375f); + wmOrtho2(-GLA_PIXEL_OFS, (float)width - GLA_PIXEL_OFS, -GLA_PIXEL_OFS, (float)height - GLA_PIXEL_OFS); glLoadIdentity(); glFlush(); diff --git a/source/blenderplayer/CMakeLists.txt b/source/blenderplayer/CMakeLists.txt index 720d68ef00d..5a71b51c5dd 100644 --- a/source/blenderplayer/CMakeLists.txt +++ b/source/blenderplayer/CMakeLists.txt @@ -174,11 +174,10 @@ endif() if(WITH_MOD_BOOLEAN) list(APPEND BLENDER_SORTED_LIBS bf_intern_bsp) - list(APPEND BLENDER_SORTED_LIBS bf_intern_bop) list(APPEND BLENDER_SORTED_LIBS bf_intern_moto) endif() - if(WITH_CARVE) + if(WITH_MOD_BOOLEAN) list(APPEND BLENDER_SORTED_LIBS extern_carve) endif() diff --git a/source/blenderplayer/bad_level_call_stubs/stubs.c b/source/blenderplayer/bad_level_call_stubs/stubs.c index ad9470b7590..bdc08e0dbfa 100644 --- a/source/blenderplayer/bad_level_call_stubs/stubs.c +++ b/source/blenderplayer/bad_level_call_stubs/stubs.c @@ -99,6 +99,7 @@ struct Tex; struct TexResult; struct Text; struct ToolSettings; +struct View2D; struct View3D; struct bAction; struct bArmature; @@ -215,6 +216,9 @@ void *ED_region_draw_cb_activate(struct ARegionType *art, void(*draw)(const stru void *ED_region_draw_cb_customdata(void *handle) {return 0;} /* XXX This one looks wrong also */ void ED_region_draw_cb_exit(struct ARegionType *art, void *handle) {} void ED_area_headerprint(struct ScrArea *sa, char *str) {} +void UI_view2d_region_to_view(struct View2D *v2d, int x, int y, float *viewx, float *viewy) {} +void UI_view2d_view_to_region(struct View2D *v2d, float x, float y, int *regionx, int *regiony) {} +void UI_view2d_to_region_no_clip(struct View2D *v2d, float x, float y, int *regionx, int *region_y) {} struct EditBone *ED_armature_bone_get_mirrored(struct ListBase *edbo, struct EditBone *ebo) {return (struct EditBone *) NULL;} struct EditBone *ED_armature_edit_bone_add(struct bArmature *arm, char *name) {return (struct EditBone*) NULL;} diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt index 245f71ce1ea..c1c04588ff2 100644 --- a/source/creator/CMakeLists.txt +++ b/source/creator/CMakeLists.txt @@ -476,15 +476,15 @@ elseif(WIN32) endif() if(WITH_PYTHON) - set_lib_path(PYLIB "python/lib") + set_lib_path(PYLIB "python") install( - FILES ${PYLIB}/python32.dll + FILES ${PYLIB}/lib/python32.dll DESTINATION ${TARGETDIR} CONFIGURATIONS Release;RelWithDebInfo;MinSizeRel ) install( - FILES ${PYLIB}/python32_d.dll + FILES ${PYLIB}/lib/python32_d.dll DESTINATION ${TARGETDIR} CONFIGURATIONS Debug ) @@ -628,10 +628,10 @@ elseif(WIN32) if(WITH_OPENIMAGEIO) if(NOT MINGW) - set_lib_path(OIIOBIN "openimageio/bin") + set_lib_path(OIIOBIN "openimageio") install( FILES - ${OIIOBIN}/OpenImageIO.dll + ${OIIOBIN}/bin/OpenImageIO.dll DESTINATION ${TARGETDIR} ) endif() @@ -862,7 +862,6 @@ endif() bf_imbuf_dds bf_collada bf_intern_bsp - bf_intern_bop bf_intern_decimate bf_intern_elbeem bf_intern_ik @@ -945,7 +944,7 @@ endif() list(APPEND BLENDER_SORTED_LIBS bf_quicktime) endif() - if(WITH_CARVE) + if(WITH_MOD_BOOLEAN) list(APPEND BLENDER_SORTED_LIBS extern_carve) endif() diff --git a/source/creator/creator.c b/source/creator/creator.c index 79bfa521390..7262222447b 100644 --- a/source/creator/creator.c +++ b/source/creator/creator.c @@ -176,7 +176,7 @@ static void blender_esc(int sig) { static int count = 0; - G.afbreek = 1; /* forces render loop to read queue, not sure if its needed */ + G.is_break = TRUE; /* forces render loop to read queue, not sure if its needed */ if (sig == 2) { if (count) { @@ -392,7 +392,7 @@ static int debug_mode_libmv(int UNUSED(argc), const char **UNUSED(argv), void *U static int set_debug_value(int argc, const char **argv, void *UNUSED(data)) { if (argc > 1) { - G.rt = atoi(argv[1]); + G.debug_value = atoi(argv[1]); return 1; } @@ -455,16 +455,14 @@ static int set_env(int argc, const char **argv, void *UNUSED(data)) return 1; } -static int playback_mode(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data)) +static int playback_mode(int argc, const char **argv, void *UNUSED(data)) { + extern void playanim(int argc, const char **argv); + /* not if -b was given first */ if (G.background == 0) { -#if 0 /* TODO, bring player back? */ playanim(argc, argv); /* not the same argc and argv as before */ -#else - fprintf(stderr, "Playback mode not supported in blender 2.6x\n"); - exit(0); -#endif + exit(0); /* 2.4x didn't do this */ } return -2; @@ -1274,11 +1272,6 @@ int main(int argc, const char **argv) BLI_threadapi_init(); - RNA_init(); - RE_engines_init(); - - init_nodesystem(); - initglobals(); /* blender.c */ IMB_init(); @@ -1299,6 +1292,15 @@ int main(int argc, const char **argv) BLI_argsParse(ba, 1, NULL, NULL); #endif + + /* after level 1 args, this is so playanim skips RNA init */ + RNA_init(); + + RE_engines_init(); + init_nodesystem(); + /* end second init */ + + #if defined(WITH_PYTHON_MODULE) || defined(WITH_HEADLESS) G.background = 1; /* python module mode ALWAYS runs in background mode (for now) */ #else diff --git a/source/gameengine/Converter/BL_ArmatureObject.h b/source/gameengine/Converter/BL_ArmatureObject.h index ced6b94e6fd..6274e770409 100644 --- a/source/gameengine/Converter/BL_ArmatureObject.h +++ b/source/gameengine/Converter/BL_ArmatureObject.h @@ -83,7 +83,7 @@ public: bool SetActiveAction(class BL_ActionActuator *act, short priority, double curtime); - struct bArmature * GetArmature() { return m_armature; } + struct bArmature *GetArmature() { return m_armature; } const struct bArmature * GetArmature() const { return m_armature; } const struct Scene * GetScene() const { return m_scene; } diff --git a/source/gameengine/Ketsji/BL_Action.cpp b/source/gameengine/Ketsji/BL_Action.cpp index fbeb34b70b4..a21c3965be9 100644 --- a/source/gameengine/Ketsji/BL_Action.cpp +++ b/source/gameengine/Ketsji/BL_Action.cpp @@ -206,7 +206,7 @@ bool BL_Action::Play(const char* name, } // Now that we have an action, we have something we can play - m_starttime = KX_GetActiveEngine()->GetFrameTime(); + m_starttime = -1.f; // We get the start time on our first update m_startframe = m_localtime = start; m_endframe = end; m_blendin = blendin; @@ -338,6 +338,11 @@ void BL_Action::Update(float curtime) curtime -= KX_KetsjiEngine::GetSuspendedDelta(); + // Grab the start time here so we don't end up with a negative m_localtime when + // suspending and resuming scenes. + if (m_starttime < 0) + m_starttime = curtime; + if (m_calc_localtime) SetLocalTime(curtime); else diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp index b28b8c86d33..b602ba447ad 100644 --- a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp +++ b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp @@ -130,10 +130,10 @@ unsigned int* KX_BlenderMaterial::GetMCol(void) const void KX_BlenderMaterial::GetMaterialRGBAColor(unsigned char *rgba) const { if (mMaterial) { - *rgba++ = (unsigned char) (mMaterial->matcolor[0]*255.0); - *rgba++ = (unsigned char) (mMaterial->matcolor[1]*255.0); - *rgba++ = (unsigned char) (mMaterial->matcolor[2]*255.0); - *rgba++ = (unsigned char) (mMaterial->matcolor[3]*255.0); + *rgba++ = (unsigned char)(mMaterial->matcolor[0] * 255.0f); + *rgba++ = (unsigned char)(mMaterial->matcolor[1] * 255.0f); + *rgba++ = (unsigned char)(mMaterial->matcolor[2] * 255.0f); + *rgba++ = (unsigned char)(mMaterial->matcolor[3] * 255.0f); } else RAS_IPolyMaterial::GetMaterialRGBAColor(rgba); } diff --git a/source/gameengine/Ketsji/KX_Dome.cpp b/source/gameengine/Ketsji/KX_Dome.cpp index d87bb937b41..44c9cb1dab8 100644 --- a/source/gameengine/Ketsji/KX_Dome.cpp +++ b/source/gameengine/Ketsji/KX_Dome.cpp @@ -748,10 +748,10 @@ void KX_Dome::CreateMeshDome250(void) * Once we take the tangent of that angle, you have the verts coordinate corresponding to the verts on the side faces. * Then we need to multiply it by sqrt(2.0) to get the coordinate of the verts on the diagonal of the original cube. */ - verts_height = tan((rad_ang/2) - (MT_PI/2))*M_SQRT2; + verts_height = tanf((rad_ang / 2.0f) - (float)(MT_PI / 2.0)) * (float)M_SQRT2; - uv_height = uv_ratio * ((verts_height/2) + 0.5); - uv_base = uv_ratio * (1.0 - ((verts_height/2) + 0.5)); + uv_height = uv_ratio * ( (verts_height / 2.0f) + 0.5f); + uv_base = uv_ratio * (1.0 - ((verts_height / 2.0f) + 0.5f)); //creating faces for the env mapcube 180deg Dome // Front Face - 2 triangles @@ -1325,7 +1325,7 @@ void KX_Dome::FlattenDome(MT_Vector3 verts[3]) for (int i=0;i<3;i++) { r = atan2(sqrt(verts[i][0]*verts[i][0] + verts[i][2]*verts[i][2]), verts[i][1]); - r /= m_radangle/2; + r /= (double)this->m_radangle / 2.0; phi = atan2(verts[i][2], verts[i][0]); @@ -1818,13 +1818,13 @@ void KX_Dome::DrawDomeFisheye(void) else if (m_mode == DOME_TRUNCATED_FRONT) { ortho_width = 1.0; - ortho_height = 2 * ((float)can_height / can_width) - 1.0; + ortho_height = 2.0f * ((float)can_height / can_width) - 1.0f; glOrtho((-ortho_width), ortho_width, (-ortho_height), ortho_width, -20.0, 10.0); } else { //m_mode == DOME_TRUNCATED_REAR ortho_width = 1.0; - ortho_height = 2 * ((float)can_height / can_width) - 1.0; + ortho_height = 2.0f * ((float)can_height / can_width) - 1.0f; glOrtho((-ortho_width), ortho_width, (-ortho_width), ortho_height, -20.0, 10.0); } @@ -1905,8 +1905,8 @@ void KX_Dome::DrawPanorama(void) ortho_height = (float)can_height/can_width; } else { - ortho_width = (float)can_width/can_height * 0.5; - ortho_height = 0.5; + ortho_width = (float)can_width / can_height * 0.5f; + ortho_height = 0.5f; } glOrtho((-ortho_width), ortho_width, (-ortho_height), ortho_height, -20.0, 10.0); diff --git a/source/gameengine/Ketsji/KX_FontObject.cpp b/source/gameengine/Ketsji/KX_FontObject.cpp index 308154d8ebc..931eac7a974 100644 --- a/source/gameengine/Ketsji/KX_FontObject.cpp +++ b/source/gameengine/Ketsji/KX_FontObject.cpp @@ -117,25 +117,25 @@ void KX_FontObject::ProcessReplica() KX_GetActiveScene()->AddFont(this); } -int GetFontId (VFont *font) +int GetFontId (VFont *vfont) { PackedFile *packedfile=NULL; int fontid = -1; - if (font->packedfile) { - packedfile= font->packedfile; - fontid= BLF_load_mem(font->name, (unsigned char*)packedfile->data, packedfile->size); + if (vfont->packedfile) { + packedfile= vfont->packedfile; + fontid= BLF_load_mem(vfont->name, (unsigned char*)packedfile->data, packedfile->size); if (fontid == -1) { - printf("ERROR: packed font \"%s\" could not be loaded.\n", font->name); + printf("ERROR: packed font \"%s\" could not be loaded.\n", vfont->name); fontid = BLF_load("default"); } return fontid; } - /* once we have packed working we can load the FO_BUILTIN_NAME font */ - const char *filepath = font->name; - if (strcmp(FO_BUILTIN_NAME, filepath) == 0) { + /* once we have packed working we can load the builtin font */ + const char *filepath = vfont->name; + if (BKE_vfont_is_builtin(vfont)) { fontid = BLF_load("default"); /* XXX the following code is supposed to work (after you add get_builtin_packedfile to BKE_font.h ) diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 496b3925456..04a806dfd92 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -261,12 +261,12 @@ void KX_GameObject::SetParent(KX_Scene *scene, KX_GameObject* obj, bool addToCom // Make sure the objects have some scale MT_Vector3 scale1 = NodeGetWorldScaling(); MT_Vector3 scale2 = obj->NodeGetWorldScaling(); - if (fabs(scale2[0]) < FLT_EPSILON || - fabs(scale2[1]) < FLT_EPSILON || - fabs(scale2[2]) < FLT_EPSILON || - fabs(scale1[0]) < FLT_EPSILON || - fabs(scale1[1]) < FLT_EPSILON || - fabs(scale1[2]) < FLT_EPSILON) { return; } + if (fabs(scale2[0]) < (MT_Scalar)FLT_EPSILON || + fabs(scale2[1]) < (MT_Scalar)FLT_EPSILON || + fabs(scale2[2]) < (MT_Scalar)FLT_EPSILON || + fabs(scale1[0]) < (MT_Scalar)FLT_EPSILON || + fabs(scale1[1]) < (MT_Scalar)FLT_EPSILON || + fabs(scale1[2]) < (MT_Scalar)FLT_EPSILON) { return; } // Remove us from our old parent and set our new parent RemoveParent(scene); @@ -931,7 +931,7 @@ void KX_GameObject::AlignAxisToVect(const MT_Vector3& dir, int axis, float fac) return; } - if (fac<=0.0) { + if (fac <= 0.0f) { return; } @@ -944,10 +944,10 @@ void KX_GameObject::AlignAxisToVect(const MT_Vector3& dir, int axis, float fac) ori.setValue(orimat[0][2], orimat[1][2], orimat[2][2]); //pivot axis if (MT_abs(vect.dot(ori)) > 1.0-3.0*MT_EPSILON) //is the vector parallel to the pivot? ori.setValue(orimat[0][1], orimat[1][1], orimat[2][1]); //change the pivot! - if (fac == 1.0) { + if (fac == 1.0f) { x = vect; } else { - x = (vect * fac) + ((orimat * MT_Vector3(1.0, 0.0, 0.0)) * (1-fac)); + x = (vect * fac) + ((orimat * MT_Vector3(1.0, 0.0, 0.0)) * (1.0f - fac)); len = x.length(); if (MT_fuzzyZero(len)) x = vect; else x /= len; @@ -959,10 +959,10 @@ void KX_GameObject::AlignAxisToVect(const MT_Vector3& dir, int axis, float fac) ori.setValue(orimat[0][0], orimat[1][0], orimat[2][0]); if (MT_abs(vect.dot(ori)) > 1.0-3.0*MT_EPSILON) ori.setValue(orimat[0][2], orimat[1][2], orimat[2][2]); - if (fac == 1.0) { + if (fac == 1.0f) { y = vect; } else { - y = (vect * fac) + ((orimat * MT_Vector3(0.0, 1.0, 0.0)) * (1-fac)); + y = (vect * fac) + ((orimat * MT_Vector3(0.0, 1.0, 0.0)) * (1.0f - fac)); len = y.length(); if (MT_fuzzyZero(len)) y = vect; else y /= len; @@ -974,10 +974,10 @@ void KX_GameObject::AlignAxisToVect(const MT_Vector3& dir, int axis, float fac) ori.setValue(orimat[0][1], orimat[1][1], orimat[2][1]); if (MT_abs(vect.dot(ori)) > 1.0-3.0*MT_EPSILON) ori.setValue(orimat[0][0], orimat[1][0], orimat[2][0]); - if (fac == 1.0) { + if (fac == 1.0f) { z = vect; } else { - z = (vect * fac) + ((orimat * MT_Vector3(0.0, 0.0, 1.0)) * (1-fac)); + z = (vect * fac) + ((orimat * MT_Vector3(0.0, 0.0, 1.0)) * (1.0f - fac)); len = z.length(); if (MT_fuzzyZero(len)) z = vect; else z /= len; @@ -1162,9 +1162,9 @@ void KX_GameObject::NodeSetWorldScale(const MT_Vector3& scale) { // Make sure the objects have some scale MT_Vector3 p_scale = parent->GetWorldScaling(); - if (fabs(p_scale[0]) < FLT_EPSILON || - fabs(p_scale[1]) < FLT_EPSILON || - fabs(p_scale[2]) < FLT_EPSILON) + if (fabs(p_scale[0]) < (MT_Scalar)FLT_EPSILON || + fabs(p_scale[1]) < (MT_Scalar)FLT_EPSILON || + fabs(p_scale[2]) < (MT_Scalar)FLT_EPSILON) { return; } @@ -1190,9 +1190,9 @@ void KX_GameObject::NodeSetWorldPosition(const MT_Point3& trans) { // Make sure the objects have some scale MT_Vector3 scale = parent->GetWorldScaling(); - if (fabs(scale[0]) < FLT_EPSILON || - fabs(scale[1]) < FLT_EPSILON || - fabs(scale[2]) < FLT_EPSILON) + if (fabs(scale[0]) < (MT_Scalar)FLT_EPSILON || + fabs(scale[1]) < (MT_Scalar)FLT_EPSILON || + fabs(scale[2]) < (MT_Scalar)FLT_EPSILON) { return; } @@ -1940,7 +1940,7 @@ PyObject* KX_GameObject::pyattr_get_mass(void *self_v, const KX_PYATTRIBUTE_DEF { KX_GameObject* self= static_cast<KX_GameObject*>(self_v); KX_IPhysicsController *spc = self->GetPhysicsController(); - return PyFloat_FromDouble(spc ? spc->GetMass() : 0.0f); + return PyFloat_FromDouble(spc ? spc->GetMass() : 0.0); } int KX_GameObject::pyattr_set_mass(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) @@ -1948,7 +1948,7 @@ int KX_GameObject::pyattr_set_mass(void *self_v, const KX_PYATTRIBUTE_DEF *attrd KX_GameObject* self= static_cast<KX_GameObject*>(self_v); KX_IPhysicsController *spc = self->GetPhysicsController(); MT_Scalar val = PyFloat_AsDouble(value); - if (val < 0.0f) { /* also accounts for non float */ + if (val < 0.0) { /* also accounts for non float */ PyErr_SetString(PyExc_AttributeError, "gameOb.mass = float: KX_GameObject, expected a float zero or above"); return PY_SET_ATTR_FAIL; } @@ -1971,7 +1971,7 @@ int KX_GameObject::pyattr_set_lin_vel_min(void *self_v, const KX_PYATTRIBUTE_DEF KX_GameObject* self= static_cast<KX_GameObject*>(self_v); KX_IPhysicsController *spc = self->GetPhysicsController(); MT_Scalar val = PyFloat_AsDouble(value); - if (val < 0.0f) { /* also accounts for non float */ + if (val < 0.0) { /* also accounts for non float */ PyErr_SetString(PyExc_AttributeError, "gameOb.linVelocityMin = float: KX_GameObject, expected a float zero or above"); return PY_SET_ATTR_FAIL; } @@ -1994,7 +1994,7 @@ int KX_GameObject::pyattr_set_lin_vel_max(void *self_v, const KX_PYATTRIBUTE_DEF KX_GameObject* self= static_cast<KX_GameObject*>(self_v); KX_IPhysicsController *spc = self->GetPhysicsController(); MT_Scalar val = PyFloat_AsDouble(value); - if (val < 0.0f) { /* also accounts for non float */ + if (val < 0.0) { /* also accounts for non float */ PyErr_SetString(PyExc_AttributeError, "gameOb.linVelocityMax = float: KX_GameObject, expected a float zero or above"); return PY_SET_ATTR_FAIL; } @@ -2360,8 +2360,8 @@ int KX_GameObject::pyattr_set_timeOffset(void *self_v, const KX_PYATTRIBUTE_DEF KX_GameObject* self= static_cast<KX_GameObject*>(self_v); if (self->GetSGNode()) { MT_Scalar val = PyFloat_AsDouble(value); - SG_Node* sg_parent= self->GetSGNode()->GetSGParent(); - if (val < 0.0f) { /* also accounts for non float */ + SG_Node *sg_parent= self->GetSGNode()->GetSGParent(); + if (val < 0.0) { /* also accounts for non float */ PyErr_SetString(PyExc_AttributeError, "gameOb.timeOffset = float: KX_GameObject, expected a float zero or above"); return PY_SET_ATTR_FAIL; } @@ -2644,7 +2644,7 @@ PyObject* KX_GameObject::PyGetReactionForce() return PyObjectFrom(dummy_point); */ - return Py_BuildValue("fff", 0.0f, 0.0f, 0.0f); + return Py_BuildValue("fff", 0.0, 0.0, 0.0); } @@ -2761,18 +2761,18 @@ PyObject* KX_GameObject::PyAlignAxisToVect(PyObject* args) { PyObject* pyvect; int axis = 2; //z axis is the default - float fac = 1.0; + float fac = 1.0f; if (PyArg_ParseTuple(args,"O|if:alignAxisToVect",&pyvect,&axis, &fac)) { MT_Vector3 vect; - if (PyVecTo(pyvect, vect)) - { - if (fac<=0.0) Py_RETURN_NONE; // Nothing to do. - if (fac> 1.0) fac= 1.0; - - AlignAxisToVect(vect,axis,fac); - NodeUpdateGS(0.f); + if (PyVecTo(pyvect, vect)) { + if (fac > 0.0f) { + if (fac> 1.0f) fac = 1.0f; + + AlignAxisToVect(vect, axis, fac); + NodeUpdateGS(0.f); + } Py_RETURN_NONE; } } diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 536b32cbd77..a7ec1b52bd8 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -2007,13 +2007,21 @@ void setupGamePython(KX_KetsjiEngine* ketsjiengine, KX_Scene* startscene, Main * /* could be done a lot more nicely, but for now a quick way to get bge.* working */ PyRun_SimpleString("sys = __import__('sys');" - "mod = sys.modules['bge'] = type(sys)('bge');" - "mod.__dict__.update({'logic':__import__('GameLogic'), " + "bge = type(sys)('bge');" + "bge.__dict__.update({'logic':__import__('GameLogic'), " "'render':__import__('Rasterizer'), " "'events':__import__('GameKeys'), " "'constraints':__import__('PhysicsConstraints'), " "'types':__import__('GameTypes'), " "'texture':__import__('VideoTexture')});" + /* so we can do 'import bge.foo as bar' */ + "sys.modules.update({'bge': bge, " + "'bge.logic':bge.logic, " + "'bge.render':bge.render, " + "'bge.events':bge.events, " + "'bge.constraints':bge.constraints, " + "'bge.types':bge.types, " + "'bge.texture':bge.texture})" ); } diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index e09d5f13bfe..5d4b9ae40c2 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -2164,7 +2164,11 @@ PyObject* KX_Scene::pyattr_get_cameras(void *self_v, const KX_PYATTRIBUTE_DEF *a PyObject* KX_Scene::pyattr_get_active_camera(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { KX_Scene* self= static_cast<KX_Scene*>(self_v); - return self->GetActiveCamera()->GetProxy(); + KX_Camera* cam= self->GetActiveCamera(); + if (cam) + return self->GetActiveCamera()->GetProxy(); + else + Py_RETURN_NONE; } diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index 79898cdc0d4..5d28bf47401 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -451,6 +451,11 @@ bool CcdPhysicsEnvironment::removeCcdPhysicsController(CcdPhysicsController* ctr } else { m_dynamicsWorld->removeCollisionObject(ctrl->GetCollisionObject()); + + if (ctrl->GetCharacterController()) + { + m_dynamicsWorld->removeAction(ctrl->GetCharacterController()); + } } } if (ctrl->m_registerCount != 0) diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp index 76d1a64a4c0..b769fc4b703 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp @@ -962,10 +962,10 @@ void RAS_OpenGLRasterizer::IndexPrimitivesInternal(RAS_MeshSlot& ms, bool multi) void RAS_OpenGLRasterizer::SetProjectionMatrix(MT_CmMatrix4x4 &mat) { glMatrixMode(GL_PROJECTION); - double* matrix = &mat(0,0); + double* matrix = &mat(0, 0); glLoadMatrixd(matrix); - m_camortho= (mat(3, 3) != 0.0f); + m_camortho = (mat(3, 3) != 0.0); } void RAS_OpenGLRasterizer::SetProjectionMatrix(const MT_Matrix4x4 & mat) @@ -977,7 +977,7 @@ void RAS_OpenGLRasterizer::SetProjectionMatrix(const MT_Matrix4x4 & mat) /* Internally, MT_Matrix4x4 uses doubles (MT_Scalar). */ glLoadMatrixd(matrix); - m_camortho= (mat[3][3] != 0.0f); + m_camortho= (mat[3][3] != 0.0); } MT_Matrix4x4 RAS_OpenGLRasterizer::GetFrustumMatrix( @@ -1002,11 +1002,11 @@ MT_Matrix4x4 RAS_OpenGLRasterizer::GetFrustumMatrix( // if Rasterizer.setFocalLength is not called we use the camera focallength if (!m_setfocallength) // if focallength is null we use a value known to be reasonable - m_focallength = (focallength == 0.f) ? m_eyeseparation * 30.0 + m_focallength = (focallength == 0.f) ? m_eyeseparation * 30.0f : focallength; near_div_focallength = frustnear / m_focallength; - offset = 0.5 * m_eyeseparation * near_div_focallength; + offset = 0.5f * m_eyeseparation * near_div_focallength; switch(m_curreye) { case RAS_STEREO_LEFTEYE: diff --git a/source/gameengine/VideoTexture/ImageRender.cpp b/source/gameengine/VideoTexture/ImageRender.cpp index 9fdd0cd393b..c8763671dd1 100644 --- a/source/gameengine/VideoTexture/ImageRender.cpp +++ b/source/gameengine/VideoTexture/ImageRender.cpp @@ -138,7 +138,7 @@ void ImageRender::Render() // compute distance of observer to mirror = D - observerPos . normal MT_Scalar observerDistance = mirrorPlaneDTerm - observerWorldPos.dot(mirrorWorldZ); // if distance < 0.01 => observer is on wrong side of mirror, don't render - if (observerDistance < 0.01f) + if (observerDistance < 0.01) return; // set camera world position = observerPos + normal * 2 * distance MT_Point3 cameraWorldPos = observerWorldPos + (MT_Scalar(2.0)*observerDistance)*mirrorWorldZ; |