diff --git a/CMakeLists.txt b/CMakeLists.txt index d39dfd9e999..855a4d8777f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -837,6 +837,15 @@ elseif(WIN32) set(GETTEXT_LIBPATH ${GETTEXT}/lib) set(GETTEXT_LIBRARIES gnu_gettext) endif() + + set(LAPACK ${LIBDIR}/lapack) + # set(LAPACK_INCLUDE_DIR ${LAPACK}/include) + set_lib_path(LAPACK_LIBPATH ${LAPACK}/lib) + set(LAPACK_LIBRARIES + ${LIBDIR}/lapack/lib/libf2c.lib + ${LIBDIR}/lapack/lib/clapack_nowrap.lib + ${LIBDIR}/lapack/lib/BLAS_nowrap.lib + ) set(PNG_LIBRARIES libpng) set(JPEG_LIBRARIES libjpeg) @@ -1011,8 +1020,10 @@ elseif(WIN32) set(PLATFORM_CFLAGS "-pipe -funsigned-char -fno-strict-aliasing") if(WITH_MINGW64) - #Yes, the point for MinGW64 is moar optimization by default :) - set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -mmmx -msse -msse2 -ftree-vectorize") + #We need to take care though not to have these on debug builds because they may play funky with gdb + if(CMAKE_BUILD_TYPE MATCHES "Release") + set(PLATFORM_CFLAGS "${PLATFORM_CFLAGS} -mmmx -ftree-vectorize") + endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive") set(PLATFORM_LINKLIBS "${PLATFORM_LINKLIBS} -lpthread") diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake index eeefcf730c8..fbd28cc2398 100644 --- a/build_files/cmake/macros.cmake +++ b/build_files/cmake/macros.cmake @@ -214,7 +214,8 @@ macro(setup_liblinks ${OPENGL_glu_LIBRARY} ${PNG_LIBRARIES} ${ZLIB_LIBRARIES} - ${FREETYPE_LIBRARY}) + ${FREETYPE_LIBRARY} + ${LAPACK_LIBRARIES}) # since we are using the local libs for python when compiling msvc projects, we need to add _d when compiling debug versions if(WITH_PYTHON) # AND NOT WITH_PYTHON_MODULE # WIN32 needs diff --git a/build_files/cmake/packaging.cmake b/build_files/cmake/packaging.cmake index c0124fe8199..8a534bc530e 100644 --- a/build_files/cmake/packaging.cmake +++ b/build_files/cmake/packaging.cmake @@ -1,5 +1,5 @@ set(PROJECT_DESCRIPTION "Blender is a very fast and versatile 3D modeller/renderer.") -set(PROJECT_COPYRIGHT "Copyright (C) 2001-2011 Blender Foundation") +set(PROJECT_COPYRIGHT "Copyright (C) 2001-2012 Blender Foundation") set(PROJECT_CONTACT "foundation@blender.org") set(PROJECT_VENDOR "Blender Foundation") set(ORG_WEBSITE "www.blender.org") @@ -31,7 +31,7 @@ set(BUILD_REV ${MY_WC_REVISION}) # Force Package Name -set(CPACK_PACKAGE_FILE_NAME ${PROJECT_NAME}-${BLENDER_VERSION}-r${BUILD_REV}-${CMAKE_SYSTEM_PROCESSOR}) +set(CPACK_PACKAGE_FILE_NAME ${PROJECT_NAME}-${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}-1.r${BUILD_REV}-${CMAKE_SYSTEM_PROCESSOR}) if(CMAKE_SYSTEM_NAME MATCHES "Linux") # RPM packages diff --git a/build_files/package_spec/rpm/blender.spec.in b/build_files/package_spec/rpm/blender.spec.in index 25ad5344721..85a689031a3 100644 --- a/build_files/package_spec/rpm/blender.spec.in +++ b/build_files/package_spec/rpm/blender.spec.in @@ -1,5 +1,11 @@ # -*- rpm-spec -*- %global __python %{__python3} +%global blender_api @CPACK_PACKAGE_VERSION_MAJOR@.@CPACK_PACKAGE_VERSION_MINOR@ + +%define _rpmdir @CPACK_RPM_DIRECTORY@ +%define _rpmfilename @CPACK_RPM_FILE_NAME@ +%define _unpackaged_files_terminate_build 0 +%define _topdir @CPACK_RPM_DIRECTORY@ BuildRoot: @CPACK_RPM_DIRECTORY@/@CPACK_PACKAGE_FILE_NAME@@CPACK_RPM_PACKAGE_COMPONENT_PART_PATH@ Summary: @CPACK_RPM_PACKAGE_SUMMARY@ @@ -9,12 +15,17 @@ Release: @CPACK_RPM_PACKAGE_RELEASE@%{?dist} License: @CPACK_RPM_PACKAGE_LICENSE@ Group: @CPACK_RPM_PACKAGE_GROUP@ Vendor: @CPACK_RPM_PACKAGE_VENDOR@ -Epoch: 1 +Epoch: 1 -%define _rpmdir @CPACK_RPM_DIRECTORY@ -%define _rpmfilename @CPACK_RPM_FILE_NAME@ -%define _unpackaged_files_terminate_build 0 -%define _topdir @CPACK_RPM_DIRECTORY@ +Requires(post): desktop-file-utils +Requires(post): shared-mime-info +Requires(postun): desktop-file-utils +Requires(postun): shared-mime-info + +Provides: blender(ABI) = %{blender_api} +Provides: blender-fonts = %{?epoch:%{epoch}:}%{version}-%{release} + +Obsoletes: blender-fonts <= 2.49a-9 %description Blender is an integrated 3d suite for modelling, animation, rendering, @@ -40,6 +51,10 @@ then fi mv "@CPACK_TOPLEVEL_DIRECTORY@/tmpBBroot" ${RPM_BUILD_ROOT} +rm -f ${RPM_BUILD_ROOT}%{_bindir}/blender-thumbnailer.py + +%find_lang %{name} + %clean rm -rf ${RPM_BUILD_ROOT} @@ -57,14 +72,15 @@ if [ -x %{_bindir}/gtk-update-icon-cache ]; then %{_bindir}/gtk-update-icon-cache --quiet %{_datadir}/icons/hicolor fi || : -%files +%files -f blender.lang %defattr(-,root,root,-) %{_bindir}/%{name} -%{_datadir}/%{name}/@CPACK_PACKAGE_VERSION_MAJOR@.@CPACK_PACKAGE_VERSION_MINOR@ +%{_datadir}/%{name}/%{blender_api}/datafiles/fonts +%{_datadir}/%{name}/%{blender_api}/scripts %{_datadir}/icons/hicolor/*/apps/%{name}.* %{_datadir}/applications/%{name}.desktop -%{_datadir}/doc/blender -%{_mandir}/man1/blender.* +%{_datadir}/doc/%{name} +%{_mandir}/man1/%{name}.* %changelog @CPACK_RPM_SPEC_CHANGELOG@ diff --git a/build_files/scons/config/win64-mingw-config.py b/build_files/scons/config/win64-mingw-config.py index 37e4bcd77a8..cecf91e48a8 100644 --- a/build_files/scons/config/win64-mingw-config.py +++ b/build_files/scons/config/win64-mingw-config.py @@ -167,7 +167,7 @@ BF_BOOST_LIBPATH = BF_BOOST + '/lib' #Ray trace optimization WITH_BF_RAYOPTIMIZATION = True -BF_RAYOPTIMIZATION_SSE_FLAGS = ['-mmmx', '-msse', '-msse2', '-ftree-vectorize'] +BF_RAYOPTIMIZATION_SSE_FLAGS = ['-mmmx', '-msse', '-msse2'] #Produces errors while rendering with subsurf/multires, WITH_BF_OPENMP = False @@ -182,7 +182,7 @@ CXXFLAGS = [ '-fpermissive' ] CPPFLAGS = ['-DWIN32', '-DMS_WIN64', '-DFREE_WINDOWS', '-DFREE_WINDOWS64', '-D_LARGEFILE_SOURCE', '-D_FILE_OFFSET_BITS=64', '-D_LARGEFILE64_SOURCE', '-DBOOST_ALL_NO_LIB', '-DBOOST_THREAD_USE_LIB', '-DGLEW_STATIC'] REL_CFLAGS = [] REL_CXXFLAGS = [] -REL_CCFLAGS = ['-DNDEBUG', '-O2', '-mmmx', '-msse', '-msse2', '-ftree-vectorize'] +REL_CCFLAGS = ['-DNDEBUG', '-O2', '-ftree-vectorize'] C_WARN = ['-Wno-char-subscripts', '-Wdeclaration-after-statement', '-Wstrict-prototypes'] diff --git a/intern/elbeem/CMakeLists.txt b/intern/elbeem/CMakeLists.txt index a3c106ff465..064269b02bc 100644 --- a/intern/elbeem/CMakeLists.txt +++ b/intern/elbeem/CMakeLists.txt @@ -86,6 +86,7 @@ set(SRC intern/solver_interface.h intern/solver_relax.h intern/utilities.h + intern/globals.h ) add_definitions( diff --git a/intern/elbeem/intern/globals.h b/intern/elbeem/intern/globals.h new file mode 100644 index 00000000000..cbfd4d0b752 --- /dev/null +++ b/intern/elbeem/intern/globals.h @@ -0,0 +1,10 @@ +/** \file elbeem/intern/globals.h + * \ingroup elbeem + */ + +// required globals + +extern bool glob_mpactive; + +extern int glob_mpnum; +extern int glob_mpindex; diff --git a/intern/elbeem/intern/ntl_blenderdumper.cpp b/intern/elbeem/intern/ntl_blenderdumper.cpp index f3e8ecc1c31..4efff4337a6 100644 --- a/intern/elbeem/intern/ntl_blenderdumper.cpp +++ b/intern/elbeem/intern/ntl_blenderdumper.cpp @@ -18,6 +18,7 @@ #include "ntl_blenderdumper.h" #include "ntl_world.h" #include "solver_interface.h" +#include "globals.h" #include @@ -46,10 +47,6 @@ ntlBlenderDumper::~ntlBlenderDumper() debMsgStd("ntlBlenderDumper",DM_NOTIFY, "ntlBlenderDumper done", 10); } -// required globals -extern bool glob_mpactive; -extern int glob_mpnum, glob_mpindex; - /****************************************************************************** * Only dump time dep. objects to file *****************************************************************************/ diff --git a/intern/elbeem/intern/ntl_geometryobject.cpp b/intern/elbeem/intern/ntl_geometryobject.cpp index 43c6b1f9456..4f640253f0f 100644 --- a/intern/elbeem/intern/ntl_geometryobject.cpp +++ b/intern/elbeem/intern/ntl_geometryobject.cpp @@ -125,7 +125,7 @@ void ntlGeometryObject::initialize(ntlRenderGlobals *glob) } if(!gotit) { - errFatal("ntlGeometryObject::initialize","Obj '"< #include #include @@ -63,14 +68,11 @@ using std::string; #ifndef snprintf #define snprintf _snprintf #endif -#ifndef bool -#define bool int + +#ifdef _MSC_VER +#if _MSC_VER >= 1300 +#include #endif -#ifndef false -#define false 0 -#endif -#ifndef true -#define true 1 #endif #else // WIN32 @@ -102,6 +104,9 @@ using std::string; #ifndef M_PI #define M_PI 3.1415926536 +#endif + +#ifndef M_E #define M_E 2.7182818284 #endif diff --git a/intern/elbeem/intern/ntl_world.cpp b/intern/elbeem/intern/ntl_world.cpp index 3b649c9f5b9..0b36f724985 100644 --- a/intern/elbeem/intern/ntl_world.cpp +++ b/intern/elbeem/intern/ntl_world.cpp @@ -496,9 +496,6 @@ void ntlWorld::singleStepSims(double targetTime) { -extern bool glob_mpactive; -extern int glob_mpindex; - /****************************************************************************** * Render the current scene * uses the global variables from the parser diff --git a/intern/elbeem/intern/particletracer.cpp b/intern/elbeem/intern/particletracer.cpp index b939f9e51ef..d6bc450198f 100644 --- a/intern/elbeem/intern/particletracer.cpp +++ b/intern/elbeem/intern/particletracer.cpp @@ -19,6 +19,7 @@ #include "ntl_matrices.h" #include "ntl_ray.h" #include "ntl_matrices.h" +#include "globals.h" #include @@ -155,9 +156,6 @@ void ParticleTracer::cleanup() { } } -extern bool glob_mpactive; -extern int glob_mpindex,glob_mpnum; - /****************************************************************************** *! dump particles if desired *****************************************************************************/ diff --git a/intern/elbeem/intern/solver_adap.cpp b/intern/elbeem/intern/solver_adap.cpp index de5099f4416..aaf558c4762 100644 --- a/intern/elbeem/intern/solver_adap.cpp +++ b/intern/elbeem/intern/solver_adap.cpp @@ -928,9 +928,6 @@ void LbmFsgrSolver::interpolateCellFromCoarse(int lev, int i, int j,int k, int d -// required globals -extern bool glob_mpactive; -extern int glob_mpnum, glob_mpindex; #define MPTADAP_INTERV 4 /*****************************************************************************/ diff --git a/intern/elbeem/intern/solver_init.cpp b/intern/elbeem/intern/solver_init.cpp index 7e9f5e7f420..aede617a4d3 100644 --- a/intern/elbeem/intern/solver_init.cpp +++ b/intern/elbeem/intern/solver_init.cpp @@ -15,6 +15,8 @@ #include "solver_relax.h" // for geo init FGI_ defines #include "elbeem.h" +#include "globals.h" + // helper for 2d init #define SWAPYZ(vec) { \ @@ -296,9 +298,6 @@ #endif // LBMDIM==2 -// required globals -extern bool glob_mpactive; -extern int glob_mpnum, glob_mpindex; /****************************************************************************** diff --git a/intern/elbeem/intern/solver_main.cpp b/intern/elbeem/intern/solver_main.cpp index 8ec0f95a366..b9436e84922 100644 --- a/intern/elbeem/intern/solver_main.cpp +++ b/intern/elbeem/intern/solver_main.cpp @@ -14,6 +14,8 @@ #include "solver_relax.h" #include "particletracer.h" #include "loop_tools.h" +#include "globals.h" + #include /*****************************************************************************/ @@ -24,8 +26,6 @@ double globdfcnt; double globdfavg[19]; double globdfmax[19]; double globdfmin[19]; -extern int glob_mpindex,glob_mpnum; -extern bool globOutstrForce; // simulation object interface void LbmFsgrSolver::step() { diff --git a/intern/elbeem/intern/solver_relax.h b/intern/elbeem/intern/solver_relax.h index 370d8ea182b..ad88b3c37c5 100644 --- a/intern/elbeem/intern/solver_relax.h +++ b/intern/elbeem/intern/solver_relax.h @@ -390,7 +390,7 @@ #define DEFAULT_STREAM \ m[dC] = RAC(ccel,dC); \ \ - if(((!nbored) & CFBnd)) { \ + if(0 /* ((!nbored) & CFBnd) */) { \ \ m[dN ] = CSRC_N ; m[dS ] = CSRC_S ; \ m[dE ] = CSRC_E ; m[dW ] = CSRC_W ; \ diff --git a/intern/elbeem/intern/solver_util.cpp b/intern/elbeem/intern/solver_util.cpp index 0a80b234ad3..935a910e7d5 100644 --- a/intern/elbeem/intern/solver_util.cpp +++ b/intern/elbeem/intern/solver_util.cpp @@ -18,6 +18,8 @@ #include "ntl_world.h" #include "simulation_object.h" +#include "globals.h" + #include #include #ifndef sqrtf @@ -31,10 +33,6 @@ // try to enhance surface? #define SURFACE_ENH 2 -extern bool glob_mpactive; -extern bool glob_mpnum; -extern bool glob_mpindex; - //! for raytracing void LbmFsgrSolver::prepareVisualization( void ) { int lev = mMaxRefine; diff --git a/release/scripts/startup/bl_operators/image.py b/release/scripts/startup/bl_operators/image.py index 6af6488e86b..f2e5e57fad8 100644 --- a/release/scripts/startup/bl_operators/image.py +++ b/release/scripts/startup/bl_operators/image.py @@ -121,12 +121,14 @@ class SaveDirty(Operator): if image.packed_file: if image.library: self.report({'WARNING'}, - "Packed library image: %r from library %r can't be re-packed" % + "Packed library image: %r from library %r" + " can't be re-packed" % (image.name, image.library.filepath)) else: image.pack(as_png=True) else: - filepath = bpy.path.abspath(image.filepath, library=image.library) + filepath = bpy.path.abspath(image.filepath, + library=image.library) if "\\" not in filepath and "/" not in filepath: self.report({'WARNING'}, "Invalid path: " + filepath) elif filepath in unique_paths: diff --git a/release/scripts/startup/bl_operators/presets.py b/release/scripts/startup/bl_operators/presets.py index 564d6d7d8cf..05f7f3f0367 100644 --- a/release/scripts/startup/bl_operators/presets.py +++ b/release/scripts/startup/bl_operators/presets.py @@ -129,9 +129,6 @@ class AddPresetBase(): value = eval(rna_path) rna_recursive_attr_expand(value, rna_path, 1) - - - file_preset.close() preset_menu_class.bl_label = bpy.path.display_name(filename) diff --git a/release/scripts/startup/bl_ui/properties_animviz.py b/release/scripts/startup/bl_ui/properties_animviz.py index 1f798f46590..3c1f910814a 100644 --- a/release/scripts/startup/bl_ui/properties_animviz.py +++ b/release/scripts/startup/bl_ui/properties_animviz.py @@ -35,7 +35,7 @@ class MotionPathButtonsPanel(): layout = self.layout mps = avs.motion_path - + # Display Range layout.prop(mps, "type", expand=True) @@ -50,21 +50,21 @@ class MotionPathButtonsPanel(): elif (mps.type == 'RANGE'): sub.prop(mps, "frame_start", text="Start") sub.prop(mps, "frame_end", text="End") - + sub.prop(mps, "frame_step", text="Step") - + col = split.column() if bones: col.label(text="Cache for Bone:") else: col.label(text="Cache:") - + if mpath: sub = col.column(align=True) sub.enabled = False sub.prop(mpath, "frame_start", text="From") sub.prop(mpath, "frame_end", text="To") - + if bones: col.operator("pose.paths_update", text="Update Paths", icon='BONE_DATA') else: @@ -72,15 +72,14 @@ class MotionPathButtonsPanel(): else: col.label(text="Not available yet...", icon='ERROR') col.label(text="Calculate Paths first", icon='INFO') - - + # Display Settings split = layout.split() - + col = split.column() col.label(text="Show:") col.prop(mps, "show_frame_numbers", text="Frame Numbers") - + col = split.column() col.prop(mps, "show_keyframe_highlight", text="Keyframes") sub = col.column() diff --git a/release/scripts/startup/bl_ui/properties_data_armature.py b/release/scripts/startup/bl_ui/properties_data_armature.py index 529d7c5f981..6bec652045e 100644 --- a/release/scripts/startup/bl_ui/properties_data_armature.py +++ b/release/scripts/startup/bl_ui/properties_data_armature.py @@ -305,10 +305,10 @@ class DATA_PT_motion_paths(MotionPathButtonsPanel, Panel): ob = context.object avs = ob.pose.animation_visualisation - + pchan = context.active_pose_bone mpath = pchan.motion_path if pchan else None - + self.draw_settings(context, avs, mpath, bones=True) diff --git a/release/scripts/startup/bl_ui/properties_data_bone.py b/release/scripts/startup/bl_ui/properties_data_bone.py index 10c4c1fdd04..11524cf9c03 100644 --- a/release/scripts/startup/bl_ui/properties_data_bone.py +++ b/release/scripts/startup/bl_ui/properties_data_bone.py @@ -356,9 +356,6 @@ class BONE_PT_deform(BoneButtonsPanel, Panel): sub.prop(bone, "bbone_in", text="Ease In") sub.prop(bone, "bbone_out", text="Ease Out") - col.label(text="Offset:") - col.prop(bone, "use_cyclic_offset") - class BONE_PT_custom_props(BoneButtonsPanel, PropertyPanel, Panel): COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'} diff --git a/release/scripts/startup/bl_ui/properties_object.py b/release/scripts/startup/bl_ui/properties_object.py index cdef7e703e5..4f3ca26725c 100644 --- a/release/scripts/startup/bl_ui/properties_object.py +++ b/release/scripts/startup/bl_ui/properties_object.py @@ -301,7 +301,7 @@ class OBJECT_PT_motion_paths(MotionPathButtonsPanel, Panel): ob = context.object avs = ob.animation_visualisation mpath = ob.motion_path - + self.draw_settings(context, avs, mpath) diff --git a/release/scripts/startup/bl_ui/properties_paint_common.py b/release/scripts/startup/bl_ui/properties_paint_common.py index 94df1ed6cf5..53cf640beb9 100644 --- a/release/scripts/startup/bl_ui/properties_paint_common.py +++ b/release/scripts/startup/bl_ui/properties_paint_common.py @@ -67,3 +67,37 @@ class UnifiedPaintPanel(): ups = context.tool_settings.unified_paint_settings ptr = ups if ups.use_unified_weight else brush parent.prop(ptr, prop_name, icon=icon, text=text, slider=slider) + + +# Used in both the View3D toolbar and texture properties +def sculpt_brush_texture_settings(layout, brush): + tex_slot = brush.texture_slot + + layout.label(text="Brush Mapping:") + + # map_mode + layout.row().prop(tex_slot, "map_mode", text="") + layout.separator() + + # angle and texture_angle_source + col = layout.column() + col.active = brush.sculpt_capabilities.has_texture_angle_source + col.label(text="Angle:") + if brush.sculpt_capabilities.has_random_texture_angle: + col.prop(brush, "texture_angle_source_random", text="") + else: + col.prop(brush, "texture_angle_source_no_random", text="") + + col = layout.column() + col.active = brush.sculpt_capabilities.has_texture_angle + col.prop(tex_slot, "angle", text="") + + # scale and offset + split = layout.split() + split.prop(tex_slot, "offset") + split.prop(tex_slot, "scale") + + # texture_sample_bias + col = layout.column(align=True) + col.label(text="Sample Bias:") + col.prop(brush, "texture_sample_bias", slider=True, text="") diff --git a/release/scripts/startup/bl_ui/properties_physics_field.py b/release/scripts/startup/bl_ui/properties_physics_field.py index 2229b9dc3da..2054215df4a 100644 --- a/release/scripts/startup/bl_ui/properties_physics_field.py +++ b/release/scripts/startup/bl_ui/properties_physics_field.py @@ -112,7 +112,6 @@ class PHYSICS_PT_field(PhysicButtonsPanel, Panel): col = split.column() col.prop(field, "use_object_coords") - col.prop(field, "use_root_coords") col.prop(field, "use_2d_force") else: basic_force_field_settings_ui(self, context, field) diff --git a/release/scripts/startup/bl_ui/properties_texture.py b/release/scripts/startup/bl_ui/properties_texture.py index 32047581550..1d5e96cf701 100644 --- a/release/scripts/startup/bl_ui/properties_texture.py +++ b/release/scripts/startup/bl_ui/properties_texture.py @@ -29,6 +29,8 @@ from bpy.types import (Brush, from rna_prop_ui import PropertyPanel +from bl_ui.properties_paint_common import sculpt_brush_texture_settings + class TEXTURE_MT_specials(Menu): bl_label = "Texture Specials" @@ -856,12 +858,7 @@ class TEXTURE_PT_mapping(TextureSlotPanel, Panel): if isinstance(idblock, Brush): if context.sculpt_object: - layout.label(text="Brush Mapping:") - layout.prop(tex, "map_mode", expand=True) - - row = layout.row() - row.active = tex.map_mode in {'FIXED', 'TILED'} - row.prop(tex, "angle") + sculpt_brush_texture_settings(layout, idblock) else: if isinstance(idblock, Material): split = layout.split(percentage=0.3) @@ -884,9 +881,9 @@ class TEXTURE_PT_mapping(TextureSlotPanel, Panel): row.prop(tex, "mapping_y", text="") row.prop(tex, "mapping_z", text="") - row = layout.row() - row.column().prop(tex, "offset") - row.column().prop(tex, "scale") + row = layout.row() + row.column().prop(tex, "offset") + row.column().prop(tex, "scale") class TEXTURE_PT_influence(TextureSlotPanel, Panel): diff --git a/release/scripts/startup/bl_ui/space_clip.py b/release/scripts/startup/bl_ui/space_clip.py index 3c25d31f886..358c534a3a7 100644 --- a/release/scripts/startup/bl_ui/space_clip.py +++ b/release/scripts/startup/bl_ui/space_clip.py @@ -107,6 +107,7 @@ class CLIP_PT_clip_view_panel: return clip and sc.view == 'CLIP' + class CLIP_PT_tracking_panel: @classmethod diff --git a/release/scripts/startup/bl_ui/space_text.py b/release/scripts/startup/bl_ui/space_text.py index d1daa4a5554..9c24e48300a 100644 --- a/release/scripts/startup/bl_ui/space_text.py +++ b/release/scripts/startup/bl_ui/space_text.py @@ -277,7 +277,7 @@ class TEXT_MT_edit(Menu): layout.separator() - layout.operator("text.move_lines", + layout.operator("text.move_lines", text="Move line(s) up").direction = 'UP' layout.operator("text.move_lines", text="Move line(s) down").direction = 'DOWN' diff --git a/release/scripts/startup/bl_ui/space_time.py b/release/scripts/startup/bl_ui/space_time.py index 8fb587e2634..0f573c46d69 100644 --- a/release/scripts/startup/bl_ui/space_time.py +++ b/release/scripts/startup/bl_ui/space_time.py @@ -83,7 +83,7 @@ class TIME_HT_header(Header): row.prop(toolsettings, "use_keyframe_insert_auto", text="", toggle=True) if toolsettings.use_keyframe_insert_auto: row.prop(toolsettings, "use_keyframe_insert_keyingset", text="", toggle=True) - + if screen.is_animation_playing: subsub = row.row() subsub.prop(toolsettings, "use_record_with_nla", toggle=True) diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py index b3ac9481931..e069d78bff0 100644 --- a/release/scripts/startup/bl_ui/space_view3d.py +++ b/release/scripts/startup/bl_ui/space_view3d.py @@ -93,7 +93,7 @@ class VIEW3D_HT_header(Header): if snap_element != 'INCREMENT': row.prop(toolsettings, "snap_target", text="") if obj: - if obj.mode in {'OBJECT','POSE'} and snap_element != 'VOLUME': + if obj.mode in {'OBJECT', 'POSE'} and snap_element != 'VOLUME': row.prop(toolsettings, "use_snap_align_rotation", text="") elif obj.mode == 'EDIT': row.prop(toolsettings, "use_snap_self", text="") @@ -164,7 +164,7 @@ class VIEW3D_MT_transform(VIEW3D_MT_transform_base): def draw(self, context): # base menu VIEW3D_MT_transform_base.draw(self, context) - + # generic... layout = self.layout layout.separator() @@ -178,16 +178,16 @@ class VIEW3D_MT_transform_object(VIEW3D_MT_transform_base): def draw(self, context): # base menu VIEW3D_MT_transform_base.draw(self, context) - + # object-specific option follow... layout = self.layout layout.separator() layout.operator("transform.translate", text="Move Texture Space").texture_space = True layout.operator("transform.resize", text="Scale Texture Space").texture_space = True - + layout.separator() - + layout.operator_context = 'EXEC_REGION_WIN' layout.operator("transform.transform", text="Align to Transform Orientation").mode = 'ALIGN' # XXX see alignmenu() in edit.c of b2.4x to get this working @@ -214,13 +214,13 @@ class VIEW3D_MT_transform_armature(VIEW3D_MT_transform_base): def draw(self, context): # base menu VIEW3D_MT_transform_base.draw(self, context) - + # armature specific extensions follow... layout = self.layout layout.separator() obj = context.object - if (obj.type == 'ARMATURE' and obj.mode in {'EDIT', 'POSE'} and + if (obj.type == 'ARMATURE' and obj.mode in {'EDIT', 'POSE'} and obj.data.draw_type in {'BBONE', 'ENVELOPE'}): layout.operator("transform.transform", text="Scale Envelope/BBone").mode = 'BONE_SIZE' @@ -612,6 +612,7 @@ class VIEW3D_MT_select_edit_curve(Menu): layout.operator("curve.select_all", text="Inverse").action = 'INVERT' layout.operator("curve.select_random") layout.operator("curve.select_nth", text="Every Nth Number of Points") + layout.operator("curve.select_linked", text="Select Linked") layout.separator() @@ -641,6 +642,7 @@ class VIEW3D_MT_select_edit_surface(Menu): layout.operator("curve.select_all", text="Inverse").action = 'INVERT' layout.operator("curve.select_random") layout.operator("curve.select_nth", text="Every Nth Number of Points") + layout.operator("curve.select_linked", text="Select Linked") layout.separator() @@ -1286,7 +1288,7 @@ class VIEW3D_MT_hide_mask(Menu): op = layout.operator("paint.hide_show", text="Show Bounding Box") op.action = 'SHOW' op.area = 'INSIDE' - + op = layout.operator("paint.hide_show", text="Hide Masked") op.area = 'MASKED' op.action = 'HIDE' @@ -1989,7 +1991,7 @@ class VIEW3D_MT_edit_curve_ctrlpoints(Menu): layout.separator() - layout.menu("VIEW3D_MT_hook") + layout.menu("VIEW3D_MT_hook") class VIEW3D_MT_edit_curve_segments(Menu): @@ -2299,7 +2301,7 @@ class VIEW3D_PT_view3d_cursor(Panel): @classmethod def poll(cls, context): view = context.space_data - return (view) + return (view is not None) def draw(self, context): layout = self.layout diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py index f3fa1585d56..d3a8427aa16 100644 --- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py +++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py @@ -20,6 +20,7 @@ import bpy from bpy.types import Menu, Panel from bl_ui.properties_paint_common import UnifiedPaintPanel +from bl_ui.properties_paint_common import sculpt_brush_texture_settings class View3DPanel(): @@ -719,45 +720,11 @@ class VIEW3D_PT_tools_brush_texture(Panel, View3DPaintPanel): col.prop(brush, "use_fixed_texture") if context.sculpt_object: - #XXX duplicated from properties_texture.py - - col.label(text="Brush Mapping:") - col.row().prop(tex_slot, "map_mode", expand=True) - - col.separator() - - col = layout.column() - col.active = tex_slot.map_mode in {'FIXED'} - col.label(text="Angle:") - if brush.sculpt_capabilities.has_random_texture_angle: - col.prop(brush, "texture_angle_source_random", text="") - else: - col.prop(brush, "texture_angle_source_no_random", text="") - - #row = col.row(align=True) - #row.label(text="Angle:") - #row.active = tex_slot.map_mode in {'FIXED', 'TILED'} - - #row = col.row(align=True) - - #col = row.column() - #col.active = tex_slot.map_mode in {'FIXED'} - #col.prop(brush, "use_rake", toggle=True, icon='PARTICLEMODE', text="") - - col = layout.column() - col.active = tex_slot.map_mode in {'FIXED', 'TILED'} - col.prop(tex_slot, "angle", text="") - - split = layout.split() - split.prop(tex_slot, "offset") - split.prop(tex_slot, "scale") + sculpt_brush_texture_settings(col, brush) + # use_texture_overlay and texture_overlay_alpha col = layout.column(align=True) - col.label(text="Sample Bias:") - col.prop(brush, "texture_sample_bias", slider=True, text="") - - col = layout.column(align=True) - col.active = tex_slot.map_mode in {'FIXED', 'TILED'} + col.active = brush.sculpt_capabilities.has_overlay col.label(text="Overlay:") row = col.row() @@ -766,7 +733,6 @@ class VIEW3D_PT_tools_brush_texture(Panel, View3DPaintPanel): else: row.prop(brush, "use_texture_overlay", toggle=True, text="", icon='RESTRICT_VIEW_ON') sub = row.row() - sub.active = tex_slot.map_mode in {'FIXED', 'TILED'} and brush.use_texture_overlay sub.prop(brush, "texture_overlay_alpha", text="Alpha") diff --git a/source/blender/blenkernel/BKE_colortools.h b/source/blender/blenkernel/BKE_colortools.h index b85f0efe7e3..d67e1a9118e 100644 --- a/source/blender/blenkernel/BKE_colortools.h +++ b/source/blender/blenkernel/BKE_colortools.h @@ -33,6 +33,7 @@ struct CurveMapping; struct CurveMap; +struct CurveMapPoint; struct Scopes; struct ImBuf; struct rctf; @@ -52,12 +53,14 @@ void curvemapping_set_black_white(struct CurveMapping *cumap, con #define CURVEMAP_SLOPE_NEGATIVE 0 #define CURVEMAP_SLOPE_POSITIVE 1 -void curvemap_reset(struct CurveMap *cuma, struct rctf *clipr, int preset, int slope); -void curvemap_remove(struct CurveMap *cuma, int flag); -void curvemap_insert(struct CurveMap *cuma, float x, float y); -void curvemap_sethandle(struct CurveMap *cuma, int type); +void curvemap_reset(struct CurveMap *cuma, struct rctf *clipr, int preset, int slope); +void curvemap_remove(struct CurveMap *cuma, int flag); +void curvemap_remove_point(struct CurveMap *cuma, struct CurveMapPoint *cmp); +struct CurveMapPoint *curvemap_insert(struct CurveMap *cuma, float x, float y); +void curvemap_sethandle(struct CurveMap *cuma, int type); void curvemapping_changed(struct CurveMapping *cumap, int rem_doubles); +void curvemapping_changed_all(struct CurveMapping *cumap); /* single curve, no table check */ float curvemap_evaluateF(struct CurveMap *cuma, float value); diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h index 62ba85ae937..c168c39fd9f 100644 --- a/source/blender/blenkernel/BKE_mesh.h +++ b/source/blender/blenkernel/BKE_mesh.h @@ -266,8 +266,8 @@ void create_vert_poly_map(MeshElemMap **map, int **mem, const struct MPoly *mface, const struct MLoop *mloop, int totvert, int totface, int totloop); -void create_vert_edge_map(struct ListBase **map, IndexNode **mem, const struct MEdge *medge, - const int totvert, const int totedge); +void create_vert_edge_map(MeshElemMap **map, int **mem, + const struct MEdge *medge, int totvert, int totedge); /* vertex level transformations & checks (no derived mesh) */ diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h index b0ee81f577a..1cdf2ee2e14 100644 --- a/source/blender/blenkernel/BKE_object.h +++ b/source/blender/blenkernel/BKE_object.h @@ -151,6 +151,7 @@ struct KeyBlock *BKE_object_insert_shape_key(struct Scene *scene, struct Object int BKE_object_is_modified(struct Scene *scene, struct Object *ob); int BKE_object_is_deform_modified(struct Scene *scene, struct Object *ob); +int BKE_object_is_animated(struct Scene *scene, struct Object *ob); void BKE_object_relink(struct Object *ob); diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index 9e46d03a3ab..0f8716e2b04 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -574,7 +574,7 @@ void BKE_pose_channels_hash_make(bPose *pose) if (!pose->chanhash) { bPoseChannel *pchan; - pose->chanhash = BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp, "make_pose_chan gh"); + pose->chanhash = BLI_ghash_str_new("make_pose_chan gh"); for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) BLI_ghash_insert(pose->chanhash, pchan->name, pchan); } diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c index b521285c626..0e81b503cbf 100644 --- a/source/blender/blenkernel/intern/cloth.c +++ b/source/blender/blenkernel/intern/cloth.c @@ -419,6 +419,61 @@ static int do_step_cloth(Object *ob, ClothModifierData *clmd, DerivedMesh *resul return ret; } +#if 0 +static DerivedMesh *cloth_to_triangles(DerivedMesh *dm) +{ + DerivedMesh *result = NULL; + unsigned int i = 0, j = 0; + unsigned int quads = 0, numfaces = dm->getNumTessFaces(dm); + MFace *mface = dm->getTessFaceArray(dm); + MFace *mface2 = NULL; + + /* calc faces */ + for(i = 0; i < numfaces; i++) + { + if(mface[i].v4) + quads++; + } + + result = CDDM_from_template(dm, dm->getNumVerts(dm), 0, numfaces + quads, 0, 0); + + DM_copy_vert_data(dm, result, 0, 0, dm->getNumVerts(dm)); + DM_copy_tessface_data(dm, result, 0, 0, numfaces); + + DM_ensure_tessface(result); + mface2 = result->getTessFaceArray(result); + + for(i = 0, j = numfaces; i < numfaces; i++) + { + // DG TODO: is this necessary? + mface2[i].v1 = mface[i].v1; + mface2[i].v2 = mface[i].v2; + mface2[i].v3 = mface[i].v3; + + mface2[i].v4 = 0; + //test_index_face(&mface2[i], &result->faceData, i, 3); + + if(mface[i].v4) + { + DM_copy_tessface_data(dm, result, i, j, 1); + + mface2[j].v1 = mface[i].v1; + mface2[j].v2 = mface[i].v3; + mface2[j].v3 = mface[i].v4; + mface2[j].v4 = 0; + //test_index_face(&mface2[j], &result->faceData, j, 3); + + j++; + } + } + + CDDM_calc_edges_tessface(result); + CDDM_tessfaces_to_faces(result); /* builds ngon faces from tess (mface) faces */ + + return result; +} +#endif + /************************************************ * clothModifier_do - main simulation function ************************************************/ diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c index 609b2d3496c..a93653537c7 100644 --- a/source/blender/blenkernel/intern/collision.c +++ b/source/blender/blenkernel/intern/collision.c @@ -161,284 +161,7 @@ void bvhtree_update_from_mvert(BVHTree * bvhtree, MFace *faces, int numfaces, MV /*********************************** Collision modifier code end ***********************************/ - -/** -* gsl_poly_solve_cubic - -* -* copied from SOLVE_CUBIC.C --> GSL -*/ - #define mySWAP(a, b) do { double tmp = b ; b = a ; a = tmp ; } while (0) -#if 0 /* UNUSED */ -static int -gsl_poly_solve_cubic (double a, double b, double c, - double *x0, double *x1, double *x2) -{ - double q = (a * a - 3 * b); - double r = (2 * a * a * a - 9 * a * b + 27 * c); - - double Q = q / 9; - double R = r / 54; - - double Q3 = Q * Q * Q; - double R2 = R * R; - - double CR2 = 729 * r * r; - double CQ3 = 2916 * q * q * q; - - if (R == 0 && Q == 0) - { - *x0 = - a / 3; - *x1 = - a / 3; - *x2 = - a / 3; - return 3; - } - else if (CR2 == CQ3) - { - /* this test is actually R2 == Q3, written in a form suitable - for exact computation with integers */ - - /* Due to finite precision some double roots may be missed, and - considered to be a pair of complex roots z = x +/- epsilon i - close to the real axis. */ - - double sqrtQ = sqrt (Q); - - if (R > 0) - { - *x0 = -2 * sqrtQ - a / 3; - *x1 = sqrtQ - a / 3; - *x2 = sqrtQ - a / 3; - } - else - { - *x0 = - sqrtQ - a / 3; - *x1 = - sqrtQ - a / 3; - *x2 = 2 * sqrtQ - a / 3; - } - return 3; - } - else if (CR2 < CQ3) /* equivalent to R2 < Q3 */ - { - double sqrtQ = sqrt (Q); - double sqrtQ3 = sqrtQ * sqrtQ * sqrtQ; - double theta = acos (R / sqrtQ3); - double norm = -2 * sqrtQ; - *x0 = norm * cos (theta / 3) - a / 3; - *x1 = norm * cos ((theta + 2.0 * M_PI) / 3) - a / 3; - *x2 = norm * cos ((theta - 2.0 * M_PI) / 3) - a / 3; - - /* Sort *x0, *x1, *x2 into increasing order */ - - if (*x0 > *x1) - mySWAP(*x0, *x1); - - if (*x1 > *x2) - { - mySWAP(*x1, *x2); - - if (*x0 > *x1) - mySWAP(*x0, *x1); - } - - return 3; - } - else - { - double sgnR = (R >= 0 ? 1 : -1); - double A = -sgnR * pow (fabs (R) + sqrt (R2 - Q3), 1.0/3.0); - double B = Q / A; - *x0 = A + B - a / 3; - return 1; - } -} - - - -/** -* gsl_poly_solve_quadratic -* -* copied from GSL -*/ -static int -gsl_poly_solve_quadratic (double a, double b, double c, - double *x0, double *x1) -{ - double disc = b * b - 4 * a * c; - - if (a == 0) /* Handle linear case */ - { - if (b == 0) - { - return 0; - } - else - { - *x0 = -c / b; - return 1; - }; - } - - if (disc > 0) - { - if (b == 0) - { - double r = fabs (0.5 * sqrt (disc) / a); - *x0 = -r; - *x1 = r; - } - else - { - double sgnb = (b > 0 ? 1 : -1); - double temp = -0.5 * (b + sgnb * sqrt (disc)); - double r1 = temp / a; - double r2 = c / temp; - - if (r1 < r2) - { - *x0 = r1; - *x1 = r2; - } - else - { - *x0 = r2; - *x1 = r1; - } - } - return 2; - } - else if (disc == 0) - { - *x0 = -0.5 * b / a; - *x1 = -0.5 * b / a; - return 2; - } - else - { - return 0; - } -} -#endif /* UNUSED */ - - - -/* -* See Bridson et al. "Robust Treatment of Collision, Contact and Friction for Cloth Animation" -* page 4, left column -*/ -#if 0 -static int cloth_get_collision_time ( double a[3], double b[3], double c[3], double d[3], double e[3], double f[3], double solution[3] ) -{ - int num_sols = 0; - - // x^0 - checked - double g = a[0] * c[1] * e[2] - a[0] * c[2] * e[1] + - a[1] * c[2] * e[0] - a[1] * c[0] * e[2] + - a[2] * c[0] * e[1] - a[2] * c[1] * e[0]; - - // x^1 - double h = -b[2] * c[1] * e[0] + b[1] * c[2] * e[0] - a[2] * d[1] * e[0] + - a[1] * d[2] * e[0] + b[2] * c[0] * e[1] - b[0] * c[2] * e[1] + - a[2] * d[0] * e[1] - a[0] * d[2] * e[1] - b[1] * c[0] * e[2] + - b[0] * c[1] * e[2] - a[1] * d[0] * e[2] + a[0] * d[1] * e[2] - - a[2] * c[1] * f[0] + a[1] * c[2] * f[0] + a[2] * c[0] * f[1] - - a[0] * c[2] * f[1] - a[1] * c[0] * f[2] + a[0] * c[1] * f[2]; - - // x^2 - double i = -b[2] * d[1] * e[0] + b[1] * d[2] * e[0] + - b[2] * d[0] * e[1] - b[0] * d[2] * e[1] - - b[1] * d[0] * e[2] + b[0] * d[1] * e[2] - - b[2] * c[1] * f[0] + b[1] * c[2] * f[0] - - a[2] * d[1] * f[0] + a[1] * d[2] * f[0] + - b[2] * c[0] * f[1] - b[0] * c[2] * f[1] + - a[2] * d[0] * f[1] - a[0] * d[2] * f[1] - - b[1] * c[0] * f[2] + b[0] * c[1] * f[2] - - a[1] * d[0] * f[2] + a[0] * d[1] * f[2]; - - // x^3 - checked - double j = -b[2] * d[1] * f[0] + b[1] * d[2] * f[0] + - b[2] * d[0] * f[1] - b[0] * d[2] * f[1] - - b[1] * d[0] * f[2] + b[0] * d[1] * f[2]; - - /* - printf("r1: %lf\n", a[0] * c[1] * e[2] - a[0] * c[2] * e[1]); - printf("r2: %lf\n", a[1] * c[2] * e[0] - a[1] * c[0] * e[2]); - printf("r3: %lf\n", a[2] * c[0] * e[1] - a[2] * c[1] * e[0]); - - printf("x1 x: %f, y: %f, z: %f\n", a[0], a[1], a[2]); - printf("x2 x: %f, y: %f, z: %f\n", c[0], c[1], c[2]); - printf("x3 x: %f, y: %f, z: %f\n", e[0], e[1], e[2]); - - printf("v1 x: %f, y: %f, z: %f\n", b[0], b[1], b[2]); - printf("v2 x: %f, y: %f, z: %f\n", d[0], d[1], d[2]); - printf("v3 x: %f, y: %f, z: %f\n", f[0], f[1], f[2]); - - printf("t^3: %lf, t^2: %lf, t^1: %lf, t^0: %lf\n", j, i, h, g); - -*/ - // Solve cubic equation to determine times t1, t2, t3, when the collision will occur. - if ( ABS ( j ) > DBL_EPSILON ) - { - i /= j; - h /= j; - g /= j; - num_sols = gsl_poly_solve_cubic ( i, h, g, &solution[0], &solution[1], &solution[2] ); - } - else - { - num_sols = gsl_poly_solve_quadratic ( i, h, g, &solution[0], &solution[1] ); - solution[2] = -1.0; - } - - // printf("num_sols: %d, sol1: %lf, sol2: %lf, sol3: %lf\n", num_sols, solution[0], solution[1], solution[2]); - - // Discard negative solutions - if ( ( num_sols >= 1 ) && ( solution[0] < DBL_EPSILON ) ) - { - --num_sols; - solution[0] = solution[num_sols]; - } - if ( ( num_sols >= 2 ) && ( solution[1] < DBL_EPSILON ) ) - { - --num_sols; - solution[1] = solution[num_sols]; - } - if ( ( num_sols == 3 ) && ( solution[2] < DBL_EPSILON ) ) - { - --num_sols; - } - - // Sort - if ( num_sols == 2 ) - { - if ( solution[0] > solution[1] ) - { - double tmp = solution[0]; - solution[0] = solution[1]; - solution[1] = tmp; - } - } - else if ( num_sols == 3 ) - { - - // Bubblesort - if ( solution[0] > solution[1] ) - { - double tmp = solution[0]; solution[0] = solution[1]; solution[1] = tmp; - } - if ( solution[1] > solution[2] ) - { - double tmp = solution[1]; solution[1] = solution[2]; solution[2] = tmp; - } - if ( solution[0] > solution[1] ) - { - double tmp = solution[0]; solution[0] = solution[1]; solution[1] = tmp; - } - } - - return num_sols; -} -#endif // w3 is not perfect @@ -485,7 +208,6 @@ DO_INLINE void collision_interpolateOnTriangle ( float to[3], float v1[3], float VECADDMUL(to, v3, w3); } -#ifndef WITH_ELTOPO static int cloth_collision_response_static ( ClothModifierData *clmd, CollisionModifierData *collmd, CollPair *collpair, CollPair *collision_end ) { int result = 0; @@ -498,6 +220,12 @@ static int cloth_collision_response_static ( ClothModifierData *clmd, CollisionM cloth1 = clmd->clothObject; for ( ; collpair != collision_end; collpair++ ) { + float i1[3], i2[3], i3[3]; + + zero_v3(i1); + zero_v3(i2); + zero_v3(i3); + // only handle static collisions here if ( collpair->flag & COLLISION_IN_FUTURE ) continue; @@ -553,9 +281,9 @@ static int cloth_collision_response_static ( ClothModifierData *clmd, CollisionM normalize_v3(vrel_t_pre); impulse = magtangent / ( 1.0f + w1*w1 + w2*w2 + w3*w3 ); // 2.0 * - VECADDMUL ( cloth1->verts[collpair->ap1].impulse, vrel_t_pre, w1 * impulse ); - VECADDMUL ( cloth1->verts[collpair->ap2].impulse, vrel_t_pre, w2 * impulse ); - VECADDMUL ( cloth1->verts[collpair->ap3].impulse, vrel_t_pre, w3 * impulse ); + VECADDMUL ( i1, vrel_t_pre, w1 * impulse ); + VECADDMUL ( i2, vrel_t_pre, w2 * impulse ); + VECADDMUL ( i3, vrel_t_pre, w3 * impulse ); } // Apply velocity stopping impulse @@ -563,13 +291,13 @@ static int cloth_collision_response_static ( ClothModifierData *clmd, CollisionM // no 2.0 * magrelVel normally, but looks nicer DG impulse = magrelVel / ( 1.0 + w1*w1 + w2*w2 + w3*w3 ); - VECADDMUL ( cloth1->verts[collpair->ap1].impulse, collpair->normal, w1 * impulse ); + VECADDMUL ( i1, collpair->normal, w1 * impulse ); cloth1->verts[collpair->ap1].impulse_count++; - VECADDMUL ( cloth1->verts[collpair->ap2].impulse, collpair->normal, w2 * impulse ); + VECADDMUL ( i2, collpair->normal, w2 * impulse ); cloth1->verts[collpair->ap2].impulse_count++; - VECADDMUL ( cloth1->verts[collpair->ap3].impulse, collpair->normal, w3 * impulse ); + VECADDMUL ( i3, collpair->normal, w3 * impulse ); cloth1->verts[collpair->ap3].impulse_count++; // Apply repulse impulse if distance too short @@ -586,785 +314,64 @@ static int cloth_collision_response_static ( ClothModifierData *clmd, CollisionM repulse = MAX2 ( impulse, repulse ); impulse = repulse / ( 1.0f + w1*w1 + w2*w2 + w3*w3 ); // original 2.0 / 0.25 - VECADDMUL ( cloth1->verts[collpair->ap1].impulse, collpair->normal, impulse ); - VECADDMUL ( cloth1->verts[collpair->ap2].impulse, collpair->normal, impulse ); - VECADDMUL ( cloth1->verts[collpair->ap3].impulse, collpair->normal, impulse ); + VECADDMUL ( i1, collpair->normal, impulse ); + VECADDMUL ( i2, collpair->normal, impulse ); + VECADDMUL ( i3, collpair->normal, impulse ); } result = 1; } - } - return result; -} -#endif /* !WITH_ELTOPO */ - -#ifdef WITH_ELTOPO -typedef struct edgepairkey { - int a1, a2, b1, b2; -} edgepairkey; - -unsigned int edgepair_hash(void *vkey) -{ - edgepairkey *key = vkey; - int keys[4] = {key->a1, key->a2, key->b1, key->b2}; - int i, j; - - for (i=0; i<4; i++) { - for (j=0; j<3; j++) { - if (keys[j] >= keys[j+1]) { - SWAP(int, keys[j], keys[j+1]); - } - } - } - - return keys[0]*101 + keys[1]*72 + keys[2]*53 + keys[3]*34; -} - -int edgepair_cmp(const void *va, const void *vb) -{ - edgepairkey *a = va, *b = vb; - int keysa[4] = {a->a1, a->a2, a->b1, a->b2}; - int keysb[4] = {b->a1, b->a2, b->b1, b->b2}; - int i; - - for (i=0; i<4; i++) { - int j, ok=0; - for (j=0; j<4; j++) { - if (keysa[i] == keysa[j]) { - ok = 1; - break; - } - } - if (!ok) - return -1; - } - - return 0; -} - -static void get_edgepairkey(edgepairkey *key, int a1, int a2, int b1, int b2) -{ - key->a1 = a1; - key->a2 = a2; - key->b1 = b1; - key->b2 = b2; -} - -/*an immense amount of duplication goes on here. . .a major performance hit, I'm sure*/ -static CollPair* cloth_edge_collision ( ModifierData *md1, ModifierData *md2, - BVHTreeOverlap *overlap, CollPair *collpair, - GHash *visithash, MemArena *arena) -{ - ClothModifierData *clmd = (ClothModifierData *)md1; - CollisionModifierData *collmd = (CollisionModifierData *) md2; - MFace *face1=NULL, *face2 = NULL; - ClothVertex *verts1 = clmd->clothObject->verts; - double distance = 0; - edgepairkey *key, tstkey; - float epsilon1 = clmd->coll_parms->epsilon; - float epsilon2 = BLI_bvhtree_getepsilon ( collmd->bvhtree ); - float no[3], uv[3], t, relnor; - int i, i1, i2, i3, i4, i5, i6; - Cloth *cloth = clmd->clothObject; - float n1[3], n2[3], off[3], v1[2][3], v2[2][3], v3[2][3], v4[2][3], v5[2][3], v6[2][3]; - void **verts[] = {v1, v2, v3, v4, v5, v6}; - int j, ret, bp1, bp2, bp3, ap1, ap2, ap3, table[6]; - - face1 = & ( clmd->clothObject->mfaces[overlap->indexA] ); - face2 = & ( collmd->mfaces[overlap->indexB] ); - - // check all 4 possible collisions - for ( i = 0; i < 4; i++ ) { - if ( i == 0 ) { - // fill faceA - ap1 = face1->v1; - ap2 = face1->v2; - ap3 = face1->v3; - - // fill faceB - bp1 = face2->v1; - bp2 = face2->v2; - bp3 = face2->v3; - } - else if ( i == 1 ) { - if ( face1->v4 ) { - // fill faceA - ap1 = face1->v1; - ap2 = face1->v3; - ap3 = face1->v4; - - // fill faceB - bp1 = face2->v1; - bp2 = face2->v2; - bp3 = face2->v3; - } - else { - continue; - } - } - if ( i == 2 ) { - if ( face2->v4 ) { - // fill faceA - ap1 = face1->v1; - ap2 = face1->v2; - ap3 = face1->v3; - - // fill faceB - bp1 = face2->v1; - bp2 = face2->v3; - bp3 = face2->v4; - } - else { - continue; - } - } - else if ( i == 3 ) { - if ( face1->v4 && face2->v4 ) { - // fill faceA - ap1 = face1->v1; - ap2 = face1->v3; - ap3 = face1->v4; - - // fill faceB - bp1 = face2->v1; - bp2 = face2->v3; - bp3 = face2->v4; - } - else { - continue; - } - } - - copy_v3_v3(v1[0], cloth->verts[ap1].txold); - copy_v3_v3(v1[1], cloth->verts[ap1].tx); - copy_v3_v3(v2[0], cloth->verts[ap2].txold); - copy_v3_v3(v2[1], cloth->verts[ap2].tx); - copy_v3_v3(v3[0], cloth->verts[ap3].txold); - copy_v3_v3(v3[1], cloth->verts[ap3].tx); - - copy_v3_v3(v4[0], collmd->current_x[bp1].co); - copy_v3_v3(v4[1], collmd->current_xnew[bp1].co); - copy_v3_v3(v5[0], collmd->current_x[bp2].co); - copy_v3_v3(v5[1], collmd->current_xnew[bp2].co); - copy_v3_v3(v6[0], collmd->current_x[bp3].co); - copy_v3_v3(v6[1], collmd->current_xnew[bp3].co); - - normal_tri_v3(n2, v4[1], v5[1], v6[1]); - - /*offset new positions a bit, to account for margins*/ - i1 = ap1; i2 = ap2; i3 = ap3; - i4 = bp1; i5 = bp2; i6 = bp3; - - for (j=0; j<3; j++) { - int collp1, collp2, k, j2 = (j+1)%3; - - table[0] = ap1; table[1] = ap2; table[2] = ap3; - table[3] = bp1; table[4] = bp2; table[5] = bp3; - for (k=0; k<3; k++) { - float p1[3], p2[3]; - int k2 = (k+1)%3; - - get_edgepairkey(&tstkey, table[j], table[j2], table[k+3], table[k2+3]); - //if (BLI_ghash_haskey(visithash, &tstkey)) - // continue; - - key = BLI_memarena_alloc(arena, sizeof(edgepairkey)); - *key = tstkey; - BLI_ghash_insert(visithash, key, NULL); - - sub_v3_v3v3(p1, verts[j], verts[j2]); - sub_v3_v3v3(p2, verts[k+3], verts[k2+3]); - - cross_v3_v3v3(off, p1, p2); - normalize_v3(off); - - if (dot_v3v3(n2, off) < 0.0) - negate_v3(off); - - mul_v3_fl(off, epsilon1 + epsilon2 + ALMOST_ZERO); - copy_v3_v3(p1, verts[k+3]); - copy_v3_v3(p2, verts[k2+3]); - add_v3_v3(p1, off); - add_v3_v3(p2, off); - - ret = eltopo_line_line_moving_isect_v3v3_f(verts[j], table[j], verts[j2], table[j2], - p1, table[k+3], p2, table[k2+3], - no, uv, &t, &relnor); - /*cloth vert versus coll face*/ - if (ret) { - collpair->ap1 = table[j]; collpair->ap2 = table[j2]; - collpair->bp1 = table[k+3]; collpair->bp2 = table[k2+3]; - - /*I'm not sure if this is correct, but hopefully it's - better then simply ignoring back edges*/ - if (dot_v3v3(n2, no) < 0.0) { - negate_v3(no); - } - - copy_v3_v3(collpair->normal, no); - mul_v3_v3fl(collpair->vector, collpair->normal, relnor); - collpair->distance = relnor; - collpair->time = t; - - copy_v2_v2(collpair->bary, uv); - - collpair->flag = COLLISION_IS_EDGES; - collpair++; - } - } - } - } - - return collpair; -} - -static int cloth_edge_collision_response_moving ( ClothModifierData *clmd, CollisionModifierData *collmd, CollPair *collpair, CollPair *collision_end ) -{ - int result = 0; - Cloth *cloth1; - float w1, w2; - float v1[3], v2[3], relativeVelocity[3]; - float magrelVel, pimpulse[3]; - - cloth1 = clmd->clothObject; - - for ( ; collpair != collision_end; collpair++ ) { - if (!(collpair->flag & COLLISION_IS_EDGES)) - continue; - - // was: txold - w1 = collpair->bary[0]; w2 = collpair->bary[1]; - - // Calculate relative "velocity". - VECADDFAC(v1, cloth1->verts[collpair->ap1].tv, cloth1->verts[collpair->ap2].tv, w1); - VECADDFAC(v2, collmd->current_v[collpair->bp1].co, collmd->current_v[collpair->bp2].co, w2); - - sub_v3_v3v3(relativeVelocity, v2, v1); - - // Calculate the normal component of the relative velocity (actually only the magnitude - the direction is stored in 'normal'). - magrelVel = dot_v3v3 ( relativeVelocity, collpair->normal ); - - // If v_n_mag < 0 the edges are approaching each other. - if ( magrelVel > ALMOST_ZERO ) { - // Calculate Impulse magnitude to stop all motion in normal direction. - float magtangent = 0, repulse = 0, d = 0; - double impulse = 0.0; - float vrel_t_pre[3]; - float temp[3], spf; - - zero_v3(pimpulse); - - // calculate tangential velocity - copy_v3_v3 ( temp, collpair->normal ); - mul_v3_fl(temp, magrelVel); - sub_v3_v3v3(vrel_t_pre, relativeVelocity, temp); - - // Decrease in magnitude of relative tangential velocity due to coulomb friction - // in original formula "magrelVel" should be the "change of relative velocity in normal direction" - magtangent = MIN2 ( clmd->coll_parms->friction * 0.01 * magrelVel, sqrt ( dot_v3v3 ( vrel_t_pre, vrel_t_pre ) ) ); - - // Apply friction impulse. - if ( magtangent > ALMOST_ZERO ) { - normalize_v3(vrel_t_pre); - - impulse = magtangent; - VECADDMUL ( pimpulse, vrel_t_pre, impulse); - } - - // Apply velocity stopping impulse - // I_c = m * v_N / 2.0 - // no 2.0 * magrelVel normally, but looks nicer DG - impulse = magrelVel; - - mul_v3_fl(collpair->normal, 0.5); - VECADDMUL ( pimpulse, collpair->normal, impulse); - + else + { // Apply repulse impulse if distance too short // I_r = -min(dt*kd, m(0, 1d/dt - v_n)) - spf = (float)clmd->sim_parms->stepsPerFrame / clmd->sim_parms->timescale; - - d = collpair->distance; - if ( ( magrelVel < 0.1*d*spf && ( d > ALMOST_ZERO ) ) ) { - repulse = MIN2 ( d*1.0/spf, 0.1*d*spf - magrelVel ); + float spf = (float)clmd->sim_parms->stepsPerFrame / clmd->sim_parms->timescale; + float d = clmd->coll_parms->epsilon*8.0f/9.0f + epsilon2*8.0f/9.0f - collpair->distance; + if ( d > ALMOST_ZERO) { // stay on the safe side and clamp repulse - if ( impulse > ALMOST_ZERO ) - repulse = MIN2 ( repulse, 5.0*impulse ); - repulse = MAX2 ( impulse, repulse ); + float repulse = d*1.0f/spf; - impulse = repulse / ( 5.0 ); // original 2.0 / 0.25 - VECADDMUL ( pimpulse, collpair->normal, impulse); - } - - w2 = 1.0f-w1; - if (w1 < 0.5) - w1 *= 2.0; - else - w2 *= 2.0; - - VECADDFAC(cloth1->verts[collpair->ap1].impulse, cloth1->verts[collpair->ap1].impulse, pimpulse, w1*2.0); - VECADDFAC(cloth1->verts[collpair->ap2].impulse, cloth1->verts[collpair->ap2].impulse, pimpulse, w2*2.0); - - cloth1->verts[collpair->ap1].impulse_count++; - cloth1->verts[collpair->ap2].impulse_count++; - - result = 1; - } - } - - return result; -} + float impulse = repulse / ( 1.0f + w1*w1 + w2*w2 + w3*w3 ); // original 2.0 / 0.25 + VECADDMUL ( i1, collpair->normal, impulse ); + VECADDMUL ( i2, collpair->normal, impulse ); + VECADDMUL ( i3, collpair->normal, impulse ); -static int cloth_collision_response_moving ( ClothModifierData *clmd, CollisionModifierData *collmd, CollPair *collpair, CollPair *collision_end ) -{ - int result = 0; - Cloth *cloth1; - float w1, w2, w3, u1, u2, u3; - float v1[3], v2[3], relativeVelocity[3]; - float magrelVel; - float epsilon2 = BLI_bvhtree_getepsilon ( collmd->bvhtree ); - - cloth1 = clmd->clothObject; - - for ( ; collpair != collision_end; collpair++ ) { - if (collpair->flag & COLLISION_IS_EDGES) - continue; - - if ( collpair->flag & COLLISION_USE_COLLFACE ) { - // was: txold - w1 = collpair->bary[0]; w2 = collpair->bary[1]; w3 = collpair->bary[2]; - - // Calculate relative "velocity". - collision_interpolateOnTriangle ( v1, collmd->current_v[collpair->bp1].co, collmd->current_v[collpair->bp2].co, collmd->current_v[collpair->bp3].co, w1, w2, w3); - - sub_v3_v3v3(relativeVelocity, v1, cloth1->verts[collpair->collp].tv); - - // Calculate the normal component of the relative velocity (actually only the magnitude - the direction is stored in 'normal'). - magrelVel = dot_v3v3 ( relativeVelocity, collpair->normal ); - - // If v_n_mag < 0 the edges are approaching each other. - if ( magrelVel > ALMOST_ZERO ) { - // Calculate Impulse magnitude to stop all motion in normal direction. - float magtangent = 0, repulse = 0, d = 0; - double impulse = 0.0; - float vrel_t_pre[3]; - float temp[3], spf; - - // calculate tangential velocity - copy_v3_v3 ( temp, collpair->normal ); - mul_v3_fl(temp, magrelVel); - sub_v3_v3v3(vrel_t_pre, relativeVelocity, temp); - - // Decrease in magnitude of relative tangential velocity due to coulomb friction - // in original formula "magrelVel" should be the "change of relative velocity in normal direction" - magtangent = MIN2 ( clmd->coll_parms->friction * 0.01 * magrelVel, sqrt ( dot_v3v3 ( vrel_t_pre, vrel_t_pre ) ) ); - - // Apply friction impulse. - if ( magtangent > ALMOST_ZERO ) { - normalize_v3(vrel_t_pre); - - impulse = magtangent; // 2.0 * - VECADDMUL ( cloth1->verts[collpair->collp].impulse, vrel_t_pre, impulse); - } - - // Apply velocity stopping impulse - // I_c = m * v_N / 2.0 - // no 2.0 * magrelVel normally, but looks nicer DG - impulse = magrelVel/2.0; - - VECADDMUL ( cloth1->verts[collpair->collp].impulse, collpair->normal, impulse); - cloth1->verts[collpair->collp].impulse_count++; - - // Apply repulse impulse if distance too short - // I_r = -min(dt*kd, m(0, 1d/dt - v_n)) - spf = (float)clmd->sim_parms->stepsPerFrame / clmd->sim_parms->timescale; - - d = -collpair->distance; - if ( ( magrelVel < 0.1*d*spf ) && ( d > ALMOST_ZERO ) ) { - repulse = MIN2 ( d*1.0/spf, 0.1*d*spf - magrelVel ); - - // stay on the safe side and clamp repulse - if ( impulse > ALMOST_ZERO ) - repulse = MIN2 ( repulse, 5.0*impulse ); - repulse = MAX2 ( impulse, repulse ); - - impulse = repulse / ( 5.0 ); // original 2.0 / 0.25 - VECADDMUL ( cloth1->verts[collpair->collp].impulse, collpair->normal, impulse); - } - - result = 1; - } - } - else { - w1 = collpair->bary[0]; w2 = collpair->bary[1]; w3 = collpair->bary[2]; - - // Calculate relative "velocity". - collision_interpolateOnTriangle ( v1, cloth1->verts[collpair->ap1].tv, cloth1->verts[collpair->ap2].tv, cloth1->verts[collpair->ap3].tv, w1, w2, w3 ); - - sub_v3_v3v3(relativeVelocity, collmd->current_v[collpair->collp].co, v1); - - // Calculate the normal component of the relative velocity (actually only the magnitude - the direction is stored in 'normal'). - magrelVel = dot_v3v3 ( relativeVelocity, collpair->normal ); - - // If v_n_mag < 0 the edges are approaching each other. - if ( magrelVel > ALMOST_ZERO ) { - // Calculate Impulse magnitude to stop all motion in normal direction. - float magtangent = 0, repulse = 0, d = 0; - double impulse = 0.0; - float vrel_t_pre[3], pimpulse[3] = {0.0f, 0.0f, 0.0f}; - float temp[3], spf; - - // calculate tangential velocity - copy_v3_v3 ( temp, collpair->normal ); - mul_v3_fl(temp, magrelVel); - sub_v3_v3v3(vrel_t_pre, relativeVelocity, temp); - - // Decrease in magnitude of relative tangential velocity due to coulomb friction - // in original formula "magrelVel" should be the "change of relative velocity in normal direction" - magtangent = MIN2 ( clmd->coll_parms->friction * 0.01 * magrelVel, sqrt ( dot_v3v3 ( vrel_t_pre, vrel_t_pre ) ) ); - - // Apply friction impulse. - if ( magtangent > ALMOST_ZERO ) { - normalize_v3(vrel_t_pre); - - impulse = magtangent; // 2.0 * - VECADDMUL ( pimpulse, vrel_t_pre, impulse); - } - - // Apply velocity stopping impulse - // I_c = m * v_N / 2.0 - // no 2.0 * magrelVel normally, but looks nicer DG - impulse = magrelVel/2.0; - - VECADDMUL ( pimpulse, collpair->normal, impulse); - - // Apply repulse impulse if distance too short - // I_r = -min(dt*kd, m(0, 1d/dt - v_n)) - spf = (float)clmd->sim_parms->stepsPerFrame / clmd->sim_parms->timescale; - - d = -collpair->distance; - if ( ( magrelVel < 0.1*d*spf ) && ( d > ALMOST_ZERO ) ) { - repulse = MIN2 ( d*1.0/spf, 0.1*d*spf - magrelVel ); - - // stay on the safe side and clamp repulse - if ( impulse > ALMOST_ZERO ) - repulse = MIN2 ( repulse, 5.0*impulse ); - repulse = MAX2 ( impulse, repulse ); - - impulse = repulse / ( 2.0 ); // original 2.0 / 0.25 - VECADDMUL ( pimpulse, collpair->normal, impulse); - } - - if (w1 < 0.5) w1 *= 2.0; - if (w2 < 0.5) w2 *= 2.0; - if (w3 < 0.5) w3 *= 2.0; - - VECADDMUL(cloth1->verts[collpair->ap1].impulse, pimpulse, w1*2.0); - VECADDMUL(cloth1->verts[collpair->ap2].impulse, pimpulse, w2*2.0); - VECADDMUL(cloth1->verts[collpair->ap3].impulse, pimpulse, w3*2.0); cloth1->verts[collpair->ap1].impulse_count++; cloth1->verts[collpair->ap2].impulse_count++; cloth1->verts[collpair->ap3].impulse_count++; - + result = 1; } } - } - + + if(result) + { + int i = 0; + + for(i = 0; i < 3; i++) + { + if(cloth1->verts[collpair->ap1].impulse_count > 0 && ABS(cloth1->verts[collpair->ap1].impulse[i]) < ABS(i1[i])) + cloth1->verts[collpair->ap1].impulse[i] = i1[i]; + + if(cloth1->verts[collpair->ap2].impulse_count > 0 && ABS(cloth1->verts[collpair->ap2].impulse[i]) < ABS(i2[i])) + cloth1->verts[collpair->ap2].impulse[i] = i2[i]; + + if(cloth1->verts[collpair->ap3].impulse_count > 0 && ABS(cloth1->verts[collpair->ap3].impulse[i]) < ABS(i3[i])) + cloth1->verts[collpair->ap3].impulse[i] = i3[i]; + } + } + } return result; } - -typedef struct tripairkey { - int p, a1, a2, a3; -} tripairkey; - -unsigned int tripair_hash(void *vkey) -{ - tripairkey *key = vkey; - int keys[4] = {key->p, key->a1, key->a2, key->a3}; - int i, j; - - for (i=0; i<4; i++) { - for (j=0; j<3; j++) { - if (keys[j] >= keys[j+1]) { - SWAP(int, keys[j], keys[j+1]); - } - } - } - - return keys[0]*101 + keys[1]*72 + keys[2]*53 + keys[3]*34; -} - -int tripair_cmp(const void *va, const void *vb) -{ - tripairkey *a = va, *b = vb; - int keysa[4] = {a->p, a->a1, a->a2, a->a3}; - int keysb[4] = {b->p, b->a1, b->a2, b->a3}; - int i; - - for (i=0; i<4; i++) { - int j, ok=0; - for (j=0; j<4; j++) { - if (keysa[i] == keysa[j]) { - ok = 1; - break; - } - } - if (!ok) - return -1; - } - - return 0; -} - -static void get_tripairkey(tripairkey *key, int p, int a1, int a2, int a3) -{ - key->a1 = a1; - key->a2 = a2; - key->a3 = a3; - key->p = p; -} - -static int checkvisit(MemArena *arena, GHash *gh, int p, int a1, int a2, int a3) -{ - tripairkey key, *key2; - - get_tripairkey(&key, p, a1, a2, a3); - if (BLI_ghash_haskey(gh, &key)) - return 1; - - key2 = BLI_memarena_alloc(arena, sizeof(*key2)); - *key2 = key; - BLI_ghash_insert(gh, key2, NULL); - - return 0; -} - -int cloth_point_tri_moving_v3v3_f(float v1[2][3], int i1, float v2[2][3], int i2, - float v3[2][3], int i3, float v4[2][3], int i4, - float normal[3], float bary[3], float *t, - float *relnor, GHash *gh, MemArena *arena) -{ - if (checkvisit(arena, gh, i1, i2, i3, i4)) - return 0; - - return eltopo_point_tri_moving_v3v3_f(v1, i1, v2, i2, v3, i3, v4, i4, normal, bary, t, relnor); -} - -static CollPair* cloth_collision ( ModifierData *md1, ModifierData *md2, BVHTreeOverlap *overlap, - CollPair *collpair, double dt, GHash *gh, MemArena *arena) -{ - ClothModifierData *clmd = (ClothModifierData *)md1; - CollisionModifierData *collmd = (CollisionModifierData *) md2; - MFace *face1=NULL, *face2 = NULL; - ClothVertex *verts1 = clmd->clothObject->verts; - double distance = 0; - float epsilon1 = clmd->coll_parms->epsilon; - float epsilon2 = BLI_bvhtree_getepsilon ( collmd->bvhtree ); - float no[3], uv[3], t, relnor; - int i, i1, i2, i3, i4, i5, i6; - Cloth *cloth = clmd->clothObject; - float n1[3], sdis, p[3], l, n2[3], off[3], v1[2][3], v2[2][3], v3[2][3], v4[2][3], v5[2][3], v6[2][3]; - int j, ret, bp1, bp2, bp3, ap1, ap2, ap3; - - face1 = & ( clmd->clothObject->mfaces[overlap->indexA] ); - face2 = & ( collmd->mfaces[overlap->indexB] ); - - // check all 4 possible collisions - for ( i = 0; i < 4; i++ ) { - if ( i == 0 ) { - // fill faceA - ap1 = face1->v1; - ap2 = face1->v2; - ap3 = face1->v3; - - // fill faceB - bp1 = face2->v1; - bp2 = face2->v2; - bp3 = face2->v3; - } - else if ( i == 1 ) { - if ( face1->v4 ) { - // fill faceA - ap1 = face1->v1; - ap2 = face1->v3; - ap3 = face1->v4; - - // fill faceB - bp1 = face2->v1; - bp2 = face2->v2; - bp3 = face2->v3; - } - else { - continue; - } - } - if ( i == 2 ) { - if ( face2->v4 ) { - // fill faceA - ap1 = face1->v1; - ap2 = face1->v2; - ap3 = face1->v3; - - // fill faceB - bp1 = face2->v1; - bp2 = face2->v3; - bp3 = face2->v4; - } - else { - continue; - } - } - else if ( i == 3 ) { - if ( face1->v4 && face2->v4 ) { - // fill faceA - ap1 = face1->v1; - ap2 = face1->v3; - ap3 = face1->v4; - - // fill faceB - bp1 = face2->v1; - bp2 = face2->v3; - bp3 = face2->v4; - } - else { - continue; - } - } - - copy_v3_v3(v1[0], cloth->verts[ap1].txold); - copy_v3_v3(v1[1], cloth->verts[ap1].tx); - copy_v3_v3(v2[0], cloth->verts[ap2].txold); - copy_v3_v3(v2[1], cloth->verts[ap2].tx); - copy_v3_v3(v3[0], cloth->verts[ap3].txold); - copy_v3_v3(v3[1], cloth->verts[ap3].tx); - - copy_v3_v3(v4[0], collmd->current_x[bp1].co); - copy_v3_v3(v4[1], collmd->current_xnew[bp1].co); - copy_v3_v3(v5[0], collmd->current_x[bp2].co); - copy_v3_v3(v5[1], collmd->current_xnew[bp2].co); - copy_v3_v3(v6[0], collmd->current_x[bp3].co); - copy_v3_v3(v6[1], collmd->current_xnew[bp3].co); - - normal_tri_v3(n2, v4[1], v5[1], v6[1]); - - sdis = clmd->coll_parms->distance_repel + epsilon2 + FLT_EPSILON; - - /*apply a repulsion force, to help the solver along*/ - copy_v3_v3(off, n2); - negate_v3(off); - if (isect_ray_plane_v3(v1[1], off, v4[1], v5[1], v6[1], &l, 0)) { - if (l >= 0.0 && l < sdis) { - mul_v3_fl(off, (l-sdis)*cloth->verts[ap1].mass*dt*clmd->coll_parms->repel_force*0.1); - - add_v3_v3(cloth->verts[ap1].tv, off); - add_v3_v3(cloth->verts[ap2].tv, off); - add_v3_v3(cloth->verts[ap3].tv, off); - } - } - - /*offset new positions a bit, to account for margins*/ - copy_v3_v3(off, n2); - mul_v3_fl(off, epsilon1 + epsilon2 + ALMOST_ZERO); - add_v3_v3(v4[1], off); add_v3_v3(v5[1], off); add_v3_v3(v6[1], off); - - i1 = ap1; i2 = ap2; i3 = ap3; - i4 = bp1+cloth->numverts; i5 = bp2+cloth->numverts; i6 = bp3+cloth->numverts; - - for (j=0; j<6; j++) { - int collp; - - switch (j) { - case 0: - ret = cloth_point_tri_moving_v3v3_f(v1, i1, v4, i4, v5, i5, v6, i6, no, uv, &t, &relnor, gh, arena); - collp = ap1; - break; - case 1: - collp = ap2; - ret = cloth_point_tri_moving_v3v3_f(v2, i2, v4, i4, v5, i5, v6, i6, no, uv, &t, &relnor, gh, arena); - break; - case 2: - collp = ap3; - ret = cloth_point_tri_moving_v3v3_f(v3, i3, v4, i4, v5, i5, v6, i6, no, uv, &t, &relnor, gh, arena); - break; - case 3: - collp = bp1; - ret = cloth_point_tri_moving_v3v3_f(v4, i4, v1, i1, v2, i2, v3, i3, no, uv, &t, &relnor, gh, arena); - break; - case 4: - collp = bp2; - ret = cloth_point_tri_moving_v3v3_f(v5, i5, v1, i1, v2, i2, v3, i3, no, uv, &t, &relnor, gh, arena); - break; - case 5: - collp = bp3; - ret = cloth_point_tri_moving_v3v3_f(v6, i6, v1, i1, v2, i2, v3, i3, no, uv, &t, &relnor, gh, arena); - break; - } - - /*cloth vert versus coll face*/ - if (ret && j < 3) { - collpair->bp1 = bp1; collpair->bp2 = bp2; collpair->bp3 = bp3; - collpair->collp = collp; - - copy_v3_v3(collpair->normal, no); - mul_v3_v3fl(collpair->vector, collpair->normal, relnor); - collpair->distance = relnor; - collpair->time = t; - - copy_v3_v3(collpair->bary, uv); - - collpair->flag = COLLISION_USE_COLLFACE; - collpair++; - } - else if (ret && j >= 3) { /*coll vert versus cloth face*/ - collpair->ap1 = ap1; collpair->ap2 = ap2; collpair->ap3 = ap3; - collpair->collp = collp; - - copy_v3_v3(collpair->normal, no); - mul_v3_v3fl(collpair->vector, collpair->normal, relnor); - collpair->distance = relnor; - collpair->time = t; - - copy_v3_v3(collpair->bary, uv); - - collpair->flag = 0; - collpair++; - } - } - } - - return collpair; -} - -static void machine_epsilon_offset(Cloth *cloth) -{ - ClothVertex *cv; - int i, j; - - cv = cloth->verts; - for (i=0; inumverts; i++, cv++) { - /*aggrevatingly enough, it's necessary to offset the coordinates - by a multiple of the 32-bit floating point epsilon when switching - into doubles*/ - #define RNDSIGN (float)(-1*(BLI_rand()%2==0)|1) - for (j=0; j<3; j++) { - cv->tx[j] += FLT_EPSILON*30.0f*RNDSIGN; - cv->txold[j] += FLT_EPSILON*30.0f*RNDSIGN; - cv->tv[j] += FLT_EPSILON*30.0f*RNDSIGN; - } - } -} - -#else /* !WITH_ELTOPO */ - //Determines collisions on overlap, collisions are written to collpair[i] and collision+number_collision_found is returned -static CollPair* cloth_collision ( ModifierData *md1, ModifierData *md2, - BVHTreeOverlap *overlap, CollPair *collpair, float dt ) +static CollPair* cloth_collision(ModifierData *md1, ModifierData *md2, + BVHTreeOverlap *overlap, CollPair *collpair, float UNUSED(dt)) { ClothModifierData *clmd = (ClothModifierData *)md1; CollisionModifierData *collmd = (CollisionModifierData *) md2; - Cloth *cloth = clmd->clothObject; + /* Cloth *cloth = clmd->clothObject; */ /* UNUSED */ MFace *face1=NULL, *face2 = NULL; #ifdef USE_BULLET ClothVertex *verts1 = clmd->clothObject->verts; @@ -1372,7 +379,6 @@ static CollPair* cloth_collision ( ModifierData *md1, ModifierData *md2, double distance = 0; float epsilon1 = clmd->coll_parms->epsilon; float epsilon2 = BLI_bvhtree_getepsilon ( collmd->bvhtree ); - float n2[3], sdis, l; int i; face1 = & ( clmd->clothObject->mfaces[overlap->indexA] ); @@ -1395,8 +401,8 @@ static CollPair* cloth_collision ( ModifierData *md1, ModifierData *md2, if ( face1->v4 ) { // fill faceA collpair->ap1 = face1->v1; - collpair->ap2 = face1->v4; - collpair->ap3 = face1->v3; + collpair->ap2 = face1->v3; + collpair->ap3 = face1->v4; // fill faceB collpair->bp1 = face2->v1; @@ -1425,39 +431,18 @@ static CollPair* cloth_collision ( ModifierData *md1, ModifierData *md2, if ( face1->v4 && face2->v4 ) { // fill faceA collpair->ap1 = face1->v1; - collpair->ap2 = face1->v4; - collpair->ap3 = face1->v3; + collpair->ap2 = face1->v3; + collpair->ap3 = face1->v4; // fill faceB collpair->bp1 = face2->v1; - collpair->bp2 = face2->v4; - collpair->bp3 = face2->v3; + collpair->bp2 = face2->v3; + collpair->bp3 = face2->v4; } else break; } - normal_tri_v3(n2, collmd->current_xnew[collpair->bp1].co, - collmd->current_xnew[collpair->bp2].co, - collmd->current_xnew[collpair->bp3].co); - - sdis = clmd->coll_parms->distance_repel + epsilon2 + FLT_EPSILON; - - /* apply a repulsion force, to help the solver along. - * this is kindof crude, it only tests one vert of the triangle */ - if (isect_ray_plane_v3(cloth->verts[collpair->ap1].tx, n2, collmd->current_xnew[collpair->bp1].co, - collmd->current_xnew[collpair->bp2].co, - collmd->current_xnew[collpair->bp3].co, &l, 0)) - { - if (l >= 0.0f && l < sdis) { - mul_v3_fl(n2, (l-sdis)*cloth->verts[collpair->ap1].mass*dt*clmd->coll_parms->repel_force*0.1f); - - add_v3_v3(cloth->verts[collpair->ap1].tv, n2); - add_v3_v3(cloth->verts[collpair->ap2].tv, n2); - add_v3_v3(cloth->verts[collpair->ap3].tv, n2); - } - } - #ifdef USE_BULLET // calc distance + normal distance = plNearestPoints ( @@ -1512,579 +497,6 @@ static CollPair* cloth_collision ( ModifierData *md1, ModifierData *md2, } return collpair; } -#endif /* WITH_ELTOPO */ - - -#if 0 -static int cloth_collision_response_moving( ClothModifierData *clmd, CollisionModifierData *collmd, CollPair *collpair, CollPair *collision_end ) -{ - int result = 0; - Cloth *cloth1; - float w1, w2, w3, u1, u2, u3; - float v1[3], v2[3], relativeVelocity[3]; - float magrelVel; - - cloth1 = clmd->clothObject; - - for ( ; collpair != collision_end; collpair++ ) - { - // compute barycentric coordinates for both collision points - collision_compute_barycentric ( collpair->pa, - cloth1->verts[collpair->ap1].txold, - cloth1->verts[collpair->ap2].txold, - cloth1->verts[collpair->ap3].txold, - &w1, &w2, &w3 ); - - // was: txold - collision_compute_barycentric ( collpair->pb, - collmd->current_x[collpair->bp1].co, - collmd->current_x[collpair->bp2].co, - collmd->current_x[collpair->bp3].co, - &u1, &u2, &u3 ); - - // Calculate relative "velocity". - collision_interpolateOnTriangle ( v1, cloth1->verts[collpair->ap1].tv, cloth1->verts[collpair->ap2].tv, cloth1->verts[collpair->ap3].tv, w1, w2, w3 ); - - collision_interpolateOnTriangle ( v2, collmd->current_v[collpair->bp1].co, collmd->current_v[collpair->bp2].co, collmd->current_v[collpair->bp3].co, u1, u2, u3 ); - - sub_v3_v3v3(relativeVelocity, v2, v1); - - // Calculate the normal component of the relative velocity (actually only the magnitude - the direction is stored in 'normal'). - magrelVel = dot_v3v3 ( relativeVelocity, collpair->normal ); - - // printf("magrelVel: %f\n", magrelVel); - - // Calculate masses of points. - // TODO - - // If v_n_mag < 0 the edges are approaching each other. - if ( magrelVel > ALMOST_ZERO ) - { - // Calculate Impulse magnitude to stop all motion in normal direction. - float magtangent = 0; - double impulse = 0.0; - float vrel_t_pre[3]; - float temp[3]; - - // calculate tangential velocity - copy_v3_v3 ( temp, collpair->normal ); - mul_v3_fl(temp, magrelVel); - sub_v3_v3v3(vrel_t_pre, relativeVelocity, temp); - - // Decrease in magnitude of relative tangential velocity due to coulomb friction - // in original formula "magrelVel" should be the "change of relative velocity in normal direction" - magtangent = MIN2 ( clmd->coll_parms->friction * 0.01 * magrelVel, sqrt ( dot_v3v3 ( vrel_t_pre, vrel_t_pre ) ) ); - - // Apply friction impulse. - if ( magtangent > ALMOST_ZERO ) - { - normalize_v3(vrel_t_pre); - - impulse = 2.0 * magtangent / ( 1.0 + w1*w1 + w2*w2 + w3*w3 ); - VECADDMUL ( cloth1->verts[collpair->ap1].impulse, vrel_t_pre, w1 * impulse ); - VECADDMUL ( cloth1->verts[collpair->ap2].impulse, vrel_t_pre, w2 * impulse ); - VECADDMUL ( cloth1->verts[collpair->ap3].impulse, vrel_t_pre, w3 * impulse ); - } - - // Apply velocity stopping impulse - // I_c = m * v_N / 2.0 - // no 2.0 * magrelVel normally, but looks nicer DG - impulse = magrelVel / ( 1.0 + w1*w1 + w2*w2 + w3*w3 ); - - VECADDMUL ( cloth1->verts[collpair->ap1].impulse, collpair->normal, w1 * impulse ); - cloth1->verts[collpair->ap1].impulse_count++; - - VECADDMUL ( cloth1->verts[collpair->ap2].impulse, collpair->normal, w2 * impulse ); - cloth1->verts[collpair->ap2].impulse_count++; - - VECADDMUL ( cloth1->verts[collpair->ap3].impulse, collpair->normal, w3 * impulse ); - cloth1->verts[collpair->ap3].impulse_count++; - - // Apply repulse impulse if distance too short - // I_r = -min(dt*kd, m(0, 1d/dt - v_n)) - /* - d = clmd->coll_parms->epsilon*8.0/9.0 + epsilon2*8.0/9.0 - collpair->distance; - if ( ( magrelVel < 0.1*d*clmd->sim_parms->stepsPerFrame ) && ( d > ALMOST_ZERO ) ) - { - repulse = MIN2 ( d*1.0/clmd->sim_parms->stepsPerFrame, 0.1*d*clmd->sim_parms->stepsPerFrame - magrelVel ); - - // stay on the safe side and clamp repulse - if ( impulse > ALMOST_ZERO ) - repulse = MIN2 ( repulse, 5.0*impulse ); - repulse = MAX2 ( impulse, repulse ); - - impulse = repulse / ( 1.0 + w1*w1 + w2*w2 + w3*w3 ); // original 2.0 / 0.25 - VECADDMUL ( cloth1->verts[collpair->ap1].impulse, collpair->normal, impulse ); - VECADDMUL ( cloth1->verts[collpair->ap2].impulse, collpair->normal, impulse ); - VECADDMUL ( cloth1->verts[collpair->ap3].impulse, collpair->normal, impulse ); - } - */ - result = 1; - } - } - return result; -} -#endif - -#if 0 -static float projectPointOntoLine(float *p, float *a, float *b) -{ - float ba[3], pa[3]; - sub_v3_v3v3(ba, b, a); - sub_v3_v3v3(pa, p, a); - return dot_v3v3(pa, ba) / dot_v3v3(ba, ba); -} - -static void calculateEENormal(float *np1, float *np2, float *np3, float *np4, float *out_normal) -{ - float line1[3], line2[3]; - float length; - - sub_v3_v3v3(line1, np2, np1); - sub_v3_v3v3(line2, np3, np1); - - // printf("l1: %f, l1: %f, l2: %f, l2: %f\n", line1[0], line1[1], line2[0], line2[1]); - - cross_v3_v3v3(out_normal, line1, line2); - - - - length = normalize_v3(out_normal); - if (length <= FLT_EPSILON) - { // lines are collinear - sub_v3_v3v3(out_normal, np2, np1); - normalize_v3(out_normal); - } -} - -static void findClosestPointsEE(float *x1, float *x2, float *x3, float *x4, float *w1, float *w2) -{ - float temp[3], temp2[3]; - - double a, b, c, e, f; - - sub_v3_v3v3(temp, x2, x1); - a = dot_v3v3(temp, temp); - - sub_v3_v3v3(temp2, x4, x3); - b = -dot_v3v3(temp, temp2); - - c = dot_v3v3(temp2, temp2); - - sub_v3_v3v3(temp2, x3, x1); - e = dot_v3v3(temp, temp2); - - sub_v3_v3v3(temp, x4, x3); - f = -dot_v3v3(temp, temp2); - - *w1 = (e * c - b * f) / (a * c - b * b); - *w2 = (f - b * *w1) / c; - -} - -// calculates the distance of 2 edges -static float edgedge_distance(float np11[3], float np12[3], float np21[3], float np22[3], float *out_a1, float *out_a2, float *out_normal) -{ - float line1[3], line2[3], cross[3]; - float length; - float temp[3], temp2[3]; - float dist_a1, dist_a2; - - sub_v3_v3v3(line1, np12, np11); - sub_v3_v3v3(line2, np22, np21); - - cross_v3_v3v3(cross, line1, line2); - length = dot_v3v3(cross, cross); - - if (length < FLT_EPSILON) - { - *out_a2 = projectPointOntoLine(np11, np21, np22); - if ((*out_a2 >= -FLT_EPSILON) && (*out_a2 <= 1.0 + FLT_EPSILON)) - { - *out_a1 = 0; - calculateEENormal(np11, np12, np21, np22, out_normal); - sub_v3_v3v3(temp, np22, np21); - mul_v3_fl(temp, *out_a2); - VECADD(temp2, temp, np21); - VECADD(temp2, temp2, np11); - return dot_v3v3(temp2, temp2); - } - - CLAMP(*out_a2, 0.0, 1.0); - if (*out_a2 > .5) - { // == 1.0 - *out_a1 = projectPointOntoLine(np22, np11, np12); - if ((*out_a1 >= -FLT_EPSILON) && (*out_a1 <= 1.0 + FLT_EPSILON)) - { - calculateEENormal(np11, np12, np21, np22, out_normal); - - // return (np22 - (np11 + (np12 - np11) * out_a1)).lengthSquared(); - sub_v3_v3v3(temp, np12, np11); - mul_v3_fl(temp, *out_a1); - VECADD(temp2, temp, np11); - sub_v3_v3v3(temp2, np22, temp2); - return dot_v3v3(temp2, temp2); - } - } - else - { // == 0.0 - *out_a1 = projectPointOntoLine(np21, np11, np12); - if ((*out_a1 >= -FLT_EPSILON) && (*out_a1 <= 1.0 + FLT_EPSILON)) - { - calculateEENormal(np11, np11, np21, np22, out_normal); - - // return (np21 - (np11 + (np12 - np11) * out_a1)).lengthSquared(); - sub_v3_v3v3(temp, np12, np11); - mul_v3_fl(temp, *out_a1); - VECADD(temp2, temp, np11); - sub_v3_v3v3(temp2, np21, temp2); - return dot_v3v3(temp2, temp2); - } - } - - CLAMP(*out_a1, 0.0, 1.0); - calculateEENormal(np11, np12, np21, np22, out_normal); - if (*out_a1 > .5) - { - if (*out_a2 > .5) - { - sub_v3_v3v3(temp, np12, np22); - } - else - { - sub_v3_v3v3(temp, np12, np21); - } - } - else - { - if (*out_a2 > .5) - { - sub_v3_v3v3(temp, np11, np22); - } - else - { - sub_v3_v3v3(temp, np11, np21); - } - } - - return dot_v3v3(temp, temp); - } - else - { - - // If the lines aren't parallel (but coplanar) they have to intersect - - findClosestPointsEE(np11, np12, np21, np22, out_a1, out_a2); - - // If both points are on the finite edges, we're done. - if (*out_a1 >= 0.0 && *out_a1 <= 1.0 && *out_a2 >= 0.0 && *out_a2 <= 1.0) - { - float p1[3], p2[3]; - - // p1= np11 + (np12 - np11) * out_a1; - sub_v3_v3v3(temp, np12, np11); - mul_v3_fl(temp, *out_a1); - VECADD(p1, np11, temp); - - // p2 = np21 + (np22 - np21) * out_a2; - sub_v3_v3v3(temp, np22, np21); - mul_v3_fl(temp, *out_a2); - VECADD(p2, np21, temp); - - calculateEENormal(np11, np12, np21, np22, out_normal); - sub_v3_v3v3(temp, p1, p2); - return dot_v3v3(temp, temp); - } - - - /* - * Clamp both points to the finite edges. - * The one that moves most during clamping is one part of the solution. - */ - dist_a1 = *out_a1; - CLAMP(dist_a1, 0.0, 1.0); - dist_a2 = *out_a2; - CLAMP(dist_a2, 0.0, 1.0); - - // Now project the "most clamped" point on the other line. - if (dist_a1 > dist_a2) - { - /* keep out_a1 */ - float p1[3]; - - // p1 = np11 + (np12 - np11) * out_a1; - sub_v3_v3v3(temp, np12, np11); - mul_v3_fl(temp, *out_a1); - VECADD(p1, np11, temp); - - *out_a2 = projectPointOntoLine(p1, np21, np22); - CLAMP(*out_a2, 0.0, 1.0); - - calculateEENormal(np11, np12, np21, np22, out_normal); - - // return (p1 - (np21 + (np22 - np21) * out_a2)).lengthSquared(); - sub_v3_v3v3(temp, np22, np21); - mul_v3_fl(temp, *out_a2); - VECADD(temp, temp, np21); - sub_v3_v3v3(temp, p1, temp); - return dot_v3v3(temp, temp); - } - else - { - /* keep out_a2 */ - float p2[3]; - - // p2 = np21 + (np22 - np21) * out_a2; - sub_v3_v3v3(temp, np22, np21); - mul_v3_fl(temp, *out_a2); - VECADD(p2, np21, temp); - - *out_a1 = projectPointOntoLine(p2, np11, np12); - CLAMP(*out_a1, 0.0, 1.0); - - calculateEENormal(np11, np12, np21, np22, out_normal); - - // return ((np11 + (np12 - np11) * out_a1) - p2).lengthSquared(); - sub_v3_v3v3(temp, np12, np11); - mul_v3_fl(temp, *out_a1); - VECADD(temp, temp, np11); - sub_v3_v3v3(temp, temp, p2); - return dot_v3v3(temp, temp); - } - } - - printf("Error in edgedge_distance: end of function\n"); - return 0; -} - -static int cloth_collision_moving_edges ( ClothModifierData *clmd, CollisionModifierData *collmd, CollPair *collpair ) -{ - EdgeCollPair edgecollpair; - Cloth *cloth1=NULL; - ClothVertex *verts1=NULL; - unsigned int i = 0, k = 0; - int numsolutions = 0; - double x1[3], v1[3], x2[3], v2[3], x3[3], v3[3]; - double solution[3], solution2[3]; - MVert *verts2 = collmd->current_x; // old x - MVert *velocity2 = collmd->current_v; // velocity - float distance = 0; - float triA[3][3], triB[3][3]; - int result = 0; - - cloth1 = clmd->clothObject; - verts1 = cloth1->verts; - - for (i = 0; i < 9; i++) - { - // 9 edge - edge possibilities - - if (i == 0) // cloth edge: 1-2; coll edge: 1-2 - { - edgecollpair.p11 = collpair->ap1; - edgecollpair.p12 = collpair->ap2; - - edgecollpair.p21 = collpair->bp1; - edgecollpair.p22 = collpair->bp2; - } - else if (i == 1) // cloth edge: 1-2; coll edge: 2-3 - { - edgecollpair.p11 = collpair->ap1; - edgecollpair.p12 = collpair->ap2; - - edgecollpair.p21 = collpair->bp2; - edgecollpair.p22 = collpair->bp3; - } - else if (i == 2) // cloth edge: 1-2; coll edge: 1-3 - { - edgecollpair.p11 = collpair->ap1; - edgecollpair.p12 = collpair->ap2; - - edgecollpair.p21 = collpair->bp1; - edgecollpair.p22 = collpair->bp3; - } - else if (i == 3) // cloth edge: 2-3; coll edge: 1-2 - { - edgecollpair.p11 = collpair->ap2; - edgecollpair.p12 = collpair->ap3; - - edgecollpair.p21 = collpair->bp1; - edgecollpair.p22 = collpair->bp2; - } - else if (i == 4) // cloth edge: 2-3; coll edge: 2-3 - { - edgecollpair.p11 = collpair->ap2; - edgecollpair.p12 = collpair->ap3; - - edgecollpair.p21 = collpair->bp2; - edgecollpair.p22 = collpair->bp3; - } - else if (i == 5) // cloth edge: 2-3; coll edge: 1-3 - { - edgecollpair.p11 = collpair->ap2; - edgecollpair.p12 = collpair->ap3; - - edgecollpair.p21 = collpair->bp1; - edgecollpair.p22 = collpair->bp3; - } - else if (i ==6) // cloth edge: 1-3; coll edge: 1-2 - { - edgecollpair.p11 = collpair->ap1; - edgecollpair.p12 = collpair->ap3; - - edgecollpair.p21 = collpair->bp1; - edgecollpair.p22 = collpair->bp2; - } - else if (i ==7) // cloth edge: 1-3; coll edge: 2-3 - { - edgecollpair.p11 = collpair->ap1; - edgecollpair.p12 = collpair->ap3; - - edgecollpair.p21 = collpair->bp2; - edgecollpair.p22 = collpair->bp3; - } - else if (i == 8) // cloth edge: 1-3; coll edge: 1-3 - { - edgecollpair.p11 = collpair->ap1; - edgecollpair.p12 = collpair->ap3; - - edgecollpair.p21 = collpair->bp1; - edgecollpair.p22 = collpair->bp3; - } - /* - if ((edgecollpair.p11 == 3) && (edgecollpair.p12 == 16)) - printf("Ahier!\n"); - if ((edgecollpair.p11 == 16) && (edgecollpair.p12 == 3)) - printf("Ahier!\n"); - */ - - // if ( !cloth_are_edges_adjacent ( clmd, collmd, &edgecollpair ) ) - { - // always put coll points in p21/p22 - sub_v3_v3v3(x1, verts1[edgecollpair.p12].txold, verts1[edgecollpair.p11].txold); - sub_v3_v3v3(v1, verts1[edgecollpair.p12].tv, verts1[edgecollpair.p11].tv); - - sub_v3_v3v3(x2, verts2[edgecollpair.p21].co, verts1[edgecollpair.p11].txold); - sub_v3_v3v3(v2, velocity2[edgecollpair.p21].co, verts1[edgecollpair.p11].tv); - - sub_v3_v3v3(x3, verts2[edgecollpair.p22].co, verts1[edgecollpair.p11].txold); - sub_v3_v3v3(v3, velocity2[edgecollpair.p22].co, verts1[edgecollpair.p11].tv); - - numsolutions = cloth_get_collision_time ( x1, v1, x2, v2, x3, v3, solution ); - - if ((edgecollpair.p11 == 3 && edgecollpair.p12==16)|| (edgecollpair.p11==16 && edgecollpair.p12==3)) - { - if (edgecollpair.p21==6 || edgecollpair.p22 == 6) - { - printf("dist: %f, sol[k]: %f, sol2[k]: %f\n", distance, solution[k], solution2[k]); - printf("a1: %f, a2: %f, b1: %f, b2: %f\n", x1[0], x2[0], x3[0], v1[0]); - printf("b21: %d, b22: %d\n", edgecollpair.p21, edgecollpair.p22); - } - } - - for ( k = 0; k < numsolutions; k++ ) - { - // printf("sol %d: %lf\n", k, solution[k]); - if ( ( solution[k] >= ALMOST_ZERO ) && ( solution[k] <= 1.0 ) && ( solution[k] > ALMOST_ZERO)) - { - float a, b; - float out_normal[3]; - float distance; - float impulse = 0; - float I_mag; - - // move verts - VECADDS(triA[0], verts1[edgecollpair.p11].txold, verts1[edgecollpair.p11].tv, solution[k]); - VECADDS(triA[1], verts1[edgecollpair.p12].txold, verts1[edgecollpair.p12].tv, solution[k]); - - VECADDS(triB[0], collmd->current_x[edgecollpair.p21].co, collmd->current_v[edgecollpair.p21].co, solution[k]); - VECADDS(triB[1], collmd->current_x[edgecollpair.p22].co, collmd->current_v[edgecollpair.p22].co, solution[k]); - - // TODO: check for collisions - distance = edgedge_distance(triA[0], triA[1], triB[0], triB[1], &a, &b, out_normal); - - if ((distance <= clmd->coll_parms->epsilon + BLI_bvhtree_getepsilon ( collmd->bvhtree ) + ALMOST_ZERO) && (dot_v3v3(out_normal, out_normal) > 0)) - { - float vrel_1_to_2[3], temp[3], temp2[3], out_normalVelocity; - float desiredVn; - - copy_v3_v3(vrel_1_to_2, verts1[edgecollpair.p11].tv); - mul_v3_fl(vrel_1_to_2, 1.0 - a); - copy_v3_v3(temp, verts1[edgecollpair.p12].tv); - mul_v3_fl(temp, a); - - VECADD(vrel_1_to_2, vrel_1_to_2, temp); - - copy_v3_v3(temp, verts1[edgecollpair.p21].tv); - mul_v3_fl(temp, 1.0 - b); - copy_v3_v3(temp2, verts1[edgecollpair.p22].tv); - mul_v3_fl(temp2, b); - VECADD(temp, temp, temp2); - - sub_v3_v3v3(vrel_1_to_2, vrel_1_to_2, temp); - - out_normalVelocity = dot_v3v3(vrel_1_to_2, out_normal); -/* - // this correction results in wrong normals sometimes? - if (out_normalVelocity < 0.0) - { - out_normalVelocity*= -1.0; - negate_v3(out_normal); - } -*/ - /* Inelastic repulsion impulse. */ - - // Calculate which normal velocity we need. - desiredVn = (out_normalVelocity * (float)solution[k] - (.1 * (clmd->coll_parms->epsilon + BLI_bvhtree_getepsilon ( collmd->bvhtree )) - sqrt(distance)) - ALMOST_ZERO); - - // Now calculate what impulse we need to reach that velocity. - I_mag = (out_normalVelocity - desiredVn) / 2.0; // / (1/m1 + 1/m2); - - // Finally apply that impulse. - impulse = (2.0 * -I_mag) / (a*a + (1.0-a)*(1.0-a) + b*b + (1.0-b)*(1.0-b)); - - VECADDMUL ( verts1[edgecollpair.p11].impulse, out_normal, (1.0-a) * impulse ); - verts1[edgecollpair.p11].impulse_count++; - - VECADDMUL ( verts1[edgecollpair.p12].impulse, out_normal, a * impulse ); - verts1[edgecollpair.p12].impulse_count++; - - // return true; - result = 1; - break; - } - else - { - // missing from collision.hpp - } - // mintime = MIN2(mintime, (float)solution[k]); - - break; - } - } - } - } - return result; -} - -static int cloth_collision_moving ( ClothModifierData *clmd, CollisionModifierData *collmd, CollPair *collpair, CollPair *collision_end ) -{ - Cloth *cloth1; - cloth1 = clmd->clothObject; - - for ( ; collpair != collision_end; collpair++ ) - { - // only handle moving collisions here - if (!( collpair->flag & COLLISION_IN_FUTURE )) - continue; - - cloth_collision_moving_edges ( clmd, collmd, collpair); - // cloth_collision_moving_tris ( clmd, collmd, collpair); - } - - return 1; -} -#endif static void add_collision_object(Object ***objs, unsigned int *numobj, unsigned int *maxobj, Object *ob, Object *self, int level, unsigned int modifier_type) { @@ -2224,37 +636,14 @@ static void cloth_bvh_objcollisions_nearcheck ( ClothModifierData * clmd, Collis CollPair **collisions, CollPair **collisions_index, int numresult, BVHTreeOverlap *overlap, double dt) { int i; -#ifdef WITH_ELTOPO - GHash *visithash = BLI_ghash_new(edgepair_hash, edgepair_cmp, "visthash, collision.c"); - GHash *tri_visithash = BLI_ghash_new(tripair_hash, tripair_cmp, "tri_visthash, collision.c"); - MemArena *arena = BLI_memarena_new(1<<16, "edge hash arena, collision.c"); -#endif *collisions = ( CollPair* ) MEM_mallocN ( sizeof ( CollPair ) * numresult * 64, "collision array" ); //*4 since cloth_collision_static can return more than 1 collision *collisions_index = *collisions; - -#ifdef WITH_ELTOPO - machine_epsilon_offset(clmd->clothObject); - for ( i = 0; i < numresult; i++ ) { - *collisions_index = cloth_collision ( (ModifierData *)clmd, (ModifierData *)collmd, - overlap+i, *collisions_index, dt, tri_visithash, arena ); - } - - for ( i = 0; i < numresult; i++ ) { - *collisions_index = cloth_edge_collision ( (ModifierData *)clmd, (ModifierData *)collmd, - overlap+i, *collisions_index, visithash, arena ); - } - BLI_ghash_free(visithash, NULL, NULL); - BLI_ghash_free(tri_visithash, NULL, NULL); - BLI_memarena_free(arena); -#else /* WITH_ELTOPO */ for ( i = 0; i < numresult; i++ ) { *collisions_index = cloth_collision ( (ModifierData *)clmd, (ModifierData *)collmd, overlap+i, *collisions_index, dt ); } -#endif /* WITH_ELTOPO */ - } static int cloth_bvh_objcollisions_resolve ( ClothModifierData * clmd, CollisionModifierData *collmd, CollPair *collisions, CollPair *collisions_index) @@ -2264,36 +653,26 @@ static int cloth_bvh_objcollisions_resolve ( ClothModifierData * clmd, Collision ClothVertex *verts = NULL; int ret = 0; int result = 0; - float tnull[3] = {0, 0, 0}; - /*numfaces = clmd->clothObject->numfaces;*/ /*UNUSED*/ numverts = clmd->clothObject->numverts; - verts = cloth->verts; // process all collisions (calculate impulses, TODO: also repulses if distance too short) result = 1; - for ( j = 0; j < 5; j++ ) { /* 5 is just a value that ensures convergence */ + for ( j = 0; j < 2; j++ ) { /* 5 is just a value that ensures convergence */ result = 0; if ( collmd->bvhtree ) { -#ifdef WITH_ELTOPO - result += cloth_collision_response_moving(clmd, collmd, collisions, collisions_index); - result += cloth_edge_collision_response_moving(clmd, collmd, collisions, collisions_index); -#else result += cloth_collision_response_static ( clmd, collmd, collisions, collisions_index ); -#endif -#ifdef WITH_ELTOPO - { -#else + // apply impulses in parallel if (result) { -#endif for (i = 0; i < numverts; i++) { // calculate "velocities" (just xnew = xold + v; no dt in v) if (verts[i].impulse_count) { - VECADDMUL ( verts[i].tv, verts[i].impulse, 1.0f / verts[i].impulse_count ); - copy_v3_v3 ( verts[i].impulse, tnull ); + // VECADDMUL ( verts[i].tv, verts[i].impulse, 1.0f / verts[i].impulse_count ); + VECADD ( verts[i].tv, verts[i].tv, verts[i].impulse); + zero_v3(verts[i].impulse); verts[i].impulse_count = 0; ret++; @@ -2301,6 +680,9 @@ static int cloth_bvh_objcollisions_resolve ( ClothModifierData * clmd, Collision } } } + + if(!result) + break; } return ret; } @@ -2337,6 +719,18 @@ int cloth_bvh_objcollision(Object *ob, ClothModifierData * clmd, float step, flo if (!collobjs) return 0; + /* move object to position (step) in time */ + for (i = 0; i < numcollobj; i++) { + Object *collob= collobjs[i]; + CollisionModifierData *collmd = (CollisionModifierData*)modifiers_findByType(collob, eModifierType_Collision); + + if (!collmd->bvhtree) + continue; + + /* move object to position (step) in time */ + collision_move_object ( collmd, step + dt, step ); + } + do { CollPair **collisions, **collisions_index; @@ -2356,10 +750,6 @@ int cloth_bvh_objcollision(Object *ob, ClothModifierData * clmd, float step, flo if (!collmd->bvhtree) continue; - /* move object to position (step) in time */ - - collision_move_object ( collmd, step + dt, step ); - /* search for overlapping collision pairs */ overlap = BLI_bvhtree_overlap ( cloth_bvh, collmd->bvhtree, &result ); diff --git a/source/blender/blenkernel/intern/colortools.c b/source/blender/blenkernel/intern/colortools.c index 7ba117861bb..d15f678f1c5 100644 --- a/source/blender/blenkernel/intern/colortools.c +++ b/source/blender/blenkernel/intern/colortools.c @@ -146,6 +146,32 @@ void curvemapping_set_black_white(CurveMapping *cumap, const float black[3], con /* ***************** operations on single curve ************* */ /* ********** NOTE: requires curvemapping_changed() call after ******** */ +/* remove specified point */ +void curvemap_remove_point(CurveMap *cuma, CurveMapPoint *point) +{ + CurveMapPoint *cmp; + int a, b, removed = 0; + + /* must have 2 points minimum */ + if (cuma->totpoint <= 2) + return; + + cmp = MEM_mallocN((cuma->totpoint) * sizeof(CurveMapPoint), "curve points"); + + /* well, lets keep the two outer points! */ + for (a = 0, b = 0; a < cuma->totpoint; a++) { + if (&cuma->curve[a] != point) { + cmp[b] = cuma->curve[a]; + b++; + } + else removed++; + } + + MEM_freeN(cuma->curve); + cuma->curve = cmp; + cuma->totpoint -= removed; +} + /* removes with flag set */ void curvemap_remove(CurveMap *cuma, int flag) { @@ -168,9 +194,10 @@ void curvemap_remove(CurveMap *cuma, int flag) cuma->totpoint -= removed; } -void curvemap_insert(CurveMap *cuma, float x, float y) +CurveMapPoint *curvemap_insert(CurveMap *cuma, float x, float y) { CurveMapPoint *cmp = MEM_callocN((cuma->totpoint + 1) * sizeof(CurveMapPoint), "curve points"); + CurveMapPoint *newcmp = NULL; int a, b, foundloc = 0; /* insert fragments of the old one and the new point to the new curve */ @@ -181,6 +208,7 @@ void curvemap_insert(CurveMap *cuma, float x, float y) cmp[a].y = y; cmp[a].flag = CUMA_SELECT; foundloc = 1; + newcmp = &cmp[a]; } else { cmp[a].x = cuma->curve[b].x; @@ -195,6 +223,8 @@ void curvemap_insert(CurveMap *cuma, float x, float y) /* free old curve and replace it with new one */ MEM_freeN(cuma->curve); cuma->curve = cmp; + + return newcmp; } void curvemap_reset(CurveMap *cuma, rctf *clipr, int preset, int slope) @@ -670,6 +700,20 @@ void curvemapping_changed(CurveMapping *cumap, int rem_doubles) curvemap_make_table(cuma, clipr); } +void curvemapping_changed_all(CurveMapping *cumap) +{ + int a, cur = cumap->cur; + + for (a = 0; a < CM_TOT; a++) { + if (cumap->cm[a].curve) { + cumap->cur = a; + curvemapping_changed(cumap, 0); + } + } + + cumap->cur = cur; +} + /* table should be verified */ float curvemap_evaluateF(CurveMap *cuma, float value) { diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c index 91c2cbb89a9..3b6d6d1c15c 100644 --- a/source/blender/blenkernel/intern/depsgraph.c +++ b/source/blender/blenkernel/intern/depsgraph.c @@ -867,7 +867,7 @@ DagNode *dag_add_node(DagForest *forest, void *fob) } if (!forest->nodeHash) - forest->nodeHash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "dag_add_node gh"); + forest->nodeHash = BLI_ghash_ptr_new("dag_add_node gh"); BLI_ghash_insert(forest->nodeHash, fob, node); } diff --git a/source/blender/blenkernel/intern/icons.c b/source/blender/blenkernel/intern/icons.c index 5990e92798e..8a49cba7649 100644 --- a/source/blender/blenkernel/intern/icons.c +++ b/source/blender/blenkernel/intern/icons.c @@ -103,7 +103,7 @@ void BKE_icons_init(int first_dyn_id) gFirstIconId = first_dyn_id; if (!gIcons) - gIcons = BLI_ghash_new(BLI_ghashutil_inthash, BLI_ghashutil_intcmp, "icons_init gh"); + gIcons = BLI_ghash_int_new("icons_init gh"); } void BKE_icons_free(void) diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index d478302931f..e3876f438f7 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -2287,21 +2287,39 @@ void create_vert_poly_map(MeshElemMap **map, int **mem, /* Generates a map where the key is the vertex and the value is a list * of edges that use that vertex as an endpoint. The lists are allocated * from one memory pool. */ -void create_vert_edge_map(ListBase **map, IndexNode **mem, const MEdge *medge, const int totvert, const int totedge) +void create_vert_edge_map(MeshElemMap **map, int **mem, + const MEdge *medge, int totvert, int totedge) { - int i, j; - IndexNode *node = NULL; - - (*map) = MEM_callocN(sizeof(ListBase) * totvert, "vert edge map"); - (*mem) = MEM_callocN(sizeof(IndexNode) * totedge * 2, "vert edge map mem"); - node = *mem; + int i, *indices; + (*map) = MEM_callocN(sizeof(MeshElemMap) * totvert, "vert-edge map"); + (*mem) = MEM_mallocN(sizeof(int) * totedge * 2, "vert-edge map mem"); + + /* Count number of edges for each vertex */ + for (i = 0; i < totedge; i++) { + (*map)[medge[i].v1].count++; + (*map)[medge[i].v2].count++; + } + + /* Assign indices mem */ + indices = (*mem); + for (i = 0; i < totvert; i++) { + (*map)[i].indices = indices; + indices += (*map)[i].count; + + /* Reset 'count' for use as index in last loop */ + (*map)[i].count = 0; + } + /* Find the users */ - for (i = 0; i < totedge; ++i) { - for (j = 0; j < 2; ++j, ++node) { - node->index = i; - BLI_addtail(&(*map)[((unsigned int *)(&medge[i].v1))[j]], node); - } + for (i = 0; i < totedge; i++) { + const int v[2] = {medge[i].v1, medge[i].v2}; + + (*map)[v[0]].indices[(*map)[v[0]].count] = i; + (*map)[v[1]].indices[(*map)[v[1]].count] = i; + + (*map)[v[0]].count++; + (*map)[v[1]].count++; } } diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c index 724d80afdd9..bd9972b62e6 100644 --- a/source/blender/blenkernel/intern/multires.c +++ b/source/blender/blenkernel/intern/multires.c @@ -1056,12 +1056,10 @@ static void multiresModifier_disp_run(DerivedMesh *dm, Mesh *me, DerivedMesh *dm dispgrid = mdisp->disps; /* if needed, reallocate multires paint mask */ - if (gpm && op == CALC_DISPLACEMENTS) { - if (gpm->level < key.level) { - gpm->level = key.level; - MEM_freeN(gpm->data); - gpm->data = MEM_callocN(sizeof(float) * key.grid_area, "gpm.data"); - } + if (gpm && gpm->level < key.level) { + gpm->level = key.level; + MEM_freeN(gpm->data); + gpm->data = MEM_callocN(sizeof(float) * key.grid_area, "gpm.data"); } for (y = 0; y < gridSize; y++) { diff --git a/source/blender/blenkernel/intern/nla.c b/source/blender/blenkernel/intern/nla.c index 02d44badc65..2b4fe72e8bb 100644 --- a/source/blender/blenkernel/intern/nla.c +++ b/source/blender/blenkernel/intern/nla.c @@ -1304,7 +1304,7 @@ void BKE_nlastrip_validate_name(AnimData *adt, NlaStrip *strip) * - this is easier than iterating over all the tracks+strips hierarchy everytime * (and probably faster) */ - gh = BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp, "nlastrip_validate_name gh"); + gh = BLI_ghash_str_new("nlastrip_validate_name gh"); for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) { for (tstrip = nlt->strips.first; tstrip; tstrip = tstrip->next) { diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 2ea832eebaa..9000019ca2a 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -3020,6 +3020,19 @@ int BKE_object_is_deform_modified(Scene *scene, Object *ob) return flag; } +/* See if an object is using an animated modifier */ +int BKE_object_is_animated(Scene *scene, Object *ob) +{ + ModifierData *md; + + for (md = modifiers_getVirtualModifierList(ob); md; md = md->next) + if(modifier_dependsOnTime(md) && + (modifier_isEnabled(scene, md, eModifierMode_Realtime) || + modifier_isEnabled(scene, md, eModifierMode_Render))) + return 1; + return 0; +} + static void copy_object__forwardModifierLinks(void *UNUSED(userData), Object *UNUSED(ob), ID **idpoin) { /* this is copied from ID_NEW; it might be better to have a macro */ diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index cd1561734cc..5397b1729f9 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -241,10 +241,10 @@ static void realloc_particles(ParticleSimulationData *sim, int new_totpart) } if (psys->particles) { - totsaved=MIN2(psys->totpart, totpart); + totsaved=MIN2(psys->totpart,totpart); /*save old pars*/ if (totsaved) { - memcpy(newpars, psys->particles, totsaved*sizeof(ParticleData)); + memcpy(newpars,psys->particles,totsaved*sizeof(ParticleData)); if (psys->particles->boid) memcpy(newboids, psys->particles->boid, totsaved*sizeof(BoidParticle)); @@ -418,7 +418,7 @@ static void distribute_simple_children(Scene *scene, Object *ob, DerivedMesh *fi cpa = psys->child; for (i=0; itotpart; p++, cpa++) { + for (p=0; ptotpart; p++,cpa++) { float length=2.0; cpa->parent=p; @@ -440,7 +440,7 @@ static void distribute_grid(DerivedMesh *dm, ParticleSystem *psys) { ParticleData *pa=NULL; float min[3], max[3], delta[3], d; - MVert *mv, *mvert = dm->getVertDataArray(dm, 0); + MVert *mv, *mvert = dm->getVertDataArray(dm,0); int totvert=dm->getNumVerts(dm), from=psys->part->from; int i, j, k, p, res=psys->part->grid_res, size[3], axis; @@ -452,13 +452,13 @@ static void distribute_grid(DerivedMesh *dm, ParticleSystem *psys) mv++; for (i=1; ico[0]); - min[1]=MIN2(min[1], mv->co[1]); - min[2]=MIN2(min[2], mv->co[2]); + min[0]=MIN2(min[0],mv->co[0]); + min[1]=MIN2(min[1],mv->co[1]); + min[2]=MIN2(min[2],mv->co[2]); - max[0]=MAX2(max[0], mv->co[0]); - max[1]=MAX2(max[1], mv->co[1]); - max[2]=MAX2(max[2], mv->co[2]); + max[0]=MAX2(max[0],mv->co[0]); + max[1]=MAX2(max[1],mv->co[1]); + max[2]=MAX2(max[2],mv->co[2]); } sub_v3_v3v3(delta, max, min); @@ -473,8 +473,8 @@ static void distribute_grid(DerivedMesh *dm, ParticleSystem *psys) size[(axis+2)%3] = (int)ceil(delta[(axis+2)%3]/d); /* float errors grrr.. */ - size[(axis+1)%3] = MIN2(size[(axis+1)%3], res); - size[(axis+2)%3] = MIN2(size[(axis+2)%3], res); + size[(axis+1)%3] = MIN2(size[(axis+1)%3],res); + size[(axis+2)%3] = MIN2(size[(axis+2)%3],res); size[0] = MAX2(size[0], 1); size[1] = MAX2(size[1], 1); @@ -485,9 +485,9 @@ static void distribute_grid(DerivedMesh *dm, ParticleSystem *psys) min[1]+= d < delta[1] ? d/2.f : delta[1]/2.f; min[2]+= d < delta[2] ? d/2.f : delta[2]/2.f; - for (i=0, p=0, pa=psys->particles; iparticles; ifuv[0] = min[0] + (float)i*d; pa->fuv[1] = min[1] + (float)j*d; pa->fuv[2] = min[2] + (float)k*d; @@ -507,8 +507,8 @@ static void distribute_grid(DerivedMesh *dm, ParticleSystem *psys) min[1] -= d/2.0f; min[2] -= d/2.0f; - for (i=0, mv=mvert; ico, min); + for (i=0,mv=mvert; ico,min); vec[0]/=delta[0]; vec[1]/=delta[1]; vec[2]/=delta[2]; @@ -517,7 +517,7 @@ static void distribute_grid(DerivedMesh *dm, ParticleSystem *psys) (int)(vec[2] * (size[2] - 1)))->flag &= ~PARS_UNEXIST; } } - else if (ELEM(from, PART_FROM_FACE, PART_FROM_VOLUME)) { + else if (ELEM(from,PART_FROM_FACE,PART_FROM_VOLUME)) { float co1[3], co2[3]; MFace *mface= NULL, *mface_array; @@ -526,7 +526,7 @@ static void distribute_grid(DerivedMesh *dm, ParticleSystem *psys) int amax= from==PART_FROM_FACE ? 3 : 1; totface=dm->getNumTessFaces(dm); - mface=mface_array=dm->getTessFaceDataArray(dm, CD_MFACE); + mface=mface_array=dm->getTessFaceDataArray(dm,CD_MFACE); for (a=0; av1].co); copy_v3_v3(v2, mvert[mface->v2].co); copy_v3_v3(v3, mvert[mface->v3].co); @@ -586,9 +586,9 @@ static void distribute_grid(DerivedMesh *dm, ParticleSystem *psys) } if (psys->part->flag & PART_GRID_HEXAGONAL) { - for (i=0, p=0, pa=psys->particles; iparticles; ifuv[0] += d/2.f; @@ -614,7 +614,7 @@ static void distribute_grid(DerivedMesh *dm, ParticleSystem *psys) if (psys->part->grid_rand > 0.f) { float rfac = d * psys->part->grid_rand; - for (p=0, pa=psys->particles; ptotpart; p++, pa++) { + for (p=0,pa=psys->particles; ptotpart; p++,pa++) { if (pa->flag & PARS_UNEXIST) continue; @@ -708,10 +708,10 @@ static void psys_uv_to_w(float u, float v, int quad, float *w) if (quad) { vert[3][0]= 0.0f; vert[3][1]= 1.0f; vert[3][2]= 0.0f; - interp_weights_poly_v3(w, vert, 4, co); + interp_weights_poly_v3( w,vert, 4, co); } else { - interp_weights_poly_v3(w, vert, 3, co); + interp_weights_poly_v3( w,vert, 3, co); w[3]= 0.0f; } } @@ -771,9 +771,9 @@ static void distribute_threads_exec(ParticleThread *thread, ParticleData *pa, Ch KDTreeNearest ptn[3]; int w, maxw; - psys_particle_on_dm(ctx->dm, from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, co1, 0, 0, 0, orco1, 0); + psys_particle_on_dm(ctx->dm,from,pa->num,pa->num_dmcache,pa->fuv,pa->foffset,co1,0,0,0,orco1,0); BKE_mesh_orco_verts_transform((Mesh*)ob->data, &orco1, 1, 1); - maxw = BLI_kdtree_find_n_nearest(ctx->tree, 3, orco1, NULL, ptn); + maxw = BLI_kdtree_find_n_nearest(ctx->tree,3,orco1,NULL,ptn); for (w=0; wverts[w]=ptn->num; @@ -785,7 +785,7 @@ static void distribute_threads_exec(ParticleThread *thread, ParticleData *pa, Ch MFace *mface; pa->num = i = ctx->index[p]; - mface = dm->getTessFaceData(dm, i, CD_MFACE); + mface = dm->getTessFaceData(dm,i,CD_MFACE); switch (distr) { case PART_DISTR_JIT: @@ -796,7 +796,7 @@ static void distribute_threads_exec(ParticleThread *thread, ParticleData *pa, Ch psys_uv_to_w(0.33333f, 0.33333f, mface->v4, pa->fuv); } else { - ctx->jitoff[i] = fmod(ctx->jitoff[i], (float)ctx->jitlevel); + ctx->jitoff[i] = fmod(ctx->jitoff[i],(float)ctx->jitlevel); psys_uv_to_w(ctx->jit[2*(int)ctx->jitoff[i]], ctx->jit[2*(int)ctx->jitoff[i]+1], mface->v4, pa->fuv); ctx->jitoff[i]++; } @@ -813,21 +813,21 @@ static void distribute_threads_exec(ParticleThread *thread, ParticleData *pa, Ch /* experimental */ if (from==PART_FROM_VOLUME) { - MVert *mvert=dm->getVertDataArray(dm, CD_MVERT); + MVert *mvert=dm->getVertDataArray(dm,CD_MVERT); tot=dm->getNumTessFaces(dm); - psys_interpolate_face(mvert, mface, 0, 0, pa->fuv, co1, nor, 0, 0, 0, 0); + psys_interpolate_face(mvert,mface,0,0,pa->fuv,co1,nor,0,0,0,0); normalize_v3(nor); - mul_v3_fl(nor, -100.0); + mul_v3_fl(nor,-100.0); - add_v3_v3v3(co2, co1, nor); + add_v3_v3v3(co2,co1,nor); min_d=2.0; intersect=0; - for (i=0, mface=dm->getTessFaceDataArray(dm, CD_MFACE); igetTessFaceDataArray(dm,CD_MFACE); inum) continue; v1=mvert[mface->v1].co; @@ -889,14 +889,14 @@ static void distribute_threads_exec(ParticleThread *thread, ParticleData *pa, Ch if (ctx->tree) { KDTreeNearest ptn[10]; - int w, maxw;//, do_seams; - float maxd /*, mind, dd */, totw= 0.0f; + int w,maxw;//, do_seams; + float maxd /*, mind,dd */, totw= 0.0f; int parent[10]; float pweight[10]; - psys_particle_on_dm(dm, cfrom, cpa->num, DMCACHE_ISCHILD, cpa->fuv, cpa->foffset, co1, nor1, NULL, NULL, orco1, NULL); + psys_particle_on_dm(dm,cfrom,cpa->num,DMCACHE_ISCHILD,cpa->fuv,cpa->foffset,co1,nor1,NULL,NULL,orco1,NULL); BKE_mesh_orco_verts_transform((Mesh*)ob->data, &orco1, 1, 1); - maxw = BLI_kdtree_find_n_nearest(ctx->tree, 4, orco1, NULL, ptn); + maxw = BLI_kdtree_find_n_nearest(ctx->tree,4,orco1,NULL,ptn); maxd=ptn[maxw-1].dist; /* mind=ptn[0].dist; */ /* UNUSED */ @@ -904,14 +904,14 @@ static void distribute_threads_exec(ParticleThread *thread, ParticleData *pa, Ch /* the weights here could be done better */ for (w=0; w=0) { cpa->pa[i]=parent[w]; cpa->w[i]=pweight[w]; @@ -997,7 +997,7 @@ static void distribute_invalid(Scene *scene, ParticleSystem *psys, int from) int p, totchild = get_psys_tot_child(scene, psys); if (psys->child && totchild) { - for (p=0, cpa=psys->child; pchild; pfuv[0]=cpa->fuv[1]=cpa->fuv[2]=cpa->fuv[3]= 0.0; cpa->foffset= 0.0f; cpa->parent=0; @@ -1033,7 +1033,7 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D int cfrom=0; int totelem=0, totpart, *particle_element=0, children=0, totseam=0; int jitlevel= 1, distr; - float *element_weight=NULL, *element_sum=NULL, *jitter_offset=NULL, *vweight=NULL; + float *element_weight=NULL,*element_sum=NULL,*jitter_offset=NULL, *vweight=NULL; float cur, maxweight=0.0, tweight, totweight, inv_totweight, co[3], nor[3], orco[3], ornor[3]; if (ELEM3(NULL, ob, psys, psys->part)) @@ -1065,7 +1065,7 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D BLI_srandom(31415926 + psys->seed); dm= CDDM_from_mesh((Mesh*)ob->data, ob); DM_ensure_tessface(dm); - distribute_grid(dm, psys); + distribute_grid(dm,psys); dm->release(dm); return 0; } @@ -1084,8 +1084,8 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D tree=BLI_kdtree_new(totpart); - for (p=0, pa=psys->particles; pfrom, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, co, nor, 0, 0, orco, ornor); + for (p=0,pa=psys->particles; pfrom,pa->num,pa->num_dmcache,pa->fuv,pa->foffset,co,nor,0,0,orco,ornor); BKE_mesh_orco_verts_transform((Mesh*)ob->data, &orco, 1, 1); BLI_kdtree_insert(tree, p, orco, ornor); } @@ -1118,12 +1118,12 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D for (p=0; pdata, &co, 1, 1); } else - copy_v3_v3(co, mv[p].co); - BLI_kdtree_insert(tree, p, co, NULL); + copy_v3_v3(co,mv[p].co); + BLI_kdtree_insert(tree,p,co,NULL); } BLI_kdtree_balance(tree); @@ -1137,7 +1137,7 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D distribute_invalid(scene, psys, children ? PART_FROM_CHILD : 0); if (G.debug & G_DEBUG) - fprintf(stderr, "Particle distribution error: Nothing to emit from!\n"); + fprintf(stderr,"Particle distribution error: Nothing to emit from!\n"); if (dm != finaldm) dm->release(dm); @@ -1160,7 +1160,7 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D orcodata= dm->getVertDataArray(dm, CD_ORCO); for (i=0; igetTessFaceData(dm, i, CD_MFACE); + MFace *mf=dm->getTessFaceData(dm,i,CD_MFACE); if (orcodata) { copy_v3_v3(co1, orcodata[mf->v1]); @@ -1175,14 +1175,14 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D } } else { - v1= (MVert*)dm->getVertData(dm, mf->v1, CD_MVERT); - v2= (MVert*)dm->getVertData(dm, mf->v2, CD_MVERT); - v3= (MVert*)dm->getVertData(dm, mf->v3, CD_MVERT); + v1= (MVert*)dm->getVertData(dm,mf->v1,CD_MVERT); + v2= (MVert*)dm->getVertData(dm,mf->v2,CD_MVERT); + v3= (MVert*)dm->getVertData(dm,mf->v3,CD_MVERT); copy_v3_v3(co1, v1->co); copy_v3_v3(co2, v2->co); copy_v3_v3(co3, v3->co); if (mf->v4) { - v4= (MVert*)dm->getVertData(dm, mf->v4, CD_MVERT); + v4= (MVert*)dm->getVertData(dm,mf->v4,CD_MVERT); copy_v3_v3(co4, v4->co); } } @@ -1202,14 +1202,14 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D maxweight /= totarea; } else { - float min=1.0f/(float)(MIN2(totelem, totpart)); + float min=1.0f/(float)(MIN2(totelem,totpart)); for (i=0; igetTessFaceData(dm, i, CD_MFACE); + MFace *mf=dm->getTessFaceData(dm,i,CD_MFACE); tweight = vweight[mf->v1] + vweight[mf->v2] + vweight[mf->v3]; if (mf->v4) { @@ -1303,7 +1303,7 @@ static int distribute_threads_init_data(ParticleThread *threads, Scene *scene, D } /* Create jittering if needed */ - if (distr==PART_DISTR_JIT && ELEM(from, PART_FROM_FACE, PART_FROM_VOLUME)) { + if (distr==PART_DISTR_JIT && ELEM(from,PART_FROM_FACE,PART_FROM_VOLUME)) { jitlevel= part->userjit; if (jitlevel == 0) { @@ -1399,7 +1399,7 @@ static void distribute_particles_on_shape(ParticleSimulationData *sim, int UNUSE { distribute_invalid(sim->scene, sim->psys, 0); - fprintf(stderr, "Shape emission not yet possible!\n"); + fprintf(stderr,"Shape emission not yet possible!\n"); } static void distribute_particles(ParticleSimulationData *sim, int from) @@ -1419,7 +1419,7 @@ static void distribute_particles(ParticleSimulationData *sim, int from) if (distr_error) { distribute_invalid(sim->scene, sim->psys, from); - fprintf(stderr, "Particle distribution error!\n"); + fprintf(stderr,"Particle distribution error!\n"); } } @@ -1620,18 +1620,18 @@ void psys_get_birth_coordinates(ParticleSimulationData *sim, ParticleData *pa, P ParticleSystem *psys = sim->psys; ParticleSettings *part; ParticleTexture ptex; - float fac, phasefac, nor[3]={0, 0, 0}, loc[3], vel[3]={0.0, 0.0, 0.0}, rot[4], q2[4]; - float r_vel[3], r_ave[3], r_rot[4], vec[3], p_vel[3]={0.0, 0.0, 0.0}; - float x_vec[3]={1.0, 0.0, 0.0}, utan[3]={0.0, 1.0, 0.0}, vtan[3]={0.0, 0.0, 1.0}, rot_vec[3]={0.0, 0.0, 0.0}; + float fac, phasefac, nor[3]={0,0,0},loc[3],vel[3]={0.0,0.0,0.0},rot[4],q2[4]; + float r_vel[3],r_ave[3],r_rot[4],vec[3],p_vel[3]={0.0,0.0,0.0}; + float x_vec[3]={1.0,0.0,0.0}, utan[3]={0.0,1.0,0.0}, vtan[3]={0.0,0.0,1.0}, rot_vec[3]={0.0,0.0,0.0}; float q_phase[4]; int p = pa - psys->particles; part=psys->part; /* get birth location from object */ if (part->tanfac != 0.f) - psys_particle_on_emitter(sim->psmd, part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, loc, nor, utan, vtan, 0, 0); + psys_particle_on_emitter(sim->psmd, part->from,pa->num, pa->num_dmcache, pa->fuv,pa->foffset,loc,nor,utan,vtan,0,0); else - psys_particle_on_emitter(sim->psmd, part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, loc, nor, 0, 0, 0, 0); + psys_particle_on_emitter(sim->psmd, part->from,pa->num, pa->num_dmcache, pa->fuv,pa->foffset,loc,nor,0,0,0,0); /* get possible textural influence */ psys_get_texture(sim, pa, &ptex, PAMAP_IVEL, cfra); @@ -1647,16 +1647,16 @@ void psys_get_birth_coordinates(ParticleSimulationData *sim, ParticleData *pa, P /* -tangent */ if (part->tanfac!=0.0f) { - //float phase=vg_rot?2.0f*(psys_particle_value_from_verts(sim->psmd->dm, part->from, pa, vg_rot)-0.5f):0.0f; + //float phase=vg_rot?2.0f*(psys_particle_value_from_verts(sim->psmd->dm,part->from,pa,vg_rot)-0.5f):0.0f; float phase=0.0f; - mul_v3_fl(vtan, -cosf((float)M_PI*(part->tanphase+phase))); + mul_v3_fl(vtan,-cosf((float)M_PI*(part->tanphase+phase))); fac= -sinf((float)M_PI*(part->tanphase+phase)); madd_v3_v3fl(vtan, utan, fac); - mul_mat3_m4_v3(ob->obmat, vtan); + mul_mat3_m4_v3(ob->obmat,vtan); copy_v3_v3(utan, nor); - mul_v3_fl(utan, dot_v3v3(vtan, nor)); + mul_v3_fl(utan,dot_v3v3(vtan,nor)); sub_v3_v3(vtan, utan); normalize_v3(vtan); @@ -1679,7 +1679,7 @@ void psys_get_birth_coordinates(ParticleSimulationData *sim, ParticleData *pa, P r_ave[1] = 2.0f * (PSYS_FRAND(p + 14) - 0.5f); r_ave[2] = 2.0f * (PSYS_FRAND(p + 15) - 0.5f); - mul_mat3_m4_v3(ob->obmat, r_ave); + mul_mat3_m4_v3(ob->obmat,r_ave); normalize_v3(r_ave); } @@ -1691,14 +1691,14 @@ void psys_get_birth_coordinates(ParticleSimulationData *sim, ParticleData *pa, P r_rot[3] = 2.0f * (PSYS_FRAND(p + 19) - 0.5f); normalize_qt(r_rot); - mat4_to_quat(rot, ob->obmat); - mul_qt_qtqt(r_rot, r_rot, rot); + mat4_to_quat(rot,ob->obmat); + mul_qt_qtqt(r_rot,r_rot,rot); } if (part->phystype==PART_PHYS_BOIDS && pa->boid) { float dvec[3], q[4], mat[3][3]; - copy_v3_v3(state->co, loc); + copy_v3_v3(state->co,loc); /* boids don't get any initial velocity */ zero_v3(state->vel); @@ -1721,7 +1721,7 @@ void psys_get_birth_coordinates(ParticleSimulationData *sim, ParticleData *pa, P cross_v3_v3v3(mat[1], mat[2], mat[0]); /* apply rotation */ - mat3_to_quat_is_ok(q, mat); + mat3_to_quat_is_ok( q,mat); copy_qt_qt(state->rot, q); } else { @@ -1775,7 +1775,7 @@ void psys_get_birth_coordinates(ParticleSimulationData *sim, ParticleData *pa, P mul_v3_v3fl(state->vel, vel, ptex.ivel); /* -location from emitter */ - copy_v3_v3(state->co, loc); + copy_v3_v3(state->co,loc); /* -rotation */ unit_qt(state->rot); @@ -1803,19 +1803,19 @@ void psys_get_birth_coordinates(ParticleSimulationData *sim, ParticleData *pa, P /* create rotation quat */ negate_v3(rot_vec); - vec_to_quat(q2, rot_vec, OB_POSX, OB_POSZ); + vec_to_quat( q2,rot_vec, OB_POSX, OB_POSZ); /* randomize rotation quat */ if (part->randrotfac!=0.0f) interp_qt_qtqt(rot, q2, r_rot, part->randrotfac); else - copy_qt_qt(rot, q2); + copy_qt_qt(rot,q2); /* rotation phase */ phasefac = part->phasefac; if (part->randphasefac != 0.0f) phasefac += part->randphasefac * PSYS_FRAND(p + 20); - axis_angle_to_quat(q_phase, x_vec, phasefac*(float)M_PI); + axis_angle_to_quat( q_phase,x_vec, phasefac*(float)M_PI); /* combine base rotation & phase */ mul_qt_qtqt(state->rot, rot, q_phase); @@ -2133,7 +2133,7 @@ static void psys_update_effectors(ParticleSimulationData *sim) static void integrate_particle(ParticleSettings *part, ParticleData *pa, float dtime, float *external_acceleration, void (*force_func)(void *forcedata, ParticleKey *state, float *force, float *impulse), void *forcedata) { ParticleKey states[5]; - float force[3], acceleration[3], impulse[3], dx[4][3], dv[4][3], oldpos[3]; + float force[3],acceleration[3],impulse[3],dx[4][3],dv[4][3],oldpos[3]; float pa_mass= (part->flag & PART_SIZEMASS ? part->mass * pa->size : part->mass); int i, steps=1; int integrator = part->integrator; @@ -2538,10 +2538,10 @@ static void sph_force_cb(void *sphdata_v, ParticleKey *state, float *force, floa u = dot_v3v3(vec, dv); if (u < 0.f && visc > 0.f) - madd_v3_v3fl(force, vec, 0.5f * q * visc * u); + madd_v3_v3fl(force, vec, 0.5f * q * visc * u ); if (u > 0.f && stiff_visc > 0.f) - madd_v3_v3fl(force, vec, 0.5f * q * stiff_visc * u); + madd_v3_v3fl(force, vec, 0.5f * q * stiff_visc * u ); } if (spring_constant > 0.f) { @@ -2714,23 +2714,23 @@ static void basic_integrate(ParticleSimulationData *sim, int p, float dfra, floa time=(cfra-pa->time)/pa->lifetime; CLAMP(time, 0.0f, 1.0f); - copy_v3_v3(tkey.co, pa->state.co); - copy_v3_v3(tkey.vel, pa->state.vel); + copy_v3_v3(tkey.co,pa->state.co); + copy_v3_v3(tkey.vel,pa->state.vel); tkey.time=pa->state.time; if (part->type != PART_HAIR) { if (do_guides(sim->psys->effectors, &tkey, p, time)) { - copy_v3_v3(pa->state.co, tkey.co); + copy_v3_v3(pa->state.co,tkey.co); /* guides don't produce valid velocity */ sub_v3_v3v3(pa->state.vel, tkey.co, pa->prev_state.co); - mul_v3_fl(pa->state.vel, 1.0f/dtime); + mul_v3_fl(pa->state.vel,1.0f/dtime); pa->state.time=tkey.time; } } } static void basic_rotate(ParticleSettings *part, ParticleData *pa, float dfra, float timestep) { - float rotfac, rot1[4], rot2[4]={1.0, 0.0, 0.0, 0.0}, dtime=dfra*timestep; + float rotfac, rot1[4], rot2[4]={1.0,0.0,0.0,0.0}, dtime=dfra*timestep; if ((part->flag & PART_ROTATIONS)==0) { pa->state.rot[0]=1.0f; @@ -2758,15 +2758,15 @@ static void basic_rotate(ParticleSettings *part, ParticleData *pa, float dfra, f } rotfac = len_v3(pa->state.ave); - if (rotfac == 0.0f) { /* unit_qt(in VecRotToQuat) doesn't give unit quat [1, 0, 0, 0]?? */ + if (rotfac == 0.0f) { /* unit_qt(in VecRotToQuat) doesn't give unit quat [1,0,0,0]?? */ rot1[0]=1.0f; rot1[1]=rot1[2]=rot1[3]=0; } else { - axis_angle_to_quat(rot1, pa->state.ave, rotfac*dtime); + axis_angle_to_quat(rot1,pa->state.ave,rotfac*dtime); } - mul_qt_qtqt(pa->state.rot, rot1, pa->prev_state.rot); - mul_qt_qtqt(pa->state.rot, rot2, pa->state.rot); + mul_qt_qtqt(pa->state.rot,rot1,pa->prev_state.rot); + mul_qt_qtqt(pa->state.rot,rot2,pa->state.rot); /* keep rotation quat in good health */ normalize_qt(pa->state.rot); @@ -3257,8 +3257,8 @@ static int collision_response(ParticleData *pa, ParticleCollision *col, BVHTreeR float frict = pd->pdef_frict + pd->pdef_rfrict * 2 * (BLI_frand() - 0.5f); float distance, nor[3], dot; - CLAMP(damp, 0.0f, 1.0f); - CLAMP(frict, 0.0f, 1.0f); + CLAMP(damp,0.0f, 1.0f); + CLAMP(frict,0.0f, 1.0f); /* get exact velocity right before collision */ madd_v3_v3v3fl(v0, col->ve1, col->acc, dt1); @@ -3604,7 +3604,7 @@ static void do_hair_dynamics(ParticleSimulationData *sim) psys_mat_hair_to_object(sim->ob, sim->psmd->dm, psys->part->from, pa, hairmat); - for (k=0, key=pa->hair; ktotkey; k++, key++) { + for (k=0, key=pa->hair; ktotkey; k++,key++) { /* create fake root before actual root to resist bending */ if (k==0) { @@ -3870,7 +3870,7 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra) } /* initialize all particles for dynamics */ LOOP_SHOWN_PARTICLES { - copy_particle_key(&pa->prev_state, &pa->state, 1); + copy_particle_key(&pa->prev_state,&pa->state,1); psys_get_texture(sim, pa, &ptex, PAMAP_SIZE, cfra); @@ -3949,7 +3949,7 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra) SPHData sphdata; sph_solver_init(sim, &sphdata); - #pragma omp parallel for firstprivate (sphdata) private (pa) schedule(dynamic, 5) + #pragma omp parallel for firstprivate (sphdata) private (pa) schedule(dynamic,5) LOOP_DYNAMIC_PARTICLES { /* do global forces & effectors */ basic_integrate(sim, p, pa->state.time, cfra); @@ -4086,7 +4086,7 @@ static void particles_fluid_step(ParticleSimulationData *sim, int UNUSED(cfra)) gzf = BLI_gzopen(filename, "rb"); if (!gzf) { - BLI_snprintf(debugStrBuffer, sizeof(debugStrBuffer), "readFsPartData::error - Unable to open file for reading '%s'\n", filename); + BLI_snprintf(debugStrBuffer, sizeof(debugStrBuffer),"readFsPartData::error - Unable to open file for reading '%s'\n", filename); // XXX bad level call elbeemDebugOut(debugStrBuffer); return; } @@ -4107,23 +4107,23 @@ static void particles_fluid_step(ParticleSimulationData *sim, int UNUSED(cfra)) for (p=0, pa=psys->particles; psize), sizeof(float)); + gzread(gzf, &(pa->size), sizeof( float )); pa->size /= 10.0f; for (j=0; j<3; j++) { float wrf; - gzread(gzf, &wrf, sizeof(wrf)); + gzread(gzf, &wrf, sizeof( wrf )); pa->state.co[j] = wrf; - //fprintf(stderr, "Rj%d ", j); + //fprintf(stderr,"Rj%d ",j); } for (j=0; j<3; j++) { float wrf; - gzread(gzf, &wrf, sizeof(wrf)); + gzread(gzf, &wrf, sizeof( wrf )); pa->state.vel[j] = wrf; } @@ -4135,7 +4135,7 @@ static void particles_fluid_step(ParticleSimulationData *sim, int UNUSED(cfra)) pa->dietime = sim->scene->r.efra + 1; pa->lifetime = sim->scene->r.efra; pa->alive = PARS_ALIVE; - //if (a < 25) fprintf(stderr, "FSPARTICLE debug set %s, a%d = %f, %f, %f, life=%f\n", filename, a, pa->co[0], pa->co[1], pa->co[2], pa->lifetime ); + //if (a < 25) fprintf(stderr,"FSPARTICLE debug set %s , a%d = %f,%f,%f , life=%f\n", filename, a, pa->co[0],pa->co[1],pa->co[2], pa->lifetime ); } else { // skip... @@ -4148,7 +4148,7 @@ static void particles_fluid_step(ParticleSimulationData *sim, int UNUSED(cfra)) gzclose(gzf); totpart = psys->totpart = activeParts; - BLI_snprintf(debugStrBuffer, sizeof(debugStrBuffer), "readFsPartData::done - particles:%d, active:%d, file:%d, mask:%d\n", psys->totpart, activeParts, fileParts, readMask); + BLI_snprintf(debugStrBuffer,sizeof(debugStrBuffer),"readFsPartData::done - particles:%d, active:%d, file:%d, mask:%d\n", psys->totpart,activeParts,fileParts,readMask); // bad level call // XXX elbeemDebugOut(debugStrBuffer); @@ -4303,7 +4303,7 @@ static void system_step(ParticleSimulationData *sim, float cfra) dynamics_step(sim, cfra+dframe+t_frac - 1.f); psys->cfra = cfra+dframe+t_frac - 1.f; #if 0 - printf("%f, %f, %f, %f\n", cfra+dframe+t_frac - 1.f, t_frac, dt_frac, sim->courant_num); + printf("%f,%f,%f,%f\n", cfra+dframe+t_frac - 1.f, t_frac, dt_frac, sim->courant_num); #endif if (part->time_flag & PART_TIME_AUTOSF) dt_frac = update_timestep(psys, sim, t_frac); @@ -4590,7 +4590,7 @@ void particle_system_update(Scene *scene, Object *ob, ParticleSystem *psys) if (part->phystype == PART_PHYS_KEYED) { psys_count_keyed_targets(&sim); set_keyed_keys(&sim); - psys_update_path_cache(&sim, (int)cfra); + psys_update_path_cache(&sim,(int)cfra); } break; } diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index ee70d4228de..a66b8a1a373 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -3669,7 +3669,7 @@ static void sb_new_scratch(SoftBody *sb) { if (!sb) return; sb->scratch = MEM_callocN(sizeof(SBScratch), "SBScratch"); - sb->scratch->colliderhash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "sb_new_scratch gh"); + sb->scratch->colliderhash = BLI_ghash_ptr_new("sb_new_scratch gh"); sb->scratch->bodyface = NULL; sb->scratch->totface = 0; sb->scratch->aabbmax[0]=sb->scratch->aabbmax[1]=sb->scratch->aabbmax[2] = 1.0e30f; diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c index 52007f1f43e..28fb75db41c 100644 --- a/source/blender/blenkernel/intern/sound.c +++ b/source/blender/blenkernel/intern/sound.c @@ -173,6 +173,7 @@ void sound_force_device(int device) void sound_init_once(void) { AUD_initOnce(); + atexit(sound_exit); } void sound_init(struct Main *bmain) diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c index 2299860b5ae..abb45608822 100644 --- a/source/blender/blenkernel/intern/tracking.c +++ b/source/blender/blenkernel/intern/tracking.c @@ -782,7 +782,7 @@ static TracksMap *tracks_map_new(const char *object_name, int is_camera, int num if (customdata_size) map->customdata = MEM_callocN(customdata_size*num_tracks, "TracksMap customdata"); - map->hash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "TracksMap hash"); + map->hash = BLI_ghash_ptr_new("TracksMap hash"); return map; } diff --git a/source/blender/blenlib/BLI_ghash.h b/source/blender/blenlib/BLI_ghash.h index b2532d0e486..9034e8e51d9 100644 --- a/source/blender/blenlib/BLI_ghash.h +++ b/source/blender/blenlib/BLI_ghash.h @@ -147,6 +147,11 @@ int BLI_ghashutil_strcmp(const void *a, const void *b); unsigned int BLI_ghashutil_inthash(const void *ptr); int BLI_ghashutil_intcmp(const void *a, const void *b); +GHash *BLI_ghash_ptr_new(const char *info); +GHash *BLI_ghash_str_new(const char *info); +GHash *BLI_ghash_int_new(const char *info); +GHash *BLI_ghash_pair_new(const char *info); + typedef struct GHashPair { const void *first; const void *second; diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c index 6ec3d033672..5cfde3dfb77 100644 --- a/source/blender/blenlib/intern/BLI_ghash.c +++ b/source/blender/blenlib/intern/BLI_ghash.c @@ -305,6 +305,23 @@ int BLI_ghashutil_strcmp(const void *a, const void *b) return strcmp(a, b); } +GHash *BLI_ghash_ptr_new(const char *info) +{ + return BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, info); +} +GHash *BLI_ghash_str_new(const char *info) +{ + return BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp, info); +} +GHash *BLI_ghash_int_new(const char *info) +{ + return BLI_ghash_new(BLI_ghashutil_inthash, BLI_ghashutil_intcmp, info); +} +GHash *BLI_ghash_pair_new(const char *info) +{ + return BLI_ghash_new(BLI_ghashutil_pairhash, BLI_ghashutil_paircmp, info); +} + GHashPair *BLI_ghashutil_pairalloc(const void *first, const void *second) { GHashPair *pair = MEM_mallocN(sizeof(GHashPair), "GHashPair"); diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c index 958de59c4b3..e6d06484e74 100644 --- a/source/blender/blenlib/intern/fileops.c +++ b/source/blender/blenlib/intern/fileops.c @@ -211,30 +211,32 @@ FILE *BLI_fopen(const char *filename, const char *mode) void *BLI_gzopen(const char *filename, const char *mode) { - FILE *file; - gzFile gzfile = NULL; - wchar_t short_name_16[256]; + gzFile gzfile; - if (!filename || !mode) + if (!filename || !mode) { return 0; - - /* xxx Creates file before transcribing the path */ - if (mode[0] == 'w') - fclose(ufopen(filename, "a")); - - UTF16_ENCODE(filename); - UTF16_ENCODE(mode); - - GetShortPathNameW(filename_16, short_name_16, 256); - - if ((file = _wfopen(short_name_16, mode_16))) { - if (!(gzfile = gzdopen(fileno(file), mode))) { - fclose(file); - } } + else { + wchar_t short_name_16[256]; + char short_name[256]; + int i = 0; - UTF16_UN_ENCODE(mode); - UTF16_UN_ENCODE(filename); + /* xxx Creates file before transcribing the path */ + if (mode[0] == 'w') + fclose(ufopen(filename, "a")); + + UTF16_ENCODE(filename); + + GetShortPathNameW(filename_16, short_name_16, 256); + + for (i = 0; i < 256; i++) { + short_name[i] = (char)short_name_16[i]; + } + + gzfile = gzopen(short_name, mode); + + UTF16_UN_ENCODE(filename); + } return gzfile; } diff --git a/source/blender/blenlib/intern/pbvh.c b/source/blender/blenlib/intern/pbvh.c index 73a90fa53a0..fdb0cc0ccc8 100644 --- a/source/blender/blenlib/intern/pbvh.c +++ b/source/blender/blenlib/intern/pbvh.c @@ -381,7 +381,7 @@ static void build_mesh_leaf_node(PBVH *bvh, PBVHNode *node) GHash *map; int i, j, totface; - map = BLI_ghash_new(BLI_ghashutil_inthash, BLI_ghashutil_intcmp, "build_mesh_leaf_node gh"); + map = BLI_ghash_int_new("build_mesh_leaf_node gh"); node->uniq_verts = node->face_verts = 0; totface = node->totprim; @@ -1262,7 +1262,7 @@ void BLI_pbvh_get_grid_updates(PBVH *bvh, int clear, void ***gridfaces, int *tot unsigned i; int tot; - map = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "pbvh_get_grid_updates gh"); + map = BLI_ghash_ptr_new("pbvh_get_grid_updates gh"); pbvh_iter_begin(&iter, bvh, NULL, NULL); diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.c index 4abbcb1888c..eb12a7bd837 100644 --- a/source/blender/blenloader/intern/readblenentry.c +++ b/source/blender/blenloader/intern/readblenentry.c @@ -221,7 +221,7 @@ LinkNode *BLO_blendhandle_get_previews(BlendHandle *bh, int ofblocktype, int *to LinkNode *BLO_blendhandle_get_linkable_groups(BlendHandle *bh) { FileData *fd = (FileData *) bh; - GHash *gathered = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "linkable_groups gh"); + GHash *gathered = BLI_ghash_ptr_new("linkable_groups gh"); LinkNode *names = NULL; BHead *bhead; diff --git a/source/blender/bmesh/intern/bmesh_core.c b/source/blender/bmesh/intern/bmesh_core.c index e20eb103e1b..736a43e1676 100644 --- a/source/blender/bmesh/intern/bmesh_core.c +++ b/source/blender/bmesh/intern/bmesh_core.c @@ -1833,7 +1833,7 @@ int bmesh_vert_separate(BMesh *bm, BMVert *v, BMVert ***r_vout, int *r_vout_len) int i, maxindex; BMLoop *nl; - visithash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__); + visithash = BLI_ghash_ptr_new(__func__); maxindex = 0; BM_ITER_ELEM (e, &eiter, v, BM_EDGES_OF_VERT) { diff --git a/source/blender/bmesh/intern/bmesh_mesh.c b/source/blender/bmesh/intern/bmesh_mesh.c index fe94983dc88..8d9f2ed7336 100644 --- a/source/blender/bmesh/intern/bmesh_mesh.c +++ b/source/blender/bmesh/intern/bmesh_mesh.c @@ -624,7 +624,7 @@ void BM_mesh_remap(BMesh *bm, int *vert_idx, int *edge_idx, int *face_idx) int *new_idx = NULL; /* Init the old-to-new vert pointers mapping */ - vptr_map = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "BM_mesh_remap vert pointers mapping"); + vptr_map = BLI_ghash_ptr_new("BM_mesh_remap vert pointers mapping"); /* Make a copy of all vertices. */ verts_pool = MEM_callocN(sizeof(BMVert *) * totvert, "BM_mesh_remap verts pool"); @@ -658,7 +658,7 @@ void BM_mesh_remap(BMesh *bm, int *vert_idx, int *edge_idx, int *face_idx) int *new_idx = NULL; /* Init the old-to-new vert pointers mapping */ - eptr_map = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "BM_mesh_remap edge pointers mapping"); + eptr_map = BLI_ghash_ptr_new("BM_mesh_remap edge pointers mapping"); /* Make a copy of all vertices. */ edges_pool = MEM_callocN(sizeof(BMEdge *) * totedge, "BM_mesh_remap edges pool"); @@ -691,7 +691,7 @@ void BM_mesh_remap(BMesh *bm, int *vert_idx, int *edge_idx, int *face_idx) int *new_idx = NULL; /* Init the old-to-new vert pointers mapping */ - fptr_map = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "BM_mesh_remap face pointers mapping"); + fptr_map = BLI_ghash_ptr_new("BM_mesh_remap face pointers mapping"); /* Make a copy of all vertices. */ faces_pool = MEM_callocN(sizeof(BMFace *) * totface, "BM_mesh_remap faces pool"); diff --git a/source/blender/bmesh/intern/bmesh_operators.c b/source/blender/bmesh/intern/bmesh_operators.c index 97347f841c8..b2d9590dc54 100644 --- a/source/blender/bmesh/intern/bmesh_operators.c +++ b/source/blender/bmesh/intern/bmesh_operators.c @@ -274,7 +274,7 @@ void BMO_slot_copy(BMOperator *source_op, BMOperator *dest_op, const char *src, } if (!dest_slot->data.ghash) { - dest_slot->data.ghash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "bmesh operator 2"); + dest_slot->data.ghash = BLI_ghash_ptr_new("bmesh operator 2"); } BLI_ghashIterator_init(&it, source_slot->data.ghash); @@ -556,7 +556,7 @@ void BMO_slot_map_insert(BMesh *UNUSED(bm), BMOperator *op, const char *slotname memcpy(mapping + 1, data, len); if (!slot->data.ghash) { - slot->data.ghash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "bmesh slot map hash"); + slot->data.ghash = BLI_ghash_ptr_new("bmesh slot map hash"); } BLI_ghash_insert(slot->data.ghash, element, mapping); diff --git a/source/blender/bmesh/intern/bmesh_walkers.c b/source/blender/bmesh/intern/bmesh_walkers.c index ea29c149c1a..79e097a7a7c 100644 --- a/source/blender/bmesh/intern/bmesh_walkers.c +++ b/source/blender/bmesh/intern/bmesh_walkers.c @@ -87,8 +87,8 @@ void BMW_init(BMWalker *walker, BMesh *bm, int type, walker->mask_edge = mask_edge; walker->mask_face = mask_face; - walker->visithash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "bmesh walkers 1"); - walker->secvisithash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "bmesh walkers sec 1"); + walker->visithash = BLI_ghash_ptr_new("bmesh walkers 1"); + walker->secvisithash = BLI_ghash_ptr_new("bmesh walkers sec 1"); if (UNLIKELY(type >= BMW_MAXWALKERS || type < 0)) { fprintf(stderr, @@ -254,6 +254,6 @@ void BMW_reset(BMWalker *walker) walker->depth = 0; BLI_ghash_free(walker->visithash, NULL, NULL); BLI_ghash_free(walker->secvisithash, NULL, NULL); - walker->visithash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "bmesh walkers 1"); - walker->secvisithash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "bmesh walkers sec 1"); + walker->visithash = BLI_ghash_ptr_new("bmesh walkers 1"); + walker->secvisithash = BLI_ghash_ptr_new("bmesh walkers sec 1"); } diff --git a/source/blender/bmesh/intern/bmesh_walkers_impl.c b/source/blender/bmesh/intern/bmesh_walkers_impl.c index 01c269657dc..4ae7b6cc350 100644 --- a/source/blender/bmesh/intern/bmesh_walkers_impl.c +++ b/source/blender/bmesh/intern/bmesh_walkers_impl.c @@ -482,7 +482,7 @@ static void bmw_LoopWalker_begin(BMWalker *walker, void *data) lwalk->lastv = lwalk->startv = BM_edge_other_vert(owalk.cur, lwalk->lastv); BLI_ghash_free(walker->visithash, NULL, NULL); - walker->visithash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "bmesh walkers 2"); + walker->visithash = BLI_ghash_ptr_new("bmesh walkers 2"); BLI_ghash_insert(walker->visithash, owalk.cur, NULL); } @@ -707,11 +707,11 @@ static void bmw_FaceLoopWalker_begin(BMWalker *walker, void *data) lwalk->nocalc = 0; BLI_ghash_free(walker->secvisithash, NULL, NULL); - walker->secvisithash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "bmesh walkers 3"); + walker->secvisithash = BLI_ghash_ptr_new("bmesh walkers 3"); BLI_ghash_insert(walker->visithash, lwalk->l->e, NULL); BLI_ghash_free(walker->visithash, NULL, NULL); - walker->visithash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "bmesh walkers 3"); + walker->visithash = BLI_ghash_ptr_new("bmesh walkers 3"); BLI_ghash_insert(walker->visithash, lwalk->l->f, NULL); } @@ -814,7 +814,7 @@ static void bmw_EdgeringWalker_begin(BMWalker *walker, void *data) } BLI_ghash_free(walker->visithash, NULL, NULL); - walker->visithash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "bmesh walkers 4"); + walker->visithash = BLI_ghash_ptr_new("bmesh walkers 4"); BLI_ghash_insert(walker->visithash, lwalk->l->e, NULL); } diff --git a/source/blender/bmesh/operators/bmo_create.c b/source/blender/bmesh/operators/bmo_create.c index 85aed6141bb..7ef6068247d 100644 --- a/source/blender/bmesh/operators/bmo_create.c +++ b/source/blender/bmesh/operators/bmo_create.c @@ -733,7 +733,7 @@ static EPath *edge_find_shortest_path(BMesh *bm, BMOperator *op, BMEdge *edge, E VertData *vdata, PathBase *pathbase, int group) { BMEdge *e; - GHash *gh = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "createops find shortest path"); + GHash *gh = BLI_ghash_ptr_new("createops find shortest path"); BMVert *v1, *v2; BMVert **verts = NULL; BLI_array_staticdeclare(verts, 1024); diff --git a/source/blender/bmesh/operators/bmo_dupe.c b/source/blender/bmesh/operators/bmo_dupe.c index 212ec33e626..ae001b2baf6 100644 --- a/source/blender/bmesh/operators/bmo_dupe.c +++ b/source/blender/bmesh/operators/bmo_dupe.c @@ -197,8 +197,8 @@ static void BKE_mesh_copy(BMOperator *op, BMesh *source, BMesh *target) GHash *vhash, *ehash; /* initialize pointer hashes */ - vhash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "bmesh dupeops v"); - ehash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "bmesh dupeops e"); + vhash = BLI_ghash_ptr_new("bmesh dupeops v"); + ehash = BLI_ghash_ptr_new("bmesh dupeops e"); /* duplicate flagged vertices */ BM_ITER_MESH (v, &viter, source, BM_VERTS_OF_MESH) { diff --git a/source/blender/bmesh/operators/bmo_hull.c b/source/blender/bmesh/operators/bmo_hull.c index 1cd095f72e4..2a48a531566 100644 --- a/source/blender/bmesh/operators/bmo_hull.c +++ b/source/blender/bmesh/operators/bmo_hull.c @@ -119,16 +119,21 @@ static void expand_boundary_edges(ListBase *edges, BLI_mempool *edge_pool, /*************************** Hull Triangles ***************************/ -static void hull_add_triangle(GHash *hull_triangles, BLI_mempool *pool, +static void hull_add_triangle(BMesh *bm, GHash *hull_triangles, BLI_mempool *pool, BMVert *v1, BMVert *v2, BMVert *v3) { HullTriangle *t; + int i; t = BLI_mempool_calloc(pool); t->v[0] = v1; t->v[1] = v2; t->v[2] = v3; + /* Mark triangles vertices as not interior */ + for (i = 0; i < 3; i++) + BMO_elem_flag_disable(bm, t->v[i], HULL_FLAG_INTERIOR_ELE); + BLI_ghash_insert(hull_triangles, t, NULL); normal_tri_v3(t->no, v1->co, v2->co, v3->co); } @@ -149,41 +154,23 @@ static GHash *hull_triangles_v_outside(GHash *hull_triangles, const BMVert *v) GHash *outside; GHashIterator iter; - outside = BLI_ghash_new(BLI_ghashutil_ptrhash, - BLI_ghashutil_ptrcmp, - "outside"); + outside = BLI_ghash_ptr_new("outside"); GHASH_ITER (iter, hull_triangles) { HullTriangle *t = BLI_ghashIterator_getKey(&iter); - if (hull_point_tri_side(t, v->co) >= 0) + if (hull_point_tri_side(t, v->co) > 0) BLI_ghash_insert(outside, t, NULL); } return outside; } -/* Similar to above, but just get true/false rather than triangles */ -static int hull_test_v_outside(GHash *hull_triangles, const BMVert *v) -{ - GHashIterator iter; - - GHASH_ITER (iter, hull_triangles) { - HullTriangle *t = BLI_ghashIterator_getKey(&iter); - - if (hull_point_tri_side(t, v->co) >= 0) - return TRUE; - } - - return FALSE; -} - - /* For vertex 'v', find which triangles must be deleted to extend the * hull; find the boundary edges of that hole so that it can be filled * with connections to the new vertex, and update the hull_triangles * to delete the marked triangles */ -static void add_point(GHash *hull_triangles, BLI_mempool *hull_pool, +static void add_point(BMesh *bm, GHash *hull_triangles, BLI_mempool *hull_pool, BLI_mempool *edge_pool, GHash *outside, BMVert *v) { ListBase edges = {NULL, NULL}; @@ -192,7 +179,13 @@ static void add_point(GHash *hull_triangles, BLI_mempool *hull_pool, GHASH_ITER (iter, outside) { HullTriangle *t = BLI_ghashIterator_getKey(&iter); + int i; + expand_boundary_edges(&edges, edge_pool, t); + + /* Mark triangle's vertices as interior */ + for (i = 0; i < 3; i++) + BMO_elem_flag_enable(bm, t->v[i], HULL_FLAG_INTERIOR_ELE); /* Delete the triangle */ BLI_ghash_remove(hull_triangles, t, NULL, NULL); @@ -202,7 +195,7 @@ static void add_point(GHash *hull_triangles, BLI_mempool *hull_pool, /* Fill hole boundary with triangles to new point */ for (e = edges.first; e; e = next) { next = e->next; - hull_add_triangle(hull_triangles, hull_pool, e->v[0], e->v[1], v); + hull_add_triangle(bm, hull_triangles, hull_pool, e->v[0], e->v[1], v); BLI_mempool_free(edge_pool, e); } } @@ -303,9 +296,7 @@ static HullFinalEdges *hull_final_edges(GHash *hull_triangles) GHashIterator iter; final_edges = MEM_callocN(sizeof(HullFinalEdges), "HullFinalEdges"); - final_edges->edges = BLI_ghash_new(BLI_ghashutil_ptrhash, - BLI_ghashutil_ptrcmp, - "final edges ghash"); + final_edges->edges = BLI_ghash_ptr_new("final edges ghash"); final_edges->base_pool = BLI_mempool_create(sizeof(ListBase), 128, 128, 0); final_edges->link_pool = BLI_mempool_create(sizeof(LinkData), 128, 128, 0); @@ -352,7 +343,7 @@ static void hull_final_edges_free(HullFinalEdges *final_edges) /************************* Initial Tetrahedron ************************/ -static void hull_add_tetrahedron(GHash *hull_triangles, BLI_mempool *pool, +static void hull_add_tetrahedron(BMesh *bm, GHash *hull_triangles, BLI_mempool *pool, BMVert *tetra[4]) { float center[3]; @@ -379,7 +370,7 @@ static void hull_add_tetrahedron(GHash *hull_triangles, BLI_mempool *pool, if (dot_v3v3(no, d) > 0) SWAP(BMVert *, v1, v3); - hull_add_triangle(hull_triangles, pool, v1, v2, v3); + hull_add_triangle(bm, hull_triangles, pool, v1, v2, v3); } } @@ -540,23 +531,12 @@ static void hull_remove_overlapping(BMesh *bm, GHash *hull_triangles, } static void hull_mark_interior_elements(BMesh *bm, BMOperator *op, - GHash *hull_triangles, HullFinalEdges *final_edges) { - BMVert *v; BMEdge *e; BMFace *f; BMOIter oiter; - /* Check all input vertices again to see if they are actually part - of the hull */ - BMO_ITER (v, &oiter, bm, op, "input", BM_VERT) { - if (!hull_test_v_outside(hull_triangles, v)) { - /* Mark for 'interior_verts' slot */ - BMO_elem_flag_enable(bm, v, HULL_FLAG_INTERIOR_ELE); - } - } - /* Check for interior edges too */ BMO_ITER (e, &oiter, bm, op, "input", BM_EDGE) { if (!hull_final_edges_lookup(final_edges, e->v1, e->v2)) @@ -689,17 +669,20 @@ void bmo_convex_hull_exec(BMesh *bm, BMOperator *op) } /* Tag input elements */ - BMO_ITER (ele, &oiter, bm, op, "input", BM_ALL) + BMO_ITER (ele, &oiter, bm, op, "input", BM_ALL) { BMO_elem_flag_enable(bm, ele, HULL_FLAG_INPUT); + + /* Mark all vertices as interior to begin with */ + if (ele->head.htype == BM_VERT) + BMO_elem_flag_enable(bm, ele, HULL_FLAG_INTERIOR_ELE); + } edge_pool = BLI_mempool_create(sizeof(HullBoundaryEdge), 128, 128, 0); hull_pool = BLI_mempool_create(sizeof(HullTriangle), 128, 128, 0); - hull_triangles = BLI_ghash_new(BLI_ghashutil_ptrhash, - BLI_ghashutil_ptrcmp, - "hull_triangles"); + hull_triangles = BLI_ghash_ptr_new("hull_triangles"); /* Add tetrahedron triangles */ - hull_add_tetrahedron(hull_triangles, hull_pool, tetra); + hull_add_tetrahedron(bm, hull_triangles, hull_pool, tetra); /* Expand hull to cover new vertices outside the existing hull */ BMO_ITER (v, &oiter, bm, op, "input", BM_VERT) { @@ -707,7 +690,7 @@ void bmo_convex_hull_exec(BMesh *bm, BMOperator *op) GHash *outside = hull_triangles_v_outside(hull_triangles, v); if (BLI_ghash_size(outside)) { /* Expand hull and delete interior triangles */ - add_point(hull_triangles, hull_pool, edge_pool, outside, v); + add_point(bm, hull_triangles, hull_pool, edge_pool, outside, v); } BLI_ghash_free(outside, NULL, NULL); } @@ -716,7 +699,7 @@ void bmo_convex_hull_exec(BMesh *bm, BMOperator *op) BLI_mempool_destroy(edge_pool); final_edges = hull_final_edges(hull_triangles); - hull_mark_interior_elements(bm, op, hull_triangles, final_edges); + hull_mark_interior_elements(bm, op, final_edges); /* Remove hull triangles covered by an existing face */ if (BMO_slot_bool_get(op, "use_existing_faces")) { diff --git a/source/blender/bmesh/tools/BME_bevel.c b/source/blender/bmesh/tools/BME_bevel.c index df031a50d54..101614d609c 100644 --- a/source/blender/bmesh/tools/BME_bevel.c +++ b/source/blender/bmesh/tools/BME_bevel.c @@ -72,7 +72,7 @@ BME_TransData_Head *BME_init_transdata(int bufsize) BME_TransData_Head *td; td = MEM_callocN(sizeof(BME_TransData_Head), "BM transdata header"); - td->gh = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "BME_init_transdata gh"); + td->gh = BLI_ghash_ptr_new("BME_init_transdata gh"); td->ma = BLI_memarena_new(bufsize, "BME_TransData arena"); BLI_memarena_use_calloc(td->ma); diff --git a/source/blender/editors/animation/anim_filter.c b/source/blender/editors/animation/anim_filter.c index 2729396cb4a..fcf424e34dc 100644 --- a/source/blender/editors/animation/anim_filter.c +++ b/source/blender/editors/animation/anim_filter.c @@ -2223,7 +2223,7 @@ static size_t animdata_filter_remove_duplis(ListBase *anim_data) /* build new hashtable to efficiently store and retrieve which entries have been * encountered already while searching */ - gh = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "animdata_filter_duplis_remove gh"); + gh = BLI_ghash_ptr_new("animdata_filter_duplis_remove gh"); /* loop through items, removing them from the list if a similar item occurs already */ for (ale = anim_data->first; ale; ale = next) { diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c index 8e2dfb72703..7ce2988b067 100644 --- a/source/blender/editors/armature/editarmature.c +++ b/source/blender/editors/armature/editarmature.c @@ -5945,7 +5945,7 @@ void generateSkeletonFromReebGraph(Scene *scene, ReebGraph *rg) ED_armature_to_edit(obedit); - arcBoneMap = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "SkeletonFromReebGraph gh"); + arcBoneMap = BLI_ghash_ptr_new("SkeletonFromReebGraph gh"); BLI_markdownSymmetry((BGraph *)rg, rg->nodes.first, scene->toolsettings->skgen_symmetry_limit); diff --git a/source/blender/editors/armature/editarmature_retarget.c b/source/blender/editors/armature/editarmature_retarget.c index 566dbc901b8..80f8c61694c 100644 --- a/source/blender/editors/armature/editarmature_retarget.c +++ b/source/blender/editors/armature/editarmature_retarget.c @@ -298,8 +298,8 @@ static RigGraph *newRigGraph(void) rg->head = NULL; - rg->bones_map = BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp, "newRigGraph bones gh"); - rg->controls_map = BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp, "newRigGraph cont gh"); + rg->bones_map = BLI_ghash_str_new("newRigGraph bones gh"); + rg->controls_map = BLI_ghash_str_new("newRigGraph cont gh"); rg->free_arc = RIG_freeRigArc; rg->free_node = NULL; @@ -532,7 +532,7 @@ static RigGraph *cloneRigGraph(RigGraph *src, ListBase *editbones, Object *ob, c RigControl *ctrl; RigGraph *rg; - ptr_hash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "cloneRigGraph gh"); + ptr_hash = BLI_ghash_ptr_new("cloneRigGraph gh"); rg = newRigGraph(); diff --git a/source/blender/editors/armature/editarmature_sketch.c b/source/blender/editors/armature/editarmature_sketch.c index 2201bcf7224..06ecf76ba3e 100644 --- a/source/blender/editors/armature/editarmature_sketch.c +++ b/source/blender/editors/armature/editarmature_sketch.c @@ -165,7 +165,7 @@ void BIF_makeListTemplates(const bContext *C) BLI_ghash_free(TEMPLATES_HASH, NULL, NULL); } - TEMPLATES_HASH = BLI_ghash_new(BLI_ghashutil_inthash, BLI_ghashutil_intcmp, "makeListTemplates gh"); + TEMPLATES_HASH = BLI_ghash_int_new("makeListTemplates gh"); TEMPLATES_CURRENT = 0; for (base = FIRSTBASE; base; base = base->next) { diff --git a/source/blender/editors/armature/reeb.c b/source/blender/editors/armature/reeb.c index 2564683ddd2..316c4699c0b 100644 --- a/source/blender/editors/armature/reeb.c +++ b/source/blender/editors/armature/reeb.c @@ -354,7 +354,7 @@ static ReebArc *copyArc(ReebGraph *rg, ReebArc *arc) memcpy(cp_arc->buckets, arc->buckets, sizeof(EmbedBucket) * cp_arc->bcount); /* copy faces map */ - cp_arc->faces = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "copyArc gh"); + cp_arc->faces = BLI_ghash_ptr_new("copyArc gh"); mergeArcFaces(rg, cp_arc, arc); /* find corresponding head and tail */ @@ -2295,7 +2295,7 @@ static ReebEdge *createArc(ReebGraph *rg, ReebNode *node1, ReebNode *node2) arc->flag = 0; // clear flag on init arc->symmetry_level = 0; - arc->faces = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "createArc gh"); + arc->faces = BLI_ghash_ptr_new("createArc gh"); if (node1->weight <= node2->weight) { v1 = node1; diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index e2824ee35cc..7afba049232 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -311,7 +311,7 @@ static void init_editNurb_keyIndex(EditNurb *editnurb, ListBase *origBase) if (editnurb->keyindex) return; - gh = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "editNurb keyIndex"); + gh = BLI_ghash_ptr_new("editNurb keyIndex"); while (orignu) { if (orignu->bezt) { @@ -667,7 +667,7 @@ static GHash *dupli_keyIndexHash(GHash *keyindex) GHash *gh; GHashIterator *hashIter; - gh = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "dupli_keyIndex gh"); + gh = BLI_ghash_ptr_new("dupli_keyIndex gh"); for (hashIter = BLI_ghashIterator_new(keyindex); !BLI_ghashIterator_isDone(hashIter); diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c index 6d2ac388374..f2a43580fd8 100644 --- a/source/blender/editors/interface/interface_ops.c +++ b/source/blender/editors/interface/interface_ops.c @@ -589,9 +589,7 @@ static void ui_editsource_active_but_set(uiBut *but) ui_editsource_info = MEM_callocN(sizeof(uiEditSourceStore), __func__); memcpy(&ui_editsource_info->but_orig, but, sizeof(uiBut)); - ui_editsource_info->hash = BLI_ghash_new(BLI_ghashutil_ptrhash, - BLI_ghashutil_ptrcmp, - __func__); + ui_editsource_info->hash = BLI_ghash_ptr_new(__func__); } static void ui_editsource_active_but_clear(void) diff --git a/source/blender/editors/mesh/editmesh_knife.c b/source/blender/editors/mesh/editmesh_knife.c index d49b77c7005..a9ec893adb7 100644 --- a/source/blender/editors/mesh/editmesh_knife.c +++ b/source/blender/editors/mesh/editmesh_knife.c @@ -2829,9 +2829,9 @@ static int knifetool_init(bContext *C, wmOperator *op, int UNUSED(do_cut)) kcd->kverts = BLI_mempool_create(sizeof(KnifeVert), 1, 512, BLI_MEMPOOL_ALLOW_ITER); kcd->kedges = BLI_mempool_create(sizeof(KnifeEdge), 1, 512, BLI_MEMPOOL_ALLOW_ITER); - kcd->origedgemap = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "knife origedgemap"); - kcd->origvertmap = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "knife origvertmap"); - kcd->kedgefacemap = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "knife origvertmap"); + kcd->origedgemap = BLI_ghash_ptr_new("knife origedgemap"); + kcd->origvertmap = BLI_ghash_ptr_new("knife origvertmap"); + kcd->kedgefacemap = BLI_ghash_ptr_new("knife origvertmap"); /* cut all the way through the mesh if use_occlude_geometry button not pushed */ kcd->cut_through = !RNA_boolean_get(op->ptr, "use_occlude_geometry"); diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index 9be71218da0..7f746ed9ef5 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -2700,7 +2700,7 @@ static int edbm_knife_cut_exec(bContext *C, wmOperator *op) } /* the floating point coordinates of verts in screen space will be stored in a hash table according to the vertices pointer */ - gh = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "knife cut exec"); + gh = BLI_ghash_ptr_new("knife cut exec"); for (bv = BM_iter_new(&iter, bm, BM_VERTS_OF_MESH, NULL); bv; bv = BM_iter_step(&iter)) { scr = MEM_mallocN(sizeof(float) * 2, "Vertex Screen Coordinates"); copy_v3_v3(co, bv->co); diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index 466338a736f..69aae5c4f06 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -1067,8 +1067,8 @@ static void make_object_duplilist_real(bContext *C, Scene *scene, Base *base, lb = object_duplilist(scene, base->object); if (use_hierarchy || use_base_parent) { - dupli_gh = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "make_object_duplilist_real dupli_gh"); - parent_gh = BLI_ghash_new(BLI_ghashutil_pairhash, BLI_ghashutil_paircmp, "make_object_duplilist_real parent_gh"); + dupli_gh = BLI_ghash_ptr_new("make_object_duplilist_real dupli_gh"); + parent_gh = BLI_ghash_pair_new("make_object_duplilist_real parent_gh"); } for (dob = lb->first; dob; dob = dob->next) { diff --git a/source/blender/editors/render/render_update.c b/source/blender/editors/render/render_update.c index 48c35873304..08ccf37265b 100644 --- a/source/blender/editors/render/render_update.c +++ b/source/blender/editors/render/render_update.c @@ -127,7 +127,7 @@ void ED_render_engine_area_exit(ScrArea *sa) for (ar = sa->regionbase.first; ar; ar = ar->next) { RegionView3D *rv3d; - if (ar->regiontype != RGN_TYPE_WINDOW) + if (ar->regiontype != RGN_TYPE_WINDOW || !(ar->regiondata)) continue; rv3d = ar->regiondata; diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c index c681f8ddb75..ebc255f4e43 100644 --- a/source/blender/editors/sculpt_paint/paint_cursor.c +++ b/source/blender/editors/sculpt_paint/paint_cursor.c @@ -86,7 +86,7 @@ static int same_snap(Snapshot *snap, Brush *brush, ViewContext *vc) mtex->rot == snap->rot) && /* make brush smaller shouldn't cause a resample */ - ((mtex->brush_map_mode == MTEX_MAP_MODE_FIXED && + ((mtex->brush_map_mode == MTEX_MAP_MODE_VIEW && (BKE_brush_size_get(vc->scene, brush) <= snap->BKE_brush_size_get)) || (BKE_brush_size_get(vc->scene, brush) == snap->BKE_brush_size_get)) && @@ -154,7 +154,7 @@ static int load_tex(Sculpt *sd, Brush *br, ViewContext *vc) make_snap(&snap, br, vc); - if (br->mtex.brush_map_mode == MTEX_MAP_MODE_FIXED) { + if (br->mtex.brush_map_mode == MTEX_MAP_MODE_VIEW) { int s = BKE_brush_size_get(vc->scene, br); int r = 1; @@ -239,7 +239,7 @@ static int load_tex(Sculpt *sd, Brush *br, ViewContext *vc) avg += br->texture_sample_bias; - if (br->mtex.brush_map_mode == MTEX_MAP_MODE_FIXED) + if (br->mtex.brush_map_mode == MTEX_MAP_MODE_VIEW) avg *= BKE_brush_curve_strength(br, len, 1); /* Falloff curve */ buffer[index] = 255 - (GLubyte)(255 * avg); @@ -278,7 +278,7 @@ static int load_tex(Sculpt *sd, Brush *br, ViewContext *vc) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - if (br->mtex.brush_map_mode == MTEX_MAP_MODE_FIXED) { + if (br->mtex.brush_map_mode == MTEX_MAP_MODE_VIEW) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); } @@ -376,7 +376,7 @@ static void paint_draw_alpha_overlay(Sculpt *sd, Brush *brush, /* check for overlay mode */ if (!(brush->flag & BRUSH_TEXTURE_OVERLAY) || - !(ELEM(brush->mtex.brush_map_mode, MTEX_MAP_MODE_FIXED, MTEX_MAP_MODE_TILED))) + !(ELEM(brush->mtex.brush_map_mode, MTEX_MAP_MODE_VIEW, MTEX_MAP_MODE_TILED))) { return; } @@ -405,7 +405,7 @@ static void paint_draw_alpha_overlay(Sculpt *sd, Brush *brush, glPushMatrix(); glLoadIdentity(); - if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_FIXED) { + if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_VIEW) { /* brush rotation */ glTranslatef(0.5, 0.5, 0); glRotatef((double)RAD2DEGF((brush->flag & BRUSH_RAKE) ? diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 3b74ae54810..d544183ced8 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -2079,7 +2079,7 @@ static char *wpaint_make_validmap(Object *ob) return NULL; } - gh = BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp, "wpaint_make_validmap gh"); + gh = BLI_ghash_str_new("wpaint_make_validmap gh"); /* add all names to a hash table */ for (dg = ob->defbase.first; dg; dg = dg->next) { diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 02c0acfc367..a124afddc8e 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -247,7 +247,17 @@ typedef struct StrokeCache { int mirror_symmetry_pass; /* the symmetry pass we are currently on between 0 and 7*/ float true_view_normal[3]; float view_normal[3]; - float last_area_normal[3]; + + /* sculpt_normal gets calculated by calc_sculpt_normal(), then the + sculpt_normal_symm gets updated quickly with the usual symmetry + transforms */ + float sculpt_normal[3]; + float sculpt_normal_symm[3]; + + /* Used for wrap texture mode, local_mat gets calculated by + calc_brush_local_mat() and used in tex_strength(). */ + float brush_local_mat[4][4]; + float last_center[3]; int radial_symmetry_pass; float symm_rot_mat[4][4]; @@ -537,7 +547,7 @@ static float integrate_overlap(Brush *br) } /* Uses symm to selectively flip any axis of a coordinate. */ -static void flip_coord(float out[3], float in[3], const char symm) +static void flip_v3_v3(float out[3], const float in[3], const char symm) { if (symm & SCULPT_SYMM_X) out[0] = -in[0]; @@ -553,13 +563,18 @@ static void flip_coord(float out[3], float in[3], const char symm) out[2] = in[2]; } +static void flip_v3(float v[3], const char symm) +{ + flip_v3_v3(v, v, symm); +} + static float calc_overlap(StrokeCache *cache, const char symm, const char axis, const float angle) { float mirror[3]; float distsq; - /* flip_coord(mirror, cache->traced_location, symm); */ - flip_coord(mirror, cache->true_location, symm); + /* flip_v3_v3(mirror, cache->traced_location, symm); */ + flip_v3_v3(mirror, cache->true_location, symm); if (axis != 0) { float mat[4][4] = MAT4_UNITY; @@ -745,15 +760,16 @@ static float tex_strength(SculptSession *ss, Brush *br, float point[3], * position in order to project it. This insures that the * brush texture will be oriented correctly. */ - flip_coord(symm_point, point, ss->cache->mirror_symmetry_pass); + flip_v3_v3(symm_point, point, ss->cache->mirror_symmetry_pass); if (ss->cache->radial_symmetry_pass) mul_m4_v3(ss->cache->symm_rot_mat_inv, symm_point); ED_view3d_project_float_v2(ss->cache->vc->ar, symm_point, point_2d, ss->cache->projection_mat); - /* if fixed mode, keep coordinates relative to mouse */ - if (mtex->brush_map_mode == MTEX_MAP_MODE_FIXED) { + if (mtex->brush_map_mode == MTEX_MAP_MODE_VIEW) { + /* keep coordinates relative to mouse */ + rotation += ss->cache->special_rotation; point_2d[0] -= ss->cache->tex_mouse[0]; @@ -765,8 +781,8 @@ static float tex_strength(SculptSession *ss, Brush *br, float point[3], x = point_2d[0] + ss->cache->vc->ar->winrct.xmin; y = point_2d[1] + ss->cache->vc->ar->winrct.ymin; } - else { /* else (mtex->brush_map_mode == MTEX_MAP_MODE_TILED) */ - /* leave the coordinates relative to the screen */ + else if (mtex->brush_map_mode == MTEX_MAP_MODE_TILED) { + /* leave the coordinates relative to the screen */ /* use unadjusted size for tiled mode */ radius = BKE_brush_size_get(ss->cache->vc->scene, br); @@ -774,17 +790,31 @@ static float tex_strength(SculptSession *ss, Brush *br, float point[3], x = point_2d[0]; y = point_2d[1]; } + else if (mtex->brush_map_mode == MTEX_MAP_MODE_AREA) { + /* Similar to fixed mode, but projects from brush angle + rather than view direction */ - x /= ss->cache->vc->ar->winx; - y /= ss->cache->vc->ar->winy; + /* Rotation is handled by the brush_local_mat */ + rotation = 0; - if (mtex->brush_map_mode == MTEX_MAP_MODE_TILED) { - x -= 0.5f; - y -= 0.5f; + mul_m4_v3(ss->cache->brush_local_mat, symm_point); + + x = symm_point[0]; + y = symm_point[1]; } + + if (mtex->brush_map_mode != MTEX_MAP_MODE_AREA) { + x /= ss->cache->vc->ar->winx; + y /= ss->cache->vc->ar->winy; + + if (mtex->brush_map_mode == MTEX_MAP_MODE_TILED) { + x -= 0.5f; + y -= 0.5f; + } - x *= ss->cache->vc->ar->winx / radius; - y *= ss->cache->vc->ar->winy / radius; + x *= ss->cache->vc->ar->winx / radius; + y *= ss->cache->vc->ar->winy / radius; + } /* it is probably worth optimizing for those cases where * the texture is not rotated by skipping the calls to @@ -882,9 +912,13 @@ static void add_norm_if(float view_vec[3], float out[3], float out_flip[3], floa static void calc_area_normal(Sculpt *sd, Object *ob, float an[3], PBVHNode **nodes, int totnode) { SculptSession *ss = ob->sculpt; - int n; - float out_flip[3] = {0.0f, 0.0f, 0.0f}; + int n, original; + + /* Grab brush requires to test on original data (see r33888 and + bug #25371) */ + original = (paint_brush(&sd->paint)->sculpt_tool == SCULPT_TOOL_GRAB ? + TRUE : ss->cache->original); (void)sd; /* unused w/o openmp */ @@ -901,7 +935,7 @@ static void calc_area_normal(Sculpt *sd, Object *ob, float an[3], PBVHNode **nod unode = sculpt_undo_push_node(ob, nodes[n], SCULPT_UNDO_COORDS); sculpt_brush_test_init(ss, &test); - if (ss->cache->original) { + if (original) { BLI_pbvh_vertex_iter_begin(ss->pbvh, nodes[n], vd, PBVH_ITER_UNIQUE) { if (sculpt_brush_test_fast(&test, unode->co[vd.i])) { @@ -944,56 +978,161 @@ static void calc_area_normal(Sculpt *sd, Object *ob, float an[3], PBVHNode **nod normalize_v3(an); } -/* This initializes the faces to be moved for this sculpt for draw/layer/flatten; then it - * finds average normal for all active vertices - note that this is called once for each mirroring direction */ -static void calc_sculpt_normal(Sculpt *sd, Object *ob, float an[3], PBVHNode **nodes, int totnode) +/* Calculate primary direction of movement for many brushes */ +static void calc_sculpt_normal(Sculpt *sd, Object *ob, + PBVHNode **nodes, int totnode, + float an[3]) { - SculptSession *ss = ob->sculpt; - Brush *brush = paint_brush(&sd->paint); + const Brush *brush = paint_brush(&sd->paint); + const SculptSession *ss = ob->sculpt; - if (ss->cache->mirror_symmetry_pass == 0 && - ss->cache->radial_symmetry_pass == 0 && - (ss->cache->first_time || !(brush->flag & BRUSH_ORIGINAL_NORMAL))) + switch (brush->sculpt_plane) { + case SCULPT_DISP_DIR_VIEW: + ED_view3d_global_to_vector(ss->cache->vc->rv3d, + ss->cache->vc->rv3d->twmat[3], + an); + break; + + case SCULPT_DISP_DIR_X: + an[1] = 0.0; + an[2] = 0.0; + an[0] = 1.0; + break; + + case SCULPT_DISP_DIR_Y: + an[0] = 0.0; + an[2] = 0.0; + an[1] = 1.0; + break; + + case SCULPT_DISP_DIR_Z: + an[0] = 0.0; + an[1] = 0.0; + an[2] = 1.0; + break; + + case SCULPT_DISP_DIR_AREA: + calc_area_normal(sd, ob, an, nodes, totnode); + + default: + break; + } +} + +static void update_sculpt_normal(Sculpt *sd, Object *ob, + PBVHNode **nodes, int totnode) +{ + const Brush *brush = paint_brush(&sd->paint); + StrokeCache *cache = ob->sculpt->cache; + + if (cache->mirror_symmetry_pass == 0 && + cache->radial_symmetry_pass == 0 && + (cache->first_time || !(brush->flag & BRUSH_ORIGINAL_NORMAL))) { - switch (brush->sculpt_plane) { - case SCULPT_DISP_DIR_VIEW: - ED_view3d_global_to_vector(ss->cache->vc->rv3d, ss->cache->vc->rv3d->twmat[3], an); - break; - - case SCULPT_DISP_DIR_X: - an[1] = 0.0; - an[2] = 0.0; - an[0] = 1.0; - break; - - case SCULPT_DISP_DIR_Y: - an[0] = 0.0; - an[2] = 0.0; - an[1] = 1.0; - break; - - case SCULPT_DISP_DIR_Z: - an[0] = 0.0; - an[1] = 0.0; - an[2] = 1.0; - break; - - case SCULPT_DISP_DIR_AREA: - calc_area_normal(sd, ob, an, nodes, totnode); - - default: - break; - } - - copy_v3_v3(ss->cache->last_area_normal, an); + calc_sculpt_normal(sd, ob, nodes, totnode, cache->sculpt_normal); + copy_v3_v3(cache->sculpt_normal_symm, cache->sculpt_normal); } else { - copy_v3_v3(an, ss->cache->last_area_normal); - flip_coord(an, an, ss->cache->mirror_symmetry_pass); - mul_m4_v3(ss->cache->symm_rot_mat, an); + copy_v3_v3(cache->sculpt_normal_symm, cache->sculpt_normal); + flip_v3(cache->sculpt_normal_symm, cache->mirror_symmetry_pass); + mul_m4_v3(cache->symm_rot_mat, cache->sculpt_normal_symm); } } +static void calc_local_y(ViewContext *vc, const float center[3], float y[3]) +{ + Object *ob = vc->obact; + float loc[3], mval_f[2] = {0.0f, 1.0f}; + + mul_v3_m4v3(loc, ob->imat, center); + initgrabz(vc->rv3d, loc[0], loc[1], loc[2]); + + ED_view3d_win_to_delta(vc->ar, mval_f, y); + normalize_v3(y); + + add_v3_v3(y, ob->loc); + mul_m4_v3(ob->imat, y); +} + +static void calc_brush_local_mat(const Brush *brush, Object *ob, + float local_mat[4][4]) +{ + const StrokeCache *cache = ob->sculpt->cache; + float tmat[4][4]; + float mat[4][4]; + float scale[4][4]; + float angle, v[3]; + float up[3]; + + /* Ensure ob->imat is up to date */ + invert_m4_m4(ob->imat, ob->obmat); + + /* Initialize last column of matrix */ + mat[0][3] = 0; + mat[1][3] = 0; + mat[2][3] = 0; + mat[3][3] = 1; + + /* Get view's up vector in object-space */ + calc_local_y(cache->vc, cache->location, up); + + /* Calculate the X axis of the local matrix */ + cross_v3_v3v3(v, up, cache->sculpt_normal); + /* Apply rotation (user angle, rake, etc.) to X axis */ + angle = brush->mtex.rot - cache->special_rotation; + rotate_v3_v3v3fl(mat[0], v, cache->sculpt_normal, angle); + + /* Get other axes */ + cross_v3_v3v3(mat[1], cache->sculpt_normal, mat[0]); + copy_v3_v3(mat[2], cache->sculpt_normal); + + /* Set location */ + copy_v3_v3(mat[3], cache->location); + + /* Scale by brush radius */ + normalize_m4(mat); + scale_m4_fl(scale, cache->radius); + mult_m4_m4m4(tmat, mat, scale); + + /* Return inverse (for converting from modelspace coords to local + area coords) */ + invert_m4_m4(local_mat, tmat); +} + +static void update_brush_local_mat(Sculpt *sd, Object *ob) +{ + StrokeCache *cache = ob->sculpt->cache; + + if (cache->mirror_symmetry_pass == 0 && + cache->radial_symmetry_pass == 0) + { + calc_brush_local_mat(paint_brush(&sd->paint), ob, + cache->brush_local_mat); + } +} + +/* Test whether the StrokeCache.sculpt_normal needs update in + do_brush_action() */ +static int brush_needs_sculpt_normal(const Brush *brush) +{ + return ((ELEM(brush->sculpt_tool, + SCULPT_TOOL_GRAB, + SCULPT_TOOL_SNAKE_HOOK) && + ((brush->normal_weight > 0) || + (brush->flag & BRUSH_FRONTFACE))) || + + ELEM7(brush->sculpt_tool, + SCULPT_TOOL_BLOB, + SCULPT_TOOL_CREASE, + SCULPT_TOOL_DRAW, + SCULPT_TOOL_LAYER, + SCULPT_TOOL_NUDGE, + SCULPT_TOOL_ROTATE, + SCULPT_TOOL_THUMB) || + + (brush->mtex.brush_map_mode == MTEX_MAP_MODE_AREA)); +} + /* For the smooth brush, uses the neighboring vertices around vert to calculate * a smoothed location for vert. Skips corner vertices (used by only one * polygon.) */ @@ -1356,14 +1495,12 @@ static void do_draw_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) { SculptSession *ss = ob->sculpt; Brush *brush = paint_brush(&sd->paint); - float offset[3], area_normal[3]; + float offset[3]; float bstrength = ss->cache->bstrength; int n; - calc_sculpt_normal(sd, ob, area_normal, nodes, totnode); - /* offset with as much as possible factored in already */ - mul_v3_v3fl(offset, area_normal, ss->cache->radius); + mul_v3_v3fl(offset, ss->cache->sculpt_normal_symm, ss->cache->radius); mul_v3_v3(offset, ss->cache->scale); mul_v3_fl(offset, bstrength); @@ -1383,7 +1520,8 @@ static void do_draw_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) if (sculpt_brush_test(&test, vd.co)) { /* offset vertex */ float fade = tex_strength(ss, brush, vd.co, test.dist, - area_normal, vd.no, vd.fno, *vd.mask); + ss->cache->sculpt_normal_symm, vd.no, + vd.fno, *vd.mask); mul_v3_v3fl(proxy[vd.i], offset, fade); @@ -1400,16 +1538,14 @@ static void do_crease_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod SculptSession *ss = ob->sculpt; const Scene *scene = ss->cache->vc->scene; Brush *brush = paint_brush(&sd->paint); - float offset[3], area_normal[3]; + float offset[3]; float bstrength = ss->cache->bstrength; float flippedbstrength, crease_correction; float brush_alpha; int n; - calc_sculpt_normal(sd, ob, area_normal, nodes, totnode); - /* offset with as much as possible factored in already */ - mul_v3_v3fl(offset, area_normal, ss->cache->radius); + mul_v3_v3fl(offset, ss->cache->sculpt_normal_symm, ss->cache->radius); mul_v3_v3(offset, ss->cache->scale); mul_v3_fl(offset, bstrength); @@ -1440,7 +1576,8 @@ static void do_crease_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod if (sculpt_brush_test(&test, vd.co)) { /* offset vertex */ const float fade = tex_strength(ss, brush, vd.co, test.dist, - area_normal, vd.no, vd.fno, *vd.mask); + ss->cache->sculpt_normal_symm, + vd.no, vd.fno, *vd.mask); float val1[3]; float val2[3]; @@ -1502,26 +1639,18 @@ static void do_grab_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) SculptSession *ss = ob->sculpt; Brush *brush = paint_brush(&sd->paint); float bstrength = ss->cache->bstrength; - float grab_delta[3], an[3]; + float grab_delta[3]; int n; float len; - if (brush->normal_weight > 0 || brush->flag & BRUSH_FRONTFACE) { - int cache = 1; - /* grab brush requires to test on original data */ - SWAP(int, ss->cache->original, cache); - calc_sculpt_normal(sd, ob, an, nodes, totnode); - SWAP(int, ss->cache->original, cache); - } - copy_v3_v3(grab_delta, ss->cache->grab_delta_symmetry); len = len_v3(grab_delta); if (brush->normal_weight > 0) { - mul_v3_fl(an, len * brush->normal_weight); + mul_v3_fl(ss->cache->sculpt_normal_symm, len * brush->normal_weight); mul_v3_fl(grab_delta, 1.0f - brush->normal_weight); - add_v3_v3(grab_delta, an); + add_v3_v3(grab_delta, ss->cache->sculpt_normal_symm); } #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPENMP) @@ -1545,7 +1674,7 @@ static void do_grab_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) { if (sculpt_brush_test(&test, origco[vd.i])) { const float fade = bstrength * tex_strength(ss, brush, origco[vd.i], test.dist, - an, origno[vd.i], NULL, *vd.mask); + ss->cache->sculpt_normal_symm, origno[vd.i], NULL, *vd.mask); mul_v3_v3fl(proxy[vd.i], grab_delta, fade); @@ -1563,16 +1692,13 @@ static void do_nudge_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode Brush *brush = paint_brush(&sd->paint); float bstrength = ss->cache->bstrength; float grab_delta[3]; - int n; - float an[3]; float tmp[3], cono[3]; + int n; copy_v3_v3(grab_delta, ss->cache->grab_delta_symmetry); - calc_sculpt_normal(sd, ob, an, nodes, totnode); - - cross_v3_v3v3(tmp, an, grab_delta); - cross_v3_v3v3(cono, tmp, an); + cross_v3_v3v3(tmp, ss->cache->sculpt_normal_symm, grab_delta); + cross_v3_v3v3(cono, tmp, ss->cache->sculpt_normal_symm); #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPENMP) for (n = 0; n < totnode; n++) { @@ -1588,7 +1714,8 @@ static void do_nudge_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode { if (sculpt_brush_test(&test, vd.co)) { const float fade = bstrength * tex_strength(ss, brush, vd.co, test.dist, - an, vd.no, vd.fno, *vd.mask); + ss->cache->sculpt_normal_symm, + vd.no, vd.fno, *vd.mask); mul_v3_v3fl(proxy[vd.i], cono, fade); @@ -1605,13 +1732,10 @@ static void do_snake_hook_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int to SculptSession *ss = ob->sculpt; Brush *brush = paint_brush(&sd->paint); float bstrength = ss->cache->bstrength; - float grab_delta[3], an[3]; + float grab_delta[3]; int n; float len; - if (brush->normal_weight > 0 || brush->flag & BRUSH_FRONTFACE) - calc_sculpt_normal(sd, ob, an, nodes, totnode); - copy_v3_v3(grab_delta, ss->cache->grab_delta_symmetry); len = len_v3(grab_delta); @@ -1620,9 +1744,9 @@ static void do_snake_hook_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int to negate_v3(grab_delta); if (brush->normal_weight > 0) { - mul_v3_fl(an, len * brush->normal_weight); + mul_v3_fl(ss->cache->sculpt_normal_symm, len * brush->normal_weight); mul_v3_fl(grab_delta, 1.0f - brush->normal_weight); - add_v3_v3(grab_delta, an); + add_v3_v3(grab_delta, ss->cache->sculpt_normal_symm); } #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPENMP) @@ -1639,7 +1763,8 @@ static void do_snake_hook_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int to { if (sculpt_brush_test(&test, vd.co)) { const float fade = bstrength * tex_strength(ss, brush, vd.co, test.dist, - an, vd.no, vd.fno, *vd.mask); + ss->cache->sculpt_normal_symm, + vd.no, vd.fno, *vd.mask); mul_v3_v3fl(proxy[vd.i], grab_delta, fade); @@ -1657,16 +1782,13 @@ static void do_thumb_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode Brush *brush = paint_brush(&sd->paint); float bstrength = ss->cache->bstrength; float grab_delta[3]; - int n; - float an[3]; float tmp[3], cono[3]; + int n; copy_v3_v3(grab_delta, ss->cache->grab_delta_symmetry); - calc_sculpt_normal(sd, ob, an, nodes, totnode); - - cross_v3_v3v3(tmp, an, grab_delta); - cross_v3_v3v3(cono, tmp, an); + cross_v3_v3v3(tmp, ss->cache->sculpt_normal_symm, grab_delta); + cross_v3_v3v3(cono, tmp, ss->cache->sculpt_normal_symm); #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPENMP) for (n = 0; n < totnode; n++) { @@ -1689,7 +1811,8 @@ static void do_thumb_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode { if (sculpt_brush_test(&test, origco[vd.i])) { const float fade = bstrength * tex_strength(ss, brush, origco[vd.i], test.dist, - an, origno[vd.i], NULL, *vd.mask); + ss->cache->sculpt_normal_symm, + origno[vd.i], NULL, *vd.mask); mul_v3_v3fl(proxy[vd.i], cono, fade); @@ -1706,20 +1829,17 @@ static void do_rotate_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod SculptSession *ss = ob->sculpt; Brush *brush = paint_brush(&sd->paint); float bstrength = ss->cache->bstrength; - float an[3]; int n; float m[4][4], rot[4][4], lmat[4][4], ilmat[4][4]; static const int flip[8] = { 1, -1, -1, 1, -1, 1, 1, -1 }; float angle = ss->cache->vertex_rotation * flip[ss->cache->mirror_symmetry_pass]; - calc_sculpt_normal(sd, ob, an, nodes, totnode); - unit_m4(m); unit_m4(lmat); copy_v3_v3(lmat[3], ss->cache->location); invert_m4_m4(ilmat, lmat); - axis_angle_to_mat4(rot, an, angle); + axis_angle_to_mat4(rot, ss->cache->sculpt_normal_symm, angle); mul_serie_m4(m, lmat, rot, ilmat, NULL, NULL, NULL, NULL, NULL); @@ -1744,7 +1864,8 @@ static void do_rotate_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod { if (sculpt_brush_test(&test, origco[vd.i])) { const float fade = bstrength * tex_strength(ss, brush, origco[vd.i], test.dist, - an, origno[vd.i], NULL, *vd.mask); + ss->cache->sculpt_normal_symm, + origno[vd.i], NULL, *vd.mask); mul_v3_m4v3(proxy[vd.i], m, origco[vd.i]); sub_v3_v3(proxy[vd.i], origco[vd.i]); @@ -1770,8 +1891,6 @@ static void do_layer_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode if (bstrength < 0) lim = -lim; - calc_sculpt_normal(sd, ob, area_normal, nodes, totnode); - mul_v3_v3v3(offset, ss->cache->scale, area_normal); #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPENMP) @@ -2069,23 +2188,23 @@ static void calc_sculpt_plane(Sculpt *sd, Object *ob, PBVHNode **nodes, int totn calc_flatten_center(sd, ob, nodes, totnode, fc); /* for area normal */ - copy_v3_v3(ss->cache->last_area_normal, an); + copy_v3_v3(ss->cache->sculpt_normal, an); /* for flatten center */ copy_v3_v3(ss->cache->last_center, fc); } else { /* for area normal */ - copy_v3_v3(an, ss->cache->last_area_normal); + copy_v3_v3(an, ss->cache->sculpt_normal); /* for flatten center */ copy_v3_v3(fc, ss->cache->last_center); /* for area normal */ - flip_coord(an, an, ss->cache->mirror_symmetry_pass); + flip_v3(an, ss->cache->mirror_symmetry_pass); /* for flatten center */ - flip_coord(fc, fc, ss->cache->mirror_symmetry_pass); + flip_v3(fc, ss->cache->mirror_symmetry_pass); /* for area normal */ mul_m4_v3(ss->cache->symm_rot_mat, an); @@ -2591,6 +2710,12 @@ static void do_brush_action(Sculpt *sd, Object *ob, Brush *brush) BLI_pbvh_node_mark_update(nodes[n]); } + if (brush_needs_sculpt_normal(brush)) + update_sculpt_normal(sd, ob, nodes, totnode); + + if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_AREA) + update_brush_local_mat(sd, ob); + /* Apply one type of brush action */ switch (brush->sculpt_tool) { case SCULPT_TOOL_DRAW: @@ -2816,9 +2941,9 @@ static void calc_brushdata_symm(Sculpt *sd, StrokeCache *cache, const char symm, { (void)sd; /* unused */ - flip_coord(cache->location, cache->true_location, symm); - flip_coord(cache->grab_delta_symmetry, cache->grab_delta, symm); - flip_coord(cache->view_normal, cache->true_view_normal, symm); + flip_v3_v3(cache->location, cache->true_location, symm); + flip_v3_v3(cache->grab_delta_symmetry, cache->grab_delta, symm); + flip_v3_v3(cache->view_normal, cache->true_view_normal, symm); /* XXX This reduces the length of the grab delta if it approaches the line of symmetry * XXX However, a different approach appears to be needed */ @@ -3364,7 +3489,7 @@ static void sculpt_update_cache_variants(bContext *C, Sculpt *sd, Object *ob, { copy_v2_v2(cache->tex_mouse, cache->mouse); - if ((brush->mtex.brush_map_mode == MTEX_MAP_MODE_FIXED) && + if ((brush->mtex.brush_map_mode == MTEX_MAP_MODE_VIEW) && (brush->flag & BRUSH_RANDOM_ROTATION) && !(brush->flag & BRUSH_RAKE)) { diff --git a/source/blender/editors/space_clip/clip_editor.c b/source/blender/editors/space_clip/clip_editor.c index a394460e71e..1126e96b194 100644 --- a/source/blender/editors/space_clip/clip_editor.c +++ b/source/blender/editors/space_clip/clip_editor.c @@ -170,7 +170,7 @@ void ED_space_clip_set(bContext *C, bScreen *screen, SpaceClip *sc, MovieClip *c if (sc->clip && sc->clip->id.us == 0) sc->clip->id.us = 1; - if (screen) { + if (screen && sc->view == SC_VIEW_CLIP) { ScrArea *area; SpaceLink *sl; @@ -179,7 +179,7 @@ void ED_space_clip_set(bContext *C, bScreen *screen, SpaceClip *sc, MovieClip *c if (sl->spacetype == SPACE_CLIP) { SpaceClip *cur_sc = (SpaceClip *) sl; - if (cur_sc != sc) { + if (cur_sc != sc && cur_sc->view != SC_VIEW_CLIP) { if (cur_sc->clip == old_clip || cur_sc->clip == NULL) { cur_sc->clip = clip; } diff --git a/source/blender/editors/space_node/node_draw.c b/source/blender/editors/space_node/node_draw.c index 3a920e16f8a..d93b1b1fcc8 100644 --- a/source/blender/editors/space_node/node_draw.c +++ b/source/blender/editors/space_node/node_draw.c @@ -914,6 +914,7 @@ void drawnodespace(const bContext *C, ARegion *ar, View2D *v2d) Scene *scene= CTX_data_scene(C); int color_manage = scene->r.color_mgt_flag & R_COLOR_MANAGEMENT; bNodeLinkDrag *nldrag; + LinkData *linkdata; UI_ThemeClearColor(TH_BACK); glClear(GL_COLOR_BUFFER_BIT); @@ -965,8 +966,10 @@ void drawnodespace(const bContext *C, ARegion *ar, View2D *v2d) /* temporary links */ glEnable(GL_BLEND); glEnable(GL_LINE_SMOOTH); - for (nldrag= snode->linkdrag.first; nldrag; nldrag= nldrag->next) - node_draw_link(&ar->v2d, snode, nldrag->link); + for (nldrag= snode->linkdrag.first; nldrag; nldrag= nldrag->next) { + for (linkdata=nldrag->links.first; linkdata; linkdata=linkdata->next) + node_draw_link(&ar->v2d, snode, (bNodeLink *)linkdata->data); + } glDisable(GL_LINE_SMOOTH); glDisable(GL_BLEND); diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c index ae6c09b0339..c23f6c76650 100644 --- a/source/blender/editors/space_node/node_edit.c +++ b/source/blender/editors/space_node/node_edit.c @@ -2324,15 +2324,13 @@ static int node_link_modal(bContext *C, wmOperator *op, wmEvent *event) SpaceNode *snode= CTX_wm_space_node(C); ARegion *ar= CTX_wm_region(C); bNodeLinkDrag *nldrag= op->customdata; - bNode *tnode, *node; - bNodeSocket *tsock= NULL, *sock; + bNode *tnode; + bNodeSocket *tsock= NULL; bNodeLink *link; + LinkData *linkdata; int in_out; - in_out= nldrag->in_out; - node= nldrag->node; - sock= nldrag->sock; - link= nldrag->link; + in_out = nldrag->in_out; UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &snode->mx, &snode->my); @@ -2342,57 +2340,86 @@ static int node_link_modal(bContext *C, wmOperator *op, wmEvent *event) if (in_out==SOCK_OUT) { if (node_find_indicated_socket(snode, &tnode, &tsock, SOCK_IN)) { - if (nodeFindLink(snode->edittree, sock, tsock)==NULL) { - if ( link->tosock!= tsock && (!tnode || (tnode!=node && link->tonode!=tnode)) ) { - link->tonode= tnode; - link->tosock= tsock; - if (link->prev==NULL && link->next==NULL) { - BLI_addtail(&snode->edittree->links, link); - } - - snode->edittree->update |= NTREE_UPDATE_LINKS; - ntreeUpdateTree(snode->edittree); - } - } - } - else { - if (link->tonode || link->tosock) { - BLI_remlink(&snode->edittree->links, link); - link->prev = link->next = NULL; - link->tonode= NULL; - link->tosock= NULL; + for (linkdata=nldrag->links.first; linkdata; linkdata=linkdata->next) { + link = linkdata->data; + + /* skip if this is already the target socket */ + if (link->tosock == tsock) + continue; + /* skip if socket is on the same node as the fromsock */ + if (tnode && link->fromnode == tnode) + continue; + + /* attach links to the socket */ + link->tonode = tnode; + link->tosock = tsock; + /* add it to the node tree temporarily */ + if (link->prev==NULL && link->next==NULL) + BLI_addtail(&snode->edittree->links, link); snode->edittree->update |= NTREE_UPDATE_LINKS; - ntreeUpdateTree(snode->edittree); } + ntreeUpdateTree(snode->edittree); + } + else { + int do_update = 0; + for (linkdata=nldrag->links.first; linkdata; linkdata=linkdata->next) { + link = linkdata->data; + + if (link->tonode || link->tosock) { + BLI_remlink(&snode->edittree->links, link); + link->prev = link->next = NULL; + link->tonode= NULL; + link->tosock= NULL; + + snode->edittree->update |= NTREE_UPDATE_LINKS; + do_update = 1; + } + } + if (do_update) + ntreeUpdateTree(snode->edittree); } } else { if (node_find_indicated_socket(snode, &tnode, &tsock, SOCK_OUT)) { - if (nodeFindLink(snode->edittree, sock, tsock)==NULL) { - if (nodeCountSocketLinks(snode->edittree, tsock) < tsock->limit) { - if ( link->fromsock!= tsock && (!tnode || (tnode!=node && link->fromnode!=tnode)) ) { - link->fromnode= tnode; - link->fromsock= tsock; - if (link->prev==NULL && link->next==NULL) { - BLI_addtail(&snode->edittree->links, link); - } - - snode->edittree->update |= NTREE_UPDATE_LINKS; - ntreeUpdateTree(snode->edittree); - } - } + for (linkdata=nldrag->links.first; linkdata; linkdata=linkdata->next) { + link = linkdata->data; + + /* skip if this is already the target socket */ + if (link->fromsock == tsock) + continue; + /* skip if socket is on the same node as the fromsock */ + if (tnode && link->tonode == tnode) + continue; + + /* attach links to the socket */ + link->fromnode = tnode; + link->fromsock = tsock; + /* add it to the node tree temporarily */ + if (link->prev==NULL && link->next==NULL) + BLI_addtail(&snode->edittree->links, link); + + snode->edittree->update |= NTREE_UPDATE_LINKS; } + ntreeUpdateTree(snode->edittree); } else { - if (link->tonode || link->tosock) { - BLI_remlink(&snode->edittree->links, link); - link->prev = link->next = NULL; - link->fromnode= NULL; - link->fromsock= NULL; - snode->edittree->update |= NTREE_UPDATE_LINKS; - ntreeUpdateTree(snode->edittree); + int do_update = 0; + for (linkdata=nldrag->links.first; linkdata; linkdata=linkdata->next) { + link = linkdata->data; + + if (link->fromnode || link->fromsock) { + BLI_remlink(&snode->edittree->links, link); + link->prev = link->next = NULL; + link->fromnode= NULL; + link->fromsock= NULL; + + snode->edittree->update |= NTREE_UPDATE_LINKS; + do_update = 1; + } } + if (do_update) + ntreeUpdateTree(snode->edittree); } } @@ -2401,139 +2428,161 @@ static int node_link_modal(bContext *C, wmOperator *op, wmEvent *event) case LEFTMOUSE: case RIGHTMOUSE: - case MIDDLEMOUSE: - if (link->tosock && link->fromsock) { - /* send changed events for original tonode and new */ - snode_update(snode, link->tonode); + case MIDDLEMOUSE: { + for (linkdata=nldrag->links.first; linkdata; linkdata=linkdata->next) { + link = linkdata->data; - /* we might need to remove a link */ - if (in_out==SOCK_OUT) - node_remove_extra_links(snode, link->tosock, link); - - /* when linking to group outputs, update the socket type */ - /* XXX this should all be part of a generic update system */ - if (!link->tonode) { - if(link->tosock->type != link->fromsock->type) - nodeSocketSetType(link->tosock, link->fromsock->type); - } - } - else if (outside_group_rect(snode) && (link->tonode || link->fromnode)) { - /* automatically add new group socket */ - if (link->tonode && link->tosock) { - link->fromsock = node_group_expose_socket(snode->edittree, link->tosock, SOCK_IN); - link->fromnode = NULL; - if (link->prev==NULL && link->next==NULL) { - BLI_addtail(&snode->edittree->links, link); + if (link->tosock && link->fromsock) { + /* send changed events for original tonode and new */ + if (link->tonode) + snode_update(snode, link->tonode); + + /* we might need to remove a link */ + if (in_out==SOCK_OUT) + node_remove_extra_links(snode, link->tosock, link); + + /* when linking to group outputs, update the socket type */ + /* XXX this should all be part of a generic update system */ + if (!link->tonode) { + if(link->tosock->type != link->fromsock->type) + nodeSocketSetType(link->tosock, link->fromsock->type); } - snode->edittree->update |= NTREE_UPDATE_GROUP_IN | NTREE_UPDATE_LINKS; } - else if (link->fromnode && link->fromsock) { - link->tosock = node_group_expose_socket(snode->edittree, link->fromsock, SOCK_OUT); - link->tonode = NULL; - if (link->prev==NULL && link->next==NULL) { - BLI_addtail(&snode->edittree->links, link); + else if (outside_group_rect(snode) && (link->tonode || link->fromnode)) { + /* automatically add new group socket */ + if (link->tonode && link->tosock) { + link->fromsock = node_group_expose_socket(snode->edittree, link->tosock, SOCK_IN); + link->fromnode = NULL; + if (link->prev==NULL && link->next==NULL) + BLI_addtail(&snode->edittree->links, link); + + snode->edittree->update |= NTREE_UPDATE_GROUP_IN | NTREE_UPDATE_LINKS; + } + else if (link->fromnode && link->fromsock) { + link->tosock = node_group_expose_socket(snode->edittree, link->fromsock, SOCK_OUT); + link->tonode = NULL; + if (link->prev==NULL && link->next==NULL) + BLI_addtail(&snode->edittree->links, link); + + snode->edittree->update |= NTREE_UPDATE_GROUP_OUT | NTREE_UPDATE_LINKS; } - snode->edittree->update |= NTREE_UPDATE_GROUP_OUT | NTREE_UPDATE_LINKS; } + else + nodeRemLink(snode->edittree, link); } - else - nodeRemLink(snode->edittree, link); ntreeUpdateTree(snode->edittree); snode_notify(C, snode); snode_dag_update(C, snode); BLI_remlink(&snode->linkdrag, nldrag); + /* links->data pointers are either held by the tree or freed already */ + BLI_freelistN(&nldrag->links); MEM_freeN(nldrag); return OPERATOR_FINISHED; + } } return OPERATOR_RUNNING_MODAL; } /* return 1 when socket clicked */ -static int node_link_init(SpaceNode *snode, bNodeLinkDrag *nldrag) +static bNodeLinkDrag *node_link_init(SpaceNode *snode, int detach) { - bNodeLink *link; - int in_out = 0; - + bNode *node; + bNodeSocket *sock; + bNodeLink *link, *link_next, *oplink; + bNodeLinkDrag *nldrag = NULL; + LinkData *linkdata; + int num_links; + /* output indicated? */ - if (node_find_indicated_socket(snode, &nldrag->node, &nldrag->sock, SOCK_OUT)) { - if (nodeCountSocketLinks(snode->edittree, nldrag->sock) < nldrag->sock->limit) - in_out = SOCK_OUT; + if (node_find_indicated_socket(snode, &node, &sock, SOCK_OUT)) { + nldrag= MEM_callocN(sizeof(bNodeLinkDrag), "drag link op customdata"); + + num_links = nodeCountSocketLinks(snode->edittree, sock); + if (num_links > 0 && (num_links >= sock->limit || detach)) { + /* dragged links are fixed on input side */ + nldrag->in_out = SOCK_IN; + /* detach current links and store them in the operator data */ + for (link= snode->edittree->links.first; link; link= link_next) { + link_next = link->next; + if (link->fromsock==sock) { + linkdata = MEM_callocN(sizeof(LinkData), "drag link op link data"); + linkdata->data = oplink = MEM_callocN(sizeof(bNodeLink), "drag link op link"); + *oplink = *link; + BLI_addtail(&nldrag->links, linkdata); + nodeRemLink(snode->edittree, link); + } + } + } else { - /* find if we break a link */ - for (link= snode->edittree->links.first; link; link= link->next) { - if (link->fromsock==nldrag->sock) - break; - } - if (link) { - nldrag->node= link->tonode; - nldrag->sock= link->tosock; - nodeRemLink(snode->edittree, link); - in_out = SOCK_IN; - } + /* dragged links are fixed on output side */ + nldrag->in_out = SOCK_OUT; + /* create a new link */ + linkdata = MEM_callocN(sizeof(LinkData), "drag link op link data"); + linkdata->data = oplink = MEM_callocN(sizeof(bNodeLink), "drag link op link"); + oplink->fromnode = node; + oplink->fromsock = sock; + BLI_addtail(&nldrag->links, linkdata); } } /* or an input? */ - else if (node_find_indicated_socket(snode, &nldrag->node, &nldrag->sock, SOCK_IN)) { - if (nodeCountSocketLinks(snode->edittree, nldrag->sock) < nldrag->sock->limit) - in_out = SOCK_IN; + else if (node_find_indicated_socket(snode, &node, &sock, SOCK_IN)) { + nldrag= MEM_callocN(sizeof(bNodeLinkDrag), "drag link op customdata"); + + num_links = nodeCountSocketLinks(snode->edittree, sock); + if (num_links > 0 && (num_links >= sock->limit || detach)) { + /* dragged links are fixed on output side */ + nldrag->in_out = SOCK_OUT; + /* detach current links and store them in the operator data */ + for (link= snode->edittree->links.first; link; link= link_next) { + link_next = link->next; + if (link->tosock==sock) { + linkdata = MEM_callocN(sizeof(LinkData), "drag link op link data"); + linkdata->data = oplink = MEM_callocN(sizeof(bNodeLink), "drag link op link"); + *oplink = *link; + BLI_addtail(&nldrag->links, linkdata); + nodeRemLink(snode->edittree, link); + + /* send changed event to original link->tonode */ + if (node) + snode_update(snode, node); + } + } + } else { - /* find if we break a link */ - for (link= snode->edittree->links.first; link; link= link->next) { - if (link->tosock==nldrag->sock) - break; - } - if (link) { - /* send changed event to original tonode */ - if (link->tonode) - snode_update(snode, link->tonode); - - nldrag->node= link->fromnode; - nldrag->sock= link->fromsock; - nodeRemLink(snode->edittree, link); - in_out = SOCK_OUT; - } + /* dragged links are fixed on input side */ + nldrag->in_out = SOCK_IN; + /* create a new link */ + linkdata = MEM_callocN(sizeof(LinkData), "drag link op link data"); + linkdata->data = oplink = MEM_callocN(sizeof(bNodeLink), "drag link op link"); + oplink->tonode = node; + oplink->tosock = sock; + BLI_addtail(&nldrag->links, linkdata); } } - return in_out; + return nldrag; } static int node_link_invoke(bContext *C, wmOperator *op, wmEvent *event) { SpaceNode *snode= CTX_wm_space_node(C); ARegion *ar= CTX_wm_region(C); - bNodeLinkDrag *nldrag= MEM_callocN(sizeof(bNodeLinkDrag), "drag link op customdata"); - + bNodeLinkDrag *nldrag; + 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); ED_preview_kill_jobs(C); - nldrag->in_out= node_link_init(snode, nldrag); + nldrag = node_link_init(snode, detach); - if (nldrag->in_out) { + if (nldrag) { op->customdata= nldrag; - - /* we make a temporal link */ - if (nldrag->in_out==SOCK_OUT) { - nldrag->link= MEM_callocN(sizeof(bNodeLink), "link"); - nldrag->link->fromnode= nldrag->node; - nldrag->link->fromsock= nldrag->sock; - nldrag->link->tonode= NULL; - nldrag->link->tosock= NULL; - } - else { - nldrag->link= MEM_callocN(sizeof(bNodeLink), "link"); - nldrag->link->fromnode= NULL; - nldrag->link->fromsock= NULL; - nldrag->link->tonode= nldrag->node; - nldrag->link->tosock= nldrag->sock; - } BLI_addtail(&snode->linkdrag, nldrag); /* add modal handler */ @@ -2541,21 +2590,20 @@ static int node_link_invoke(bContext *C, wmOperator *op, wmEvent *event) return OPERATOR_RUNNING_MODAL; } - else { - MEM_freeN(nldrag); + else return OPERATOR_CANCELLED|OPERATOR_PASS_THROUGH; - } } static int node_link_cancel(bContext *C, wmOperator *op) { SpaceNode *snode= CTX_wm_space_node(C); bNodeLinkDrag *nldrag= op->customdata; - - nodeRemLink(snode->edittree, nldrag->link); + BLI_remlink(&snode->linkdrag, nldrag); + + BLI_freelistN(&nldrag->links); MEM_freeN(nldrag); - + return OPERATOR_CANCELLED; } @@ -2575,6 +2623,8 @@ void NODE_OT_link(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING; + + RNA_def_boolean(ot->srna, "detach", FALSE, "Detach", "Detach and redirect existing links"); } /* ********************** Make Link operator ***************** */ diff --git a/source/blender/editors/space_node/node_intern.h b/source/blender/editors/space_node/node_intern.h index 17078443987..802c471c7aa 100644 --- a/source/blender/editors/space_node/node_intern.h +++ b/source/blender/editors/space_node/node_intern.h @@ -52,9 +52,11 @@ typedef struct bNodeLinkDrag { struct bNodeLinkDrag *next, *prev; - struct bNode *node; - struct bNodeSocket *sock; - struct bNodeLink *link; + /* List of links dragged by the operator. + * Note: This is a list of LinkData structs on top of the actual bNodeLinks. + * This way the links can be added to the node tree while being stored in this list. + */ + ListBase links; int in_out; } bNodeLinkDrag; diff --git a/source/blender/editors/space_node/node_ops.c b/source/blender/editors/space_node/node_ops.c index 7d9d7d736f6..5d586f08eb0 100644 --- a/source/blender/editors/space_node/node_ops.c +++ b/source/blender/editors/space_node/node_ops.c @@ -171,6 +171,8 @@ void node_keymap(struct wmKeyConfig *keyconf) /* 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); WM_keymap_add_item(keymap, "NODE_OT_resize", LEFTMOUSE, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "NODE_OT_links_cut", LEFTMOUSE, KM_PRESS, KM_CTRL, 0); diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 5413aa88ab6..95797fd9afc 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -3603,19 +3603,21 @@ static int draw_mesh_object(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D } } - /* GPU_begin_object_materials checked if this is needed */ - if (do_alpha_after) { - if (ob->dtx & OB_DRAWXRAY) { - add_view3d_after(&v3d->afterdraw_xraytransp, base, flag); + if ((flag & DRAW_PICKING) == 0 && (base->flag & OB_FROMDUPLI) == 0) { + /* GPU_begin_object_materials checked if this is needed */ + if (do_alpha_after) { + if (ob->dtx & OB_DRAWXRAY) { + add_view3d_after(&v3d->afterdraw_xraytransp, base, flag); + } + else { + add_view3d_after(&v3d->afterdraw_transp, base, flag); + } } - else { - add_view3d_after(&v3d->afterdraw_transp, base, flag); - } - } - else if (ob->dtx & OB_DRAWXRAY && ob->dtx & OB_DRAWTRANSP) { - /* special case xray+transp when alpha is 1.0, without this the object vanishes */ - if (v3d->xray == 0 && v3d->transp == 0) { - add_view3d_after(&v3d->afterdraw_xray, base, flag); + else if (ob->dtx & OB_DRAWXRAY && ob->dtx & OB_DRAWTRANSP) { + /* special case xray+transp when alpha is 1.0, without this the object vanishes */ + if (v3d->xray == 0 && v3d->transp == 0) { + add_view3d_after(&v3d->afterdraw_xray, base, flag); + } } } diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 682d8950440..6eff4a6dce9 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -1715,6 +1715,7 @@ typedef struct View3DAfter { void add_view3d_after(ListBase *lb, Base *base, int flag) { View3DAfter *v3da = MEM_callocN(sizeof(View3DAfter), "View 3d after"); + BLI_assert((base->flag & OB_FROMDUPLI) == 0); BLI_addtail(lb, v3da); v3da->base = base; v3da->flag = flag; diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c index 4f7fc3639f4..6a2c3eee7a5 100644 --- a/source/blender/gpu/intern/gpu_codegen.c +++ b/source/blender/gpu/intern/gpu_codegen.c @@ -232,7 +232,7 @@ static char *gpu_generate_function_prototyps(GHash *hash) GPUFunction *GPU_lookup_function(const char *name) { if (!FUNCTION_HASH) { - FUNCTION_HASH = BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp, "GPU_lookup_function gh"); + FUNCTION_HASH = BLI_ghash_str_new("GPU_lookup_function gh"); gpu_parse_functions_string(FUNCTION_HASH, glsl_material_library); /*FUNCTION_PROTOTYPES = gpu_generate_function_prototyps(FUNCTION_HASH); FUNCTION_LIB = GPU_shader_create_lib(datatoc_gpu_shader_material_glsl);*/ @@ -375,8 +375,8 @@ static void codegen_set_unique_ids(ListBase *nodes) GPUOutput *output; int id = 1, texid = 0; - bindhash= BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "codegen_set_unique_ids1 gh"); - definehash= BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "codegen_set_unique_ids2 gh"); + bindhash= BLI_ghash_ptr_new("codegen_set_unique_ids1 gh"); + definehash= BLI_ghash_ptr_new("codegen_set_unique_ids2 gh"); for (node=nodes->first; node; node=node->next) { for (input=node->inputs.first; input; input=input->next) { diff --git a/source/blender/imbuf/intern/filetype.c b/source/blender/imbuf/intern/filetype.c index 59c10165974..da207c19695 100644 --- a/source/blender/imbuf/intern/filetype.c +++ b/source/blender/imbuf/intern/filetype.c @@ -44,13 +44,26 @@ #include "imbuf.h" -static int imb_ftype_default(ImFileType *type, ImBuf *ibuf) { return (ibuf->ftype & type->filetype); } +static int imb_ftype_default(ImFileType *type, ImBuf *ibuf) +{ + return (ibuf->ftype & type->filetype); +} #if defined(__APPLE__) && defined(IMBUF_COCOA) -static int imb_ftype_cocoa(ImFileType *type, ImBuf *ibuf) { return (ibuf->ftype & TIF); } +static int imb_ftype_cocoa(ImFileType *type, ImBuf *ibuf) +{ + return (ibuf->ftype & TIF); +} #endif -static int imb_ftype_iris(ImFileType *type, ImBuf *ibuf) { (void)type; return (ibuf->ftype == IMAGIC); } +static int imb_ftype_iris(ImFileType *type, ImBuf *ibuf) +{ + (void)type; + return (ibuf->ftype == IMAGIC); +} #ifdef WITH_QUICKTIME -static int imb_ftype_quicktime(ImFileType *type, ImBuf *ibuf) { return 0; } // XXX +static int imb_ftype_quicktime(ImFileType *type, ImBuf *ibuf) +{ + return 0; /* XXX */ +} #endif #ifdef WITH_QUICKTIME @@ -58,7 +71,7 @@ void quicktime_init(void); void quicktime_exit(void); #endif -ImFileType IMB_FILE_TYPES[]= { +ImFileType IMB_FILE_TYPES[] = { {NULL, NULL, imb_is_a_jpeg, imb_ftype_default, imb_load_jpeg, imb_savejpeg, NULL, 0, JPG}, {NULL, NULL, imb_is_a_png, imb_ftype_default, imb_loadpng, imb_savepng, NULL, 0, PNG}, {NULL, NULL, imb_is_a_bmp, imb_ftype_default, imb_bmp_decode, imb_savebmp, NULL, 0, BMP}, @@ -88,13 +101,14 @@ ImFileType IMB_FILE_TYPES[]= { #ifdef WITH_QUICKTIME {quicktime_init, quicktime_exit, imb_is_a_quicktime, imb_ftype_quicktime, imb_quicktime_decode, NULL, NULL, 0, QUICKTIME}, #endif - {NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0}}; + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0} +}; void imb_filetypes_init(void) { ImFileType *type; - for (type=IMB_FILE_TYPES; type->is_a; type++) + for (type = IMB_FILE_TYPES; type->is_a; type++) if (type->init) type->init(); } @@ -103,7 +117,7 @@ void imb_filetypes_exit(void) { ImFileType *type; - for (type=IMB_FILE_TYPES; type->is_a; type++) + for (type = IMB_FILE_TYPES; type->is_a; type++) if (type->exit) type->exit(); } diff --git a/source/blender/imbuf/intern/jpeg.c b/source/blender/imbuf/intern/jpeg.c index f3a382eaa56..1a96e55e3d1 100644 --- a/source/blender/imbuf/intern/jpeg.c +++ b/source/blender/imbuf/intern/jpeg.c @@ -47,21 +47,21 @@ #include "jpeglib.h" #include "jerror.h" -#define IS_jpg(x) (x->ftype & JPG) -#define IS_stdjpg(x) ((x->ftype & JPG_MSK) == JPG_STD) -#define IS_vidjpg(x) ((x->ftype & JPG_MSK) == JPG_VID) -#define IS_jstjpg(x) ((x->ftype & JPG_MSK) == JPG_JST) -#define IS_maxjpg(x) ((x->ftype & JPG_MSK) == JPG_MAX) +#define IS_jpg(x) (x->ftype & JPG) +#define IS_stdjpg(x) ((x->ftype & JPG_MSK) == JPG_STD) +#define IS_vidjpg(x) ((x->ftype & JPG_MSK) == JPG_VID) +#define IS_jstjpg(x) ((x->ftype & JPG_MSK) == JPG_JST) +#define IS_maxjpg(x) ((x->ftype & JPG_MSK) == JPG_MAX) /* the types are from the jpeg lib */ -static void jpeg_error (j_common_ptr cinfo); +static void jpeg_error(j_common_ptr cinfo); static void init_source(j_decompress_ptr cinfo); static boolean fill_input_buffer(j_decompress_ptr cinfo); static void skip_input_data(j_decompress_ptr cinfo, long num_bytes); static void term_source(j_decompress_ptr cinfo); static void memory_source(j_decompress_ptr cinfo, unsigned char *buffer, size_t size); -static boolean handle_app1 (j_decompress_ptr cinfo); -static ImBuf * ibJpegImageFromCinfo(struct jpeg_decompress_struct * cinfo, int flags); +static boolean handle_app1(j_decompress_ptr cinfo); +static ImBuf *ibJpegImageFromCinfo(struct jpeg_decompress_struct *cinfo, int flags); /* @@ -82,7 +82,7 @@ static int ibuf_ftype; int imb_is_a_jpeg(unsigned char *mem) { - if ((mem[0]== 0xFF) && (mem[1] == 0xD8))return 1; + if ((mem[0] == 0xFF) && (mem[1] == 0xD8)) return 1; return 0; } @@ -91,19 +91,19 @@ int imb_is_a_jpeg(unsigned char *mem) //---------------------------------------------------------- typedef struct my_error_mgr { - struct jpeg_error_mgr pub; /* "public" fields */ + struct jpeg_error_mgr pub; /* "public" fields */ - jmp_buf setjmp_buffer; /* for return to caller */ + jmp_buf setjmp_buffer; /* for return to caller */ } my_error_mgr; -typedef my_error_mgr * my_error_ptr; +typedef my_error_mgr *my_error_ptr; -static void jpeg_error (j_common_ptr cinfo) +static void jpeg_error(j_common_ptr cinfo) { my_error_ptr err = (my_error_ptr)cinfo->err; /* Always display the message */ - (*cinfo->err->output_message) (cinfo); + (*cinfo->err->output_message)(cinfo); /* Let the memory manager delete any temp files before we die */ jpeg_destroy(cinfo); @@ -117,19 +117,19 @@ static void jpeg_error (j_common_ptr cinfo) //---------------------------------------------------------- typedef struct { - unsigned char *buffer; - int filled; + unsigned char *buffer; + int filled; } buffer_struct; typedef struct { - struct jpeg_source_mgr pub; /* public fields */ + struct jpeg_source_mgr pub; /* public fields */ - unsigned char *buffer; - int size; - JOCTET terminal[2]; + unsigned char *buffer; + int size; + JOCTET terminal[2]; } my_source_mgr; -typedef my_source_mgr * my_src_ptr; +typedef my_source_mgr *my_src_ptr; static void init_source(j_decompress_ptr cinfo) { @@ -179,25 +179,25 @@ static void memory_source(j_decompress_ptr cinfo, unsigned char *buffer, size_t if (cinfo->src == NULL) { /* first time for this JPEG object? */ cinfo->src = (struct jpeg_source_mgr *)(*cinfo->mem->alloc_small) - ((j_common_ptr) cinfo, JPOOL_PERMANENT, sizeof(my_source_mgr)); + ((j_common_ptr) cinfo, JPOOL_PERMANENT, sizeof(my_source_mgr)); } src = (my_src_ptr) cinfo->src; - src->pub.init_source = init_source; - src->pub.fill_input_buffer = fill_input_buffer; - src->pub.skip_input_data = skip_input_data; - src->pub.resync_to_restart = jpeg_resync_to_restart; - src->pub.term_source = term_source; + src->pub.init_source = init_source; + src->pub.fill_input_buffer = fill_input_buffer; + src->pub.skip_input_data = skip_input_data; + src->pub.resync_to_restart = jpeg_resync_to_restart; + src->pub.term_source = term_source; - src->pub.bytes_in_buffer = size; - src->pub.next_input_byte = buffer; + src->pub.bytes_in_buffer = size; + src->pub.next_input_byte = buffer; src->buffer = buffer; src->size = size; } -#define MAKESTMT(stuff) do { stuff } while (0) +#define MAKESTMT(stuff) do { stuff } while (0) #define INPUT_VARS(cinfo) \ struct jpeg_source_mgr * datasrc = (cinfo)->src; \ @@ -229,7 +229,7 @@ static void memory_source(j_decompress_ptr cinfo, unsigned char *buffer, size_t /* Read a byte into variable V. * If must suspend, take the specified action (typically "return FALSE"). */ -#define INPUT_BYTE(cinfo,V,action) \ +#define INPUT_BYTE(cinfo, V, action) \ MAKESTMT(MAKE_BYTE_AVAIL(cinfo,action); \ bytes_in_buffer--; \ V = GETJOCTET(*next_input_byte++); ) @@ -237,17 +237,17 @@ static void memory_source(j_decompress_ptr cinfo, unsigned char *buffer, size_t /* As above, but read two bytes interpreted as an unsigned 16-bit integer. * V should be declared unsigned int or perhaps INT32. */ -#define INPUT_2BYTES(cinfo,V,action) \ +#define INPUT_2BYTES(cinfo, V, action) \ MAKESTMT(MAKE_BYTE_AVAIL(cinfo,action); \ bytes_in_buffer--; \ V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \ - MAKE_BYTE_AVAIL(cinfo,action); \ + MAKE_BYTE_AVAIL(cinfo, action); \ bytes_in_buffer--; \ V += GETJOCTET(*next_input_byte++); ) static boolean -handle_app1 (j_decompress_ptr cinfo) +handle_app1(j_decompress_ptr cinfo) { INT32 length; /* initialized by the macro */ INT32 i; @@ -264,20 +264,20 @@ handle_app1 (j_decompress_ptr cinfo) if (strncmp(neogeo, "NeoGeo", 6) == 0) memcpy(&ibuf_ftype, neogeo + 6, 4); ibuf_ftype = BIG_LONG(ibuf_ftype); } - INPUT_SYNC(cinfo); /* do before skip_input_data */ - if (length > 0) (*cinfo->src->skip_input_data) (cinfo, length); + INPUT_SYNC(cinfo); /* do before skip_input_data */ + if (length > 0) (*cinfo->src->skip_input_data)(cinfo, length); return TRUE; } -static ImBuf * ibJpegImageFromCinfo(struct jpeg_decompress_struct * cinfo, int flags) +static ImBuf *ibJpegImageFromCinfo(struct jpeg_decompress_struct *cinfo, int flags) { JSAMPARRAY row_pointer; - JSAMPLE * buffer = NULL; + JSAMPLE *buffer = NULL; int row_stride; int x, y, depth, r, g, b, k; - struct ImBuf * ibuf = NULL; - uchar * rect; + struct ImBuf *ibuf = NULL; + uchar *rect; jpeg_saved_marker_ptr marker; char *str, *key, *value; @@ -314,7 +314,7 @@ static ImBuf * ibJpegImageFromCinfo(struct jpeg_decompress_struct * cinfo, int f else { row_stride = cinfo->output_width * depth; - row_pointer = (*cinfo->mem->alloc_sarray) ((j_common_ptr) cinfo, JPOOL_IMAGE, row_stride, 1); + row_pointer = (*cinfo->mem->alloc_sarray)((j_common_ptr) cinfo, JPOOL_IMAGE, row_stride, 1); for (y = ibuf->y - 1; y >= 0; y--) { jpeg_read_scanlines(cinfo, row_pointer, 1); @@ -323,14 +323,14 @@ static ImBuf * ibJpegImageFromCinfo(struct jpeg_decompress_struct * cinfo, int f switch (depth) { case 1: - for (x=ibuf->x; x >0; x--) { + for (x = ibuf->x; x > 0; x--) { rect[3] = 255; rect[0] = rect[1] = rect[2] = *buffer++; rect += 4; } break; case 3: - for (x=ibuf->x; x >0; x--) { + for (x = ibuf->x; x > 0; x--) { rect[3] = 255; rect[0] = *buffer++; rect[1] = *buffer++; @@ -339,7 +339,7 @@ static ImBuf * ibJpegImageFromCinfo(struct jpeg_decompress_struct * cinfo, int f } break; case 4: - for (x=ibuf->x; x >0; x--) { + for (x = ibuf->x; x > 0; x--) { r = *buffer++; g = *buffer++; b = *buffer++; @@ -371,7 +371,7 @@ static ImBuf * ibJpegImageFromCinfo(struct jpeg_decompress_struct * cinfo, int f } } - marker= cinfo->marker_list; + marker = cinfo->marker_list; while (marker) { if (marker->marker != JPEG_COM) goto next_stamp_marker; @@ -400,8 +400,8 @@ static ImBuf * ibJpegImageFromCinfo(struct jpeg_decompress_struct * cinfo, int f goto next_stamp_marker; } - str = BLI_strdup ((char *) marker->data); - key = strchr (str, ':'); + str = BLI_strdup((char *) marker->data); + key = strchr(str, ':'); /* * A little paranoid, but the file maybe * is broken... and a "extra" check is better @@ -413,7 +413,7 @@ static ImBuf * ibJpegImageFromCinfo(struct jpeg_decompress_struct * cinfo, int f } key++; - value = strchr (key, ':'); + value = strchr(key, ':'); if (!value) { MEM_freeN(str); goto next_stamp_marker; @@ -425,7 +425,7 @@ static ImBuf * ibJpegImageFromCinfo(struct jpeg_decompress_struct * cinfo, int f ibuf->flags |= IB_metadata; MEM_freeN(str); next_stamp_marker: - marker= marker->next; + marker = marker->next; } jpeg_finish_decompress(cinfo); @@ -441,11 +441,11 @@ next_stamp_marker: return(ibuf); } -ImBuf * imb_load_jpeg (unsigned char * buffer, size_t size, int flags) +ImBuf *imb_load_jpeg(unsigned char *buffer, size_t size, int flags) { struct jpeg_decompress_struct _cinfo, *cinfo = &_cinfo; struct my_error_mgr jerr; - ImBuf * ibuf; + ImBuf *ibuf; if (!imb_is_a_jpeg(buffer)) return NULL; @@ -470,11 +470,11 @@ ImBuf * imb_load_jpeg (unsigned char * buffer, size_t size, int flags) } -static void write_jpeg(struct jpeg_compress_struct * cinfo, struct ImBuf * ibuf) +static void write_jpeg(struct jpeg_compress_struct *cinfo, struct ImBuf *ibuf) { - JSAMPLE * buffer = NULL; + JSAMPLE *buffer = NULL; JSAMPROW row_pointer[1]; - uchar * rect; + uchar *rect; int x, y; char neogeo[128]; ImMetaData *iptr; @@ -486,15 +486,15 @@ static void write_jpeg(struct jpeg_compress_struct * cinfo, struct ImBuf * ibuf) ibuf_ftype = BIG_LONG(ibuf->ftype); memcpy(neogeo + 6, &ibuf_ftype, 4); - jpeg_write_marker(cinfo, 0xe1, (JOCTET*) neogeo, 10); + jpeg_write_marker(cinfo, 0xe1, (JOCTET *) neogeo, 10); if (ibuf->metadata) { /* key + max value + "Blender" */ - text= MEM_mallocN(530, "stamp info read"); - iptr= ibuf->metadata; + text = MEM_mallocN(530, "stamp info read"); + iptr = ibuf->metadata; while (iptr) { - if (!strcmp (iptr->key, "None")) { - jpeg_write_marker(cinfo, JPEG_COM, (JOCTET *) iptr->value, strlen (iptr->value) + 1); + if (!strcmp(iptr->key, "None")) { + jpeg_write_marker(cinfo, JPEG_COM, (JOCTET *) iptr->value, strlen(iptr->value) + 1); goto next_stamp_info; } @@ -507,8 +507,8 @@ static void write_jpeg(struct jpeg_compress_struct * cinfo, struct ImBuf * ibuf) * The first "Blender" is a simple identify to help * in the read process. */ - sprintf (text, "Blender:%s:%s", iptr->key, iptr->value); - jpeg_write_marker(cinfo, JPEG_COM, (JOCTET *) text, strlen (text)+1); + sprintf(text, "Blender:%s:%s", iptr->key, iptr->value); + jpeg_write_marker(cinfo, JPEG_COM, (JOCTET *) text, strlen(text) + 1); next_stamp_info: iptr = iptr->next; } @@ -516,9 +516,9 @@ next_stamp_info: } row_pointer[0] = - MEM_mallocN(sizeof(JSAMPLE) * - cinfo->input_components * - cinfo->image_width, "jpeg row_pointer"); + MEM_mallocN(sizeof(JSAMPLE) * + cinfo->input_components * + cinfo->image_width, "jpeg row_pointer"); for (y = ibuf->y - 1; y >= 0; y--) { rect = (uchar *) (ibuf->rect + y * ibuf->x); @@ -542,7 +542,7 @@ next_stamp_info: case JCS_UNKNOWN: memcpy(buffer, rect, 4 * ibuf->x); break; - /* default was missing... intentional ? */ + /* default was missing... intentional ? */ default: ; /* do nothing */ } @@ -555,7 +555,7 @@ next_stamp_info: } -static int init_jpeg(FILE * outfile, struct jpeg_compress_struct * cinfo, struct ImBuf *ibuf) +static int init_jpeg(FILE *outfile, struct jpeg_compress_struct *cinfo, struct ImBuf *ibuf) { int quality; @@ -587,7 +587,7 @@ static int init_jpeg(FILE * outfile, struct jpeg_compress_struct * cinfo, struct case JCS_UNKNOWN: cinfo->input_components = 4; break; - /* default was missing... intentional ? */ + /* default was missing... intentional ? */ default: ; /* do nothing */ } @@ -604,7 +604,7 @@ static int init_jpeg(FILE * outfile, struct jpeg_compress_struct * cinfo, struct static int save_stdjpeg(const char *name, struct ImBuf *ibuf) { - FILE * outfile; + FILE *outfile; struct jpeg_compress_struct _cinfo, *cinfo = &_cinfo; struct my_error_mgr jerr; @@ -638,7 +638,7 @@ static int save_stdjpeg(const char *name, struct ImBuf *ibuf) static int save_vidjpeg(const char *name, struct ImBuf *ibuf) { - FILE * outfile; + FILE *outfile; struct jpeg_compress_struct _cinfo, *cinfo = &_cinfo; struct my_error_mgr jerr; @@ -678,7 +678,7 @@ static int save_vidjpeg(const char *name, struct ImBuf *ibuf) static int save_jstjpeg(const char *name, struct ImBuf *ibuf) { char fieldname[1024]; - struct ImBuf * tbuf; + struct ImBuf *tbuf; int oldy, returnval; tbuf = IMB_allocImBuf(ibuf->x, ibuf->y / 2, 24, IB_rect); @@ -708,7 +708,7 @@ static int save_jstjpeg(const char *name, struct ImBuf *ibuf) static int save_maxjpeg(const char *name, struct ImBuf *ibuf) { - FILE * outfile; + FILE *outfile; struct jpeg_compress_struct _cinfo, *cinfo = &_cinfo; struct my_error_mgr jerr; diff --git a/source/blender/imbuf/intern/metadata.c b/source/blender/imbuf/intern/metadata.c index 0da7358b55b..a7caae73679 100644 --- a/source/blender/imbuf/intern/metadata.c +++ b/source/blender/imbuf/intern/metadata.c @@ -43,7 +43,7 @@ -void IMB_metadata_free(struct ImBuf* img) +void IMB_metadata_free(struct ImBuf *img) { ImMetaData *info; @@ -54,7 +54,7 @@ void IMB_metadata_free(struct ImBuf* img) } info = img->metadata; while (info) { - ImMetaData* next = info->next; + ImMetaData *next = info->next; MEM_freeN(info->key); MEM_freeN(info->value); MEM_freeN(info); @@ -62,7 +62,7 @@ void IMB_metadata_free(struct ImBuf* img) } } -int IMB_metadata_get_field(struct ImBuf* img, const char* key, char* field, int len) +int IMB_metadata_get_field(struct ImBuf *img, const char *key, char *field, int len) { ImMetaData *info; int retval = 0; @@ -84,7 +84,7 @@ int IMB_metadata_get_field(struct ImBuf* img, const char* key, char* field, int return retval; } -int IMB_metadata_add_field(struct ImBuf* img, const char* key, const char* value) +int IMB_metadata_add_field(struct ImBuf *img, const char *key, const char *value) { ImMetaData *info; ImMetaData *last; @@ -121,7 +121,7 @@ int IMB_metadata_del_field(struct ImBuf *img, const char *key) p = img->metadata; p1 = NULL; while (p) { - if (!strcmp (key, p->key)) { + if (!strcmp(key, p->key)) { if (p1) p1->next = p->next; else @@ -146,18 +146,18 @@ int IMB_metadata_change_field(struct ImBuf *img, const char *key, const char *fi return (0); if (!img->metadata) - return (IMB_metadata_add_field (img, key, field)); + return (IMB_metadata_add_field(img, key, field)); p = img->metadata; while (p) { - if (!strcmp (key, p->key)) { - MEM_freeN (p->value); - p->value = BLI_strdup (field); + if (!strcmp(key, p->key)) { + MEM_freeN(p->value); + p->value = BLI_strdup(field); return (1); } p = p->next; } - return (IMB_metadata_add_field (img, key, field)); + return (IMB_metadata_add_field(img, key, field)); } diff --git a/source/blender/imbuf/intern/readimage.c b/source/blender/imbuf/intern/readimage.c index e9d549be8b9..e78c4a55843 100644 --- a/source/blender/imbuf/intern/readimage.c +++ b/source/blender/imbuf/intern/readimage.c @@ -60,9 +60,9 @@ ImBuf *IMB_ibImageFromMemory(unsigned char *mem, size_t size, int flags, const c return NULL; } - for (type=IMB_FILE_TYPES; type->is_a; type++) { + for (type = IMB_FILE_TYPES; type->is_a; type++) { if (type->load) { - ibuf= type->load(mem, size, flags); + ibuf = type->load(mem, size, flags); if (ibuf) { if (flags & IB_premul) { IMB_premultiply_alpha(ibuf); @@ -87,15 +87,15 @@ ImBuf *IMB_loadifffile(int file, int flags, const char *descr) if (file == -1) return NULL; - size= BLI_file_descriptor_size(file); + size = BLI_file_descriptor_size(file); - mem= mmap(NULL, size, PROT_READ, MAP_SHARED, file, 0); - if (mem==(unsigned char*)-1) { + mem = mmap(NULL, size, PROT_READ, MAP_SHARED, file, 0); + if (mem == (unsigned char *)-1) { fprintf(stderr, "%s: couldn't get mapping %s\n", __func__, descr); return NULL; } - ibuf= IMB_ibImageFromMemory(mem, size, flags, descr); + ibuf = IMB_ibImageFromMemory(mem, size, flags, descr); if (munmap(mem, size)) fprintf(stderr, "%s: couldn't unmap file %s\n", __func__, descr); @@ -126,16 +126,16 @@ ImBuf *IMB_loadiffname(const char *filepath, int flags) imb_cache_filename(filepath_tx, filepath, flags); - file = BLI_open(filepath_tx, O_BINARY|O_RDONLY, 0); + file = BLI_open(filepath_tx, O_BINARY | O_RDONLY, 0); if (file < 0) return NULL; - ibuf= IMB_loadifffile(file, flags, filepath_tx); + ibuf = IMB_loadifffile(file, flags, filepath_tx); if (ibuf) { BLI_strncpy(ibuf->name, filepath, sizeof(ibuf->name)); BLI_strncpy(ibuf->cachename, filepath_tx, sizeof(ibuf->cachename)); - for (a=1; amiptot; a++) - BLI_strncpy(ibuf->mipmap[a-1]->cachename, filepath_tx, sizeof(ibuf->cachename)); + for (a = 1; a < ibuf->miptot; a++) + BLI_strncpy(ibuf->mipmap[a - 1]->cachename, filepath_tx, sizeof(ibuf->cachename)); if (flags & IB_fields) IMB_de_interlace(ibuf); } @@ -152,10 +152,10 @@ ImBuf *IMB_testiffname(const char *filepath, int flags) imb_cache_filename(filepath_tx, filepath, flags); - file = BLI_open(filepath_tx, O_BINARY|O_RDONLY, 0); + file = BLI_open(filepath_tx, O_BINARY | O_RDONLY, 0); if (file < 0) return NULL; - ibuf=IMB_loadifffile(file, flags|IB_test|IB_multilayer, filepath_tx); + ibuf = IMB_loadifffile(file, flags | IB_test | IB_multilayer, filepath_tx); if (ibuf) { BLI_strncpy(ibuf->name, filepath, sizeof(ibuf->name)); @@ -175,15 +175,15 @@ static void imb_loadtilefile(ImBuf *ibuf, int file, int tx, int ty, unsigned int if (file == -1) return; - size= BLI_file_descriptor_size(file); + size = BLI_file_descriptor_size(file); - mem= mmap(NULL, size, PROT_READ, MAP_SHARED, file, 0); - if (mem==(unsigned char*)-1) { + mem = mmap(NULL, size, PROT_READ, MAP_SHARED, file, 0); + if (mem == (unsigned char *)-1) { fprintf(stderr, "Couldn't get memory mapping for %s\n", ibuf->cachename); return; } - for (type=IMB_FILE_TYPES; type->is_a; type++) + for (type = IMB_FILE_TYPES; type->is_a; type++) if (type->load_tile && type->ftype(type, ibuf)) type->load_tile(ibuf, mem, size, tx, ty, rect); @@ -195,7 +195,7 @@ void imb_loadtile(ImBuf *ibuf, int tx, int ty, unsigned int *rect) { int file; - file = BLI_open(ibuf->cachename, O_BINARY|O_RDONLY, 0); + file = BLI_open(ibuf->cachename, O_BINARY | O_RDONLY, 0); if (file < 0) return; imb_loadtilefile(ibuf, file, tx, ty, rect); diff --git a/source/blender/imbuf/intern/targa.c b/source/blender/imbuf/intern/targa.c index 1a05dd93229..c690995d28a 100644 --- a/source/blender/imbuf/intern/targa.c +++ b/source/blender/imbuf/intern/targa.c @@ -50,8 +50,7 @@ /***/ -typedef struct TARGA -{ +typedef struct TARGA { unsigned char numid; unsigned char maptyp; unsigned char imgtyp; @@ -72,27 +71,27 @@ static int tga_out1(unsigned int data, FILE *file) { uchar *p; - p = (uchar *) & data; + p = (uchar *) &data; if (putc(p[0], file) == EOF) return(EOF); return (~EOF); } -static int tga_out2(unsigned int data, FILE * file) +static int tga_out2(unsigned int data, FILE *file) { uchar *p; - p = (uchar *) & data; + p = (uchar *) &data; if (putc(p[0], file) == EOF) return(EOF); if (putc(p[1], file) == EOF) return(EOF); return (~EOF); } -static int tga_out3(unsigned int data, FILE * file) +static int tga_out3(unsigned int data, FILE *file) { uchar *p; - p = (uchar *) & data; + p = (uchar *) &data; if (putc(p[2], file) == EOF) return(EOF); if (putc(p[1], file) == EOF) return(EOF); if (putc(p[0], file) == EOF) return(EOF); @@ -100,11 +99,11 @@ static int tga_out3(unsigned int data, FILE * file) } -static int tga_out4(unsigned int data, FILE * file) +static int tga_out4(unsigned int data, FILE *file) { uchar *p; - p = (uchar *) & data; + p = (uchar *) &data; /* order = bgra */ if (putc(p[2], file) == EOF) return(EOF); if (putc(p[1], file) == EOF) return(EOF); @@ -113,7 +112,7 @@ static int tga_out4(unsigned int data, FILE * file) return (~EOF); } -static short makebody_tga(ImBuf * ibuf, FILE * file, int (*out)(unsigned int, FILE*)) +static short makebody_tga(ImBuf *ibuf, FILE *file, int (*out)(unsigned int, FILE *)) { register int last, this; register int copy, bytes; @@ -125,22 +124,22 @@ static short makebody_tga(ImBuf * ibuf, FILE * file, int (*out)(unsigned int, FI rectstart = rect = ibuf->rect + (y * ibuf->x); last = *rect++; this = *rect++; - copy = last^this; + copy = last ^ this; while (bytes > 0) { if (copy) { do { last = this; this = *rect++; if (last == this) { - if (this == rect[-3]) { /* three the same? */ - bytes --; /* set bytes */ + if (this == rect[-3]) { /* three the same? */ + bytes--; /* set bytes */ break; } } } while (--bytes != 0); - copy = rect-rectstart; - copy --; + copy = rect - rectstart; + copy--; if (bytes) copy -= 2; temp = rect; @@ -148,9 +147,9 @@ static short makebody_tga(ImBuf * ibuf, FILE * file, int (*out)(unsigned int, FI while (copy) { last = copy; - if (copy>=128) last = 128; + if (copy >= 128) last = 128; copy -= last; - if (fputc(last-1, file) == EOF) return(0); + if (fputc(last - 1, file) == EOF) return(0); do { if (out(*rect++, file) == EOF) return(0); } while (--last != 0); @@ -162,17 +161,17 @@ static short makebody_tga(ImBuf * ibuf, FILE * file, int (*out)(unsigned int, FI copy = FALSE; } else { - while (*rect++ == this) { /* seek for first different byte */ - if (--bytes == 0) break; /* oor end of line */ + while (*rect++ == this) { /* seek for first different byte */ + if (--bytes == 0) break; /* oor end of line */ } - rect --; - copy = rect-rectstart; + rect--; + copy = rect - rectstart; rectstart = rect; - bytes --; + bytes--; this = *rect++; while (copy) { - if (copy>128) { + if (copy > 128) { if (fputc(255, file) == EOF) return(0); copy -= 128; } @@ -185,14 +184,14 @@ static short makebody_tga(ImBuf * ibuf, FILE * file, int (*out)(unsigned int, FI } if (out(last, file) == EOF) return(0); } - copy=TRUE; + copy = TRUE; } } } return (1); } -static int dumptarga(struct ImBuf * ibuf, FILE * file) +static int dumptarga(struct ImBuf *ibuf, FILE *file) { int size; uchar *rect; @@ -243,16 +242,16 @@ static int dumptarga(struct ImBuf * ibuf, FILE * file) } -int imb_savetarga(struct ImBuf * ibuf, const char *name, int flags) +int imb_savetarga(struct ImBuf *ibuf, const char *name, int flags) { - char buf[20]= {0}; + char buf[20] = {0}; FILE *fildes; short ok = 0; (void)flags; /* unused */ - buf[16] = (ibuf->planes + 0x7 ) & ~0x7; - if (ibuf->planes > 8 ) { + buf[16] = (ibuf->planes + 0x7) & ~0x7; + if (ibuf->planes > 8) { buf[2] = 10; } else { @@ -273,11 +272,11 @@ int imb_savetarga(struct ImBuf * ibuf, const char *name, int flags) /* Don't forget to indicate that your 32 bit * targa uses 8 bits for the alpha channel! */ - if (ibuf->planes==32) { + if (ibuf->planes == 32) { buf[17] |= 0x08; } fildes = BLI_fopen(name, "wb"); - if (!fildes) return 0; + if (!fildes) return 0; if (fwrite(buf, 1, 18, fildes) != 18) { fclose(fildes); @@ -289,18 +288,18 @@ int imb_savetarga(struct ImBuf * ibuf, const char *name, int flags) } else { switch ((ibuf->planes + 7) >> 3) { - case 1: - ok = makebody_tga(ibuf, fildes, tga_out1); - break; - case 2: - ok = makebody_tga(ibuf, fildes, tga_out2); - break; - case 3: - ok = makebody_tga(ibuf, fildes, tga_out3); - break; - case 4: - ok = makebody_tga(ibuf, fildes, tga_out4); - break; + case 1: + ok = makebody_tga(ibuf, fildes, tga_out1); + break; + case 2: + ok = makebody_tga(ibuf, fildes, tga_out2); + break; + case 3: + ok = makebody_tga(ibuf, fildes, tga_out3); + break; + case 4: + ok = makebody_tga(ibuf, fildes, tga_out4); + break; } } @@ -315,27 +314,27 @@ static int checktarga(TARGA *tga, unsigned char *mem) tga->maptyp = mem[1]; tga->imgtyp = mem[2]; - tga->maporig = GSS(mem+3); - tga->mapsize = GSS(mem+5); + tga->maporig = GSS(mem + 3); + tga->mapsize = GSS(mem + 5); tga->mapbits = mem[7]; - tga->xorig = GSS(mem+8); - tga->yorig = GSS(mem+10); - tga->xsize = GSS(mem+12); - tga->ysize = GSS(mem+14); + tga->xorig = GSS(mem + 8); + tga->yorig = GSS(mem + 10); + tga->xsize = GSS(mem + 12); + tga->ysize = GSS(mem + 14); tga->pixsize = mem[16]; tga->imgdes = mem[17]; if (tga->maptyp > 1) return(0); switch (tga->imgtyp) { - case 1: /* raw cmap */ - case 2: /* raw rgb */ - case 3: /* raw b&w */ - case 9: /* cmap */ - case 10: /* rgb */ - case 11: /* b&w */ - break; - default: - return(0); + case 1: /* raw cmap */ + case 2: /* raw rgb */ + case 3: /* raw b&w */ + case 9: /* cmap */ + case 10: /* rgb */ + case 11: /* b&w */ + break; + default: + return(0); } if (tga->mapsize && tga->mapbits > 32) return(0); if (tga->xsize <= 0 || tga->xsize >= 8192) return(0); @@ -356,7 +355,7 @@ static void complete_partial_load(struct ImBuf *ibuf, unsigned int *rect) { int size = (ibuf->x * ibuf->y) - (rect - ibuf->rect); if (size) { - printf("decodetarga: incomplete file, %.1f%% missing\n", 100*((float)size / (ibuf->x * ibuf->y))); + printf("decodetarga: incomplete file, %.1f%% missing\n", 100 * ((float)size / (ibuf->x * ibuf->y))); /* not essential but makes displaying partially rendered TGA's less ugly */ memset(rect, 0, size); @@ -369,10 +368,10 @@ static void complete_partial_load(struct ImBuf *ibuf, unsigned int *rect) static void decodetarga(struct ImBuf *ibuf, unsigned char *mem, size_t mem_size, int psize) { - unsigned char *mem_end = mem+mem_size; + unsigned char *mem_end = mem + mem_size; int count, col, size; unsigned int *rect; - uchar * cp = (uchar *) &col; + uchar *cp = (uchar *) &col; if (ibuf == NULL) return; if (ibuf->rect == NULL) return; @@ -387,7 +386,7 @@ static void decodetarga(struct ImBuf *ibuf, unsigned char *mem, size_t mem_size, while (size > 0) { count = *mem++; - if (mem>mem_end) + if (mem > mem_end) goto partial_load; if (count >= 128) { @@ -432,7 +431,7 @@ static void decodetarga(struct ImBuf *ibuf, unsigned char *mem, size_t mem_size, } } else { - count ++; + count++; size -= count; if (size >= 0) { while (count > 0) { @@ -465,13 +464,13 @@ static void decodetarga(struct ImBuf *ibuf, unsigned char *mem, size_t mem_size, } } *rect++ = col; - count --; + count--; - if (mem>mem_end) + if (mem > mem_end) goto partial_load; } - if (mem>mem_end) + if (mem > mem_end) goto partial_load; } } @@ -485,12 +484,12 @@ partial_load: complete_partial_load(ibuf, rect); } -static void ldtarga(struct ImBuf * ibuf, unsigned char * mem, size_t mem_size, int psize) +static void ldtarga(struct ImBuf *ibuf, unsigned char *mem, size_t mem_size, int psize) { - unsigned char *mem_end = mem+mem_size; + unsigned char *mem_end = mem + mem_size; int col, size; unsigned int *rect; - uchar * cp = (uchar *) &col; + uchar *cp = (uchar *) &col; if (ibuf == NULL) return; if (ibuf->rect == NULL) return; @@ -503,7 +502,7 @@ static void ldtarga(struct ImBuf * ibuf, unsigned char * mem, size_t mem_size, i cp[1] = cp[2] = 0; while (size > 0) { - if (mem>mem_end) + if (mem > mem_end) goto partial_load; if (psize & 2) { @@ -545,13 +544,12 @@ partial_load: } -struct ImBuf *imb_loadtarga(unsigned char *mem, size_t mem_size, int flags) -{ +struct ImBuf *imb_loadtarga(unsigned char *mem, size_t mem_size, int flags){ TARGA tga; - struct ImBuf * ibuf; + struct ImBuf *ibuf; int col, count, size; - unsigned int *rect, *cmap= NULL /*, mincol= 0*/, maxcol= 0; - uchar * cp = (uchar *) &col; + unsigned int *rect, *cmap = NULL /*, mincol= 0*/, maxcol = 0; + uchar *cp = (uchar *) &col; if (checktarga(&tga, mem) == 0) return(NULL); @@ -570,9 +568,9 @@ struct ImBuf *imb_loadtarga(unsigned char *mem, size_t mem_size, int flags) /* load color map */ /*mincol = tga.maporig;*/ /*UNUSED*/ maxcol = tga.mapsize; - cmap = MEM_callocN(sizeof(unsigned int)*maxcol, "targa cmap"); + cmap = MEM_callocN(sizeof(unsigned int) * maxcol, "targa cmap"); - for (count = 0 ; count < maxcol ; count ++) { + for (count = 0; count < maxcol; count++) { switch (tga.mapbits >> 3) { case 4: cp[0] = mem[3]; @@ -603,7 +601,7 @@ struct ImBuf *imb_loadtarga(unsigned char *mem, size_t mem_size, int flags) for (col = maxcol - 1; col > 0; col >>= 1) size++; ibuf->planes = size; - if (tga.mapbits != 32) { /* set alpha bits */ + if (tga.mapbits != 32) { /* set alpha bits */ cmap[0] &= BIG_LONG(0x00ffffffl); } } @@ -613,33 +611,33 @@ struct ImBuf *imb_loadtarga(unsigned char *mem, size_t mem_size, int flags) if (tga.imgtyp != 1 && tga.imgtyp != 9) { /* happens sometimes (beuh) */ if (cmap) { MEM_freeN(cmap); - cmap= NULL; + cmap = NULL; } } switch (tga.imgtyp) { - case 1: - case 2: - case 3: - if (tga.pixsize <= 8) ldtarga(ibuf, mem, mem_size, 0); - else if (tga.pixsize <= 16) ldtarga(ibuf, mem, mem_size, 1); - else if (tga.pixsize <= 24) ldtarga(ibuf, mem, mem_size, 2); - else if (tga.pixsize <= 32) ldtarga(ibuf, mem, mem_size, 3); - break; - case 9: - case 10: - case 11: - if (tga.pixsize <= 8) decodetarga(ibuf, mem, mem_size, 0); - else if (tga.pixsize <= 16) decodetarga(ibuf, mem, mem_size, 1); - else if (tga.pixsize <= 24) decodetarga(ibuf, mem, mem_size, 2); - else if (tga.pixsize <= 32) decodetarga(ibuf, mem, mem_size, 3); - break; + case 1: + case 2: + case 3: + if (tga.pixsize <= 8) ldtarga(ibuf, mem, mem_size, 0); + else if (tga.pixsize <= 16) ldtarga(ibuf, mem, mem_size, 1); + else if (tga.pixsize <= 24) ldtarga(ibuf, mem, mem_size, 2); + else if (tga.pixsize <= 32) ldtarga(ibuf, mem, mem_size, 3); + break; + case 9: + case 10: + case 11: + if (tga.pixsize <= 8) decodetarga(ibuf, mem, mem_size, 0); + else if (tga.pixsize <= 16) decodetarga(ibuf, mem, mem_size, 1); + else if (tga.pixsize <= 24) decodetarga(ibuf, mem, mem_size, 2); + else if (tga.pixsize <= 32) decodetarga(ibuf, mem, mem_size, 3); + break; } if (cmap) { /* apply color map */ rect = ibuf->rect; - for (size = ibuf->x * ibuf->y; size>0; --size, ++rect) { + for (size = ibuf->x * ibuf->y; size > 0; --size, ++rect) { col = *rect; if (col >= 0 && col < maxcol) *rect = cmap[col]; } @@ -651,8 +649,8 @@ struct ImBuf *imb_loadtarga(unsigned char *mem, size_t mem_size, int flags) rect = ibuf->rect; for (size = ibuf->x * ibuf->y; size > 0; --size, ++rect) { col = *rect; - cp = (uchar*)rect; - mem = (uchar*)&col; + cp = (uchar *)rect; + mem = (uchar *)&col; cp[3] = ((mem[1] << 1) & 0xf8); cp[2] = ((mem[0] & 0xe0) >> 2) + ((mem[1] & 0x03) << 6); @@ -672,7 +670,7 @@ struct ImBuf *imb_loadtarga(unsigned char *mem, size_t mem_size, int flags) crect = (uchar *) ibuf->rect; lrect = (unsigned int *) ibuf->rect; - for (size = ibuf->x * ibuf->y; size > 0; size --) { + for (size = ibuf->x * ibuf->y; size > 0; size--) { col = *lrect++; crect[0] = 255; diff --git a/source/blender/imbuf/intern/util.c b/source/blender/imbuf/intern/util.c index 99872192e32..4820347f048 100644 --- a/source/blender/imbuf/intern/util.c +++ b/source/blender/imbuf/intern/util.c @@ -93,7 +93,8 @@ const char *imb_ext_image[] = { #ifdef WITH_OPENEXR ".exr", #endif - NULL}; + NULL +}; const char *imb_ext_image_qt[] = { ".gif", @@ -101,7 +102,8 @@ const char *imb_ext_image_qt[] = { ".pct", ".pict", ".pntg", ".qtif", - NULL}; + NULL +}; const char *imb_ext_movie[] = { ".avi", @@ -128,7 +130,8 @@ const char *imb_ext_movie[] = { ".divx", ".xvid", ".mxf", - NULL}; + NULL +}; /* sort of wrong being here... */ const char *imb_ext_audio[] = { @@ -145,7 +148,8 @@ const char *imb_ext_audio[] = { ".aif", ".aiff", ".m4a", - NULL}; + NULL +}; static int IMB_ispic_name(const char *name) { @@ -160,7 +164,7 @@ static int IMB_ispic_name(const char *name) if (((st.st_mode) & S_IFMT) != S_IFREG) return FALSE; - if ((fp = BLI_open(name, O_BINARY|O_RDONLY, 0)) < 0) + if ((fp = BLI_open(name, O_BINARY | O_RDONLY, 0)) < 0) return FALSE; if (read(fp, buf, 32) != 32) { @@ -174,8 +178,8 @@ static int IMB_ispic_name(const char *name) if ((BIG_LONG(buf[0]) & 0xfffffff0) == 0xffd8ffe0) return JPG; - for (type=IMB_FILE_TYPES; type->is_a; type++) - if (type->is_a((uchar*)buf)) + for (type = IMB_FILE_TYPES; type->is_a; type++) + if (type->is_a((uchar *)buf)) return type->filetype; return FALSE; @@ -184,9 +188,9 @@ static int IMB_ispic_name(const char *name) int IMB_ispic(const char *filename) { if (U.uiflag & USER_FILTERFILEEXTS) { - if ( (BLI_testextensie_array(filename, imb_ext_image)) || - (G.have_quicktime && BLI_testextensie_array(filename, imb_ext_image_qt)) - ) { + if ( (BLI_testextensie_array(filename, imb_ext_image)) || + (G.have_quicktime && BLI_testextensie_array(filename, imb_ext_image_qt)) + ) { return IMB_ispic_name(filename); } else { @@ -200,15 +204,15 @@ int IMB_ispic(const char *filename) -static int isavi (const char *name) +static int isavi(const char *name) { - return AVI_is_avi (name); + return AVI_is_avi(name); } #ifdef WITH_QUICKTIME -static int isqtime (const char *name) +static int isqtime(const char *name) { - return anim_is_quicktime (name); + return anim_is_quicktime(name); } #endif @@ -241,7 +245,7 @@ void do_init_ffmpeg(void) } } -static int isffmpeg (const char *filename) +static int isffmpeg(const char *filename) { AVFormatContext *pFormatCtx; unsigned int i; @@ -252,24 +256,24 @@ static int isffmpeg (const char *filename) do_init_ffmpeg(); if (BLI_testextensie(filename, ".swf") || - BLI_testextensie(filename, ".jpg") || - BLI_testextensie(filename, ".png") || - BLI_testextensie(filename, ".dds") || - BLI_testextensie(filename, ".tga") || - BLI_testextensie(filename, ".bmp") || - BLI_testextensie(filename, ".exr") || - BLI_testextensie(filename, ".cin") || + BLI_testextensie(filename, ".jpg") || + BLI_testextensie(filename, ".png") || + BLI_testextensie(filename, ".dds") || + BLI_testextensie(filename, ".tga") || + BLI_testextensie(filename, ".bmp") || + BLI_testextensie(filename, ".exr") || + BLI_testextensie(filename, ".cin") || BLI_testextensie(filename, ".wav")) { return 0; } - if (av_open_input_file(&pFormatCtx, filename, NULL, 0, NULL)!=0) { + if (av_open_input_file(&pFormatCtx, filename, NULL, 0, NULL) != 0) { if (UTIL_DEBUG) fprintf(stderr, "isffmpeg: av_open_input_file failed\n"); return 0; } - if (av_find_stream_info(pFormatCtx)<0) { + if (av_find_stream_info(pFormatCtx) < 0) { if (UTIL_DEBUG) fprintf(stderr, "isffmpeg: av_find_stream_info failed\n"); av_close_input_file(pFormatCtx); return 0; @@ -278,32 +282,32 @@ static int isffmpeg (const char *filename) if (UTIL_DEBUG) av_dump_format(pFormatCtx, 0, filename, 0); - /* Find the first video stream */ - videoStream=-1; - for (i=0; inb_streams; i++) + /* Find the first video stream */ + videoStream = -1; + for (i = 0; i < pFormatCtx->nb_streams; i++) if (pFormatCtx->streams[i] && - pFormatCtx->streams[i]->codec && - (pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)) + pFormatCtx->streams[i]->codec && + (pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)) { - videoStream=i; + videoStream = i; break; } - if (videoStream==-1) { + if (videoStream == -1) { av_close_input_file(pFormatCtx); return 0; } pCodecCtx = pFormatCtx->streams[videoStream]->codec; - /* Find the decoder for the video stream */ - pCodec=avcodec_find_decoder(pCodecCtx->codec_id); - if (pCodec==NULL) { + /* Find the decoder for the video stream */ + pCodec = avcodec_find_decoder(pCodecCtx->codec_id); + if (pCodec == NULL) { av_close_input_file(pFormatCtx); return 0; } - if (avcodec_open(pCodecCtx, pCodec)<0) { + if (avcodec_open(pCodecCtx, pCodec) < 0) { av_close_input_file(pFormatCtx); return 0; } @@ -316,9 +320,9 @@ static int isffmpeg (const char *filename) #endif #ifdef WITH_REDCODE -static int isredcode(const char * filename) +static int isredcode(const char *filename) { - struct redcode_handle * h = redcode_open(filename); + struct redcode_handle *h = redcode_open(filename); if (!h) { return 0; } @@ -328,7 +332,7 @@ static int isredcode(const char * filename) #endif -int imb_get_anim_type(const char * name) +int imb_get_anim_type(const char *name) { int type; struct stat st; @@ -336,13 +340,13 @@ int imb_get_anim_type(const char * name) if (UTIL_DEBUG) printf("in getanimtype: %s\n", name); #ifndef _WIN32 -# ifdef WITH_QUICKTIME +# ifdef WITH_QUICKTIME if (isqtime(name)) return (ANIM_QTIME); -# endif -# ifdef WITH_FFMPEG +# endif +# ifdef WITH_FFMPEG /* stat test below fails on large files > 4GB */ if (isffmpeg(name)) return (ANIM_FFMPEG); -# endif +# endif if (BLI_stat(name, &st) == -1) return(0); if (((st.st_mode) & S_IFMT) != S_IFREG) return(0); @@ -354,12 +358,12 @@ int imb_get_anim_type(const char * name) if (((st.st_mode) & S_IFMT) != S_IFREG) return(0); if (ismovie(name)) return (ANIM_MOVIE); -# ifdef WITH_QUICKTIME +# ifdef WITH_QUICKTIME if (isqtime(name)) return (ANIM_QTIME); -# endif -# ifdef WITH_FFMPEG +# endif +# ifdef WITH_FFMPEG if (isffmpeg(name)) return (ANIM_FFMPEG); -# endif +# endif if (isavi(name)) return (ANIM_AVI); @@ -412,5 +416,5 @@ int IMB_isanim(const char *filename) type = imb_get_anim_type(filename); } - return (type && type!=ANIM_SEQUENCE); + return (type && type != ANIM_SEQUENCE); } diff --git a/source/blender/makesdna/DNA_texture_types.h b/source/blender/makesdna/DNA_texture_types.h index c026c2018fd..7497f5e7449 100644 --- a/source/blender/makesdna/DNA_texture_types.h +++ b/source/blender/makesdna/DNA_texture_types.h @@ -517,9 +517,10 @@ typedef struct ColorMapping { #define MTEX_LIN_LIGHT 16 /* brush_map_mode */ -#define MTEX_MAP_MODE_FIXED 0 +#define MTEX_MAP_MODE_VIEW 0 #define MTEX_MAP_MODE_TILED 1 #define MTEX_MAP_MODE_3D 2 +#define MTEX_MAP_MODE_AREA 3 /* **************** EnvMap ********************* */ diff --git a/source/blender/makesdna/intern/dna_genfile.c b/source/blender/makesdna/intern/dna_genfile.c index 472278340e5..80c80d02e06 100644 --- a/source/blender/makesdna/intern/dna_genfile.c +++ b/source/blender/makesdna/intern/dna_genfile.c @@ -496,7 +496,7 @@ static void init_structDNA(SDNA *sdna, int do_endian_swap) #ifdef WITH_DNA_GHASH /* create a ghash lookup to speed up */ - sdna->structs_map = BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp, "init_structDNA gh"); + sdna->structs_map = BLI_ghash_str_new("init_structDNA gh"); for (nr = 0; nr < sdna->nr_structs; nr++) { sp = sdna->structs[nr]; diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 3079ba8c8d8..0a07887f196 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -74,7 +74,7 @@ void RNA_init(void) for (srna = BLENDER_RNA.structs.first; srna; srna = srna->cont.next) { if (!srna->cont.prophash) { - srna->cont.prophash = BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp, "RNA_init gh"); + srna->cont.prophash = BLI_ghash_str_new("RNA_init gh"); for (prop = srna->cont.properties.first; prop; prop = prop->next) if (!(prop->flag & PROP_BUILTIN)) diff --git a/source/blender/makesrna/intern/rna_armature.c b/source/blender/makesrna/intern/rna_armature.c index 45887a2264d..16328c4f864 100644 --- a/source/blender/makesrna/intern/rna_armature.c +++ b/source/blender/makesrna/intern/rna_armature.c @@ -492,10 +492,12 @@ static void rna_def_bone_common(StructRNA *srna, int editbone) "(useful for non-obstructive custom bone shapes)"); RNA_def_property_update(prop, 0, "rna_Armature_redraw_data"); + /* XXX: use_cyclic_offset is deprecated in 2.5. May/may not return */ prop = RNA_def_property(srna, "use_cyclic_offset", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", BONE_NO_CYCLICOFFSET); RNA_def_property_ui_text(prop, "Cyclic Offset", - "When bone doesn't have a parent, it receives cyclic offset effects"); + "When bone doesn't have a parent, it receives cyclic offset effects (Deprecated)"); + // "When bone doesn't have a parent, it receives cyclic offset effects"); RNA_def_property_update(prop, 0, "rna_Armature_update_data"); prop = RNA_def_property(srna, "hide_select", PROP_BOOLEAN, PROP_NONE); diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c index 893dd7a9707..2247e7cf5a8 100644 --- a/source/blender/makesrna/intern/rna_brush.c +++ b/source/blender/makesrna/intern/rna_brush.c @@ -142,6 +142,14 @@ static int rna_SculptCapabilities_has_normal_weight_get(PointerRNA *ptr) return ELEM(br->sculpt_tool, SCULPT_TOOL_GRAB, SCULPT_TOOL_SNAKE_HOOK); } +static int rna_SculptCapabilities_has_overlay_get(PointerRNA *ptr) +{ + Brush *br = (Brush *)ptr->data; + return ELEM(br->mtex.brush_map_mode, + MTEX_MAP_MODE_VIEW, + MTEX_MAP_MODE_TILED); +} + static int rna_SculptCapabilities_has_persistence_get(PointerRNA *ptr) { Brush *br = (Brush *)ptr->data; @@ -164,7 +172,9 @@ static int rna_SculptCapabilities_has_plane_offset_get(PointerRNA *ptr) static int rna_SculptCapabilities_has_random_texture_angle_get(PointerRNA *ptr) { Brush *br = (Brush *)ptr->data; - return ((br->mtex.brush_map_mode == MTEX_MAP_MODE_FIXED) && + return (ELEM(br->mtex.brush_map_mode, + MTEX_MAP_MODE_VIEW, + MTEX_MAP_MODE_AREA) && !(br->flag & BRUSH_ANCHORED) && !ELEM4(br->sculpt_tool, SCULPT_TOOL_GRAB, SCULPT_TOOL_ROTATE, @@ -222,6 +232,23 @@ static int rna_SculptCapabilities_has_strength_get(PointerRNA *ptr) return !ELEM(br->sculpt_tool, SCULPT_TOOL_GRAB, SCULPT_TOOL_SNAKE_HOOK); } +static int rna_SculptCapabilities_has_texture_angle_get(PointerRNA *ptr) +{ + Brush *br = (Brush *)ptr->data; + return ELEM3(br->mtex.brush_map_mode, + MTEX_MAP_MODE_VIEW, + MTEX_MAP_MODE_AREA, + MTEX_MAP_MODE_TILED); +} + +static int rna_SculptCapabilities_has_texture_angle_source_get(PointerRNA *ptr) +{ + Brush *br = (Brush *)ptr->data; + return ELEM(br->mtex.brush_map_mode, + MTEX_MAP_MODE_VIEW, + MTEX_MAP_MODE_AREA); +} + static PointerRNA rna_Brush_sculpt_capabilities_get(PointerRNA *ptr) { return rna_pointer_inherit_refine(ptr, &RNA_SculptCapabilities, ptr->id.data); @@ -393,7 +420,8 @@ static void rna_def_brush_texture_slot(BlenderRNA *brna) PropertyRNA *prop; static EnumPropertyItem prop_map_mode_items[] = { - {MTEX_MAP_MODE_FIXED, "FIXED", 0, "Fixed", ""}, + {MTEX_MAP_MODE_VIEW, "VIEW_PLANE", 0, "View Plane", ""}, + {MTEX_MAP_MODE_AREA, "AREA_PLANE", 0, "Area Plane", ""}, {MTEX_MAP_MODE_TILED, "TILED", 0, "Tiled", ""}, {MTEX_MAP_MODE_3D, "3D", 0, "3D", ""}, {0, NULL, 0, NULL, NULL} @@ -441,6 +469,7 @@ static void rna_def_sculpt_capabilities(BlenderRNA *brna) BRUSH_CAPABILITY(has_height, "Has Height"); BRUSH_CAPABILITY(has_jitter, "Has Jitter"); BRUSH_CAPABILITY(has_normal_weight, "Has Crease/Pinch Factor"); + BRUSH_CAPABILITY(has_overlay, "Has Overlay"); BRUSH_CAPABILITY(has_persistence, "Has Persistence"); BRUSH_CAPABILITY(has_pinch_factor, "Has Pinch Factor"); BRUSH_CAPABILITY(has_plane_offset, "Has Plane Offset"); @@ -451,6 +480,8 @@ static void rna_def_sculpt_capabilities(BlenderRNA *brna) BRUSH_CAPABILITY(has_space_attenuation, "Has Space Attenuation"); BRUSH_CAPABILITY(has_spacing, "Has Spacing"); BRUSH_CAPABILITY(has_strength, "Has Strength"); + BRUSH_CAPABILITY(has_texture_angle, "Has Texture Angle"); + BRUSH_CAPABILITY(has_texture_angle_source, "Has Texture Angle Source"); #undef SCULPT_CAPABILITY } diff --git a/source/blender/makesrna/intern/rna_color.c b/source/blender/makesrna/intern/rna_color.c index 76116602711..381d0f46c28 100644 --- a/source/blender/makesrna/intern/rna_color.c +++ b/source/blender/makesrna/intern/rna_color.c @@ -320,18 +320,14 @@ static void rna_def_curvemappoint(BlenderRNA *brna) srna = RNA_def_struct(brna, "CurveMapPoint", NULL); RNA_def_struct_ui_text(srna, "CurveMapPoint", "Point of a curve used for a curve mapping"); - /* not editable for now, need to have CurveMapping to do curvemapping_changed */ - prop = RNA_def_property(srna, "location", PROP_FLOAT, PROP_XYZ); RNA_def_property_float_sdna(prop, NULL, "x"); RNA_def_property_array(prop, 2); - RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Location", "X/Y coordinates of the curve point"); prop = RNA_def_property(srna, "handle_type", PROP_ENUM, PROP_NONE); RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag"); RNA_def_property_enum_items(prop, prop_handle_type_items); - RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Handle Type", "Curve interpolation at this point: Bezier or vector"); prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE); @@ -339,10 +335,38 @@ static void rna_def_curvemappoint(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Select", "Selection state of the curve point"); } +static void rna_def_curvemap_points_api(BlenderRNA *brna, PropertyRNA *cprop) +{ + StructRNA *srna; + PropertyRNA *parm; + FunctionRNA *func; + + RNA_def_property_srna(cprop, "CurveMapPoints"); + srna = RNA_def_struct(brna, "CurveMapPoints", NULL); + RNA_def_struct_sdna(srna, "CurveMap"); + RNA_def_struct_ui_text(srna, "Curve Map Point", "Collection of Curve Map Points"); + + func = RNA_def_function(srna, "new", "curvemap_insert"); + RNA_def_function_ui_description(func, "Add point to CurveMap"); + parm = RNA_def_float(func, "position", 0.0f, -FLT_MAX, FLT_MAX, "Position", "Position to add point", -FLT_MAX, FLT_MAX); + RNA_def_property_flag(parm, PROP_REQUIRED); + parm = RNA_def_float(func, "value", 0.0f, -FLT_MAX, FLT_MAX, "Value", "Value of point", -FLT_MAX, FLT_MAX); + RNA_def_property_flag(parm, PROP_REQUIRED); + parm = RNA_def_pointer(func, "point", "CurveMapPoint", "", "New point"); + RNA_def_function_return(func, parm); + + func = RNA_def_function(srna, "remove", "curvemap_remove_point"); + RNA_def_function_ui_description(func, "Delete point from CurveMap"); + parm = RNA_def_pointer(func, "point", "CurveMapPoint", "", "PointElement to remove"); + RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL); +} + static void rna_def_curvemap(BlenderRNA *brna) { StructRNA *srna; - PropertyRNA *prop; + PropertyRNA *prop, *parm; + FunctionRNA *func; + static EnumPropertyItem prop_extend_items[] = { {0, "HORIZONTAL", 0, "Horizontal", ""}, {CUMA_EXTEND_EXTRAPOLATE, "EXTRAPOLATED", 0, "Extrapolated", ""}, @@ -352,24 +376,30 @@ static void rna_def_curvemap(BlenderRNA *brna) srna = RNA_def_struct(brna, "CurveMap", NULL); RNA_def_struct_ui_text(srna, "CurveMap", "Curve in a curve mapping"); - /* not editable for now, need to have CurveMapping to do curvemapping_changed */ - prop = RNA_def_property(srna, "extend", PROP_ENUM, PROP_NONE); RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag"); RNA_def_property_enum_items(prop, prop_extend_items); - RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Extend", "Extrapolate the curve or extend it horizontally"); prop = RNA_def_property(srna, "points", PROP_COLLECTION, PROP_NONE); RNA_def_property_collection_sdna(prop, NULL, "curve", "totpoint"); RNA_def_property_struct_type(prop, "CurveMapPoint"); RNA_def_property_ui_text(prop, "Points", ""); + rna_def_curvemap_points_api(brna, prop); + + func = RNA_def_function(srna, "evaluate", "curvemap_evaluateF"); + RNA_def_function_ui_description(func, "Evaluate curve at given location"); + parm = RNA_def_float(func, "position", 0.0f, -FLT_MAX, FLT_MAX, "Position", "Position to evaluate curve at", -FLT_MAX, FLT_MAX); + RNA_def_property_flag(parm, PROP_REQUIRED); + parm = RNA_def_float(func, "value", 0.0f, -FLT_MAX, FLT_MAX, "Value", "Value of curve at given location", -FLT_MAX, FLT_MAX); + RNA_def_function_return(func, parm); } static void rna_def_curvemapping(BlenderRNA *brna) { StructRNA *srna; PropertyRNA *prop; + FunctionRNA *func; srna = RNA_def_struct(brna, "CurveMapping", NULL); RNA_def_struct_ui_text(srna, "CurveMapping", @@ -423,6 +453,9 @@ static void rna_def_curvemapping(BlenderRNA *brna) RNA_def_property_range(prop, -1000.0f, 1000.0f); RNA_def_property_ui_text(prop, "White Level", "For RGB curves, the color that white is mapped to"); RNA_def_property_float_funcs(prop, NULL, "rna_CurveMapping_white_level_set", NULL); + + func = RNA_def_function(srna, "update", "curvemapping_changed_all"); + RNA_def_function_ui_description(func, "Update curve mapping after making changes"); } static void rna_def_color_ramp_element(BlenderRNA *brna) diff --git a/source/blender/makesrna/intern/rna_sequencer_api.c b/source/blender/makesrna/intern/rna_sequencer_api.c index 38a923f87e5..41c6f046c04 100644 --- a/source/blender/makesrna/intern/rna_sequencer_api.c +++ b/source/blender/makesrna/intern/rna_sequencer_api.c @@ -316,19 +316,34 @@ static StripElem *rna_SequenceElements_push(ID *id, Sequence *seq, const char *f return se; } -static void rna_SequenceElements_pop(ID *id, Sequence *seq, ReportList *reports) +static void rna_SequenceElements_pop(ID *id, Sequence *seq, ReportList *reports, int index) { + int i; Scene *scene = (Scene *)id; + StripElem *new_seq, *se; if (seq->len == 1) { BKE_report(reports, RPT_ERROR, "SequenceElements.pop: can not pop the last element"); return; } - /* just chop off the end ...what could possibly go wrong? */ - seq->strip->stripdata = MEM_reallocN(seq->strip->stripdata, sizeof(StripElem) * (seq->len - 1)); + if (seq->len <= index) { + BKE_report(reports, RPT_ERROR, "SequenceElements.pop: index out of range"); + return; + } + + new_seq = MEM_callocN(sizeof(StripElem) * (seq->len - 1), "SequenceElements_pop"); seq->len--; + for (i = 0, se = seq->strip->stripdata; i < seq->len; i++, se++) { + if (i == index) + se++; + BLI_strncpy(new_seq[i].name, se->name, sizeof(se->name)); + } + + MEM_freeN(seq->strip->stripdata); + seq->strip->stripdata = new_seq; + calc_sequence_disp(scene, seq); WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, scene); @@ -379,6 +394,8 @@ void RNA_api_sequence_elements(BlenderRNA *brna, PropertyRNA *cprop) func = RNA_def_function(srna, "pop", "rna_SequenceElements_pop"); RNA_def_function_flag(func, FUNC_USE_REPORTS | FUNC_USE_SELF_ID); RNA_def_function_ui_description(func, "Pop an image off the collection"); + parm = RNA_def_int(func, "index", 0, 0, INT_MAX, "", "Index of image to remove", 0, INT_MAX); + RNA_def_property_flag(parm, PROP_REQUIRED); } void RNA_api_sequences(BlenderRNA *brna, PropertyRNA *cprop) diff --git a/source/blender/modifiers/intern/MOD_boolean_util.c b/source/blender/modifiers/intern/MOD_boolean_util.c index 39344aad5a9..1b4d9444fd9 100644 --- a/source/blender/modifiers/intern/MOD_boolean_util.c +++ b/source/blender/modifiers/intern/MOD_boolean_util.c @@ -381,7 +381,7 @@ static DerivedMesh *ConvertCSGDescriptorsToDerivedMesh( } // a hash table to remap materials to indices - material_hash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "CSG_mat gh"); + material_hash = BLI_ghash_ptr_new("CSG_mat gh"); if (mat) *totmat = 0; diff --git a/source/blender/modifiers/intern/MOD_build.c b/source/blender/modifiers/intern/MOD_build.c index 9285ec6674c..121b0ee89e3 100644 --- a/source/blender/modifiers/intern/MOD_build.c +++ b/source/blender/modifiers/intern/MOD_build.c @@ -90,13 +90,10 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob), MLoop *ml_dst, *ml_src /*, *mloop_dst */; GHashIterator *hashIter; /* maps vert indices in old mesh to indices in new mesh */ - GHash *vertHash = BLI_ghash_new(BLI_ghashutil_inthash, - BLI_ghashutil_intcmp, "build ve apply gh"); + GHash *vertHash = BLI_ghash_int_new("build ve apply gh"); /* maps edge indices in new mesh to indices in old mesh */ - GHash *edgeHash = BLI_ghash_new(BLI_ghashutil_inthash, - BLI_ghashutil_intcmp, "build ed apply gh"); - GHash *edgeHash2 = BLI_ghash_new(BLI_ghashutil_inthash, - BLI_ghashutil_intcmp, "build ed apply gh"); + GHash *edgeHash = BLI_ghash_int_new("build ed apply gh"); + GHash *edgeHash2 = BLI_ghash_int_new("build ed apply gh"); const int numVert_src = dm->getNumVerts(dm); const int numEdge_src = dm->getNumEdges(dm); diff --git a/source/blender/modifiers/intern/MOD_mask.c b/source/blender/modifiers/intern/MOD_mask.c index 396e48df50c..5206aa281f7 100644 --- a/source/blender/modifiers/intern/MOD_mask.c +++ b/source/blender/modifiers/intern/MOD_mask.c @@ -167,7 +167,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, * - vgroups to indices -> vgroupHash (string, int) * - bones to vgroup indices -> boneHash (index of vgroup, dummy) */ - vgroupHash = BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp, "mask vgroup gh"); + vgroupHash = BLI_ghash_str_new("mask vgroup gh"); /* build mapping of names of vertex groups to indices */ for (i = 0, def = ob->defbase.first; def; def = def->next, i++) @@ -191,7 +191,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, } /* hashes for quickly providing a mapping from old to new - use key=oldindex, value=newindex */ - vertHash = BLI_ghash_new(BLI_ghashutil_inthash, BLI_ghashutil_intcmp, "mask vert gh"); + vertHash = BLI_ghash_int_new("mask vert gh"); /* add vertices which exist in vertexgroups into vertHash for filtering */ for (i = 0, dv = dvert; i < maxVerts; i++, dv++) { @@ -239,7 +239,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, return dm; /* hashes for quickly providing a mapping from old to new - use key=oldindex, value=newindex */ - vertHash = BLI_ghash_new(BLI_ghashutil_inthash, BLI_ghashutil_intcmp, "mask vert2 bh"); + vertHash = BLI_ghash_int_new("mask vert2 bh"); /* add vertices which exist in vertexgroup into ghash for filtering */ for (i = 0, dv = dvert; i < maxVerts; i++, dv++) { @@ -262,8 +262,8 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, } /* hashes for quickly providing a mapping from old to new - use key=oldindex, value=newindex */ - edgeHash = BLI_ghash_new(BLI_ghashutil_inthash, BLI_ghashutil_intcmp, "mask ed2 gh"); - polyHash = BLI_ghash_new(BLI_ghashutil_inthash, BLI_ghashutil_intcmp, "mask fa2 gh"); + edgeHash = BLI_ghash_int_new("mask ed2 gh"); + polyHash = BLI_ghash_int_new("mask fa2 gh"); mpoly = dm->getPolyArray(dm); mloop = dm->getLoopArray(dm); diff --git a/source/blender/modifiers/intern/MOD_mirror.c b/source/blender/modifiers/intern/MOD_mirror.c index 5c9c4e76076..6f3d47b3426 100644 --- a/source/blender/modifiers/intern/MOD_mirror.c +++ b/source/blender/modifiers/intern/MOD_mirror.c @@ -258,7 +258,7 @@ static DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd, MLoopUV *dmloopuv = CustomData_get_layer_n(&result->loopData, CD_MLOOPUV, a); int j = maxLoops; dmloopuv += j; /* second set of loops only */ - for (; i-- > 0; dmloopuv++) { + for (; j-- > 0; dmloopuv++) { if (do_mirr_u) dmloopuv->uv[0] = 1.0f - dmloopuv->uv[0]; if (do_mirr_v) dmloopuv->uv[1] = 1.0f - dmloopuv->uv[1]; } diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 6c1e811aae0..f20e029c7b6 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -176,13 +176,13 @@ static GHash *id_weakref_pool_get(ID *id) } else { /* first time, allocate pool */ - id_weakref_pool = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "rna_global_pool"); + id_weakref_pool = BLI_ghash_ptr_new("rna_global_pool"); weakinfo_hash = NULL; } if (weakinfo_hash == NULL) { /* we're using a ghash as a set, could use libHX's HXMAP_SINGULAR but would be an extra dep. */ - weakinfo_hash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "rna_id"); + weakinfo_hash = BLI_ghash_ptr_new("rna_id"); BLI_ghash_insert(id_weakref_pool, (void *)id, weakinfo_hash); } diff --git a/source/blender/python/intern/bpy_rna_callback.c b/source/blender/python/intern/bpy_rna_callback.c index 13532b24e55..f7114115a91 100644 --- a/source/blender/python/intern/bpy_rna_callback.c +++ b/source/blender/python/intern/bpy_rna_callback.c @@ -107,7 +107,7 @@ PyObject *pyrna_callback_add(BPy_StructRNA *self, PyObject *args) Py_INCREF(args); } else { - PyErr_SetString(PyExc_TypeError, "callback_add(): type does not suppport callbacks"); + PyErr_SetString(PyExc_TypeError, "callback_add(): type does not support callbacks"); return NULL; } diff --git a/source/blender/render/intern/raytrace/bvh.h b/source/blender/render/intern/raytrace/bvh.h index c2e18a9236e..fab0bb94618 100644 --- a/source/blender/render/intern/raytrace/bvh.h +++ b/source/blender/render/intern/raytrace/bvh.h @@ -59,12 +59,12 @@ inline int test_bb_group4(__m128 *bb_group, const Isect *isec) copy_v3_v3(start, isec->start); copy_v3_v3(idot_axis, isec->idot_axis); - const __m128 tmin1 = _mm_max_ps(tmin0, _mm_mul_ps( _mm_sub_ps( bb_group[isec->bv_index[0]], _mm_set_ps1(start[0]) ), _mm_set_ps1(idot_axis[0])) ); - const __m128 tmax1 = _mm_min_ps(tmax0, _mm_mul_ps( _mm_sub_ps( bb_group[isec->bv_index[1]], _mm_set_ps1(start[0]) ), _mm_set_ps1(idot_axis[0])) ); - const __m128 tmin2 = _mm_max_ps(tmin1, _mm_mul_ps( _mm_sub_ps( bb_group[isec->bv_index[2]], _mm_set_ps1(start[1]) ), _mm_set_ps1(idot_axis[1])) ); - const __m128 tmax2 = _mm_min_ps(tmax1, _mm_mul_ps( _mm_sub_ps( bb_group[isec->bv_index[3]], _mm_set_ps1(start[1]) ), _mm_set_ps1(idot_axis[1])) ); - const __m128 tmin3 = _mm_max_ps(tmin2, _mm_mul_ps( _mm_sub_ps( bb_group[isec->bv_index[4]], _mm_set_ps1(start[2]) ), _mm_set_ps1(idot_axis[2])) ); - const __m128 tmax3 = _mm_min_ps(tmax2, _mm_mul_ps( _mm_sub_ps( bb_group[isec->bv_index[5]], _mm_set_ps1(start[2]) ), _mm_set_ps1(idot_axis[2])) ); + const __m128 tmin1 = _mm_max_ps(tmin0, _mm_mul_ps(_mm_sub_ps(bb_group[isec->bv_index[0]], _mm_set_ps1(start[0]) ), _mm_set_ps1(idot_axis[0])) ); + const __m128 tmax1 = _mm_min_ps(tmax0, _mm_mul_ps(_mm_sub_ps(bb_group[isec->bv_index[1]], _mm_set_ps1(start[0]) ), _mm_set_ps1(idot_axis[0])) ); + const __m128 tmin2 = _mm_max_ps(tmin1, _mm_mul_ps(_mm_sub_ps(bb_group[isec->bv_index[2]], _mm_set_ps1(start[1]) ), _mm_set_ps1(idot_axis[1])) ); + const __m128 tmax2 = _mm_min_ps(tmax1, _mm_mul_ps(_mm_sub_ps(bb_group[isec->bv_index[3]], _mm_set_ps1(start[1]) ), _mm_set_ps1(idot_axis[1])) ); + const __m128 tmin3 = _mm_max_ps(tmin2, _mm_mul_ps(_mm_sub_ps(bb_group[isec->bv_index[4]], _mm_set_ps1(start[2]) ), _mm_set_ps1(idot_axis[2])) ); + const __m128 tmax3 = _mm_min_ps(tmax2, _mm_mul_ps(_mm_sub_ps(bb_group[isec->bv_index[5]], _mm_set_ps1(start[2]) ), _mm_set_ps1(idot_axis[2])) ); return _mm_movemask_ps(_mm_cmpge_ps(tmax3, tmin3)); } @@ -142,7 +142,7 @@ static float bvh_cost(Tree *obj) /* bvh tree nodes generics */ template static inline int bvh_node_hit_test(Node *node, Isect *isec) { - return rayobject_bb_intersect_test(isec, (const float*)node->bb); + return rayobject_bb_intersect_test(isec, (const float *)node->bb); } @@ -185,7 +185,7 @@ static int bvh_node_stack_raycast(Node *root, Isect *isec) } } else { - hit |= RE_rayobject_intersect( (RayObject*)node, isec); + hit |= RE_rayobject_intersect( (RayObject *)node, isec); if (SHADOW && hit) return hit; } } @@ -211,84 +211,84 @@ static int bvh_node_stack_raycast_simd(Node *root, Isect *isec) if (!is_leaf(root->child)) bvh_node_push_childs(root, isec, stack, stack_pos); else - return RE_rayobject_intersect( (RayObject*)root->child, isec); + return RE_rayobject_intersect( (RayObject *)root->child, isec); } else - return RE_rayobject_intersect( (RayObject*)root, isec); + return RE_rayobject_intersect( (RayObject *)root, isec); } else { if (!is_leaf(root)) stack[stack_pos++] = root; else - return RE_rayobject_intersect( (RayObject*)root, isec); + return RE_rayobject_intersect( (RayObject *)root, isec); } while (true) { //Use SIMD 4 if (stack_pos >= 4) { __m128 t_bb[6]; - Node * t_node[4]; + Node *t_node[4]; stack_pos -= 4; /* prepare the 4BB for SIMD */ - t_node[0] = stack[stack_pos+0]->child; - t_node[1] = stack[stack_pos+1]->child; - t_node[2] = stack[stack_pos+2]->child; - t_node[3] = stack[stack_pos+3]->child; - - const float *bb0 = stack[stack_pos+0]->bb; - const float *bb1 = stack[stack_pos+1]->bb; - const float *bb2 = stack[stack_pos+2]->bb; - const float *bb3 = stack[stack_pos+3]->bb; - - const __m128 x0y0x1y1 = _mm_shuffle_ps( _mm_load_ps(bb0), _mm_load_ps(bb1), _MM_SHUFFLE(1, 0, 1, 0) ); - const __m128 x2y2x3y3 = _mm_shuffle_ps( _mm_load_ps(bb2), _mm_load_ps(bb3), _MM_SHUFFLE(1, 0, 1, 0) ); - t_bb[0] = _mm_shuffle_ps( x0y0x1y1, x2y2x3y3, _MM_SHUFFLE(2, 0, 2, 0) ); - t_bb[1] = _mm_shuffle_ps( x0y0x1y1, x2y2x3y3, _MM_SHUFFLE(3, 1, 3, 1) ); + t_node[0] = stack[stack_pos + 0]->child; + t_node[1] = stack[stack_pos + 1]->child; + t_node[2] = stack[stack_pos + 2]->child; + t_node[3] = stack[stack_pos + 3]->child; - const __m128 z0X0z1X1 = _mm_shuffle_ps( _mm_load_ps(bb0), _mm_load_ps(bb1), _MM_SHUFFLE(3, 2, 3, 2) ); - const __m128 z2X2z3X3 = _mm_shuffle_ps( _mm_load_ps(bb2), _mm_load_ps(bb3), _MM_SHUFFLE(3, 2, 3, 2) ); - t_bb[2] = _mm_shuffle_ps( z0X0z1X1, z2X2z3X3, _MM_SHUFFLE(2, 0, 2, 0) ); - t_bb[3] = _mm_shuffle_ps( z0X0z1X1, z2X2z3X3, _MM_SHUFFLE(3, 1, 3, 1) ); + const float *bb0 = stack[stack_pos + 0]->bb; + const float *bb1 = stack[stack_pos + 1]->bb; + const float *bb2 = stack[stack_pos + 2]->bb; + const float *bb3 = stack[stack_pos + 3]->bb; - const __m128 Y0Z0Y1Z1 = _mm_shuffle_ps( _mm_load_ps(bb0+4), _mm_load_ps(bb1+4), _MM_SHUFFLE(1, 0, 1, 0) ); - const __m128 Y2Z2Y3Z3 = _mm_shuffle_ps( _mm_load_ps(bb2+4), _mm_load_ps(bb3+4), _MM_SHUFFLE(1, 0, 1, 0) ); - t_bb[4] = _mm_shuffle_ps( Y0Z0Y1Z1, Y2Z2Y3Z3, _MM_SHUFFLE(2, 0, 2, 0) ); - t_bb[5] = _mm_shuffle_ps( Y0Z0Y1Z1, Y2Z2Y3Z3, _MM_SHUFFLE(3, 1, 3, 1) ); + const __m128 x0y0x1y1 = _mm_shuffle_ps(_mm_load_ps(bb0), _mm_load_ps(bb1), _MM_SHUFFLE(1, 0, 1, 0) ); + const __m128 x2y2x3y3 = _mm_shuffle_ps(_mm_load_ps(bb2), _mm_load_ps(bb3), _MM_SHUFFLE(1, 0, 1, 0) ); + t_bb[0] = _mm_shuffle_ps(x0y0x1y1, x2y2x3y3, _MM_SHUFFLE(2, 0, 2, 0) ); + t_bb[1] = _mm_shuffle_ps(x0y0x1y1, x2y2x3y3, _MM_SHUFFLE(3, 1, 3, 1) ); + + const __m128 z0X0z1X1 = _mm_shuffle_ps(_mm_load_ps(bb0), _mm_load_ps(bb1), _MM_SHUFFLE(3, 2, 3, 2) ); + const __m128 z2X2z3X3 = _mm_shuffle_ps(_mm_load_ps(bb2), _mm_load_ps(bb3), _MM_SHUFFLE(3, 2, 3, 2) ); + t_bb[2] = _mm_shuffle_ps(z0X0z1X1, z2X2z3X3, _MM_SHUFFLE(2, 0, 2, 0) ); + t_bb[3] = _mm_shuffle_ps(z0X0z1X1, z2X2z3X3, _MM_SHUFFLE(3, 1, 3, 1) ); + + const __m128 Y0Z0Y1Z1 = _mm_shuffle_ps(_mm_load_ps(bb0 + 4), _mm_load_ps(bb1 + 4), _MM_SHUFFLE(1, 0, 1, 0) ); + const __m128 Y2Z2Y3Z3 = _mm_shuffle_ps(_mm_load_ps(bb2 + 4), _mm_load_ps(bb3 + 4), _MM_SHUFFLE(1, 0, 1, 0) ); + t_bb[4] = _mm_shuffle_ps(Y0Z0Y1Z1, Y2Z2Y3Z3, _MM_SHUFFLE(2, 0, 2, 0) ); + t_bb[5] = _mm_shuffle_ps(Y0Z0Y1Z1, Y2Z2Y3Z3, _MM_SHUFFLE(3, 1, 3, 1) ); #if 0 - for(int i=0; i<4; i++) + for (int i = 0; i < 4; i++) { - Node *t = stack[stack_pos+i]; + Node *t = stack[stack_pos + i]; assert(!is_leaf(t)); - float *bb = ((float*)t_bb)+i; - bb[4*0] = t->bb[0]; - bb[4*1] = t->bb[1]; - bb[4*2] = t->bb[2]; - bb[4*3] = t->bb[3]; - bb[4*4] = t->bb[4]; - bb[4*5] = t->bb[5]; + float *bb = ((float *)t_bb) + i; + bb[4 * 0] = t->bb[0]; + bb[4 * 1] = t->bb[1]; + bb[4 * 2] = t->bb[2]; + bb[4 * 3] = t->bb[3]; + bb[4 * 4] = t->bb[4]; + bb[4 * 5] = t->bb[5]; t_node[i] = t->child; } #endif RE_RC_COUNT(isec->raycounter->simd_bb.test); - int res = test_bb_group4( t_bb, isec ); + int res = test_bb_group4(t_bb, isec); for (int i = 0; i < 4; i++) - if (res & (1 << i)) { - RE_RC_COUNT(isec->raycounter->simd_bb.hit); - if (!is_leaf(t_node[i])) { - for (Node *t = t_node[i]; t; t = t->sibling) { - assert(stack_pos < MAX_STACK_SIZE); - stack[stack_pos++] = t; + if (res & (1 << i)) { + RE_RC_COUNT(isec->raycounter->simd_bb.hit); + if (!is_leaf(t_node[i])) { + for (Node *t = t_node[i]; t; t = t->sibling) { + assert(stack_pos < MAX_STACK_SIZE); + stack[stack_pos++] = t; + } + } + else { + hit |= RE_rayobject_intersect( (RayObject *)t_node[i], isec); + if (hit && isec->mode == RE_RAY_SHADOW) return hit; } } - else { - hit |= RE_rayobject_intersect( (RayObject*)t_node[i], isec); - if (hit && isec->mode == RE_RAY_SHADOW) return hit; - } - } } else if (stack_pos > 0) { Node *node = stack[--stack_pos]; @@ -300,7 +300,7 @@ static int bvh_node_stack_raycast_simd(Node *root, Isect *isec) assert(stack_pos <= MAX_STACK_SIZE); } else { - hit |= RE_rayobject_intersect( (RayObject*)node->child, isec); + hit |= RE_rayobject_intersect( (RayObject *)node->child, isec); if (hit && isec->mode == RE_RAY_SHADOW) return hit; } } @@ -324,7 +324,7 @@ static int bvh_node_raycast(Node *node, Isect *isec) if (isec->idot_axis[node->split_axis] > 0.0f) { int i; - for(i=0; ichild[i])) { if (node->child[i] == 0) break; @@ -332,16 +332,14 @@ static int bvh_node_raycast(Node *node, Isect *isec) hit |= bvh_node_raycast(node->child[i], isec); if (hit && isec->mode == RE_RAY_SHADOW) return hit; } - else - { - hit |= RE_rayobject_intersect( (RayObject*)node->child[i], isec); + else { + hit |= RE_rayobject_intersect( (RayObject *)node->child[i], isec); if (hit && isec->mode == RE_RAY_SHADOW) return hit; } } - else - { + else { int i; - for(i=BVH_NCHILDS-1; i>=0; i--) + for (i = BVH_NCHILDS - 1; i >= 0; i--) if (!is_leaf(node->child[i])) { if (node->child[i]) @@ -350,9 +348,8 @@ static int bvh_node_raycast(Node *node, Isect *isec) if (hit && isec->mode == RE_RAY_SHADOW) return hit; } } - else - { - hit |= RE_rayobject_intersect( (RayObject*)node->child[i], isec); + else { + hit |= RE_rayobject_intersect( (RayObject *)node->child[i], isec); if (hit && isec->mode == RE_RAY_SHADOW) return hit; } } @@ -367,44 +364,44 @@ void bvh_dfs_make_hint(Node *node, LCTSHint *hint, int reserve_space, HintObject assert(hint->size + reserve_space + 1 <= RE_RAY_LCTS_MAX_SIZE); if (is_leaf(node)) { - hint->stack[hint->size++] = (RayObject*)node; + hint->stack[hint->size++] = (RayObject *)node; } else { int childs = count_childs(node); if (hint->size + reserve_space + childs <= RE_RAY_LCTS_MAX_SIZE) { - int result = hint_test_bb(hintObject, node->bb, node->bb+3); + int result = hint_test_bb(hintObject, node->bb, node->bb + 3); if (result == HINT_RECURSE) { /* We are 100% sure the ray will be pass inside this node */ bvh_dfs_make_hint_push_siblings(node->child, hint, reserve_space, hintObject); } else if (result == HINT_ACCEPT) { - hint->stack[hint->size++] = (RayObject*)node; + hint->stack[hint->size++] = (RayObject *)node; } } else { - hint->stack[hint->size++] = (RayObject*)node; + hint->stack[hint->size++] = (RayObject *)node; } } } template -static RayObjectAPI* bvh_get_api(int maxstacksize); +static RayObjectAPI *bvh_get_api(int maxstacksize); template static inline RayObject *bvh_create_tree(int size) { - Tree *obj= (Tree*)MEM_callocN(sizeof(Tree), "BVHTree" ); + Tree *obj = (Tree *)MEM_callocN(sizeof(Tree), "BVHTree"); assert(RE_rayobject_isAligned(obj)); /* RayObject API assumes real data to be 4-byte aligned */ obj->rayobj.api = bvh_get_api(DFS_STACK_SIZE); obj->root = NULL; obj->node_arena = NULL; - obj->builder = rtbuild_create( size ); + obj->builder = rtbuild_create(size); - return RE_rayobject_unalignRayAPI((RayObject*) obj); + return RE_rayobject_unalignRayAPI((RayObject *) obj); } #endif diff --git a/source/blender/render/intern/raytrace/rayobject.cpp b/source/blender/render/intern/raytrace/rayobject.cpp index ac29d9e78ee..ca74367dd37 100644 --- a/source/blender/render/intern/raytrace/rayobject.cpp +++ b/source/blender/render/intern/raytrace/rayobject.cpp @@ -50,7 +50,7 @@ * because function is too long. Since this is code that is called billions * of times we really do want to inline. */ -MALWAYS_INLINE RayObject* rayface_from_coords(RayFace *rayface, void *ob, void *face, +MALWAYS_INLINE RayObject *rayface_from_coords(RayFace *rayface, void *ob, void *face, float *v1, float *v2, float *v3, float *v4) { rayface->ob = ob; @@ -85,14 +85,14 @@ MALWAYS_INLINE void rayface_from_vlak(RayFace *rayface, ObjectInstanceRen *obi, } } -RayObject* RE_rayface_from_vlak(RayFace *rayface, ObjectInstanceRen *obi, VlakRen *vlr) +RayObject *RE_rayface_from_vlak(RayFace *rayface, ObjectInstanceRen *obi, VlakRen *vlr) { return rayface_from_coords(rayface, obi, vlr, vlr->v1->co, vlr->v2->co, vlr->v3->co, vlr->v4 ? vlr->v4->co : 0); } /* VlakPrimitive */ -RayObject* RE_vlakprimitive_from_vlak(VlakPrimitive *face, struct ObjectInstanceRen *obi, struct VlakRen *vlr) +RayObject *RE_vlakprimitive_from_vlak(VlakPrimitive *face, struct ObjectInstanceRen *obi, struct VlakRen *vlr) { face->ob = obi; face->face = vlr; @@ -110,13 +110,13 @@ MALWAYS_INLINE int vlr_check_intersect(Isect *is, ObjectInstanceRen *obi, VlakRe return 0; /* I know... cpu cycle waste, might do smarter once */ - if (is->mode==RE_RAY_MIRROR) + if (is->mode == RE_RAY_MIRROR) return !(vlr->mat->mode & MA_ONLYCAST); else return (is->lay & obi->lay); } -MALWAYS_INLINE int vlr_check_intersect_solid(Isect *UNUSED(is), ObjectInstanceRen* UNUSED(obi), VlakRen *vlr) +MALWAYS_INLINE int vlr_check_intersect_solid(Isect *UNUSED(is), ObjectInstanceRen *UNUSED(obi), VlakRen *vlr) { /* solid material types only */ if (vlr->mat->material_type == MA_TYPE_SURFACE) @@ -125,7 +125,7 @@ MALWAYS_INLINE int vlr_check_intersect_solid(Isect *UNUSED(is), ObjectInstanceRe return 0; } -MALWAYS_INLINE int vlr_check_bake(Isect *is, ObjectInstanceRen* obi, VlakRen *UNUSED(vlr)) +MALWAYS_INLINE int vlr_check_bake(Isect *is, ObjectInstanceRen *obi, VlakRen *UNUSED(vlr)) { return (obi->obr->ob != is->userdata) && (obi->obr->ob->flag & SELECT); } @@ -138,7 +138,7 @@ MALWAYS_INLINE int isec_tri_quad(float start[3], float dir[3], RayFace *face, fl float t0[3], t1[3], x[3], r[3], m[3], u, v, divdet, det1, l; int quad; - quad= RE_rayface_isQuad(face); + quad = RE_rayface_isQuad(face); copy_v3_v3(co1, face->v1); copy_v3_v3(co2, face->v2); @@ -151,29 +151,29 @@ MALWAYS_INLINE int isec_tri_quad(float start[3], float dir[3], RayFace *face, fl sub_v3_v3v3(t1, co3, co1); cross_v3_v3v3(x, r, t1); - divdet= dot_v3v3(t0, x); + divdet = dot_v3v3(t0, x); sub_v3_v3v3(m, start, co3); - det1= dot_v3v3(m, x); + det1 = dot_v3v3(m, x); if (divdet != 0.0f) { - divdet= 1.0f/divdet; - v= det1*divdet; + divdet = 1.0f / divdet; + v = det1 * divdet; - if (v < RE_RAYTRACE_EPSILON && v > -(1.0f+RE_RAYTRACE_EPSILON)) { + if (v < RE_RAYTRACE_EPSILON && v > -(1.0f + RE_RAYTRACE_EPSILON)) { float cros[3]; cross_v3_v3v3(cros, m, t0); - u= divdet*dot_v3v3(cros, r); + u = divdet * dot_v3v3(cros, r); - if (u < RE_RAYTRACE_EPSILON && (v + u) > -(1.0f+RE_RAYTRACE_EPSILON)) { - l= divdet*dot_v3v3(cros, t1); + if (u < RE_RAYTRACE_EPSILON && (v + u) > -(1.0f + RE_RAYTRACE_EPSILON)) { + l = divdet * dot_v3v3(cros, t1); /* check if intersection is within ray length */ if (l > -RE_RAYTRACE_EPSILON && l < *lambda) { - uv[0]= u; - uv[1]= v; - *lambda= l; + uv[0] = u; + uv[1] = v; + *lambda = l; return 1; } } @@ -184,25 +184,25 @@ MALWAYS_INLINE int isec_tri_quad(float start[3], float dir[3], RayFace *face, fl if (quad) { copy_v3_v3(co4, face->v4); sub_v3_v3v3(t0, co3, co4); - divdet= dot_v3v3(t0, x); + divdet = dot_v3v3(t0, x); if (divdet != 0.0f) { - divdet= 1.0f/divdet; - v = det1*divdet; + divdet = 1.0f / divdet; + v = det1 * divdet; - if (v < RE_RAYTRACE_EPSILON && v > -(1.0f+RE_RAYTRACE_EPSILON)) { + if (v < RE_RAYTRACE_EPSILON && v > -(1.0f + RE_RAYTRACE_EPSILON)) { float cros[3]; cross_v3_v3v3(cros, m, t0); - u= divdet*dot_v3v3(cros, r); + u = divdet * dot_v3v3(cros, r); - if (u < RE_RAYTRACE_EPSILON && (v + u) > -(1.0f+RE_RAYTRACE_EPSILON)) { - l= divdet*dot_v3v3(cros, t1); + if (u < RE_RAYTRACE_EPSILON && (v + u) > -(1.0f + RE_RAYTRACE_EPSILON)) { + l = divdet * dot_v3v3(cros, t1); - if (l >- RE_RAYTRACE_EPSILON && l < *lambda) { - uv[0]= u; - uv[1]= -(1.0f + v + u); - *lambda= l; + if (l > -RE_RAYTRACE_EPSILON && l < *lambda) { + uv[0] = u; + uv[1] = -(1.0f + v + u); + *lambda = l; return 2; } } @@ -221,7 +221,7 @@ MALWAYS_INLINE int isec_tri_quad_neighbour(float start[3], float dir[3], RayFace float t0[3], t1[3], x[3], r[3], m[3], u, v, divdet, det1; int quad; - quad= RE_rayface_isQuad(face); + quad = RE_rayface_isQuad(face); copy_v3_v3(co1, face->v1); copy_v3_v3(co2, face->v2); @@ -234,22 +234,22 @@ MALWAYS_INLINE int isec_tri_quad_neighbour(float start[3], float dir[3], RayFace sub_v3_v3v3(t1, co3, co1); cross_v3_v3v3(x, r, t1); - divdet= dot_v3v3(t0, x); + divdet = dot_v3v3(t0, x); sub_v3_v3v3(m, start, co3); - det1= dot_v3v3(m, x); + det1 = dot_v3v3(m, x); if (divdet != 0.0f) { - divdet= 1.0f/divdet; - v= det1*divdet; + divdet = 1.0f / divdet; + v = det1 * divdet; - if (v < RE_RAYTRACE_EPSILON && v > -(1.0f+RE_RAYTRACE_EPSILON)) { + if (v < RE_RAYTRACE_EPSILON && v > -(1.0f + RE_RAYTRACE_EPSILON)) { float cros[3]; cross_v3_v3v3(cros, m, t0); - u= divdet*dot_v3v3(cros, r); + u = divdet * dot_v3v3(cros, r); - if (u < RE_RAYTRACE_EPSILON && (v + u) > -(1.0f+RE_RAYTRACE_EPSILON)) + if (u < RE_RAYTRACE_EPSILON && (v + u) > -(1.0f + RE_RAYTRACE_EPSILON)) return 1; } } @@ -258,19 +258,19 @@ MALWAYS_INLINE int isec_tri_quad_neighbour(float start[3], float dir[3], RayFace if (quad) { copy_v3_v3(co4, face->v4); sub_v3_v3v3(t0, co3, co4); - divdet= dot_v3v3(t0, x); + divdet = dot_v3v3(t0, x); if (divdet != 0.0f) { - divdet= 1.0f/divdet; - v = det1*divdet; + divdet = 1.0f / divdet; + v = det1 * divdet; - if (v < RE_RAYTRACE_EPSILON && v > -(1.0f+RE_RAYTRACE_EPSILON)) { + if (v < RE_RAYTRACE_EPSILON && v > -(1.0f + RE_RAYTRACE_EPSILON)) { float cros[3]; cross_v3_v3v3(cros, m, t0); - u= divdet*dot_v3v3(cros, r); + u = divdet * dot_v3v3(cros, r); - if (u < RE_RAYTRACE_EPSILON && (v + u) > -(1.0f+RE_RAYTRACE_EPSILON)) + if (u < RE_RAYTRACE_EPSILON && (v + u) > -(1.0f + RE_RAYTRACE_EPSILON)) return 2; } } @@ -285,7 +285,7 @@ MALWAYS_INLINE int isec_tri_quad_neighbour(float start[3], float dir[3], RayFace MALWAYS_INLINE int intersect_rayface(RayObject *hit_obj, RayFace *face, Isect *is) { float dist, uv[2]; - int ok= 0; + int ok = 0; /* avoid self-intersection */ if (is->orig.ob == face->ob && is->orig.face == face->face) @@ -293,25 +293,25 @@ MALWAYS_INLINE int intersect_rayface(RayObject *hit_obj, RayFace *face, Isect *i /* check if we should intersect this face */ if (is->check == RE_CHECK_VLR_RENDER) { - if (vlr_check_intersect(is, (ObjectInstanceRen*)face->ob, (VlakRen*)face->face) == 0) + if (vlr_check_intersect(is, (ObjectInstanceRen *)face->ob, (VlakRen *)face->face) == 0) return 0; } else if (is->check == RE_CHECK_VLR_NON_SOLID_MATERIAL) { - if (vlr_check_intersect(is, (ObjectInstanceRen*)face->ob, (VlakRen*)face->face) == 0) + if (vlr_check_intersect(is, (ObjectInstanceRen *)face->ob, (VlakRen *)face->face) == 0) return 0; - if (vlr_check_intersect_solid(is, (ObjectInstanceRen*)face->ob, (VlakRen*)face->face) == 0) + if (vlr_check_intersect_solid(is, (ObjectInstanceRen *)face->ob, (VlakRen *)face->face) == 0) return 0; } else if (is->check == RE_CHECK_VLR_BAKE) { - if (vlr_check_bake(is, (ObjectInstanceRen*)face->ob, (VlakRen*)face->face) == 0) + if (vlr_check_bake(is, (ObjectInstanceRen *)face->ob, (VlakRen *)face->face) == 0) return 0; } /* ray counter */ RE_RC_COUNT(is->raycounter->faces.test); - dist= is->dist; - ok= isec_tri_quad(is->start, is->dir, face, uv, &dist); + dist = is->dist; + ok = isec_tri_quad(is->start, is->dir, face, uv, &dist); if (ok) { @@ -319,21 +319,21 @@ MALWAYS_INLINE int intersect_rayface(RayObject *hit_obj, RayFace *face, Isect *i * of it, causing intersection to be detected in its neighbor face */ if (is->skip & RE_SKIP_VLR_NEIGHBOUR) { if (dist < 0.1f && is->orig.ob == face->ob) { - VlakRen * a = (VlakRen*)is->orig.face; - VlakRen * b = (VlakRen*)face->face; + VlakRen *a = (VlakRen *)is->orig.face; + VlakRen *b = (VlakRen *)face->face; /* so there's a shared edge or vertex, let's intersect ray with * face itself, if that's true we can safely return 1, otherwise * we assume the intersection is invalid, 0 */ - if (a->v1==b->v1 || a->v2==b->v1 || a->v3==b->v1 || a->v4==b->v1 || - a->v1==b->v2 || a->v2==b->v2 || a->v3==b->v2 || a->v4==b->v2 || - a->v1==b->v3 || a->v2==b->v3 || a->v3==b->v3 || a->v4==b->v3 || - (b->v4 && (a->v1==b->v4 || a->v2==b->v4 || a->v3==b->v4 || a->v4==b->v4))) + if (a->v1 == b->v1 || a->v2 == b->v1 || a->v3 == b->v1 || a->v4 == b->v1 || + a->v1 == b->v2 || a->v2 == b->v2 || a->v3 == b->v2 || a->v4 == b->v2 || + a->v1 == b->v3 || a->v2 == b->v3 || a->v3 == b->v3 || a->v4 == b->v3 || + (b->v4 && (a->v1 == b->v4 || a->v2 == b->v4 || a->v3 == b->v4 || a->v4 == b->v4))) { /* create RayFace from original face, transformed if necessary */ RayFace origface; - ObjectInstanceRen *ob= (ObjectInstanceRen*)is->orig.ob; - rayface_from_vlak(&origface, ob, (VlakRen*)is->orig.face); + ObjectInstanceRen *ob = (ObjectInstanceRen *)is->orig.ob; + rayface_from_vlak(&origface, ob, (VlakRen *)is->orig.face); if (!isec_tri_quad_neighbour(is->start, is->dir, &origface)) { return 0; @@ -344,9 +344,9 @@ MALWAYS_INLINE int intersect_rayface(RayObject *hit_obj, RayFace *face, Isect *i RE_RC_COUNT(is->raycounter->faces.hit); - is->isect= ok; // which half of the quad - is->dist= dist; - is->u= uv[0]; is->v= uv[1]; + is->isect = ok; // which half of the quad + is->dist = dist; + is->u = uv[0]; is->v = uv[1]; is->hit.ob = face->ob; is->hit.face = face->face; @@ -368,19 +368,19 @@ int RE_rayobject_raycast(RayObject *r, Isect *isec) RE_RC_COUNT(isec->raycounter->raycast.test); /* setup vars used on raycast */ - for (i=0; i<3; i++) { - isec->idot_axis[i] = 1.0f / isec->dir[i]; + 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+1] = 1 - isec->bv_index[2*i]; + isec->bv_index[2 * i] = isec->idot_axis[i] < 0.0 ? 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+1] = i+3*isec->bv_index[2*i+1]; + 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]; } #ifdef RT_USE_LAST_HIT /* last hit heuristic */ - if (isec->mode==RE_RAY_SHADOW && isec->last_hit) { + if (isec->mode == RE_RAY_SHADOW && isec->last_hit) { RE_RC_COUNT(isec->raycounter->rayshadow_last_hit.test); if (RE_rayobject_intersect(isec->last_hit, isec)) { @@ -410,11 +410,11 @@ int RE_rayobject_raycast(RayObject *r, Isect *isec) int RE_rayobject_intersect(RayObject *r, Isect *i) { if (RE_rayobject_isRayFace(r)) { - return intersect_rayface(r, (RayFace*) RE_rayobject_align(r), i); + return intersect_rayface(r, (RayFace *) RE_rayobject_align(r), i); } else if (RE_rayobject_isVlakPrimitive(r)) { //TODO optimize (useless copy to RayFace to avoid duplicate code) - VlakPrimitive *face = (VlakPrimitive*) RE_rayobject_align(r); + VlakPrimitive *face = (VlakPrimitive *) RE_rayobject_align(r); RayFace nface; rayface_from_vlak(&nface, face->ob, face->face); @@ -470,7 +470,7 @@ float RE_rayobject_cost(RayObject *r) void RE_rayobject_merge_bb(RayObject *r, float *min, float *max) { if (RE_rayobject_isRayFace(r)) { - RayFace *face = (RayFace*) RE_rayobject_align(r); + RayFace *face = (RayFace *) RE_rayobject_align(r); DO_MINMAX(face->v1, min, max); DO_MINMAX(face->v2, min, max); @@ -478,7 +478,7 @@ void RE_rayobject_merge_bb(RayObject *r, float *min, float *max) if (RE_rayface_isQuad(face)) DO_MINMAX(face->v4, min, max); } else if (RE_rayobject_isVlakPrimitive(r)) { - VlakPrimitive *face = (VlakPrimitive*) RE_rayobject_align(r); + VlakPrimitive *face = (VlakPrimitive *) RE_rayobject_align(r); RayFace nface; rayface_from_vlak(&nface, face->ob, face->face); diff --git a/source/blender/render/intern/raytrace/rayobject_blibvh.cpp b/source/blender/render/intern/raytrace/rayobject_blibvh.cpp index 79ca21270fa..2d642a0a0d8 100644 --- a/source/blender/render/intern/raytrace/rayobject_blibvh.cpp +++ b/source/blender/render/intern/raytrace/rayobject_blibvh.cpp @@ -44,7 +44,7 @@ static int RE_rayobject_blibvh_intersect(RayObject *o, Isect *isec); static void RE_rayobject_blibvh_add(RayObject *o, RayObject *ob); static void RE_rayobject_blibvh_done(RayObject *o); static void RE_rayobject_blibvh_free(RayObject *o); -static void RE_rayobject_blibvh_bb(RayObject *o, float min[3], float max[3]); +static void RE_rayobject_blibvh_bb(RayObject * o, float min[3], float max[3]); static float RE_rayobject_blibvh_cost(RayObject *UNUSED(o)) { @@ -69,8 +69,7 @@ static RayObjectAPI bvh_api = RE_rayobject_blibvh_hint_bb }; -typedef struct BVHObject -{ +typedef struct BVHObject { RayObject rayobj; RayObject **leafs, **next_leaf; BVHTree *bvh; @@ -79,26 +78,25 @@ typedef struct BVHObject RayObject *RE_rayobject_blibvh_create(int size) { - BVHObject *obj= (BVHObject*)MEM_callocN(sizeof(BVHObject), "BVHObject"); + BVHObject *obj = (BVHObject *)MEM_callocN(sizeof(BVHObject), "BVHObject"); assert(RE_rayobject_isAligned(obj)); /* RayObject API assumes real data to be 4-byte aligned */ obj->rayobj.api = &bvh_api; obj->bvh = BLI_bvhtree_new(size, 0.0, 4, 6); - obj->next_leaf = obj->leafs = (RayObject**)MEM_callocN(size*sizeof(RayObject*), "BVHObject leafs"); + obj->next_leaf = obj->leafs = (RayObject **)MEM_callocN(size * sizeof(RayObject *), "BVHObject leafs"); INIT_MINMAX(obj->bb[0], obj->bb[1]); - return RE_rayobject_unalignRayAPI((RayObject*) obj); + return RE_rayobject_unalignRayAPI((RayObject *) obj); } -struct BVHCallbackUserData -{ +struct BVHCallbackUserData { Isect *isec; RayObject **leafs; }; static void bvh_callback(void *userdata, int index, const BVHTreeRay *UNUSED(ray), BVHTreeRayHit *hit) { - struct BVHCallbackUserData *data = (struct BVHCallbackUserData*)userdata; + struct BVHCallbackUserData *data = (struct BVHCallbackUserData *)userdata; Isect *isec = data->isec; RayObject *face = data->leafs[index]; @@ -114,7 +112,7 @@ static void bvh_callback(void *userdata, int index, const BVHTreeRay *UNUSED(ray static int RE_rayobject_blibvh_intersect(RayObject *o, Isect *isec) { - BVHObject *obj = (BVHObject*)o; + BVHObject *obj = (BVHObject *)o; BVHTreeRayHit hit; float dir[3]; struct BVHCallbackUserData data; @@ -126,15 +124,15 @@ static int RE_rayobject_blibvh_intersect(RayObject *o, Isect *isec) hit.index = 0; hit.dist = isec->dist; - return BLI_bvhtree_ray_cast(obj->bvh, isec->start, dir, 0.0, &hit, bvh_callback, (void*)&data); + return BLI_bvhtree_ray_cast(obj->bvh, isec->start, dir, 0.0, &hit, bvh_callback, (void *)&data); } static void RE_rayobject_blibvh_add(RayObject *o, RayObject *ob) { - BVHObject *obj = (BVHObject*)o; + BVHObject *obj = (BVHObject *)o; float min_max[6]; - INIT_MINMAX(min_max, min_max+3); - RE_rayobject_merge_bb(ob, min_max, min_max+3); + INIT_MINMAX(min_max, min_max + 3); + RE_rayobject_merge_bb(ob, min_max, min_max + 3); DO_MIN(min_max, obj->bb[0]); DO_MAX(min_max + 3, obj->bb[1]); @@ -145,13 +143,13 @@ static void RE_rayobject_blibvh_add(RayObject *o, RayObject *ob) static void RE_rayobject_blibvh_done(RayObject *o) { - BVHObject *obj = (BVHObject*)o; + BVHObject *obj = (BVHObject *)o; BLI_bvhtree_balance(obj->bvh); } static void RE_rayobject_blibvh_free(RayObject *o) { - BVHObject *obj = (BVHObject*)o; + BVHObject *obj = (BVHObject *)o; if (obj->bvh) BLI_bvhtree_free(obj->bvh); @@ -164,7 +162,7 @@ static void RE_rayobject_blibvh_free(RayObject *o) static void RE_rayobject_blibvh_bb(RayObject *o, float min[3], float max[3]) { - BVHObject *obj = (BVHObject*)o; + BVHObject *obj = (BVHObject *)o; DO_MIN(obj->bb[0], min); DO_MAX(obj->bb[1], max); } diff --git a/source/blender/render/intern/raytrace/rayobject_hint.h b/source/blender/render/intern/raytrace/rayobject_hint.h index 37d9edb035d..6eb3c035935 100644 --- a/source/blender/render/intern/raytrace/rayobject_hint.h +++ b/source/blender/render/intern/raytrace/rayobject_hint.h @@ -33,25 +33,23 @@ #ifndef __RAYOBJECT_HINT_H__ #define __RAYOBJECT_HINT_H__ -#define HINT_RECURSE 1 -#define HINT_ACCEPT 0 -#define HINT_DISCARD -1 +#define HINT_RECURSE 1 +#define HINT_ACCEPT 0 +#define HINT_DISCARD -1 -struct HintBB -{ +struct HintBB { float bb[6]; }; inline int hint_test_bb(HintBB *obj, float *Nmin, float *Nmax) { - if (bb_fits_inside( Nmin, Nmax, obj->bb, obj->bb+3 ) ) + if (bb_fits_inside(Nmin, Nmax, obj->bb, obj->bb + 3) ) return HINT_RECURSE; else return HINT_ACCEPT; } #if 0 -struct HintFrustum -{ +struct HintFrustum { float co[3]; float no[4][3]; }; diff --git a/source/blender/render/intern/raytrace/rayobject_qbvh.cpp b/source/blender/render/intern/raytrace/rayobject_qbvh.cpp index bfcfbee536f..2e37782d047 100644 --- a/source/blender/render/intern/raytrace/rayobject_qbvh.cpp +++ b/source/blender/render/intern/raytrace/rayobject_qbvh.cpp @@ -40,10 +40,9 @@ #ifdef __SSE__ -#define DFS_STACK_SIZE 256 +#define DFS_STACK_SIZE 256 -struct QBVHTree -{ +struct QBVHTree { RayObject rayobj; SVBVHNode *root; @@ -61,11 +60,11 @@ void bvh_done(QBVHTree *obj) //TODO find a away to exactly calculate the needed memory MemArena *arena1 = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "qbvh arena"); - BLI_memarena_use_malloc(arena1); + BLI_memarena_use_malloc(arena1); MemArena *arena2 = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "qbvh arena 2"); - BLI_memarena_use_malloc(arena2); - BLI_memarena_use_align(arena2, 16); + BLI_memarena_use_malloc(arena2); + BLI_memarena_use_align(arena2, 16); //Build and optimize the tree //TODO do this in 1 pass (half memory usage during building) @@ -95,7 +94,7 @@ void bvh_done(QBVHTree *obj) } template -int intersect(QBVHTree *obj, Isect* isec) +int intersect(QBVHTree *obj, Isect *isec) { //TODO renable hint support if (RE_rayobject_isAligned(obj->root)) { @@ -105,7 +104,7 @@ int intersect(QBVHTree *obj, Isect* isec) return svbvh_node_stack_raycast(obj->root, isec); } else - return RE_rayobject_intersect((RayObject*)obj->root, isec); + return RE_rayobject_intersect((RayObject *)obj->root, isec); } template @@ -114,7 +113,7 @@ void bvh_hint_bb(Tree *tree, LCTSHint *hint, float *UNUSED(min), float *UNUSED(m //TODO renable hint support { hint->size = 0; - hint->stack[hint->size++] = (RayObject*)tree->root; + hint->stack[hint->size++] = (RayObject *)tree->root; } } /* the cast to pointer function is needed to workarround gcc bug: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11407 */ @@ -123,20 +122,20 @@ RayObjectAPI make_api() { static RayObjectAPI api = { - (RE_rayobject_raycast_callback) ((int(*)(Tree*, Isect*)) &intersect), - (RE_rayobject_add_callback) ((void(*)(Tree*, RayObject*)) &bvh_add), - (RE_rayobject_done_callback) ((void(*)(Tree*)) &bvh_done), - (RE_rayobject_free_callback) ((void(*)(Tree*)) &bvh_free), - (RE_rayobject_merge_bb_callback)((void(*)(Tree*, float*, float*)) &bvh_bb), - (RE_rayobject_cost_callback) ((float(*)(Tree*)) &bvh_cost), - (RE_rayobject_hint_bb_callback) ((void(*)(Tree*, LCTSHint*, float*, float*)) &bvh_hint_bb) + (RE_rayobject_raycast_callback) ((int (*)(Tree *, Isect *)) & intersect), + (RE_rayobject_add_callback) ((void (*)(Tree *, RayObject *)) & bvh_add), + (RE_rayobject_done_callback) ((void (*)(Tree *)) & bvh_done), + (RE_rayobject_free_callback) ((void (*)(Tree *)) & bvh_free), + (RE_rayobject_merge_bb_callback)((void (*)(Tree *, float *, float *)) & bvh_bb), + (RE_rayobject_cost_callback) ((float (*)(Tree *)) & bvh_cost), + (RE_rayobject_hint_bb_callback) ((void (*)(Tree *, LCTSHint *, float *, float *)) & bvh_hint_bb) }; return api; } template -RayObjectAPI* bvh_get_api(int maxstacksize) +RayObjectAPI *bvh_get_api(int maxstacksize) { static RayObjectAPI bvh_api256 = make_api(); diff --git a/source/blender/render/intern/raytrace/rayobject_rtbuild.cpp b/source/blender/render/intern/raytrace/rayobject_rtbuild.cpp index eb3bdb37f9d..66af64be160 100644 --- a/source/blender/render/intern/raytrace/rayobject_rtbuild.cpp +++ b/source/blender/render/intern/raytrace/rayobject_rtbuild.cpp @@ -54,19 +54,19 @@ static void rtbuild_init(RTBuilder *b) b->primitives.end = 0; b->primitives.maxsize = 0; - for (int i=0; ichild_offset[i] = 0; - for (int i=0; i<3; i++) + for (int i = 0; i < 3; i++) b->sorted_begin[i] = b->sorted_end[i] = 0; - INIT_MINMAX(b->bb, b->bb+3); + INIT_MINMAX(b->bb, b->bb + 3); } -RTBuilder* rtbuild_create(int size) +RTBuilder *rtbuild_create(int size) { - RTBuilder *builder = (RTBuilder*) MEM_mallocN( sizeof(RTBuilder), "RTBuilder" ); - RTBuilder::Object *memblock= (RTBuilder::Object*)MEM_mallocN( sizeof(RTBuilder::Object)*size, "RTBuilder.objects"); + RTBuilder *builder = (RTBuilder *) MEM_mallocN(sizeof(RTBuilder), "RTBuilder"); + RTBuilder::Object *memblock = (RTBuilder::Object *)MEM_mallocN(sizeof(RTBuilder::Object) * size, "RTBuilder.objects"); rtbuild_init(builder); @@ -74,8 +74,8 @@ RTBuilder* rtbuild_create(int size) builder->primitives.begin = builder->primitives.end = memblock; builder->primitives.maxsize = size; - for (int i=0; i<3; i++) { - builder->sorted_begin[i] = (RTBuilder::Object**)MEM_mallocN( sizeof(RTBuilder::Object*)*size, "RTBuilder.sorted_objects"); + for (int i = 0; i < 3; i++) { + builder->sorted_begin[i] = (RTBuilder::Object **)MEM_mallocN(sizeof(RTBuilder::Object *) * size, "RTBuilder.sorted_objects"); builder->sorted_end[i] = builder->sorted_begin[i]; } @@ -87,7 +87,7 @@ void rtbuild_free(RTBuilder *b) { if (b->primitives.begin) MEM_freeN(b->primitives.begin); - for (int i=0; i<3; i++) + for (int i = 0; i < 3; i++) if (b->sorted_begin[i]) MEM_freeN(b->sorted_begin[i]); @@ -98,10 +98,10 @@ void rtbuild_add(RTBuilder *b, RayObject *o) { float bb[6]; - assert( b->primitives.begin + b->primitives.maxsize != b->primitives.end ); + assert(b->primitives.begin + b->primitives.maxsize != b->primitives.end); - INIT_MINMAX(bb, bb+3); - RE_rayobject_merge_bb(o, bb, bb+3); + INIT_MINMAX(bb, bb + 3); + RE_rayobject_merge_bb(o, bb, bb + 3); /* skip objects with invalid bounding boxes, nan causes DO_MINMAX * to do nothing, so we get these invalid values. this shouldn't @@ -114,16 +114,16 @@ void rtbuild_add(RTBuilder *b, RayObject *o) if (!finite(bb[3]) || !finite(bb[4]) || !finite(bb[5])) return; /* skip objects with zero bounding box, they are of no use, and - * will give problems in rtbuild_heuristic_object_split later */ + * will give problems in rtbuild_heuristic_object_split later */ if (bb[0] == bb[3] && bb[1] == bb[4] && bb[2] == bb[5]) return; copy_v3_v3(b->primitives.end->bb, bb); - copy_v3_v3(b->primitives.end->bb+3, bb+3); + copy_v3_v3(b->primitives.end->bb + 3, bb + 3); b->primitives.end->obj = o; b->primitives.end->cost = RE_rayobject_cost(o); - for (int i=0; i<3; i++) { + for (int i = 0; i < 3; i++) { *(b->sorted_end[i]) = b->primitives.end; b->sorted_end[i]++; } @@ -153,32 +153,33 @@ static void object_sort(Item *begin, Item *end, int axis) assert(false); } -void rtbuild_done(RTBuilder *b, RayObjectControl* ctrl) +void rtbuild_done(RTBuilder *b, RayObjectControl *ctrl) { - for (int i=0; i<3; i++) - if (b->sorted_begin[i]) { - if (RE_rayobjectcontrol_test_break(ctrl)) break; - object_sort( b->sorted_begin[i], b->sorted_end[i], i ); + for (int i = 0; i < 3; i++) { + if (b->sorted_begin[i]) { + if (RE_rayobjectcontrol_test_break(ctrl)) break; + object_sort(b->sorted_begin[i], b->sorted_end[i], i); + } } } -RayObject* rtbuild_get_primitive(RTBuilder *b, int index) +RayObject *rtbuild_get_primitive(RTBuilder *b, int index) { return b->sorted_begin[0][index]->obj; } -RTBuilder* rtbuild_get_child(RTBuilder *b, int child, RTBuilder *tmp) +RTBuilder *rtbuild_get_child(RTBuilder *b, int child, RTBuilder *tmp) { - rtbuild_init( tmp ); + rtbuild_init(tmp); - for (int i=0; i<3; i++) + for (int i = 0; i < 3; i++) if (b->sorted_begin[i]) { - tmp->sorted_begin[i] = b->sorted_begin[i] + b->child_offset[child ]; - tmp->sorted_end [i] = b->sorted_begin[i] + b->child_offset[child+1]; + tmp->sorted_begin[i] = b->sorted_begin[i] + b->child_offset[child]; + tmp->sorted_end[i] = b->sorted_begin[i] + b->child_offset[child + 1]; } else { tmp->sorted_begin[i] = 0; - tmp->sorted_end [i] = 0; + tmp->sorted_end[i] = 0; } return tmp; @@ -188,7 +189,7 @@ void rtbuild_calc_bb(RTBuilder *b) { if (b->bb[0] == 1.0e30f) { for (RTBuilder::Object **index = b->sorted_begin[0]; index != b->sorted_end[0]; index++) - RE_rayobject_merge_bb( (*index)->obj, b->bb, b->bb+3); + RE_rayobject_merge_bb( (*index)->obj, b->bb, b->bb + 3); } } @@ -196,14 +197,14 @@ void rtbuild_merge_bb(RTBuilder *b, float *min, float *max) { rtbuild_calc_bb(b); DO_MIN(b->bb, min); - DO_MAX(b->bb+3, max); + DO_MAX(b->bb + 3, max); } #if 0 int rtbuild_get_largest_axis(RTBuilder *b) { rtbuild_calc_bb(b); - return bb_largest_axis(b->bb, b->bb+3); + return bb_largest_axis(b->bb, b->bb + 3); } //Left balanced tree @@ -219,26 +220,25 @@ int rtbuild_mean_split(RTBuilder *b, int nchilds, int axis) assert(nchilds <= RTBUILD_MAX_CHILDS); //TODO optimize calc of leafs_per_child - for (s=nchilds; schild_offset[0] = 0; - for (i=1; i<=nchilds; i++) + for (i = 1; i <= nchilds; i++) b->child_offset[i] = mleafs_per_child; //split remaining leafs - missing_leafs = tot_leafs - mleafs_per_child*nchilds; - for (i=1; i<=nchilds; i++) + missing_leafs = tot_leafs - mleafs_per_child * nchilds; + for (i = 1; i <= nchilds; i++) { if (missing_leafs > Mleafs_per_child - mleafs_per_child) { b->child_offset[i] += Mleafs_per_child - mleafs_per_child; missing_leafs -= Mleafs_per_child - mleafs_per_child; } - else - { + else { b->child_offset[i] += missing_leafs; missing_leafs = 0; break; @@ -246,14 +246,14 @@ int rtbuild_mean_split(RTBuilder *b, int nchilds, int axis) } //adjust for accumulative offsets - for (i=1; i<=nchilds; i++) - b->child_offset[i] += b->child_offset[i-1]; + for (i = 1; i <= nchilds; i++) + b->child_offset[i] += b->child_offset[i - 1]; //Count created childs - for (i=nchilds; b->child_offset[i] == b->child_offset[i-1]; i--); + for (i = nchilds; b->child_offset[i] == b->child_offset[i - 1]; i--) ; split_leafs(b, b->child_offset, i, axis); - assert( b->child_offset[0] == 0 && b->child_offset[i] == tot_leafs ); + assert(b->child_offset[0] == 0 && b->child_offset[i] == tot_leafs); return i; } @@ -279,20 +279,19 @@ int rtbuild_median_split(RTBuilder *b, float *separators, int nchilds, int axis) { return rtbuild_mean_split(b, nchilds, axis); } - else - { + else { int i; b->split_axis = axis; //Calculate child offsets b->child_offset[0] = 0; - for (i=0; ichild_offset[i+1] = split_leafs_by_plane(b, b->child_offset[i], size, separators[i]); + for (i = 0; i < nchilds - 1; i++) + b->child_offset[i + 1] = split_leafs_by_plane(b, b->child_offset[i], size, separators[i]); b->child_offset[nchilds] = size; - for (i=0; ichild_offset[i+1] - b->child_offset[i] == size) + for (i = 0; i < nchilds; i++) + if (b->child_offset[i + 1] - b->child_offset[i] == size) return rtbuild_mean_split(b, nchilds, axis); return nchilds; @@ -306,9 +305,9 @@ int rtbuild_median_split_largest_axis(RTBuilder *b, int nchilds) rtbuild_calc_bb(b); - la = bb_largest_axis(b->bb, b->bb+3); - for (i=1; ibb[la+3]-b->bb[la])*i / nchilds; + la = bb_largest_axis(b->bb, b->bb + 3); + for (i = 1; i < nchilds; i++) + separators[i - 1] = (b->bb[la + 3] - b->bb[la]) * i / nchilds; return rtbuild_median_split(b, separators, nchilds, la); } @@ -317,8 +316,7 @@ int rtbuild_median_split_largest_axis(RTBuilder *b, int nchilds) //Heuristics Object Splitter -struct SweepCost -{ +struct SweepCost { float bb[6]; float cost; }; @@ -333,30 +331,30 @@ int rtbuild_heuristic_object_split(RTBuilder *b, int nchilds) if (size > nchilds) { float bcost = FLT_MAX; - baxis = -1, boffset = size/2; + baxis = -1, boffset = size / 2; - SweepCost *sweep = (SweepCost*)MEM_mallocN( sizeof(SweepCost)*size, "RTBuilder.HeuristicSweep" ); + SweepCost *sweep = (SweepCost *)MEM_mallocN(sizeof(SweepCost) * size, "RTBuilder.HeuristicSweep"); - for (int axis=0; axis<3; axis++) { + for (int axis = 0; axis < 3; axis++) { SweepCost sweep_left; RTBuilder::Object **obj = b->sorted_begin[axis]; // float right_cost = 0; - for (int i=size-1; i>=0; i--) { - if (i == size-1) { + for (int i = size - 1; i >= 0; i--) { + if (i == size - 1) { copy_v3_v3(sweep[i].bb, obj[i]->bb); - copy_v3_v3(sweep[i].bb+3, obj[i]->bb+3); + copy_v3_v3(sweep[i].bb + 3, obj[i]->bb + 3); sweep[i].cost = obj[i]->cost; } else { - sweep[i].bb[0] = MIN2(obj[i]->bb[0], sweep[i+1].bb[0]); - sweep[i].bb[1] = MIN2(obj[i]->bb[1], sweep[i+1].bb[1]); - sweep[i].bb[2] = MIN2(obj[i]->bb[2], sweep[i+1].bb[2]); - sweep[i].bb[3] = MAX2(obj[i]->bb[3], sweep[i+1].bb[3]); - sweep[i].bb[4] = MAX2(obj[i]->bb[4], sweep[i+1].bb[4]); - sweep[i].bb[5] = MAX2(obj[i]->bb[5], sweep[i+1].bb[5]); - sweep[i].cost = obj[i]->cost + sweep[i+1].cost; + sweep[i].bb[0] = MIN2(obj[i]->bb[0], sweep[i + 1].bb[0]); + sweep[i].bb[1] = MIN2(obj[i]->bb[1], sweep[i + 1].bb[1]); + sweep[i].bb[2] = MIN2(obj[i]->bb[2], sweep[i + 1].bb[2]); + sweep[i].bb[3] = MAX2(obj[i]->bb[3], sweep[i + 1].bb[3]); + sweep[i].bb[4] = MAX2(obj[i]->bb[4], sweep[i + 1].bb[4]); + sweep[i].bb[5] = MAX2(obj[i]->bb[5], sweep[i + 1].bb[5]); + sweep[i].cost = obj[i]->cost + sweep[i + 1].cost; } // right_cost += obj[i]->cost; } @@ -371,7 +369,7 @@ int rtbuild_heuristic_object_split(RTBuilder *b, int nchilds) // right_cost -= obj[0]->cost; if (right_cost < 0) right_cost = 0; - for (int i=1; i= 0); assert(right_side >= 0); - if (left_side > bcost) break; //No way we can find a better heuristic in this axis + if (left_side > bcost) break; //No way we can find a better heuristic in this axis assert(hcost >= 0); // this makes sure the tree built is the same whatever is the order of the sorting axis - if ( hcost < bcost || (hcost == bcost && axis < baxis)) { + if (hcost < bcost || (hcost == bcost && axis < baxis)) { bcost = hcost; baxis = axis; boffset = i; } - DO_MIN( obj[i]->bb, sweep_left.bb ); - DO_MAX( obj[i]->bb+3, sweep_left.bb+3 ); + DO_MIN(obj[i]->bb, sweep_left.bb); + DO_MAX(obj[i]->bb + 3, sweep_left.bb + 3); sweep_left.cost += obj[i]->cost; // right_cost -= obj[i]->cost; if (right_cost < 0) right_cost = 0; @@ -426,10 +424,10 @@ int rtbuild_heuristic_object_split(RTBuilder *b, int nchilds) /* Adjust sorted arrays for childs */ - for (int i=0; isorted_begin[baxis][i]->selected = true; - for (int i=boffset; isorted_begin[baxis][i]->selected = false; - for (int i=0; i<3; i++) - std::stable_partition( b->sorted_begin[i], b->sorted_end[i], selected_node ); + for (int i = 0; i < boffset; i++) b->sorted_begin[baxis][i]->selected = true; + for (int i = boffset; i < size; i++) b->sorted_begin[baxis][i]->selected = false; + for (int i = 0; i < 3; i++) + std::stable_partition(b->sorted_begin[i], b->sorted_end[i], selected_node); return nchilds; } @@ -445,13 +443,13 @@ static void split_leafs(RTBuilder *b, int *nth, int partitions, int split_axis) int i; b->split_axis = split_axis; - for (i=0; i < partitions-1; i++) + for (i = 0; i < partitions - 1; i++) { - assert(nth[i] < nth[i+1] && nth[i+1] < nth[partitions]); + assert(nth[i] < nth[i + 1] && nth[i + 1] < nth[partitions]); - if (split_axis == 0) std::nth_element(b, nth[i], nth[i+1], nth[partitions], obj_bb_compare); - if (split_axis == 1) std::nth_element(b, nth[i], nth[i+1], nth[partitions], obj_bb_compare); - if (split_axis == 2) std::nth_element(b, nth[i], nth[i+1], nth[partitions], obj_bb_compare); + if (split_axis == 0) std::nth_element(b, nth[i], nth[i + 1], nth[partitions], obj_bb_compare); + if (split_axis == 1) std::nth_element(b, nth[i], nth[i + 1], nth[partitions], obj_bb_compare); + if (split_axis == 2) std::nth_element(b, nth[i], nth[i + 1], nth[partitions], obj_bb_compare); } } #endif @@ -461,20 +459,20 @@ static void split_leafs(RTBuilder *b, int *nth, int partitions, int split_axis) */ float bb_volume(float *min, float *max) { - return (max[0]-min[0])*(max[1]-min[1])*(max[2]-min[2]); + return (max[0] - min[0]) * (max[1] - min[1]) * (max[2] - min[2]); } float bb_area(float *min, float *max) { float sub[3], a; - sub[0] = max[0]-min[0]; - sub[1] = max[1]-min[1]; - sub[2] = max[2]-min[2]; + sub[0] = max[0] - min[0]; + sub[1] = max[1] - min[1]; + sub[2] = max[2] - min[2]; - a = (sub[0]*sub[1] + sub[0]*sub[2] + sub[1]*sub[2])*2; - /* used to have an assert() here on negative results - * however, in this case its likely some overflow or ffast math error. - * so just return 0.0f instead. */ + a = (sub[0] * sub[1] + sub[0] * sub[2] + sub[1] * sub[2]) * 2; + /* used to have an assert() here on negative results + * however, in this case its likely some overflow or ffast math error. + * so just return 0.0f instead. */ return a < 0.0f ? 0.0f : a; } @@ -482,9 +480,9 @@ int bb_largest_axis(float *min, float *max) { float sub[3]; - sub[0] = max[0]-min[0]; - sub[1] = max[1]-min[1]; - sub[2] = max[2]-min[2]; + sub[0] = max[0] - min[0]; + sub[1] = max[1] - min[1]; + sub[2] = max[2] - min[2]; if (sub[0] > sub[1]) { if (sub[0] > sub[2]) return 0; @@ -502,10 +500,10 @@ int bb_largest_axis(float *min, float *max) int bb_fits_inside(float *outer_min, float *outer_max, float *inner_min, float *inner_max) { int i; - for (i=0; i<3; i++) + for (i = 0; i < 3; i++) if (outer_min[i] > inner_min[i]) return 0; - for (i=0; i<3; i++) + for (i = 0; i < 3; i++) if (outer_max[i] < inner_max[i]) return 0; return 1; diff --git a/source/blender/render/intern/raytrace/rayobject_rtbuild.h b/source/blender/render/intern/raytrace/rayobject_rtbuild.h index f6e9aabf43d..22e3d009c07 100644 --- a/source/blender/render/intern/raytrace/rayobject_rtbuild.h +++ b/source/blender/render/intern/raytrace/rayobject_rtbuild.h @@ -52,10 +52,8 @@ extern "C" { #define RTBUILD_MAX_CHILDS 32 -typedef struct RTBuilder -{ - struct Object - { +typedef struct RTBuilder { + struct Object { RayObject *obj; float cost; float bb[6]; @@ -63,8 +61,7 @@ typedef struct RTBuilder }; /* list to all primitives added in this tree */ - struct - { + struct { Object *begin, *end; int maxsize; } primitives; @@ -76,7 +73,7 @@ typedef struct RTBuilder int split_axis; /* child partitions calculated during splitting */ - int child_offset[RTBUILD_MAX_CHILDS+1]; + int child_offset[RTBUILD_MAX_CHILDS + 1]; // int child_sorted_axis; /* -1 if not sorted */ @@ -85,17 +82,17 @@ typedef struct RTBuilder } RTBuilder; /* used during creation */ -RTBuilder* rtbuild_create(int size); +RTBuilder *rtbuild_create(int size); void rtbuild_free(RTBuilder *b); void rtbuild_add(RTBuilder *b, RayObject *o); void rtbuild_done(RTBuilder *b, RayObjectControl *c); void rtbuild_merge_bb(RTBuilder *b, float *min, float *max); int rtbuild_size(RTBuilder *b); -RayObject* rtbuild_get_primitive(RTBuilder *b, int offset); +RayObject *rtbuild_get_primitive(RTBuilder *b, int offset); /* used during tree reorganization */ -RTBuilder* rtbuild_get_child(RTBuilder *b, int child, RTBuilder *tmp); +RTBuilder *rtbuild_get_child(RTBuilder *b, int child, RTBuilder *tmp); /* Calculates child partitions and returns number of efectively needed partitions */ int rtbuild_get_largest_axis(RTBuilder *b); diff --git a/source/blender/render/intern/raytrace/rayobject_svbvh.cpp b/source/blender/render/intern/raytrace/rayobject_svbvh.cpp index 3cf2b4b5d5f..697ba9ad6e2 100644 --- a/source/blender/render/intern/raytrace/rayobject_svbvh.cpp +++ b/source/blender/render/intern/raytrace/rayobject_svbvh.cpp @@ -40,10 +40,9 @@ #ifdef __SSE__ -#define DFS_STACK_SIZE 256 +#define DFS_STACK_SIZE 256 -struct SVBVHTree -{ +struct SVBVHTree { RayObject rayobj; SVBVHNode *root; @@ -56,11 +55,10 @@ struct SVBVHTree /* * Cost to test N childs */ -struct PackCost -{ +struct PackCost { float operator()(int n) { - return (n / 4) + ((n % 4) > 2 ? 1 : n%4); + return (n / 4) + ((n % 4) > 2 ? 1 : n % 4); } }; @@ -72,11 +70,11 @@ void bvh_done(SVBVHTree *obj) //TODO find a away to exactly calculate the needed memory MemArena *arena1 = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "svbvh arena"); - BLI_memarena_use_malloc(arena1); + BLI_memarena_use_malloc(arena1); MemArena *arena2 = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "svbvh arena2"); - BLI_memarena_use_malloc(arena2); - BLI_memarena_use_align(arena2, 16); + BLI_memarena_use_malloc(arena2); + BLI_memarena_use_align(arena2, 16); //Build and optimize the tree if (0) { @@ -123,12 +121,12 @@ void bvh_done(SVBVHTree *obj) obj->node_arena = arena2; obj->cost = 1.0; - rtbuild_free( obj->builder ); + rtbuild_free(obj->builder); obj->builder = NULL; } template -int intersect(SVBVHTree *obj, Isect* isec) +int intersect(SVBVHTree *obj, Isect *isec) { //TODO renable hint support if (RE_rayobject_isAligned(obj->root)) { @@ -138,7 +136,7 @@ int intersect(SVBVHTree *obj, Isect* isec) return svbvh_node_stack_raycast(obj->root, isec); } else - return RE_rayobject_intersect( (RayObject*) obj->root, isec ); + return RE_rayobject_intersect( (RayObject *) obj->root, isec); } template @@ -147,7 +145,7 @@ void bvh_hint_bb(Tree *tree, LCTSHint *hint, float *UNUSED(min), float *UNUSED(m //TODO renable hint support { hint->size = 0; - hint->stack[hint->size++] = (RayObject*)tree->root; + hint->stack[hint->size++] = (RayObject *)tree->root; } } /* the cast to pointer function is needed to workarround gcc bug: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11407 */ @@ -156,20 +154,20 @@ RayObjectAPI make_api() { static RayObjectAPI api = { - (RE_rayobject_raycast_callback) ((int(*)(Tree*, Isect*)) &intersect), - (RE_rayobject_add_callback) ((void(*)(Tree*, RayObject*)) &bvh_add), - (RE_rayobject_done_callback) ((void(*)(Tree*)) &bvh_done), - (RE_rayobject_free_callback) ((void(*)(Tree*)) &bvh_free), - (RE_rayobject_merge_bb_callback)((void(*)(Tree*, float*, float*)) &bvh_bb), - (RE_rayobject_cost_callback) ((float(*)(Tree*)) &bvh_cost), - (RE_rayobject_hint_bb_callback) ((void(*)(Tree*, LCTSHint*, float*, float*)) &bvh_hint_bb) + (RE_rayobject_raycast_callback) ((int (*)(Tree *, Isect *)) & intersect), + (RE_rayobject_add_callback) ((void (*)(Tree *, RayObject *)) & bvh_add), + (RE_rayobject_done_callback) ((void (*)(Tree *)) & bvh_done), + (RE_rayobject_free_callback) ((void (*)(Tree *)) & bvh_free), + (RE_rayobject_merge_bb_callback)((void (*)(Tree *, float *, float *)) & bvh_bb), + (RE_rayobject_cost_callback) ((float (*)(Tree *)) & bvh_cost), + (RE_rayobject_hint_bb_callback) ((void (*)(Tree *, LCTSHint *, float *, float *)) & bvh_hint_bb) }; return api; } template -RayObjectAPI* bvh_get_api(int maxstacksize) +RayObjectAPI *bvh_get_api(int maxstacksize) { static RayObjectAPI bvh_api256 = make_api(); diff --git a/source/blender/render/intern/raytrace/rayobject_vbvh.cpp b/source/blender/render/intern/raytrace/rayobject_vbvh.cpp index 47e78b8912e..9e7075438cb 100644 --- a/source/blender/render/intern/raytrace/rayobject_vbvh.cpp +++ b/source/blender/render/intern/raytrace/rayobject_vbvh.cpp @@ -55,10 +55,9 @@ int tot_hints = 0; #include #include -#define DFS_STACK_SIZE 256 +#define DFS_STACK_SIZE 256 -struct VBVHTree -{ +struct VBVHTree { RayObject rayobj; VBVHNode *root; MemArena *node_arena; @@ -69,8 +68,7 @@ struct VBVHTree /* * Cost to test N childs */ -struct PackCost -{ +struct PackCost { float operator()(int n) { return n; @@ -84,7 +82,7 @@ void bvh_done(VBVHTree *obj) //TODO find a away to exactly calculate the needed memory MemArena *arena1 = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "vbvh arena"); - BLI_memarena_use_malloc(arena1); + BLI_memarena_use_malloc(arena1); //Build and optimize the tree if (1) { @@ -107,10 +105,10 @@ void bvh_done(VBVHTree *obj) obj->root = NULL; } else { -/* - TODO + /* TODO */ +#if 0 MemArena *arena2 = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "vbvh arena2"); - BLI_memarena_use_malloc(arena2); + BLI_memarena_use_malloc(arena2); //Finds the optimal packing of this tree using a given cost model //TODO this uses quite a lot of memory, find ways to reduce memory usage during building @@ -119,11 +117,11 @@ void bvh_done(VBVHTree *obj) obj->root = Reorganize_VBVH(arena1).transform(root); BLI_memarena_free(arena2); - */ +#endif } //Cleanup - rtbuild_free( obj->builder ); + rtbuild_free(obj->builder); obj->builder = NULL; obj->node_arena = arena1; @@ -131,17 +129,17 @@ void bvh_done(VBVHTree *obj) } template -int intersect(VBVHTree *obj, Isect* isec) +int intersect(VBVHTree *obj, Isect *isec) { //TODO renable hint support if (RE_rayobject_isAligned(obj->root)) { if (isec->mode == RE_RAY_SHADOW) - return bvh_node_stack_raycast( obj->root, isec); + return bvh_node_stack_raycast(obj->root, isec); else - return bvh_node_stack_raycast( obj->root, isec); + return bvh_node_stack_raycast(obj->root, isec); } else - return RE_rayobject_intersect( (RayObject*) obj->root, isec ); + return RE_rayobject_intersect( (RayObject *) obj->root, isec); } template @@ -150,7 +148,7 @@ void bvh_hint_bb(Tree *tree, LCTSHint *hint, float *UNUSED(min), float *UNUSED(m //TODO renable hint support { hint->size = 0; - hint->stack[hint->size++] = (RayObject*)tree->root; + hint->stack[hint->size++] = (RayObject *)tree->root; } } @@ -178,20 +176,20 @@ RayObjectAPI make_api() { static RayObjectAPI api = { - (RE_rayobject_raycast_callback) ((int(*)(Tree*, Isect*)) &intersect), - (RE_rayobject_add_callback) ((void(*)(Tree*, RayObject*)) &bvh_add), - (RE_rayobject_done_callback) ((void(*)(Tree*)) &bvh_done), - (RE_rayobject_free_callback) ((void(*)(Tree*)) &bvh_free), - (RE_rayobject_merge_bb_callback)((void(*)(Tree*, float*, float*)) &bvh_bb), - (RE_rayobject_cost_callback) ((float(*)(Tree*)) &bvh_cost), - (RE_rayobject_hint_bb_callback) ((void(*)(Tree*, LCTSHint*, float*, float*)) &bvh_hint_bb) + (RE_rayobject_raycast_callback) ((int (*)(Tree *, Isect *)) & intersect), + (RE_rayobject_add_callback) ((void (*)(Tree *, RayObject *)) & bvh_add), + (RE_rayobject_done_callback) ((void (*)(Tree *)) & bvh_done), + (RE_rayobject_free_callback) ((void (*)(Tree *)) & bvh_free), + (RE_rayobject_merge_bb_callback)((void (*)(Tree *, float *, float *)) & bvh_bb), + (RE_rayobject_cost_callback) ((float (*)(Tree *)) & bvh_cost), + (RE_rayobject_hint_bb_callback) ((void (*)(Tree *, LCTSHint *, float *, float *)) & bvh_hint_bb) }; return api; } template -RayObjectAPI* bvh_get_api(int maxstacksize) +RayObjectAPI *bvh_get_api(int maxstacksize) { static RayObjectAPI bvh_api256 = make_api(); diff --git a/source/blender/render/intern/raytrace/reorganize.h b/source/blender/render/intern/raytrace/reorganize.h index a47bd27d11b..1e9a0319b2f 100644 --- a/source/blender/render/intern/raytrace/reorganize.h +++ b/source/blender/render/intern/raytrace/reorganize.h @@ -57,13 +57,13 @@ extern int tot_pushdown; template bool node_fits_inside(Node *a, Node *b) { - return bb_fits_inside(b->bb, b->bb+3, a->bb, a->bb+3); + return bb_fits_inside(b->bb, b->bb + 3, a->bb, a->bb + 3); } template -void reorganize_find_fittest_parent(Node *tree, Node *node, std::pair &cost) +void reorganize_find_fittest_parent(Node *tree, Node *node, std::pair &cost) { - std::queue q; + std::queue q; q.push(tree); while (!q.empty()) { @@ -72,8 +72,8 @@ void reorganize_find_fittest_parent(Node *tree, Node *node, std::pairchild) ) { - float pcost = bb_area(parent->bb, parent->bb+3); - cost = std::min( cost, std::make_pair(pcost, parent) ); + float pcost = bb_area(parent->bb, parent->bb + 3); + cost = std::min(cost, std::make_pair(pcost, parent) ); for (Node *child = parent->child; child; child = child->sibling) q.push(child); } @@ -84,11 +84,11 @@ static int tot_moves = 0; template void reorganize(Node *root) { - std::queue q; + std::queue q; q.push(root); while (!q.empty()) { - Node * node = q.front(); + Node *node = q.front(); q.pop(); if (RE_rayobject_isAligned(node->child)) { @@ -96,7 +96,7 @@ void reorganize(Node *root) assert(RE_rayobject_isAligned(*prev)); q.push(*prev); - std::pair best(FLT_MAX, root); + std::pair best(FLT_MAX, root); reorganize_find_fittest_parent(root, *prev, best); if (best.second == node) { @@ -129,7 +129,7 @@ void reorganize(Node *root) template void remove_useless(Node *node, Node **new_node) { - if ( RE_rayobject_isAligned(node->child) ) { + if (RE_rayobject_isAligned(node->child) ) { for (Node **prev = &node->child; *prev; ) { Node *next = (*prev)->sibling; @@ -160,12 +160,12 @@ void pushup(Node *parent) { if (is_leaf(parent)) return; - float p_area = bb_area(parent->bb, parent->bb+3); + float p_area = bb_area(parent->bb, parent->bb + 3); Node **prev = &parent->child; for (Node *child = parent->child; RE_rayobject_isAligned(child) && child; ) { const float c_area = bb_area(child->bb, child->bb + 3); const int nchilds = count_childs(child); - float original_cost = ((p_area != 0.0f)? (c_area / p_area)*nchilds: 1.0f) + 1; + float original_cost = ((p_area != 0.0f) ? (c_area / p_area) * nchilds : 1.0f) + 1; float flatten_cost = nchilds; if (flatten_cost < original_cost && nchilds >= 2) { append_sibling(child, child->child); @@ -201,7 +201,7 @@ void pushup_simd(Node *parent) Node **prev = &parent->child; for (Node *child = parent->child; RE_rayobject_isAligned(child) && child; ) { int cn = count_childs(child); - if (cn-1 <= (SSize - (n%SSize) ) % SSize && RE_rayobject_isAligned(child->child) ) { + if (cn - 1 <= (SSize - (n % SSize) ) % SSize && RE_rayobject_isAligned(child->child) ) { n += (cn - 1); append_sibling(child, child->child); child = child->sibling; @@ -227,7 +227,7 @@ template void pushdown(Node *parent) { Node **s_child = &parent->child; - Node * child = parent->child; + Node *child = parent->child; while (child && RE_rayobject_isAligned(child)) { Node *next = child->sibling; @@ -236,18 +236,18 @@ void pushdown(Node *parent) //assert(bb_fits_inside(parent->bb, parent->bb+3, child->bb, child->bb+3)); for (Node *i = parent->child; RE_rayobject_isAligned(i) && i; i = i->sibling) - if (child != i && bb_fits_inside(i->bb, i->bb+3, child->bb, child->bb+3) && RE_rayobject_isAligned(i->child)) { + if (child != i && bb_fits_inside(i->bb, i->bb + 3, child->bb, child->bb + 3) && RE_rayobject_isAligned(i->child)) { // todo optimize (should the one with the smallest area?) // float ia = bb_area(i->bb, i->bb+3) // if (child->i) - *s_child = child->sibling; - child->sibling = i->child; - i->child = child; - next_s_child = s_child; + *s_child = child->sibling; + child->sibling = i->child; + i->child = child; + next_s_child = s_child; - tot_pushdown++; - break; - } + tot_pushdown++; + break; + } child = next; s_child = next_s_child; } @@ -273,13 +273,13 @@ float bvh_refit(Node *node) for (Node *child = node->child; child; child = child->sibling) total += bvh_refit(child); - float old_area = bb_area(node->bb, node->bb+3); - INIT_MINMAX(node->bb, node->bb+3); + float old_area = bb_area(node->bb, node->bb + 3); + INIT_MINMAX(node->bb, node->bb + 3); for (Node *child = node->child; child; child = child->sibling) { DO_MIN(child->bb, node->bb); - DO_MAX(child->bb+3, node->bb+3); + DO_MAX(child->bb + 3, node->bb + 3); } - total += old_area - bb_area(node->bb, node->bb+3); + total += old_area - bb_area(node->bb, node->bb + 3); return total; } @@ -289,12 +289,11 @@ float bvh_refit(Node *node) * with the purpose to reduce the expected cost (eg.: number of BB tests). */ #include -#define MAX_CUT_SIZE 4 /* svbvh assumes max 4 children! */ -#define MAX_OPTIMIZE_CHILDS MAX_CUT_SIZE +#define MAX_CUT_SIZE 4 /* svbvh assumes max 4 children! */ +#define MAX_OPTIMIZE_CHILDS MAX_CUT_SIZE -struct OVBVHNode -{ - float bb[6]; +struct OVBVHNode { + float bb[6]; OVBVHNode *child; OVBVHNode *sibling; @@ -306,7 +305,7 @@ struct OVBVHNode float cut_cost[MAX_CUT_SIZE]; float get_cost(int cutsize) { - return cut_cost[cutsize-1]; + return cut_cost[cutsize - 1]; } /* @@ -316,7 +315,7 @@ struct OVBVHNode int cut_size[MAX_CUT_SIZE]; int get_cut_size(int parent_cut_size) { - return cut_size[parent_cut_size-1]; + return cut_size[parent_cut_size - 1]; } /* @@ -327,19 +326,21 @@ struct OVBVHNode { if (cutsize == 1) { **cut = this; - *cut = &(**cut)->sibling; + *cut = &(**cut)->sibling; } else { if (cutsize > MAX_CUT_SIZE) { for (OVBVHNode *child = this->child; child && RE_rayobject_isAligned(child); child = child->sibling) { - child->set_cut( 1, cut ); + child->set_cut(1, cut); cutsize--; } assert(cutsize == 0); } - else - for (OVBVHNode *child = this->child; child && RE_rayobject_isAligned(child); child = child->sibling) - child->set_cut( child->get_cut_size( cutsize ), cut ); + else { + for (OVBVHNode *child = this->child; child && RE_rayobject_isAligned(child); child = child->sibling) { + child->set_cut(child->get_cut_size(cutsize), cut); + } + } } } @@ -365,8 +366,7 @@ struct OVBVHNode * */ template -struct VBVH_optimalPackSIMD -{ +struct VBVH_optimalPackSIMD { TestCost testcost; VBVH_optimalPackSIMD(TestCost testcost) @@ -377,8 +377,7 @@ struct VBVH_optimalPackSIMD /* * calc best cut on a node */ - struct calc_best - { + struct calc_best { Node *child[MAX_OPTIMIZE_CHILDS]; float child_hit_prob[MAX_OPTIMIZE_CHILDS]; @@ -387,10 +386,10 @@ struct VBVH_optimalPackSIMD int nchilds = 0; //Fetch childs and needed data { - float parent_area = bb_area(node->bb, node->bb+3); + float parent_area = bb_area(node->bb, node->bb + 3); for (Node *child = node->child; child && RE_rayobject_isAligned(child); child = child->sibling) { this->child[nchilds] = child; - this->child_hit_prob[nchilds] = (parent_area != 0.0f)? bb_area(child->bb, child->bb+3) / parent_area: 1.0f; + this->child_hit_prob[nchilds] = (parent_area != 0.0f) ? bb_area(child->bb, child->bb + 3) / parent_area : 1.0f; nchilds++; } @@ -399,7 +398,7 @@ struct VBVH_optimalPackSIMD //Build DP table to find minimum cost to represent this node with a given cutsize - int bt [MAX_OPTIMIZE_CHILDS + 1][MAX_CUT_SIZE + 1]; //backtrace table + int bt[MAX_OPTIMIZE_CHILDS + 1][MAX_CUT_SIZE + 1]; //backtrace table float cost[MAX_OPTIMIZE_CHILDS + 1][MAX_CUT_SIZE + 1]; //cost table (can be reduced to float[2][MAX_CUT_COST]) for (int i = 0; i <= nchilds; i++) { @@ -410,13 +409,13 @@ struct VBVH_optimalPackSIMD cost[0][0] = 0; - for (int i = 1; i<=nchilds; i++) { - for (int size = i - 1; size/*+(nchilds-i)*/<=MAX_CUT_SIZE; size++) { - for (int cut = 1; cut+size/*+(nchilds-i)*/<=MAX_CUT_SIZE; cut++) { + for (int i = 1; i <= nchilds; i++) { + for (int size = i - 1; size /*+(nchilds-i)*/ <= MAX_CUT_SIZE; size++) { + for (int cut = 1; cut + size /*+(nchilds-i)*/ <= MAX_CUT_SIZE; cut++) { float new_cost = cost[i - 1][size] + child_hit_prob[i - 1] * child[i - 1]->get_cost(cut); - if (new_cost < cost[i][size+cut]) { - cost[i][size+cut] = new_cost; - bt[i][size+cut] = cut; + if (new_cost < cost[i][size + cut]) { + cost[i][size + cut] = new_cost; + bt[i][size + cut] = cut; } } } @@ -424,11 +423,11 @@ struct VBVH_optimalPackSIMD //Save the ways to archieve the minimum cost with a given cutsize for (int i = nchilds; i <= MAX_CUT_SIZE; i++) { - node->cut_cost[i-1] = cost[nchilds][i]; + node->cut_cost[i - 1] = cost[nchilds][i]; if (cost[nchilds][i] < INFINITY) { int current_size = i; - for (int j=nchilds; j>0; j--) { - child[j-1]->cut_size[i-1] = bt[j][current_size]; + for (int j = nchilds; j > 0; j--) { + child[j - 1]->cut_size[i - 1] = bt[j][current_size]; current_size -= bt[j][current_size]; } } @@ -439,23 +438,23 @@ struct VBVH_optimalPackSIMD void calc_costs(Node *node) { - if ( RE_rayobject_isAligned(node->child) ) { + if (RE_rayobject_isAligned(node->child) ) { int nchilds = 0; for (Node *child = node->child; child && RE_rayobject_isAligned(child); child = child->sibling) { calc_costs(child); nchilds++; } - for (int i=0; icut_cost[i] = INFINITY; //We are not allowed to look on nodes with with so many childs if (nchilds > MAX_CUT_SIZE) { float cost = 0; - float parent_area = bb_area(node->bb, node->bb+3); + float parent_area = bb_area(node->bb, node->bb + 3); for (Node *child = node->child; child && RE_rayobject_isAligned(child); child = child->sibling) { - cost += ((parent_area != 0.0f)? ( bb_area(child->bb, child->bb+3) / parent_area ): 1.0f) * child->get_cost(1); + cost += ((parent_area != 0.0f) ? (bb_area(child->bb, child->bb + 3) / parent_area) : 1.0f) * child->get_cost(1); } cost += testcost(nchilds); @@ -466,7 +465,7 @@ struct VBVH_optimalPackSIMD calc_best calc(node); //calc expected cost if we optimaly pack this node - for (int cutsize=nchilds; cutsize<=MAX_CUT_SIZE; cutsize++) { + for (int cutsize = nchilds; cutsize <= MAX_CUT_SIZE; cutsize++) { float m = node->get_cost(cutsize) + testcost(cutsize); if (m < node->cut_cost[0]) { node->cut_cost[0] = m; @@ -491,7 +490,7 @@ struct VBVH_optimalPackSIMD if (num == 0) { num++; first = true; } calc_costs(node); - if ((G.debug & G_DEBUG) && first) printf("expected cost = %f (%d)\n", node->cut_cost[0], node->best_cutsize ); + if ((G.debug & G_DEBUG) && first) printf("expected cost = %f (%d)\n", node->cut_cost[0], node->best_cutsize); node->optimize(); } return node; diff --git a/source/blender/render/intern/raytrace/svbvh.h b/source/blender/render/intern/raytrace/svbvh.h index ff402446b9f..a58094e5021 100644 --- a/source/blender/render/intern/raytrace/svbvh.h +++ b/source/blender/render/intern/raytrace/svbvh.h @@ -41,8 +41,7 @@ #include #include -struct SVBVHNode -{ +struct SVBVHNode { float child_bb[24]; SVBVHNode *child[4]; int nchilds; @@ -120,12 +119,12 @@ static int svbvh_node_stack_raycast(SVBVHNode *root, Isect *isec) node = stack[--stack_pos]; if (!svbvh_node_is_leaf(node)) { - int nchilds= node->nchilds; + int nchilds = node->nchilds; if (nchilds == 4) { - float *child_bb= node->child_bb; - int res = svbvh_bb_intersect_test_simd4(isec, ((__m128*) (child_bb))); - SVBVHNode **child= node->child; + float *child_bb = node->child_bb; + int res = svbvh_bb_intersect_test_simd4(isec, ((__m128 *) (child_bb))); + SVBVHNode **child = node->child; RE_RC_COUNT(isec->raycounter->simd_bb.test); @@ -135,8 +134,8 @@ static int svbvh_node_stack_raycast(SVBVHNode *root, Isect *isec) if (res & 8) { stack[stack_pos++] = child[3]; RE_RC_COUNT(isec->raycounter->simd_bb.hit); } } else { - float *child_bb= node->child_bb; - SVBVHNode **child= node->child; + float *child_bb = node->child_bb; + SVBVHNode **child = node->child; int i; for (i = 0; i < nchilds; i++) { @@ -147,7 +146,7 @@ static int svbvh_node_stack_raycast(SVBVHNode *root, Isect *isec) } } else { - hit |= RE_rayobject_intersect((RayObject*)node, isec); + hit |= RE_rayobject_intersect((RayObject *)node, isec); if (SHADOW && hit) break; } } @@ -160,7 +159,7 @@ template<> inline void bvh_node_merge_bb(SVBVHNode *node, float min[3], float max[3]) { if (is_leaf(node)) { - RE_rayobject_merge_bb((RayObject*)node, min, max); + RE_rayobject_merge_bb((RayObject *)node, min, max); } else { int i; @@ -180,7 +179,7 @@ inline void bvh_node_merge_bb(SVBVHNode *node, float min[3], float ma } } - for ( ; i < node->nchilds; i++) { + for (; i < node->nchilds; i++) { DO_MIN(node->child_bb + 6 * i, min); DO_MAX(node->child_bb + 3 + 6 * i, max); } @@ -193,8 +192,7 @@ inline void bvh_node_merge_bb(SVBVHNode *node, float min[3], float ma * Builds a SVBVH tree form a VBVHTree */ template -struct Reorganize_SVBVH -{ +struct Reorganize_SVBVH { MemArena *arena; float childs_per_node; @@ -220,14 +218,14 @@ struct Reorganize_SVBVH printf("%f childs per node\n", childs_per_node / nodes); printf("%d childs BB are useless\n", useless_bb); for (int i = 0; i < 16; i++) { - printf("%i childs per node: %d/%d = %f\n", i, nodes_with_childs[i], nodes, nodes_with_childs[i]/float(nodes)); + printf("%i childs per node: %d/%d = %f\n", i, nodes_with_childs[i], nodes, nodes_with_childs[i] / float(nodes)); } } } SVBVHNode *create_node(int nchilds) { - SVBVHNode *node = (SVBVHNode*)BLI_memarena_alloc(arena, sizeof(SVBVHNode)); + SVBVHNode *node = (SVBVHNode *)BLI_memarena_alloc(arena, sizeof(SVBVHNode)); node->nchilds = nchilds; return node; @@ -235,22 +233,22 @@ struct Reorganize_SVBVH void copy_bb(float *bb, const float *old_bb) { - std::copy(old_bb, old_bb+6, bb); + std::copy(old_bb, old_bb + 6, bb); } void prepare_for_simd(SVBVHNode *node) { - int i=0; + int i = 0; while (i + 4 <= node->nchilds) { - float vec_tmp[4*6]; - float *res = node->child_bb+6*i; - std::copy(res, res+6*4, vec_tmp); - - for (int j=0; j<6; j++) { - res[4*j+0] = vec_tmp[6*0+j]; - res[4*j+1] = vec_tmp[6*1+j]; - res[4*j+2] = vec_tmp[6*2+j]; - res[4*j+3] = vec_tmp[6*3+j]; + float vec_tmp[4 * 6]; + float *res = node->child_bb + 6 * i; + std::copy(res, res + 6 * 4, vec_tmp); + + for (int j = 0; j < 6; j++) { + res[4 * j + 0] = vec_tmp[6 * 0 + j]; + res[4 * j + 1] = vec_tmp[6 * 1 + j]; + res[4 * j + 2] = vec_tmp[6 * 2 + j]; + res[4 * j + 3] = vec_tmp[6 * 3 + j]; } i += 4; @@ -260,15 +258,15 @@ struct Reorganize_SVBVH /* amt must be power of two */ inline int padup(int num, int amt) { - return ((num+(amt-1))&~(amt-1)); + return ((num + (amt - 1)) & ~(amt - 1)); } SVBVHNode *transform(OldNode *old) { if (is_leaf(old)) - return (SVBVHNode*)old; + return (SVBVHNode *)old; if (is_leaf(old->child)) - return (SVBVHNode*)old->child; + return (SVBVHNode *)old->child; int nchilds = count_childs(old); int alloc_childs = nchilds; @@ -282,27 +280,27 @@ struct Reorganize_SVBVH if (nchilds < 16) nodes_with_childs[nchilds]++; - useless_bb += alloc_childs-nchilds; + useless_bb += alloc_childs - nchilds; while (alloc_childs > nchilds) { const static float def_bb[6] = { FLT_MAX, FLT_MAX, FLT_MAX, FLT_MIN, FLT_MIN, FLT_MIN }; alloc_childs--; node->child[alloc_childs] = NULL; - copy_bb(node->child_bb+alloc_childs*6, def_bb); + copy_bb(node->child_bb + alloc_childs * 6, def_bb); } - int i=nchilds; + int i = nchilds; for (OldNode *o_child = old->child; o_child; o_child = o_child->sibling) { i--; node->child[i] = transform(o_child); if (is_leaf(o_child)) { float bb[6]; - INIT_MINMAX(bb, bb+3); - RE_rayobject_merge_bb((RayObject*)o_child, bb, bb+3); - copy_bb(node->child_bb+i*6, bb); + INIT_MINMAX(bb, bb + 3); + RE_rayobject_merge_bb((RayObject *)o_child, bb, bb + 3); + copy_bb(node->child_bb + i * 6, bb); break; } else { - copy_bb(node->child_bb+i*6, o_child->bb); + copy_bb(node->child_bb + i * 6, o_child->bb); } } assert(i == 0); diff --git a/source/blender/render/intern/raytrace/vbvh.h b/source/blender/render/intern/raytrace/vbvh.h index d8ff9000a3f..ec671f95c76 100644 --- a/source/blender/render/intern/raytrace/vbvh.h +++ b/source/blender/render/intern/raytrace/vbvh.h @@ -40,9 +40,8 @@ /* * VBVHNode represents a BVHNode with support for a variable number of childrens */ -struct VBVHNode -{ - float bb[6]; +struct VBVHNode { + float bb[6]; VBVHNode *child; VBVHNode *sibling; @@ -107,8 +106,7 @@ void append_sibling(Node *node, Node *sibling) * Builds a binary VBVH from a rtbuild */ template -struct BuildBinaryVBVH -{ +struct BuildBinaryVBVH { MemArena *arena; RayObjectControl *control; @@ -126,7 +124,7 @@ struct BuildBinaryVBVH Node *create_node() { - Node *node = (Node*)BLI_memarena_alloc( arena, sizeof(Node) ); + Node *node = (Node *)BLI_memarena_alloc(arena, sizeof(Node) ); assert(RE_rayobject_isAligned(node)); node->sibling = NULL; @@ -146,7 +144,7 @@ struct BuildBinaryVBVH { return _transform(builder); - } catch(...) + } catch (...) { } return NULL; @@ -161,8 +159,8 @@ struct BuildBinaryVBVH } else if (size == 1) { Node *node = create_node(); - INIT_MINMAX(node->bb, node->bb+3); - rtbuild_merge_bb(builder, node->bb, node->bb+3); + INIT_MINMAX(node->bb, node->bb + 3); + rtbuild_merge_bb(builder, node->bb, node->bb + 3); node->child = (Node *) rtbuild_get_primitive(builder, 0); return node; } @@ -174,7 +172,7 @@ struct BuildBinaryVBVH Node **child = &node->child; int nc = rtbuild_split(builder); - INIT_MINMAX(node->bb, node->bb+3); + INIT_MINMAX(node->bb, node->bb + 3); assert(nc == 2); for (int i = 0; i < nc; i++) { @@ -183,7 +181,7 @@ struct BuildBinaryVBVH *child = _transform(&tmp); DO_MIN((*child)->bb, node->bb); - DO_MAX((*child)->bb+3, node->bb+3); + DO_MAX((*child)->bb + 3, node->bb + 3); child = &((*child)->sibling); } @@ -194,9 +192,8 @@ struct BuildBinaryVBVH }; #if 0 -template -struct Reorganize_VBVH -{ +template +struct Reorganize_VBVH { Tree *tree; Reorganize_VBVH(Tree *t) @@ -206,27 +203,27 @@ struct Reorganize_VBVH VBVHNode *create_node() { - VBVHNode *node = (VBVHNode*)BLI_memarena_alloc(tree->node_arena, sizeof(VBVHNode)); + VBVHNode *node = (VBVHNode *)BLI_memarena_alloc(tree->node_arena, sizeof(VBVHNode)); return node; } void copy_bb(VBVHNode *node, OldNode *old) { - std::copy( old->bb, old->bb+6, node->bb ); + std::copy(old->bb, old->bb + 6, node->bb); } VBVHNode *transform(OldNode *old) { if (is_leaf(old)) - return (VBVHNode*)old; + return (VBVHNode *)old; VBVHNode *node = create_node(); VBVHNode **child_ptr = &node->child; node->sibling = 0; - copy_bb(node,old); + copy_bb(node, old); - for(OldNode *o_child = old->child; o_child; o_child = o_child->sibling) + for (OldNode *o_child = old->child; o_child; o_child = o_child->sibling) { VBVHNode *n_child = transform(o_child); *child_ptr = n_child; diff --git a/source/blender/render/intern/source/convertblender.c b/source/blender/render/intern/source/convertblender.c index b69f9518c1a..c2b0e1e777f 100644 --- a/source/blender/render/intern/source/convertblender.c +++ b/source/blender/render/intern/source/convertblender.c @@ -902,7 +902,7 @@ static float *get_object_orco(Render *re, Object *ob) float *orco; if (!re->orco_hash) - re->orco_hash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "get_object_orco gh"); + re->orco_hash = BLI_ghash_ptr_new("get_object_orco gh"); orco = BLI_ghash_lookup(re->orco_hash, ob); @@ -924,7 +924,7 @@ static float *get_object_orco(Render *re, Object *ob) static void set_object_orco(Render *re, void *ob, float *orco) { if (!re->orco_hash) - re->orco_hash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "set_object_orco gh"); + re->orco_hash = BLI_ghash_ptr_new("set_object_orco gh"); BLI_ghash_insert(re->orco_hash, ob, orco); } @@ -4318,6 +4318,8 @@ static void finalize_render_object(Render *re, ObjectRen *obr, int timeoffset) /* Baking lets us define a quad split order */ split_quads(obr, re->r.bake_quad_split); } + else if(BKE_object_is_animated(re->scene, ob)) + split_quads(obr, 1); else { if ((re->r.mode & R_SIMPLIFY && re->r.simplify_flag & R_SIMPLE_NO_TRIANGULATE) == 0) check_non_flat_quads(obr); diff --git a/source/blender/render/intern/source/sss.c b/source/blender/render/intern/source/sss.c index c8a37998169..690598d8c05 100644 --- a/source/blender/render/intern/source/sss.c +++ b/source/blender/render/intern/source/sss.c @@ -990,7 +990,7 @@ void make_sss_tree(Render *re) { Material *mat; - re->sss_hash= BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "make_sss_tree gh"); + re->sss_hash= BLI_ghash_ptr_new("make_sss_tree gh"); re->i.infostr= "SSS preprocessing"; re->stats_draw(re->sdh, &re->i); diff --git a/source/blender/render/intern/source/strand.c b/source/blender/render/intern/source/strand.c index 6690425967c..02d342754ea 100644 --- a/source/blender/render/intern/source/strand.c +++ b/source/blender/render/intern/source/strand.c @@ -333,8 +333,8 @@ StrandShadeCache *strand_shade_cache_create(void) StrandShadeCache *cache; cache= MEM_callocN(sizeof(StrandShadeCache), "StrandShadeCache"); - cache->resulthash= BLI_ghash_new(BLI_ghashutil_pairhash, BLI_ghashutil_paircmp, "strand_shade_cache_create1 gh"); - cache->refcounthash= BLI_ghash_new(BLI_ghashutil_pairhash, BLI_ghashutil_paircmp, "strand_shade_cache_create2 gh"); + cache->resulthash= BLI_ghash_pair_new("strand_shade_cache_create1 gh"); + cache->refcounthash= BLI_ghash_pair_new("strand_shade_cache_create2 gh"); cache->memarena= BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "strand shade cache arena"); return cache; diff --git a/source/blender/render/intern/source/texture_ocean.c b/source/blender/render/intern/source/texture_ocean.c index c13347dc162..4ef88e4740a 100644 --- a/source/blender/render/intern/source/texture_ocean.c +++ b/source/blender/render/intern/source/texture_ocean.c @@ -56,7 +56,7 @@ extern struct Render R; /* ***** actual texture sampling ***** */ int ocean_texture(Tex *tex, float *texvec, TexResult *texres) { - OceanTex *ot= tex->ot; + OceanTex *ot = tex->ot; ModifierData *md; OceanModifierData *omd; @@ -64,8 +64,8 @@ int ocean_texture(Tex *tex, float *texvec, TexResult *texres) if ( !(ot) || !(ot->object) || - !(md = (ModifierData *)modifiers_findByType(ot->object, eModifierType_Ocean)) || - !(omd= (OceanModifierData *)md)->ocean) + !(md = (ModifierData *)modifiers_findByType(ot->object, eModifierType_Ocean)) || + !(omd = (OceanModifierData *)md)->ocean) { return 0; } @@ -75,10 +75,10 @@ int ocean_texture(Tex *tex, float *texvec, TexResult *texres) int retval = TEX_INT; OceanResult ocr; - const float u = 0.5f+0.5f*texvec[0]; - const float v = 0.5f+0.5f*texvec[1]; + const float u = 0.5f + 0.5f * texvec[0]; + const float v = 0.5f + 0.5f * texvec[1]; - if (omd->oceancache && omd->cached==TRUE) { + if (omd->oceancache && omd->cached == TRUE) { CLAMP(cfra, omd->bakestart, omd->bakeend); cfra -= omd->bakestart; // shift to 0 based diff --git a/source/blender/windowmanager/intern/wm.c b/source/blender/windowmanager/intern/wm.c index 7285e155dc6..a34d294461c 100644 --- a/source/blender/windowmanager/intern/wm.c +++ b/source/blender/windowmanager/intern/wm.c @@ -183,7 +183,7 @@ void WM_menutype_freelink(MenuType *mt) /* called on initialize WM_init() */ void WM_menutype_init(void) { - menutypes_hash = BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp, "menutypes_hash gh"); + menutypes_hash = BLI_ghash_str_new("menutypes_hash gh"); } void WM_menutype_free(void) diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index c18625c0168..7f3a93258da 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -3740,7 +3740,7 @@ void wm_operatortype_free(void) /* called on initialize WM_init() */ void wm_operatortype_init(void) { - global_ops_hash = BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp, "wm_operatortype_init gh"); + global_ops_hash = BLI_ghash_str_new("wm_operatortype_init gh"); WM_operatortype_append(WM_OT_window_duplicate); WM_operatortype_append(WM_OT_read_homefile); diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index 5f6b15dee02..af3ba02ed4d 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -932,7 +932,7 @@ static int wm_window_timer(const bContext *C) wtnext = wt->next; /* in case timer gets removed */ win = wt->win; - if (wt->sleep== 0) { + if (wt->sleep == 0) { if (time > wt->ntime) { wt->delta = time - wt->ltime; wt->duration += wt->delta;