diff --git a/SConstruct b/SConstruct index 993167acfe9..681e3964a13 100644 --- a/SConstruct +++ b/SConstruct @@ -280,8 +280,10 @@ if 'blenderlite' in B.targets: if env['OURPLATFORM']=='darwin': print B.bc.OKGREEN + "Detected Xcode version: -- " + B.bc.ENDC + env['XCODE_CUR_VER'] + " --" print "Available " + env['MACOSX_SDK_CHECK'] - if not 'Mac OS X 10.5' in env['MACOSX_SDK_CHECK']: - print B.bc.OKGREEN + "MacOSX10.5.sdk not available:" + B.bc.ENDC + " using MacOSX10.6.sdk" + if not 'Mac OS X 10.6' in env['MACOSX_SDK_CHECK']: + print B.bc.OKGREEN + "Auto-setting available MacOSX SDK -> " + B.bc.ENDC + "MacOSX10.7.sdk" + elif not 'Mac OS X 10.5' in env['MACOSX_SDK_CHECK']: + print B.bc.OKGREEN + "Auto-setting available MacOSX SDK -> " + B.bc.ENDC + "MacOSX10.6.sdk" else: print B.bc.OKGREEN + "Found recommended sdk :" + B.bc.ENDC + " using MacOSX10.5.sdk" diff --git a/build_files/scons/config/darwin-config.py b/build_files/scons/config/darwin-config.py index e5bce90e50d..1ce9416d5c4 100644 --- a/build_files/scons/config/darwin-config.py +++ b/build_files/scons/config/darwin-config.py @@ -32,6 +32,8 @@ elif cmd_res[:2]=='10': MAC_CUR_VER='10.6' elif cmd_res[:2]=='11': MAC_CUR_VER='10.7' +elif cmd_res[:2]=='12': + MAC_CUR_VER='10.8' cmd = 'xcodebuild -version' cmd_xcode=commands.getoutput(cmd) XCODE_CUR_VER=cmd_xcode[6:][:3] # truncate output to major.minor version @@ -75,7 +77,7 @@ else : LCGDIR = '#../lib/darwin-9.x.universal' CC = 'gcc-4.2' CXX = 'g++-4.2' - else: + elif 'Mac OS X 10.6' in MACOSX_SDK_CHECK: # OSX 10.6/7 with Xcode 4.x MAC_MIN_VERS = '10.6' MACOSX_DEPLOYMENT_TARGET = '10.6' @@ -83,6 +85,14 @@ else : LCGDIR = '#../lib/darwin-9.x.universal' CC = 'gcc-4.2' CXX = 'g++-4.2' + else: + # OSX 10.8 with Xcode 4.4 and higher (no 10.6sdk! ) + MAC_MIN_VERS = '10.6' + MACOSX_DEPLOYMENT_TARGET = '10.6' + MACOSX_SDK='/Developer/SDKs/MacOSX10.7.sdk' + LCGDIR = '#../lib/darwin-9.x.universal' + CC = 'gcc' + CXX = 'g++' LIBDIR = '${LCGDIR}' @@ -333,8 +343,8 @@ if not WITH_OSX_STATICPYTHON: #note to build succesfully on 10.3.9 SDK you need to patch 10.3.9 by adding the SystemStubs.a lib from 10.4 -#for 10.7.sdk, SystemStubs needs to be excluded (lib doesn't exist anymore) -if MACOSX_DEPLOYMENT_TARGET == '10.7': +#for > 10.7.sdk, SystemStubs needs to be excluded (lib doesn't exist anymore) +if MACOSX_SDK.endswith("10.7.sdk") or MACOSX_SDK.endswith("10.8.sdk"): LLIBS = ['stdc++'] else: LLIBS = ['stdc++', 'SystemStubs'] diff --git a/build_files/scons/tools/Blender.py b/build_files/scons/tools/Blender.py index ff7b3878733..2a6e027a819 100644 --- a/build_files/scons/tools/Blender.py +++ b/build_files/scons/tools/Blender.py @@ -693,11 +693,23 @@ def UnixPyBundle(target=None, source=None, env=None): run("rm -r '%s/turtle.py'" % py_target) run("rm -f '%s/lib-dynload/_tkinter.so'" % py_target) + if env['WITH_BF_PYTHON_INSTALL_NUMPY']: + numpy_src = py_src + "/site-packages/numpy" + numpy_target = py_target + "/site-packages/numpy" + + if os.path.exists(numpy_src): + print 'Install numpy from:' + print '\t"%s" into...' % numpy_src + print '\t"%s"\n' % numpy_target + + run("cp -R '%s' '%s'" % (numpy_src, os.path.dirname(numpy_target))) + else: + print 'Failed to find numpy at %s, skipping copying' % numpy_src + run("find '%s' -type d -name 'test' -prune -exec rm -rf {} ';'" % py_target) run("find '%s' -type d -name '__pycache__' -exec rm -rf {} ';'" % py_target) run("find '%s' -name '*.py[co]' -exec rm -rf {} ';'" % py_target) run("find '%s' -name '*.so' -exec strip -s {} ';'" % py_target) - #### END ACTION STUFF ######### diff --git a/build_files/scons/tools/btools.py b/build_files/scons/tools/btools.py index af484ed382e..e08a013d081 100644 --- a/build_files/scons/tools/btools.py +++ b/build_files/scons/tools/btools.py @@ -135,7 +135,7 @@ def validate_arguments(args, bc): 'BF_CXX', 'WITH_BF_STATICCXX', 'BF_CXX_LIB_STATIC', 'BF_TWEAK_MODE', 'BF_SPLIT_SRC', 'WITHOUT_BF_INSTALL', - 'WITHOUT_BF_PYTHON_INSTALL', 'WITHOUT_BF_PYTHON_UNPACK', + 'WITHOUT_BF_PYTHON_INSTALL', 'WITHOUT_BF_PYTHON_UNPACK', 'WITH_BF_PYTHON_INSTALL_NUMPY' 'WITHOUT_BF_OVERWRITE_INSTALL', 'WITH_BF_OPENMP', 'BF_OPENMP', 'BF_OPENMP_LIBPATH', 'WITH_GHOST_COCOA', @@ -520,6 +520,7 @@ def read_opts(env, cfg, args): (BoolVariable('BF_SPLIT_SRC', 'Split src lib into several chunks if true', False)), (BoolVariable('WITHOUT_BF_INSTALL', 'dont install if true', False)), (BoolVariable('WITHOUT_BF_PYTHON_INSTALL', 'dont install Python modules if true', False)), + (BoolVariable('WITH_BF_PYTHON_INSTALL_NUMPY', 'install Python mumpy module', False)), (BoolVariable('WITHOUT_BF_PYTHON_UNPACK', 'dont remove and unpack Python modules everytime if true', False)), (BoolVariable('WITHOUT_BF_OVERWRITE_INSTALL', 'dont remove existing files before breating the new install directory (set to False when making packages for others)', False)), (BoolVariable('BF_FANCY', 'Enable fancy output if true', True)), diff --git a/doc/python_api/examples/bpy.ops.2.py b/doc/python_api/examples/bpy.ops.2.py index 01e7dc1902e..cf6df946873 100644 --- a/doc/python_api/examples/bpy.ops.2.py +++ b/doc/python_api/examples/bpy.ops.2.py @@ -19,4 +19,4 @@ The execution context is as a non keyword, string argument in: # group add popup import bpy -bpy.ops.object.group_instance_add('INVOKE_DEFAULT') \ No newline at end of file +bpy.ops.object.group_instance_add('INVOKE_DEFAULT') diff --git a/doc/python_api/rst/bge.logic.rst b/doc/python_api/rst/bge.logic.rst index d071984b14b..0d1d0df88c3 100644 --- a/doc/python_api/rst/bge.logic.rst +++ b/doc/python_api/rst/bge.logic.rst @@ -172,7 +172,7 @@ General functions Restarts the current game by reloading the .blend file (the last saved version, not what is currently running). -.. function:: LibLoad(blend, type, data, load_actions=False, verbose=False) +.. function:: LibLoad(blend, type, data, load_actions=False, verbose=False, load_scripts=True) Converts the all of the datablocks of the given type from the given blend. @@ -186,6 +186,8 @@ General functions :type load_actions: bool :arg verbose: Whether or not to print debugging information (e.g., "SceneName: Scene") :type verbose: bool + :arg load_scripts: Whether or not to load text datablocks as well (can be disabled for some extra security) + :type load_scripts: bool .. function:: LibNew(name, type, data) diff --git a/doc/python_api/rst/info_best_practice.rst b/doc/python_api/rst/info_best_practice.rst index 481555d412a..37de8fa381d 100644 --- a/doc/python_api/rst/info_best_practice.rst +++ b/doc/python_api/rst/info_best_practice.rst @@ -56,7 +56,69 @@ To enable line length checks use this instead. User Interface Layout ===================== -TODO: Thomas +Some notes to keep in mind when writing UI layouts: + +* UI code is quite simple. Layout declarations are there to easily create a decent layout. + + General rule here: If you need more code for the layout declaration, then for the actual properties, you do it wrong. + +Example layouts: + +* layout() + + The basic layout is a simple Top -> Bottom layout. + + .. code-block:: python + + layout.prop() + layout.prop() + +* layout.row() + + Use row(), when you want more than 1 propertey in one line. + + .. code-block:: python + + row = layout.row() + row.prop() + row.prop() + +* layout.column() + + Use column(), when you want your properties in a column. + + .. code-block:: python + + col = layout.column() + col.prop() + col.prop() + +* layout.split() + + This can be used to create more complex layouts. For example you can split the layout and create two column() layouts next to each other. + Don't use split, when you simply want two properties in a row. Use row() for that. + + .. code-block:: python + + split = layout.split() + + col = split.column() + col.prop() + col.prop() + + col = split.column() + col.prop() + col.prop() + +Declaration names: + +Try to only use these variable names for layout declarations: + +* row for a row() layout +* col for a column() layout +* split for a split() layout +* flow for a column_flow() layout +* sub for a sub layout (a column inside a column for example) Script Efficiency diff --git a/doc/python_api/sphinx_doc_gen.py b/doc/python_api/sphinx_doc_gen.py index 57dec830c74..ed014f7553b 100644 --- a/doc/python_api/sphinx_doc_gen.py +++ b/doc/python_api/sphinx_doc_gen.py @@ -979,6 +979,7 @@ def pycontext2sphinx(basepath): "meta_ball": ("MetaBall", False), "object": ("Object", False), "particle_edit_object": ("Object", False), + "particle_settings": ("ParticleSettings", False), "particle_system": ("ParticleSystem", False), "particle_system_editable": ("ParticleSystem", False), "pose_bone": ("PoseBone", False), diff --git a/extern/bullet2/patches/ghost_character.patch b/extern/bullet2/patches/ghost_character.patch new file mode 100644 index 00000000000..d4098cb8bc2 --- /dev/null +++ b/extern/bullet2/patches/ghost_character.patch @@ -0,0 +1,28 @@ +Index: extern/bullet2/src/BulletDynamics/Character/btKinematicCharacterController.cpp +=================================================================== +--- extern/bullet2/src/BulletDynamics/Character/btKinematicCharacterController.cpp (revision 49183) ++++ extern/bullet2/src/BulletDynamics/Character/btKinematicCharacterController.cpp (working copy) +@@ -77,6 +77,9 @@ + if (convexResult.m_hitCollisionObject == m_me) + return btScalar(1.0); + ++ if (!convexResult.m_hitCollisionObject->hasContactResponse()) ++ return btScalar(1.0); ++ + btVector3 hitNormalWorld; + if (normalInWorldSpace) + { +@@ -173,7 +176,12 @@ + m_manifoldArray.resize(0); + + btBroadphasePair* collisionPair = &m_ghostObject->getOverlappingPairCache()->getOverlappingPairArray()[i]; +- ++ btCollisionObject* obj0 = static_cast(collisionPair->m_pProxy0->m_clientObject); ++ btCollisionObject* obj1 = static_cast(collisionPair->m_pProxy1->m_clientObject); ++ ++ if ((obj0 && !obj0->hasContactResponse()) || (obj1 && !obj1->hasContactResponse())) ++ continue; ++ + if (collisionPair->m_algorithm) + collisionPair->m_algorithm->getAllContactManifolds(m_manifoldArray); + diff --git a/extern/bullet2/readme.txt b/extern/bullet2/readme.txt index e537ac26189..343cb104c4d 100644 --- a/extern/bullet2/readme.txt +++ b/extern/bullet2/readme.txt @@ -13,3 +13,7 @@ Originally committed in blender svn revision: 45908. Apply patches/make_id.patch to prevent duplicated define of MAKE_ID macro in blender side and bullet side. Sergey + +Apply patches/ghost_character.path to prevent characters from colliding with ghost objects. +Mitchell + diff --git a/extern/bullet2/src/BulletDynamics/Character/btKinematicCharacterController.cpp b/extern/bullet2/src/BulletDynamics/Character/btKinematicCharacterController.cpp index f733dc0cd22..5fd4ee28511 100644 --- a/extern/bullet2/src/BulletDynamics/Character/btKinematicCharacterController.cpp +++ b/extern/bullet2/src/BulletDynamics/Character/btKinematicCharacterController.cpp @@ -77,6 +77,9 @@ public: if (convexResult.m_hitCollisionObject == m_me) return btScalar(1.0); + if (!convexResult.m_hitCollisionObject->hasContactResponse()) + return btScalar(1.0); + btVector3 hitNormalWorld; if (normalInWorldSpace) { @@ -173,7 +176,12 @@ bool btKinematicCharacterController::recoverFromPenetration ( btCollisionWorld* m_manifoldArray.resize(0); btBroadphasePair* collisionPair = &m_ghostObject->getOverlappingPairCache()->getOverlappingPairArray()[i]; - + btCollisionObject* obj0 = static_cast(collisionPair->m_pProxy0->m_clientObject); + btCollisionObject* obj1 = static_cast(collisionPair->m_pProxy1->m_clientObject); + + if ((obj0 && !obj0->hasContactResponse()) || (obj1 && !obj1->hasContactResponse())) + continue; + if (collisionPair->m_algorithm) collisionPair->m_algorithm->getAllContactManifolds(m_manifoldArray); diff --git a/extern/libmv/libmv/simple_pipeline/camera_intrinsics.cc b/extern/libmv/libmv/simple_pipeline/camera_intrinsics.cc index ab9b21d6dfd..6319846a079 100644 --- a/extern/libmv/libmv/simple_pipeline/camera_intrinsics.cc +++ b/extern/libmv/libmv/simple_pipeline/camera_intrinsics.cc @@ -209,7 +209,7 @@ void CameraIntrinsics::ComputeLookupGrid(Grid* grid, int width, int height, doub if( ix >= width-2 ) ix = width-2; if( iy >= height-2 ) iy = height-2; - Offset offset = { ix-x, iy-y, fx, fy }; + Offset offset = { (short)(ix-x), (short)(iy-y), (unsigned char)fx, (unsigned char)fy }; grid->offset[y*width+x] = offset; } } diff --git a/extern/libmv/libmv/simple_pipeline/detect.cc b/extern/libmv/libmv/simple_pipeline/detect.cc index 8ac42ab0aba..8a093dadeca 100644 --- a/extern/libmv/libmv/simple_pipeline/detect.cc +++ b/extern/libmv/libmv/simple_pipeline/detect.cc @@ -66,7 +66,7 @@ std::vector DetectFAST(const unsigned char* data, int width, int height Feature *all_features = new Feature[num_features]; for(int i = 0; i < num_features; ++i) { - Feature a = { nonmax[i].x, nonmax[i].y, scores[i], 0 }; + Feature a = { (float)nonmax[i].x, (float)nonmax[i].y, (float)scores[i], 0 }; all_features[i] = a; } @@ -173,7 +173,7 @@ void DetectMORAVEC(ubyte* image, int stride, int width, int height, Feature* det for(int y=16; ymin) detected[i++] = f; } } diff --git a/extern/libmv/third_party/ceres/include/ceres/jet.h b/extern/libmv/third_party/ceres/include/ceres/jet.h index 264861735ed..a37870210f1 100644 --- a/extern/libmv/third_party/ceres/include/ceres/jet.h +++ b/extern/libmv/third_party/ceres/include/ceres/jet.h @@ -163,8 +163,8 @@ #include "Eigen/Core" -// Visual Studio 2010 or older version -#if defined(_MSC_VER) && _MSC_VER <= 1600 +// Visual Studio 2012 or older version +#if defined(_MSC_VER) && _MSC_VER <= 1700 namespace std { inline bool isfinite(double x) { return _finite(x); } inline bool isinf (double x) { return !_finite(x) && !_isnan(x); } diff --git a/extern/libmv/third_party/ceres/internal/ceres/collections_port.h b/extern/libmv/third_party/ceres/internal/ceres/collections_port.h index 55f72539023..6f8a830a85e 100644 --- a/extern/libmv/third_party/ceres/internal/ceres/collections_port.h +++ b/extern/libmv/third_party/ceres/internal/ceres/collections_port.h @@ -33,7 +33,7 @@ #ifndef CERES_INTERNAL_COLLECTIONS_PORT_H_ #define CERES_INTERNAL_COLLECTIONS_PORT_H_ -#if defined(_MSC_VER) && _MSC_VER <= 1600 +#if defined(_MSC_VER) && _MSC_VER <= 1700 #include #include #else diff --git a/extern/recastnavigation/Recast/Source/RecastContour.cpp b/extern/recastnavigation/Recast/Source/RecastContour.cpp index 078c464e5f4..df943838ffb 100644 --- a/extern/recastnavigation/Recast/Source/RecastContour.cpp +++ b/extern/recastnavigation/Recast/Source/RecastContour.cpp @@ -321,7 +321,7 @@ static void simplifyContour(rcIntArray& points, rcIntArray& simplified, // Find maximum deviation from the segment. float maxd = 0; - int maxi = -1; + int i_max = -1; int ci, cinc, endi; // Traverse the segment in lexilogical order so that the @@ -350,7 +350,7 @@ static void simplifyContour(rcIntArray& points, rcIntArray& simplified, if (d > maxd) { maxd = d; - maxi = ci; + i_max = ci; } ci = (ci+cinc) % pn; } @@ -359,7 +359,7 @@ static void simplifyContour(rcIntArray& points, rcIntArray& simplified, // If the max deviation is larger than accepted error, // add new point, else continue to next segment. - if (maxi != -1 && maxd > (maxError*maxError)) + if (i_max != -1 && maxd > (maxError*maxError)) { // Add space for the new point. simplified.resize(simplified.size()+4); @@ -372,10 +372,10 @@ static void simplifyContour(rcIntArray& points, rcIntArray& simplified, simplified[j*4+3] = simplified[(j-1)*4+3]; } // Add the point. - simplified[(i+1)*4+0] = points[maxi*4+0]; - simplified[(i+1)*4+1] = points[maxi*4+1]; - simplified[(i+1)*4+2] = points[maxi*4+2]; - simplified[(i+1)*4+3] = maxi; + simplified[(i+1)*4+0] = points[i_max*4+0]; + simplified[(i+1)*4+1] = points[i_max*4+1]; + simplified[(i+1)*4+2] = points[i_max*4+2]; + simplified[(i+1)*4+3] = i_max; } else { @@ -399,7 +399,7 @@ static void simplifyContour(rcIntArray& points, rcIntArray& simplified, const int bi = simplified[ii*4+3]; // Find maximum deviation from the segment. - int maxi = -1; + int i_max = -1; int ci = (ai+1) % pn; // Tessellate only outer edges or edges between areas. @@ -423,19 +423,19 @@ static void simplifyContour(rcIntArray& points, rcIntArray& simplified, if (bx > ax || (bx == ax && bz > az)) { const int n = bi < ai ? (bi+pn - ai) : (bi - ai); - maxi = (ai + n/2) % pn; + i_max = (ai + n/2) % pn; } else { const int n = bi < ai ? (bi+pn - ai) : (bi - ai); - maxi = (ai + (n+1)/2) % pn; + i_max = (ai + (n+1)/2) % pn; } } } // If the max deviation is larger than accepted error, // add new point, else continue to next segment. - if (maxi != -1) + if (i_max != -1) { // Add space for the new point. simplified.resize(simplified.size()+4); @@ -448,10 +448,10 @@ static void simplifyContour(rcIntArray& points, rcIntArray& simplified, simplified[j*4+3] = simplified[(j-1)*4+3]; } // Add the point. - simplified[(i+1)*4+0] = points[maxi*4+0]; - simplified[(i+1)*4+1] = points[maxi*4+1]; - simplified[(i+1)*4+2] = points[maxi*4+2]; - simplified[(i+1)*4+3] = maxi; + simplified[(i+1)*4+0] = points[i_max*4+0]; + simplified[(i+1)*4+1] = points[i_max*4+1]; + simplified[(i+1)*4+2] = points[i_max*4+2]; + simplified[(i+1)*4+3] = i_max; } else { diff --git a/extern/recastnavigation/Recast/Source/RecastMesh.cpp b/extern/recastnavigation/Recast/Source/RecastMesh.cpp index ef37d569a17..e6d89eed3a8 100644 --- a/extern/recastnavigation/Recast/Source/RecastMesh.cpp +++ b/extern/recastnavigation/Recast/Source/RecastMesh.cpp @@ -305,7 +305,7 @@ static int triangulate(int n, const int* verts, int* indices, int* tris) while (n > 3) { int minLen = -1; - int mini = -1; + int i_min = -1; for (int i = 0; i < n; i++) { int i1 = next(i, n); @@ -321,12 +321,12 @@ static int triangulate(int n, const int* verts, int* indices, int* tris) if (minLen < 0 || len < minLen) { minLen = len; - mini = i; + i_min = i; } } } - if (mini == -1) + if (i_min == -1) { // Should not happen. /* printf("mini == -1 ntris=%d n=%d\n", ntris, n); @@ -338,7 +338,7 @@ static int triangulate(int n, const int* verts, int* indices, int* tris) return -ntris; } - int i = mini; + int i = i_min; int i1 = next(i, n); int i2 = next(i1, n); diff --git a/extern/recastnavigation/Recast/Source/RecastMeshDetail.cpp b/extern/recastnavigation/Recast/Source/RecastMeshDetail.cpp index 3922c864eba..130c08ec369 100644 --- a/extern/recastnavigation/Recast/Source/RecastMeshDetail.cpp +++ b/extern/recastnavigation/Recast/Source/RecastMeshDetail.cpp @@ -579,23 +579,23 @@ static bool buildPolyDetail(rcContext* ctx, const float* in, const int nin, const float* vb = &edge[b*3]; // Find maximum deviation along the segment. float maxd = 0; - int maxi = -1; + int i_max = -1; for (int m = a+1; m < b; ++m) { float d = distancePtSeg(&edge[m*3],va,vb); if (d > maxd) { maxd = d; - maxi = m; + i_max = m; } } // If the max deviation is larger than accepted error, // add new point, else continue to next segment. - if (maxi != -1 && maxd > rcSqr(sampleMaxError)) + if (i_max != -1 && maxd > rcSqr(sampleMaxError)) { for (int m = nidx; m > k; --m) idx[m] = idx[m-1]; - idx[k+1] = maxi; + idx[k+1] = i_max; nidx++; } else diff --git a/intern/audaspace/FX/AUD_ButterworthFactory.h b/intern/audaspace/FX/AUD_ButterworthFactory.h index d3606270154..dc8b4d92775 100644 --- a/intern/audaspace/FX/AUD_ButterworthFactory.h +++ b/intern/audaspace/FX/AUD_ButterworthFactory.h @@ -56,8 +56,8 @@ public: AUD_ButterworthFactory(AUD_Reference factory, float frequency); virtual void recalculateCoefficients(AUD_SampleRate rate, - std::vector& b, - std::vector& a); + std::vector& b, + std::vector& a); }; #endif //__AUD_BUTTERWORTHFACTORY_H__ diff --git a/intern/audaspace/FX/AUD_DynamicIIRFilterFactory.h b/intern/audaspace/FX/AUD_DynamicIIRFilterFactory.h index fef379f68b1..5b297db2d56 100644 --- a/intern/audaspace/FX/AUD_DynamicIIRFilterFactory.h +++ b/intern/audaspace/FX/AUD_DynamicIIRFilterFactory.h @@ -56,8 +56,8 @@ public: * \param[out] a The output filter coefficients. */ virtual void recalculateCoefficients(AUD_SampleRate rate, - std::vector& b, - std::vector& a)=0; + std::vector& b, + std::vector& a)=0; }; #endif // __AUD_DYNAMICIIRFILTERFACTORY_H__ diff --git a/intern/audaspace/FX/AUD_FaderFactory.h b/intern/audaspace/FX/AUD_FaderFactory.h index 8fcd4baa623..82eaf2fae9f 100644 --- a/intern/audaspace/FX/AUD_FaderFactory.h +++ b/intern/audaspace/FX/AUD_FaderFactory.h @@ -68,8 +68,8 @@ public: * \param length How long fading should last in seconds. */ AUD_FaderFactory(AUD_Reference factory, - AUD_FadeType type = AUD_FADE_IN, - float start = 0.0f, float length = 1.0f); + AUD_FadeType type = AUD_FADE_IN, + float start = 0.0f, float length = 1.0f); /** * Returns the fading type. diff --git a/intern/audaspace/intern/AUD_3DMath.h b/intern/audaspace/intern/AUD_3DMath.h index f39566958cd..1b109ebee1e 100644 --- a/intern/audaspace/intern/AUD_3DMath.h +++ b/intern/audaspace/intern/AUD_3DMath.h @@ -136,8 +136,8 @@ public: inline AUD_Vector3 cross(const AUD_Vector3& op) const { return AUD_Vector3(m_y * op.m_z - m_z * op.m_y, - m_z * op.m_x - m_x * op.m_z, - m_x * op.m_y - m_y * op.m_x); + m_z * op.m_x - m_x * op.m_z, + m_x * op.m_y - m_y * op.m_x); } /** diff --git a/intern/audaspace/intern/AUD_C-API.h b/intern/audaspace/intern/AUD_C-API.h index 66e6984c71b..6af0c648d0e 100644 --- a/intern/audaspace/intern/AUD_C-API.h +++ b/intern/audaspace/intern/AUD_C-API.h @@ -442,10 +442,10 @@ extern void AUD_closeReadDevice(AUD_Device* device); * The sound is therefore bandpassed, rectified and resampled. */ extern float* AUD_readSoundBuffer(const char* filename, float low, float high, - float attack, float release, float threshold, - int accumulate, int additive, int square, - float sthreshold, double samplerate, - int* length); + float attack, float release, float threshold, + int accumulate, int additive, int square, + float sthreshold, double samplerate, + int* length); /** * Pauses a playing sound after a specific amount of time. @@ -493,7 +493,7 @@ extern void AUD_setSequencerFPS(AUD_Sound* sequencer, float fps); * \return The entry added. */ extern AUD_SEntry* AUD_addSequence(AUD_Sound* sequencer, AUD_Sound* sound, - float begin, float end, float skip); + float begin, float end, float skip); /** * Removes an entry from the scene. @@ -567,8 +567,8 @@ extern void AUD_setSequencerAnimData(AUD_Sound* sequencer, AUD_AnimateableProper * \param cone_volume_outer The volume outside the outer cone. */ extern void AUD_updateSequenceData(AUD_SEntry* entry, float volume_max, float volume_min, - float distance_max, float distance_reference, float attenuation, - float cone_angle_outer, float cone_angle_inner, float cone_volume_outer); + float distance_max, float distance_reference, float attenuation, + float cone_angle_outer, float cone_angle_inner, float cone_volume_outer); /** * Updates all non-animated parameters of the entry. @@ -578,7 +578,7 @@ extern void AUD_updateSequenceData(AUD_SEntry* entry, float volume_max, float vo * \param model The distance model for distance calculation. */ extern void AUD_updateSequencerData(AUD_Sound* sequencer, float speed_of_sound, - float factor, AUD_DistanceModel model); + float factor, AUD_DistanceModel model); /** * Sets the audio output specification of the sound scene to the specs of the diff --git a/intern/boolop/intern/BOP_BSPNode.h b/intern/boolop/intern/BOP_BSPNode.h index e8646cd904c..6c110416dd7 100644 --- a/intern/boolop/intern/BOP_BSPNode.h +++ b/intern/boolop/intern/BOP_BSPNode.h @@ -52,43 +52,43 @@ public: // Construction methods BOP_BSPNode(const MT_Plane3& plane); ~BOP_BSPNode(); - unsigned int addFace(const BOP_BSPPoints& pts, - const MT_Plane3& plane); - BOP_TAG classifyFace(const MT_Point3& p1, - const MT_Point3& p2, - const MT_Point3& p3, - const MT_Plane3& plane) const; - BOP_TAG simplifiedClassifyFace(const MT_Point3& p1, - const MT_Point3& p2, - const MT_Point3& p3, - const MT_Plane3& plane) const; + unsigned int addFace(const BOP_BSPPoints& pts, + const MT_Plane3& plane); + BOP_TAG classifyFace(const MT_Point3& p1, + const MT_Point3& p2, + const MT_Point3& p3, + const MT_Plane3& plane) const; + BOP_TAG simplifiedClassifyFace(const MT_Point3& p1, + const MT_Point3& p2, + const MT_Point3& p3, + const MT_Plane3& plane) const; protected: BOP_TAG testPoint(const MT_Point3& p) const; - BOP_TAG classifyFaceIN(const MT_Point3& p1, - const MT_Point3& p2, - const MT_Point3& p3, - const MT_Plane3& plane) const; - BOP_TAG classifyFaceOUT(const MT_Point3& p1, - const MT_Point3& p2, - const MT_Point3& p3, - const MT_Plane3& plane) const; - BOP_TAG simplifiedClassifyFaceIN(const MT_Point3& p1, - const MT_Point3& p2, - const MT_Point3& p3, - const MT_Plane3& plane) const; - BOP_TAG simplifiedClassifyFaceOUT(const MT_Point3& p1, - const MT_Point3& p2, - const MT_Point3& p3, - const MT_Plane3& plane) const; + BOP_TAG classifyFaceIN(const MT_Point3& p1, + const MT_Point3& p2, + const MT_Point3& p3, + const MT_Plane3& plane) const; + BOP_TAG classifyFaceOUT(const MT_Point3& p1, + const MT_Point3& p2, + const MT_Point3& p3, + const MT_Plane3& plane) const; + BOP_TAG simplifiedClassifyFaceIN(const MT_Point3& p1, + const MT_Point3& p2, + const MT_Point3& p3, + const MT_Plane3& plane) const; + BOP_TAG simplifiedClassifyFaceOUT(const MT_Point3& p1, + const MT_Point3& p2, + const MT_Point3& p3, + const MT_Plane3& plane) const; bool hasSameOrientation(const MT_Plane3& plane) const; int compChildren() const; - int splitTriangle(MT_Point3* res, - const MT_Plane3& plane, - const MT_Point3& p1, - const MT_Point3& p2, - const MT_Point3& p3, - const BOP_TAG tag) const; + int splitTriangle(MT_Point3* res, + const MT_Plane3& plane, + const MT_Point3& p1, + const MT_Point3& p2, + const MT_Point3& p3, + const BOP_TAG tag) const; public: // Inline acces methods diff --git a/intern/boolop/intern/BOP_BSPTree.h b/intern/boolop/intern/BOP_BSPTree.h index b3abd55bf2a..5dc55e47175 100644 --- a/intern/boolop/intern/BOP_BSPTree.h +++ b/intern/boolop/intern/BOP_BSPTree.h @@ -50,22 +50,22 @@ public: virtual ~BOP_BSPTree(); void addMesh(BOP_Mesh* mesh, BOP_Faces& facesList); void addFace(BOP_Mesh* mesh, BOP_Face* face); - virtual void addFace(const MT_Point3& p1, - const MT_Point3& p2, - const MT_Point3& p3, - const MT_Plane3& plane); - BOP_TAG classifyFace(const MT_Point3& p1, - const MT_Point3& p2, - const MT_Point3& p3, - const MT_Plane3& plane) const; - BOP_TAG filterFace(const MT_Point3& p1, - const MT_Point3& p2, - const MT_Point3& p3, - BOP_Face* face); - BOP_TAG simplifiedClassifyFace(const MT_Point3& p1, - const MT_Point3& p2, - const MT_Point3& p3, - const MT_Plane3& plane) const; + virtual void addFace(const MT_Point3& p1, + const MT_Point3& p2, + const MT_Point3& p3, + const MT_Plane3& plane); + BOP_TAG classifyFace(const MT_Point3& p1, + const MT_Point3& p2, + const MT_Point3& p3, + const MT_Plane3& plane) const; + BOP_TAG filterFace(const MT_Point3& p1, + const MT_Point3& p2, + const MT_Point3& p3, + BOP_Face* face); + BOP_TAG simplifiedClassifyFace(const MT_Point3& p1, + const MT_Point3& p2, + const MT_Point3& p3, + const MT_Plane3& plane) const; unsigned int getDeep() const; void print(); inline void setRoot(BOP_BSPNode* root) {m_root=root;}; diff --git a/intern/boolop/intern/BOP_CarveInterface.cpp b/intern/boolop/intern/BOP_CarveInterface.cpp index ff7244ea84b..4b3bda113fd 100644 --- a/intern/boolop/intern/BOP_CarveInterface.cpp +++ b/intern/boolop/intern/BOP_CarveInterface.cpp @@ -547,13 +547,32 @@ static uint quadMerge(std::map::vertex_t*, uint> *vertexToIndex_map, return 0; } -static bool Carve_checkDegeneratedFace(MeshSet<3>::face_t *face) +static bool Carve_checkDegeneratedFace(std::map::vertex_t*, uint> *vertexToIndex_map, MeshSet<3>::face_t *face) { /* only tris and quads for now */ if (face->n_edges == 3) { + uint v1, v2, v3; + + v1 = vertexToIndex_map->find(face->edge->prev->vert)->second; + v2 = vertexToIndex_map->find(face->edge->vert)->second; + v3 = vertexToIndex_map->find(face->edge->next->vert)->second; + + if (v1 == v2 || v2 == v3 || v1 == v3) + return true; + return triangleArea(face->edge->prev->vert->v, face->edge->vert->v, face->edge->next->vert->v) < DBL_EPSILON; } else if (face->n_edges == 4) { + uint v1, v2, v3, v4; + + v1 = vertexToIndex_map->find(face->edge->prev->vert)->second; + v2 = vertexToIndex_map->find(face->edge->vert)->second; + v3 = vertexToIndex_map->find(face->edge->next->vert)->second; + v4 = vertexToIndex_map->find(face->edge->next->next->vert)->second; + + if (v1 == v2 || v1 == v3 || v1 == v4 || v2 == v3 || v2 == v4 || v3 == v4) + return true; + return triangleArea(face->edge->vert->v, face->edge->next->vert->v, face->edge->next->next->vert->v) + triangleArea(face->edge->prev->vert->v, face->edge->vert->v, face->edge->next->next->vert->v) < DBL_EPSILON; } @@ -595,8 +614,14 @@ static BSP_CSGMesh *Carve_exportMesh(MeshSet<3>* &poly, carve::interpolate::Face MeshSet<3>::face_iter face_iter = poly->faceBegin(); for (i = 0; face_iter != poly->faceEnd(); ++face_iter, ++i) { MeshSet<3>::face_t *f = *face_iter; + + if (Carve_checkDegeneratedFace(&vertexToIndex_map, f)) + continue; + ofaces[oface_num.getAttribute(f)].push_back(i); + MeshSet<3>::face_t::edge_iter_t edge_iter = f->begin(); + for (; edge_iter != f->end(); ++edge_iter) { int index = vertexToIndex_map[edge_iter->vert]; vi[index].push_back(i); @@ -659,36 +684,27 @@ static BSP_CSGMesh *Carve_exportMesh(MeshSet<3>* &poly, carve::interpolate::Face } } - bool degenerativeFace = false; + // add all information except vertices to the output mesh + outputMesh->FaceSet().push_back(BSP_MFace()); + BSP_MFace& outFace = outputMesh->FaceSet().back(); + outFace.m_verts.clear(); + outFace.m_plane.setValue(f->plane.N.v); + outFace.m_orig_face = orig; - if (!result) { - /* merged triangles are already checked for degenerative quad */ - degenerativeFace = Carve_checkDegeneratedFace(f); - } - - if (!degenerativeFace) { - // add all information except vertices to the output mesh - outputMesh->FaceSet().push_back(BSP_MFace()); - BSP_MFace& outFace = outputMesh->FaceSet().back(); - outFace.m_verts.clear(); - outFace.m_plane.setValue(f->plane.N.v); - outFace.m_orig_face = orig; - - // if we merged faces, use the list of common vertices; otherwise - // use the faces's vertices - if (result) { - // make quat using verts stored in result - outFace.m_verts.push_back(quadverts[0]); - outFace.m_verts.push_back(quadverts[1]); - outFace.m_verts.push_back(quadverts[2]); - outFace.m_verts.push_back(quadverts[3]); - } else { - MeshSet<3>::face_t::edge_iter_t edge_iter = f->begin(); - for (; edge_iter != f->end(); ++edge_iter) { - //int index = ofacevert_num.getAttribute(f, edge_iter.idx()); - int index = vertexToIndex_map[edge_iter->vert]; - outFace.m_verts.push_back( index ); - } + // if we merged faces, use the list of common vertices; otherwise + // use the faces's vertices + if (result) { + // make quat using verts stored in result + outFace.m_verts.push_back(quadverts[0]); + outFace.m_verts.push_back(quadverts[1]); + outFace.m_verts.push_back(quadverts[2]); + outFace.m_verts.push_back(quadverts[3]); + } else { + MeshSet<3>::face_t::edge_iter_t edge_iter = f->begin(); + for (; edge_iter != f->end(); ++edge_iter) { + //int index = ofacevert_num.getAttribute(f, edge_iter.idx()); + int index = vertexToIndex_map[edge_iter->vert]; + outFace.m_verts.push_back( index ); } } } diff --git a/intern/cycles/blender/blender_object.cpp b/intern/cycles/blender/blender_object.cpp index a928bd9a6ea..242f7c8ecef 100644 --- a/intern/cycles/blender/blender_object.cpp +++ b/intern/cycles/blender/blender_object.cpp @@ -306,6 +306,7 @@ void BlenderSync::sync_objects(BL::SpaceView3D b_v3d, int motion) for(b_sce.objects.begin(b_ob); b_ob != b_sce.objects.end(); ++b_ob) { bool hide = (render_layer.use_viewport_visibility)? b_ob->hide(): b_ob->hide_render(); uint ob_layer = get_layer(b_ob->layers(), b_ob->layers_local_view(), object_is_light(*b_ob)); + CYCLES_LOCAL_LAYER_HACK(render_layer.use_localview, ob_layer); hide = hide || !(ob_layer & scene_layer); if(!hide) { diff --git a/intern/cycles/blender/blender_particles.cpp b/intern/cycles/blender/blender_particles.cpp index f591aaa6d83..d669aa34a68 100644 --- a/intern/cycles/blender/blender_particles.cpp +++ b/intern/cycles/blender/blender_particles.cpp @@ -144,16 +144,20 @@ void BlenderSync::sync_particles(Object *ob, BL::Object b_ob) BL::Object::particle_systems_iterator b_psys; for(b_ob.particle_systems.begin(b_psys); b_psys != b_ob.particle_systems.end(); ++b_psys) { if (use_particle_system(*b_psys)) { + int pa_index = 0; BL::ParticleSystem::particles_iterator b_pa; for(b_psys->particles.begin(b_pa), index = 0; b_pa != b_psys->particles.end(); ++b_pa, ++index) { if(use_particle(*b_pa)) { Particle pa; + pa.index = pa_index; pa.age = b_scene.frame_current() - b_pa->birth_time(); pa.lifetime = b_pa->lifetime(); ob->particles.push_back(pa); } + + ++pa_index; } } } diff --git a/intern/cycles/blender/blender_sync.cpp b/intern/cycles/blender/blender_sync.cpp index c9d2d68da0a..ae28453a696 100644 --- a/intern/cycles/blender/blender_sync.cpp +++ b/intern/cycles/blender/blender_sync.cpp @@ -219,7 +219,9 @@ void BlenderSync::sync_render_layers(BL::SpaceView3D b_v3d, const char *layer) layer = layername.c_str(); } else { + render_layer.use_localview = (b_v3d.local_view() ? true : false); render_layer.scene_layer = get_layer(b_v3d.layers(), b_v3d.layers_local_view()); + CYCLES_LOCAL_LAYER_HACK(render_layer.use_localview, render_layer.scene_layer); render_layer.layer = render_layer.scene_layer; render_layer.holdout_layer = 0; render_layer.material_override = PointerRNA_NULL; @@ -245,6 +247,7 @@ void BlenderSync::sync_render_layers(BL::SpaceView3D b_v3d, const char *layer) render_layer.material_override = b_rlay->material_override(); render_layer.use_background = b_rlay->use_sky(); render_layer.use_viewport_visibility = false; + render_layer.use_localview = false; render_layer.samples = b_rlay->samples(); } diff --git a/intern/cycles/blender/blender_sync.h b/intern/cycles/blender/blender_sync.h index 8c31c4b86ba..1a6c04db10c 100644 --- a/intern/cycles/blender/blender_sync.h +++ b/intern/cycles/blender/blender_sync.h @@ -127,10 +127,25 @@ private: BL::Material material_override; bool use_background; bool use_viewport_visibility; + bool use_localview; int samples; } render_layer; }; +/* we don't have spare bits for localview (normally 20-28) + * because PATH_RAY_LAYER_SHIFT uses 20-32. + * So - check if we have localview and if so, shift local + * view bits down to 1-8, since this is done for the view + * port only - it should be OK and not conflict with + * render layers. - Campbell. + * + * ... as an alternative we could use uint64_t + */ +#define CYCLES_LOCAL_LAYER_HACK(use_localview, layer) \ + if (use_localview) { \ + layer >>= 20; \ + } (void)0 + CCL_NAMESPACE_END #endif /* __BLENDER_SYNC_H__ */ diff --git a/intern/cycles/bvh/bvh.cpp b/intern/cycles/bvh/bvh.cpp index bdcd3b6ba19..4d3588452eb 100644 --- a/intern/cycles/bvh/bvh.cpp +++ b/intern/cycles/bvh/bvh.cpp @@ -378,19 +378,10 @@ void BVH::pack_instances(size_t nodes_size) int mesh_tri_offset = mesh->tri_offset; /* fill in node indexes for instances */ - if( - /* XXX, brecht. check this is needed!. it could be a bug elsewhere - * /mango/pro/scenes/04_2e/04_2e.blend r2158. on Ian's system 192.168.3.27 - campbell */ - (bvh->pack.is_leaf.size() != 0) && - - /* previously only checked this */ - bvh->pack.is_leaf[0]) - { + if((bvh->pack.is_leaf.size() != 0) && bvh->pack.is_leaf[0]) pack.object_node[object_offset++] = -noffset-1; - } - else { + else pack.object_node[object_offset++] = noffset; - } mesh_map[mesh] = pack.object_node[object_offset-1]; diff --git a/intern/cycles/device/device_opencl.cpp b/intern/cycles/device/device_opencl.cpp index 13ebeff70d2..c9ec7c75063 100644 --- a/intern/cycles/device/device_opencl.cpp +++ b/intern/cycles/device/device_opencl.cpp @@ -298,15 +298,12 @@ public: { string build_options = " -cl-fast-relaxed-math "; - /* Multi Closure for nVidia cards */ if(platform_name == "NVIDIA CUDA") build_options += "-D__KERNEL_SHADING__ -D__KERNEL_OPENCL_NVIDIA__ -cl-nv-maxrregcount=24 -cl-nv-verbose "; - - /* No Float3 for Apple */ + else if(platform_name == "Apple") build_options += "-D__CL_NO_FLOAT3__ -D__KERNEL_OPENCL_APPLE__ "; - - /* Basic shading for AMD cards (non Apple) */ + else if(platform_name == "AMD Accelerated Parallel Processing") build_options += "-D__CL_NO_FLOAT3__ -D__KERNEL_OPENCL_AMD__ "; diff --git a/intern/cycles/kernel/kernel_montecarlo.h b/intern/cycles/kernel/kernel_montecarlo.h index 939f3915b6c..afc53b1117a 100644 --- a/intern/cycles/kernel/kernel_montecarlo.h +++ b/intern/cycles/kernel/kernel_montecarlo.h @@ -87,8 +87,8 @@ __device_inline void sample_cos_hemisphere(const float3 N, } __device_inline void sample_uniform_hemisphere(const float3 N, - float randu, float randv, - float3 *omega_in, float *pdf) + float randu, float randv, + float3 *omega_in, float *pdf) { float z = randu; float r = sqrtf(max(0.0f, 1.0f - z*z)); diff --git a/intern/cycles/kernel/kernel_object.h b/intern/cycles/kernel/kernel_object.h index 18e0b1e8a87..4ff315ca265 100644 --- a/intern/cycles/kernel/kernel_object.h +++ b/intern/cycles/kernel/kernel_object.h @@ -169,20 +169,27 @@ __device int shader_pass_id(KernelGlobals *kg, ShaderData *sd) return kernel_tex_fetch(__shader_flag, (sd->shader & SHADER_MASK)*2 + 1); } -__device float particle_age(KernelGlobals *kg, int particle) +__device_inline float particle_index(KernelGlobals *kg, int particle) { int offset = particle*PARTICLE_SIZE; float4 f = kernel_tex_fetch(__particles, offset); return f.x; } -__device float particle_lifetime(KernelGlobals *kg, int particle) +__device float particle_age(KernelGlobals *kg, int particle) { int offset = particle*PARTICLE_SIZE; float4 f = kernel_tex_fetch(__particles, offset); return f.y; } +__device float particle_lifetime(KernelGlobals *kg, int particle) +{ + int offset = particle*PARTICLE_SIZE; + float4 f = kernel_tex_fetch(__particles, offset); + return f.z; +} + CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/kernel_path.h b/intern/cycles/kernel/kernel_path.h index 98ab9169c21..f5188345948 100644 --- a/intern/cycles/kernel/kernel_path.h +++ b/intern/cycles/kernel/kernel_path.h @@ -288,7 +288,7 @@ __device float4 kernel_path_progressive(KernelGlobals *kg, RNG *rng, int sample, if(sd.flag & SD_HOLDOUT_MASK) holdout_weight = make_float3(1.0f, 1.0f, 1.0f); else - shader_holdout_eval(kg, &sd); + holdout_weight = shader_holdout_eval(kg, &sd); /* any throughput is ok, should all be identical here */ L_transparent += average(holdout_weight*throughput); @@ -655,7 +655,7 @@ __device float4 kernel_path_non_progressive(KernelGlobals *kg, RNG *rng, int sam if(sd.flag & SD_HOLDOUT_MASK) holdout_weight = make_float3(1.0f, 1.0f, 1.0f); else - shader_holdout_eval(kg, &sd); + holdout_weight = shader_holdout_eval(kg, &sd); /* any throughput is ok, should all be identical here */ L_transparent += average(holdout_weight*throughput); diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h index d204b114b8e..30d45ad1118 100644 --- a/intern/cycles/kernel/kernel_types.h +++ b/intern/cycles/kernel/kernel_types.h @@ -172,6 +172,8 @@ enum PathRayFlag { PATH_RAY_ALL = (1|2|4|8|16|32|64|128|256|512), + /* this gives collisions with localview bits + * see: CYCLES_LOCAL_LAYER_HACK(), grr - Campbell */ PATH_RAY_LAYER_SHIFT = (32-20) }; diff --git a/intern/cycles/kernel/svm/svm_geometry.h b/intern/cycles/kernel/svm/svm_geometry.h index 88127b56474..3cfce1d087a 100644 --- a/intern/cycles/kernel/svm/svm_geometry.h +++ b/intern/cycles/kernel/svm/svm_geometry.h @@ -101,6 +101,12 @@ __device void svm_node_particle_info(KernelGlobals *kg, ShaderData *sd, float *s float data; switch(type) { + case NODE_INFO_PAR_INDEX: { + uint particle_id = object_particle_id(kg, sd->object); + data = particle_index(kg, particle_id); + stack_store_float(stack, out_offset, data); + break; + } case NODE_INFO_PAR_AGE: { uint particle_id = object_particle_id(kg, sd->object); data = particle_age(kg, particle_id); diff --git a/intern/cycles/kernel/svm/svm_types.h b/intern/cycles/kernel/svm/svm_types.h index c1eeeb55268..cbff0c099ea 100644 --- a/intern/cycles/kernel/svm/svm_types.h +++ b/intern/cycles/kernel/svm/svm_types.h @@ -114,6 +114,7 @@ typedef enum NodeObjectInfo { } NodeObjectInfo; typedef enum NodeParticleInfo { + NODE_INFO_PAR_INDEX, NODE_INFO_PAR_AGE, NODE_INFO_PAR_LIFETIME } NodeParticleInfo; diff --git a/intern/cycles/render/light.cpp b/intern/cycles/render/light.cpp index 6c03d0859a7..d00b242d153 100644 --- a/intern/cycles/render/light.cpp +++ b/intern/cycles/render/light.cpp @@ -194,10 +194,11 @@ void LightManager::device_update_distribution(Device *device, DeviceScene *dscen /* sum area */ if(have_emission) { + bool transform_applied = mesh->transform_applied; Transform tfm = object->tfm; int object_id = j; - if(mesh->transform_applied) + if(transform_applied) object_id = ~object_id; for(size_t i = 0; i < mesh->triangles.size(); i++) { @@ -211,9 +212,15 @@ void LightManager::device_update_distribution(Device *device, DeviceScene *dscen offset++; Mesh::Triangle t = mesh->triangles[i]; - float3 p1 = transform_point(&tfm, mesh->verts[t.v[0]]); - float3 p2 = transform_point(&tfm, mesh->verts[t.v[1]]); - float3 p3 = transform_point(&tfm, mesh->verts[t.v[2]]); + float3 p1 = mesh->verts[t.v[0]]; + float3 p2 = mesh->verts[t.v[1]]; + float3 p3 = mesh->verts[t.v[2]]; + + if(!transform_applied) { + p1 = transform_point(&tfm, p1); + p2 = transform_point(&tfm, p2); + p3 = transform_point(&tfm, p3); + } totarea += triangle_area(p1, p2, p3); } diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp index e4a4b874964..250570e1d65 100644 --- a/intern/cycles/render/nodes.cpp +++ b/intern/cycles/render/nodes.cpp @@ -1798,12 +1798,15 @@ void ObjectInfoNode::compile(OSLCompiler& compiler) ParticleInfoNode::ParticleInfoNode() : ShaderNode("particle_info") { + add_output("Index", SHADER_SOCKET_FLOAT); add_output("Age", SHADER_SOCKET_FLOAT); add_output("Lifetime", SHADER_SOCKET_FLOAT); } void ParticleInfoNode::attributes(AttributeRequestSet *attributes) { + if(!output("Index")->links.empty()) + attributes->add(ATTR_STD_PARTICLE); if(!output("Age")->links.empty()) attributes->add(ATTR_STD_PARTICLE); if(!output("Lifetime")->links.empty()) @@ -1816,6 +1819,12 @@ void ParticleInfoNode::compile(SVMCompiler& compiler) { ShaderOutput *out; + out = output("Index"); + if(!out->links.empty()) { + compiler.stack_assign(out); + compiler.add_node(NODE_PARTICLE_INFO, NODE_INFO_PAR_INDEX, out->stack_offset); + } + out = output("Age"); if(!out->links.empty()) { compiler.stack_assign(out); diff --git a/intern/cycles/render/object.cpp b/intern/cycles/render/object.cpp index 6de7eaea343..0fe227fd171 100644 --- a/intern/cycles/render/object.cpp +++ b/intern/cycles/render/object.cpp @@ -111,8 +111,9 @@ void Object::apply_transform() mesh->compute_bounds(); compute_bounds(false); } - - tfm = transform_identity(); + + /* tfm is not reset to identity, all code that uses it needs to check the + transform_applied boolean */ } void Object::tag_update(Scene *scene) @@ -269,7 +270,7 @@ void ObjectManager::device_update_particles(Device *device, DeviceScene *dscene, /* pack in texture */ int offset = i*PARTICLE_SIZE; - particles[offset] = make_float4(pa.age, pa.lifetime, 0.0f, 0.0f); + particles[offset] = make_float4(pa.index, pa.age, pa.lifetime, 0.0f); i++; diff --git a/intern/cycles/render/object.h b/intern/cycles/render/object.h index 6d674731b07..9b2f5bc8768 100644 --- a/intern/cycles/render/object.h +++ b/intern/cycles/render/object.h @@ -36,6 +36,7 @@ struct Transform; /* Object */ struct Particle { + int index; float age; float lifetime; }; diff --git a/intern/cycles/subd/subd_build.cpp b/intern/cycles/subd/subd_build.cpp index c8181838ec3..312980f1fa2 100644 --- a/intern/cycles/subd/subd_build.cpp +++ b/intern/cycles/subd/subd_build.cpp @@ -117,7 +117,7 @@ Patch *SubdAccBuilder::run(SubdFace *face) memcpy(patch->hull, position, sizeof(float3)*20); return patch; } - else if(face->num_edges() == 4) { + else if(face->num_edges() == 4) { GregoryQuadPatch *patch = new GregoryQuadPatch(); memcpy(patch->hull, position, sizeof(float3)*20); return patch; @@ -644,7 +644,7 @@ Patch *SubdLinearBuilder::run(SubdFace *face) hull = lpatch->hull; patch = lpatch; } - else if(face->num_edges() == 4) { + else if(face->num_edges() == 4) { LinearQuadPatch *lpatch = new LinearQuadPatch(); hull = lpatch->hull; patch = lpatch; diff --git a/intern/cycles/util/util_cache.cpp b/intern/cycles/util/util_cache.cpp index 2924ed30b88..55ed50b2ca6 100644 --- a/intern/cycles/util/util_cache.cpp +++ b/intern/cycles/util/util_cache.cpp @@ -26,6 +26,12 @@ #include "util_path.h" #include "util_types.h" +#include + +#if (BOOST_VERSION < 104400) +# define BOOST_FILESYSTEM_VERSION 2 +#endif + #include #include @@ -115,7 +121,11 @@ void Cache::clear_except(const string& name, const set& except) boost::filesystem::directory_iterator it(dir), it_end; for(; it != it_end; it++) { +#if (BOOST_FILESYSTEM_VERSION == 2) + string filename = it->path().filename(); +#else string filename = it->path().filename().string(); +#endif if(boost::starts_with(filename, name)) if(except.find(filename) == except.end()) diff --git a/intern/cycles/util/util_path.cpp b/intern/cycles/util/util_path.cpp index 53dbfe9a42c..a571fe81118 100644 --- a/intern/cycles/util/util_path.cpp +++ b/intern/cycles/util/util_path.cpp @@ -26,6 +26,12 @@ OIIO_NAMESPACE_USING #include +#include + +#if (BOOST_VERSION < 104400) +# define BOOST_FILESYSTEM_VERSION 2 +#endif + #include #include @@ -58,7 +64,11 @@ string path_user_get(const string& sub) string path_filename(const string& path) { +#if (BOOST_FILESYSTEM_VERSION == 2) + return boost::filesystem::path(path).filename(); +#else return boost::filesystem::path(path).filename().string(); +#endif } string path_dirname(const string& path) diff --git a/intern/decimation/intern/LOD_QuadricEditor.cpp b/intern/decimation/intern/LOD_QuadricEditor.cpp index b56f6a5b520..fbaf0c1180f 100644 --- a/intern/decimation/intern/LOD_QuadricEditor.cpp +++ b/intern/decimation/intern/LOD_QuadricEditor.cpp @@ -174,7 +174,7 @@ BuildQuadrics( vector::iterator edge_it = edges.begin(); vector::const_iterator edge_end = edges.end(); - for (; edge_it != edge_end; ++edge_it) { + for (; edge_it != edge_end; ++edge_it) { MT_Vector3 target = TargetVertex(*edge_it); @@ -235,7 +235,7 @@ ComputeEdgeCosts( vector::const_iterator edge_it = edges.begin(); vector::const_iterator edge_end = edges.end(); - for (; edge_it != edge_end; ++edge_it) { + for (; edge_it != edge_end; ++edge_it) { MT_Vector3 target = TargetVertex(edge_set[*edge_it]); diff --git a/intern/elbeem/intern/mvmcoords.cpp b/intern/elbeem/intern/mvmcoords.cpp index 426b8c6606d..281a9656fcf 100644 --- a/intern/elbeem/intern/mvmcoords.cpp +++ b/intern/elbeem/intern/mvmcoords.cpp @@ -16,6 +16,13 @@ #include "mvmcoords.h" #include + +#if defined(_MSC_VER) && _MSC_VER > 1600 +// sdt::greater +#include +#endif + + using std::vector; void MeanValueMeshCoords::clear() diff --git a/intern/ghost/GHOST_IWindow.h b/intern/ghost/GHOST_IWindow.h index 5005718e4a5..b606294e97d 100644 --- a/intern/ghost/GHOST_IWindow.h +++ b/intern/ghost/GHOST_IWindow.h @@ -278,7 +278,7 @@ public: GHOST_TUns8 mask[16][2], int hotX, int hotY) = 0; - + virtual GHOST_TSuccess setCustomCursorShape(GHOST_TUns8 *bitmap, GHOST_TUns8 *mask, int sizex, int sizey, diff --git a/intern/ghost/intern/GHOST_DisplayManagerX11.cpp b/intern/ghost/intern/GHOST_DisplayManagerX11.cpp index d719a4caa55..0bd90854a31 100644 --- a/intern/ghost/intern/GHOST_DisplayManagerX11.cpp +++ b/intern/ghost/intern/GHOST_DisplayManagerX11.cpp @@ -48,7 +48,7 @@ GHOST_DisplayManagerX11( GHOST_DisplayManager(), m_system(system) { - //nothing to do. + /* nothing to do. */ } GHOST_TSuccess @@ -87,7 +87,7 @@ getNumDisplaySettings( XF86VidModeGetAllModeLines(dpy, DefaultScreen(dpy), &numSettings, &vidmodes); #else - // We only have one X11 setting at the moment. + /* We only have one X11 setting at the moment. */ GHOST_ASSERT(display < 1, "Only single display systems are currently supported.\n"); numSettings = GHOST_TInt32(1); #endif @@ -144,8 +144,8 @@ getDisplaySetting( setting.bpp = DefaultDepth(x_display, DefaultScreen(x_display)); #endif - // Don't think it's possible to get this value from X! - // So let's guess!! + /* Don't think it's possible to get this value from X! + * So let's guess!! */ setting.frequency = 60; return GHOST_kSuccess; @@ -171,11 +171,10 @@ setCurrentDisplaySetting( const GHOST_DisplaySetting& setting) { #ifdef WITH_X11_XF86VMODE - // - // Mode switching code ported from Quake 2: - // ftp://ftp.idsoftware.com/idstuff/source/q2source-3.21.zip - // See linux/gl_glx.c:GLimp_SetMode - // + /* Mode switching code ported from Quake 2: + * ftp: ftp.idsoftware.com/idstuff/source/q2source-3.21.zip + * See linux/gl_glx.c:GLimp_SetMode + */ int majorVersion, minorVersion; XF86VidModeModeInfo **vidmodes; Display *dpy = m_system->getXDisplay(); @@ -187,7 +186,7 @@ setCurrentDisplaySetting( scrnum = DefaultScreen(dpy); - // Get video mode list + /* Get video mode list */ majorVersion = minorVersion = 0; if (!XF86VidModeQueryVersion(dpy, &majorVersion, &minorVersion)) { fprintf(stderr, "Error: XF86VidMode extension missing!\n"); @@ -228,20 +227,21 @@ setCurrentDisplaySetting( actualWidth, actualHeight); # endif - // change to the mode + /* change to the mode */ XF86VidModeSwitchToMode(dpy, scrnum, vidmodes[best_fit]); - // Move the viewport to top left + /* Move the viewport to top left */ XF86VidModeSetViewPort(dpy, scrnum, 0, 0); } - else + else { return GHOST_kFailure; + } XFlush(dpy); return GHOST_kSuccess; #else - // Just pretend the request was successful. + /* Just pretend the request was successful. */ return GHOST_kSuccess; #endif } diff --git a/intern/ghost/intern/GHOST_DropTargetX11.cpp b/intern/ghost/intern/GHOST_DropTargetX11.cpp index c1cc55b332a..e2e15277a99 100644 --- a/intern/ghost/intern/GHOST_DropTargetX11.cpp +++ b/intern/ghost/intern/GHOST_DropTargetX11.cpp @@ -144,23 +144,23 @@ void GHOST_DropTargetX11::UrlDecode(char *decodedOut, int bufferSize, const char break; } - // We are now converting + /* We are now converting */ state = STATE_CONVERTING; break; case STATE_CONVERTING: bothDigits = true; - // Create a buffer to hold the hex. For example, if %20, this - // buffer would hold 20 (in ASCII) + /* Create a buffer to hold the hex. For example, if %20, this + * buffer would hold 20 (in ASCII) */ memset(tempNumBuf, 0, sizeof(tempNumBuf)); - // Conversion complete (i.e. don't convert again next iter) + /* Conversion complete (i.e. don't convert again next iter) */ state = STATE_SEARCH; strncpy(tempNumBuf, &encodedIn[i], 2); - // Ensure both characters are hexadecimal + /* Ensure both characters are hexadecimal */ for (j = 0; j < 2; ++j) { if (!isxdigit(tempNumBuf[j])) @@ -170,16 +170,16 @@ void GHOST_DropTargetX11::UrlDecode(char *decodedOut, int bufferSize, const char if (!bothDigits) break; - // Convert two hexadecimal characters into one character + /* Convert two hexadecimal characters into one character */ sscanf(tempNumBuf, "%x", &asciiCharacter); - // Ensure we aren't going to overflow + /* Ensure we aren't going to overflow */ assert(strlen(decodedOut) < bufferSize); - // Concatenate this character onto the output + /* Concatenate this character onto the output */ strncat(decodedOut, (char *)&asciiCharacter, 1); - // Skip the next character + /* Skip the next character */ i++; break; } diff --git a/intern/ghost/intern/GHOST_NDOFManagerX11.cpp b/intern/ghost/intern/GHOST_NDOFManagerX11.cpp index bd285bc7a27..49e7def8730 100644 --- a/intern/ghost/intern/GHOST_NDOFManagerX11.cpp +++ b/intern/ghost/intern/GHOST_NDOFManagerX11.cpp @@ -58,8 +58,11 @@ GHOST_NDOFManagerX11::GHOST_NDOFManagerX11(GHOST_System& sys) } } else { +#ifdef DEBUG + /* annoying for official builds, just adds noise and most prople don't own these */ puts("ndof: spacenavd not found"); /* This isn't a hard error, just means the user doesn't have a 3D mouse. */ +#endif } } diff --git a/intern/ghost/intern/GHOST_SystemPathsX11.cpp b/intern/ghost/intern/GHOST_SystemPathsX11.cpp index 83f7e87977c..35bebd588c3 100644 --- a/intern/ghost/intern/GHOST_SystemPathsX11.cpp +++ b/intern/ghost/intern/GHOST_SystemPathsX11.cpp @@ -38,11 +38,11 @@ #include #include -#include // for fprintf only -#include // for exit +#include /* for fprintf only */ +#include /* for exit */ -#include // for get home without use getenv() -#include // for PATH_MAX +#include /* for get home without use getenv() */ +#include /* for PATH_MAX */ #ifdef PREFIX static const char *static_path = PREFIX "/share"; diff --git a/intern/ghost/intern/GHOST_SystemX11.cpp b/intern/ghost/intern/GHOST_SystemX11.cpp index 03a952fafb3..e8f172f8b1c 100644 --- a/intern/ghost/intern/GHOST_SystemX11.cpp +++ b/intern/ghost/intern/GHOST_SystemX11.cpp @@ -32,7 +32,6 @@ * \ingroup GHOST */ - #include "GHOST_SystemX11.h" #include "GHOST_WindowX11.h" #include "GHOST_WindowManager.h" @@ -44,11 +43,11 @@ #include "GHOST_DisplayManagerX11.h" #include "GHOST_EventDragnDrop.h" #ifdef WITH_INPUT_NDOF -#include "GHOST_NDOFManagerX11.h" +# include "GHOST_NDOFManagerX11.h" #endif #ifdef WITH_XDND -#include "GHOST_DropTargetX11.h" +# include "GHOST_DropTargetX11.h" #endif #include "GHOST_Debug.h" @@ -61,20 +60,19 @@ #include #endif -// For timing - +/* For timing */ #include #include #include #include -#include // for fprintf only -#include // for exit +#include /* for fprintf only */ +#include /* for exit */ static GHOST_TKey convertXKey(KeySym key); -//these are for copy and select copy +/* these are for copy and select copy */ static char *txt_cut_buffer = NULL; static char *txt_select_buffer = NULL; @@ -90,7 +88,7 @@ GHOST_SystemX11( if (!m_display) { std::cerr << "Unable to open a display" << std::endl; - abort(); //was return before, but this would just mean it will crash later + abort(); /* was return before, but this would just mean it will crash later */ } #if defined(WITH_X11_XINPUT) && defined(X_HAVE_UTF8_STRING) @@ -128,13 +126,13 @@ GHOST_SystemX11( m_last_warp = 0; - // compute the initial time + /* compute the initial time */ timeval tv; if (gettimeofday(&tv, NULL) == -1) { GHOST_ASSERT(false, "Could not instantiate timer!"); } - // Taking care not to overflow the tv.tv_sec*1000 + /* Taking care not to overflow the tv.tv_sec*1000 */ m_start_time = GHOST_TUns64(tv.tv_sec) * 1000 + tv.tv_usec / 1000; @@ -190,7 +188,7 @@ getMilliSeconds() const GHOST_ASSERT(false, "Could not compute time!"); } - // Taking care not to overflow the tv.tv_sec*1000 + /* Taking care not to overflow the tv.tv_sec*1000 */ return GHOST_TUns64(tv.tv_sec) * 1000 + tv.tv_usec / 1000 - m_start_time; } @@ -254,16 +252,16 @@ createWindow( - window = new GHOST_WindowX11( - this, m_display, title, left, top, width, height, state, parentWindow, type, stereoVisual - ); + window = new GHOST_WindowX11(this, m_display, title, + left, top, width, height, + state, parentWindow, type, stereoVisual); if (window) { - // Both are now handle in GHOST_WindowX11.cpp - // Focus and Delete atoms. + /* Both are now handle in GHOST_WindowX11.cpp + * Focus and Delete atoms. */ if (window->getValid()) { - // Store the pointer to the window + /* Store the pointer to the window */ m_windowManager->addWindow(window); m_windowManager->setActiveWindow(window); pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowSize, window) ); @@ -313,10 +311,10 @@ findGhostWindow( if (xwind == 0) return NULL; - // It is not entirely safe to do this as the backptr may point - // to a window that has recently been removed. - // We should always check the window manager's list of windows - // and only process events on these windows. + /* It is not entirely safe to do this as the backptr may point + * to a window that has recently been removed. + * We should always check the window manager's list of windows + * and only process events on these windows. */ vector & win_vec = m_windowManager->getWindows(); @@ -411,8 +409,8 @@ GHOST_SystemX11:: processEvents( bool waitForEvent) { - // Get all the current events -- translate them into - // ghost events and call base class pushEvent() method. + /* Get all the current events -- translate them into + * ghost events and call base class pushEvent() method. */ bool anyProcessed = false; @@ -519,8 +517,8 @@ GHOST_SystemX11::processEvent(XEvent *xe) XExposeEvent & xee = xe->xexpose; if (xee.count == 0) { - // Only generate a single expose event - // per read of the event queue. + /* Only generate a single expose event + * per read of the event queue. */ g_event = new GHOST_Event( @@ -761,7 +759,7 @@ GHOST_SystemX11::processEvent(XEvent *xe) break; } - // change of size, border, layer etc. + /* change of size, border, layer etc. */ case ConfigureNotify: { /* XConfigureEvent & xce = xe->xconfigure; */ @@ -780,12 +778,11 @@ GHOST_SystemX11::processEvent(XEvent *xe) { XFocusChangeEvent &xfe = xe->xfocus; - // TODO: make sure this is the correct place for activate/deactivate + /* TODO: make sure this is the correct place for activate/deactivate */ // printf("X: focus %s for window %d\n", xfe.type == FocusIn ? "in" : "out", (int) xfe.window); - // May have to look at the type of event and filter some - // out. - + /* May have to look at the type of event and filter some out. */ + GHOST_TEventType gtype = (xfe.type == FocusIn) ? GHOST_kEventWindowActivate : GHOST_kEventWindowDeactivate; @@ -860,7 +857,7 @@ GHOST_SystemX11::processEvent(XEvent *xe) case DestroyNotify: ::exit(-1); - // We're not interested in the following things.(yet...) + /* We're not interested in the following things.(yet...) */ case NoExpose: case GraphicsExpose: break; @@ -945,8 +942,12 @@ GHOST_SystemX11::processEvent(XEvent *xe) nxe.xselection.target = xse->target; nxe.xselection.time = xse->time; - /*Check to see if the requestor is asking for String*/ - if (xse->target == utf8_string || xse->target == string || xse->target == compound_text || xse->target == c_string) { + /* Check to see if the requestor is asking for String */ + if (xse->target == utf8_string || + xse->target == string || + xse->target == compound_text || + xse->target == c_string) + { if (xse->selection == XInternAtom(m_display, "PRIMARY", False)) { XChangeProperty(m_display, xse->requestor, xse->property, xse->target, 8, PropModeReplace, (unsigned char *)txt_select_buffer, strlen(txt_select_buffer)); @@ -968,11 +969,11 @@ GHOST_SystemX11::processEvent(XEvent *xe) XFlush(m_display); } else { - //Change property to None because we do not support anything but STRING + /* Change property to None because we do not support anything but STRING */ nxe.xselection.property = None; } - //Send the event to the client 0 0 == False, SelectionNotify + /* Send the event to the client 0 0 == False, SelectionNotify */ XSendEvent(m_display, xse->requestor, 0, 0, &nxe); XFlush(m_display); break; @@ -1023,14 +1024,14 @@ getModifierKeys( GHOST_ModifierKeys& keys) const { - // analyse the masks retuned from XQueryPointer. + /* analyse the masks retuned from XQueryPointer. */ memset((void *)m_keyboard_vector, 0, sizeof(m_keyboard_vector)); XQueryKeymap(m_display, (char *)m_keyboard_vector); - // now translate key symobols into keycodes and - // test with vector. + /* now translate key symobols into keycodes and + * test with vector. */ const static KeyCode shift_l = XKeysymToKeycode(m_display, XK_Shift_L); const static KeyCode shift_r = XKeysymToKeycode(m_display, XK_Shift_R); @@ -1041,16 +1042,16 @@ getModifierKeys( const static KeyCode super_l = XKeysymToKeycode(m_display, XK_Super_L); const static KeyCode super_r = XKeysymToKeycode(m_display, XK_Super_R); - // shift + /* shift */ keys.set(GHOST_kModifierKeyLeftShift, ((m_keyboard_vector[shift_l >> 3] >> (shift_l & 7)) & 1) != 0); keys.set(GHOST_kModifierKeyRightShift, ((m_keyboard_vector[shift_r >> 3] >> (shift_r & 7)) & 1) != 0); - // control + /* control */ keys.set(GHOST_kModifierKeyLeftControl, ((m_keyboard_vector[control_l >> 3] >> (control_l & 7)) & 1) != 0); keys.set(GHOST_kModifierKeyRightControl, ((m_keyboard_vector[control_r >> 3] >> (control_r & 7)) & 1) != 0); - // alt + /* alt */ keys.set(GHOST_kModifierKeyLeftAlt, ((m_keyboard_vector[alt_l >> 3] >> (alt_l & 7)) & 1) != 0); keys.set(GHOST_kModifierKeyRightAlt, ((m_keyboard_vector[alt_r >> 3] >> (alt_r & 7)) & 1) != 0); - // super (windows) - only one GHOST-kModifierKeyOS, so mapping to either + /* super (windows) - only one GHOST-kModifierKeyOS, so mapping to either */ keys.set(GHOST_kModifierKeyOS, ( ((m_keyboard_vector[super_l >> 3] >> (super_l & 7)) & 1) || ((m_keyboard_vector[super_r >> 3] >> (super_r & 7)) & 1) ) != 0); @@ -1123,9 +1124,9 @@ setCursorPosition( GHOST_TInt32 y ) { - // This is a brute force move in screen coordinates - // XWarpPointer does relative moves so first determine the - // current pointer position. + /* This is a brute force move in screen coordinates + * XWarpPointer does relative moves so first determine the + * current pointer position. */ int cx, cy; if (getCursorPosition(cx, cy) == GHOST_kFailure) { @@ -1336,15 +1337,15 @@ convertXKey(KeySym key) /* from xclip.c xcout() v0.11 */ -#define XCLIB_XCOUT_NONE 0 /* no context */ +#define XCLIB_XCOUT_NONE 0 /* no context */ #define XCLIB_XCOUT_SENTCONVSEL 1 /* sent a request */ -#define XCLIB_XCOUT_INCR 2 /* in an incr loop */ +#define XCLIB_XCOUT_INCR 2 /* in an incr loop */ #define XCLIB_XCOUT_FALLBACK 3 /* STRING failed, need fallback to UTF8 */ #define XCLIB_XCOUT_FALLBACK_UTF8 4 /* UTF8 failed, move to compouned */ #define XCLIB_XCOUT_FALLBACK_COMP 5 /* compouned failed, move to text. */ #define XCLIB_XCOUT_FALLBACK_TEXT 6 -// Retrieves the contents of a selections. +/* Retrieves the contents of a selections. */ void GHOST_SystemX11::getClipboard_xcout(XEvent evt, Atom sel, Atom target, unsigned char **txt, unsigned long *len, unsigned int *context) const @@ -1361,15 +1362,15 @@ void GHOST_SystemX11::getClipboard_xcout(XEvent evt, Window win = window->getXWindow(); switch (*context) { - // There is no context, do an XConvertSelection() + /* There is no context, do an XConvertSelection() */ case XCLIB_XCOUT_NONE: - // Initialise return length to 0 + /* Initialise return length to 0 */ if (*len > 0) { free(*txt); *len = 0; } - // Send a selection request + /* Send a selection request */ XConvertSelection(m_display, sel, target, m_xclip_out, win, CurrentTime); *context = XCLIB_XCOUT_SENTCONVSEL; return; @@ -1391,22 +1392,22 @@ void GHOST_SystemX11::getClipboard_xcout(XEvent evt, return; } - // find the size and format of the data in property + /* find the size and format of the data in property */ XGetWindowProperty(m_display, win, m_xclip_out, 0, 0, False, AnyPropertyType, &pty_type, &pty_format, &pty_items, &pty_size, &buffer); XFree(buffer); if (pty_type == m_incr) { - // start INCR mechanism by deleting property + /* start INCR mechanism by deleting property */ XDeleteProperty(m_display, win, m_xclip_out); XFlush(m_display); *context = XCLIB_XCOUT_INCR; return; } - // if it's not incr, and not format == 8, then there's - // nothing in the selection (that xclip understands, anyway) + /* if it's not incr, and not format == 8, then there's + * nothing in the selection (that xclip understands, anyway) */ if (pty_format != 8) { *context = XCLIB_XCOUT_NONE; @@ -1418,73 +1419,73 @@ void GHOST_SystemX11::getClipboard_xcout(XEvent evt, False, AnyPropertyType, &pty_type, &pty_format, &pty_items, &pty_size, &buffer); - // finished with property, delete it + /* finished with property, delete it */ XDeleteProperty(m_display, win, m_xclip_out); - // copy the buffer to the pointer for returned data + /* copy the buffer to the pointer for returned data */ ltxt = (unsigned char *) malloc(pty_items); memcpy(ltxt, buffer, pty_items); - // set the length of the returned data + /* set the length of the returned data */ *len = pty_items; *txt = ltxt; - // free the buffer + /* free the buffer */ XFree(buffer); *context = XCLIB_XCOUT_NONE; - // complete contents of selection fetched, return 1 + /* complete contents of selection fetched, return 1 */ return; case XCLIB_XCOUT_INCR: - // To use the INCR method, we basically delete the - // property with the selection in it, wait for an - // event indicating that the property has been created, - // then read it, delete it, etc. + /* To use the INCR method, we basically delete the + * property with the selection in it, wait for an + * event indicating that the property has been created, + * then read it, delete it, etc. */ - // make sure that the event is relevant + /* make sure that the event is relevant */ if (evt.type != PropertyNotify) return; - // skip unless the property has a new value + /* skip unless the property has a new value */ if (evt.xproperty.state != PropertyNewValue) return; - // check size and format of the property + /* check size and format of the property */ XGetWindowProperty(m_display, win, m_xclip_out, 0, 0, False, AnyPropertyType, &pty_type, &pty_format, &pty_items, &pty_size, (unsigned char **) &buffer); if (pty_format != 8) { - // property does not contain text, delete it - // to tell the other X client that we have read - // it and to send the next property + /* property does not contain text, delete it + * to tell the other X client that we have read + * it and to send the next property */ XFree(buffer); XDeleteProperty(m_display, win, m_xclip_out); return; } if (pty_size == 0) { - // no more data, exit from loop + /* no more data, exit from loop */ XFree(buffer); XDeleteProperty(m_display, win, m_xclip_out); *context = XCLIB_XCOUT_NONE; - // this means that an INCR transfer is now - // complete, return 1 + /* this means that an INCR transfer is now + * complete, return 1 */ return; } XFree(buffer); - // if we have come this far, the propery contains - // text, we know the size. + /* if we have come this far, the property contains + * text, we know the size. */ XGetWindowProperty(m_display, win, m_xclip_out, 0, (long) pty_size, False, AnyPropertyType, &pty_type, &pty_format, &pty_items, &pty_size, (unsigned char **) &buffer); - // allocate memory to accommodate data in *txt + /* allocate memory to accommodate data in *txt */ if (*len == 0) { *len = pty_items; ltxt = (unsigned char *) malloc(*len); @@ -1494,13 +1495,13 @@ void GHOST_SystemX11::getClipboard_xcout(XEvent evt, ltxt = (unsigned char *) realloc(ltxt, *len); } - // add data to ltxt + /* add data to ltxt */ memcpy(<xt[*len - pty_items], buffer, pty_items); *txt = ltxt; XFree(buffer); - // delete property to get the next item + /* delete property to get the next item */ XDeleteProperty(m_display, win, m_xclip_out); XFlush(m_display); return; @@ -1514,7 +1515,7 @@ GHOST_TUns8 *GHOST_SystemX11::getClipboard(bool selection) const Atom target = m_utf8_string; Window owner; - // from xclip.c doOut() v0.11 + /* from xclip.c doOut() v0.11 */ unsigned char *sel_buf; unsigned long sel_len = 0; XEvent evt; diff --git a/intern/ghost/intern/GHOST_Window.h b/intern/ghost/intern/GHOST_Window.h index 91a974bde19..10a6a57b9fe 100644 --- a/intern/ghost/intern/GHOST_Window.h +++ b/intern/ghost/intern/GHOST_Window.h @@ -335,7 +335,7 @@ protected: /** Modified state : are there unsaved changes */ bool m_isUnsavedChanges; - /** Stores wether this is a full screen window. */ + /** Stores whether this is a full screen window. */ bool m_fullScreen; /** Stereo visual created. Only necessary for 'real' stereo support, diff --git a/intern/ghost/intern/GHOST_WindowNULL.h b/intern/ghost/intern/GHOST_WindowNULL.h index dcbb7d2b346..e3d092101b0 100644 --- a/intern/ghost/intern/GHOST_WindowNULL.h +++ b/intern/ghost/intern/GHOST_WindowNULL.h @@ -81,9 +81,9 @@ protected: GHOST_TSuccess activateDrawingContext( ) { return GHOST_kFailure; } ~GHOST_WindowNULL( ) { /* nothing */ } GHOST_TSuccess setWindowCursorVisibility( bool visible ) { return GHOST_kSuccess; } - GHOST_TSuccess setState(GHOST_TWindowState state) { return GHOST_kSuccess; } + GHOST_TSuccess setState(GHOST_TWindowState state) { return GHOST_kSuccess; } GHOST_TWindowState getState() const { return GHOST_kWindowStateNormal; } - GHOST_TSuccess invalidate() { return GHOST_kSuccess; } + GHOST_TSuccess invalidate() { return GHOST_kSuccess; } GHOST_TSuccess setOrder(GHOST_TWindowOrder order) { return GHOST_kSuccess; } diff --git a/intern/ghost/intern/GHOST_WindowWin32.cpp b/intern/ghost/intern/GHOST_WindowWin32.cpp index e3fe28e2e64..3a6e646de11 100644 --- a/intern/ghost/intern/GHOST_WindowWin32.cpp +++ b/intern/ghost/intern/GHOST_WindowWin32.cpp @@ -1343,7 +1343,7 @@ static int EnumPixelFormats(HDC hdc) ::DescribePixelFormat(hdc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd); w = WeightPixelFormat(pfd); // be strict on stereo - if (!((sPreferredFormat.dwFlags ^ pfd.dwFlags) & PFD_STEREO)) { + if (!((sPreferredFormat.dwFlags ^ pfd.dwFlags) & PFD_STEREO)) { if (w > weight) { weight = w; iPixelFormat = i; diff --git a/intern/ghost/intern/GHOST_WindowX11.cpp b/intern/ghost/intern/GHOST_WindowX11.cpp index 80d5b5a4652..3dc10d17169 100644 --- a/intern/ghost/intern/GHOST_WindowX11.cpp +++ b/intern/ghost/intern/GHOST_WindowX11.cpp @@ -39,7 +39,7 @@ #include "GHOST_DropTargetX11.h" #endif -// For standard X11 cursors +/* For standard X11 cursors */ #include #include @@ -53,8 +53,8 @@ #include #include -// For obscure full screen mode stuuf -// lifted verbatim from blut. +/* For obscure full screen mode stuuf + * lifted verbatim from blut. */ typedef struct { long flags; @@ -95,7 +95,7 @@ typedef struct { f.write('\n') */ -// See the python script above to regenerate the 48x48 icon within blender +/* See the python script above to regenerate the 48x48 icon within blender */ #define BLENDER_ICON_WIDTH 48 #define BLENDER_ICON_HEIGHT 48 static unsigned char BLENDER_ICON_48x48x24[] = { @@ -178,13 +178,13 @@ GHOST_WindowX11( m_custom_cursor(None) { - // Set up the minimum atrributes that we require and see if - // X can find us a visual matching those requirements. + /* Set up the minimum atrributes that we require and see if + * X can find us a visual matching those requirements. */ int attributes[40], i, samples; Atom atoms[2]; int natom; - int glxVersionMajor, glxVersionMinor; // As in GLX major.minor + int glxVersionMajor, glxVersionMinor; /* As in GLX major.minor */ #ifdef WITH_X11_XINPUT /* initialize incase X11 fails to load */ @@ -251,11 +251,11 @@ GHOST_WindowX11( } } - // Create a bunch of attributes needed to create an X window. + /* Create a bunch of attributes needed to create an X window. */ - // First create a colormap for the window and visual. - // This seems pretty much a legacy feature as we are in rgba mode anyway. + /* First create a colormap for the window and visual. + * This seems pretty much a legacy feature as we are in rgba mode anyway. */ XSetWindowAttributes xattributes; memset(&xattributes, 0, sizeof(xattributes)); @@ -268,7 +268,7 @@ GHOST_WindowX11( xattributes.border_pixel = 0; - // Specify which events we are interested in hearing. + /* Specify which events we are interested in hearing. */ xattributes.event_mask = ExposureMask | StructureNotifyMask | @@ -277,7 +277,7 @@ GHOST_WindowX11( ButtonPressMask | ButtonReleaseMask | PointerMotionMask | FocusChangeMask | PropertyChangeMask; - // create the window! + /* create the window! */ ; if (parentWindow == 0) { @@ -287,7 +287,7 @@ GHOST_WindowX11( top, width, height, - 0, // no border. + 0, /* no border. */ m_visual->depth, InputOutput, m_visual->visual, @@ -311,12 +311,12 @@ GHOST_WindowX11( m_window = XCreateWindow(m_display, - parentWindow, // reparent against embedder + parentWindow, /* reparent against embedder */ left, top, width, height, - 0, // no border. + 0, /* no border. */ m_visual->depth, InputOutput, m_visual->visual, @@ -353,9 +353,9 @@ GHOST_WindowX11( m_post_init = False; m_post_state = GHOST_kWindowStateNormal; } - - // Create some hints for the window manager on how - // we want this window treated. + + /* Create some hints for the window manager on how + * we want this window treated. */ XSizeHints *xsizehints = XAllocSizeHints(); xsizehints->flags = PPosition | PSize | PMinSize | PMaxSize; @@ -363,8 +363,8 @@ GHOST_WindowX11( xsizehints->y = top; xsizehints->width = width; xsizehints->height = height; - xsizehints->min_width = 320; // size hints, could be made apart of the ghost api - xsizehints->min_height = 240; // limits are also arbitrary, but should not allow 1x1 window + xsizehints->min_width = 320; /* size hints, could be made apart of the ghost api */ + xsizehints->min_height = 240; /* limits are also arbitrary, but should not allow 1x1 window */ xsizehints->max_width = 65535; xsizehints->max_height = 65535; XSetWMNormalHints(m_display, m_window, xsizehints); @@ -404,7 +404,7 @@ GHOST_WindowX11( m_xic = NULL; #endif - // Set the window icon + /* Set the window icon */ XWMHints *xwmhints = XAllocWMHints(); XImage *x_image, *mask_image; Pixmap icon_pixmap, mask_pixmap; @@ -442,7 +442,7 @@ GHOST_WindowX11( XPutImage(display, icon_pixmap, gc_icon, x_image, 0, 0, 0, 0, BLENDER_ICON_WIDTH, BLENDER_ICON_HEIGHT); XPutImage(display, mask_pixmap, gc_mask, mask_image, 0, 0, 0, 0, BLENDER_ICON_WIDTH, BLENDER_ICON_HEIGHT); - // Now the pixmap is ok to assign to the window as a hint + /* Now the pixmap is ok to assign to the window as a hint */ xwmhints->icon_pixmap = icon_pixmap; xwmhints->icon_mask = mask_pixmap; XFreeGC(display, gc_icon); @@ -455,7 +455,7 @@ GHOST_WindowX11( xwmhints->flags = InputHint | IconPixmapHint | IconMaskHint | StateHint; XSetWMHints(display, m_window, xwmhints); XFree(xwmhints); - // done setting the icon + /* done setting the icon */ setTitle(title); @@ -463,7 +463,7 @@ GHOST_WindowX11( initXInputDevices(); #endif - // now set up the rendering context. + /* now set up the rendering context. */ if (installDrawingContext(type) == GHOST_kSuccess) { m_valid_setup = true; GHOST_PRINT("Created window\n"); @@ -748,8 +748,8 @@ setTitle( (const unsigned char *) title.ReadPtr(), title.Length()); -// This should convert to valid x11 string -// and getTitle would need matching change + /* This should convert to valid x11 string + * and getTitle would need matching change */ XStoreName(m_display, m_window, title); XFlush(m_display); @@ -772,8 +772,8 @@ GHOST_WindowX11:: getWindowBounds( GHOST_Rect& bounds) const { - // Getting the window bounds under X11 is not - // really supported (nor should it be desired). + /* Getting the window bounds under X11 is not + * really supported (nor should it be desired). */ getClientBounds(bounds); } @@ -848,7 +848,7 @@ screenToClient( GHOST_TInt32& outX, GHOST_TInt32& outY) const { - // This is correct! + /* This is correct! */ int ax, ay; Window temp; @@ -1274,18 +1274,18 @@ GHOST_TSuccess GHOST_WindowX11:: invalidate() { - // So the idea of this function is to generate an expose event - // for the window. - // Unfortunately X does not handle expose events for you and - // it is the client's job to refresh the dirty part of the window. - // We need to queue up invalidate calls and generate GHOST events - // for them in the system. - - // We implement this by setting a boolean in this class to concatenate - // all such calls into a single event for this window. - - // At the same time we queue the dirty windows in the system class - // and generate events for them at the next processEvents call. + /* So the idea of this function is to generate an expose event + * for the window. + * Unfortunately X does not handle expose events for you and + * it is the client's job to refresh the dirty part of the window. + * We need to queue up invalidate calls and generate GHOST events + * for them in the system. + * + * We implement this by setting a boolean in this class to concatenate + * all such calls into a single event for this window. + * + * At the same time we queue the dirty windows in the system class + * and generate events for them at the next processEvents call. */ if (m_invalid_window == false) { m_system->addDirtyWindow(this); @@ -1384,7 +1384,7 @@ GHOST_WindowX11:: installDrawingContext( GHOST_TDrawingContextType type) { - // only support openGL for now. + /* only support openGL for now. */ GHOST_TSuccess success; switch (type) { case GHOST_kDrawingContextTypeOpenGL: diff --git a/intern/guardedalloc/MEM_guardedalloc.h b/intern/guardedalloc/MEM_guardedalloc.h index 65ce7baba1e..ae8115a337e 100644 --- a/intern/guardedalloc/MEM_guardedalloc.h +++ b/intern/guardedalloc/MEM_guardedalloc.h @@ -63,6 +63,9 @@ #include /* needed for FILE* */ #include "MEM_sys_types.h" /* needed for uintptr_t */ +/* some GNU attributes are only available from GCC 4.3 */ +#define MEM_GNU_ATTRIBUTES (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 403)) + #ifdef __cplusplus extern "C" { #endif @@ -71,7 +74,7 @@ extern "C" { * by vmemh. If the pointer was not previously allocated by this * module, the result is undefined.*/ size_t MEM_allocN_len(const void *vmemh) -#ifdef __GNUC__ +#if MEM_GNU_ATTRIBUTES __attribute__((warn_unused_result)) #endif ; @@ -90,7 +93,7 @@ extern "C" { * Duplicates a block of memory, and returns a pointer to the * newly allocated block. */ void *MEM_dupallocN(void *vmemh) -#ifdef __GNUC__ +#if MEM_GNU_ATTRIBUTES __attribute__((warn_unused_result)) #endif ; @@ -101,7 +104,7 @@ extern "C" { * as a system realloc but just makes a new allocation and copies * over from existing memory. */ void *MEM_reallocN(void *vmemh, size_t len) -#ifdef __GNUC__ +#if MEM_GNU_ATTRIBUTES __attribute__((warn_unused_result)) __attribute__((alloc_size(2))) #endif @@ -112,7 +115,7 @@ extern "C" { * memory is cleared. The name must be static, because only a * pointer to it is stored ! */ void *MEM_callocN(size_t len, const char *str) -#ifdef __GNUC__ +#if MEM_GNU_ATTRIBUTES __attribute__((warn_unused_result)) __attribute__((nonnull(2))) __attribute__((alloc_size(1))) @@ -124,7 +127,7 @@ extern "C" { * name must be a static, because only a pointer to it is stored ! * */ void *MEM_mallocN(size_t len, const char *str) -#ifdef __GNUC__ +#if MEM_GNU_ATTRIBUTES __attribute__((warn_unused_result)) __attribute__((nonnull(2))) __attribute__((alloc_size(1))) @@ -136,7 +139,7 @@ extern "C" { * Can be free'd with MEM_freeN as usual. * */ void *MEM_mapallocN(size_t len, const char *str) -#ifdef __GNUC__ +#if MEM_GNU_ATTRIBUTES __attribute__((warn_unused_result)) __attribute__((nonnull(2))) __attribute__((alloc_size(1))) @@ -188,7 +191,7 @@ extern "C" { /** Get the peak memory usage in bytes, including mmap allocations. */ uintptr_t MEM_get_peak_memory(void) -#ifdef __GNUC__ +#if MEM_GNU_ATTRIBUTES __attribute__((warn_unused_result)) #endif ; diff --git a/intern/guardedalloc/intern/mallocn.c b/intern/guardedalloc/intern/mallocn.c index 76df58f4a50..c4902e6aa5a 100644 --- a/intern/guardedalloc/intern/mallocn.c +++ b/intern/guardedalloc/intern/mallocn.c @@ -54,6 +54,14 @@ #include "MEM_guardedalloc.h" +/* Only for debugging: + * store original buffer's name when doing MEM_dupallocN + * helpful to profile issues with non-freed "dup_alloc" buffers, + * but this introduces some overhead to memory header and makes + * things slower a bit, so betterto keep disabled by default + */ +//#define DEBUG_MEMDUPLINAME + /* Only for debugging: * lets you count the allocations so as to find the allocator of unfreed memory * in situations where the leak is predictable */ @@ -96,6 +104,10 @@ typedef struct MemHead { #ifdef DEBUG_MEMCOUNTER int _count; #endif + +#ifdef DEBUG_MEMDUPLINAME + int need_free_name, pad; +#endif } MemHead; typedef struct MemTail { @@ -243,13 +255,36 @@ void *MEM_dupallocN(void *vmemh) if (vmemh) { MemHead *memh = vmemh; memh--; - + +#ifndef DEBUG_MEMDUPLINAME if (memh->mmap) newp = MEM_mapallocN(memh->len, "dupli_mapalloc"); else newp = MEM_mallocN(memh->len, "dupli_alloc"); if (newp == NULL) return NULL; +#else + { + MemHead *nmemh; + char *name = malloc(strlen(memh->name) + 24); + + if (memh->mmap) { + sprintf(name, "%s %s", "dupli_mapalloc", memh->name); + newp = MEM_mapallocN(memh->len, name); + } + else { + sprintf(name, "%s %s", "dupli_alloc", memh->name); + newp = MEM_mallocN(memh->len, name); + } + + if (newp == NULL) return NULL; + + nmemh = newp; + nmemh--; + + nmemh->need_free_name = 1; + } +#endif memcpy(newp, vmemh, memh->len); } @@ -289,6 +324,10 @@ static void make_memhead_header(MemHead *memh, size_t len, const char *str) memh->len = len; memh->mmap = 0; memh->tag2 = MEMTAG2; + +#ifdef DEBUG_MEMDUPLINAME + memh->need_free_name = 0; +#endif memt = (MemTail *)(((char *) memh) + sizeof(MemHead) + len); memt->tag3 = MEMTAG3; @@ -605,7 +644,7 @@ void MEM_printmemlist_pydict(void) MEM_printmemlist_internal(1); } -short MEM_freeN(void *vmemh) /* anders compileertie niet meer */ +short MEM_freeN(void *vmemh) { short error = 0; MemTail *memt; @@ -733,6 +772,11 @@ static void rem_memblock(MemHead *memh) totblock--; mem_in_use -= memh->len; +#ifdef DEBUG_MEMDUPLINAME + if (memh->need_free_name) + free((char *) memh->name); +#endif + if (memh->mmap) { mmap_in_use -= memh->len; if (munmap(memh, memh->len + sizeof(MemHead) + sizeof(MemTail))) diff --git a/intern/iksolver/extern/IK_solver.h b/intern/iksolver/extern/IK_solver.h index 7f780a0a17f..a3f599e06c8 100644 --- a/intern/iksolver/extern/IK_solver.h +++ b/intern/iksolver/extern/IK_solver.h @@ -163,6 +163,9 @@ float IK_SolverGetPoleAngle(IK_Solver *solver); int IK_Solve(IK_Solver *solver, float tolerance, int max_iterations); +#define IK_STRETCH_STIFF_EPS 0.001f +#define IK_STRETCH_STIFF_MIN 0.001f +#define IK_STRETCH_STIFF_MAX 1e10 #ifdef __cplusplus } diff --git a/intern/iksolver/intern/IK_QJacobian.cpp b/intern/iksolver/intern/IK_QJacobian.cpp index e85da6eda4a..bb7b7c5c0b8 100644 --- a/intern/iksolver/intern/IK_QJacobian.cpp +++ b/intern/iksolver/intern/IK_QJacobian.cpp @@ -35,7 +35,7 @@ #include "TNT/svd.h" IK_QJacobian::IK_QJacobian() -: m_sdls(true), m_min_damp(1.0) + : m_sdls(true), m_min_damp(1.0) { } @@ -106,16 +106,16 @@ void IK_QJacobian::ArmMatrices(int dof, int task_size) void IK_QJacobian::SetBetas(int id, int, const MT_Vector3& v) { - m_beta[id] = v.x(); - m_beta[id+1] = v.y(); - m_beta[id+2] = v.z(); + m_beta[id + 0] = v.x(); + m_beta[id + 1] = v.y(); + m_beta[id + 2] = v.z(); } void IK_QJacobian::SetDerivatives(int id, int dof_id, const MT_Vector3& v, MT_Scalar norm_weight) { - m_jacobian[id][dof_id] = v.x()*m_weight_sqrt[dof_id]; - m_jacobian[id+1][dof_id] = v.y()*m_weight_sqrt[dof_id]; - m_jacobian[id+2][dof_id] = v.z()*m_weight_sqrt[dof_id]; + m_jacobian[id + 0][dof_id] = v.x() * m_weight_sqrt[dof_id]; + m_jacobian[id + 1][dof_id] = v.y() * m_weight_sqrt[dof_id]; + m_jacobian[id + 2][dof_id] = v.z() * m_weight_sqrt[dof_id]; m_d_norm_weight[dof_id] = norm_weight; } @@ -194,7 +194,7 @@ void IK_QJacobian::SubTask(IK_QJacobian& jacobian) // doesn't work well at all int i; for (i = 0; i < m_d_theta.size(); i++) - m_d_theta[i] = m_d_theta[i] + /*m_min_damp**/jacobian.AngleUpdate(i); + m_d_theta[i] = m_d_theta[i] + /*m_min_damp * */ jacobian.AngleUpdate(i); } void IK_QJacobian::Restrict(TVector& d_theta, TMatrix& null) @@ -230,7 +230,7 @@ void IK_QJacobian::InvertSDLS() // DLS. The SDLS damps individual singular values, instead of using a single // damping term. - MT_Scalar max_angle_change = MT_PI/4.0; + MT_Scalar max_angle_change = MT_PI / 4.0; MT_Scalar epsilon = 1e-10; int i, j; @@ -239,35 +239,35 @@ void IK_QJacobian::InvertSDLS() for (i = 0; i < m_dof; i++) { m_norm[i] = 0.0; - for (j = 0; j < m_task_size; j+=3) { + for (j = 0; j < m_task_size; j += 3) { MT_Scalar n = 0.0; - n += m_jacobian[j][i]*m_jacobian[j][i]; - n += m_jacobian[j+1][i]*m_jacobian[j+1][i]; - n += m_jacobian[j+2][i]*m_jacobian[j+2][i]; + n += m_jacobian[j][i] * m_jacobian[j][i]; + n += m_jacobian[j + 1][i] * m_jacobian[j + 1][i]; + n += m_jacobian[j + 2][i] * m_jacobian[j + 2][i]; m_norm[i] += sqrt(n); } } - for (i = 0; i max_dtheta) max_dtheta = abs_dtheta; } @@ -295,19 +295,19 @@ void IK_QJacobian::InvertSDLS() // compute damping term and damp the dTheta's MT_Scalar gamma = max_angle_change; if (N < M) - gamma *= N/M; + gamma *= N / M; - MT_Scalar damp = (gamma < max_dtheta)? gamma/max_dtheta: 1.0; + MT_Scalar damp = (gamma < max_dtheta) ? gamma / max_dtheta : 1.0; for (j = 0; j < m_d_theta.size(); j++) { // slight hack: we do 0.80*, so that if there is some oscillation, // the system can still converge (for joint limits). also, it's // better to go a little to slow than to far - MT_Scalar dofdamp = damp/m_weight[j]; + MT_Scalar dofdamp = damp / m_weight[j]; if (dofdamp > 1.0) dofdamp = 1.0; - m_d_theta[j] += 0.80*dofdamp*m_d_theta_tmp[j]; + m_d_theta[j] += 0.80 * dofdamp * m_d_theta_tmp[j]; } if (damp < m_min_damp) @@ -317,7 +317,7 @@ void IK_QJacobian::InvertSDLS() // weight + prevent from doing angle updates with angles > max_angle_change MT_Scalar max_angle = 0.0, abs_angle; - for (j = 0; j max_angle_change) { - MT_Scalar damp = (max_angle_change)/(max_angle_change + max_angle); + MT_Scalar damp = (max_angle_change) / (max_angle_change + max_angle); - for (j = 0; j epsilon && m_svd_w[i] < w_min) w_min = m_svd_w[i]; } // compute lambda damping term - MT_Scalar d = x_length/max_angle_change; + MT_Scalar d = x_length / max_angle_change; MT_Scalar lambda; - if (w_min <= d/2) - lambda = d/2; + if (w_min <= d / 2) + lambda = d / 2; else if (w_min < d) - lambda = sqrt(w_min*(d - w_min)); + lambda = sqrt(w_min * (d - w_min)); else lambda = 0.0; @@ -393,17 +393,17 @@ void IK_QJacobian::InvertDLS() for (i = 0; i < m_svd_w.size(); i++) { if (m_svd_w[i] > epsilon) { - MT_Scalar wInv = m_svd_w[i]/(m_svd_w[i]*m_svd_w[i] + lambda); + MT_Scalar wInv = m_svd_w[i] / (m_svd_w[i] * m_svd_w[i] + lambda); // compute V*Winv*Ut*Beta m_svd_u_beta[i] *= wInv; - for (j = 0; j mx) mx = dtheta_abs; } diff --git a/intern/iksolver/intern/IK_QJacobianSolver.cpp b/intern/iksolver/intern/IK_QJacobianSolver.cpp index fe5ecf8abe3..43d177d0651 100644 --- a/intern/iksolver/intern/IK_QJacobianSolver.cpp +++ b/intern/iksolver/intern/IK_QJacobianSolver.cpp @@ -45,22 +45,22 @@ IK_QJacobianSolver::IK_QJacobianSolver() MT_Scalar IK_QJacobianSolver::ComputeScale() { - std::vector::iterator seg; - float length = 0.0f; + std::vector::iterator seg; + MT_Scalar length = 0.0f; for (seg = m_segments.begin(); seg != m_segments.end(); seg++) length += (*seg)->MaxExtension(); - if(length == 0.0f) - return 1.0f; + if (length == 0.0) + return 1.0; else - return 1.0f/length; + return 1.0 / length; } -void IK_QJacobianSolver::Scale(float scale, std::list& tasks) +void IK_QJacobianSolver::Scale(MT_Scalar scale, std::list& tasks) { - std::list::iterator task; - std::vector::iterator seg; + std::list::iterator task; + std::vector::iterator seg; for (task = tasks.begin(); task != tasks.end(); task++) (*task)->Scale(scale); @@ -82,13 +82,13 @@ void IK_QJacobianSolver::AddSegmentList(IK_QSegment *seg) AddSegmentList(child); } -bool IK_QJacobianSolver::Setup(IK_QSegment *root, std::list& tasks) +bool IK_QJacobianSolver::Setup(IK_QSegment *root, std::list& tasks) { m_segments.clear(); AddSegmentList(root); // assign each segment a unique id for the jacobian - std::vector::iterator seg; + std::vector::iterator seg; int num_dof = 0; for (seg = m_segments.begin(); seg != m_segments.end(); seg++) { @@ -103,7 +103,7 @@ bool IK_QJacobianSolver::Setup(IK_QSegment *root, std::list& tasks) int primary_size = 0, primary = 0; int secondary_size = 0, secondary = 0; MT_Scalar primary_weight = 0.0, secondary_weight = 0.0; - std::list::iterator task; + std::list::iterator task; for (task = tasks.begin(); task != tasks.end(); task++) { IK_QTask *qtask = *task; @@ -128,20 +128,20 @@ bool IK_QJacobianSolver::Setup(IK_QSegment *root, std::list& tasks) m_secondary_enabled = (secondary > 0); // rescale weights of tasks to sum up to 1 - MT_Scalar primary_rescale = 1.0/primary_weight; + MT_Scalar primary_rescale = 1.0 / primary_weight; MT_Scalar secondary_rescale; if (MT_fuzzyZero(secondary_weight)) secondary_rescale = 0.0; else - secondary_rescale = 1.0/secondary_weight; + secondary_rescale = 1.0 / secondary_weight; for (task = tasks.begin(); task != tasks.end(); task++) { IK_QTask *qtask = *task; if (qtask->Primary()) - qtask->SetWeight(qtask->Weight()*primary_rescale); + qtask->SetWeight(qtask->Weight() * primary_rescale); else - qtask->SetWeight(qtask->Weight()*secondary_rescale); + qtask->SetWeight(qtask->Weight() * secondary_rescale); } // set matrix sizes @@ -154,7 +154,7 @@ bool IK_QJacobianSolver::Setup(IK_QSegment *root, std::list& tasks) for (seg = m_segments.begin(); seg != m_segments.end(); seg++) for (i = 0; i < (*seg)->NumberOfDoF(); i++) - m_jacobian.SetDoFWeight((*seg)->DoFId()+i, (*seg)->Weight(i)); + m_jacobian.SetDoFWeight((*seg)->DoFId() + i, (*seg)->Weight(i)); return true; } @@ -165,15 +165,15 @@ void IK_QJacobianSolver::SetPoleVectorConstraint(IK_QSegment *tip, MT_Vector3& g m_poletip = tip; m_goal = goal; m_polegoal = polegoal; - m_poleangle = (getangle)? 0.0f: poleangle; + m_poleangle = (getangle) ? 0.0f : poleangle; m_getpoleangle = getangle; } static MT_Scalar safe_acos(MT_Scalar f) { // acos that does not return NaN with rounding errors - if (f <= -1.0f) return MT_PI; - else if (f >= 1.0f) return 0.0; + if (f <= -1.0) return MT_PI; + else if (f >= 1.0) return 0.0; else return acos(f); } @@ -182,7 +182,7 @@ static MT_Vector3 normalize(const MT_Vector3& v) // a sane normalize function that doesn't give (1, 0, 0) in case // of a zero length vector, like MT_Vector3.normalize MT_Scalar len = v.length(); - return MT_fuzzyZero(len)? MT_Vector3(0, 0, 0): v/len; + return MT_fuzzyZero(len) ? MT_Vector3(0, 0, 0) : v / len; } static float angle(const MT_Vector3& v1, const MT_Vector3& v2) @@ -190,21 +190,21 @@ static float angle(const MT_Vector3& v1, const MT_Vector3& v2) return safe_acos(v1.dot(v2)); } -void IK_QJacobianSolver::ConstrainPoleVector(IK_QSegment *root, std::list& tasks) +void IK_QJacobianSolver::ConstrainPoleVector(IK_QSegment *root, std::list& tasks) { // this function will be called before and after solving. calling it before // solving gives predictable solutions by rotating towards the solution, // and calling it afterwards ensures the solution is exact. - if(!m_poleconstraint) + if (!m_poleconstraint) return; // disable pole vector constraint in case of multiple position tasks - std::list::iterator task; + std::list::iterator task; int positiontasks = 0; for (task = tasks.begin(); task != tasks.end(); task++) - if((*task)->PositionTask()) + if ((*task)->PositionTask()) positiontasks++; if (positiontasks >= 2) { @@ -223,12 +223,12 @@ void IK_QJacobianSolver::ConstrainPoleVector(IK_QSegment *root, std::list 0.0f) + if (rootz.dot(mat[1] * cos(m_poleangle) + mat[0] * sin(m_poleangle)) > 0.0) m_poleangle = -m_poleangle; // solve again, with the pole angle we just computed @@ -257,15 +257,15 @@ void IK_QJacobianSolver::ConstrainPoleVector(IK_QSegment *root, std::list::iterator seg; + std::vector::iterator seg; IK_QSegment *qseg, *minseg = NULL; MT_Scalar minabsdelta = 1e10, absdelta; MT_Vector3 delta, mindelta; @@ -318,11 +318,11 @@ bool IK_QJacobianSolver::UpdateAngles(MT_Scalar& norm) } bool IK_QJacobianSolver::Solve( - IK_QSegment *root, - std::list tasks, - const MT_Scalar, - const int max_iterations -) + IK_QSegment *root, + std::list tasks, + const MT_Scalar, + const int max_iterations + ) { float scale = ComputeScale(); bool solved = false; @@ -339,7 +339,7 @@ bool IK_QJacobianSolver::Solve( // update transform root->UpdateTransform(m_rootmatrix); - std::list::iterator task; + std::list::iterator task; // compute jacobian for (task = tasks.begin(); task != tasks.end(); task++) { @@ -367,7 +367,7 @@ bool IK_QJacobianSolver::Solve( } while (UpdateAngles(norm)); // unlock segments again after locking in clamping loop - std::vector::iterator seg; + std::vector::iterator seg; for (seg = m_segments.begin(); seg != m_segments.end(); seg++) (*seg)->UnLock(); @@ -383,10 +383,10 @@ bool IK_QJacobianSolver::Solve( } } - if(m_poleconstraint) + if (m_poleconstraint) root->PrependBasis(m_rootmatrix.getBasis()); - Scale(1.0f/scale, tasks); + Scale(1.0f / scale, tasks); //analyze_add_run(max_iterations, analyze_time()-dt); diff --git a/intern/iksolver/intern/IK_QJacobianSolver.h b/intern/iksolver/intern/IK_QJacobianSolver.h index cfcd2849fb2..ead2b150b40 100644 --- a/intern/iksolver/intern/IK_QJacobianSolver.h +++ b/intern/iksolver/intern/IK_QJacobianSolver.h @@ -77,7 +77,7 @@ private: void ConstrainPoleVector(IK_QSegment *root, std::list& tasks); MT_Scalar ComputeScale(); - void Scale(float scale, std::list& tasks); + void Scale(MT_Scalar scale, std::list& tasks); private: diff --git a/intern/iksolver/intern/IK_QSegment.cpp b/intern/iksolver/intern/IK_QSegment.cpp index d81ed453037..e511d8233a2 100644 --- a/intern/iksolver/intern/IK_QSegment.cpp +++ b/intern/iksolver/intern/IK_QSegment.cpp @@ -60,24 +60,25 @@ static MT_Matrix3x3 RotationMatrix(MT_Scalar angle, int axis) static MT_Scalar EulerAngleFromMatrix(const MT_Matrix3x3& R, int axis) { - MT_Scalar t = sqrt(R[0][0]*R[0][0] + R[0][1]*R[0][1]); + MT_Scalar t = sqrt(R[0][0] * R[0][0] + R[0][1] * R[0][1]); - if (t > 16.0*MT_EPSILON) { - if (axis == 0) return -atan2(R[1][2], R[2][2]); - else if(axis == 1) return atan2(-R[0][2], t); - else return -atan2(R[0][1], R[0][0]); - } else { - if (axis == 0) return -atan2(-R[2][1], R[1][1]); - else if(axis == 1) return atan2(-R[0][2], t); - else return 0.0f; - } + if (t > 16.0 * MT_EPSILON) { + if (axis == 0) return -atan2(R[1][2], R[2][2]); + else if (axis == 1) return atan2(-R[0][2], t); + else return -atan2(R[0][1], R[0][0]); + } + else { + if (axis == 0) return -atan2(-R[2][1], R[1][1]); + else if (axis == 1) return atan2(-R[0][2], t); + else return 0.0f; + } } static MT_Scalar safe_acos(MT_Scalar f) { - if (f <= -1.0f) + if (f <= -1.0) return MT_PI; - else if (f >= 1.0f) + else if (f >= 1.0) return 0.0; else return acos(f); @@ -89,7 +90,7 @@ static MT_Scalar ComputeTwist(const MT_Matrix3x3& R) MT_Scalar qy = R[0][2] - R[2][0]; MT_Scalar qw = R[0][0] + R[1][1] + R[2][2] + 1; - MT_Scalar tau = 2*atan2(qy, qw); + MT_Scalar tau = 2.0 * atan2(qy, qw); return tau; } @@ -108,7 +109,7 @@ static void RemoveTwist(MT_Matrix3x3& R) MT_Matrix3x3 T = ComputeTwistMatrix(tau); // remove twist - R = R*T.transposed(); + R = R * T.transposed(); } static MT_Vector3 SphericalRangeParameters(const MT_Matrix3x3& R) @@ -117,7 +118,7 @@ static MT_Vector3 SphericalRangeParameters(const MT_Matrix3x3& R) MT_Scalar tau = ComputeTwist(R); // compute swing parameters - MT_Scalar num = 2.0*(1.0 + R[1][1]); + MT_Scalar num = 2.0 * (1.0 + R[1][1]); // singularity at pi if (MT_abs(num) < MT_EPSILON) @@ -126,9 +127,9 @@ static MT_Vector3 SphericalRangeParameters(const MT_Matrix3x3& R) // enforce limits at all then return MT_Vector3(0.0, tau, 1.0); - num = 1.0/sqrt(num); - MT_Scalar ax = -R[2][1]*num; - MT_Scalar az = R[0][1]*num; + num = 1.0 / sqrt(num); + MT_Scalar ax = -R[2][1] * num; + MT_Scalar az = R[0][1] * num; return MT_Vector3(ax, tau, az); } @@ -136,8 +137,8 @@ static MT_Vector3 SphericalRangeParameters(const MT_Matrix3x3& R) static MT_Matrix3x3 ComputeSwingMatrix(MT_Scalar ax, MT_Scalar az) { // length of (ax, 0, az) = sin(theta/2) - MT_Scalar sine2 = ax*ax + az*az; - MT_Scalar cosine2 = sqrt((sine2 >= 1.0)? 0.0: 1.0-sine2); + MT_Scalar sine2 = ax * ax + az * az; + MT_Scalar cosine2 = sqrt((sine2 >= 1.0) ? 0.0 : 1.0 - sine2); // compute swing matrix MT_Matrix3x3 S(MT_Quaternion(ax, 0.0, az, -cosine2)); @@ -151,11 +152,11 @@ static MT_Vector3 MatrixToAxisAngle(const MT_Matrix3x3& R) R[0][2] - R[2][0], R[1][0] - R[0][1]); - MT_Scalar c = safe_acos((R[0][0] + R[1][1] + R[2][2] - 1)/2); + MT_Scalar c = safe_acos((R[0][0] + R[1][1] + R[2][2] - 1) / 2); MT_Scalar l = delta.length(); if (!MT_fuzzyZero(l)) - delta *= c/l; + delta *= c / l; return delta; } @@ -192,10 +193,10 @@ static bool EllipseClamp(MT_Scalar& ax, MT_Scalar& az, MT_Scalar *amin, MT_Scala z = zlim; } else { - MT_Scalar invx = 1.0/(xlim*xlim); - MT_Scalar invz = 1.0/(zlim*zlim); + MT_Scalar invx = 1.0 / (xlim * xlim); + MT_Scalar invz = 1.0 / (zlim * zlim); - if ((x*x*invx + z*z*invz) <= 1.0) + if ((x * x * invx + z * z * invz) <= 1.0) return false; if (MT_fuzzyZero(x)) { @@ -203,17 +204,17 @@ static bool EllipseClamp(MT_Scalar& ax, MT_Scalar& az, MT_Scalar *amin, MT_Scala z = zlim; } else { - MT_Scalar rico = z/x; + MT_Scalar rico = z / x; MT_Scalar old_x = x; - x = sqrt(1.0/(invx + invz*rico*rico)); + x = sqrt(1.0 / (invx + invz * rico * rico)); if (old_x < 0.0) x = -x; - z = rico*x; + z = rico * x; } } - ax = (ax < 0.0)? -x: x; - az = (az < 0.0)? -z: z; + ax = (ax < 0.0) ? -x : x; + az = (az < 0.0) ? -z : z; return true; } @@ -221,8 +222,8 @@ static bool EllipseClamp(MT_Scalar& ax, MT_Scalar& az, MT_Scalar *amin, MT_Scala // IK_QSegment IK_QSegment::IK_QSegment(int num_DoF, bool translational) -: m_parent(NULL), m_child(NULL), m_sibling(NULL), m_composite(NULL), - m_num_DoF(num_DoF), m_translational(translational) + : m_parent(NULL), m_child(NULL), m_sibling(NULL), m_composite(NULL), + m_num_DoF(num_DoF), m_translational(translational) { m_locked[0] = m_locked[1] = m_locked[2] = false; m_weight[0] = m_weight[1] = m_weight[2] = 1.0; @@ -251,11 +252,11 @@ void IK_QSegment::Reset() } void IK_QSegment::SetTransform( - const MT_Vector3& start, - const MT_Matrix3x3& rest_basis, - const MT_Matrix3x3& basis, - const MT_Scalar length -) + const MT_Vector3& start, + const MT_Matrix3x3& rest_basis, + const MT_Matrix3x3& basis, + const MT_Scalar length + ) { m_max_extension = start.length() + length; @@ -271,7 +272,7 @@ void IK_QSegment::SetTransform( MT_Matrix3x3 IK_QSegment::BasisChange() const { - return m_orig_basis.transposed()*m_basis; + return m_orig_basis.transposed() * m_basis; } MT_Vector3 IK_QSegment::TranslationChange() const @@ -329,7 +330,7 @@ void IK_QSegment::RemoveChild(IK_QSegment *child) void IK_QSegment::UpdateTransform(const MT_Transform& global) { // compute the global transform at the end of the segment - m_global_start = global.getOrigin() + global.getBasis()*m_start; + m_global_start = global.getOrigin() + global.getBasis() * m_start; m_global_transform.setOrigin(m_global_start); m_global_transform.setBasis(global.getBasis() * m_rest_basis * m_basis); @@ -345,7 +346,7 @@ void IK_QSegment::PrependBasis(const MT_Matrix3x3& mat) m_basis = m_rest_basis.inverse() * mat * m_rest_basis * m_basis; } -void IK_QSegment::Scale(float scale) +void IK_QSegment::Scale(MT_Scalar scale) { m_start *= scale; m_translation *= scale; @@ -358,7 +359,7 @@ void IK_QSegment::Scale(float scale) // IK_QSphericalSegment IK_QSphericalSegment::IK_QSphericalSegment() -: IK_QSegment(3, false), m_limit_x(false), m_limit_y(false), m_limit_z(false) + : IK_QSegment(3, false), m_limit_x(false), m_limit_y(false), m_limit_z(false) { } @@ -386,8 +387,8 @@ void IK_QSphericalSegment::SetLimit(int axis, MT_Scalar lmin, MT_Scalar lmax) lmin = MT_clamp(lmin, -MT_PI, MT_PI); lmax = MT_clamp(lmax, -MT_PI, MT_PI); - lmin = sin(lmin*0.5); - lmax = sin(lmax*0.5); + lmin = sin(lmin * 0.5); + lmax = sin(lmax * 0.5); if (axis == 0) { m_min[0] = -lmax; @@ -414,8 +415,8 @@ bool IK_QSphericalSegment::UpdateAngle(const IK_QJacobian &jacobian, MT_Vector3& MT_Vector3 dq; dq.x() = jacobian.AngleUpdate(m_DoF_id); - dq.y() = jacobian.AngleUpdate(m_DoF_id+1); - dq.z() = jacobian.AngleUpdate(m_DoF_id+2); + dq.y() = jacobian.AngleUpdate(m_DoF_id + 1); + dq.z() = jacobian.AngleUpdate(m_DoF_id + 2); // Directly update the rotation matrix, with Rodrigues' rotation formula, // to avoid singularities and allow smooth integration. @@ -423,29 +424,29 @@ bool IK_QSphericalSegment::UpdateAngle(const IK_QJacobian &jacobian, MT_Vector3& MT_Scalar theta = dq.length(); if (!MT_fuzzyZero(theta)) { - MT_Vector3 w = dq*(1.0/theta); + MT_Vector3 w = dq * (1.0 / theta); MT_Scalar sine = sin(theta); MT_Scalar cosine = cos(theta); - MT_Scalar cosineInv = 1-cosine; + MT_Scalar cosineInv = 1 - cosine; - MT_Scalar xsine = w.x()*sine; - MT_Scalar ysine = w.y()*sine; - MT_Scalar zsine = w.z()*sine; + MT_Scalar xsine = w.x() * sine; + MT_Scalar ysine = w.y() * sine; + MT_Scalar zsine = w.z() * sine; - MT_Scalar xxcosine = w.x()*w.x()*cosineInv; - MT_Scalar xycosine = w.x()*w.y()*cosineInv; - MT_Scalar xzcosine = w.x()*w.z()*cosineInv; - MT_Scalar yycosine = w.y()*w.y()*cosineInv; - MT_Scalar yzcosine = w.y()*w.z()*cosineInv; - MT_Scalar zzcosine = w.z()*w.z()*cosineInv; + MT_Scalar xxcosine = w.x() * w.x() * cosineInv; + MT_Scalar xycosine = w.x() * w.y() * cosineInv; + MT_Scalar xzcosine = w.x() * w.z() * cosineInv; + MT_Scalar yycosine = w.y() * w.y() * cosineInv; + MT_Scalar yzcosine = w.y() * w.z() * cosineInv; + MT_Scalar zzcosine = w.z() * w.z() * cosineInv; MT_Matrix3x3 M( - cosine + xxcosine, -zsine + xycosine, ysine + xzcosine, - zsine + xycosine, cosine + yycosine, -xsine + yzcosine, - -ysine + xzcosine, xsine + yzcosine, cosine + zzcosine); + cosine + xxcosine, -zsine + xycosine, ysine + xzcosine, + zsine + xycosine, cosine + yycosine, -xsine + yzcosine, + -ysine + xzcosine, xsine + yzcosine, cosine + zzcosine); - m_new_basis = m_basis*M; + m_new_basis = m_basis * M; } else m_new_basis = m_basis; @@ -505,13 +506,13 @@ bool IK_QSphericalSegment::UpdateAngle(const IK_QJacobian &jacobian, MT_Vector3& if (clamp[0] == false && clamp[1] == false && clamp[2] == false) { if (m_locked[0] || m_locked[1] || m_locked[2]) - m_new_basis = ComputeSwingMatrix(ax, az)*ComputeTwistMatrix(ay); + m_new_basis = ComputeSwingMatrix(ax, az) * ComputeTwistMatrix(ay); return false; } - m_new_basis = ComputeSwingMatrix(ax, az)*ComputeTwistMatrix(ay); + m_new_basis = ComputeSwingMatrix(ax, az) * ComputeTwistMatrix(ay); - delta = MatrixToAxisAngle(m_basis.transposed()*m_new_basis); + delta = MatrixToAxisAngle(m_basis.transposed() * m_new_basis); if (!(m_locked[0] || m_locked[2]) && (clamp[0] || clamp[2])) { m_locked_ax = ax; @@ -528,12 +529,12 @@ void IK_QSphericalSegment::Lock(int dof, IK_QJacobian& jacobian, MT_Vector3& del { if (dof == 1) { m_locked[1] = true; - jacobian.Lock(m_DoF_id+1, delta[1]); + jacobian.Lock(m_DoF_id + 1, delta[1]); } else { m_locked[0] = m_locked[2] = true; jacobian.Lock(m_DoF_id, delta[0]); - jacobian.Lock(m_DoF_id+2, delta[2]); + jacobian.Lock(m_DoF_id + 2, delta[2]); } } @@ -545,14 +546,14 @@ void IK_QSphericalSegment::UpdateAngleApply() // IK_QNullSegment IK_QNullSegment::IK_QNullSegment() -: IK_QSegment(0, false) + : IK_QSegment(0, false) { } // IK_QRevoluteSegment IK_QRevoluteSegment::IK_QRevoluteSegment(int axis) -: IK_QSegment(1, false), m_axis(axis), m_angle(0.0), m_limit(false) + : IK_QSegment(1, false), m_axis(axis), m_angle(0.0), m_limit(false) { } @@ -634,7 +635,7 @@ void IK_QRevoluteSegment::SetWeight(int axis, MT_Scalar weight) // IK_QSwingSegment IK_QSwingSegment::IK_QSwingSegment() -: IK_QSegment(2, false), m_limit_x(false), m_limit_z(false) + : IK_QSegment(2, false), m_limit_x(false), m_limit_z(false) { } @@ -646,7 +647,7 @@ void IK_QSwingSegment::SetBasis(const MT_Matrix3x3& basis) MT_Vector3 IK_QSwingSegment::Axis(int dof) const { - return m_global_transform.getBasis().getColumn((dof==0)? 0: 2); + return m_global_transform.getBasis().getColumn((dof == 0) ? 0 : 2); } bool IK_QSwingSegment::UpdateAngle(const IK_QJacobian &jacobian, MT_Vector3& delta, bool *clamp) @@ -657,7 +658,7 @@ bool IK_QSwingSegment::UpdateAngle(const IK_QJacobian &jacobian, MT_Vector3& del MT_Vector3 dq; dq.x() = jacobian.AngleUpdate(m_DoF_id); dq.y() = 0.0; - dq.z() = jacobian.AngleUpdate(m_DoF_id+1); + dq.z() = jacobian.AngleUpdate(m_DoF_id + 1); // Directly update the rotation matrix, with Rodrigues' rotation formula, // to avoid singularities and allow smooth integration. @@ -665,25 +666,25 @@ bool IK_QSwingSegment::UpdateAngle(const IK_QJacobian &jacobian, MT_Vector3& del MT_Scalar theta = dq.length(); if (!MT_fuzzyZero(theta)) { - MT_Vector3 w = dq*(1.0/theta); + MT_Vector3 w = dq * (1.0 / theta); MT_Scalar sine = sin(theta); MT_Scalar cosine = cos(theta); - MT_Scalar cosineInv = 1-cosine; + MT_Scalar cosineInv = 1 - cosine; - MT_Scalar xsine = w.x()*sine; - MT_Scalar zsine = w.z()*sine; + MT_Scalar xsine = w.x() * sine; + MT_Scalar zsine = w.z() * sine; - MT_Scalar xxcosine = w.x()*w.x()*cosineInv; - MT_Scalar xzcosine = w.x()*w.z()*cosineInv; - MT_Scalar zzcosine = w.z()*w.z()*cosineInv; + MT_Scalar xxcosine = w.x() * w.x() * cosineInv; + MT_Scalar xzcosine = w.x() * w.z() * cosineInv; + MT_Scalar zzcosine = w.z() * w.z() * cosineInv; MT_Matrix3x3 M( - cosine + xxcosine, -zsine, xzcosine, - zsine, cosine, -xsine, - xzcosine, xsine, cosine + zzcosine); + cosine + xxcosine, -zsine, xzcosine, + zsine, cosine, -xsine, + xzcosine, xsine, cosine + zzcosine); - m_new_basis = m_basis*M; + m_new_basis = m_basis * M; RemoveTwist(m_new_basis); } @@ -731,7 +732,7 @@ bool IK_QSwingSegment::UpdateAngle(const IK_QJacobian &jacobian, MT_Vector3& del m_new_basis = ComputeSwingMatrix(ax, az); - delta = MatrixToAxisAngle(m_basis.transposed()*m_new_basis); + delta = MatrixToAxisAngle(m_basis.transposed() * m_new_basis); delta[1] = delta[2]; delta[2] = 0.0; return true; @@ -741,7 +742,7 @@ void IK_QSwingSegment::Lock(int, IK_QJacobian& jacobian, MT_Vector3& delta) { m_locked[0] = m_locked[1] = true; jacobian.Lock(m_DoF_id, delta[0]); - jacobian.Lock(m_DoF_id+1, delta[1]); + jacobian.Lock(m_DoF_id + 1, delta[1]); } void IK_QSwingSegment::UpdateAngleApply() @@ -758,11 +759,11 @@ void IK_QSwingSegment::SetLimit(int axis, MT_Scalar lmin, MT_Scalar lmax) lmin = MT_clamp(lmin, -MT_PI, MT_PI); lmax = MT_clamp(lmax, -MT_PI, MT_PI); - lmin = sin(lmin*0.5); - lmax = sin(lmax*0.5); + lmin = sin(lmin * 0.5); + lmax = sin(lmax * 0.5); // put center of ellispe in the middle between min and max - MT_Scalar offset = 0.5*(lmin + lmax); + MT_Scalar offset = 0.5 * (lmin + lmax); //lmax = lmax - offset; if (axis == 0) { @@ -794,8 +795,8 @@ void IK_QSwingSegment::SetWeight(int axis, MT_Scalar weight) // IK_QElbowSegment IK_QElbowSegment::IK_QElbowSegment(int axis) -: IK_QSegment(2, false), m_axis(axis), m_twist(0.0), m_angle(0.0), - m_cos_twist(1.0), m_sin_twist(0.0), m_limit(false), m_limit_twist(false) + : IK_QSegment(2, false), m_axis(axis), m_twist(0.0), m_angle(0.0), + m_cos_twist(1.0), m_sin_twist(0.0), m_limit(false), m_limit_twist(false) { } @@ -807,7 +808,7 @@ void IK_QElbowSegment::SetBasis(const MT_Matrix3x3& basis) RemoveTwist(m_basis); m_angle = EulerAngleFromMatrix(basis, m_axis); - m_basis = RotationMatrix(m_angle, m_axis)*ComputeTwistMatrix(m_twist); + m_basis = RotationMatrix(m_angle, m_axis) * ComputeTwistMatrix(m_twist); } MT_Vector3 IK_QElbowSegment::Axis(int dof) const @@ -850,7 +851,7 @@ bool IK_QElbowSegment::UpdateAngle(const IK_QJacobian &jacobian, MT_Vector3& del } if (!m_locked[1]) { - m_new_twist = m_twist + jacobian.AngleUpdate(m_DoF_id+1); + m_new_twist = m_twist + jacobian.AngleUpdate(m_DoF_id + 1); if (m_limit_twist) { if (m_new_twist > m_max_twist) { @@ -877,7 +878,7 @@ void IK_QElbowSegment::Lock(int dof, IK_QJacobian& jacobian, MT_Vector3& delta) } else { m_locked[1] = true; - jacobian.Lock(m_DoF_id+1, delta[1]); + jacobian.Lock(m_DoF_id + 1, delta[1]); } } @@ -892,7 +893,7 @@ void IK_QElbowSegment::UpdateAngleApply() MT_Matrix3x3 A = RotationMatrix(m_angle, m_axis); MT_Matrix3x3 T = RotationMatrix(m_sin_twist, m_cos_twist, 1); - m_basis = A*T; + m_basis = A * T; } void IK_QElbowSegment::SetLimit(int axis, MT_Scalar lmin, MT_Scalar lmax) @@ -927,7 +928,7 @@ void IK_QElbowSegment::SetWeight(int axis, MT_Scalar weight) // IK_QTranslateSegment IK_QTranslateSegment::IK_QTranslateSegment(int axis1) -: IK_QSegment(1, true) + : IK_QSegment(1, true) { m_axis_enabled[0] = m_axis_enabled[1] = m_axis_enabled[2] = false; m_axis_enabled[axis1] = true; @@ -938,7 +939,7 @@ IK_QTranslateSegment::IK_QTranslateSegment(int axis1) } IK_QTranslateSegment::IK_QTranslateSegment(int axis1, int axis2) -: IK_QSegment(2, true) + : IK_QSegment(2, true) { m_axis_enabled[0] = m_axis_enabled[1] = m_axis_enabled[2] = false; m_axis_enabled[axis1] = true; @@ -951,7 +952,7 @@ IK_QTranslateSegment::IK_QTranslateSegment(int axis1, int axis2) } IK_QTranslateSegment::IK_QTranslateSegment() -: IK_QSegment(3, true) + : IK_QSegment(3, true) { m_axis_enabled[0] = m_axis_enabled[1] = m_axis_enabled[2] = true; @@ -1013,7 +1014,7 @@ void IK_QTranslateSegment::UpdateAngleApply() void IK_QTranslateSegment::Lock(int dof, IK_QJacobian& jacobian, MT_Vector3& delta) { m_locked[dof] = true; - jacobian.Lock(m_DoF_id+dof, delta[dof]); + jacobian.Lock(m_DoF_id + dof, delta[dof]); } void IK_QTranslateSegment::SetWeight(int axis, MT_Scalar weight) @@ -1030,12 +1031,12 @@ void IK_QTranslateSegment::SetLimit(int axis, MT_Scalar lmin, MT_Scalar lmax) if (lmax < lmin) return; - m_min[axis]= lmin; - m_max[axis]= lmax; - m_limit[axis]= true; + m_min[axis] = lmin; + m_max[axis] = lmax; + m_limit[axis] = true; } -void IK_QTranslateSegment::Scale(float scale) +void IK_QTranslateSegment::Scale(MT_Scalar scale) { int i; diff --git a/intern/iksolver/intern/IK_QSegment.h b/intern/iksolver/intern/IK_QSegment.h index 68d40829137..25a8fbc0804 100644 --- a/intern/iksolver/intern/IK_QSegment.h +++ b/intern/iksolver/intern/IK_QSegment.h @@ -170,7 +170,7 @@ public: void Reset(); // scale - virtual void Scale(float scale); + virtual void Scale(MT_Scalar scale); protected: @@ -338,7 +338,7 @@ public: void SetWeight(int axis, MT_Scalar weight); void SetLimit(int axis, MT_Scalar lmin, MT_Scalar lmax); - void Scale(float scale); + void Scale(MT_Scalar scale); private: int m_axis[3]; diff --git a/intern/iksolver/intern/IK_QTask.cpp b/intern/iksolver/intern/IK_QTask.cpp index e050bb00658..0ba716ff59d 100644 --- a/intern/iksolver/intern/IK_QTask.cpp +++ b/intern/iksolver/intern/IK_QTask.cpp @@ -36,11 +36,11 @@ // IK_QTask IK_QTask::IK_QTask( - int size, - bool primary, - bool active, - const IK_QSegment *segment -) : + int size, + bool primary, + bool active, + const IK_QSegment *segment + ) : m_size(size), m_primary(primary), m_active(active), m_segment(segment), m_weight(1.0) { @@ -49,10 +49,10 @@ IK_QTask::IK_QTask( // IK_QPositionTask IK_QPositionTask::IK_QPositionTask( - bool primary, - const IK_QSegment *segment, - const MT_Vector3& goal -) : + bool primary, + const IK_QSegment *segment, + const MT_Vector3& goal + ) : IK_QTask(3, primary, true, segment), m_goal(goal) { // computing clamping length @@ -67,7 +67,7 @@ IK_QPositionTask::IK_QPositionTask( num++; } - m_clamp_length /= 2*num; + m_clamp_length /= 2 * num; } void IK_QPositionTask::ComputeJacobian(IK_QJacobian& jacobian) @@ -79,9 +79,9 @@ void IK_QPositionTask::ComputeJacobian(IK_QJacobian& jacobian) MT_Scalar length = d_pos.length(); if (length > m_clamp_length) - d_pos = (m_clamp_length/length)*d_pos; + d_pos = (m_clamp_length / length) * d_pos; - jacobian.SetBetas(m_id, m_size, m_weight*d_pos); + jacobian.SetBetas(m_id, m_size, m_weight * d_pos); // compute derivatives int i; @@ -91,13 +91,13 @@ void IK_QPositionTask::ComputeJacobian(IK_QJacobian& jacobian) MT_Vector3 p = seg->GlobalStart() - pos; for (i = 0; i < seg->NumberOfDoF(); i++) { - MT_Vector3 axis = seg->Axis(i)*m_weight; + MT_Vector3 axis = seg->Axis(i) * m_weight; if (seg->Translational()) - jacobian.SetDerivatives(m_id, seg->DoFId()+i, axis, 1e2); + jacobian.SetDerivatives(m_id, seg->DoFId() + i, axis, 1e2); else { MT_Vector3 pa = p.cross(axis); - jacobian.SetDerivatives(m_id, seg->DoFId()+i, pa, 1e0); + jacobian.SetDerivatives(m_id, seg->DoFId() + i, pa, 1e0); } } } @@ -113,10 +113,10 @@ MT_Scalar IK_QPositionTask::Distance() const // IK_QOrientationTask IK_QOrientationTask::IK_QOrientationTask( - bool primary, - const IK_QSegment *segment, - const MT_Matrix3x3& goal -) : + bool primary, + const IK_QSegment *segment, + const MT_Matrix3x3& goal + ) : IK_QTask(3, primary, true, segment), m_goal(goal), m_distance(0.0) { } @@ -126,17 +126,17 @@ void IK_QOrientationTask::ComputeJacobian(IK_QJacobian& jacobian) // compute betas const MT_Matrix3x3& rot = m_segment->GlobalTransform().getBasis(); - MT_Matrix3x3 d_rotm = m_goal*rot.transposed(); + MT_Matrix3x3 d_rotm = m_goal * rot.transposed(); d_rotm.transpose(); MT_Vector3 d_rot; - d_rot = -0.5*MT_Vector3(d_rotm[2][1] - d_rotm[1][2], - d_rotm[0][2] - d_rotm[2][0], - d_rotm[1][0] - d_rotm[0][1]); + d_rot = -0.5 * MT_Vector3(d_rotm[2][1] - d_rotm[1][2], + d_rotm[0][2] - d_rotm[2][0], + d_rotm[1][0] - d_rotm[0][1]); m_distance = d_rot.length(); - jacobian.SetBetas(m_id, m_size, m_weight*d_rot); + jacobian.SetBetas(m_id, m_size, m_weight * d_rot); // compute derivatives int i; @@ -146,10 +146,10 @@ void IK_QOrientationTask::ComputeJacobian(IK_QJacobian& jacobian) for (i = 0; i < seg->NumberOfDoF(); i++) { if (seg->Translational()) - jacobian.SetDerivatives(m_id, seg->DoFId()+i, MT_Vector3(0, 0, 0), 1e2); + jacobian.SetDerivatives(m_id, seg->DoFId() + i, MT_Vector3(0, 0, 0), 1e2); else { - MT_Vector3 axis = seg->Axis(i)*m_weight; - jacobian.SetDerivatives(m_id, seg->DoFId()+i, axis, 1e0); + MT_Vector3 axis = seg->Axis(i) * m_weight; + jacobian.SetDerivatives(m_id, seg->DoFId() + i, axis, 1e0); } } } @@ -158,15 +158,15 @@ void IK_QOrientationTask::ComputeJacobian(IK_QJacobian& jacobian) // Note: implementation not finished! IK_QCenterOfMassTask::IK_QCenterOfMassTask( - bool primary, - const IK_QSegment *segment, - const MT_Vector3& goal_center -) : + bool primary, + const IK_QSegment *segment, + const MT_Vector3& goal_center + ) : IK_QTask(3, primary, true, segment), m_goal_center(goal_center) { m_total_mass_inv = ComputeTotalMass(m_segment); if (!MT_fuzzyZero(m_total_mass_inv)) - m_total_mass_inv = 1.0/m_total_mass_inv; + m_total_mass_inv = 1.0 / m_total_mass_inv; } MT_Scalar IK_QCenterOfMassTask::ComputeTotalMass(const IK_QSegment *segment) @@ -182,7 +182,7 @@ MT_Scalar IK_QCenterOfMassTask::ComputeTotalMass(const IK_QSegment *segment) MT_Vector3 IK_QCenterOfMassTask::ComputeCenter(const IK_QSegment *segment) { - MT_Vector3 center = /*seg->Mass()**/segment->GlobalStart(); + MT_Vector3 center = /*seg->Mass()**/ segment->GlobalStart(); const IK_QSegment *seg; for (seg = segment->Child(); seg; seg = seg->Sibling()) @@ -197,14 +197,14 @@ void IK_QCenterOfMassTask::JacobianSegment(IK_QJacobian& jacobian, MT_Vector3& c MT_Vector3 p = center - segment->GlobalStart(); for (i = 0; i < segment->NumberOfDoF(); i++) { - MT_Vector3 axis = segment->Axis(i)*m_weight; - axis *= /*segment->Mass()**/m_total_mass_inv; + MT_Vector3 axis = segment->Axis(i) * m_weight; + axis *= /*segment->Mass()**/ m_total_mass_inv; if (segment->Translational()) - jacobian.SetDerivatives(m_id, segment->DoFId()+i, axis, 1e2); + jacobian.SetDerivatives(m_id, segment->DoFId() + i, axis, 1e2); else { MT_Vector3 pa = axis.cross(p); - jacobian.SetDerivatives(m_id, segment->DoFId()+i, pa, 1e0); + jacobian.SetDerivatives(m_id, segment->DoFId() + i, pa, 1e0); } } @@ -215,7 +215,7 @@ void IK_QCenterOfMassTask::JacobianSegment(IK_QJacobian& jacobian, MT_Vector3& c void IK_QCenterOfMassTask::ComputeJacobian(IK_QJacobian& jacobian) { - MT_Vector3 center = ComputeCenter(m_segment)*m_total_mass_inv; + MT_Vector3 center = ComputeCenter(m_segment) * m_total_mass_inv; // compute beta MT_Vector3 d_pos = m_goal_center - center; @@ -224,10 +224,10 @@ void IK_QCenterOfMassTask::ComputeJacobian(IK_QJacobian& jacobian) #if 0 if (m_distance > m_clamp_length) - d_pos = (m_clamp_length/m_distance)*d_pos; + d_pos = (m_clamp_length / m_distance) * d_pos; #endif - jacobian.SetBetas(m_id, m_size, m_weight*d_pos); + jacobian.SetBetas(m_id, m_size, m_weight * d_pos); // compute derivatives JacobianSegment(jacobian, center, m_segment); diff --git a/intern/iksolver/intern/IK_QTask.h b/intern/iksolver/intern/IK_QTask.h index 3d968cdfe38..45b1e59e606 100644 --- a/intern/iksolver/intern/IK_QTask.h +++ b/intern/iksolver/intern/IK_QTask.h @@ -78,7 +78,7 @@ public: virtual bool PositionTask() const { return false; } - virtual void Scale(float) {} + virtual void Scale(MT_Scalar) {} protected: int m_id; @@ -103,7 +103,7 @@ public: MT_Scalar Distance() const; bool PositionTask() const { return true; } - void Scale(float scale) { m_goal *= scale; m_clamp_length *= scale; } + void Scale(MT_Scalar scale) { m_goal *= scale; m_clamp_length *= scale; } private: MT_Vector3 m_goal; @@ -141,7 +141,7 @@ public: MT_Scalar Distance() const; - void Scale(float scale) { m_goal_center *= scale; m_distance *= scale; } + void Scale(MT_Scalar scale) { m_goal_center *= scale; m_distance *= scale; } private: MT_Scalar ComputeTotalMass(const IK_QSegment *segment); diff --git a/intern/iksolver/intern/IK_Solver.cpp b/intern/iksolver/intern/IK_Solver.cpp index 3876f26362c..6c2e30932bb 100644 --- a/intern/iksolver/intern/IK_Solver.cpp +++ b/intern/iksolver/intern/IK_Solver.cpp @@ -42,20 +42,21 @@ using namespace std; class IK_QSolver { public: - IK_QSolver() : root(NULL) {}; + IK_QSolver() : root(NULL) { + }; IK_QJacobianSolver solver; IK_QSegment *root; - std::list tasks; + std::list tasks; }; // FIXME: locks still result in small "residual" changes to the locked axes... IK_QSegment *CreateSegment(int flag, bool translate) { int ndof = 0; - ndof += (flag & IK_XDOF)? 1: 0; - ndof += (flag & IK_YDOF)? 1: 0; - ndof += (flag & IK_ZDOF)? 1: 0; + ndof += (flag & IK_XDOF) ? 1 : 0; + ndof += (flag & IK_YDOF) ? 1 : 0; + ndof += (flag & IK_ZDOF) ? 1 : 0; IK_QSegment *seg; @@ -78,7 +79,7 @@ IK_QSegment *CreateSegment(int flag, bool translate) if (flag & IK_XDOF) { axis1 = 0; - axis2 = (flag & IK_YDOF)? 1: 2; + axis2 = (flag & IK_YDOF) ? 1 : 2; } else { axis1 = 1; @@ -91,7 +92,7 @@ IK_QSegment *CreateSegment(int flag, bool translate) if (axis1 + axis2 == 2) seg = new IK_QSwingSegment(); else - seg = new IK_QElbowSegment((axis1 == 0)? 0: 2); + seg = new IK_QElbowSegment((axis1 == 0) ? 0 : 2); } } else { @@ -131,7 +132,7 @@ IK_Segment *IK_CreateSegment(int flag) void IK_FreeSegment(IK_Segment *seg) { - IK_QSegment *qseg = (IK_QSegment*)seg; + IK_QSegment *qseg = (IK_QSegment *)seg; if (qseg->Composite()) delete qseg->Composite(); @@ -140,8 +141,8 @@ void IK_FreeSegment(IK_Segment *seg) void IK_SetParent(IK_Segment *seg, IK_Segment *parent) { - IK_QSegment *qseg = (IK_QSegment*)seg; - IK_QSegment *qparent = (IK_QSegment*)parent; + IK_QSegment *qseg = (IK_QSegment *)seg; + IK_QSegment *qparent = (IK_QSegment *)parent; if (qparent && qparent->Composite()) qseg->SetParent(qparent->Composite()); @@ -151,7 +152,7 @@ void IK_SetParent(IK_Segment *seg, IK_Segment *parent) void IK_SetTransform(IK_Segment *seg, float start[3], float rest[][3], float basis[][3], float length) { - IK_QSegment *qseg = (IK_QSegment*)seg; + IK_QSegment *qseg = (IK_QSegment *)seg; MT_Vector3 mstart(start); // convert from blender column major to moto row major @@ -177,19 +178,19 @@ void IK_SetTransform(IK_Segment *seg, float start[3], float rest[][3], float bas void IK_SetLimit(IK_Segment *seg, IK_SegmentAxis axis, float lmin, float lmax) { - IK_QSegment *qseg = (IK_QSegment*)seg; + IK_QSegment *qseg = (IK_QSegment *)seg; if (axis >= IK_TRANS_X) { - if(!qseg->Translational()) { - if(qseg->Composite() && qseg->Composite()->Translational()) + if (!qseg->Translational()) { + if (qseg->Composite() && qseg->Composite()->Translational()) qseg = qseg->Composite(); else return; } - if(axis == IK_TRANS_X) axis = IK_X; - else if(axis == IK_TRANS_Y) axis = IK_Y; - else axis = IK_Z; + if (axis == IK_TRANS_X) axis = IK_X; + else if (axis == IK_TRANS_Y) axis = IK_Y; + else axis = IK_Z; } qseg->SetLimit(axis, lmin, lmax); @@ -197,25 +198,25 @@ void IK_SetLimit(IK_Segment *seg, IK_SegmentAxis axis, float lmin, float lmax) void IK_SetStiffness(IK_Segment *seg, IK_SegmentAxis axis, float stiffness) { - if (stiffness < 0.0) + if (stiffness < 0.0f) return; - if (stiffness > 0.999) - stiffness = 0.999; + if (stiffness > (1.0 - IK_STRETCH_STIFF_EPS)) + stiffness = (1.0 - IK_STRETCH_STIFF_EPS); - IK_QSegment *qseg = (IK_QSegment*)seg; - MT_Scalar weight = 1.0-stiffness; + IK_QSegment *qseg = (IK_QSegment *)seg; + MT_Scalar weight = 1.0f - stiffness; if (axis >= IK_TRANS_X) { - if(!qseg->Translational()) { - if(qseg->Composite() && qseg->Composite()->Translational()) + if (!qseg->Translational()) { + if (qseg->Composite() && qseg->Composite()->Translational()) qseg = qseg->Composite(); else return; } - if(axis == IK_TRANS_X) axis = IK_X; - else if(axis == IK_TRANS_Y) axis = IK_Y; + if (axis == IK_TRANS_X) axis = IK_X; + else if (axis == IK_TRANS_Y) axis = IK_Y; else axis = IK_Z; } @@ -224,7 +225,7 @@ void IK_SetStiffness(IK_Segment *seg, IK_SegmentAxis axis, float stiffness) void IK_GetBasisChange(IK_Segment *seg, float basis_change[][3]) { - IK_QSegment *qseg = (IK_QSegment*)seg; + IK_QSegment *qseg = (IK_QSegment *)seg; if (qseg->Translational() && qseg->Composite()) qseg = qseg->Composite(); @@ -245,7 +246,7 @@ void IK_GetBasisChange(IK_Segment *seg, float basis_change[][3]) void IK_GetTranslationChange(IK_Segment *seg, float *translation_change) { - IK_QSegment *qseg = (IK_QSegment*)seg; + IK_QSegment *qseg = (IK_QSegment *)seg; if (!qseg->Translational() && qseg->Composite()) qseg = qseg->Composite(); @@ -263,9 +264,9 @@ IK_Solver *IK_CreateSolver(IK_Segment *root) return NULL; IK_QSolver *solver = new IK_QSolver(); - solver->root = (IK_QSegment*)root; + solver->root = (IK_QSegment *)root; - return (IK_Solver*)solver; + return (IK_Solver *)solver; } void IK_FreeSolver(IK_Solver *solver) @@ -273,9 +274,9 @@ void IK_FreeSolver(IK_Solver *solver) if (solver == NULL) return; - IK_QSolver *qsolver = (IK_QSolver*)solver; - std::list& tasks = qsolver->tasks; - std::list::iterator task; + IK_QSolver *qsolver = (IK_QSolver *)solver; + std::list& tasks = qsolver->tasks; + std::list::iterator task; for (task = tasks.begin(); task != tasks.end(); task++) delete (*task); @@ -288,8 +289,8 @@ void IK_SolverAddGoal(IK_Solver *solver, IK_Segment *tip, float goal[3], float w if (solver == NULL || tip == NULL) return; - IK_QSolver *qsolver = (IK_QSolver*)solver; - IK_QSegment *qtip = (IK_QSegment*)tip; + IK_QSolver *qsolver = (IK_QSolver *)solver; + IK_QSegment *qtip = (IK_QSegment *)tip; if (qtip->Composite()) qtip = qtip->Composite(); @@ -306,8 +307,8 @@ void IK_SolverAddGoalOrientation(IK_Solver *solver, IK_Segment *tip, float goal[ if (solver == NULL || tip == NULL) return; - IK_QSolver *qsolver = (IK_QSolver*)solver; - IK_QSegment *qtip = (IK_QSegment*)tip; + IK_QSolver *qsolver = (IK_QSolver *)solver; + IK_QSegment *qtip = (IK_QSegment *)tip; if (qtip->Composite()) qtip = qtip->Composite(); @@ -327,14 +328,14 @@ void IK_SolverSetPoleVectorConstraint(IK_Solver *solver, IK_Segment *tip, float if (solver == NULL || tip == NULL) return; - IK_QSolver *qsolver = (IK_QSolver*)solver; - IK_QSegment *qtip = (IK_QSegment*)tip; + IK_QSolver *qsolver = (IK_QSolver *)solver; + IK_QSegment *qtip = (IK_QSegment *)tip; MT_Vector3 qgoal(goal); MT_Vector3 qpolegoal(polegoal); qsolver->solver.SetPoleVectorConstraint( - qtip, qgoal, qpolegoal, poleangle, getangle); + qtip, qgoal, qpolegoal, poleangle, getangle); } float IK_SolverGetPoleAngle(IK_Solver *solver) @@ -342,7 +343,7 @@ float IK_SolverGetPoleAngle(IK_Solver *solver) if (solver == NULL) return 0.0f; - IK_QSolver *qsolver = (IK_QSolver*)solver; + IK_QSolver *qsolver = (IK_QSolver *)solver; return qsolver->solver.GetPoleAngle(); } @@ -352,8 +353,8 @@ void IK_SolverAddCenterOfMass(IK_Solver *solver, IK_Segment *root, float goal[3] if (solver == NULL || root == NULL) return; - IK_QSolver *qsolver = (IK_QSolver*)solver; - IK_QSegment *qroot = (IK_QSegment*)root; + IK_QSolver *qsolver = (IK_QSolver *)solver; + IK_QSegment *qroot = (IK_QSegment *)root; // convert from blender column major to moto row major MT_Vector3 center(goal); @@ -368,18 +369,18 @@ int IK_Solve(IK_Solver *solver, float tolerance, int max_iterations) if (solver == NULL) return 0; - IK_QSolver *qsolver = (IK_QSolver*)solver; + IK_QSolver *qsolver = (IK_QSolver *)solver; IK_QSegment *root = qsolver->root; IK_QJacobianSolver& jacobian = qsolver->solver; - std::list& tasks = qsolver->tasks; + std::list& tasks = qsolver->tasks; MT_Scalar tol = tolerance; - if(!jacobian.Setup(root, tasks)) + if (!jacobian.Setup(root, tasks)) return 0; bool result = jacobian.Solve(root, tasks, tol, max_iterations); - return ((result)? 1: 0); + return ((result) ? 1 : 0); } diff --git a/intern/iksolver/intern/MT_ExpMap.cpp b/intern/iksolver/intern/MT_ExpMap.cpp index c997d434861..b2b13acebeb 100644 --- a/intern/iksolver/intern/MT_ExpMap.cpp +++ b/intern/iksolver/intern/MT_ExpMap.cpp @@ -37,11 +37,11 @@ * Set the exponential map from a quaternion. The quaternion must be non-zero. */ - void +void MT_ExpMap:: setRotation( - const MT_Quaternion &q -) { + const MT_Quaternion &q) +{ // ok first normalize the quaternion // then compute theta the axis-angle and the normalized axis v // scale v by theta and that's it hopefully! @@ -53,7 +53,7 @@ setRotation( m_sinp = m_v.length(); m_v /= m_sinp; - m_theta = atan2(double(m_sinp),double(cosp)); + m_theta = atan2(double(m_sinp), double(cosp)); m_v *= m_theta; } @@ -62,10 +62,10 @@ setRotation( * representation */ - const MT_Quaternion& +const MT_Quaternion& MT_ExpMap:: -getRotation( -) const { +getRotation() const +{ return m_q; } @@ -73,10 +73,10 @@ getRotation( * Convert the exponential map to a 3x3 matrix */ - MT_Matrix3x3 +MT_Matrix3x3 MT_ExpMap:: -getMatrix( -) const { +getMatrix() const +{ return MT_Matrix3x3(m_q); } @@ -84,11 +84,11 @@ getMatrix( * Update & reparameterizate the exponential map */ - void +void MT_ExpMap:: update( - const MT_Vector3& dv -){ + const MT_Vector3& dv) +{ m_v += dv; angleUpdated(); @@ -100,14 +100,13 @@ update( * from the map) and return them as a 3x3 matrix */ - void +void MT_ExpMap:: partialDerivatives( - MT_Matrix3x3& dRdx, - MT_Matrix3x3& dRdy, - MT_Matrix3x3& dRdz -) const { - + MT_Matrix3x3& dRdx, + MT_Matrix3x3& dRdy, + MT_Matrix3x3& dRdz) const +{ MT_Quaternion dQdx[3]; compute_dQdVi(dQdx); @@ -117,29 +116,28 @@ partialDerivatives( compute_dRdVi(dQdx[2], dRdz); } - void +void MT_ExpMap:: compute_dRdVi( - const MT_Quaternion &dQdvi, - MT_Matrix3x3 & dRdvi -) const { - - MT_Scalar prod[9]; + const MT_Quaternion &dQdvi, + MT_Matrix3x3 & dRdvi) const +{ + MT_Scalar prod[9]; /* This efficient formulation is arrived at by writing out the * entire chain rule product dRdq * dqdv in terms of 'q' and * noticing that all the entries are formed from sums of just * nine products of 'q' and 'dqdv' */ - prod[0] = -MT_Scalar(4)*m_q.x()*dQdvi.x(); - prod[1] = -MT_Scalar(4)*m_q.y()*dQdvi.y(); - prod[2] = -MT_Scalar(4)*m_q.z()*dQdvi.z(); - prod[3] = MT_Scalar(2)*(m_q.y()*dQdvi.x() + m_q.x()*dQdvi.y()); - prod[4] = MT_Scalar(2)*(m_q.w()*dQdvi.z() + m_q.z()*dQdvi.w()); - prod[5] = MT_Scalar(2)*(m_q.z()*dQdvi.x() + m_q.x()*dQdvi.z()); - prod[6] = MT_Scalar(2)*(m_q.w()*dQdvi.y() + m_q.y()*dQdvi.w()); - prod[7] = MT_Scalar(2)*(m_q.z()*dQdvi.y() + m_q.y()*dQdvi.z()); - prod[8] = MT_Scalar(2)*(m_q.w()*dQdvi.x() + m_q.x()*dQdvi.w()); + prod[0] = -MT_Scalar(4) * m_q.x() * dQdvi.x(); + prod[1] = -MT_Scalar(4) * m_q.y() * dQdvi.y(); + prod[2] = -MT_Scalar(4) * m_q.z() * dQdvi.z(); + prod[3] = MT_Scalar(2) * (m_q.y() * dQdvi.x() + m_q.x() * dQdvi.y()); + prod[4] = MT_Scalar(2) * (m_q.w() * dQdvi.z() + m_q.z() * dQdvi.w()); + prod[5] = MT_Scalar(2) * (m_q.z() * dQdvi.x() + m_q.x() * dQdvi.z()); + prod[6] = MT_Scalar(2) * (m_q.w() * dQdvi.y() + m_q.y() * dQdvi.w()); + prod[7] = MT_Scalar(2) * (m_q.z() * dQdvi.y() + m_q.y() * dQdvi.z()); + prod[8] = MT_Scalar(2) * (m_q.w() * dQdvi.x() + m_q.x() * dQdvi.w()); /* first row, followed by second and third */ dRdvi[0][0] = prod[1] + prod[2]; @@ -157,61 +155,60 @@ compute_dRdVi( // compute partial derivatives dQ/dVi - void +void MT_ExpMap:: compute_dQdVi( - MT_Quaternion *dQdX -) const { - + MT_Quaternion *dQdX) const +{ /* This is an efficient implementation of the derivatives given * in Appendix A of the paper with common subexpressions factored out */ MT_Scalar sinc, termCoeff; if (m_theta < MT_EXPMAP_MINANGLE) { - sinc = 0.5 - m_theta*m_theta/48.0; - termCoeff = (m_theta*m_theta/40.0 - 1.0)/24.0; + sinc = 0.5 - m_theta * m_theta / 48.0; + termCoeff = (m_theta * m_theta / 40.0 - 1.0) / 24.0; } else { MT_Scalar cosp = m_q.w(); - MT_Scalar ang = 1.0/m_theta; + MT_Scalar ang = 1.0 / m_theta; - sinc = m_sinp*ang; - termCoeff = ang*ang*(0.5*cosp - sinc); + sinc = m_sinp * ang; + termCoeff = ang * ang * (0.5 * cosp - sinc); } for (int i = 0; i < 3; i++) { MT_Quaternion& dQdx = dQdX[i]; - int i2 = (i+1)%3; - int i3 = (i+2)%3; + int i2 = (i + 1) % 3; + int i3 = (i + 2) % 3; - MT_Scalar term = m_v[i]*termCoeff; + MT_Scalar term = m_v[i] * termCoeff; - dQdx[i] = term*m_v[i] + sinc; - dQdx[i2] = term*m_v[i2]; - dQdx[i3] = term*m_v[i3]; - dQdx.w() = -0.5*m_v[i]*sinc; + dQdx[i] = term * m_v[i] + sinc; + dQdx[i2] = term * m_v[i2]; + dQdx[i3] = term * m_v[i3]; + dQdx.w() = -0.5 * m_v[i] * sinc; } } // reParametize away from singularity, updating // m_v and m_theta - void +void MT_ExpMap:: -reParametrize( -){ +reParametrize() +{ if (m_theta > MT_PI) { MT_Scalar scl = m_theta; - if (m_theta > MT_2_PI){ /* first get theta into range 0..2PI */ + if (m_theta > MT_2_PI) { /* first get theta into range 0..2PI */ m_theta = MT_Scalar(fmod(m_theta, MT_2_PI)); - scl = m_theta/scl; + scl = m_theta / scl; m_v *= scl; } - if (m_theta > MT_PI){ + if (m_theta > MT_PI) { scl = m_theta; m_theta = MT_2_PI - m_theta; - scl = MT_Scalar(1.0) - MT_2_PI/scl; + scl = MT_Scalar(1.0) - MT_2_PI / scl; m_v *= scl; } } @@ -219,10 +216,10 @@ reParametrize( // compute cached variables - void +void MT_ExpMap:: -angleUpdated( -){ +angleUpdated() +{ m_theta = m_v.length(); reParametrize(); @@ -233,20 +230,21 @@ angleUpdated( m_sinp = MT_Scalar(0.0); /* Taylor Series for sinc */ - MT_Vector3 temp = m_v * MT_Scalar(MT_Scalar(.5) - m_theta*m_theta/MT_Scalar(48.0)); + MT_Vector3 temp = m_v * MT_Scalar(MT_Scalar(.5) - m_theta * m_theta / MT_Scalar(48.0)); m_q.x() = temp.x(); m_q.y() = temp.y(); m_q.z() = temp.z(); m_q.w() = MT_Scalar(1.0); - } else { - m_sinp = MT_Scalar(sin(.5*m_theta)); + } + else { + m_sinp = MT_Scalar(sin(.5 * m_theta)); /* Taylor Series for sinc */ - MT_Vector3 temp = m_v * (m_sinp/m_theta); + MT_Vector3 temp = m_v * (m_sinp / m_theta); m_q.x() = temp.x(); m_q.y() = temp.y(); m_q.z() = temp.z(); - m_q.w() = MT_Scalar(cos(.5*m_theta)); + m_q.w() = MT_Scalar(cos(0.5 * m_theta)); } } diff --git a/intern/itasc/Armature.cpp b/intern/itasc/Armature.cpp index 1dacb8bc184..78780ed8ba3 100644 --- a/intern/itasc/Armature.cpp +++ b/intern/itasc/Armature.cpp @@ -319,7 +319,7 @@ int Armature::addConstraint(const std::string& segment_name, ConstraintCallback return iConstraint; } } - if (m_finalized) { + if (m_finalized) { if (_freeParam && _param) free(_param); return -1; diff --git a/intern/itasc/kdl/utilities/utility_io.cpp b/intern/itasc/kdl/utilities/utility_io.cpp index 0926f424f71..e16a85167bc 100644 --- a/intern/itasc/kdl/utilities/utility_io.cpp +++ b/intern/itasc/kdl/utilities/utility_io.cpp @@ -106,7 +106,7 @@ int _EatSpace( std::istream& is,int* countp=NULL) { // Eats whites, returns, tabs and the delim character -// Checks wether delim char. is encountered. +// Checks whether delim char. is encountered. void Eat( std::istream& is, int delim ) { int ch; @@ -119,7 +119,7 @@ void Eat( std::istream& is, int delim ) } // Eats whites, returns, tabs and the delim character -// Checks wether delim char. is encountered. +// Checks whether delim char. is encountered. // EatEnd does not eat all space-like char's at the end. void EatEnd( std::istream& is, int delim ) { diff --git a/intern/memutil/MEM_RefCountPtr.h b/intern/memutil/MEM_RefCountPtr.h index ffdf927b551..da10e689fbf 100644 --- a/intern/memutil/MEM_RefCountPtr.h +++ b/intern/memutil/MEM_RefCountPtr.h @@ -130,7 +130,7 @@ protected : /** * Protected constructors - * This class is not for direct instanciation. Sub classes + * This class is not for direct instantiation. Sub classes * should only be allocated on the heap. */ diff --git a/intern/raskter/raskter.c b/intern/raskter/raskter.c index e2d4809a23c..659d01e2d82 100644 --- a/intern/raskter/raskter.c +++ b/intern/raskter/raskter.c @@ -37,6 +37,15 @@ #endif +// this is needed for inlining behavior +#if defined _WIN32 +# define DO_INLINE __inline +#elif defined (__sun) || defined (__sun__) +# define DO_INLINE +#else +# define DO_INLINE static inline +#endif + /* * Sort all the edges of the input polygon by Y, then by X, of the "first" vertex encountered. @@ -814,14 +823,14 @@ int get_range_expanded_pixel_coord(float normalized_value, int max_value) { return (int)((normalized_value * (float)(max_value)) + 0.5f); } -__inline float get_pixel_intensity(float *buf, int buf_x, int buf_y, int pos_x, int pos_y) { +DO_INLINE float get_pixel_intensity(float *buf, int buf_x, int buf_y, int pos_x, int pos_y) { if(pos_x < 0 || pos_x >= buf_x || pos_y < 0 || pos_y >= buf_y) { return 0.0f; } return buf[(pos_y * buf_x) + pos_x]; } -__inline float get_pixel_intensity_bilinear(float *buf, int buf_x, int buf_y, float u, float v) { +DO_INLINE float get_pixel_intensity_bilinear(float *buf, int buf_x, int buf_y, float u, float v) { int a; int b; int a_plus_1; @@ -847,7 +856,7 @@ __inline float get_pixel_intensity_bilinear(float *buf, int buf_x, int buf_y, fl } -__inline void set_pixel_intensity(float *buf, int buf_x, int buf_y, int pos_x, int pos_y, float intensity) { +DO_INLINE void set_pixel_intensity(float *buf, int buf_x, int buf_y, int pos_x, int pos_y, float intensity) { if(pos_x < 0 || pos_x >= buf_x || pos_y < 0 || pos_y >= buf_y) { return; } diff --git a/release/scripts/modules/bl_i18n_utils/bl_process_msg.py b/release/scripts/modules/bl_i18n_utils/bl_process_msg.py index f189e3a0d80..b884423606d 100644 --- a/release/scripts/modules/bl_i18n_utils/bl_process_msg.py +++ b/release/scripts/modules/bl_i18n_utils/bl_process_msg.py @@ -270,7 +270,6 @@ def dump_messages_rna(messages, check_ctxt): walk_keymap_hierarchy(KM_HIERARCHY, "KM_HIERARCHY") - def dump_messages_pytext(messages, check_ctxt): """ dumps text inlined in the python user interface: eg. @@ -291,7 +290,7 @@ def dump_messages_pytext(messages, check_ctxt): # Break recursive nodes look up on some kind of nodes. # E.g. we don’t want to get strings inside subscripts (blah["foo"])! - stopper_nodes = {ast.Subscript,} + stopper_nodes = {ast.Subscript, } for func_id, func in bpy.types.UILayout.bl_rna.functions.items(): # check it has a 'text' argument diff --git a/release/scripts/modules/bl_i18n_utils/check_po.py b/release/scripts/modules/bl_i18n_utils/check_po.py index b669a9ddff2..03a933887c6 100755 --- a/release/scripts/modules/bl_i18n_utils/check_po.py +++ b/release/scripts/modules/bl_i18n_utils/check_po.py @@ -94,7 +94,6 @@ def main(): help="Restrict processed languages to those.") args = parser.parse_args() - if args.pot: global FILE_NAME_POT FILE_NAME_POT = args.pot @@ -145,24 +144,24 @@ def main(): ret = t if args.stats and glob_stats["nbr"] != 0.0: - nbr_contexts = len(glob_stats["contexts"]-{""}) + nbr_contexts = len(glob_stats["contexts"] - {""}) if nbr_contexts != 1: if nbr_contexts == 0: nbr_contexts = "No" _ctx_txt = "s are" else: _ctx_txt = " is" - print("\nAverage stats for all {:.0f} processed files:\n" \ - " {:>6.1%} done!\n" \ - " {:>6.1%} of messages are tooltips.\n" \ - " {:>6.1%} of tooltips are translated.\n" \ - " {:>6.1%} of translated messages are tooltips.\n" \ - " {:>6.1%} of messages are commented.\n" \ - " The org msgids are currently made of {} signs.\n" \ - " All processed translations are currently made of {} signs.\n" \ - " {} specific context{} present:\n {}\n" \ - "".format(glob_stats["nbr"], glob_stats["lvl"]/glob_stats["nbr"], - glob_stats["lvl_ttips"]/glob_stats["nbr"], + print("\nAverage stats for all {:.0f} processed files:\n" + " {:>6.1%} done!\n" + " {:>6.1%} of messages are tooltips.\n" + " {:>6.1%} of tooltips are translated.\n" + " {:>6.1%} of translated messages are tooltips.\n" + " {:>6.1%} of messages are commented.\n" + " The org msgids are currently made of {} signs.\n" + " All processed translations are currently made of {} signs.\n" + " {} specific context{} present:\n {}\n" + "".format(glob_stats["nbr"], glob_stats["lvl"] / glob_stats["nbr"], + glob_stats["lvl_ttips"] / glob_stats["nbr"], glob_stats["lvl_trans_ttips"]/glob_stats["nbr"], glob_stats["lvl_ttips_in_trans"]/glob_stats["nbr"], glob_stats["lvl_comm"]/glob_stats["nbr"], glob_stats["nbr_signs"], diff --git a/release/scripts/modules/bl_i18n_utils/clean_po.py b/release/scripts/modules/bl_i18n_utils/clean_po.py index f0b8dd6b1d2..2924ad9fb74 100755 --- a/release/scripts/modules/bl_i18n_utils/clean_po.py +++ b/release/scripts/modules/bl_i18n_utils/clean_po.py @@ -65,7 +65,6 @@ def main(): help="Restrict processed languages to those.") args = parser.parse_args() - ret = 0 if args.langs: diff --git a/release/scripts/modules/bl_i18n_utils/import_po_from_branches.py b/release/scripts/modules/bl_i18n_utils/import_po_from_branches.py index cbbef17b37d..a15bea9ef0d 100755 --- a/release/scripts/modules/bl_i18n_utils/import_po_from_branches.py +++ b/release/scripts/modules/bl_i18n_utils/import_po_from_branches.py @@ -56,12 +56,11 @@ def main(): help="Restrict processed languages to those.") args = parser.parse_args() - ret = 0 - threshold = float(settings.IMPORT_MIN_LEVEL)/100.0 + threshold = float(settings.IMPORT_MIN_LEVEL) / 100.0 if args.threshold is not None: - threshold = float(args.threshold)/100.0 + threshold = float(args.threshold) / 100.0 for lang in os.listdir(BRANCHES_DIR): if args.langs and lang not in args.langs: @@ -74,7 +73,7 @@ def main(): trans_msgs = stats["trans_msg"] lvl = 0.0 if tot_msgs: - lvl = float(trans_msgs)/float(tot_msgs) + lvl = float(trans_msgs) / float(tot_msgs) if lvl > threshold: if state["is_broken"] and args.strict: print("{:<10}: {:>6.1%} done, but BROKEN, skipped." \ diff --git a/release/scripts/modules/bl_i18n_utils/merge_po.py b/release/scripts/modules/bl_i18n_utils/merge_po.py index 51e587ca4c8..baf67de2e81 100755 --- a/release/scripts/modules/bl_i18n_utils/merge_po.py +++ b/release/scripts/modules/bl_i18n_utils/merge_po.py @@ -21,7 +21,7 @@ # # Merge one or more .po files into the first dest one. -# If a msgkey is present in more than one merged po, the one in the first file wins, unless +# If a msgkey is present in more than one merged po, the one in the first file wins, unless # it’s marked as fuzzy and one later is not. # The fuzzy flag is removed if necessary. # All other comments are never modified. @@ -59,7 +59,6 @@ def main(): help="The po's to merge into the dst.po one.") args = parser.parse_args() - ret = 0 done_msgkeys = set() done_fuzzy_msgkeys = set() @@ -78,7 +77,7 @@ def main(): # If we don’t want to replace existing valid translations, pre-populate # done_msgkeys and done_fuzzy_msgkeys. if not args.replace: - done_msgkeys = dst_states["trans_msg"].copy() + done_msgkeys = dst_states["trans_msg"].copy() done_fuzzy_msgkeys = dst_states["fuzzy_msg"].copy() for po in args.src: messages, states, stats = utils.parse_messages(po) diff --git a/release/scripts/modules/bl_i18n_utils/rtl_preprocess.py b/release/scripts/modules/bl_i18n_utils/rtl_preprocess.py index 9b2ee983952..5ee5c71be8b 100755 --- a/release/scripts/modules/bl_i18n_utils/rtl_preprocess.py +++ b/release/scripts/modules/bl_i18n_utils/rtl_preprocess.py @@ -86,6 +86,7 @@ FRIBIDI_FLAGS_DEFAULT = FRIBIDI_FLAG_SHAPE_MIRRORING | \ FRIBIDI_FLAGS_ARABIC = FRIBIDI_FLAG_SHAPE_ARAB_PRES | \ FRIBIDI_FLAG_SHAPE_ARAB_LIGA + ##### Kernel processing funcs. ##### def protect_format_seq(msg): """ @@ -185,6 +186,7 @@ def log2vis(msgs): yield fbc_str.value + ##### Command line stuff. ##### def main(): import argparse @@ -208,7 +210,6 @@ def main(): help="The po's to pre-process messages.") args = parser.parse_args() - msgs, state, u1 = utils.parse_messages(args.src) if state["is_broken"]: print("Source po is BROKEN, aborting.") diff --git a/release/scripts/modules/bl_i18n_utils/settings.py b/release/scripts/modules/bl_i18n_utils/settings.py index 094d8e481e9..d323dd37979 100644 --- a/release/scripts/modules/bl_i18n_utils/settings.py +++ b/release/scripts/modules/bl_i18n_utils/settings.py @@ -55,7 +55,7 @@ DOMAIN = "blender" # Our own "gettext" stuff. # File type (ext) to parse. -PYGETTEXT_ALLOWED_EXTS = {".c", ".cpp", ".cxx", ".hpp", ".hxx", ".h"} +PYGETTEXT_ALLOWED_EXTS = {".c", ".cpp", ".cxx", ".hpp", ".hxx", ".h"} # Where to search contexts definitions, relative to SOURCE_DIR (defined below). PYGETTEXT_CONTEXTS_DEFSRC = os.path.join("source", "blender", "blenfont", @@ -97,7 +97,7 @@ _msg_re = r"(?P" + _str_whole_re.format(_="_msg") + r")" PYGETTEXT_KEYWORDS = (() + tuple((r"{}\(\s*" + _msg_re + r"\s*\)").format(it) for it in ("IFACE_", "TIP_", "N_")) + - tuple((r"{}\(\s*" + _ctxt_re + r"\s*,\s*"+ _msg_re + r"\s*\)").format(it) + tuple((r"{}\(\s*" + _ctxt_re + r"\s*,\s*" + _msg_re + r"\s*\)").format(it) for it in ("CTX_IFACE_", "CTX_TIP_", "CTX_N_")) ) diff --git a/release/scripts/modules/bl_i18n_utils/spell_check_utils.py b/release/scripts/modules/bl_i18n_utils/spell_check_utils.py index 6dfb4be56aa..d668f2badfc 100644 --- a/release/scripts/modules/bl_i18n_utils/spell_check_utils.py +++ b/release/scripts/modules/bl_i18n_utils/spell_check_utils.py @@ -376,7 +376,7 @@ dict_uimsgs = { "chebychev", "kutta", "lennard", - "minkowsky", + "minkowski", "minnaert", "musgrave", "nayar", @@ -414,7 +414,7 @@ dict_uimsgs = { "gpu", "gpus", "hc", "hdr", - "hh", "mm", "ss", "ff", # hh:mm:ss:ff timecode + "hh", "mm", "ss", "ff", # hh:mm:ss:ff timecode "hsv", "hsva", "id", "itu", diff --git a/release/scripts/modules/bl_i18n_utils/update_branches.py b/release/scripts/modules/bl_i18n_utils/update_branches.py index 6626fa937a6..199b09aa13a 100755 --- a/release/scripts/modules/bl_i18n_utils/update_branches.py +++ b/release/scripts/modules/bl_i18n_utils/update_branches.py @@ -38,6 +38,7 @@ except: PY3 = settings.PYTHON3_EXEC + def main(): import argparse parser = argparse.ArgumentParser(description="" \ @@ -59,7 +60,6 @@ def main(): help="Restrict processed languages to those.") args = parser.parse_args() - ret = 0 # Generate a temp messages file. diff --git a/release/scripts/modules/bl_i18n_utils/update_mo.py b/release/scripts/modules/bl_i18n_utils/update_mo.py index 2ca24a76cfe..4a68f19fab0 100755 --- a/release/scripts/modules/bl_i18n_utils/update_mo.py +++ b/release/scripts/modules/bl_i18n_utils/update_mo.py @@ -47,7 +47,7 @@ def process_po(po, lang, mo=None): mo_dir = os.path.join(TRUNK_MO_DIR, lang, "LC_MESSAGES") # Create dirs if not existing! if not os.path.isdir(mo_dir): - os.makedirs(mo_dir, exist_ok = True) + os.makedirs(mo_dir, exist_ok=True) # show stats cmd = (GETTEXT_MSGFMT_EXECUTABLE, diff --git a/release/scripts/modules/bl_i18n_utils/update_po.py b/release/scripts/modules/bl_i18n_utils/update_po.py index d098b50e907..4c6495c5cfe 100755 --- a/release/scripts/modules/bl_i18n_utils/update_po.py +++ b/release/scripts/modules/bl_i18n_utils/update_po.py @@ -36,8 +36,8 @@ except: GETTEXT_MSGMERGE_EXECUTABLE = settings.GETTEXT_MSGMERGE_EXECUTABLE -BRANCHES_DIR = settings.BRANCHES_DIR -TRUNK_PO_DIR = settings.TRUNK_PO_DIR +BRANCHES_DIR = settings.BRANCHES_DIR +TRUNK_PO_DIR = settings.TRUNK_PO_DIR FILE_NAME_POT = settings.FILE_NAME_POT diff --git a/release/scripts/modules/bl_i18n_utils/update_pot.py b/release/scripts/modules/bl_i18n_utils/update_pot.py index ca5d156be9b..f98fc5d7705 100755 --- a/release/scripts/modules/bl_i18n_utils/update_pot.py +++ b/release/scripts/modules/bl_i18n_utils/update_pot.py @@ -74,12 +74,13 @@ pygettexts = tuple(re.compile(r).search _clean_str = re.compile(settings.str_clean_re).finditer clean_str = lambda s: "".join(m.group("clean") for m in _clean_str(s)) + def check_file(path, rel_path, messages): with open(path, encoding="utf-8") as f: f = f.read() for srch in pygettexts: m = srch(f) - line = pos =0 + line = pos = 0 while m: d = m.groupdict() # Context. @@ -149,6 +150,8 @@ from spell_check_utils import (dict_uimsgs, ) _spell_checked = set() + + def spell_check(txt, cache): ret = [] @@ -194,6 +197,8 @@ def gen_empty_pot(): escape_re = tuple(re.compile(r[0]) for r in settings.ESCAPE_RE) escape = lambda s, n: escape_re[n].sub(settings.ESCAPE_RE[n][1], s) + + def merge_messages(msgs, states, messages, do_checks, spell_cache): num_added = num_present = 0 for (context, msgid), srcs in messages.items(): diff --git a/release/scripts/modules/bl_i18n_utils/update_trunk.py b/release/scripts/modules/bl_i18n_utils/update_trunk.py index 5e0ceab387c..b7f8f375744 100755 --- a/release/scripts/modules/bl_i18n_utils/update_trunk.py +++ b/release/scripts/modules/bl_i18n_utils/update_trunk.py @@ -65,7 +65,6 @@ def main(): help="Restrict processed languages to those.") args = parser.parse_args() - ret = 0 failed = set() diff --git a/release/scripts/modules/bl_i18n_utils/utils.py b/release/scripts/modules/bl_i18n_utils/utils.py index ebf0f994a7a..3e5394d85a4 100644 --- a/release/scripts/modules/bl_i18n_utils/utils.py +++ b/release/scripts/modules/bl_i18n_utils/utils.py @@ -40,6 +40,7 @@ def stripeol(s): def is_tooltip(msgid): return len(msgid) > 30 + def parse_messages(fname): """ Returns a tupple (messages, states, stats). @@ -82,7 +83,6 @@ def parse_messages(fname): fuzzy_messages = set() commented_messages = set() - def clean_vars(): nonlocal reading_msgid, reading_msgstr, reading_msgctxt, \ reading_comment, is_fuzzy, is_translated, is_commented, \ @@ -143,7 +143,6 @@ def parse_messages(fname): clean_vars() - with open(fname, 'r', encoding="utf-8") as f: for line_nr, line in enumerate(f): line = stripeol(line) @@ -156,7 +155,7 @@ def parse_messages(fname): reading_ctxt = True if line.startswith(COMMENT_PREFIX): is_commented = True - line = line[9+len(COMMENT_PREFIX):-1] + line = line[9 + len(COMMENT_PREFIX):-1] else: line = line[9:-1] msgctxt_lines.append(line) @@ -167,7 +166,7 @@ def parse_messages(fname): reading_msgid = True if line.startswith(COMMENT_PREFIX): is_commented = True - line = line[7+len(COMMENT_PREFIX):-1] + line = line[7 + len(COMMENT_PREFIX):-1] else: line = line[7:-1] msgid_lines.append(line) @@ -180,7 +179,7 @@ def parse_messages(fname): reading_msgid = False reading_msgstr = True if line.startswith(COMMENT_PREFIX): - line = line[8+len(COMMENT_PREFIX):-1] + line = line[8 + len(COMMENT_PREFIX):-1] if not is_commented: is_broken = True else: @@ -194,13 +193,13 @@ def parse_messages(fname): elif line.startswith("#"): if reading_msgid: if is_commented: - msgid_lines.append(line[1+len(COMMENT_PREFIX):-1]) + msgid_lines.append(line[1 + len(COMMENT_PREFIX):-1]) else: msgid_lines.append(line) is_broken = True elif reading_msgstr: if is_commented: - msgstr_lines.append(line[1+len(COMMENT_PREFIX):-1]) + msgstr_lines.append(line[1 + len(COMMENT_PREFIX):-1]) else: msgstr_lines.append(line) is_broken = True @@ -338,13 +337,13 @@ def print_stats(stats, glob_stats=None, prefix=""): lvl = lvl_ttips = lvl_trans_ttips = lvl_ttips_in_trans = lvl_comm = 0.0 if tot_msgs > 0: - lvl = float(trans_msgs)/float(tot_msgs) - lvl_ttips = float(tot_ttips)/float(tot_msgs) - lvl_comm = float(comm_msgs)/float(tot_msgs+comm_msgs) + lvl = float(trans_msgs) / float(tot_msgs) + lvl_ttips = float(tot_ttips) / float(tot_msgs) + lvl_comm = float(comm_msgs) / float(tot_msgs+comm_msgs) if tot_ttips > 0: - lvl_trans_ttips = float(trans_ttips)/float(tot_ttips) + lvl_trans_ttips = float(trans_ttips) / float(tot_ttips) if trans_msgs > 0: - lvl_ttips_in_trans = float(trans_ttips)/float(trans_msgs) + lvl_ttips_in_trans = float(trans_ttips) / float(trans_msgs) if glob_stats: glob_stats["nbr"] += 1.0 @@ -368,9 +367,8 @@ def print_stats(stats, glob_stats=None, prefix=""): "{:>6.1%} of translated messages are tooltips ({} over {}).\n" "".format(lvl_ttips_in_trans, trans_ttips, trans_msgs), "{:>6.1%} of messages are commented ({} over {}).\n" - "".format(lvl_comm, comm_msgs, comm_msgs+tot_msgs), + "".format(lvl_comm, comm_msgs, comm_msgs + tot_msgs), "This translation is currently made of {} signs.\n" "".format(nbr_trans_signs)) print(prefix.join(lines)) return 0 - diff --git a/release/scripts/modules/bpy/utils.py b/release/scripts/modules/bpy/utils.py index ad657284492..09deb33c174 100644 --- a/release/scripts/modules/bpy/utils.py +++ b/release/scripts/modules/bpy/utils.py @@ -34,13 +34,14 @@ __all__ = ( "register_class", "register_module", "resource_path", + "script_path_user", + "script_path_pref", "script_paths", "smpte_from_frame", "smpte_from_seconds", "unregister_class", "unregister_module", "user_resource", - "user_script_path", ) from _bpy import register_class, unregister_class, blend_paths, resource_path @@ -252,15 +253,16 @@ _scripts = _os.path.join(_os.path.dirname(__file__), _scripts = (_os.path.normpath(_scripts), ) -def user_script_path(): - # returns the env var and falls back to userprefs +def script_path_user(): + """returns the env var and falls back to home dir or None""" path = _user_resource('SCRIPTS') + return _os.path.normpath(path) if path else None - if path: - path = _os.path.normpath(path) - return path - else: - return None + +def script_path_pref(): + """returns the user preference or None""" + path = _bpy.context.user_preferences.filepaths.script_directory + return _os.path.normpath(path) if path else None def script_paths(subdir=None, user_pref=True, check_all=False): @@ -278,10 +280,6 @@ def script_paths(subdir=None, user_pref=True, check_all=False): :rtype: list """ scripts = list(_scripts) - prefs = _bpy.context.user_preferences - - # add user scripts dir - user_script = user_script_path() if check_all: # all possible paths @@ -291,7 +289,7 @@ def script_paths(subdir=None, user_pref=True, check_all=False): # only paths blender uses base_paths = _bpy_script_paths() - for path in base_paths + (user_script, ): + for path in base_paths + (script_path_user(), script_path_pref()): if path: path = _os.path.normpath(path) if path not in scripts and _os.path.isdir(path): diff --git a/release/scripts/modules/console_python.py b/release/scripts/modules/console_python.py index 2aaadb17b71..d32606eb0b0 100644 --- a/release/scripts/modules/console_python.py +++ b/release/scripts/modules/console_python.py @@ -308,7 +308,8 @@ def banner(context): 'OUTPUT') add_scrollback("Convenience Imports: from mathutils import *; " "from math import *", 'OUTPUT') - add_scrollback("Convenience Variables: C = bpy.context, D = bpy.data", 'OUTPUT') + add_scrollback("Convenience Variables: C = bpy.context, D = bpy.data", + 'OUTPUT') add_scrollback("", 'OUTPUT') sc.prompt = PROMPT diff --git a/release/scripts/modules/sys_info.py b/release/scripts/modules/sys_info.py index 6fc50bcfe0d..ea75bfde809 100644 --- a/release/scripts/modules/sys_info.py +++ b/release/scripts/modules/sys_info.py @@ -87,7 +87,8 @@ def write_sysinfo(op): output.write("\nDirectories:\n") output.write(lilies) output.write("scripts: %r\n" % (bpy.utils.script_paths())) - output.write("user scripts: %r\n" % (bpy.utils.user_script_path())) + output.write("user scripts: %r\n" % (bpy.utils.script_path_user())) + output.write("pref scripts: %r\n" % (bpy.utils.script_path_pref())) output.write("datafiles: %r\n" % (bpy.utils.user_resource('DATAFILES'))) output.write("config: %r\n" % (bpy.utils.user_resource('CONFIG'))) output.write("scripts : %r\n" % (bpy.utils.user_resource('SCRIPTS'))) diff --git a/release/scripts/startup/bl_operators/wm.py b/release/scripts/startup/bl_operators/wm.py index 18450ebe316..a81733fe59c 100644 --- a/release/scripts/startup/bl_operators/wm.py +++ b/release/scripts/startup/bl_operators/wm.py @@ -101,7 +101,6 @@ def operator_value_is_undo(value): return (isinstance(id_data, bpy.types.ID) and (not isinstance(id_data, (bpy.types.WindowManager, bpy.types.Screen, - bpy.types.Scene, bpy.types.Brush, )))) diff --git a/release/scripts/startup/bl_ui/__init__.py b/release/scripts/startup/bl_ui/__init__.py index 84049e9f1fe..847807029fa 100644 --- a/release/scripts/startup/bl_ui/__init__.py +++ b/release/scripts/startup/bl_ui/__init__.py @@ -38,6 +38,7 @@ _modules = ( "properties_data_modifier", "properties_data_speaker", "properties_game", + "properties_mask_common", "properties_material", "properties_object_constraint", "properties_object", diff --git a/release/scripts/startup/bl_ui/properties_data_armature.py b/release/scripts/startup/bl_ui/properties_data_armature.py index 03aa41bb9aa..e194d7a1370 100644 --- a/release/scripts/startup/bl_ui/properties_data_armature.py +++ b/release/scripts/startup/bl_ui/properties_data_armature.py @@ -323,6 +323,7 @@ class DATA_PT_onion_skinning(OnionSkinButtonsPanel): # , Panel): # inherit from def draw(self, context): ob = context.object + self.draw_settings(context, ob.pose.animation_visualization, bones=True) diff --git a/release/scripts/startup/bl_ui/properties_data_mesh.py b/release/scripts/startup/bl_ui/properties_data_mesh.py index 4f3be914e66..5f21f78a375 100644 --- a/release/scripts/startup/bl_ui/properties_data_mesh.py +++ b/release/scripts/startup/bl_ui/properties_data_mesh.py @@ -148,7 +148,7 @@ class DATA_PT_vertex_groups(MeshButtonsPanel, Panel): col = row.column(align=True) col.operator("object.vertex_group_add", icon='ZOOMIN', text="") - col.operator("object.vertex_group_remove", icon='ZOOMOUT', text="") + col.operator("object.vertex_group_remove", icon='ZOOMOUT', text="").all = False col.menu("MESH_MT_vertex_group_specials", icon='DOWNARROW_HLT', text="") if group: col.separator() diff --git a/release/scripts/startup/bl_ui/properties_data_speaker.py b/release/scripts/startup/bl_ui/properties_data_speaker.py index 853c11c96c6..ca922dfb544 100644 --- a/release/scripts/startup/bl_ui/properties_data_speaker.py +++ b/release/scripts/startup/bl_ui/properties_data_speaker.py @@ -105,14 +105,13 @@ class DATA_PT_cone(DataButtonsPanel, Panel): speaker = context.speaker split = layout.split() - col = split.column() + col = split.column() col.label("Angle:") col.prop(speaker, "cone_angle_outer", text="Outer") col.prop(speaker, "cone_angle_inner", text="Inner") col = split.column() - col.label("Volume:") col.prop(speaker, "cone_volume_outer", text="Outer") diff --git a/release/scripts/startup/bl_ui/properties_game.py b/release/scripts/startup/bl_ui/properties_game.py index c25c0c7d40d..5ff49a7d369 100644 --- a/release/scripts/startup/bl_ui/properties_game.py +++ b/release/scripts/startup/bl_ui/properties_game.py @@ -337,7 +337,6 @@ class RENDER_PT_game_stereo(RenderButtonsPanel, Panel): if dome_type in {'FISHEYE', 'TRUNCATED_REAR', 'TRUNCATED_FRONT'}: col = split.column() - col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True) col.prop(gs, "dome_angle", slider=True) @@ -347,14 +346,13 @@ class RENDER_PT_game_stereo(RenderButtonsPanel, Panel): elif dome_type == 'PANORAM_SPH': col = split.column() - col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True) + col = split.column() col.prop(gs, "dome_tessellation", text="Tessellation") else: # cube map col = split.column() - col.prop(gs, "dome_buffer_resolution", text="Resolution", slider=True) col = split.column() @@ -396,6 +394,7 @@ class RENDER_PT_game_system(RenderButtonsPanel, Panel): layout = self.layout gs = context.scene.game_settings + row = layout.row() row.prop(gs, "use_frame_rate") row.prop(gs, "restrict_animation_updates") @@ -415,10 +414,10 @@ class RENDER_PT_game_display(RenderButtonsPanel, Panel): def draw(self, context): layout = self.layout - row = layout.row() - row.prop(context.scene.render, "fps", text="Animation Frame Rate", slider=False) - gs = context.scene.game_settings + + layout.prop(context.scene.render, "fps", text="Animation Frame Rate", slider=False) + flow = layout.column_flow() flow.prop(gs, "show_debug_properties", text="Debug Properties") flow.prop(gs, "show_framerate_profile", text="Framerate and Profile") @@ -582,14 +581,14 @@ class WORLD_PT_game_mist(WorldButtonsPanel, Panel): world = context.world layout.active = world.mist_settings.use_mist - row = layout.row() - row.prop(world.mist_settings, "falloff") + + layout.prop(world.mist_settings, "falloff") row = layout.row(align=True) row.prop(world.mist_settings, "start") row.prop(world.mist_settings, "depth") - row = layout.row() - row.prop(world.mist_settings, "intensity", text="Minimum Intensity") + + layout.prop(world.mist_settings, "intensity", text="Minimum Intensity") class WORLD_PT_game_physics(WorldButtonsPanel, Panel): diff --git a/release/scripts/startup/bl_ui/properties_mask_common.py b/release/scripts/startup/bl_ui/properties_mask_common.py new file mode 100644 index 00000000000..e40b46fda70 --- /dev/null +++ b/release/scripts/startup/bl_ui/properties_mask_common.py @@ -0,0 +1,317 @@ +# ##### BEGIN GPL LICENSE BLOCK ##### +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# ##### END GPL LICENSE BLOCK ##### + +# + +# panels get subclassed (not registered directly) +# menus are referenced `as is` + +import bpy +from bpy.types import Menu + + +class MASK_PT_mask: + # subclasses must define... + #~ bl_space_type = 'CLIP_EDITOR' + #~ bl_region_type = 'UI' + bl_label = "Mask Settings" + bl_options = {'DEFAULT_CLOSED'} + + @classmethod + def poll(cls, context): + space_data = context.space_data + return space_data.mask and space_data.mode == 'MASK' + + def draw(self, context): + layout = self.layout + + sc = context.space_data + mask = sc.mask + + col = layout.column(align=True) + col.prop(mask, "frame_start") + col.prop(mask, "frame_end") + + +class MASK_PT_layers: + # subclasses must define... + #~ bl_space_type = 'CLIP_EDITOR' + #~ bl_region_type = 'UI' + bl_label = "Mask Layers" + + @classmethod + def poll(cls, context): + space_data = context.space_data + return space_data.mask and space_data.mode == 'MASK' + + def draw(self, context): + layout = self.layout + + sc = context.space_data + mask = sc.mask + active_layer = mask.layers.active + + rows = 5 if active_layer else 2 + + row = layout.row() + row.template_list(mask, "layers", + mask, "active_layer_index", rows=rows) + + sub = row.column(align=True) + + sub.operator("mask.layer_new", icon='ZOOMIN', text="") + sub.operator("mask.layer_remove", icon='ZOOMOUT', text="") + + if active_layer: + sub.separator() + + props = sub.operator("mask.layer_move", icon='TRIA_UP', text="") + props.direction = 'UP' + + props = sub.operator("mask.layer_move", icon='TRIA_DOWN', text="") + props.direction = 'DOWN' + + layout.prop(active_layer, "name") + + # blending + row = layout.row(align=True) + row.prop(active_layer, "alpha") + row.prop(active_layer, "invert", text="", icon='IMAGE_ALPHA') + + layout.prop(active_layer, "blend") + layout.prop(active_layer, "falloff") + + +class MASK_PT_spline(): + # subclasses must define... + #~ bl_space_type = 'CLIP_EDITOR' + #~ bl_region_type = 'UI' + bl_label = "Active Spline" + + @classmethod + def poll(cls, context): + sc = context.space_data + mask = sc.mask + + if mask and sc.mode == 'MASK': + return mask.layers.active and mask.layers.active.splines.active + + return False + + def draw(self, context): + layout = self.layout + + sc = context.space_data + mask = sc.mask + spline = mask.layers.active.splines.active + + col = layout.column() + col.prop(spline, "weight_interpolation") + + row = col.row() + row.prop(spline, "use_cyclic") + row.prop(spline, "use_fill") + + +class MASK_PT_point(): + # subclasses must define... + #~ bl_space_type = 'CLIP_EDITOR' + #~ bl_region_type = 'UI' + bl_label = "Active Point" + + @classmethod + def poll(cls, context): + sc = context.space_data + mask = sc.mask + + if mask and sc.mode == 'MASK': + mask_layer_active = mask.layers.active + return (mask_layer_active and + mask_layer_active.splines.active_point) + + return False + + def draw(self, context): + layout = self.layout + + sc = context.space_data + mask = sc.mask + point = mask.layers.active.splines.active_point + parent = point.parent + + col = layout.column() + col.prop(point, "handle_type") + + col = layout.column() + # Currently only parenting yo movie clip is allowed, so do not + # ver-oplicate things for now and use single template_ID + #col.template_any_ID(parent, "id", "id_type", text="") + + col.label("Parent:") + col.prop(parent, "id", text="") + + if parent.id_type == 'MOVIECLIP' and parent.id: + clip = parent.id + tracking = clip.tracking + + col.prop_search(parent, "parent", tracking, + "objects", icon='OBJECT_DATA', text="Object:") + + if parent.parent in tracking.objects: + object = tracking.objects[parent.parent] + col.prop_search(parent, "sub_parent", object, + "tracks", icon='ANIM_DATA', text="Track:") + else: + col.prop_search(parent, "sub_parent", tracking, + "tracks", icon='ANIM_DATA', text="Track:") + + +class MASK_PT_display(): + # subclasses must define... + #~ bl_space_type = 'CLIP_EDITOR' + #~ bl_region_type = 'UI' + bl_label = "Mask Display" + bl_options = {'DEFAULT_CLOSED'} + + @classmethod + def poll(cls, context): + space_data = context.space_data + return space_data.mask and space_data.mode == 'MASK' + + def draw(self, context): + layout = self.layout + + space_data = context.space_data + + layout.prop(space_data, "mask_draw_type", text="") + layout.prop(space_data, "show_mask_smooth") + + +class MASK_PT_tools(): + # subclasses must define... + #~ bl_space_type = 'CLIP_EDITOR' + #~ bl_region_type = 'TOOLS' + bl_label = "Mask Tools" + + @classmethod + def poll(cls, context): + space_data = context.space_data + return space_data.mask and space_data.mode == 'MASK' + + def draw(self, context): + layout = self.layout + + col = layout.column(align=True) + col.label(text="Transform:") + col.operator("transform.translate") + col.operator("transform.rotate") + col.operator("transform.resize", text="Scale") + props = col.operator("transform.transform", text="Shrink/Fatten") + props.mode = 'MASK_SHRINKFATTEN' + + col = layout.column(align=True) + col.label(text="Spline:") + col.operator("mask.delete") + col.operator("mask.cyclic_toggle") + col.operator("mask.switch_direction") + + col = layout.column(align=True) + col.label(text="Parenting:") + col.operator("mask.parent_set") + col.operator("mask.parent_clear") + + +class MASK_MT_mask(Menu): + bl_label = "Mask" + + def draw(self, context): + layout = self.layout + + layout.operator("mask.delete") + + layout.separator() + layout.operator("mask.cyclic_toggle") + layout.operator("mask.switch_direction") + layout.operator("mask.normals_make_consistent") + layout.operator("mask.feather_weight_clear") # TODO, better place? + + layout.separator() + layout.operator("mask.parent_clear") + layout.operator("mask.parent_set") + + layout.separator() + layout.menu("MASK_MT_visibility") + layout.menu("MASK_MT_transform") + layout.menu("MASK_MT_animation") + + +class MASK_MT_visibility(Menu): + bl_label = "Show/Hide" + + def draw(self, context): + layout = self.layout + + layout.operator("mask.hide_view_clear", text="Show Hidden") + layout.operator("mask.hide_view_set", text="Hide Selected") + + props = layout.operator("mask.hide_view_set", text="Hide Unselected") + props.unselected = True + + +class MASK_MT_transform(Menu): + bl_label = "Transform" + + def draw(self, context): + layout = self.layout + + layout.operator("transform.translate") + layout.operator("transform.rotate") + layout.operator("transform.resize") + props = layout.operator("transform.transform", text="Shrink/Fatten") + props.mode = 'MASK_SHRINKFATTEN' + + +class MASK_MT_animation(Menu): + bl_label = "Animation" + + def draw(self, context): + layout = self.layout + + layout.operator("mask.shape_key_clear") + layout.operator("mask.shape_key_insert") + layout.operator("mask.shape_key_feather_reset") + layout.operator("mask.shape_key_rekey") + + +class MASK_MT_select(Menu): + bl_label = "Select" + + def draw(self, context): + layout = self.layout + sc = context.space_data + + layout.operator("mask.select_border") + layout.operator("mask.select_circle") + + layout.separator() + + layout.operator("mask.select_all").action = 'TOGGLE' + layout.operator("mask.select_all", text="Inverse").action = 'INVERT' + +if __name__ == "__main__": # only for live edit. + bpy.utils.register_module(__name__) diff --git a/release/scripts/startup/bl_ui/properties_material.py b/release/scripts/startup/bl_ui/properties_material.py index 6e66bd0d98b..dfc75168d2b 100644 --- a/release/scripts/startup/bl_ui/properties_material.py +++ b/release/scripts/startup/bl_ui/properties_material.py @@ -350,7 +350,6 @@ class MATERIAL_PT_shading(MaterialButtonsPanel, Panel): class MATERIAL_PT_transp(MaterialButtonsPanel, Panel): bl_label = "Transparency" - # bl_options = {'DEFAULT_CLOSED'} COMPAT_ENGINES = {'BLENDER_RENDER'} @classmethod diff --git a/release/scripts/startup/bl_ui/properties_object.py b/release/scripts/startup/bl_ui/properties_object.py index 68b261cc1d5..275cb8fab65 100644 --- a/release/scripts/startup/bl_ui/properties_object.py +++ b/release/scripts/startup/bl_ui/properties_object.py @@ -259,7 +259,6 @@ class OBJECT_PT_duplication(ObjectButtonsPanel, Panel): layout.prop(ob, "use_dupli_vertices_rotation", text="Rotation") elif ob.dupli_type == 'FACES': - row = layout.row() row.prop(ob, "use_dupli_faces_scale", text="Scale") row.prop(ob, "dupli_faces_scale", text="Inherit Scale") diff --git a/release/scripts/startup/bl_ui/properties_physics_common.py b/release/scripts/startup/bl_ui/properties_physics_common.py index 4db056e77a2..7f824d94431 100644 --- a/release/scripts/startup/bl_ui/properties_physics_common.py +++ b/release/scripts/startup/bl_ui/properties_physics_common.py @@ -186,11 +186,8 @@ def effector_weights_ui(self, context, weights): split = layout.split() - col = split.column() - col.prop(weights, "gravity", slider=True) - - col = split.column() - col.prop(weights, "all", slider=True) + split.prop(weights, "gravity", slider=True) + split.prop(weights, "all", slider=True) layout.separator() diff --git a/release/scripts/startup/bl_ui/properties_physics_field.py b/release/scripts/startup/bl_ui/properties_physics_field.py index 65603c65041..70499b18f41 100644 --- a/release/scripts/startup/bl_ui/properties_physics_field.py +++ b/release/scripts/startup/bl_ui/properties_physics_field.py @@ -168,7 +168,6 @@ class PHYSICS_PT_field(PhysicButtonsPanel, Panel): class PHYSICS_PT_collision(PhysicButtonsPanel, Panel): bl_label = "Collision" - #bl_options = {'DEFAULT_CLOSED'} @classmethod def poll(cls, context): diff --git a/release/scripts/startup/bl_ui/properties_scene.py b/release/scripts/startup/bl_ui/properties_scene.py index c9c9c36217b..8449d26f6e6 100644 --- a/release/scripts/startup/bl_ui/properties_scene.py +++ b/release/scripts/startup/bl_ui/properties_scene.py @@ -39,6 +39,7 @@ class SCENE_PT_scene(SceneButtonsPanel, Panel): def draw(self, context): layout = self.layout + scene = context.scene layout.prop(scene, "camera") @@ -52,6 +53,7 @@ class SCENE_PT_audio(SceneButtonsPanel, Panel): def draw(self, context): layout = self.layout + scene = context.scene rd = context.scene.render ffmpeg = rd.ffmpeg @@ -81,6 +83,7 @@ class SCENE_PT_unit(SceneButtonsPanel, Panel): def draw(self, context): layout = self.layout + unit = context.scene.unit_settings col = layout.column() diff --git a/release/scripts/startup/bl_ui/properties_texture.py b/release/scripts/startup/bl_ui/properties_texture.py index 5bde9538e54..46a17675c91 100644 --- a/release/scripts/startup/bl_ui/properties_texture.py +++ b/release/scripts/startup/bl_ui/properties_texture.py @@ -116,6 +116,7 @@ class TEXTURE_PT_context_texture(TextureButtonsPanel, Panel): def draw(self, context): layout = self.layout + slot = getattr(context, "texture_slot", None) node = getattr(context, "texture_node", None) space = context.space_data diff --git a/release/scripts/startup/bl_ui/properties_world.py b/release/scripts/startup/bl_ui/properties_world.py index 76d70aafc2e..0b8d8a45a08 100644 --- a/release/scripts/startup/bl_ui/properties_world.py +++ b/release/scripts/startup/bl_ui/properties_world.py @@ -82,6 +82,7 @@ class WORLD_PT_world(WorldButtonsPanel, Panel): def draw(self, context): layout = self.layout + world = context.world row = layout.row() @@ -111,6 +112,7 @@ class WORLD_PT_ambient_occlusion(WorldButtonsPanel, Panel): def draw(self, context): layout = self.layout + light = context.world.light_settings layout.active = light.use_ambient_occlusion @@ -130,6 +132,7 @@ class WORLD_PT_environment_lighting(WorldButtonsPanel, Panel): def draw(self, context): layout = self.layout + light = context.world.light_settings layout.active = light.use_environment_light @@ -149,6 +152,7 @@ class WORLD_PT_indirect_lighting(WorldButtonsPanel, Panel): def draw(self, context): layout = self.layout + light = context.world.light_settings layout.active = light.use_indirect_light and light.gather_method == 'APPROXIMATE' @@ -167,6 +171,7 @@ class WORLD_PT_gather(WorldButtonsPanel, Panel): def draw(self, context): layout = self.layout + light = context.world.light_settings layout.active = light.use_ambient_occlusion or light.use_environment_light or light.use_indirect_light @@ -221,6 +226,7 @@ class WORLD_PT_mist(WorldButtonsPanel, Panel): def draw(self, context): layout = self.layout + world = context.world layout.active = world.mist_settings.use_mist @@ -250,6 +256,7 @@ class WORLD_PT_stars(WorldButtonsPanel, Panel): def draw(self, context): layout = self.layout + world = context.world layout.active = world.star_settings.use_stars diff --git a/release/scripts/startup/bl_ui/space_clip.py b/release/scripts/startup/bl_ui/space_clip.py index ac724518e85..559cf7f93b7 100644 --- a/release/scripts/startup/bl_ui/space_clip.py +++ b/release/scripts/startup/bl_ui/space_clip.py @@ -115,11 +115,11 @@ class CLIP_HT_header(Header): sub.menu("CLIP_MT_view") if clip: - sub.menu("CLIP_MT_select") - sub.menu("CLIP_MT_clip") - sub.menu("CLIP_MT_mask") + sub.menu("MASK_MT_select") + sub.menu("CLIP_MT_clip") # XXX - remove? + sub.menu("MASK_MT_mask") else: - sub.menu("CLIP_MT_clip") + sub.menu("CLIP_MT_clip") # XXX - remove? row = layout.row() row.template_ID(sc, "clip", open="clip.open") @@ -161,16 +161,6 @@ class CLIP_PT_clip_view_panel: return clip and sc.view == 'CLIP' -class CLIP_PT_mask_view_panel: - - @classmethod - def poll(cls, context): - sc = context.space_data - clip = sc.clip - - return clip and sc.view == 'CLIP' and sc.mode == 'MASKEDIT' - - class CLIP_PT_tracking_panel: @classmethod @@ -197,10 +187,11 @@ class CLIP_PT_tools_marker(CLIP_PT_tracking_panel, Panel): bl_label = "Marker" def draw(self, context): + layout = self.layout + sc = context.space_data clip = sc.clip settings = clip.tracking.settings - layout = self.layout col = layout.column(align=True) col.operator("clip.add_marker_move") @@ -302,6 +293,7 @@ class CLIP_PT_tools_solve(CLIP_PT_tracking_panel, Panel): def draw(self, context): layout = self.layout + clip = context.space_data.clip tracking = clip.tracking settings = tracking.settings @@ -422,34 +414,6 @@ class CLIP_PT_tools_object(CLIP_PT_reconstruction_panel, Panel): col.prop(settings, "object_distance") -class CLIP_PT_tools_mask(CLIP_PT_mask_view_panel, Panel): - bl_space_type = 'CLIP_EDITOR' - bl_region_type = 'TOOLS' - bl_label = "Mask Tools" - - def draw(self, context): - layout = self.layout - - col = layout.column(align=True) - col.label(text="Transform:") - col.operator("transform.translate") - col.operator("transform.rotate") - col.operator("transform.resize", text="Scale") - props = col.operator("transform.transform", text="Shrink/Fatten") - props.mode = 'MASK_SHRINKFATTEN' - - col = layout.column(align=True) - col.label(text="Spline:") - col.operator("mask.delete") - col.operator("mask.cyclic_toggle") - col.operator("mask.switch_direction") - - col = layout.column(align=True) - col.label(text="Parenting:") - col.operator("mask.parent_set") - col.operator("mask.parent_clear") - - class CLIP_PT_tools_grease_pencil(Panel): bl_space_type = 'CLIP_EDITOR' bl_region_type = 'TOOLS' @@ -465,7 +429,7 @@ class CLIP_PT_tools_grease_pencil(Panel): if sc.mode == 'DISTORTION': return sc.view == 'CLIP' - elif sc.mode == 'MASKEDIT': + elif sc.mode == 'MASK': return True return False @@ -520,6 +484,7 @@ class CLIP_PT_track(CLIP_PT_tracking_panel, Panel): def draw(self, context): layout = self.layout + sc = context.space_data clip = context.space_data.clip act_track = clip.tracking.tracks.active @@ -586,6 +551,7 @@ class CLIP_PT_track_settings(CLIP_PT_tracking_panel, Panel): def draw(self, context): layout = self.layout + clip = context.space_data.clip settings = clip.tracking.settings @@ -661,136 +627,6 @@ class CLIP_PT_tracking_camera(Panel): col.prop(clip.tracking.camera, "k3") -class CLIP_PT_mask_layers(Panel): - bl_space_type = 'CLIP_EDITOR' - bl_region_type = 'UI' - bl_label = "Mask Layers" - - @classmethod - def poll(cls, context): - sc = context.space_data - - return sc.mask and sc.mode == 'MASKEDIT' - - def draw(self, context): - layout = self.layout - - sc = context.space_data - mask = sc.mask - active_layer = mask.layers.active - - rows = 5 if active_layer else 2 - - row = layout.row() - row.template_list(mask, "layers", - mask, "active_layer_index", rows=rows) - - sub = row.column(align=True) - - sub.operator("mask.layer_new", icon='ZOOMIN', text="") - sub.operator("mask.layer_remove", icon='ZOOMOUT', text="") - - if active_layer: - sub.separator() - - props = sub.operator("mask.layer_move", icon='TRIA_UP', text="") - props.direction = 'UP' - - props = sub.operator("mask.layer_move", icon='TRIA_DOWN', text="") - props.direction = 'DOWN' - - layout.prop(active_layer, "name") - - # blending - row = layout.row(align=True) - row.prop(active_layer, "alpha") - row.prop(active_layer, "invert", text="", icon='IMAGE_ALPHA') - - layout.prop(active_layer, "blend") - layout.prop(active_layer, "falloff") - - -class CLIP_PT_active_mask_spline(Panel): - bl_space_type = 'CLIP_EDITOR' - bl_region_type = 'UI' - bl_label = "Active Spline" - - @classmethod - def poll(cls, context): - sc = context.space_data - mask = sc.mask - - if mask and sc.mode == 'MASKEDIT': - return mask.layers.active and mask.layers.active.splines.active - - return False - - def draw(self, context): - layout = self.layout - - sc = context.space_data - mask = sc.mask - spline = mask.layers.active.splines.active - - col = layout.column() - col.prop(spline, "weight_interpolation") - rowsub = col.row() - rowsub.prop(spline, "use_cyclic") - rowsub.prop(spline, "use_fill") - - -class CLIP_PT_active_mask_point(Panel): - bl_space_type = 'CLIP_EDITOR' - bl_region_type = 'UI' - bl_label = "Active Point" - - @classmethod - def poll(cls, context): - sc = context.space_data - mask = sc.mask - - if mask and sc.mode == 'MASKEDIT': - mask_layer_active = mask.layers.active - return (mask_layer_active and - mask_layer_active.splines.active_point) - - return False - - def draw(self, context): - layout = self.layout - - sc = context.space_data - mask = sc.mask - point = mask.layers.active.splines.active_point - parent = point.parent - - col = layout.column() - col.prop(point, "handle_type") - - col = layout.column() - # Currently only parenting yo movie clip is allowed, so do not - # ver-oplicate things for now and use single template_ID - #col.template_any_ID(parent, "id", "id_type", text="") - - col.label("Parent:") - col.prop(parent, "id", text="") - - if parent.id_type == 'MOVIECLIP' and parent.id: - clip = parent.id - tracking = clip.tracking - - col.prop_search(parent, "parent", tracking, - "objects", icon='OBJECT_DATA', text="Object:") - - if parent.parent in tracking.objects: - object = tracking.objects[parent.parent] - col.prop_search(parent, "sub_parent", object, - "tracks", icon='ANIM_DATA', text="Track:") - else: - col.prop_search(parent, "sub_parent", tracking, - "tracks", icon='ANIM_DATA', text="Track:") - - class CLIP_PT_display(CLIP_PT_clip_view_panel, Panel): bl_space_type = 'CLIP_EDITOR' bl_region_type = 'UI' @@ -835,29 +671,6 @@ class CLIP_PT_display(CLIP_PT_clip_view_panel, Panel): row = col.row() row.prop(clip, "display_aspect", text="") - if sc.mode == 'MASKEDIT': - col = layout.column() - col.prop(sc, "mask_draw_type", text="") - col.prop(sc, "show_mask_smooth") - - -# TODO, move into its own file -class CLIP_PT_mask(CLIP_PT_mask_view_panel, Panel): - bl_space_type = 'CLIP_EDITOR' - bl_region_type = 'UI' - bl_label = "Mask Settings" - bl_options = {'DEFAULT_CLOSED'} - - def draw(self, context): - layout = self.layout - - sc = context.space_data - mask = sc.mask - - col = layout.column(align=True) - col.prop(mask, "frame_start") - col.prop(mask, "frame_end") - class CLIP_PT_marker_display(CLIP_PT_clip_view_panel, Panel): bl_space_type = 'CLIP_EDITOR' @@ -868,7 +681,7 @@ class CLIP_PT_marker_display(CLIP_PT_clip_view_panel, Panel): def poll(cls, context): sc = context.space_data - return sc.mode != 'MASKEDIT' + return sc.mode != 'MASK' def draw(self, context): layout = self.layout @@ -973,6 +786,7 @@ class CLIP_PT_proxy(CLIP_PT_clip_view_panel, Panel): def draw(self, context): layout = self.layout + sc = context.space_data clip = sc.clip @@ -1050,6 +864,7 @@ class CLIP_MT_view(Menu): def draw(self, context): layout = self.layout + sc = context.space_data if sc.view == 'CLIP': @@ -1213,30 +1028,18 @@ class CLIP_MT_select(Menu): def draw(self, context): layout = self.layout - sc = context.space_data - if sc.mode == 'MASKEDIT': - layout.operator("mask.select_border") - layout.operator("mask.select_circle") + layout.operator("clip.select_border") + layout.operator("clip.select_circle") - layout.separator() + layout.separator() - layout.operator("mask.select_all" - ).action = 'TOGGLE' - layout.operator("mask.select_all", - text="Inverse").action = 'INVERT' - else: - layout.operator("clip.select_border") - layout.operator("clip.select_circle") + layout.operator("clip.select_all" + ).action = 'TOGGLE' + layout.operator("clip.select_all", + text="Inverse").action = 'INVERT' - layout.separator() - - layout.operator("clip.select_all" - ).action = 'TOGGLE' - layout.operator("clip.select_all", - text="Inverse").action = 'INVERT' - - layout.menu("CLIP_MT_select_grouped") + layout.menu("CLIP_MT_select_grouped") class CLIP_MT_select_grouped(Menu): @@ -1280,30 +1083,6 @@ class CLIP_MT_tracking_specials(Menu): props.action = 'UNLOCK' -class CLIP_MT_mask(Menu): - bl_label = "Mask" - - def draw(self, context): - layout = self.layout - - layout.operator("mask.delete") - - layout.separator() - layout.operator("mask.cyclic_toggle") - layout.operator("mask.switch_direction") - layout.operator("mask.normals_make_consistent") - layout.operator("mask.feather_weight_clear") # TODO, better place? - - layout.separator() - layout.operator("mask.parent_clear") - layout.operator("mask.parent_set") - - layout.separator() - layout.menu("CLIP_MT_mask_visibility") - layout.menu("CLIP_MT_mask_transform") - layout.menu("CLIP_MT_mask_animation") - - class CLIP_MT_select_mode(Menu): bl_label = "Select Mode" @@ -1315,44 +1094,6 @@ class CLIP_MT_select_mode(Menu): layout.operator_enum("clip.mode_set", "mode") -class CLIP_MT_mask_visibility(Menu): - bl_label = "Show/Hide" - - def draw(self, context): - layout = self.layout - - layout.operator("mask.hide_view_clear", text="Show Hidden") - layout.operator("mask.hide_view_set", text="Hide Selected") - - props = layout.operator("mask.hide_view_set", text="Hide Unselected") - props.unselected = True - - -class CLIP_MT_mask_transform(Menu): - bl_label = "Transform" - - def draw(self, context): - layout = self.layout - - layout.operator("transform.translate") - layout.operator("transform.rotate") - layout.operator("transform.resize") - props = layout.operator("transform.transform", text="Shrink/Fatten") - props.mode = 'MASK_SHRINKFATTEN' - - -class CLIP_MT_mask_animation(Menu): - bl_label = "Animation" - - def draw(self, context): - layout = self.layout - - layout.operator("mask.shape_key_clear") - layout.operator("mask.shape_key_insert") - layout.operator("mask.shape_key_feather_reset") - layout.operator("mask.shape_key_rekey") - - class CLIP_MT_camera_presets(Menu): """Predefined tracking camera intrinsics""" bl_label = "Camera Presets" @@ -1394,5 +1135,49 @@ class CLIP_MT_stabilize_2d_specials(Menu): layout.operator("clip.stabilize_2d_select") + +# ----------------------------------------------------------------------------- +# Mask (similar code in space_image.py, keep in sync) + + +from bl_ui.properties_mask_common import (MASK_PT_mask, + MASK_PT_layers, + MASK_PT_spline, + MASK_PT_point, + MASK_PT_display, + MASK_PT_tools) + + +class CLIP_PT_mask(MASK_PT_mask, Panel): + bl_space_type = 'CLIP_EDITOR' + bl_region_type = 'UI' + + +class CLIP_PT_mask_layers(MASK_PT_layers, Panel): + bl_space_type = 'CLIP_EDITOR' + bl_region_type = 'UI' + + +class CLIP_PT_mask_display(MASK_PT_display, Panel): + bl_space_type = 'CLIP_EDITOR' + bl_region_type = 'UI' + + +class CLIP_PT_active_mask_spline(MASK_PT_spline, Panel): + bl_space_type = 'CLIP_EDITOR' + bl_region_type = 'UI' + + +class CLIP_PT_active_mask_point(MASK_PT_point, Panel): + bl_space_type = 'CLIP_EDITOR' + bl_region_type = 'UI' + + +class CLIP_PT_tools_mask(MASK_PT_tools, Panel): + bl_space_type = 'CLIP_EDITOR' + bl_region_type = 'TOOLS' + +# --- end mask --- + if __name__ == "__main__": # only for live edit. bpy.utils.register_module(__name__) diff --git a/release/scripts/startup/bl_ui/space_image.py b/release/scripts/startup/bl_ui/space_image.py index cfe5d66740c..7752eb9771a 100644 --- a/release/scripts/startup/bl_ui/space_image.py +++ b/release/scripts/startup/bl_ui/space_image.py @@ -27,7 +27,7 @@ class ImagePaintPanel(UnifiedPaintPanel): bl_region_type = 'UI' -class BrushButtonsPanel(): +class BrushButtonsPanel: bl_space_type = 'IMAGE_EDITOR' bl_region_type = 'UI' @@ -153,10 +153,6 @@ class IMAGE_MT_image(Menu): if ima.source in {'FILE', 'GENERATED'} and ima.type != 'OPEN_EXR_MULTILAYER': layout.operator("image.pack", text="Pack As PNG").as_png = True - if not context.tool_settings.use_uv_sculpt: - layout.separator() - layout.prop(sima, "use_image_paint") - layout.separator() @@ -217,6 +213,7 @@ class IMAGE_MT_uvs_snap(Menu): def draw(self, context): layout = self.layout + layout.operator_context = 'EXEC_REGION_WIN' layout.operator("uv.snap_selected", text="Selected to Pixels").target = 'PIXELS' @@ -234,6 +231,7 @@ class IMAGE_MT_uvs_mirror(Menu): def draw(self, context): layout = self.layout + layout.operator_context = 'EXEC_REGION_WIN' layout.operator("transform.mirror", text="X Axis").constraint_axis[0] = True @@ -353,10 +351,12 @@ class IMAGE_HT_header(Header): ima = sima.image iuser = sima.image_user toolsettings = context.tool_settings + mode = sima.mode show_render = sima.show_render # show_paint = sima.show_paint show_uvedit = sima.show_uvedit + show_maskedit = sima.show_maskedit row = layout.row(align=True) row.template_header() @@ -381,6 +381,8 @@ class IMAGE_HT_header(Header): if not show_render: layout.prop(sima, "use_image_pin", text="") + layout.prop(sima, "mode", text="") + # uv editing if show_uvedit: uvedit = sima.uv_editor @@ -406,13 +408,18 @@ class IMAGE_HT_header(Header): mesh = context.edit_object.data layout.prop_search(mesh.uv_textures, "active", mesh, "uv_textures", text="") + if show_maskedit: + row = layout.row() + row.template_ID(sima, "mask", new="mask.new") + + # reused for mask + uvedit = sima.uv_editor + layout.prop(uvedit, "pivot_point", text="", icon_only=True) + if ima: # layers layout.template_image_layers(ima, iuser) - # painting - layout.prop(sima, "use_image_paint", text="") - # draw options row = layout.row(align=True) row.prop(sima, "draw_channels", text="", expand=True) @@ -423,7 +430,7 @@ class IMAGE_HT_header(Header): if ima.type == 'COMPOSITE' and ima.source in {'MOVIE', 'SEQUENCE'}: row.operator("image.play_composite", icon='PLAY') - if show_uvedit or sima.use_image_paint: + if show_uvedit or mode == 'PAINT': layout.prop(sima, "use_realtime_update", text="", icon_only=True, icon='LOCKED') @@ -834,20 +841,57 @@ class IMAGE_UV_sculpt(Panel, ImagePaintPanel): self.prop_unified_strength(row, context, brush, "strength", slider=True, text="Strength") self.prop_unified_strength(row, context, brush, "use_pressure_strength") - split = layout.split() - col = split.column() - + col = layout.column() col.prop(toolsettings, "uv_sculpt_lock_borders") col.prop(toolsettings, "uv_sculpt_all_islands") - - split = layout.split() - col = split.column() - col.prop(toolsettings, "uv_sculpt_tool") if toolsettings.uv_sculpt_tool == 'RELAX': col.prop(toolsettings, "uv_relax_method") +# ----------------------------------------------------------------------------- +# Mask (similar code in space_clip.py, keep in sync) +# note! - panel placement does _not_ fit well with image panels... need to fix + +from bl_ui.properties_mask_common import (MASK_PT_mask, + MASK_PT_layers, + MASK_PT_spline, + MASK_PT_point, + MASK_PT_display, + MASK_PT_tools) + + +class IMAGE_PT_mask(MASK_PT_mask, Panel): + bl_space_type = 'IMAGE_EDITOR' + bl_region_type = 'PREVIEW' + + +class IMAGE_PT_mask_layers(MASK_PT_layers, Panel): + bl_space_type = 'IMAGE_EDITOR' + bl_region_type = 'PREVIEW' + + +class IMAGE_PT_mask_display(MASK_PT_display, Panel): + bl_space_type = 'IMAGE_EDITOR' + bl_region_type = 'PREVIEW' + + +class IMAGE_PT_active_mask_spline(MASK_PT_spline, Panel): + bl_space_type = 'IMAGE_EDITOR' + bl_region_type = 'PREVIEW' + + +class IMAGE_PT_active_mask_point(MASK_PT_point, Panel): + bl_space_type = 'IMAGE_EDITOR' + bl_region_type = 'PREVIEW' + + +class IMAGE_PT_tools_mask(MASK_PT_tools, Panel): + bl_space_type = 'IMAGE_EDITOR' + bl_region_type = 'UI' # is 'TOOLS' in the clip editor + +# --- end mask --- + if __name__ == "__main__": # only for live edit. bpy.utils.register_module(__name__) diff --git a/release/scripts/startup/bl_ui/space_node.py b/release/scripts/startup/bl_ui/space_node.py index 40c7b632247..e66d8f70c81 100644 --- a/release/scripts/startup/bl_ui/space_node.py +++ b/release/scripts/startup/bl_ui/space_node.py @@ -135,7 +135,8 @@ class NODE_MT_select(Menu): layout.operator("node.select_border") layout.separator() - layout.operator("node.select_all") + layout.operator("node.select_all").action = 'TOGGLE' + layout.operator("node.select_all", text="Inverse").action = 'INVERT' layout.operator("node.select_linked_from") layout.operator("node.select_linked_to") layout.operator("node.select_same_type") @@ -226,16 +227,21 @@ class NODE_PT_quality(bpy.types.Panel): def draw(self, context): layout = self.layout + snode = context.space_data tree = snode.node_tree - layout.prop(tree, "render_quality", text="Render") - layout.prop(tree, "edit_quality", text="Edit") - layout.prop(tree, "chunk_size") - layout.prop(tree, "use_opencl") - layout.prop(tree, "two_pass") - layout.prop(snode, "show_highlight") - + col = layout.column() + col.prop(tree, "render_quality", text="Render") + col.prop(tree, "edit_quality", text="Edit") + col.prop(tree, "chunk_size") + + col = layout.column() + col.prop(tree, "use_opencl") + col.prop(tree, "two_pass") + col.prop(snode, "show_highlight") + col.prop(snode, "use_hidden_preview") + class NODE_MT_node_color_presets(Menu): """Predefined node color""" diff --git a/release/scripts/startup/bl_ui/space_sequencer.py b/release/scripts/startup/bl_ui/space_sequencer.py index a71a2870bee..d099db1645b 100644 --- a/release/scripts/startup/bl_ui/space_sequencer.py +++ b/release/scripts/startup/bl_ui/space_sequencer.py @@ -184,6 +184,7 @@ class SEQUENCER_MT_add(Menu): def draw(self, context): layout = self.layout + layout.operator_context = 'INVOKE_REGION_WIN' if len(bpy.data.scenes) > 10: @@ -216,6 +217,7 @@ class SEQUENCER_MT_add_effect(Menu): def draw(self, context): layout = self.layout + layout.operator_context = 'INVOKE_REGION_WIN' layout.operator("sequencer.effect_strip_add", text="Add").type = 'ADD' @@ -834,6 +836,7 @@ class SEQUENCER_PT_preview(SequencerButtonsPanel_Output, Panel): def draw(self, context): layout = self.layout + render = context.scene.render col = layout.column() diff --git a/release/scripts/startup/bl_ui/space_text.py b/release/scripts/startup/bl_ui/space_text.py index 9c24e48300a..eca9bc22db9 100644 --- a/release/scripts/startup/bl_ui/space_text.py +++ b/release/scripts/startup/bl_ui/space_text.py @@ -302,6 +302,7 @@ class TEXT_MT_toolbox(Menu): def draw(self, context): layout = self.layout + layout.operator_context = 'INVOKE_DEFAULT' layout.operator("text.cut") diff --git a/release/scripts/startup/bl_ui/space_time.py b/release/scripts/startup/bl_ui/space_time.py index 0f573c46d69..ed1d2a0ae24 100644 --- a/release/scripts/startup/bl_ui/space_time.py +++ b/release/scripts/startup/bl_ui/space_time.py @@ -160,8 +160,7 @@ class TIME_MT_frame(Menu): layout.separator() - sub = layout.row() - sub.menu("TIME_MT_autokey") + layout.menu("TIME_MT_autokey") class TIME_MT_playback(Menu): diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py index 66382e72a4d..e443c7804a6 100644 --- a/release/scripts/startup/bl_ui/space_userpref.py +++ b/release/scripts/startup/bl_ui/space_userpref.py @@ -79,6 +79,7 @@ class USERPREF_HT_header(Header): def draw(self, context): layout = self.layout + layout.template_header(menus=False) userpref = context.user_preferences @@ -137,6 +138,7 @@ class USERPREF_MT_splash(Menu): def draw(self, context): layout = self.layout + split = layout.split() row = split.row() row.label("") @@ -850,6 +852,7 @@ class USERPREF_MT_ndof_settings(Menu): def draw(self, context): layout = self.layout + input_prefs = context.user_preferences.inputs layout.separator() @@ -979,6 +982,7 @@ class USERPREF_MT_addons_dev_guides(Menu): # menu to open web-pages with addons development guides def draw(self, context): layout = self.layout + layout.operator("wm.url_open", text="API Concepts", icon='URL').url = "http://wiki.blender.org/index.php/Dev:2.5/Py/API/Intro" layout.operator("wm.url_open", text="Addon Guidelines", icon='URL').url = "http://wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Guidelines/Addons" layout.operator("wm.url_open", text="How to share your addon", icon='URL').url = "http://wiki.blender.org/index.php/Dev:Py/Sharing" @@ -1004,10 +1008,10 @@ class USERPREF_PT_addons(Panel): @staticmethod def is_user_addon(mod, user_addon_paths): if not user_addon_paths: - user_script_path = bpy.utils.user_script_path() - if user_script_path is not None: - user_addon_paths.append(os.path.join(user_script_path, "addons")) - user_addon_paths.append(os.path.join(bpy.utils.resource_path('USER'), "scripts", "addons")) + for path in (bpy.utils.script_path_user(), + bpy.utils.script_path_pref()): + if path is not None: + user_addon_paths.append(os.path.join(path, "addons")) for path in user_addon_paths: if bpy.path.is_subdir(mod.__file__, path): diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py index 16f84414695..f3050fb8a9f 100644 --- a/release/scripts/startup/bl_ui/space_view3d.py +++ b/release/scripts/startup/bl_ui/space_view3d.py @@ -64,28 +64,29 @@ class VIEW3D_HT_header(Header): layout.template_header_3D() if obj: + mode = obj.mode # Particle edit - if obj.mode == 'PARTICLE_EDIT': + if mode == 'PARTICLE_EDIT': row.prop(toolsettings.particle_edit, "select_mode", text="", expand=True) # Occlude geometry - if view.viewport_shade not in {'BOUNDBOX', 'WIREFRAME'} and (obj.mode == 'PARTICLE_EDIT' or (obj.mode == 'EDIT' and obj.type == 'MESH')): + if view.viewport_shade not in {'BOUNDBOX', 'WIREFRAME'} and (mode == 'PARTICLE_EDIT' or (mode == 'EDIT' and obj.type == 'MESH')): row.prop(view, "use_occlude_geometry", text="") # Proportional editing - if obj.mode in {'EDIT', 'PARTICLE_EDIT'}: + if mode in {'EDIT', 'PARTICLE_EDIT'}: row = layout.row(align=True) row.prop(toolsettings, "proportional_edit", text="", icon_only=True) if toolsettings.proportional_edit != 'DISABLED': row.prop(toolsettings, "proportional_edit_falloff", text="", icon_only=True) - elif obj.mode == 'OBJECT': + elif mode == 'OBJECT': row = layout.row(align=True) row.prop(toolsettings, "use_proportional_edit_objects", text="", icon_only=True) if toolsettings.use_proportional_edit_objects: row.prop(toolsettings, "proportional_edit_falloff", text="", icon_only=True) # Snap - if not obj or obj.mode not in {'SCULPT', 'VERTEX_PAINT', 'WEIGHT_PAINT', 'TEXTURE_PAINT'}: + if not obj or mode not in {'SCULPT', 'VERTEX_PAINT', 'WEIGHT_PAINT', 'TEXTURE_PAINT'}: snap_element = toolsettings.snap_element row = layout.row(align=True) row.prop(toolsettings, "use_snap", text="") @@ -93,9 +94,9 @@ 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 mode in {'OBJECT', 'POSE'} and snap_element != 'VOLUME': row.prop(toolsettings, "use_snap_align_rotation", text="") - elif obj.mode == 'EDIT': + elif mode == 'EDIT': row.prop(toolsettings, "use_snap_self", text="") if snap_element == 'VOLUME': @@ -110,7 +111,7 @@ class VIEW3D_HT_header(Header): props.animation = True # Pose - if obj and obj.mode == 'POSE': + if obj and mode == 'POSE': row = layout.row(align=True) row.operator("pose.copy", text="", icon='COPYDOWN') row.operator("pose.paste", text="", icon='PASTEDOWN') @@ -176,11 +177,12 @@ class VIEW3D_MT_transform(VIEW3D_MT_transform_base): # Object-specific extensions to Transform menu class VIEW3D_MT_transform_object(VIEW3D_MT_transform_base): def draw(self, context): + layout = self.layout + # 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 @@ -212,11 +214,12 @@ class VIEW3D_MT_transform_object(VIEW3D_MT_transform_base): # Armature EditMode extensions to Transform menu class VIEW3D_MT_transform_armature(VIEW3D_MT_transform_base): def draw(self, context): + layout = self.layout + # base menu VIEW3D_MT_transform_base.draw(self, context) # armature specific extensions follow... - layout = self.layout layout.separator() obj = context.object @@ -429,18 +432,23 @@ class VIEW3D_MT_view_align_selected(Menu): props = layout.operator("view3d.viewnumpad", text="Top") props.align_active = True props.type = 'TOP' + props = layout.operator("view3d.viewnumpad", text="Bottom") props.align_active = True props.type = 'BOTTOM' + props = layout.operator("view3d.viewnumpad", text="Front") props.align_active = True props.type = 'FRONT' + props = layout.operator("view3d.viewnumpad", text="Back") props.align_active = True props.type = 'BACK' + props = layout.operator("view3d.viewnumpad", text="Right") props.align_active = True props.type = 'RIGHT' + props = layout.operator("view3d.viewnumpad", text="Left") props.align_active = True props.type = 'LEFT' @@ -1191,6 +1199,7 @@ class VIEW3D_MT_vertex_group(Menu): def draw(self, context): layout = self.layout + layout.operator_context = 'EXEC_AREA' layout.operator("object.vertex_group_assign", text="Assign to New Group").new = True @@ -1349,6 +1358,7 @@ class VIEW3D_MT_particle_specials(Menu): def draw(self, context): layout = self.layout + particle_edit = context.tool_settings.particle_edit layout.operator("particle.rekey") @@ -1792,6 +1802,7 @@ class VIEW3D_MT_edit_mesh_edges(Menu): def draw(self, context): layout = self.layout + layout.operator_context = 'INVOKE_REGION_WIN' layout.operator("mesh.edge_face_add") @@ -1844,6 +1855,7 @@ class VIEW3D_MT_edit_mesh_faces(Menu): def draw(self, context): layout = self.layout + layout.operator_context = 'INVOKE_REGION_WIN' layout.operator("mesh.flip_normals") @@ -2644,6 +2656,7 @@ class VIEW3D_PT_etch_a_ton(Panel): def draw(self, context): layout = self.layout + toolsettings = context.scene.tool_settings col = layout.column() diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py index f3365da6ad6..ac962ab5097 100644 --- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py +++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py @@ -1124,6 +1124,7 @@ class VIEW3D_MT_tools_projectpaint_clone(Menu): def draw(self, context): layout = self.layout + for i, tex in enumerate(context.active_object.data.uv_textures): props = layout.operator("wm.context_set_int", text=tex.name) props.data_path = "active_object.data.uv_texture_clone_index" diff --git a/release/scripts/templates/ui_panel.py b/release/scripts/templates/ui_panel.py new file mode 100644 index 00000000000..095fa105efa --- /dev/null +++ b/release/scripts/templates/ui_panel.py @@ -0,0 +1,56 @@ +import bpy + + +class LayoutDemoPanel(bpy.types.Panel): + """Creates a Panel in the scene context of the properties editor""" + bl_label = "Layout Demo" + bl_idname = "SCENE_PT_layout" + bl_space_type = 'PROPERTIES' + bl_region_type = 'WINDOW' + bl_context = "scene" + + def draw(self, context): + layout = self.layout + + sc = context.scene + + #Create a simple row. + layout.label(text=" Simple Row:") + + row = layout.row() + row.prop(sc, "frame_start") + row.prop(sc, "frame_end") + + #Create an row where the buttons are aligned to each other. + layout.label(text=" Aligned Row") + + row = layout.row(align=True) + row.prop(sc, "frame_start") + row.prop(sc, "frame_end") + + #Create two columns, by using a split layout. + split = layout.split() + + # First column + col = split.column() + col.label(text="Column One:") + col.prop(sc, "frame_end") + col.prop(sc, "frame_start") + + # Second column, aligned + col = split.column(align=True) + col.label(text="Column Two") + col.prop(sc, "frame_start") + col.prop(sc, "frame_end") + + +def register(): + bpy.utils.register_class(LayoutDemoPanel) + + +def unregister(): + bpy.utils.unregister_class(LayoutDemoPanel) + + +if __name__ == "__main__": + register() diff --git a/source/blender/avi/intern/avi.c b/source/blender/avi/intern/avi.c index cceba82aca7..1c79c9b4237 100644 --- a/source/blender/avi/intern/avi.c +++ b/source/blender/avi/intern/avi.c @@ -857,9 +857,9 @@ AviError AVI_open_compress(char *name, AviMovie *movie, int streams, ...) #if 0 if (movie->streams[i].format == AVI_FORMAT_MJPEG) { AviMJPEGUnknown *tmp; - - tmp = (AviMJPEGUnknown *) ((char*) movie->streams[i].sf +sizeof(AviBitmapInfoHeader)); - + + tmp = (AviMJPEGUnknown *)((char *) movie->streams[i].sf + sizeof(AviBitmapInfoHeader)); + tmp->a = 44; tmp->b = 24; tmp->c = 0; @@ -965,11 +965,15 @@ AviError AVI_write_frame(AviMovie *movie, int frame_num, ...) /* Allocate the new memory for the index entry */ if (frame_num + 1 > movie->index_entries) { - temp = (AviIndexEntry *) MEM_mallocN((frame_num + 1) * - (movie->header->Streams + 1) * sizeof(AviIndexEntry), "newidxentry"); + const size_t entry_size = (movie->header->Streams + 1) * sizeof(AviIndexEntry); + if (movie->entries != NULL) { - memcpy(temp, movie->entries, movie->index_entries * (movie->header->Streams + 1) * sizeof(AviIndexEntry)); - MEM_freeN(movie->entries); + temp = (AviIndexEntry *)MEM_reallocN(movie->entries, (frame_num + 1) * entry_size); + /* clear new bytes */ + memset(&temp[movie->index_entries], 0, ((frame_num + 1) - movie->index_entries) * entry_size); + } + else { + temp = (AviIndexEntry *) MEM_callocN((frame_num + 1) * entry_size, "newidxentry"); } movie->entries = temp; diff --git a/source/blender/blenfont/intern/blf_lang.c b/source/blender/blenfont/intern/blf_lang.c index 9e8884ad94d..b37180d499c 100644 --- a/source/blender/blenfont/intern/blf_lang.c +++ b/source/blender/blenfont/intern/blf_lang.c @@ -82,7 +82,7 @@ static const char *locales[] = { "spanish", "es", "catalan", "ca_AD", "czech", "cs_CZ", - "ptb", "pt", + "portuguese", "pt", #if defined(_WIN32) && !defined(FREE_WINDOWS) "Chinese (Simplified)_China.1252", "zh_CN", "Chinese (Traditional)_China.1252", "zh_TW", diff --git a/source/blender/blenkernel/BKE_blender.h b/source/blender/blenkernel/BKE_blender.h index 48c7103d8fd..0c09c24e709 100644 --- a/source/blender/blenkernel/BKE_blender.h +++ b/source/blender/blenkernel/BKE_blender.h @@ -42,7 +42,7 @@ extern "C" { * and keep comment above the defines. * Use STRINGIFY() rather than defining with quotes */ #define BLENDER_VERSION 263 -#define BLENDER_SUBVERSION 14 +#define BLENDER_SUBVERSION 17 #define BLENDER_MINVERSION 250 #define BLENDER_MINSUBVERSION 0 diff --git a/source/blender/blenkernel/BKE_cdderivedmesh.h b/source/blender/blenkernel/BKE_cdderivedmesh.h index eeebcdafe48..d7882d8e7ec 100644 --- a/source/blender/blenkernel/BKE_cdderivedmesh.h +++ b/source/blender/blenkernel/BKE_cdderivedmesh.h @@ -61,12 +61,14 @@ DerivedMesh *CDDM_from_BMEditMesh(struct BMEditMesh *em, struct Mesh *me, int us /* merge verts */ DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap); +DerivedMesh *CDDM_from_curve_orco(struct Scene *scene, struct Object *ob); + /* creates a CDDerivedMesh from the given curve object */ struct DerivedMesh *CDDM_from_curve(struct Object *ob); /* creates a CDDerivedMesh from the given curve object and specified dispbase */ /* useful for OrcoDM creation for curves with constructive modifiers */ -DerivedMesh *CDDM_from_curve_displist(struct Object *ob, struct ListBase *dispbase); +DerivedMesh *CDDM_from_curve_displist(struct Object *ob, struct ListBase *dispbase, int **orco_index_ptr); /* Copies the given DerivedMesh with verts, faces & edges stored as * custom element data. diff --git a/source/blender/blenkernel/BKE_mask.h b/source/blender/blenkernel/BKE_mask.h index 9a4f30c853f..1148cffffb4 100644 --- a/source/blender/blenkernel/BKE_mask.h +++ b/source/blender/blenkernel/BKE_mask.h @@ -122,12 +122,16 @@ void BKE_mask_point_select_set_handle(struct MaskSplinePoint *point, const short /* general */ struct Mask *BKE_mask_new(const char *name); +struct Mask *BKE_mask_copy_nolib(struct Mask *mask); +struct Mask *BKE_mask_copy(struct Mask *mask); void BKE_mask_free(struct Mask *mask); void BKE_mask_unlink(struct Main *bmain, struct Mask *mask); void BKE_mask_coord_from_movieclip(struct MovieClip *clip, struct MovieClipUser *user, float r_co[2], const float co[2]); +void BKE_mask_coord_from_frame(float r_co[2], const float co[2], const float frame_size[2]); void BKE_mask_coord_to_movieclip(struct MovieClip *clip, struct MovieClipUser *user, float r_co[2], const float co[2]); +void BKE_mask_coord_to_frame(float r_co[2], const float co[2], const float frame_size[2]); /* parenting */ @@ -181,23 +185,8 @@ void BKE_mask_layer_shape_changed_add(struct MaskLayer *masklay, int index, void BKE_mask_layer_shape_changed_remove(struct MaskLayer *masklay, int index, int count); -/* rasterization */ int BKE_mask_get_duration(struct Mask *mask); -void BKE_mask_rasterize_layers(struct ListBase *masklayers, int width, int height, float *buffer, - const short do_aspect_correct, const short do_mask_aa, - const short do_feather); - -void BKE_mask_rasterize(struct Mask *mask, int width, int height, float *buffer, - const short do_aspect_correct, const short do_mask_aa, - const short do_feather); - -/* initialization for tiling */ -#ifdef __PLX_RASKTER_MT__ -void BKE_mask_init_layers(Mask *mask, struct layer_init_data *mlayer_data, int width, int height, - const short do_aspect_correct); -#endif - #define MASKPOINT_ISSEL_ANY(p) ( ((p)->bezt.f1 | (p)->bezt.f2 | (p)->bezt.f2) & SELECT) #define MASKPOINT_ISSEL_KNOT(p) ( (p)->bezt.f2 & SELECT) #define MASKPOINT_ISSEL_HANDLE_ONLY(p) ( (((p)->bezt.f1 | (p)->bezt.f2) & SELECT) && (((p)->bezt.f2 & SELECT) == 0) ) @@ -210,11 +199,9 @@ void BKE_mask_init_layers(Mask *mask, struct layer_init_data *mlayer_data, int w #define MASKPOINT_SEL_HANDLE(p) { (p)->bezt.f1 |= SELECT; (p)->bezt.f3 |= SELECT; } (void)0 #define MASKPOINT_DESEL_HANDLE(p) { (p)->bezt.f1 &= ~SELECT; (p)->bezt.f3 &= ~SELECT; } (void)0 -/* disable to test alternate rasterizer */ -/* #define USE_RASKTER */ +#define MASK_RESOL_MAX 128 /* mask_rasterize.c */ -#ifndef USE_RASKTER struct MaskRasterHandle; typedef struct MaskRasterHandle MaskRasterHandle; @@ -225,6 +212,9 @@ void BKE_maskrasterize_handle_init(MaskRasterHandle *mr_handle, str const short do_aspect_correct, const short do_mask_aa, const short do_feather); float BKE_maskrasterize_handle_sample(MaskRasterHandle *mr_handle, const float xy[2]); -#endif /* USE_RASKTER */ + +void BKE_maskrasterize_buffer(MaskRasterHandle *mr_handle, + const unsigned int width, const unsigned int height, + float *buffer); #endif /* __BKE_MASK_H__ */ diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h index 6fac915d520..954fb47806b 100644 --- a/source/blender/blenkernel/BKE_mesh.h +++ b/source/blender/blenkernel/BKE_mesh.h @@ -143,9 +143,13 @@ int BKE_mesh_nurbs_to_mdata(struct Object *ob, struct MVert **allvert, int *tot int *totloop, int *totpoly); int BKE_mesh_nurbs_displist_to_mdata(struct Object *ob, struct ListBase *dispbase, struct MVert **allvert, int *_totvert, struct MEdge **alledge, int *_totedge, struct MLoop **allloop, struct MPoly **allpoly, - int *_totloop, int *_totpoly); + int *_totloop, int *_totpoly, int **orco_index_ptr); +void BKE_mesh_nurbs_to_mdata_orco(struct MPoly *mpoly, int totpoly, + struct MLoop *mloops, struct MLoopUV *mloopuvs, + float (*orco)[3], int (*orco_index)[4]); void BKE_mesh_from_nurbs(struct Object *ob); -void BKE_mesh_from_nurbs_displist(struct Object *ob, struct ListBase *dispbase); +void BKE_mesh_from_nurbs_displist(struct Object *ob, struct ListBase *dispbase, + int **orco_index_ptr); void BKE_mesh_from_curve(struct Scene *scene, struct Object *ob); void free_dverts(struct MDeformVert *dvert, int totvert); void copy_dverts(struct MDeformVert *dst, struct MDeformVert *src, int totvert); /* __NLA */ @@ -157,8 +161,8 @@ void BKE_mesh_convert_mfaces_to_mpolys_ex(struct ID *id, struct CustomData *fdata, struct CustomData *ldata, struct CustomData *pdata, int totedge_i, int totface_i, int totloop_i, int totpoly_i, struct MEdge *medge, struct MFace *mface, - int *totloop_r, int *totpoly_r, - struct MLoop **mloop_r, struct MPoly **mpoly_r); + int *totloop_r, int *totpoly_r, + struct MLoop **mloop_r, struct MPoly **mpoly_r); void BKE_mesh_calc_normals_tessface(struct MVert *mverts, int numVerts, struct MFace *mfaces, int numFaces, float (*faceNors_r)[3]); diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 7bd9f75b2dd..93b5e748987 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -88,8 +88,8 @@ typedef struct bNodeSocketTemplate { } bNodeSocketTemplate; typedef void (*NodeSocketButtonFunction)(const struct bContext *C, struct uiBlock *block, - struct bNodeTree *ntree, struct bNode *node, struct bNodeSocket *sock, - const char *name, int x, int y, int width); + struct bNodeTree *ntree, struct bNode *node, struct bNodeSocket *sock, + const char *name, int x, int y, int width); /** Defines a socket type. * Defines the appearance and behavior of a socket in the UI. @@ -301,36 +301,36 @@ struct bNodeType *ntreeGetNodeType(struct bNodeTree *ntree); struct bNodeSocketType *ntreeGetSocketType(int type); struct bNodeTree *ntreeAddTree(const char *name, int type, int nodetype); -void ntreeInitTypes(struct bNodeTree *ntree); +void ntreeInitTypes(struct bNodeTree *ntree); -void ntreeFreeTree(struct bNodeTree *ntree); +void ntreeFreeTree(struct bNodeTree *ntree); struct bNodeTree *ntreeCopyTree(struct bNodeTree *ntree); -void ntreeSwitchID(struct bNodeTree *ntree, struct ID *sce_from, struct ID *sce_to); -void ntreeMakeLocal(struct bNodeTree *ntree); -int ntreeHasType(struct bNodeTree *ntree, int type); +void ntreeSwitchID(struct bNodeTree *ntree, struct ID *sce_from, struct ID *sce_to); +void ntreeMakeLocal(struct bNodeTree *ntree); +int ntreeHasType(struct bNodeTree *ntree, int type); -void ntreeUpdateTree(struct bNodeTree *ntree); +void ntreeUpdateTree(struct bNodeTree *ntree); /* XXX Currently each tree update call does call to ntreeVerifyNodes too. * Some day this should be replaced by a decent depsgraph automatism! */ -void ntreeVerifyNodes(struct Main *main, struct ID *id); +void ntreeVerifyNodes(struct Main *main, struct ID *id); -void ntreeGetDependencyList(struct bNodeTree *ntree, struct bNode ***deplist, int *totnodes); +void ntreeGetDependencyList(struct bNodeTree *ntree, struct bNode ***deplist, int *totnodes); /* XXX old trees handle output flags automatically based on special output node types and last active selection. * new tree types have a per-output socket flag to indicate the final output to use explicitly. */ -void ntreeSetOutput(struct bNodeTree *ntree); -void ntreeInitPreview(struct bNodeTree *, int xsize, int ysize); -void ntreeClearPreview(struct bNodeTree *ntree); +void ntreeSetOutput(struct bNodeTree *ntree); +void ntreeInitPreview(struct bNodeTree *, int xsize, int ysize); +void ntreeClearPreview(struct bNodeTree *ntree); -void ntreeFreeCache(struct bNodeTree *ntree); +void ntreeFreeCache(struct bNodeTree *ntree); -int ntreeNodeExists(struct bNodeTree *ntree, struct bNode *testnode); -int ntreeOutputExists(struct bNode *node, struct bNodeSocket *testsock); +int ntreeNodeExists(struct bNodeTree *ntree, struct bNode *testnode); +int ntreeOutputExists(struct bNode *node, struct bNodeSocket *testsock); struct bNodeTree *ntreeLocalize(struct bNodeTree *ntree); -void ntreeLocalSync(struct bNodeTree *localtree, struct bNodeTree *ntree); -void ntreeLocalMerge(struct bNodeTree *localtree, struct bNodeTree *ntree); +void ntreeLocalSync(struct bNodeTree *localtree, struct bNodeTree *ntree); +void ntreeLocalMerge(struct bNodeTree *localtree, struct bNodeTree *ntree); /* ************** GENERIC API, NODES *************** */ @@ -339,98 +339,98 @@ struct bNodeSocket *nodeInsertSocket(struct bNodeTree *ntree, struct bNode *node void nodeRemoveSocket(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocket *sock); void nodeRemoveAllSockets(struct bNodeTree *ntree, struct bNode *node); -void nodeAddToPreview(struct bNode *node, float col[4], int x, int y, int do_manage); +void nodeAddToPreview(struct bNode *node, float col[4], int x, int y, int do_manage); struct bNode *nodeAddNode(struct bNodeTree *ntree, struct bNodeTemplate *ntemp); -void nodeUnlinkNode(struct bNodeTree *ntree, struct bNode *node); -void nodeUniqueName(struct bNodeTree *ntree, struct bNode *node); +void nodeUnlinkNode(struct bNodeTree *ntree, struct bNode *node); +void nodeUniqueName(struct bNodeTree *ntree, struct bNode *node); -void nodeRegisterType(struct bNodeTreeType *ttype, struct bNodeType *ntype); -void nodeMakeDynamicType(struct bNode *node); -int nodeDynamicUnlinkText(struct ID *txtid); +void nodeRegisterType(struct bNodeTreeType *ttype, struct bNodeType *ntype); +void nodeMakeDynamicType(struct bNode *node); +int nodeDynamicUnlinkText(struct ID *txtid); -void nodeFreeNode(struct bNodeTree *ntree, struct bNode *node); +void nodeFreeNode(struct bNodeTree *ntree, struct bNode *node); struct bNode *nodeCopyNode(struct bNodeTree *ntree, struct bNode *node); struct bNodeLink *nodeAddLink(struct bNodeTree *ntree, struct bNode *fromnode, struct bNodeSocket *fromsock, struct bNode *tonode, struct bNodeSocket *tosock); -void nodeRemLink(struct bNodeTree *ntree, struct bNodeLink *link); -void nodeRemSocketLinks(struct bNodeTree *ntree, struct bNodeSocket *sock); -void nodeInternalRelink(struct bNodeTree *ntree, struct bNode *node); +void nodeRemLink(struct bNodeTree *ntree, struct bNodeLink *link); +void nodeRemSocketLinks(struct bNodeTree *ntree, struct bNodeSocket *sock); +void nodeInternalRelink(struct bNodeTree *ntree, struct bNode *node); -void nodeToView(struct bNode *node, float x, float y, float *rx, float *ry); -void nodeFromView(struct bNode *node, float x, float y, float *rx, float *ry); -void nodeAttachNode(struct bNode *node, struct bNode *parent); -void nodeDetachNode(struct bNode *node); +void nodeToView(struct bNode *node, float x, float y, float *rx, float *ry); +void nodeFromView(struct bNode *node, float x, float y, float *rx, float *ry); +void nodeAttachNode(struct bNode *node, struct bNode *parent); +void nodeDetachNode(struct bNode *node); -struct bNode *nodeFindNodebyName(struct bNodeTree *ntree, const char *name); -int nodeFindNode(struct bNodeTree *ntree, struct bNodeSocket *sock, struct bNode **nodep, int *sockindex, int *in_out); +struct bNode *nodeFindNodebyName(struct bNodeTree *ntree, const char *name); +int nodeFindNode(struct bNodeTree *ntree, struct bNodeSocket *sock, struct bNode **nodep, int *sockindex, int *in_out); struct bNodeLink *nodeFindLink(struct bNodeTree *ntree, struct bNodeSocket *from, struct bNodeSocket *to); -int nodeCountSocketLinks(struct bNodeTree *ntree, struct bNodeSocket *sock); +int nodeCountSocketLinks(struct bNodeTree *ntree, struct bNodeSocket *sock); -void nodeSetActive(struct bNodeTree *ntree, struct bNode *node); -struct bNode *nodeGetActive(struct bNodeTree *ntree); -struct bNode *nodeGetActiveID(struct bNodeTree *ntree, short idtype); -int nodeSetActiveID(struct bNodeTree *ntree, short idtype, struct ID *id); -void nodeClearActive(struct bNodeTree *ntree); -void nodeClearActiveID(struct bNodeTree *ntree, short idtype); -struct bNode *nodeGetActiveTexture(struct bNodeTree *ntree); +void nodeSetActive(struct bNodeTree *ntree, struct bNode *node); +struct bNode *nodeGetActive(struct bNodeTree *ntree); +struct bNode *nodeGetActiveID(struct bNodeTree *ntree, short idtype); +int nodeSetActiveID(struct bNodeTree *ntree, short idtype, struct ID *id); +void nodeClearActive(struct bNodeTree *ntree); +void nodeClearActiveID(struct bNodeTree *ntree, short idtype); +struct bNode *nodeGetActiveTexture(struct bNodeTree *ntree); -void nodeUpdate(struct bNodeTree *ntree, struct bNode *node); -int nodeUpdateID(struct bNodeTree *ntree, struct ID *id); +void nodeUpdate(struct bNodeTree *ntree, struct bNode *node); +int nodeUpdateID(struct bNodeTree *ntree, struct ID *id); -void nodeFreePreview(struct bNode *node); +void nodeFreePreview(struct bNode *node); -int nodeSocketIsHidden(struct bNodeSocket *sock); -void nodeSocketSetType(struct bNodeSocket *sock, int type); +int nodeSocketIsHidden(struct bNodeSocket *sock); +void nodeSocketSetType(struct bNodeSocket *sock, int type); /* ************** NODE TYPE ACCESS *************** */ struct bNodeTemplate nodeMakeTemplate(struct bNode *node); -int nodeValid(struct bNodeTree *ntree, struct bNodeTemplate *ntemp); -const char* nodeLabel(struct bNode *node); +int nodeValid(struct bNodeTree *ntree, struct bNodeTemplate *ntemp); +const char *nodeLabel(struct bNode *node); struct bNodeTree *nodeGroupEditGet(struct bNode *node); struct bNodeTree *nodeGroupEditSet(struct bNode *node, int edit); -void nodeGroupEditClear(struct bNode *node); +void nodeGroupEditClear(struct bNode *node); /* Init a new node type struct with default values and callbacks */ -void node_type_base(struct bNodeTreeType *ttype, struct bNodeType *ntype, int type, +void node_type_base(struct bNodeTreeType *ttype, struct bNodeType *ntype, int type, const char *name, short nclass, short flag); -void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs); -void node_type_size(struct bNodeType *ntype, int width, int minwidth, int maxwidth); -void node_type_init(struct bNodeType *ntype, void (*initfunc)(struct bNodeTree *ntree, struct bNode *node, struct bNodeTemplate *ntemp)); -void node_type_valid(struct bNodeType *ntype, int (*validfunc)(struct bNodeTree *ntree, struct bNodeTemplate *ntemp)); -void node_type_storage(struct bNodeType *ntype, - const char *storagename, - void (*freestoragefunc)(struct bNode *), - void (*copystoragefunc)(struct bNode *, struct bNode *)); -void node_type_label(struct bNodeType *ntype, const char *(*labelfunc)(struct bNode *)); -void node_type_template(struct bNodeType *ntype, struct bNodeTemplate (*templatefunc)(struct bNode *)); -void node_type_update(struct bNodeType *ntype, - void (*updatefunc)(struct bNodeTree *ntree, struct bNode *node), - void (*verifyfunc)(struct bNodeTree *ntree, struct bNode *node, struct ID *id)); -void node_type_tree(struct bNodeType *ntype, - void (*inittreefunc)(struct bNodeTree *), - void (*updatetreefunc)(struct bNodeTree *)); -void node_type_group_edit(struct bNodeType *ntype, - struct bNodeTree *(*group_edit_get)(struct bNode *node), - struct bNodeTree *(*group_edit_set)(struct bNode *node, int edit), - void (*group_edit_clear)(struct bNode *node)); +void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs); +void node_type_size(struct bNodeType *ntype, int width, int minwidth, int maxwidth); +void node_type_init(struct bNodeType *ntype, void (*initfunc)(struct bNodeTree *ntree, struct bNode *node, struct bNodeTemplate *ntemp)); +void node_type_valid(struct bNodeType *ntype, int (*validfunc)(struct bNodeTree *ntree, struct bNodeTemplate *ntemp)); +void node_type_storage(struct bNodeType *ntype, + const char *storagename, + void (*freestoragefunc)(struct bNode *), + void (*copystoragefunc)(struct bNode *, struct bNode *)); +void node_type_label(struct bNodeType *ntype, const char *(*labelfunc)(struct bNode *)); +void node_type_template(struct bNodeType *ntype, struct bNodeTemplate (*templatefunc)(struct bNode *)); +void node_type_update(struct bNodeType *ntype, + void (*updatefunc)(struct bNodeTree *ntree, struct bNode *node), + void (*verifyfunc)(struct bNodeTree *ntree, struct bNode *node, struct ID *id)); +void node_type_tree(struct bNodeType *ntype, + void (*inittreefunc)(struct bNodeTree *), + void (*updatetreefunc)(struct bNodeTree *)); +void node_type_group_edit(struct bNodeType *ntype, + struct bNodeTree *(*group_edit_get)(struct bNode *node), + struct bNodeTree *(*group_edit_set)(struct bNode *node, int edit), + void (*group_edit_clear)(struct bNode *node)); -void node_type_exec(struct bNodeType *ntype, void (*execfunc)(void *data, struct bNode *, struct bNodeStack **, +void node_type_exec(struct bNodeType *ntype, void (*execfunc)(void *data, struct bNode *, struct bNodeStack **, struct bNodeStack **)); -void node_type_exec_new(struct bNodeType *ntype, - void *(*initexecfunc)(struct bNode *node), - void (*freeexecfunc)(struct bNode *node, void *nodedata), - void (*newexecfunc)(void *data, int thread, struct bNode *, void *nodedata, - struct bNodeStack **, struct bNodeStack **)); -void node_type_internal_connect(struct bNodeType *ntype, ListBase (*internal_connect)(struct bNodeTree *, struct bNode *)); -void node_type_gpu(struct bNodeType *ntype, int (*gpufunc)(struct GPUMaterial *mat, struct bNode *node, +void node_type_exec_new(struct bNodeType *ntype, + void *(*initexecfunc)(struct bNode *node), + void (*freeexecfunc)(struct bNode *node, void *nodedata), + void (*newexecfunc)(void *data, int thread, struct bNode *, void *nodedata, + struct bNodeStack **, struct bNodeStack **)); +void node_type_internal_connect(struct bNodeType *ntype, ListBase (*internal_connect)(struct bNodeTree *, struct bNode *)); +void node_type_gpu(struct bNodeType *ntype, int (*gpufunc)(struct GPUMaterial *mat, struct bNode *node, struct GPUNodeStack *in, struct GPUNodeStack *out)); -void node_type_gpu_ext(struct bNodeType *ntype, int (*gpuextfunc)(struct GPUMaterial *mat, struct bNode *node, +void node_type_gpu_ext(struct bNodeType *ntype, int (*gpuextfunc)(struct GPUMaterial *mat, struct bNode *node, void *nodedata, struct GPUNodeStack *in, struct GPUNodeStack *out)); -void node_type_compatibility(struct bNodeType *ntype, short compatibility); +void node_type_compatibility(struct bNodeType *ntype, short compatibility); /* ************** COMMON NODES *************** */ @@ -545,16 +545,16 @@ struct ShadeResult; /* API */ struct bNodeTreeExec *ntreeShaderBeginExecTree(struct bNodeTree *ntree, int use_tree_data); -void ntreeShaderEndExecTree(struct bNodeTreeExec *exec, int use_tree_data); -void ntreeShaderExecTree(struct bNodeTree *ntree, struct ShadeInput *shi, struct ShadeResult *shr); -void ntreeShaderGetTexcoMode(struct bNodeTree *ntree, int osa, short *texco, int *mode); -void nodeShaderSynchronizeID(struct bNode *node, int copyto); +void ntreeShaderEndExecTree(struct bNodeTreeExec *exec, int use_tree_data); +void ntreeShaderExecTree(struct bNodeTree *ntree, struct ShadeInput *shi, struct ShadeResult *shr); +void ntreeShaderGetTexcoMode(struct bNodeTree *ntree, int osa, short *texco, int *mode); +void nodeShaderSynchronizeID(struct bNode *node, int copyto); - /* switch material render loop */ +/* switch material render loop */ extern void (*node_shader_lamp_loop)(struct ShadeInput *, struct ShadeResult *); -void set_node_shader_lamp_loop(void (*lamp_loop_func)(struct ShadeInput *, struct ShadeResult *)); +void set_node_shader_lamp_loop(void (*lamp_loop_func)(struct ShadeInput *, struct ShadeResult *)); -void ntreeGPUMaterialNodes(struct bNodeTree *ntree, struct GPUMaterial *mat); +void ntreeGPUMaterialNodes(struct bNodeTree *ntree, struct GPUMaterial *mat); /* ************** COMPOSITE NODES *************** */ diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h index 419fb4cedae..a93e542fe15 100644 --- a/source/blender/blenkernel/BKE_paint.h +++ b/source/blender/blenkernel/BKE_paint.h @@ -51,10 +51,11 @@ extern const char PAINT_CURSOR_VERTEX_PAINT[3]; extern const char PAINT_CURSOR_WEIGHT_PAINT[3]; extern const char PAINT_CURSOR_TEXTURE_PAINT[3]; -void paint_init(struct Paint *p, const char col[3]); -void free_paint(struct Paint *p); -void copy_paint(struct Paint *src, struct Paint *tar); +void BKE_paint_init(struct Paint *p, const char col[3]); +void BKE_paint_free(struct Paint *p); +void BKE_paint_copy(struct Paint *src, struct Paint *tar); +/* TODO, give these BKE_ prefix too */ struct Paint *paint_get_active(struct Scene *sce); struct Paint *paint_get_active_from_context(const struct bContext *C); struct Brush *paint_brush(struct Paint *paint); diff --git a/source/blender/blenkernel/BKE_sequencer.h b/source/blender/blenkernel/BKE_sequencer.h index d6c1a26fdba..a8890d5a37e 100644 --- a/source/blender/blenkernel/BKE_sequencer.h +++ b/source/blender/blenkernel/BKE_sequencer.h @@ -182,7 +182,7 @@ struct Sequence *BKE_sequencer_active_get(struct Scene *scene); int BKE_sequencer_active_get_pair(struct Scene *scene, struct Sequence **seq_act, struct Sequence **seq_other); void BKE_sequencer_active_set(struct Scene *scene, struct Sequence *seq); - +struct Mask *BKE_sequencer_mask_get(struct Scene *scene); /* apply functions recursively */ int seqbase_recursive_apply(struct ListBase *seqbase, int (*apply_func)(struct Sequence *seq, void *), void *arg); diff --git a/source/blender/blenkernel/BKE_tracking.h b/source/blender/blenkernel/BKE_tracking.h index 2b30c845754..c14476a3b59 100644 --- a/source/blender/blenkernel/BKE_tracking.h +++ b/source/blender/blenkernel/BKE_tracking.h @@ -110,6 +110,8 @@ struct MovieTrackingMarker *BKE_tracking_marker_ensure(struct MovieTrackingTrack void BKE_tracking_marker_pattern_minmax(const struct MovieTrackingMarker *marker, float min[2], float max[2]); +void BKE_tracking_marker_get_subframe_position(struct MovieTrackingTrack *track, float framenr, float pos[2]); + /* **** Object **** */ struct MovieTrackingObject *BKE_tracking_object_add(struct MovieTracking *tracking, const char *name); void BKE_tracking_object_delete(struct MovieTracking *tracking, struct MovieTrackingObject *object); @@ -146,8 +148,8 @@ struct ImBuf *BKE_tracking_distortion_exec(struct MovieDistortion *distortion, s struct ImBuf *ibuf, int width, int height, float overscan, int undistort); void BKE_tracking_distortion_free(struct MovieDistortion *distortion); -void BKE_tracking_distort_v2(struct MovieTracking *tracking, float co[2], float nco[2]); -void BKE_tracking_undistort_v2(struct MovieTracking *tracking, float co[2], float nco[2]); +void BKE_tracking_distort_v2(struct MovieTracking *tracking, const float co[2], float r_co[2]); +void BKE_tracking_undistort_v2(struct MovieTracking *tracking, const float co[2], float r_co[2]); struct ImBuf *BKE_tracking_undistort_frame(struct MovieTracking *tracking, struct ImBuf *ibuf, int calibration_width, int calibration_height, float overscan); diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index af6583fd726..6a8ddd8e00a 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -1438,9 +1438,9 @@ static void cyclic_offs_bone(Object *ob, bPose *pose, bActionStrip *strip, float if (strip->flag & ACTSTRIP_CYCLIC_USEZ) pose->cyclic_offset[2] = time * min[2]; } else { - if (fabs(min[0]) >= fabs(min[1]) && fabs(min[0]) >= fabs(min[2])) + if (fabsf(min[0]) >= fabsf(min[1]) && fabsf(min[0]) >= fabsf(min[2])) pose->cyclic_offset[0] = time * min[0]; - else if (fabs(min[1]) >= fabs(min[0]) && fabs(min[1]) >= fabs(min[2])) + else if (fabsf(min[1]) >= fabsf(min[0]) && fabsf(min[1]) >= fabsf(min[2])) pose->cyclic_offset[1] = time * min[1]; else pose->cyclic_offset[2] = time * min[2]; diff --git a/source/blender/blenkernel/intern/anim.c b/source/blender/blenkernel/intern/anim.c index 16ff1646f43..43b2df7ff95 100644 --- a/source/blender/blenkernel/intern/anim.c +++ b/source/blender/blenkernel/intern/anim.c @@ -1458,12 +1458,18 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p /* particle rotation uses x-axis as the aligned axis, so pre-rotate the object accordingly */ if ((part->draw & PART_DRAW_ROTATE_OB) == 0) { - float xvec[3], q[4]; + float xvec[3], q[4], size_mat[4][4], original_size[3]; + + mat4_to_size(original_size, obmat); + size_to_mat4(size_mat, original_size); + xvec[0] = -1.f; xvec[1] = xvec[2] = 0; vec_to_quat(q, xvec, ob->trackflag, ob->upflag); quat_to_mat4(obmat, q); obmat[3][3] = 1.0f; + + mult_m4_m4m4(obmat, obmat, size_mat); } /* Normal particles and cached hair live in global space so we need to diff --git a/source/blender/blenkernel/intern/boids.c b/source/blender/blenkernel/intern/boids.c index edb3120cf87..e6259cc9faf 100644 --- a/source/blender/blenkernel/intern/boids.c +++ b/source/blender/blenkernel/intern/boids.c @@ -1168,7 +1168,7 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa) /* constrain direction with maximum angular velocity */ angle = saacos(dot_v3v3(old_dir, wanted_dir)); - angle = MIN2(angle, val.max_ave); + angle = minf(angle, val.max_ave); cross_v3_v3v3(nor, old_dir, wanted_dir); axis_angle_to_quat(q, nor, angle); diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index 53a9057116c..468861242d0 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -1052,13 +1052,13 @@ void BKE_brush_painter_break_stroke(BrushPainter *painter) static void brush_pressure_apply(BrushPainter *painter, Brush *brush, float pressure) { if (BKE_brush_use_alpha_pressure(painter->scene, brush)) - brush_alpha_set(painter->scene, brush, MAX2(0.0f, painter->startalpha * pressure)); + brush_alpha_set(painter->scene, brush, maxf(0.0f, painter->startalpha * pressure)); if (BKE_brush_use_size_pressure(painter->scene, brush)) - BKE_brush_size_set(painter->scene, brush, MAX2(1.0f, painter->startsize * pressure)); + BKE_brush_size_set(painter->scene, brush, maxf(1.0f, painter->startsize * pressure)); if (brush->flag & BRUSH_JITTER_PRESSURE) - brush->jitter = MAX2(0.0f, painter->startjitter * pressure); + brush->jitter = maxf(0.0f, painter->startjitter * pressure); if (brush->flag & BRUSH_SPACING_PRESSURE) - brush->spacing = MAX2(1.0f, painter->startspacing * (1.5f - pressure)); + brush->spacing = maxf(1.0f, painter->startspacing * (1.5f - pressure)); } void BKE_brush_jitter_pos(const Scene *scene, Brush *brush, const float pos[2], float jitterpos[2]) @@ -1066,7 +1066,7 @@ void BKE_brush_jitter_pos(const Scene *scene, Brush *brush, const float pos[2], int use_jitter = brush->jitter != 0; /* jitter-ed brush gives weird and unpredictable result for this - * kinds of stroke, so manyally disable jitter usage (sergey) */ + * kinds of stroke, so manually disable jitter usage (sergey) */ use_jitter &= (brush->flag & (BRUSH_RESTORE_MESH | BRUSH_ANCHORED)) == 0; if (use_jitter) { @@ -1158,7 +1158,7 @@ int BKE_brush_painter_paint(BrushPainter *painter, BrushFunc func, const float p /* compute brush spacing adapted to brush radius, spacing may depend * on pressure, so update it */ brush_pressure_apply(painter, brush, painter->lastpressure); - spacing = MAX2(1.0f, radius) * brush->spacing * 0.01f; + spacing = maxf(1.0f, radius) * brush->spacing * 0.01f; /* setup starting distance, direction vector and accumulated distance */ startdistance = painter->accumdistance; @@ -1176,7 +1176,7 @@ int BKE_brush_painter_paint(BrushPainter *painter, BrushFunc func, const float p t = step / len; press = (1.0f - t) * painter->lastpressure + t * pressure; brush_pressure_apply(painter, brush, press); - spacing = MAX2(1.0f, radius) * brush->spacing * 0.01f; + spacing = maxf(1.0f, radius) * brush->spacing * 0.01f; BKE_brush_jitter_pos(scene, brush, paintpos, finalpos); diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index b19b9db8749..88748d5f0b8 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -52,6 +52,7 @@ #include "BKE_paint.h" #include "BKE_utildefines.h" #include "BKE_tessmesh.h" +#include "BKE_curve.h" #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" @@ -1709,10 +1710,49 @@ DerivedMesh *CDDM_from_mesh(Mesh *mesh, Object *UNUSED(ob)) DerivedMesh *CDDM_from_curve(Object *ob) { - return CDDM_from_curve_displist(ob, &ob->disp); + return CDDM_from_curve_displist(ob, &ob->disp, NULL); } -DerivedMesh *CDDM_from_curve_displist(Object *ob, ListBase *dispbase) +DerivedMesh *CDDM_from_curve_orco(struct Scene *scene, Object *ob) +{ + int *orco_index_ptr = NULL; + int (*orco_index)[4] = NULL; + float (*orco)[3] = NULL; + DerivedMesh *dm = CDDM_from_curve_displist(ob, &ob->disp, &orco_index_ptr); + + if (orco_index_ptr) { + orco = (float (*)[3])BKE_curve_make_orco(scene, ob); + } + + if (orco && orco_index_ptr) { + const char *uvname = "Orco"; + + int totpoly = dm->getNumPolys(dm); + + MPoly *mpolys = dm->getPolyArray(dm); + MLoop *mloops = dm->getLoopArray(dm); + + MLoopUV *mloopuvs; + + CustomData_add_layer_named(&dm->polyData, CD_MTEXPOLY, CD_DEFAULT, NULL, dm->numPolyData, uvname); + mloopuvs = CustomData_add_layer_named(&dm->loopData, CD_MLOOPUV, CD_DEFAULT, NULL, dm->numLoopData, uvname); + + BKE_mesh_nurbs_to_mdata_orco(mpolys, totpoly, + mloops, mloopuvs, + orco, orco_index); + } + + if (orco_index) { + MEM_freeN(orco_index); + } + if (orco) { + MEM_freeN(orco); + } + + return dm; +} + +DerivedMesh *CDDM_from_curve_displist(Object *ob, ListBase *dispbase, int **orco_index_ptr) { DerivedMesh *dm; CDDerivedMesh *cddm; @@ -1723,7 +1763,7 @@ DerivedMesh *CDDM_from_curve_displist(Object *ob, ListBase *dispbase) int totvert, totedge, totloop, totpoly; if (BKE_mesh_nurbs_displist_to_mdata(ob, dispbase, &allvert, &totvert, &alledge, - &totedge, &allloop, &allpoly, &totloop, &totpoly) != 0) + &totedge, &allloop, &allpoly, &totloop, &totpoly, orco_index_ptr) != 0) { /* Error initializing mdata. This often happens when curve is empty */ return CDDM_new(0, 0, 0, 0, 0); diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c index 516de35fab3..af9bb971d05 100644 --- a/source/blender/blenkernel/intern/collision.c +++ b/source/blender/blenkernel/intern/collision.c @@ -414,8 +414,9 @@ static CollPair* cloth_collision(ModifierData *md1, ModifierData *md2, collpair->bp2 = face2->v2; collpair->bp3 = face2->v3; } - else + else { i++; + } } if ( i == 2 ) { if ( face2->v4 ) { @@ -429,8 +430,9 @@ static CollPair* cloth_collision(ModifierData *md1, ModifierData *md2, collpair->bp2 = face2->v4; collpair->bp3 = face2->v3; } - else + else { break; + } } else if ( i == 3 ) { if ( face1->v4 && face2->v4 ) { @@ -444,8 +446,9 @@ static CollPair* cloth_collision(ModifierData *md1, ModifierData *md2, collpair->bp2 = face2->v3; collpair->bp3 = face2->v4; } - else + else { break; + } } #ifdef USE_BULLET @@ -464,8 +467,7 @@ static CollPair* cloth_collision(ModifierData *md1, ModifierData *md2, collpair->flag = 0; collpair++; }/* - else - { + else { float w1, w2, w3, u1, u2, u3; float v1[3], v2[3], relativeVelocity[3]; diff --git a/source/blender/blenkernel/intern/colortools.c b/source/blender/blenkernel/intern/colortools.c index 31ad4d0380a..20fae973756 100644 --- a/source/blender/blenkernel/intern/colortools.c +++ b/source/blender/blenkernel/intern/colortools.c @@ -66,10 +66,10 @@ CurveMapping *curvemapping_add(int tot, float minx, float miny, float maxx, floa cumap->flag = CUMA_DO_CLIP; if (tot == 4) cumap->cur = 3; /* rhms, hack for 'col' curve? */ - clipminx = MIN2(minx, maxx); - clipminy = MIN2(miny, maxy); - clipmaxx = MAX2(minx, maxx); - clipmaxy = MAX2(miny, maxy); + clipminx = minf(minx, maxx); + clipminy = minf(miny, maxy); + clipmaxx = maxf(minx, maxx); + clipmaxy = maxf(miny, maxy); BLI_rctf_init(&cumap->curr, clipminx, clipmaxx, clipminy, clipmaxy); cumap->clipr = cumap->curr; @@ -463,8 +463,8 @@ static void curvemap_make_table(CurveMap *cuma, rctf *clipr) bezt = MEM_callocN(cuma->totpoint * sizeof(BezTriple), "beztarr"); for (a = 0; a < cuma->totpoint; a++) { - cuma->mintable = MIN2(cuma->mintable, cmp[a].x); - cuma->maxtable = MAX2(cuma->maxtable, cmp[a].x); + cuma->mintable = minf(cuma->mintable, cmp[a].x); + cuma->maxtable = maxf(cuma->maxtable, cmp[a].x); bezt[a].vec[1][0] = cmp[a].x; bezt[a].vec[1][1] = cmp[a].y; if (cmp[a].flag & CUMA_VECTOR) @@ -655,13 +655,13 @@ void curvemapping_changed(CurveMapping *cumap, int rem_doubles) for (a = 0; a < cuma->totpoint; a++) { if (cmp[a].flag & CUMA_SELECT) { if (cmp[a].x < clipr->xmin) - dx = MIN2(dx, cmp[a].x - clipr->xmin); + dx = minf(dx, cmp[a].x - clipr->xmin); else if (cmp[a].x > clipr->xmax) - dx = MAX2(dx, cmp[a].x - clipr->xmax); + dx = maxf(dx, cmp[a].x - clipr->xmax); if (cmp[a].y < clipr->ymin) - dy = MIN2(dy, cmp[a].y - clipr->ymin); + dy = minf(dy, cmp[a].y - clipr->ymin); else if (cmp[a].y > clipr->ymax) - dy = MAX2(dy, cmp[a].y - clipr->ymax); + dy = maxf(dy, cmp[a].y - clipr->ymax); } } for (a = 0; a < cuma->totpoint; a++) { @@ -961,7 +961,7 @@ void BKE_histogram_update_sample_line(Histogram *hist, ImBuf *ibuf, const short hist->channels = 3; hist->x_resolution = 256; hist->xmax = 1.0f; - hist->ymax = 1.0f; + /* hist->ymax = 1.0f; */ /* now do this on the operator _only_ */ if (ibuf->rect == NULL && ibuf->rect_float == NULL) return; diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index c2b38442a6b..8298023161b 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -3624,7 +3624,7 @@ static void damptrack_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t cross_v3_v3v3(raxis, obvec, tarvec); rangle = dot_v3v3(obvec, tarvec); - rangle = acos(MAX2(-1.0f, MIN2(1.0f, rangle)) ); + rangle = acos(maxf(-1.0f, minf(1.0f, rangle))); /* construct rotation matrix from the axis-angle rotation found above * - this call takes care to make sure that the axis provided is a unit vector first diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c index ff2dd27e0c9..be81c70f261 100644 --- a/source/blender/blenkernel/intern/context.c +++ b/source/blender/blenkernel/intern/context.c @@ -242,6 +242,8 @@ static void *ctx_wm_python_context_get(const bContext *C, const char *member, vo if (result.ptr.data) return result.ptr.data; } +#else + (void)C, (void)member; #endif return fall_through; @@ -370,8 +372,15 @@ PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, Stru { PointerRNA ptr = CTX_data_pointer_get(C, member); - if (ptr.data && RNA_struct_is_a(ptr.type, type)) - return ptr; + if (ptr.data) { + if (RNA_struct_is_a(ptr.type, type)) { + return ptr; + } + else { + printf("%s: warning, member '%s' is '%s', not '%s'\n", + __func__, member, RNA_struct_identifier(ptr.type), RNA_struct_identifier(type)); + } + } return PointerRNA_NULL; } diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index 31491a80f2b..e7dc825accd 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -1712,7 +1712,7 @@ static void calc_bevel_sin_cos(float x1, float y1, float x2, float y2, float *si y2 /= t02; t02 = x1 * x2 + y1 * y2; - if (fabs(t02) >= 1.0) + if (fabsf(t02) >= 1.0f) t02 = 0.5 * M_PI; else t02 = (saacos(t02)) / 2.0f; @@ -2366,9 +2366,9 @@ void BKE_curve_bevelList_make(Object *ob) bevp0 = bevp1 + (nr - 1); nr--; while (nr--) { - if (fabs(bevp0->vec[0] - bevp1->vec[0]) < 0.00001) { - if (fabs(bevp0->vec[1] - bevp1->vec[1]) < 0.00001) { - if (fabs(bevp0->vec[2] - bevp1->vec[2]) < 0.00001) { + if (fabsf(bevp0->vec[0] - bevp1->vec[0]) < 0.00001f) { + if (fabsf(bevp0->vec[1] - bevp1->vec[1]) < 0.00001f) { + if (fabsf(bevp0->vec[2] - bevp1->vec[2]) < 0.00001f) { bevp0->dupe_tag = TRUE; bl->dupe_nr++; } diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c index 4026d3f06d3..636f60c7ce1 100644 --- a/source/blender/blenkernel/intern/depsgraph.c +++ b/source/blender/blenkernel/intern/depsgraph.c @@ -352,10 +352,9 @@ static void dag_add_driver_relation(AnimData *adt, DagForest *dag, DagNode *node static void dag_add_material_driver_relations(DagForest *dag, DagNode *node, Material *ma); /* recursive handling for material nodetree drivers */ -static void dag_add_material_nodetree_driver_relations(DagForest *dag, DagNode *node, bNodeTree *ntree, Material *rootma) +static void dag_add_material_nodetree_driver_relations(DagForest *dag, DagNode *node, bNodeTree *ntree) { bNode *n; - Material *ma; /* nodetree itself */ if (ntree->adt) { @@ -364,14 +363,13 @@ static void dag_add_material_nodetree_driver_relations(DagForest *dag, DagNode * /* nodetree's nodes... */ for (n = ntree->nodes.first; n; n = n->next) { - if (n->id && GS(n->id->name) == ID_MA) { - ma = (Material *)n->id; - if (ma != rootma) { - dag_add_material_driver_relations(dag, node, ma); + if (n->id) { + if (GS(n->id->name) == ID_MA) { + dag_add_material_driver_relations(dag, node, (Material *)n->id); + } + else if (n->type == NODE_GROUP) { + dag_add_material_nodetree_driver_relations(dag, node, (bNodeTree *)n->id); } - } - else if (n->type == NODE_GROUP && n->id) { - dag_add_material_nodetree_driver_relations(dag, node, (bNodeTree *)n->id, rootma); } } } @@ -379,6 +377,15 @@ static void dag_add_material_nodetree_driver_relations(DagForest *dag, DagNode * /* recursive handling for material drivers */ static void dag_add_material_driver_relations(DagForest *dag, DagNode *node, Material *ma) { + /* Prevent infinite recursion by checking (and tagging the material) as having been visited + * already (see build_dag()). This assumes ma->id.flag & LIB_DOIT isn't set by anything else + * in the meantime... [#32017] + */ + if (ma->id.flag & LIB_DOIT) + return; + else + ma->id.flag |= LIB_DOIT; + /* material itself */ if (ma->adt) { dag_add_driver_relation(ma->adt, dag, node, 1); @@ -390,7 +397,7 @@ static void dag_add_material_driver_relations(DagForest *dag, DagNode *node, Mat /* material's nodetree */ if (ma->nodetree) { - dag_add_material_nodetree_driver_relations(dag, node, ma->nodetree, ma); + dag_add_material_nodetree_driver_relations(dag, node, ma->nodetree); } } @@ -804,6 +811,9 @@ DagForest *build_dag(Main *bmain, Scene *sce, short mask) sce->theDag = dag; } + /* clear "LIB_DOIT" flag from all materials, to prevent infinite recursion problems later [#32017] */ + tag_main_idcode(bmain, ID_MA, FALSE); + /* add base node for scene. scene is always the first node in DAG */ scenenode = dag_add_node(dag, sce); diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c index 8011efebaac..00a76e87d83 100644 --- a/source/blender/blenkernel/intern/displist.c +++ b/source/blender/blenkernel/intern/displist.c @@ -948,7 +948,7 @@ static void curve_calc_modifiers_post(Scene *scene, Object *ob, ListBase *dispba curve_to_filledpoly(cu, nurb, dispbase); } - dm = CDDM_from_curve_displist(ob, dispbase); + dm = CDDM_from_curve_displist(ob, dispbase, NULL); CDDM_calc_normals_mapping(dm); } @@ -1038,7 +1038,7 @@ static DerivedMesh *create_orco_dm(Scene *scene, Object *ob) /* OrcoDM should be created from underformed disp lists */ BKE_displist_make_curveTypes_forOrco(scene, ob, &disp); - dm = CDDM_from_curve_displist(ob, &disp); + dm = CDDM_from_curve_displist(ob, &disp, NULL); BKE_displist_free(&disp); diff --git a/source/blender/blenkernel/intern/ipo.c b/source/blender/blenkernel/intern/ipo.c index 2fe567cc9bf..8de9640eb35 100644 --- a/source/blender/blenkernel/intern/ipo.c +++ b/source/blender/blenkernel/intern/ipo.c @@ -2094,7 +2094,7 @@ void do_versions_ipos_to_animato(Main *main) bAction *new_act; /* add a new action for this, and convert all data into that action */ - new_act = add_empty_action("ConvIPO_Action"); // XXX need a better name... + new_act = add_empty_action(id->name+2); ipo_to_animato(NULL, ipo, NULL, NULL, NULL, NULL, &new_act->curves, &drivers); new_act->idroot = ipo->blocktype; } diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index d3ca785caaf..77e7623ae3d 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -363,6 +363,9 @@ int id_copy(ID *id, ID **newid, int test) return 0; /* can't be copied from here */ case ID_GD: return 0; /* not implemented */ + case ID_MSK: + if (!test) *newid = (ID *)BKE_mask_copy((Mask *)id); + return 1; case ID_LS: if(!test) *newid= (ID*)FRS_copy_linestyle((FreestyleLineStyle*)id); return 1; diff --git a/source/blender/blenkernel/intern/mask.c b/source/blender/blenkernel/intern/mask.c index fa11721a944..b3f146586a8 100644 --- a/source/blender/blenkernel/intern/mask.c +++ b/source/blender/blenkernel/intern/mask.c @@ -56,8 +56,6 @@ #include "BKE_movieclip.h" #include "BKE_utildefines.h" -#include "raskter.h" - static MaskSplinePoint *mask_spline_point_next(MaskSpline *spline, MaskSplinePoint *points_array, MaskSplinePoint *point) { if (point == &points_array[spline->tot_point - 1]) { @@ -110,7 +108,7 @@ static BezTriple *mask_spline_point_prev_bezt(MaskSpline *spline, MaskSplinePoin if (spline->flag & MASK_SPLINE_CYCLIC) { return &(points_array[0].bezt); } - else { + else { return NULL; } } @@ -156,6 +154,7 @@ MaskLayer *BKE_mask_layer_new(Mask *mask, const char *name) mask->masklay_tot++; + masklay->blend = MASK_BLEND_MERGE; masklay->alpha = 1.0f; return masklay; @@ -188,28 +187,48 @@ void BKE_mask_layer_unique_name(Mask *mask, MaskLayer *masklay) BLI_uniquename(&mask->masklayers, masklay, "MaskLayer", '.', offsetof(MaskLayer, name), sizeof(masklay->name)); } -MaskLayer *BKE_mask_layer_copy(MaskLayer *layer) +MaskLayer *BKE_mask_layer_copy(MaskLayer *masklay) { - MaskLayer *layer_new; + MaskLayer *masklay_new; MaskSpline *spline; - layer_new = MEM_callocN(sizeof(MaskLayer), "new mask layer"); + masklay_new = MEM_callocN(sizeof(MaskLayer), "new mask layer"); - BLI_strncpy(layer_new->name, layer->name, sizeof(layer_new->name)); + BLI_strncpy(masklay_new->name, masklay->name, sizeof(masklay_new->name)); - layer_new->alpha = layer->alpha; - layer_new->blend = layer->blend; - layer_new->blend_flag = layer->blend_flag; - layer_new->flag = layer->flag; - layer_new->restrictflag = layer->restrictflag; + masklay_new->alpha = masklay->alpha; + masklay_new->blend = masklay->blend; + masklay_new->blend_flag = masklay->blend_flag; + masklay_new->flag = masklay->flag; + masklay_new->restrictflag = masklay->restrictflag; - for (spline = layer->splines.first; spline; spline = spline->next) { + for (spline = masklay->splines.first; spline; spline = spline->next) { MaskSpline *spline_new = BKE_mask_spline_copy(spline); - BLI_addtail(&layer_new->splines, spline_new); + BLI_addtail(&masklay_new->splines, spline_new); } - return layer_new; + /* correct animation */ + if (masklay->splines_shapes.first) { + MaskLayerShape *masklay_shape; + MaskLayerShape *masklay_shape_new; + + for (masklay_shape = masklay->splines_shapes.first; + masklay_shape; + masklay_shape = masklay_shape->next) + { + masklay_shape_new = MEM_callocN(sizeof(MaskLayerShape), "new mask layer shape"); + + masklay_shape_new->data = MEM_dupallocN(masklay_shape->data); + masklay_shape_new->tot_vert = masklay_shape->tot_vert; + masklay_shape_new->flag = masklay_shape->flag; + masklay_shape_new->frame = masklay_shape->frame; + + BLI_addtail(&masklay_new->splines_shapes, masklay_shape_new); + } + } + + return masklay_new; } void BKE_mask_layer_copy_list(ListBase *masklayers_new, ListBase *masklayers) @@ -281,6 +300,12 @@ int BKE_mask_spline_resolution(MaskSpline *spline, int width, int height) resol = MAX2(resol, cur_resol); } + BLI_assert(resol > 0); + + if (resol > MASK_RESOL_MAX) { + resol = MASK_RESOL_MAX; + } + return resol; } @@ -311,6 +336,12 @@ int BKE_mask_spline_feather_resolution(MaskSpline *spline, int width, int height resol += max_jump / max_segment; + BLI_assert(resol > 0); + + if (resol > MASK_RESOL_MAX) { + resol = MASK_RESOL_MAX; + } + return resol; } @@ -541,6 +572,8 @@ static void spline_feather_collapse_inner_loops(MaskSpline *spline, float (*feat int next = i + 1; float delta; + DO_MINMAX2(feather_points[i], min, max); + if (next == tot_feather_point) { if (spline->flag & MASK_SPLINE_CYCLIC) next = 0; @@ -555,16 +588,27 @@ static void spline_feather_collapse_inner_loops(MaskSpline *spline, float (*feat delta = fabsf(feather_points[i][1] - feather_points[next][1]); if (delta > max_delta_y) max_delta_y = delta; + } - DO_MINMAX2(feather_points[i], min, max); + /* prevent divisionsby zero by ensuring bounding box is not collapsed */ + if (max[0] - min[0] < FLT_EPSILON) { + max[0] += 0.01f; + min[0] -= 0.01f; + } + + if (max[1] - min[1] < FLT_EPSILON) { + max[1] += 0.01f; + min[1] -= 0.01f; } /* use dynamically calculated buckets per side, so we likely wouldn't * run into a situation when segment doesn't fit two buckets which is * pain collecting candidates for intersection */ + max_delta_x /= max[0] - min[0]; max_delta_y /= max[1] - min[1]; + max_delta = MAX2(max_delta_x, max_delta_y); buckets_per_side = MIN2(512, 0.9f / max_delta); @@ -1295,6 +1339,8 @@ static Mask *mask_alloc(const char *name) mask = BKE_libblock_alloc(&G.main->mask, ID_MSK, name); + mask->id.flag |= LIB_FAKEUSER; + return mask; } @@ -1317,6 +1363,49 @@ Mask *BKE_mask_new(const char *name) return mask; } +Mask *BKE_mask_copy_nolib(Mask *mask) +{ + Mask *mask_new; + + mask_new = MEM_dupallocN(mask); + + /*take care here! - we may want to copy anim data */ + mask_new->adt = NULL; + + mask_new->masklayers.first = NULL; + mask_new->masklayers.last = NULL; + + BKE_mask_layer_copy_list(&mask_new->masklayers, &mask->masklayers); + + /* enable fake user by default */ + if (!(mask_new->id.flag & LIB_FAKEUSER)) { + mask_new->id.flag |= LIB_FAKEUSER; + mask_new->id.us++; + } + + return mask_new; +} + +Mask *BKE_mask_copy(Mask *mask) +{ + Mask *mask_new; + + mask_new = BKE_libblock_copy(&mask->id); + + mask_new->masklayers.first = NULL; + mask_new->masklayers.last = NULL; + + BKE_mask_layer_copy_list(&mask_new->masklayers, &mask->masklayers); + + /* enable fake user by default */ + if (!(mask_new->id.flag & LIB_FAKEUSER)) { + mask_new->id.flag |= LIB_FAKEUSER; + mask_new->id.us++; + } + + return mask_new; +} + void BKE_mask_point_free(MaskSplinePoint *point) { if (point->uw) @@ -1471,8 +1560,8 @@ void BKE_mask_unlink(Main *bmain, Mask *mask) if (sl->spacetype == SPACE_CLIP) { SpaceClip *sc = (SpaceClip *) sl; - if (sc->mask == mask) - sc->mask = NULL; + if (sc->mask_info.mask == mask) + sc->mask_info.mask = NULL; } } } @@ -1481,47 +1570,63 @@ void BKE_mask_unlink(Main *bmain, Mask *mask) mask->id.us = 0; } +void BKE_mask_coord_from_frame(float r_co[2], const float co[2], const float frame_size[2]) +{ + if (frame_size[0] == frame_size[1]) { + r_co[0] = co[0]; + r_co[1] = co[1]; + } + else if (frame_size[0] < frame_size[1]) { + r_co[0] = ((co[0] - 0.5f) * (frame_size[0] / frame_size[1])) + 0.5f; + r_co[1] = co[1]; + } + else { /* (frame_size[0] > frame_size[1]) */ + r_co[0] = co[0]; + r_co[1] = ((co[1] - 0.5f) * (frame_size[1] / frame_size[0])) + 0.5f; + } +} void BKE_mask_coord_from_movieclip(MovieClip *clip, MovieClipUser *user, float r_co[2], const float co[2]) { int width, height; + float frame_size[2]; /* scaling for the clip */ BKE_movieclip_get_size(clip, user, &width, &height); - if (width == height) { - r_co[0] = co[0]; - r_co[1] = co[1]; - } - else if (width < height) { - r_co[0] = ((co[0] - 0.5f) * ((float)width / (float)height)) + 0.5f; - r_co[1] = co[1]; - } - else { /* (width > height) */ - r_co[0] = co[0]; - r_co[1] = ((co[1] - 0.5f) * ((float)height / (float)width)) + 0.5f; - } + frame_size[0] = (float)width; + frame_size[1] = (float)height; + + BKE_mask_coord_from_frame(r_co, co, frame_size); } /* as above but divide */ +void BKE_mask_coord_to_frame(float r_co[2], const float co[2], const float frame_size[2]) +{ + if (frame_size[0] == frame_size[1]) { + r_co[0] = co[0]; + r_co[1] = co[1]; + } + else if (frame_size[0] < frame_size[1]) { + r_co[0] = ((co[0] - 0.5f) / (frame_size[0] / frame_size[1])) + 0.5f; + r_co[1] = co[1]; + } + else { /* (frame_size[0] > frame_size[1]) */ + r_co[0] = co[0]; + r_co[1] = ((co[1] - 0.5f) / (frame_size[1] / frame_size[0])) + 0.5f; + } +} void BKE_mask_coord_to_movieclip(MovieClip *clip, MovieClipUser *user, float r_co[2], const float co[2]) { int width, height; + float frame_size[2]; /* scaling for the clip */ BKE_movieclip_get_size(clip, user, &width, &height); - if (width == height) { - r_co[0] = co[0]; - r_co[1] = co[1]; - } - else if (width < height) { - r_co[0] = ((co[0] - 0.5f) / ((float)width / (float)height)) + 0.5f; - r_co[1] = co[1]; - } - else { /* (width > height) */ - r_co[0] = co[0]; - r_co[1] = ((co[1] - 0.5f) / ((float)height / (float)width)) + 0.5f; - } + frame_size[0] = (float)width; + frame_size[1] = (float)height; + + BKE_mask_coord_to_frame(r_co, co, frame_size); } static int BKE_mask_evaluate_parent(MaskParent *parent, float ctime, float r_co[2]) @@ -1543,9 +1648,8 @@ static int BKE_mask_evaluate_parent(MaskParent *parent, float ctime, float r_co[ user.framenr = ctime; if (track) { - MovieTrackingMarker *marker = BKE_tracking_marker_get(track, clip_framenr); float marker_pos_ofs[2]; - add_v2_v2v2(marker_pos_ofs, marker->pos, track->offset); + BKE_tracking_marker_get_subframe_position(track, clip_framenr, marker_pos_ofs); BKE_mask_coord_from_movieclip(clip, &user, r_co, marker_pos_ofs); return TRUE; @@ -2431,255 +2535,7 @@ void BKE_mask_layer_shape_changed_remove(MaskLayer *masklay, int index, int coun } } -/* local functions */ -static void invert_vn_vn(float *array, const int size) -{ - float *arr = array + (size - 1); - int i = size; - while (i--) { - *(arr) = 1.0f - *(arr); - arr--; - } -} - -static void m_invert_vn_vn(float *array, const float f, const int size) -{ - float *arr = array + (size - 1); - int i = size; - while (i--) { - *(arr) = 1.0f - (*(arr) * f); - arr--; - } -} - -static void clamp_vn_vn(float *array, const int size) -{ - float *arr = array + (size - 1); - - int i = size; - while (i--) { - if (*arr < 0.0f) *arr = 0.0f; - else if (*arr > 1.0f) *arr = 1.0f; - arr--; - } -} - int BKE_mask_get_duration(Mask *mask) { - return MAX2(1, mask->efra - mask->sfra); -} - -/* rasterization */ -void BKE_mask_rasterize_layers(ListBase *masklayers, int width, int height, float *buffer, - const short do_aspect_correct, const short do_mask_aa, - const short do_feather) -{ - MaskLayer *masklay; - - /* temp blending buffer */ - const int buffer_size = width * height; - float *buffer_tmp = MEM_mallocN(sizeof(float) * buffer_size, __func__); - - for (masklay = masklayers->first; masklay; masklay = masklay->next) { - MaskSpline *spline; - float alpha; - - if (masklay->restrictflag & MASK_RESTRICT_RENDER) { - continue; - } - - memset(buffer_tmp, 0, sizeof(float) * buffer_size); - - for (spline = masklay->splines.first; spline; spline = spline->next) { - float (*diff_points)[2]; - int tot_diff_point; - - float (*diff_feather_points)[2]; - int tot_diff_feather_points; - - diff_points = BKE_mask_spline_differentiate_with_resolution(spline, width, height, - &tot_diff_point); - - if (tot_diff_point) { - if (do_feather) { - diff_feather_points = - BKE_mask_spline_feather_differentiated_points_with_resolution(spline, width, height, - &tot_diff_feather_points); - } - else { - tot_diff_feather_points = 0; - diff_feather_points = NULL; - } - - if (do_aspect_correct) { - if (width != height) { - float *fp; - float *ffp; - int i; - float asp; - - if (width < height) { - fp = &diff_points[0][0]; - ffp = tot_diff_feather_points ? &diff_feather_points[0][0] : NULL; - asp = (float)width / (float)height; - } - else { - fp = &diff_points[0][1]; - ffp = tot_diff_feather_points ? &diff_feather_points[0][1] : NULL; - asp = (float)height / (float)width; - } - - for (i = 0; i < tot_diff_point; i++, fp += 2) { - (*fp) = (((*fp) - 0.5f) / asp) + 0.5f; - } - - if (tot_diff_feather_points) { - for (i = 0; i < tot_diff_feather_points; i++, ffp += 2) { - (*ffp) = (((*ffp) - 0.5f) / asp) + 0.5f; - } - } - } - } - - if (tot_diff_point) { - PLX_raskterize(diff_points, tot_diff_point, - buffer_tmp, width, height,do_mask_aa); - - if (tot_diff_feather_points) { - PLX_raskterize_feather(diff_points, tot_diff_point, - diff_feather_points, tot_diff_feather_points, - buffer_tmp, width, height); - MEM_freeN(diff_feather_points); - } - - MEM_freeN(diff_points); - } - } - } - - /* blend with original */ - if (masklay->blend_flag & MASK_BLENDFLAG_INVERT) { - /* apply alpha multiply before inverting */ - if (masklay->alpha != 1.0f) { - m_invert_vn_vn(buffer_tmp, masklay->alpha, buffer_size); - } - else { - invert_vn_vn(buffer_tmp, buffer_size); - } - - alpha = 1.0f; - } - else { - alpha = masklay->alpha; - } - - switch (masklay->blend) { - case MASK_BLEND_SUBTRACT: - { - if (alpha == 1.0f) { - sub_vn_vn(buffer, buffer_tmp, buffer_size); - } - else { - msub_vn_vn(buffer, buffer_tmp, alpha, buffer_size); - } - break; - } - case MASK_BLEND_ADD: - default: - { - if (alpha == 1.0f) { - add_vn_vn(buffer, buffer_tmp, buffer_size); - } - else { - madd_vn_vn(buffer, buffer_tmp, alpha, buffer_size); - } - break; - } - } - - if(do_mask_aa){ - //PLX_antialias_buffer(buffer,width,height); - } - /* clamp at the end */ - clamp_vn_vn(buffer, buffer_size); - } - MEM_freeN(buffer_tmp); -} - -#ifdef __PLX_RASKTER_MT__ -void BKE_mask_init_layers(Mask *mask, struct layer_init_data *mlayer_data, int width, int height, const short do_aspect_correct){ - MaskLayer *masklay; - int numLayers=0; - int currLayer=0; - for (masklay = mask->masklayers->first; masklay; masklay = masklay->next) { - numLayers++; - } - mlayer_data = MEM_mallocN(sizeof(struct layer_init_data) * numLayers, __func__); //size correct? - - - for (masklay = mask->masklayers->first; masklay; masklay = masklay->next) { - MaskSpline *spline; - for (spline = masklay->splines.first; spline; spline = spline->next) { - float (*diff_points)[2]; - int tot_diff_point; - - float (*diff_feather_points)[2]; - int tot_diff_feather_points; - - diff_points = BKE_mask_spline_differentiate_with_resolution(spline, width, height, - &tot_diff_point); - - if (tot_diff_point) { - if (do_feather) { - diff_feather_points = - BKE_mask_spline_feather_differentiated_points_with_resolution(spline, width, height, - &tot_diff_feather_points); - } - else { - tot_diff_feather_points = 0; - diff_feather_points = NULL; - } - - if (do_aspect_correct) { - if (width != height) { - float *fp; - float *ffp; - int i; - float asp; - - if (width < height) { - fp = &diff_points[0][0]; - ffp = tot_diff_feather_points ? &diff_feather_points[0][0] : NULL; - asp = (float)width / (float)height; - } - else { - fp = &diff_points[0][1]; - ffp = tot_diff_feather_points ? &diff_feather_points[0][1] : NULL; - asp = (float)height / (float)width; - } - - for (i = 0; i < tot_diff_point; i++, fp += 2) { - (*fp) = (((*fp) - 0.5f) / asp) + 0.5f; - } - - if (tot_diff_feather_points) { - for (i = 0; i < tot_diff_feather_points; i++, ffp += 2) { - (*ffp) = (((*ffp) - 0.5f) / asp) + 0.5f; - } - } - } - } - PLX_init_base_data(mlayer_data[currLayer], diff_points, tot_diff_points, width, height); - currLayer++; - } - } - } -} -#endif - -void BKE_mask_rasterize(Mask *mask, int width, int height, float *buffer, - const short do_aspect_correct, const short do_mask_aa, - const short do_feather) -{ - BKE_mask_rasterize_layers(&mask->masklayers, width, height, buffer, do_aspect_correct, do_mask_aa, do_feather); + return maxi(1, mask->efra - mask->sfra); } diff --git a/source/blender/blenkernel/intern/mask_rasterize.c b/source/blender/blenkernel/intern/mask_rasterize.c index b05c1ad4eaa..b26e6de59c4 100644 --- a/source/blender/blenkernel/intern/mask_rasterize.c +++ b/source/blender/blenkernel/intern/mask_rasterize.c @@ -45,8 +45,6 @@ #include "BKE_mask.h" -#ifndef USE_RASKTER - /* this is rather and annoying hack, use define to isolate it. * problem is caused by scanfill removing edges on us. */ #define USE_SCANFILL_EDGE_WORKAROUND @@ -1251,6 +1249,9 @@ float BKE_maskrasterize_handle_sample(MaskRasterHandle *mr_handle, const float x } switch (layer->blend) { + case MASK_BLEND_MERGE: + value += value_layer * (1.0f - value); + break; case MASK_BLEND_ADD: value += value_layer; break; @@ -1286,4 +1287,36 @@ float BKE_maskrasterize_handle_sample(MaskRasterHandle *mr_handle, const float x return value; } -#endif /* USE_RASKTER */ +/** + * \brief Rasterize a buffer from a single mask + * + * We could get some speedup by inlining #BKE_maskrasterize_handle_sample + * and calculating each layer then blending buffers, but this function is only + * used by the sequencer - so better have the caller thread. + * + * Since #BKE_maskrasterize_handle_sample is used threaded elsewhere, + * we can simply use openmp here for some speedup. + */ +void BKE_maskrasterize_buffer(MaskRasterHandle *mr_handle, + const unsigned int width, const unsigned int height, + float *buffer) +{ +#ifdef _MSC_VER + int y; /* msvc requires signed for some reason */ +#else + unsigned int y; +#endif + +#pragma omp parallel for private(y) + for (y = 0; y < height; y++) { + unsigned int i = y * width; + unsigned int x; + float xy[2]; + xy[1] = (float)y / (float)height; + for (x = 0; x < width; x++, i++) { + xy[0] = (float)x / (float)width; + + buffer[i] = BKE_maskrasterize_handle_sample(mr_handle, xy); + } + } +} diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index 6167379309c..e93b08f15fc 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -1057,28 +1057,24 @@ int material_in_material(Material *parmat, Material *mat) /* ****************** */ /* Update drivers for materials in a nodetree */ -static void material_node_drivers_update(Scene *scene, bNodeTree *ntree, float ctime, Material *rootma) +static void material_node_drivers_update(Scene *scene, bNodeTree *ntree, float ctime) { bNode *node; - Material *ma; /* nodetree itself */ if (ntree->adt && ntree->adt->drivers.first) { BKE_animsys_evaluate_animdata(scene, &ntree->id, ntree->adt, ctime, ADT_RECALC_DRIVERS); } - /* nodes... */ + /* nodes */ for (node = ntree->nodes.first; node; node = node->next) { - if (node->id && GS(node->id->name) == ID_MA) { - /* TODO: prevent infinite recursion here... */ - ma = (Material *)node->id; - if (ma != rootma) { - material_drivers_update(scene, ma, ctime); - } - } - else if (node->type == NODE_GROUP && node->id) { - material_node_drivers_update(scene, (bNodeTree *)node->id, - ctime, rootma); + if (node->id) { + if (GS(node->id->name) == ID_MA) { + material_drivers_update(scene, (Material *)node->id, ctime); + } + else if (node->type == NODE_GROUP) { + material_node_drivers_update(scene, (bNodeTree *)node->id, ctime); + } } } } @@ -1093,6 +1089,15 @@ void material_drivers_update(Scene *scene, Material *ma, float ctime) //if (G.f & G_DEBUG) // printf("material_drivers_update(%s, %s)\n", scene->id.name, ma->id.name); + /* Prevent infinite recursion by checking (and tagging the material) as having been visited already + * (see BKE_scene_update_tagged()). This assumes ma->id.flag & LIB_DOIT isn't set by anything else + * in the meantime... [#32017] + */ + if (ma->id.flag & LIB_DOIT) + return; + else + ma->id.flag |= LIB_DOIT; + /* material itself */ if (ma->adt && ma->adt->drivers.first) { BKE_animsys_evaluate_animdata(scene, &ma->id, ma->adt, ctime, ADT_RECALC_DRIVERS); @@ -1100,7 +1105,7 @@ void material_drivers_update(Scene *scene, Material *ma, float ctime) /* nodes */ if (ma->nodetree) { - material_node_drivers_update(scene, ma->nodetree, ctime, ma); + material_node_drivers_update(scene, ma->nodetree, ctime); } } diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index c5752e193df..77cd127e6ea 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -394,6 +394,7 @@ void BKE_mesh_unlink(Mesh *me) if (me == NULL) return; + if (me->mat) for (a = 0; a < me->totcol; a++) { if (me->mat[a]) me->mat[a]->id.us--; me->mat[a] = NULL; @@ -1234,19 +1235,21 @@ int BKE_mesh_nurbs_to_mdata(Object *ob, MVert **allvert, int *totvert, allvert, totvert, alledge, totedge, allloop, allpoly, - totloop, totpoly); + totloop, totpoly, NULL); } /* BMESH: this doesn't calculate all edges from polygons, * only free standing edges are calculated */ /* Initialize mverts, medges and, faces for converting nurbs to mesh and derived mesh */ -/* use specified dispbase */ +/* use specified dispbase */ +/* TODO: orco values for non DL_SURF types */ int BKE_mesh_nurbs_displist_to_mdata(Object *ob, ListBase *dispbase, MVert **allvert, int *_totvert, MEdge **alledge, int *_totedge, MLoop **allloop, MPoly **allpoly, - int *_totloop, int *_totpoly) + int *_totloop, int *_totpoly, + int **orco_index_ptr) { DispList *dl; Curve *cu; @@ -1258,6 +1261,7 @@ int BKE_mesh_nurbs_displist_to_mdata(Object *ob, ListBase *dispbase, int a, b, ofs, vertcount, startvert, totvert = 0, totedge = 0, totloop = 0, totvlak = 0; int p1, p2, p3, p4, *index; int conv_polys = 0; + int (*orco_index)[4] = NULL; cu = ob->data; @@ -1308,6 +1312,11 @@ int BKE_mesh_nurbs_displist_to_mdata(Object *ob, ListBase *dispbase, /* verts and faces */ vertcount = 0; + if (orco_index_ptr) { + *orco_index_ptr = MEM_callocN(sizeof(int) * totvlak * 4, "nurbs_init orco"); + orco_index = (int (*)[4]) *orco_index_ptr; + } + dl = dispbase->first; while (dl) { int smooth = dl->rt & CU_SMOOTH ? 1 : 0; @@ -1385,8 +1394,6 @@ int BKE_mesh_nurbs_displist_to_mdata(Object *ob, ListBase *dispbase, mloop += 3; index += 3; } - - } else if (dl->type == DL_SURF) { startvert = vertcount; @@ -1431,6 +1438,15 @@ int BKE_mesh_nurbs_displist_to_mdata(Object *ob, ListBase *dispbase, mpoly->totloop = 4; mpoly->mat_nr = dl->col; + if (orco_index) { + const int poly_index = mpoly - *allpoly; + const int p_orco_base = startvert + ((dl->nr + 1) * a) + b; + orco_index[poly_index][0] = p_orco_base + 1; + orco_index[poly_index][1] = p_orco_base + dl->nr + 2; + orco_index[poly_index][2] = p_orco_base + dl->nr + 1; + orco_index[poly_index][3] = p_orco_base; + } + if (smooth) mpoly->flag |= ME_SMOOTH; mpoly++; mloop += 4; @@ -1461,8 +1477,34 @@ int BKE_mesh_nurbs_displist_to_mdata(Object *ob, ListBase *dispbase, return 0; } + +MINLINE void copy_uv_orco_v2_v2(float r[2], const float a[2]) +{ + r[0] = 0.5f + a[0] * 0.5f; + r[1] = 0.5f + a[1] * 0.5f; +} + +/** + * orco is normally from #BKE_curve_make_orco + */ +void BKE_mesh_nurbs_to_mdata_orco(MPoly *mpoly, int totpoly, + MLoop *mloops, MLoopUV *mloopuvs, + float (*orco)[3], int (*orco_index)[4]) +{ + MPoly *mp; + + int i, j; + for (i = 0, mp = mpoly; i < totpoly; i++, mp++) { + MLoop *ml = mloops + mp->loopstart; + MLoopUV *mluv = mloopuvs + mp->loopstart; + for (j = 0; j < mp->totloop; j++, ml++, mluv++) { + copy_uv_orco_v2_v2(mluv->uv, orco[orco_index[i][j]]); + } + } +} + /* this may fail replacing ob->data, be sure to check ob->type */ -void BKE_mesh_from_nurbs_displist(Object *ob, ListBase *dispbase) +void BKE_mesh_from_nurbs_displist(Object *ob, ListBase *dispbase, int **orco_index_ptr) { Main *bmain = G.main; Object *ob1; @@ -1480,7 +1522,7 @@ void BKE_mesh_from_nurbs_displist(Object *ob, ListBase *dispbase) if (dm == NULL) { if (BKE_mesh_nurbs_displist_to_mdata(ob, dispbase, &allvert, &totvert, &alledge, &totedge, &allloop, - &allpoly, &totloop, &totpoly) != 0) + &allpoly, &totloop, &totpoly, orco_index_ptr) != 0) { /* Error initializing */ return; @@ -1536,7 +1578,7 @@ void BKE_mesh_from_nurbs_displist(Object *ob, ListBase *dispbase) void BKE_mesh_from_nurbs(Object *ob) { - return BKE_mesh_from_nurbs_displist(ob, &ob->disp); + BKE_mesh_from_nurbs_displist(ob, &ob->disp, NULL); } typedef struct EdgeLink { diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index de367b6b4d0..4c23a370a5d 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -504,7 +504,9 @@ static void movieclip_load_get_szie(MovieClip *clip) if (width && height) { clip->tracking.camera.principal[0] = ((float)width) / 2.0f; clip->tracking.camera.principal[1] = ((float)height) / 2.0f; - + } + else { + clip->lastsize[0] = clip->lastsize[1] = IMG_SIZE_FALLBACK; } } diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c index 866194eea0e..1c06d95a70b 100644 --- a/source/blender/blenkernel/intern/multires.c +++ b/source/blender/blenkernel/intern/multires.c @@ -1311,7 +1311,7 @@ void multires_set_space(DerivedMesh *dm, Object *ob, int from, int to) memcpy(subGridData[i], gridData[i], key.elem_size * gridSize * gridSize); } - /*numGrids = ccgdm->dm->getNumGrids((DerivedMesh*)ccgdm);*/ /*UNUSED*/ + /* numGrids = ccgdm->dm->getNumGrids((DerivedMesh *)ccgdm); */ /*UNUSED*/ gridSize = ccgdm->getGridSize((DerivedMesh *)ccgdm); gridData = ccgdm->getGridData((DerivedMesh *)ccgdm); gridOffset = ccgdm->getGridOffset((DerivedMesh *)ccgdm); diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 56b1c0a17e8..592bc10424f 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -91,8 +91,8 @@ bNodeTreeType *ntreeGetType(int type) static bNodeType *node_get_type(bNodeTree *ntree, int type) { bNodeType *ntype = ntreeGetType(ntree->type)->node_types.first; - for (; ntype; ntype= ntype->next) - if (ntype->type==type) + for (; ntype; ntype = ntype->next) + if (ntype->type == type) return ntype; return NULL; @@ -105,12 +105,12 @@ bNodeType *ntreeGetNodeType(bNodeTree *ntree) bNodeSocketType *ntreeGetSocketType(int type) { - static bNodeSocketType *types[NUM_SOCKET_TYPES]= {NULL}; + static bNodeSocketType *types[NUM_SOCKET_TYPES] = {NULL}; static int types_init = 1; if (types_init) { node_socket_type_init(types); - types_init= 0; + types_init = 0; } if (type < NUM_SOCKET_TYPES) { @@ -125,8 +125,8 @@ void ntreeInitTypes(bNodeTree *ntree) { bNode *node, *next; - for (node= ntree->nodes.first; node; node= next) { - next= node->next; + for (node = ntree->nodes.first; node; node = next) { + next = node->next; node->typeinfo = node_get_type(ntree, node->type); @@ -143,11 +143,11 @@ static bNodeSocket *make_socket(bNodeTree *UNUSED(ntree), int in_out, const char { bNodeSocket *sock; - sock= MEM_callocN(sizeof(bNodeSocket), "sock"); + sock = MEM_callocN(sizeof(bNodeSocket), "sock"); BLI_strncpy(sock->name, name, NODE_MAXSTR); - sock->limit = (in_out==SOCK_IN ? 1 : 0xFFF); - sock->type= type; + sock->limit = (in_out == SOCK_IN ? 1 : 0xFFF); + sock->type = type; sock->storage = NULL; sock->default_value = node_socket_make_default_value(type); @@ -159,9 +159,9 @@ static bNodeSocket *make_socket(bNodeTree *UNUSED(ntree), int in_out, const char bNodeSocket *nodeAddSocket(bNodeTree *ntree, bNode *node, int in_out, const char *name, int type) { bNodeSocket *sock = make_socket(ntree, in_out, name, type); - if (in_out==SOCK_IN) + if (in_out == SOCK_IN) BLI_addtail(&node->inputs, sock); - else if (in_out==SOCK_OUT) + else if (in_out == SOCK_OUT) BLI_addtail(&node->outputs, sock); node->update |= NODE_UPDATE; @@ -172,9 +172,9 @@ bNodeSocket *nodeAddSocket(bNodeTree *ntree, bNode *node, int in_out, const char bNodeSocket *nodeInsertSocket(bNodeTree *ntree, bNode *node, int in_out, bNodeSocket *next_sock, const char *name, int type) { bNodeSocket *sock = make_socket(ntree, in_out, name, type); - if (in_out==SOCK_IN) + if (in_out == SOCK_IN) BLI_insertlinkbefore(&node->inputs, next_sock, sock); - else if (in_out==SOCK_OUT) + else if (in_out == SOCK_OUT) BLI_insertlinkbefore(&node->outputs, next_sock, sock); node->update |= NODE_UPDATE; @@ -186,9 +186,9 @@ void nodeRemoveSocket(bNodeTree *ntree, bNode *node, bNodeSocket *sock) { bNodeLink *link, *next; - for (link= ntree->links.first; link; link= next) { - next= link->next; - if (link->fromsock==sock || link->tosock==sock) { + for (link = ntree->links.first; link; link = next) { + next = link->next; + if (link->fromsock == sock || link->tosock == sock) { nodeRemLink(ntree, link); } } @@ -208,17 +208,17 @@ void nodeRemoveAllSockets(bNodeTree *ntree, bNode *node) bNodeSocket *sock; bNodeLink *link, *next; - for (link= ntree->links.first; link; link= next) { - next= link->next; - if (link->fromnode==node || link->tonode==node) { + for (link = ntree->links.first; link; link = next) { + next = link->next; + if (link->fromnode == node || link->tonode == node) { nodeRemLink(ntree, link); } } - for (sock=node->inputs.first; sock; sock=sock->next) + for (sock = node->inputs.first; sock; sock = sock->next) node_socket_free_default_value(sock->type, sock->default_value); BLI_freelistN(&node->inputs); - for (sock=node->outputs.first; sock; sock=sock->next) + for (sock = node->outputs.first; sock; sock = sock->next) node_socket_free_default_value(sock->type, sock->default_value); BLI_freelistN(&node->outputs); @@ -236,20 +236,20 @@ int nodeFindNode(bNodeTree *ntree, bNodeSocket *sock, bNode **nodep, int *sockin { bNode *node; bNodeSocket *tsock; - int index= 0; + int index = 0; - for (node= ntree->nodes.first; node; node= node->next) { - for (index=0, tsock= node->inputs.first; tsock; tsock= tsock->next, index++) { - if (tsock==sock) { - if (in_out) *in_out= SOCK_IN; + for (node = ntree->nodes.first; node; node = node->next) { + for (index = 0, tsock = node->inputs.first; tsock; tsock = tsock->next, index++) { + if (tsock == sock) { + if (in_out) *in_out = SOCK_IN; break; } } if (tsock) break; - for (index=0, tsock= node->outputs.first; tsock; tsock= tsock->next, index++) { - if (tsock==sock) { - if (in_out) *in_out= SOCK_OUT; + for (index = 0, tsock = node->outputs.first; tsock; tsock = tsock->next, index++) { + if (tsock == sock) { + if (in_out) *in_out = SOCK_OUT; break; } } @@ -258,12 +258,12 @@ int nodeFindNode(bNodeTree *ntree, bNodeSocket *sock, bNode **nodep, int *sockin } if (node) { - *nodep= node; - if (sockindex) *sockindex= index; + *nodep = node; + if (sockindex) *sockindex = index; return 1; } - *nodep= NULL; + *nodep = NULL; return 0; } @@ -274,7 +274,7 @@ static void node_add_sockets_from_type(bNodeTree *ntree, bNode *node, bNodeType /* bNodeSocket *sock; */ /* UNUSED */ if (ntype->inputs) { - sockdef= ntype->inputs; + sockdef = ntype->inputs; while (sockdef->type != -1) { /* sock = */ node_add_input_from_template(ntree, node, sockdef); @@ -282,7 +282,7 @@ static void node_add_sockets_from_type(bNodeTree *ntree, bNode *node, bNodeType } } if (ntype->outputs) { - sockdef= ntype->outputs; + sockdef = ntype->outputs; while (sockdef->type != -1) { /* sock = */ node_add_output_from_template(ntree, node, sockdef); @@ -302,7 +302,7 @@ bNode *nodeAddNode(bNodeTree *ntree, struct bNodeTemplate *ntemp) bNode *node; bNodeType *ntype; - ntype= node_get_type(ntree, ntemp->type); + ntype = node_get_type(ntree, ntemp->type); if (ntype == NULL) { printf("nodeAddNodeType() error: '%d' type invalid\n", ntemp->type); return NULL; @@ -311,20 +311,20 @@ bNode *nodeAddNode(bNodeTree *ntree, struct bNodeTemplate *ntemp) if (!nodeValid(ntree, ntemp)) return NULL; - node= MEM_callocN(sizeof(bNode), "new node"); - node->type= ntype->type; - node->typeinfo= ntype; - node->flag= NODE_SELECT|ntype->flag; - node->width= ntype->width; - node->miniwidth= 42.0f; - node->height= ntype->height; - node->color[0] = node->color[1] = node->color[2] = 0.608; /* default theme color */ + node = MEM_callocN(sizeof(bNode), "new node"); + node->type = ntype->type; + node->typeinfo = ntype; + node->flag = NODE_SELECT | ntype->flag; + node->width = ntype->width; + node->miniwidth = 42.0f; + node->height = ntype->height; + node->color[0] = node->color[1] = node->color[2] = 0.608; /* default theme color */ node_add_sockets_from_type(ntree, node, ntype); BLI_addtail(&ntree->nodes, node); - if (ntype->initfunc!=NULL) + if (ntype->initfunc != NULL) ntype->initfunc(ntree, node, ntemp); /* initialize the node name with the node label. @@ -343,19 +343,19 @@ bNode *nodeAddNode(bNodeTree *ntree, struct bNodeTemplate *ntemp) /* ntree is the target tree */ bNode *nodeCopyNode(struct bNodeTree *ntree, struct bNode *node) { - bNode *nnode= MEM_callocN(sizeof(bNode), "dupli node"); + bNode *nnode = MEM_callocN(sizeof(bNode), "dupli node"); bNodeSocket *sock, *oldsock; - *nnode= *node; + *nnode = *node; nodeUniqueName(ntree, nnode); BLI_addtail(&ntree->nodes, nnode); BLI_duplicatelist(&nnode->inputs, &node->inputs); - oldsock= node->inputs.first; - for (sock= nnode->inputs.first; sock; sock= sock->next, oldsock= oldsock->next) { - oldsock->new_sock= sock; - sock->stack_index= 0; + oldsock = node->inputs.first; + for (sock = nnode->inputs.first; sock; sock = sock->next, oldsock = oldsock->next) { + oldsock->new_sock = sock; + sock->stack_index = 0; sock->default_value = node_socket_make_default_value(oldsock->type); node_socket_copy_default_value(oldsock->type, sock->default_value, oldsock->default_value); @@ -367,10 +367,10 @@ bNode *nodeCopyNode(struct bNodeTree *ntree, struct bNode *node) } BLI_duplicatelist(&nnode->outputs, &node->outputs); - oldsock= node->outputs.first; - for (sock= nnode->outputs.first; sock; sock= sock->next, oldsock= oldsock->next) { - oldsock->new_sock= sock; - sock->stack_index= 0; + oldsock = node->outputs.first; + for (sock = nnode->outputs.first; sock; sock = sock->next, oldsock = oldsock->next) { + oldsock->new_sock = sock; + sock->stack_index = 0; sock->default_value = node_socket_make_default_value(oldsock->type); node_socket_copy_default_value(oldsock->type, sock->default_value, oldsock->default_value); @@ -386,9 +386,9 @@ bNode *nodeCopyNode(struct bNodeTree *ntree, struct bNode *node) if (node->typeinfo->copystoragefunc) node->typeinfo->copystoragefunc(node, nnode); - node->new_node= nnode; - nnode->new_node= NULL; - nnode->preview= NULL; + node->new_node = nnode; + nnode->new_node = NULL; + nnode->preview = NULL; ntree->update |= NTREE_UPDATE_NODES; @@ -399,84 +399,84 @@ bNode *nodeCopyNode(struct bNodeTree *ntree, struct bNode *node) bNodeLink *nodeAddLink(bNodeTree *ntree, bNode *fromnode, bNodeSocket *fromsock, bNode *tonode, bNodeSocket *tosock) { bNodeSocket *sock; - bNodeLink *link= NULL; - int from= 0, to= 0; + bNodeLink *link = NULL; + int from = 0, to = 0; if (fromnode) { /* test valid input */ - for (sock= fromnode->outputs.first; sock; sock= sock->next) - if (sock==fromsock) + for (sock = fromnode->outputs.first; sock; sock = sock->next) + if (sock == fromsock) break; if (sock) - from= 1; /* OK */ + from = 1; /* OK */ else { - for (sock= fromnode->inputs.first; sock; sock= sock->next) - if (sock==fromsock) + for (sock = fromnode->inputs.first; sock; sock = sock->next) + if (sock == fromsock) break; if (sock) - from= -1; /* OK but flip */ + from = -1; /* OK but flip */ } } else { /* check tree sockets */ - for (sock= ntree->inputs.first; sock; sock= sock->next) - if (sock==fromsock) + for (sock = ntree->inputs.first; sock; sock = sock->next) + if (sock == fromsock) break; if (sock) - from= 1; /* OK */ + from = 1; /* OK */ else { - for (sock= ntree->outputs.first; sock; sock= sock->next) - if (sock==fromsock) + for (sock = ntree->outputs.first; sock; sock = sock->next) + if (sock == fromsock) break; if (sock) - from= -1; /* OK but flip */ + from = -1; /* OK but flip */ } } if (tonode) { - for (sock= tonode->inputs.first; sock; sock= sock->next) - if (sock==tosock) + for (sock = tonode->inputs.first; sock; sock = sock->next) + if (sock == tosock) break; if (sock) - to= 1; /* OK */ + to = 1; /* OK */ else { - for (sock= tonode->outputs.first; sock; sock= sock->next) - if (sock==tosock) + for (sock = tonode->outputs.first; sock; sock = sock->next) + if (sock == tosock) break; if (sock) - to= -1; /* OK but flip */ + to = -1; /* OK but flip */ } } else { /* check tree sockets */ - for (sock= ntree->outputs.first; sock; sock= sock->next) - if (sock==tosock) + for (sock = ntree->outputs.first; sock; sock = sock->next) + if (sock == tosock) break; if (sock) - to= 1; /* OK */ + to = 1; /* OK */ else { - for (sock= ntree->inputs.first; sock; sock= sock->next) - if (sock==tosock) + for (sock = ntree->inputs.first; sock; sock = sock->next) + if (sock == tosock) break; if (sock) - to= -1; /* OK but flip */ + to = -1; /* OK but flip */ } } if (from >= 0 && to >= 0) { - link= MEM_callocN(sizeof(bNodeLink), "link"); + link = MEM_callocN(sizeof(bNodeLink), "link"); BLI_addtail(&ntree->links, link); - link->fromnode= fromnode; - link->fromsock= fromsock; - link->tonode= tonode; - link->tosock= tosock; + link->fromnode = fromnode; + link->fromsock = fromsock; + link->tonode = tonode; + link->tosock = tosock; } else if (from <= 0 && to <= 0) { - link= MEM_callocN(sizeof(bNodeLink), "link"); + link = MEM_callocN(sizeof(bNodeLink), "link"); BLI_addtail(&ntree->links, link); - link->fromnode= tonode; - link->fromsock= tosock; - link->tonode= fromnode; - link->tosock= fromsock; + link->fromnode = tonode; + link->fromsock = tosock; + link->tonode = fromnode; + link->tosock = fromsock; } ntree->update |= NTREE_UPDATE_LINKS; @@ -488,7 +488,7 @@ void nodeRemLink(bNodeTree *ntree, bNodeLink *link) { BLI_remlink(&ntree->links, link); if (link->tosock) - link->tosock->link= NULL; + link->tosock->link = NULL; MEM_freeN(link); ntree->update |= NTREE_UPDATE_LINKS; @@ -498,9 +498,9 @@ void nodeRemSocketLinks(bNodeTree *ntree, bNodeSocket *sock) { bNodeLink *link, *next; - for (link= ntree->links.first; link; link= next) { - next= link->next; - if (link->fromsock==sock || link->tosock==sock) { + for (link = ntree->links.first; link; link = next) { + next = link->next; + if (link->fromsock == sock || link->tosock == sock) { nodeRemLink(ntree, link); } } @@ -519,15 +519,15 @@ void nodeInternalRelink(bNodeTree *ntree, bNode *node) intlinks = node->typeinfo->internal_connect(ntree, node); /* store link pointers in output sockets, for efficient lookup */ - for (link=intlinks.first; link; link=link->next) + for (link = intlinks.first; link; link = link->next) link->tosock->link = link; /* redirect downstream links */ - for (link=ntree->links.first; link; link=link_next) { + for (link = ntree->links.first; link; link = link_next) { link_next = link->next; /* do we have internal link? */ - if (link->fromnode==node) { + if (link->fromnode == node) { if (link->fromsock->link) { /* get the upstream input link */ bNodeLink *fromlink = link->fromsock->link->fromsock->link; @@ -547,10 +547,10 @@ void nodeInternalRelink(bNodeTree *ntree, bNode *node) } /* remove remaining upstream links */ - for (link=ntree->links.first; link; link=link_next) { + for (link = ntree->links.first; link; link = link_next) { link_next = link->next; - if (link->tonode==node) + if (link->tonode == node) nodeRemLink(ntree, link); } @@ -612,15 +612,15 @@ bNodeTree *ntreeAddTree(const char *name, int type, int nodetype) /* trees are created as local trees if they of compositor, material or texture type, * node groups and other tree types are created as library data. */ - if (ELEM3(type, NTREE_COMPOSIT, NTREE_SHADER, NTREE_TEXTURE) && nodetype==0) { - ntree= MEM_callocN(sizeof(bNodeTree), "new node tree"); - *( (short *)ntree->id.name )= ID_NT; /* not "type", as that is ntree->type */ - BLI_strncpy(ntree->id.name+2, name, sizeof(ntree->id.name)); + if (ELEM3(type, NTREE_COMPOSIT, NTREE_SHADER, NTREE_TEXTURE) && nodetype == 0) { + ntree = MEM_callocN(sizeof(bNodeTree), "new node tree"); + *( (short *)ntree->id.name) = ID_NT; /* not "type", as that is ntree->type */ + BLI_strncpy(ntree->id.name + 2, name, sizeof(ntree->id.name)); } else - ntree= BKE_libblock_alloc(&G.main->nodetree, ID_NT, name); + ntree = BKE_libblock_alloc(&G.main->nodetree, ID_NT, name); - ntree->type= type; + ntree->type = type; ntree->nodetype = nodetype; ntreeInitTypes(ntree); @@ -648,53 +648,53 @@ static bNodeTree *ntreeCopyTree_internal(bNodeTree *ntree, const short do_make_e bNodeLink *link; bNodeSocket *gsock, *oldgsock; - if (ntree==NULL) return NULL; + if (ntree == NULL) return NULL; /* is ntree part of library? */ - for (newtree=G.main->nodetree.first; newtree; newtree= newtree->id.next) - if (newtree==ntree) break; + for (newtree = G.main->nodetree.first; newtree; newtree = newtree->id.next) + if (newtree == ntree) break; if (newtree) { - newtree= BKE_libblock_copy(&ntree->id); + newtree = BKE_libblock_copy(&ntree->id); } else { - newtree= MEM_dupallocN(ntree); + newtree = MEM_dupallocN(ntree); BKE_libblock_copy_data(&newtree->id, &ntree->id, TRUE); /* copy animdata and ID props */ } id_us_plus((ID *)newtree->gpd); /* in case a running nodetree is copied */ - newtree->execdata= NULL; + newtree->execdata = NULL; - newtree->nodes.first= newtree->nodes.last= NULL; - newtree->links.first= newtree->links.last= NULL; + newtree->nodes.first = newtree->nodes.last = NULL; + newtree->links.first = newtree->links.last = NULL; last = ntree->nodes.last; - for (node= ntree->nodes.first; node; node= node->next) { + for (node = ntree->nodes.first; node; node = node->next) { if (do_make_extern) { id_lib_extern(node->id); } - node->new_node= NULL; - /* nnode= */ nodeCopyNode(newtree, node); /* sets node->new */ + node->new_node = NULL; + /* nnode= */ nodeCopyNode(newtree, node); /* sets node->new */ /* make sure we don't copy new nodes again! */ - if (node==last) + if (node == last) break; } /* socket definition for group usage */ BLI_duplicatelist(&newtree->inputs, &ntree->inputs); - for (gsock= newtree->inputs.first, oldgsock= ntree->inputs.first; gsock; gsock=gsock->next, oldgsock=oldgsock->next) { - oldgsock->new_sock= gsock; + for (gsock = newtree->inputs.first, oldgsock = ntree->inputs.first; gsock; gsock = gsock->next, oldgsock = oldgsock->next) { + oldgsock->new_sock = gsock; gsock->groupsock = (oldgsock->groupsock ? oldgsock->groupsock->new_sock : NULL); gsock->default_value = node_socket_make_default_value(oldgsock->type); node_socket_copy_default_value(oldgsock->type, gsock->default_value, oldgsock->default_value); } BLI_duplicatelist(&newtree->outputs, &ntree->outputs); - for (gsock= newtree->outputs.first, oldgsock= ntree->outputs.first; gsock; gsock=gsock->next, oldgsock=oldgsock->next) { - oldgsock->new_sock= gsock; + for (gsock = newtree->outputs.first, oldgsock = ntree->outputs.first; gsock; gsock = gsock->next, oldgsock = oldgsock->next) { + oldgsock->new_sock = gsock; gsock->groupsock = (oldgsock->groupsock ? oldgsock->groupsock->new_sock : NULL); gsock->default_value = node_socket_make_default_value(oldgsock->type); node_socket_copy_default_value(oldgsock->type, gsock->default_value, oldgsock->default_value); @@ -702,7 +702,7 @@ static bNodeTree *ntreeCopyTree_internal(bNodeTree *ntree, const short do_make_e /* copy links */ BLI_duplicatelist(&newtree->links, &ntree->links); - for (link= newtree->links.first; link; link= link->next) { + for (link = newtree->links.first; link; link = link->next) { link->fromnode = (link->fromnode ? link->fromnode->new_node : NULL); link->fromsock = (link->fromsock ? link->fromsock->new_sock : NULL); link->tonode = (link->tonode ? link->tonode->new_node : NULL); @@ -713,7 +713,7 @@ static bNodeTree *ntreeCopyTree_internal(bNodeTree *ntree, const short do_make_e } /* update node->parent pointers */ - for (node=newtree->nodes.first; node; node=node->next) { + for (node = newtree->nodes.first; node; node = node->next) { if (node->parent) node->parent = node->parent->new_node; } @@ -731,9 +731,9 @@ void ntreeSwitchID(bNodeTree *ntree, ID *id_from, ID *id_to) { bNode *node; /* for scene duplication only */ - for (node= ntree->nodes.first; node; node= node->next) { - if (node->id==id_from) { - node->id= id_to; + for (node = ntree->nodes.first; node; node = node->next) { + if (node->id == id_from) { + node->id = id_to; } } } @@ -747,34 +747,34 @@ void nodeFreePreview(bNode *node) if (node->preview->rect) MEM_freeN(node->preview->rect); MEM_freeN(node->preview); - node->preview= NULL; + node->preview = NULL; } } static void node_init_preview(bNode *node, int xsize, int ysize) { - if (node->preview==NULL) { - node->preview= MEM_callocN(sizeof(bNodePreview), "node preview"); + if (node->preview == NULL) { + node->preview = MEM_callocN(sizeof(bNodePreview), "node preview"); // printf("added preview %s\n", node->name); } /* node previews can get added with variable size this way */ - if (xsize==0 || ysize==0) + if (xsize == 0 || ysize == 0) return; /* sanity checks & initialize */ if (node->preview->rect) { - if (node->preview->xsize!=xsize && node->preview->ysize!=ysize) { + if (node->preview->xsize != xsize && node->preview->ysize != ysize) { MEM_freeN(node->preview->rect); - node->preview->rect= NULL; + node->preview->rect = NULL; } } - if (node->preview->rect==NULL) { - node->preview->rect= MEM_callocN(4*xsize + xsize*ysize*sizeof(char)*4, "node preview rect"); - node->preview->xsize= xsize; - node->preview->ysize= ysize; + if (node->preview->rect == NULL) { + node->preview->rect = MEM_callocN(4 * xsize + xsize * ysize * sizeof(char) * 4, "node preview rect"); + node->preview->xsize = xsize; + node->preview->ysize = ysize; } /* no clear, makes nicer previews */ } @@ -783,13 +783,13 @@ void ntreeInitPreview(bNodeTree *ntree, int xsize, int ysize) { bNode *node; - if (ntree==NULL) + if (ntree == NULL) return; - for (node= ntree->nodes.first; node; node= node->next) { - if (node->typeinfo->flag & NODE_PREVIEW) /* hrms, check for closed nodes? */ + for (node = ntree->nodes.first; node; node = node->next) { + if (node->typeinfo->flag & NODE_PREVIEW) /* hrms, check for closed nodes? */ node_init_preview(node, xsize, ysize); - if (node->type==NODE_GROUP && (node->flag & NODE_GROUP_EDIT)) + if (node->type == NODE_GROUP && (node->flag & NODE_GROUP_EDIT)) ntreeInitPreview((bNodeTree *)node->id, xsize, ysize); } } @@ -805,13 +805,13 @@ void ntreeClearPreview(bNodeTree *ntree) { bNode *node; - if (ntree==NULL) + if (ntree == NULL) return; - for (node= ntree->nodes.first; node; node= node->next) { + for (node = ntree->nodes.first; node; node = node->next) { if (node->typeinfo->flag & NODE_PREVIEW) nodeClearPreview(node); - if (node->type==NODE_GROUP && (node->flag & NODE_GROUP_EDIT)) + if (node->type == NODE_GROUP && (node->flag & NODE_GROUP_EDIT)) ntreeClearPreview((bNodeTree *)node->id); } } @@ -821,11 +821,11 @@ void ntreeClearPreview(bNodeTree *ntree) * add the color once. Preview gets cleared before it starts render though */ void nodeAddToPreview(bNode *node, float col[4], int x, int y, int do_manage) { - bNodePreview *preview= node->preview; + bNodePreview *preview = node->preview; if (preview) { - if (x>=0 && y>=0) { - if (xxsize && yysize) { - unsigned char *tar= preview->rect+ 4*((preview->xsize*y) + x); + if (x >= 0 && y >= 0) { + if (x < preview->xsize && y < preview->ysize) { + unsigned char *tar = preview->rect + 4 * ((preview->xsize * y) + x); if (do_manage) { linearrgb_to_srgb_uchar4(tar, col); @@ -849,22 +849,22 @@ void nodeUnlinkNode(bNodeTree *ntree, bNode *node) bNodeSocket *sock; ListBase *lb; - for (link= ntree->links.first; link; link= next) { - next= link->next; + for (link = ntree->links.first; link; link = next) { + next = link->next; - if (link->fromnode==node) { - lb= &node->outputs; + if (link->fromnode == node) { + lb = &node->outputs; if (link->tonode) link->tonode->update |= NODE_UPDATE; } - else if (link->tonode==node) - lb= &node->inputs; + else if (link->tonode == node) + lb = &node->inputs; else - lb= NULL; + lb = NULL; if (lb) { - for (sock= lb->first; sock; sock= sock->next) { - if (link->fromsock==sock || link->tosock==sock) + for (sock = lb->first; sock; sock = sock->next) { + if (link->fromsock == sock || link->tosock == sock) break; } if (sock) { @@ -877,7 +877,7 @@ void nodeUnlinkNode(bNodeTree *ntree, bNode *node) static void node_unlink_attached(bNodeTree *ntree, bNode *parent) { bNode *node; - for (node=ntree->nodes.first; node; node=node->next) { + for (node = ntree->nodes.first; node; node = node->next) { if (node->parent == parent) nodeDetachNode(node); } @@ -885,7 +885,7 @@ static void node_unlink_attached(bNodeTree *ntree, bNode *parent) void nodeFreeNode(bNodeTree *ntree, bNode *node) { - bNodeTreeType *treetype= ntreeGetType(ntree->type); + bNodeTreeType *treetype = ntreeGetType(ntree->type); bNodeSocket *sock, *nextsock; /* remove all references to this node */ @@ -902,12 +902,12 @@ void nodeFreeNode(bNodeTree *ntree, bNode *node) if (node->typeinfo && node->typeinfo->freestoragefunc) node->typeinfo->freestoragefunc(node); - for (sock=node->inputs.first; sock; sock = nextsock) { + for (sock = node->inputs.first; sock; sock = nextsock) { nextsock = sock->next; node_socket_free_default_value(sock->type, sock->default_value); MEM_freeN(sock); } - for (sock=node->outputs.first; sock; sock = nextsock) { + for (sock = node->outputs.first; sock; sock = nextsock) { nextsock = sock->next; node_socket_free_default_value(sock->type, sock->default_value); MEM_freeN(sock); @@ -926,7 +926,7 @@ void ntreeFreeTree(bNodeTree *ntree) bNode *node, *next; bNodeSocket *sock; - if (ntree==NULL) return; + if (ntree == NULL) return; /* XXX hack! node trees should not store execution graphs at all. * This should be removed when old tree types no longer require it. @@ -935,15 +935,15 @@ void ntreeFreeTree(bNodeTree *ntree) */ if (ntree->execdata) { switch (ntree->type) { - case NTREE_COMPOSIT: - ntreeCompositEndExecTree(ntree->execdata, 1); - break; - case NTREE_SHADER: - ntreeShaderEndExecTree(ntree->execdata, 1); - break; - case NTREE_TEXTURE: - ntreeTexEndExecTree(ntree->execdata, 1); - break; + case NTREE_COMPOSIT: + ntreeCompositEndExecTree(ntree->execdata, 1); + break; + case NTREE_SHADER: + ntreeShaderEndExecTree(ntree->execdata, 1); + break; + case NTREE_TEXTURE: + ntreeTexEndExecTree(ntree->execdata, 1); + break; } } @@ -951,17 +951,17 @@ void ntreeFreeTree(bNodeTree *ntree) id_us_min((ID *)ntree->gpd); - BLI_freelistN(&ntree->links); /* do first, then unlink_node goes fast */ + BLI_freelistN(&ntree->links); /* do first, then unlink_node goes fast */ - for (node= ntree->nodes.first; node; node= next) { - next= node->next; + for (node = ntree->nodes.first; node; node = next) { + next = node->next; nodeFreeNode(ntree, node); } - for (sock=ntree->inputs.first; sock; sock=sock->next) + for (sock = ntree->inputs.first; sock; sock = sock->next) node_socket_free_default_value(sock->type, sock->default_value); BLI_freelistN(&ntree->inputs); - for (sock=ntree->outputs.first; sock; sock=sock->next) + for (sock = ntree->outputs.first; sock; sock = sock->next) node_socket_free_default_value(sock->type, sock->default_value); BLI_freelistN(&ntree->outputs); } @@ -970,9 +970,9 @@ void ntreeFreeCache(bNodeTree *ntree) { bNodeTreeType *treetype; - if (ntree==NULL) return; + if (ntree == NULL) return; - treetype= ntreeGetType(ntree->type); + treetype = ntreeGetType(ntree->type); if (treetype->free_cache) treetype->free_cache(ntree); } @@ -982,45 +982,46 @@ void ntreeSetOutput(bNodeTree *ntree) bNode *node; /* find the active outputs, might become tree type dependent handler */ - for (node= ntree->nodes.first; node; node= node->next) { - if (node->typeinfo->nclass==NODE_CLASS_OUTPUT) { + for (node = ntree->nodes.first; node; node = node->next) { + if (node->typeinfo->nclass == NODE_CLASS_OUTPUT) { bNode *tnode; - int output= 0; + int output = 0; /* we need a check for which output node should be tagged like this, below an exception */ - if (node->type==CMP_NODE_OUTPUT_FILE) + if (node->type == CMP_NODE_OUTPUT_FILE) continue; /* there is more types having output class, each one is checked */ - for (tnode= ntree->nodes.first; tnode; tnode= tnode->next) { - if (tnode->typeinfo->nclass==NODE_CLASS_OUTPUT) { + for (tnode = ntree->nodes.first; tnode; tnode = tnode->next) { + if (tnode->typeinfo->nclass == NODE_CLASS_OUTPUT) { - if (ntree->type==NTREE_COMPOSIT) { + if (ntree->type == NTREE_COMPOSIT) { /* same type, exception for viewer */ - if (tnode->type==node->type || - (ELEM(tnode->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER) && - ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER))) { + if (tnode->type == node->type || + (ELEM(tnode->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER) && + ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER))) + { if (tnode->flag & NODE_DO_OUTPUT) { output++; - if (output>1) + if (output > 1) tnode->flag &= ~NODE_DO_OUTPUT; } } } else { /* same type */ - if (tnode->type==node->type) { + if (tnode->type == node->type) { if (tnode->flag & NODE_DO_OUTPUT) { output++; - if (output>1) + if (output > 1) tnode->flag &= ~NODE_DO_OUTPUT; } } } } } - if (output==0) + if (output == 0) node->flag |= NODE_DO_OUTPUT; } } @@ -1037,28 +1038,32 @@ typedef struct MakeLocalCallData { static void ntreeMakeLocal_CheckLocal(void *calldata, ID *owner_id, bNodeTree *ntree) { - MakeLocalCallData *cd= (MakeLocalCallData*)calldata; + MakeLocalCallData *cd = (MakeLocalCallData *)calldata; bNode *node; /* find if group is in tree */ - for (node= ntree->nodes.first; node; node= node->next) { + for (node = ntree->nodes.first; node; node = node->next) { if (node->id == cd->group_id) { - if (owner_id->lib) cd->lib= 1; - else cd->local= 1; + if (owner_id->lib) { + cd->lib = TRUE; + } + else { + cd->local = TRUE; + } } } } static void ntreeMakeLocal_LinkNew(void *calldata, ID *owner_id, bNodeTree *ntree) { - MakeLocalCallData *cd= (MakeLocalCallData*)calldata; + MakeLocalCallData *cd = (MakeLocalCallData *)calldata; bNode *node; /* find if group is in tree */ - for (node= ntree->nodes.first; node; node= node->next) { + for (node = ntree->nodes.first; node; node = node->next) { if (node->id == cd->group_id) { - if (owner_id->lib==NULL) { - node->id= cd->new_id; + if (owner_id->lib == NULL) { + node->id = cd->new_id; cd->new_id->us++; cd->group_id->us--; } @@ -1068,8 +1073,8 @@ static void ntreeMakeLocal_LinkNew(void *calldata, ID *owner_id, bNodeTree *ntre void ntreeMakeLocal(bNodeTree *ntree) { - Main *bmain= G.main; - bNodeTreeType *treetype= ntreeGetType(ntree->type); + Main *bmain = G.main; + bNodeTreeType *treetype = ntreeGetType(ntree->type); MakeLocalCallData cd; /* - only lib users: do nothing @@ -1077,8 +1082,8 @@ void ntreeMakeLocal(bNodeTree *ntree) * - mixed: make copy */ - if (ntree->id.lib==NULL) return; - if (ntree->id.us==1) { + if (ntree->id.lib == NULL) return; + if (ntree->id.us == 1) { id_clear_lib_data(bmain, (ID *)ntree); return; } @@ -1092,14 +1097,14 @@ void ntreeMakeLocal(bNodeTree *ntree) treetype->foreach_nodetree(G.main, &cd, &ntreeMakeLocal_CheckLocal); /* if all users are local, we simply make tree local */ - if (cd.local && cd.lib==0) { + if (cd.local && cd.lib == 0) { id_clear_lib_data(bmain, (ID *)ntree); } else if (cd.local && cd.lib) { /* this is the mixed case, we copy the tree and assign it to local users */ - bNodeTree *newtree= ntreeCopyTree(ntree); + bNodeTree *newtree = ntreeCopyTree(ntree); - newtree->id.us= 0; + newtree->id.us = 0; cd.new_id = &newtree->id; @@ -1109,18 +1114,18 @@ void ntreeMakeLocal(bNodeTree *ntree) int ntreeNodeExists(bNodeTree *ntree, bNode *testnode) { - bNode *node= ntree->nodes.first; - for (; node; node= node->next) - if (node==testnode) + bNode *node = ntree->nodes.first; + for (; node; node = node->next) + if (node == testnode) return 1; return 0; } int ntreeOutputExists(bNode *node, bNodeSocket *testsock) { - bNodeSocket *sock= node->outputs.first; - for (; sock; sock= sock->next) - if (sock==testsock) + bNodeSocket *sock = node->outputs.first; + for (; sock; sock = sock->next) + if (sock == testsock) return 1; return 0; } @@ -1128,33 +1133,33 @@ int ntreeOutputExists(bNode *node, bNodeSocket *testsock) /* returns localized tree for execution in threads */ bNodeTree *ntreeLocalize(bNodeTree *ntree) { - bNodeTreeType *ntreetype= ntreeGetType(ntree->type); + bNodeTreeType *ntreetype = ntreeGetType(ntree->type); bNodeTree *ltree; bNode *node; - bAction *action_backup= NULL, *tmpact_backup= NULL; + bAction *action_backup = NULL, *tmpact_backup = NULL; /* Workaround for copying an action on each render! * set action to NULL so animdata actions don't get copied */ - AnimData *adt= BKE_animdata_from_id(&ntree->id); + AnimData *adt = BKE_animdata_from_id(&ntree->id); if (adt) { - action_backup= adt->action; - tmpact_backup= adt->tmpact; + action_backup = adt->action; + tmpact_backup = adt->tmpact; - adt->action= NULL; - adt->tmpact= NULL; + adt->action = NULL; + adt->tmpact = NULL; } /* node copy func */ ltree = ntreeCopyTree_internal(ntree, FALSE); if (adt) { - AnimData *ladt= BKE_animdata_from_id(<ree->id); + AnimData *ladt = BKE_animdata_from_id(<ree->id); - adt->action= ladt->action= action_backup; - adt->tmpact= ladt->tmpact= tmpact_backup; + adt->action = ladt->action = action_backup; + adt->tmpact = ladt->tmpact = tmpact_backup; if (action_backup) action_backup->id.us++; if (tmpact_backup) tmpact_backup->id.us++; @@ -1165,9 +1170,9 @@ bNodeTree *ntreeLocalize(bNodeTree *ntree) /* ensures only a single output node is enabled */ ntreeSetOutput(ntree); - for (node= ntree->nodes.first; node; node= node->next) { + for (node = ntree->nodes.first; node; node = node->next) { /* store new_node pointer to original */ - node->new_node->new_node= node; + node->new_node->new_node = node; } if (ntreetype->localize) @@ -1181,7 +1186,7 @@ bNodeTree *ntreeLocalize(bNodeTree *ntree) /* is called by jobs manager, outside threads, so it doesnt happen during draw */ void ntreeLocalSync(bNodeTree *localtree, bNodeTree *ntree) { - bNodeTreeType *ntreetype= ntreeGetType(ntree->type); + bNodeTreeType *ntreetype = ntreeGetType(ntree->type); if (ntreetype->local_sync) ntreetype->local_sync(localtree, ntree); @@ -1191,16 +1196,16 @@ void ntreeLocalSync(bNodeTree *localtree, bNodeTree *ntree) /* we have to assume the editor already changed completely */ void ntreeLocalMerge(bNodeTree *localtree, bNodeTree *ntree) { - bNodeTreeType *ntreetype= ntreeGetType(ntree->type); + bNodeTreeType *ntreetype = ntreeGetType(ntree->type); bNode *lnode; /* move over the compbufs and previews */ - for (lnode= localtree->nodes.first; lnode; lnode= lnode->next) { + for (lnode = localtree->nodes.first; lnode; lnode = lnode->next) { if (ntreeNodeExists(ntree, lnode->new_node)) { if (lnode->preview && lnode->preview->rect) { nodeFreePreview(lnode->new_node); - lnode->new_node->preview= lnode->preview; - lnode->preview= NULL; + lnode->new_node->preview = lnode->preview; + lnode->preview = NULL; } } } @@ -1219,7 +1224,7 @@ int ntreeHasType(bNodeTree *ntree, int type) bNode *node; if (ntree) - for (node= ntree->nodes.first; node; node= node->next) + for (node = ntree->nodes.first; node; node = node->next) if (node->type == type) return 1; return 0; @@ -1229,10 +1234,10 @@ bNodeLink *nodeFindLink(bNodeTree *ntree, bNodeSocket *from, bNodeSocket *to) { bNodeLink *link; - for (link= ntree->links.first; link; link= link->next) { - if (link->fromsock==from && link->tosock==to) + for (link = ntree->links.first; link; link = link->next) { + if (link->fromsock == from && link->tosock == to) return link; - if (link->fromsock==to && link->tosock==from) /* hrms? */ + if (link->fromsock == to && link->tosock == from) /* hrms? */ return link; } return NULL; @@ -1241,10 +1246,10 @@ bNodeLink *nodeFindLink(bNodeTree *ntree, bNodeSocket *from, bNodeSocket *to) int nodeCountSocketLinks(bNodeTree *ntree, bNodeSocket *sock) { bNodeLink *link; - int tot= 0; + int tot = 0; - for (link= ntree->links.first; link; link= link->next) { - if (link->fromsock==sock || link->tosock==sock) + for (link = ntree->links.first; link; link = link->next) { + if (link->fromsock == sock || link->tosock == sock) tot++; } return tot; @@ -1254,9 +1259,9 @@ bNode *nodeGetActive(bNodeTree *ntree) { bNode *node; - if (ntree==NULL) return NULL; + if (ntree == NULL) return NULL; - for (node= ntree->nodes.first; node; node= node->next) + for (node = ntree->nodes.first; node; node = node->next) if (node->flag & NODE_ACTIVE) break; return node; @@ -1267,19 +1272,19 @@ bNode *nodeGetActiveID(bNodeTree *ntree, short idtype) { bNode *node; - if (ntree==NULL) return NULL; + if (ntree == NULL) return NULL; /* check for group edit */ - for (node= ntree->nodes.first; node; node= node->next) + for (node = ntree->nodes.first; node; node = node->next) if (node->flag & NODE_GROUP_EDIT) break; if (node) - ntree= (bNodeTree*)node->id; + ntree = (bNodeTree *)node->id; /* now find active node with this id */ - for (node= ntree->nodes.first; node; node= node->next) - if (node->id && GS(node->id->name)==idtype) + for (node = ntree->nodes.first; node; node = node->next) + if (node->id && GS(node->id->name) == idtype) if (node->flag & NODE_ACTIVE_ID) break; @@ -1289,24 +1294,24 @@ bNode *nodeGetActiveID(bNodeTree *ntree, short idtype) int nodeSetActiveID(bNodeTree *ntree, short idtype, ID *id) { bNode *node; - int ok= FALSE; + int ok = FALSE; - if (ntree==NULL) return ok; + if (ntree == NULL) return ok; /* check for group edit */ - for (node= ntree->nodes.first; node; node= node->next) + for (node = ntree->nodes.first; node; node = node->next) if (node->flag & NODE_GROUP_EDIT) break; if (node) - ntree= (bNodeTree*)node->id; + ntree = (bNodeTree *)node->id; /* now find active node with this id */ - for (node= ntree->nodes.first; node; node= node->next) { - if (node->id && GS(node->id->name)==idtype) { - if (id && ok==FALSE && node->id==id) { + for (node = ntree->nodes.first; node; node = node->next) { + if (node->id && GS(node->id->name) == idtype) { + if (id && ok == FALSE && node->id == id) { node->flag |= NODE_ACTIVE_ID; - ok= TRUE; + ok = TRUE; } else { node->flag &= ~NODE_ACTIVE_ID; @@ -1323,10 +1328,10 @@ void nodeClearActiveID(bNodeTree *ntree, short idtype) { bNode *node; - if (ntree==NULL) return; + if (ntree == NULL) return; - for (node= ntree->nodes.first; node; node= node->next) - if (node->id && GS(node->id->name)==idtype) + for (node = ntree->nodes.first; node; node = node->next) + if (node->id && GS(node->id->name) == idtype) node->flag &= ~NODE_ACTIVE_ID; } @@ -1334,9 +1339,9 @@ void nodeClearActive(bNodeTree *ntree) { bNode *node; - if (ntree==NULL) return; + if (ntree == NULL) return; - for (node= ntree->nodes.first; node; node= node->next) + for (node = ntree->nodes.first; node; node = node->next) node->flag &= ~(NODE_ACTIVE | NODE_ACTIVE_ID); } @@ -1347,7 +1352,7 @@ void nodeSetActive(bNodeTree *ntree, bNode *node) bNode *tnode; /* make sure only one node is active, and only one per ID type */ - for (tnode= ntree->nodes.first; tnode; tnode= tnode->next) { + for (tnode = ntree->nodes.first; tnode; tnode = tnode->next) { tnode->flag &= ~NODE_ACTIVE; if (node->id && tnode->id) { @@ -1395,12 +1400,12 @@ static int node_get_deplist_recurs(bNode *node, bNode ***nsort) node->done = TRUE; /* check linked nodes */ - for (sock= node->inputs.first; sock; sock= sock->next) { + for (sock = node->inputs.first; sock; sock = sock->next) { if (sock->link) { - fromnode= sock->link->fromnode; + fromnode = sock->link->fromnode; if (fromnode) { - if (fromnode->done==0) - fromnode->level= node_get_deplist_recurs(fromnode, nsort); + if (fromnode->done == 0) + fromnode->level = node_get_deplist_recurs(fromnode, nsort); if (fromnode->level <= level) level = fromnode->level - 1; } @@ -1409,14 +1414,14 @@ static int node_get_deplist_recurs(bNode *node, bNode ***nsort) /* check parent node */ if (node->parent) { - if (node->parent->done==0) - node->parent->level= node_get_deplist_recurs(node->parent, nsort); + if (node->parent->done == 0) + node->parent->level = node_get_deplist_recurs(node->parent, nsort); if (node->parent->level <= level) level = node->parent->level - 1; } if (nsort) { - **nsort= node; + **nsort = node; (*nsort)++; } @@ -1427,24 +1432,24 @@ void ntreeGetDependencyList(struct bNodeTree *ntree, struct bNode ***deplist, in { bNode *node, **nsort; - *totnodes=0; + *totnodes = 0; /* first clear data */ - for (node= ntree->nodes.first; node; node= node->next) { + for (node = ntree->nodes.first; node; node = node->next) { node->done = FALSE; (*totnodes)++; } - if (*totnodes==0) { + if (*totnodes == 0) { *deplist = NULL; return; } - nsort= *deplist= MEM_callocN((*totnodes)*sizeof(bNode*), "sorted node array"); + nsort = *deplist = MEM_callocN((*totnodes) * sizeof(bNode *), "sorted node array"); /* recursive check */ - for (node= ntree->nodes.first; node; node= node->next) { - if (node->done==0) { - node->level= node_get_deplist_recurs(node, &nsort); + for (node = ntree->nodes.first; node; node = node->next) { + if (node->done == 0) { + node->level = node_get_deplist_recurs(node, &nsort); } } } @@ -1455,14 +1460,14 @@ static void ntree_update_node_level(bNodeTree *ntree) bNode *node; /* first clear tag */ - for (node= ntree->nodes.first; node; node= node->next) { + for (node = ntree->nodes.first; node; node = node->next) { node->done = FALSE; } /* recursive check */ - for (node= ntree->nodes.first; node; node= node->next) { - if (node->done==0) { - node->level= node_get_deplist_recurs(node, NULL); + for (node = ntree->nodes.first; node; node = node->next) { + if (node->done == 0) { + node->level = node_get_deplist_recurs(node, NULL); } } } @@ -1474,25 +1479,25 @@ static void ntree_update_link_pointers(bNodeTree *ntree) bNodeLink *link; /* first clear data */ - for (node= ntree->nodes.first; node; node= node->next) { - for (sock= node->inputs.first; sock; sock= sock->next) { - sock->link= NULL; + for (node = ntree->nodes.first; node; node = node->next) { + for (sock = node->inputs.first; sock; sock = sock->next) { + sock->link = NULL; sock->flag &= ~SOCK_IN_USE; } - for (sock= node->outputs.first; sock; sock= sock->next) { + for (sock = node->outputs.first; sock; sock = sock->next) { sock->flag &= ~SOCK_IN_USE; } } - for (sock= ntree->inputs.first; sock; sock= sock->next) { + for (sock = ntree->inputs.first; sock; sock = sock->next) { sock->flag &= ~SOCK_IN_USE; } - for (sock= ntree->outputs.first; sock; sock= sock->next) { - sock->link= NULL; + for (sock = ntree->outputs.first; sock; sock = sock->next) { + sock->link = NULL; sock->flag &= ~SOCK_IN_USE; } - for (link= ntree->links.first; link; link= link->next) { - link->tosock->link= link; + for (link = ntree->links.first; link; link = link->next) { + link->tosock->link = link; link->fromsock->flag |= SOCK_IN_USE; link->tosock->flag |= SOCK_IN_USE; @@ -1517,10 +1522,10 @@ static void ntree_validate_links(bNodeTree *ntree) static void ntree_verify_nodes_cb(void *calldata, struct ID *UNUSED(owner_id), struct bNodeTree *ntree) { - ID *id= (ID*)calldata; + ID *id = (ID *)calldata; bNode *node; - for (node=ntree->nodes.first; node; node=node->next) + for (node = ntree->nodes.first; node; node = node->next) if (node->typeinfo->verifyfunc) node->typeinfo->verifyfunc(ntree, node, id); } @@ -1531,21 +1536,21 @@ void ntreeVerifyNodes(struct Main *main, struct ID *id) bNodeTree *ntree; int n; - for (n=0; n < NUM_NTREE_TYPES; ++n) { - ntreetype= ntreeGetType(n); + for (n = 0; n < NUM_NTREE_TYPES; ++n) { + ntreetype = ntreeGetType(n); if (ntreetype && ntreetype->foreach_nodetree) ntreetype->foreach_nodetree(main, id, ntree_verify_nodes_cb); } - for (ntree=main->nodetree.first; ntree; ntree=ntree->id.next) + for (ntree = main->nodetree.first; ntree; ntree = ntree->id.next) ntree_verify_nodes_cb(id, NULL, ntree); } void ntreeUpdateTree(bNodeTree *ntree) { - bNodeTreeType *ntreetype= ntreeGetType(ntree->type); + bNodeTreeType *ntreetype = ntreeGetType(ntree->type); bNode *node; - if (ntree->update & (NTREE_UPDATE_LINKS|NTREE_UPDATE_NODES)) { + if (ntree->update & (NTREE_UPDATE_LINKS | NTREE_UPDATE_NODES)) { /* set the bNodeSocket->link pointers */ ntree_update_link_pointers(ntree); @@ -1554,7 +1559,7 @@ void ntreeUpdateTree(bNodeTree *ntree) } /* update individual nodes */ - for (node=ntree->nodes.first; node; node=node->next) { + for (node = ntree->nodes.first; node; node = node->next) { /* node tree update tags override individual node update flags */ if ((node->update & NODE_UPDATE) || (ntree->update & NTREE_UPDATE)) { if (ntreetype->update_node) @@ -1567,7 +1572,7 @@ void ntreeUpdateTree(bNodeTree *ntree) } /* check link validity */ - if (ntree->update & (NTREE_UPDATE_LINKS|NTREE_UPDATE_NODES)) + if (ntree->update & (NTREE_UPDATE_LINKS | NTREE_UPDATE_NODES)) ntree_validate_links(ntree); /* generic tree update callback */ @@ -1577,7 +1582,7 @@ void ntreeUpdateTree(bNodeTree *ntree) /* Trees can be associated with a specific node type (i.e. group nodes), * in that case a tree update function may be defined by that node type. */ - bNodeType *ntype= node_get_type(ntree, ntree->nodetype); + bNodeType *ntype = node_get_type(ntree, ntree->nodetype); if (ntype && ntype->updatetreefunc) ntype->updatetreefunc(ntree); } @@ -1591,7 +1596,7 @@ void ntreeUpdateTree(bNodeTree *ntree) void nodeUpdate(bNodeTree *ntree, bNode *node) { - bNodeTreeType *ntreetype= ntreeGetType(ntree->type); + bNodeTreeType *ntreetype = ntreeGetType(ntree->type); if (ntreetype->update_node) ntreetype->update_node(ntree, node); @@ -1613,8 +1618,8 @@ int nodeUpdateID(bNodeTree *ntree, ID *id) ntreetype = ntreeGetType(ntree->type); if (ntreetype->update_node) { - for (node= ntree->nodes.first; node; node= node->next) { - if (node->id==id) { + for (node = ntree->nodes.first; node; node = node->next) { + if (node->id == id) { change = TRUE; node->update |= NODE_UPDATE_ID; ntreetype->update_node(ntree, node); @@ -1624,8 +1629,8 @@ int nodeUpdateID(bNodeTree *ntree, ID *id) } } else { - for (node= ntree->nodes.first; node; node= node->next) { - if (node->id==id) { + for (node = ntree->nodes.first; node; node = node->next) { + if (node->id == id) { change = TRUE; node->update |= NODE_UPDATE_ID; if (node->typeinfo->updatefunc) @@ -1644,7 +1649,7 @@ int nodeUpdateID(bNodeTree *ntree, ID *id) int nodeValid(bNodeTree *ntree, bNodeTemplate *ntemp) { - bNodeType *ntype= node_get_type(ntree, ntemp->type); + bNodeType *ntype = node_get_type(ntree, ntemp->type); if (ntype) { if (ntype->validfunc) return ntype->validfunc(ntree, ntemp); @@ -1655,9 +1660,9 @@ int nodeValid(bNodeTree *ntree, bNodeTemplate *ntemp) return 0; } -const char* nodeLabel(bNode *node) +const char *nodeLabel(bNode *node) { - if (node->label[0]!='\0') + if (node->label[0] != '\0') return node->label; else if (node->typeinfo->labelfunc) return node->typeinfo->labelfunc(node); @@ -1769,8 +1774,8 @@ void node_type_template(struct bNodeType *ntype, struct bNodeTemplate (*template } void node_type_update(struct bNodeType *ntype, - void (*updatefunc)(struct bNodeTree *ntree, struct bNode *node), - void (*verifyfunc)(struct bNodeTree *ntree, struct bNode *node, struct ID *id)) + void (*updatefunc)(struct bNodeTree *ntree, struct bNode *node), + void (*verifyfunc)(struct bNodeTree *ntree, struct bNode *node, struct ID *id)) { ntype->updatefunc = updatefunc; ntype->verifyfunc = verifyfunc; @@ -1783,9 +1788,9 @@ void node_type_tree(struct bNodeType *ntype, void (*inittreefunc)(struct bNodeTr } void node_type_group_edit(struct bNodeType *ntype, - struct bNodeTree *(*group_edit_get)(struct bNode *node), - struct bNodeTree *(*group_edit_set)(struct bNode *node, int edit), - void (*group_edit_clear)(struct bNode *node)) + struct bNodeTree *(*group_edit_get)(struct bNode *node), + struct bNodeTree *(*group_edit_set)(struct bNode *node, int edit), + void (*group_edit_clear)(struct bNode *node)) { ntype->group_edit_get = group_edit_get; ntype->group_edit_set = group_edit_set; @@ -1798,9 +1803,9 @@ void node_type_exec(struct bNodeType *ntype, void (*execfunc)(void *data, struct } void node_type_exec_new(struct bNodeType *ntype, - void *(*initexecfunc)(struct bNode *node), - void (*freeexecfunc)(struct bNode *node, void *nodedata), - void (*newexecfunc)(void *data, int thread, struct bNode *, void *nodedata, struct bNodeStack **, struct bNodeStack **)) + void *(*initexecfunc)(struct bNode *node), + void (*freeexecfunc)(struct bNode *node, void *nodedata), + void (*newexecfunc)(void *data, int thread, struct bNode *, void *nodedata, struct bNodeStack **, struct bNodeStack **)) { ntype->initexecfunc = initexecfunc; ntype->freeexecfunc = freeexecfunc; @@ -1829,10 +1834,10 @@ void node_type_compatibility(struct bNodeType *ntype, short compatibility) static bNodeType *is_nodetype_registered(ListBase *typelist, int type) { - bNodeType *ntype= typelist->first; + bNodeType *ntype = typelist->first; - for (;ntype; ntype= ntype->next ) - if (ntype->type==type) + for (; ntype; ntype = ntype->next) + if (ntype->type == type) return ntype; return NULL; @@ -1841,9 +1846,9 @@ static bNodeType *is_nodetype_registered(ListBase *typelist, int type) void nodeRegisterType(bNodeTreeType *ttype, bNodeType *ntype) { ListBase *typelist = &(ttype->node_types); - bNodeType *found= is_nodetype_registered(typelist, ntype->type); + bNodeType *found = is_nodetype_registered(typelist, ntype->type); - if (found==NULL) + if (found == NULL) BLI_addtail(typelist, ntype); } @@ -2070,7 +2075,7 @@ static void registerTextureNodes(bNodeTreeType *ttype) static void free_typeinfos(ListBase *list) { bNodeType *ntype, *next; - for (ntype=list->first; ntype; ntype=next) { + for (ntype = list->first; ntype; ntype = next) { next = ntype->next; if (ntype->needs_free) @@ -2102,14 +2107,14 @@ void clear_scene_in_nodes(Main *bmain, Scene *sce) Scene *sce1; bNode *node; - for (sce1= bmain->scene.first; sce1; sce1=sce1->id.next) { - if (sce1!=sce) { + for (sce1 = bmain->scene.first; sce1; sce1 = sce1->id.next) { + if (sce1 != sce) { if (sce1->nodetree) { - for (node= sce1->nodetree->nodes.first; node; node= node->next) { - if (node->type==CMP_NODE_R_LAYERS) { - Scene *nodesce= (Scene *)node->id; + for (node = sce1->nodetree->nodes.first; node; node = node->next) { + if (node->type == CMP_NODE_R_LAYERS) { + Scene *nodesce = (Scene *)node->id; - if (nodesce==sce) node->id = NULL; + if (nodesce == sce) node->id = NULL; } } } diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 2692e2a2929..efcc131038f 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -212,7 +212,14 @@ void BKE_object_link_modifiers(struct Object *ob, struct Object *from) for (md = from->modifiers.first; md; md = md->next) { ModifierData *nmd = NULL; - if (ELEM4(md->type, eModifierType_Hook, eModifierType_Softbody, eModifierType_ParticleInstance, eModifierType_Collision)) continue; + if (ELEM4(md->type, + eModifierType_Hook, + eModifierType_Softbody, + eModifierType_ParticleInstance, + eModifierType_Collision)) + { + continue; + } if (!BKE_object_support_modifier_type_check(ob, md->type)) continue; @@ -1328,7 +1335,8 @@ void BKE_object_copy_proxy_drivers(Object *ob, Object *target) if ((Object *)dtar->id == target) dtar->id = (ID *)ob; else { - /* only on local objects because this causes indirect links a -> b -> c, blend to point directly to a.blend + /* only on local objects because this causes indirect links + * 'a -> b -> c', blend to point directly to a.blend * when a.blend has a proxy thats linked into c.blend */ if (ob->id.lib == NULL) id_lib_extern((ID *)dtar->id); @@ -1698,16 +1706,16 @@ static void ob_parcurve(Scene *scene, Object *ob, Object *par, float mat[][4]) if (cu->flag & CU_FOLLOW) { #if 0 - float x1, q[4]; + float si, q[4]; vec_to_quat(quat, dir, ob->trackflag, ob->upflag); /* the tilt */ normalize_v3(dir); q[0] = (float)cos(0.5 * vec[3]); - x1 = (float)sin(0.5 * vec[3]); - q[1] = -x1 * dir[0]; - q[2] = -x1 * dir[1]; - q[3] = -x1 * dir[2]; + si = (float)sin(0.5 * vec[3]); + q[1] = -si * dir[0]; + q[2] = -si * dir[1]; + q[3] = -si * dir[2]; mul_qt_qtqt(quat, q, quat); #else quat_apply_track(quat, ob->trackflag, ob->upflag); @@ -1813,7 +1821,11 @@ static void give_parvert(Object *par, int nr, float vec[3]) dm->getVertCo(dm, 0, vec); } } - else fprintf(stderr, "%s: DerivedMesh is needed to solve parenting, object position can be wrong now\n", __func__); + else { + fprintf(stderr, + "%s: DerivedMesh is needed to solve parenting, " + "object position can be wrong now\n", __func__); + } } else if (ELEM(par->type, OB_CURVE, OB_SURF)) { Nurb *nu; diff --git a/source/blender/blenkernel/intern/ocean.c b/source/blender/blenkernel/intern/ocean.c index 13ea70d652d..66b0cff691e 100644 --- a/source/blender/blenkernel/intern/ocean.c +++ b/source/blender/blenkernel/intern/ocean.c @@ -834,7 +834,7 @@ void BKE_init_ocean(struct Ocean *o, int M, int N, float Lx, float Lz, float V, o->_fft_in_nz = (fftw_complex *) MEM_mallocN(o->_M * (1 + o->_N / 2) * sizeof(fftw_complex), "ocean_fft_in_nz"); o->_N_x = (double *) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_N_x"); - /*o->_N_y = (float*) fftwf_malloc(o->_M * o->_N * sizeof(float)); (MEM01)*/ + /* o->_N_y = (float *) fftwf_malloc(o->_M * o->_N * sizeof(float)); (MEM01) */ o->_N_z = (double *) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_N_z"); o->_N_x_plan = fftw_plan_dft_c2r_2d(o->_M, o->_N, o->_fft_in_nx, o->_N_x, FFTW_ESTIMATE); diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index ef3fd5c93d0..3267253e744 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -168,7 +168,7 @@ int paint_vertsel_test(Object *ob) ); } -void paint_init(Paint *p, const char col[3]) +void BKE_paint_init(Paint *p, const char col[3]) { Brush *brush; @@ -184,7 +184,7 @@ void paint_init(Paint *p, const char col[3]) p->flags |= PAINT_SHOW_BRUSH; } -void free_paint(Paint *paint) +void BKE_paint_free(Paint *paint) { id_us_min((ID *)paint->brush); } @@ -193,7 +193,7 @@ void free_paint(Paint *paint) * still do a id_us_plus(), rather then if we were copying betweem 2 existing * scenes where a matching value should decrease the existing user count as * with paint_brush_set() */ -void copy_paint(Paint *src, Paint *tar) +void BKE_paint_copy(Paint *src, Paint *tar) { tar->brush = src->brush; id_us_plus((ID *)tar->brush); diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 4a5267be7b3..5e4a150c4af 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -180,21 +180,21 @@ Scene *BKE_scene_copy(Scene *sce, int type) ts->vpaint->paintcursor = NULL; ts->vpaint->vpaint_prev = NULL; ts->vpaint->wpaint_prev = NULL; - copy_paint(&ts->vpaint->paint, &ts->vpaint->paint); + BKE_paint_copy(&ts->vpaint->paint, &ts->vpaint->paint); } if (ts->wpaint) { ts->wpaint = MEM_dupallocN(ts->wpaint); ts->wpaint->paintcursor = NULL; ts->wpaint->vpaint_prev = NULL; ts->wpaint->wpaint_prev = NULL; - copy_paint(&ts->wpaint->paint, &ts->wpaint->paint); + BKE_paint_copy(&ts->wpaint->paint, &ts->wpaint->paint); } if (ts->sculpt) { ts->sculpt = MEM_dupallocN(ts->sculpt); - copy_paint(&ts->sculpt->paint, &ts->sculpt->paint); + BKE_paint_copy(&ts->sculpt->paint, &ts->sculpt->paint); } - copy_paint(&ts->imapaint.paint, &ts->imapaint.paint); + BKE_paint_copy(&ts->imapaint.paint, &ts->imapaint.paint); ts->imapaint.paintcursor = NULL; ts->particle.paintcursor = NULL; } @@ -301,22 +301,22 @@ void BKE_scene_free(Scene *sce) if (sce->toolsettings) { if (sce->toolsettings->vpaint) { - free_paint(&sce->toolsettings->vpaint->paint); + BKE_paint_free(&sce->toolsettings->vpaint->paint); MEM_freeN(sce->toolsettings->vpaint); } if (sce->toolsettings->wpaint) { - free_paint(&sce->toolsettings->wpaint->paint); + BKE_paint_free(&sce->toolsettings->wpaint->paint); MEM_freeN(sce->toolsettings->wpaint); } if (sce->toolsettings->sculpt) { - free_paint(&sce->toolsettings->sculpt->paint); + BKE_paint_free(&sce->toolsettings->sculpt->paint); MEM_freeN(sce->toolsettings->sculpt); } if (sce->toolsettings->uvsculpt) { - free_paint(&sce->toolsettings->uvsculpt->paint); + BKE_paint_free(&sce->toolsettings->uvsculpt->paint); MEM_freeN(sce->toolsettings->uvsculpt); } - free_paint(&sce->toolsettings->imapaint.paint); + BKE_paint_free(&sce->toolsettings->imapaint.paint); MEM_freeN(sce->toolsettings); sce->toolsettings = NULL; @@ -1025,6 +1025,11 @@ void BKE_scene_update_tagged(Main *bmain, Scene *scene) DAG_ids_flush_tagged(bmain); scene->physics_settings.quick_cache_step = 0; + + /* clear "LIB_DOIT" flag from all materials, to prevent infinite recursion problems later + * when trying to find materials with drivers that need evaluating [#32017] + */ + tag_main_idcode(bmain, ID_MA, FALSE); /* update all objects: drivers, matrices, displists, etc. flags set * by depgraph or manual, no layer check here, gets correct flushed diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c index 4dfa9f7e12e..56fddfdaa2b 100644 --- a/source/blender/blenkernel/intern/screen.c +++ b/source/blender/blenkernel/intern/screen.c @@ -356,7 +356,7 @@ ARegion *BKE_area_find_region_type(ScrArea *sa, int type) /* note, using this function is generally a last resort, you really want to be * using the context when you can - campbell * -1 for any type */ -struct ScrArea *BKE_screen_find_big_area(struct bScreen *sc, const int spacetype, const short min) +ScrArea *BKE_screen_find_big_area(bScreen *sc, const int spacetype, const short min) { ScrArea *sa, *big = NULL; int size, maxsize = 0; diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c index b7f72ff86e2..2900cb55529 100644 --- a/source/blender/blenkernel/intern/sequencer.c +++ b/source/blender/blenkernel/intern/sequencer.c @@ -545,7 +545,9 @@ static void seq_update_sound_bounds_recursive_rec(Scene *scene, Sequence *metase * since sound is played outside of evaluating the imbufs, */ for (seq = metaseq->seqbase.first; seq; seq = seq->next) { if (seq->type == SEQ_TYPE_META) { - seq_update_sound_bounds_recursive_rec(scene, seq, MAX2(start, metaseq_start(seq)), MIN2(end, metaseq_end(seq))); + seq_update_sound_bounds_recursive_rec(scene, seq, + maxi(start, metaseq_start(seq)), + mini(end, metaseq_end(seq))); } else if (ELEM(seq->type, SEQ_TYPE_SOUND_RAM, SEQ_TYPE_SCENE)) { if (seq->scene_sound) { @@ -2070,10 +2072,30 @@ static ImBuf *seq_render_mask_strip( if (!seq->mask) { return NULL; } + else { + Mask *mask_temp; + MaskRasterHandle *mr_handle; - BKE_mask_evaluate(seq->mask, seq->mask->sfra + nr, TRUE); + mask_temp = BKE_mask_copy_nolib(seq->mask); + + BKE_mask_evaluate(mask_temp, seq->mask->sfra + nr, TRUE); + + maskbuf = MEM_mallocN(sizeof(float) * context.rectx * context.recty, __func__); + + mr_handle = BKE_maskrasterize_handle_new(); + + BKE_maskrasterize_handle_init(mr_handle, mask_temp, + context.rectx, context.recty, + TRUE, TRUE, TRUE); + + BKE_mask_free(mask_temp); + MEM_freeN(mask_temp); + + BKE_maskrasterize_buffer(mr_handle, context.rectx, context.recty, maskbuf); + + BKE_maskrasterize_handle_free(mr_handle); + } - maskbuf = MEM_callocN(sizeof(float) * context.rectx * context.recty, __func__); if (seq->flag & SEQ_MAKE_FLOAT) { /* pixels */ @@ -2082,14 +2104,6 @@ static ImBuf *seq_render_mask_strip( ibuf = IMB_allocImBuf(context.rectx, context.recty, 32, IB_rectfloat); - BKE_mask_rasterize(seq->mask, - context.rectx, context.recty, - maskbuf, - TRUE, - FALSE, /*XXX- TODO: make on/off for anti-aliasing */ - TRUE /*XXX- TODO: make on/off for feather */ - ); - fp_src = maskbuf; fp_dst = ibuf->rect_float; i = context.rectx * context.recty; @@ -2108,14 +2122,6 @@ static ImBuf *seq_render_mask_strip( ibuf = IMB_allocImBuf(context.rectx, context.recty, 32, IB_rect); - BKE_mask_rasterize(seq->mask, - context.rectx, context.recty, - maskbuf, - TRUE, - FALSE, /*XXX- TODO: make on/off for anti-aliasing */ - TRUE /*XXX- TODO: make on/off for feather */ - ); - fp_src = maskbuf; ub_dst = (unsigned char *)ibuf->rect; i = context.rectx * context.recty; @@ -3140,7 +3146,7 @@ int seq_tx_get_final_left(Sequence *seq, int metaclip) { if (metaclip && seq->tmp) { /* return the range clipped by the parents range */ - return MAX2(seq_tx_get_final_left(seq, 0), seq_tx_get_final_left((Sequence *)seq->tmp, 1) ); + return maxi(seq_tx_get_final_left(seq, 0), seq_tx_get_final_left((Sequence *)seq->tmp, TRUE)); } else { return (seq->start - seq->startstill) + seq->startofs; @@ -3151,7 +3157,7 @@ int seq_tx_get_final_right(Sequence *seq, int metaclip) { if (metaclip && seq->tmp) { /* return the range clipped by the parents range */ - return MIN2(seq_tx_get_final_right(seq, 0), seq_tx_get_final_right((Sequence *)seq->tmp, 1) ); + return mini(seq_tx_get_final_right(seq, 0), seq_tx_get_final_right((Sequence *)seq->tmp, TRUE)); } else { return ((seq->start + seq->len) + seq->endstill) - seq->endofs; @@ -3810,6 +3816,18 @@ int BKE_sequencer_active_get_pair(Scene *scene, Sequence **seq_act, Sequence **s } } +Mask *BKE_sequencer_mask_get(Scene *scene) +{ + Sequence *seq_act = BKE_sequencer_active_get(scene); + + if (seq_act && seq_act->type == SEQ_TYPE_MASK) { + return seq_act->mask; + } + else { + return NULL; + } +} + /* api like funcs for adding */ void seq_load_apply(Scene *scene, Sequence *seq, SeqLoadInfo *seq_load) diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index 2c105e4940d..26ca3805c28 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -3309,7 +3309,7 @@ static void mesh_to_softbody(Scene *scene, Object *ob) if (ob->softflag & OB_SB_GOAL) {bp->goal = sb->defgoal;} } - /* to proove the concept + /* to proof the concept * this enables per vertex *mass painting* */ @@ -3798,7 +3798,7 @@ static void softbody_update_positions(Object *ob, SoftBody *sb, float (*vertexCo /* vertexCos came from local world, go global */ mul_m4_v3(ob->obmat, bp->origE); /* just to be save give bp->origT a defined value - * will be calulated in interpolate_exciter()*/ + * will be calculated in interpolate_exciter() */ copy_v3_v3(bp->origT, bp->origE); } } diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c index 4342eb20d55..693f6fc1057 100644 --- a/source/blender/blenkernel/intern/tracking.c +++ b/source/blender/blenkernel/intern/tracking.c @@ -853,7 +853,7 @@ static void track_mask_gpencil_layer_rasterize(int frame_width, int frame_height fp[1] = (stroke_points[i].y - marker->search_min[1]) * frame_height / mask_height; } - /* TODO: add an option to control wether AA is enabled or not */ + /* TODO: add an option to control whether AA is enabled or not */ PLX_raskterize((float (*)[2])mask_points, stroke->totpoints, mask, mask_width, mask_height, FALSE); MEM_freeN(mask_points); @@ -916,7 +916,7 @@ void BKE_tracking_track_deselect(MovieTrackingTrack *track, int area) BKE_tracking_track_flag_clear(track, area, SELECT); } -/*********************** Marker *************************/ +/*********************** Marker *************************/ MovieTrackingMarker *BKE_tracking_marker_insert(MovieTrackingTrack *track, MovieTrackingMarker *marker) { @@ -995,8 +995,8 @@ void BKE_tracking_marker_clamp(MovieTrackingMarker *marker, int event) if (event == CLAMP_PAT_DIM) { for (a = 0; a < 2; a++) { /* search shouldn't be resized smaller than pattern */ - marker->search_min[a] = MIN2(pat_min[a], marker->search_min[a]); - marker->search_max[a] = MAX2(pat_max[a], marker->search_max[a]); + marker->search_min[a] = minf(pat_min[a], marker->search_min[a]); + marker->search_max[a] = maxf(pat_max[a], marker->search_max[a]); } } else if (event == CLAMP_PAT_POS) { @@ -1020,8 +1020,8 @@ void BKE_tracking_marker_clamp(MovieTrackingMarker *marker, int event) else if (event == CLAMP_SEARCH_DIM) { for (a = 0; a < 2; a++) { /* search shouldn't be resized smaller than pattern */ - marker->search_min[a] = MIN2(pat_min[a], marker->search_min[a]); - marker->search_max[a] = MAX2(pat_max[a], marker->search_max[a]); + marker->search_min[a] = minf(pat_min[a], marker->search_min[a]); + marker->search_max[a] = maxf(pat_max[a], marker->search_max[a]); } } else if (event == CLAMP_SEARCH_POS) { @@ -1133,6 +1133,36 @@ void BKE_tracking_marker_pattern_minmax(const MovieTrackingMarker *marker, float DO_MINMAX2(marker->pattern_corners[3], min, max); } +void BKE_tracking_marker_get_subframe_position(MovieTrackingTrack *track, float framenr, float pos[2]) +{ + MovieTrackingMarker *marker = BKE_tracking_marker_get(track, (int) framenr); + MovieTrackingMarker *marker_last = track->markers + (track->markersnr - 1); + + if (marker != marker_last) { + MovieTrackingMarker *marker_next = marker + 1; + + if (marker_next->framenr == marker->framenr + 1) { + /* currently only do subframing inside tracked ranges, do not extrapolate tracked segments + * could be changed when / if mask parent would be interpolating position in-between + * tracked segments + */ + + float fac = (framenr - (int) framenr) / (marker_next->framenr - marker->framenr); + + interp_v2_v2v2(pos, marker->pos, marker_next->pos, fac); + } + else { + copy_v2_v2(pos, marker->pos); + } + } + else { + copy_v2_v2(pos, marker->pos); + } + + /* currently track offset is always wanted to be applied here, could be made an option later */ + add_v2_v2(pos, track->offset); +} + /*********************** Object *************************/ MovieTrackingObject *BKE_tracking_object_add(MovieTracking *tracking, const char *name) @@ -1505,7 +1535,7 @@ void BKE_tracking_distortion_free(MovieDistortion *distortion) MEM_freeN(distortion); } -void BKE_tracking_distort_v2(MovieTracking *tracking, float co[2], float nco[2]) +void BKE_tracking_distort_v2(MovieTracking *tracking, const float co[2], float r_co[2]) { MovieTrackingCamera *camera = &tracking->camera; @@ -1521,16 +1551,16 @@ void BKE_tracking_distort_v2(MovieTracking *tracking, float co[2], float nco[2]) camera->k1, camera->k2, camera->k3, x, y, &x, &y); /* result is in image coords already */ - nco[0] = x; - nco[1] = y; + r_co[0] = x; + r_co[1] = y; #else (void) camera; (void) co; - (void) nco; + zero_v2(r_co); #endif } -void BKE_tracking_undistort_v2(MovieTracking *tracking, float co[2], float nco[2]) +void BKE_tracking_undistort_v2(MovieTracking *tracking, const float co[2], float r_co[2]) { MovieTrackingCamera *camera = &tracking->camera; @@ -1541,12 +1571,12 @@ void BKE_tracking_undistort_v2(MovieTracking *tracking, float co[2], float nco[2 libmv_InvertIntrinsics(camera->focal, camera->principal[0], camera->principal[1] * aspy, camera->k1, camera->k2, camera->k3, x, y, &x, &y); - nco[0] = x * camera->focal + camera->principal[0]; - nco[1] = y * camera->focal + camera->principal[1] * aspy; + r_co[0] = x * camera->focal + camera->principal[0]; + r_co[1] = y * camera->focal + camera->principal[1] * aspy; #else (void) camera; (void) co; - (void) nco; + zero_v2(r_co); #endif } @@ -3242,7 +3272,7 @@ static float stabilization_calculate_autoscale_factor(MovieTracking *tracking, i S = (-w * I - h * J) / (dx * I + dy * J + K); - scale = MAX2(scale, S); + scale = maxf(scale, S); } } } @@ -3251,7 +3281,7 @@ static float stabilization_calculate_autoscale_factor(MovieTracking *tracking, i stab->scale = scale; if (stab->maxscale > 0.0f) - stab->scale = MIN2(stab->scale, stab->maxscale); + stab->scale = minf(stab->scale, stab->maxscale); } else { stab->scale = 1.0f; diff --git a/source/blender/blenkernel/intern/writeframeserver.c b/source/blender/blenkernel/intern/writeframeserver.c index a2028ff5fa1..a0f367961d2 100644 --- a/source/blender/blenkernel/intern/writeframeserver.c +++ b/source/blender/blenkernel/intern/writeframeserver.c @@ -128,7 +128,7 @@ int BKE_frameserver_start(struct Scene *scene, RenderData *UNUSED(rd), int rectx return 0; } - setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char*) &arg, sizeof(arg)); + setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &arg, sizeof(arg)); addr.sin_family = AF_INET; addr.sin_port = htons(U.frameserverport); @@ -177,7 +177,7 @@ static char good_bye[] = "
\n"
 "Render stopped. Goodbye
"; -static int safe_write(char * s, int tosend) +static int safe_write(char *s, int tosend) { int total = tosend; do { @@ -192,15 +192,15 @@ static int safe_write(char * s, int tosend) return total; } -static int safe_puts(char * s) +static int safe_puts(char *s) { return safe_write(s, strlen(s)); } -static int handle_request(RenderData *rd, char * req) +static int handle_request(RenderData *rd, char *req) { - char * p; - char * path; + char *p; + char *path; int pathlen; if (memcmp(req, "GET ", 4) != 0) { @@ -230,22 +230,22 @@ static int handle_request(RenderData *rd, char * req) char buf[4096]; sprintf(buf, - "HTTP/1.1 200 OK\r\n" - "Content-Type: text/html\r\n" - "\r\n" - "start %d\n" - "end %d\n" - "width %d\n" - "height %d\n" - "rate %d\n" - "ratescale %d\n", - rd->sfra, - rd->efra, - render_width, - render_height, - rd->frs_sec, - 1 - ); + "HTTP/1.1 200 OK\r\n" + "Content-Type: text/html\r\n" + "\r\n" + "start %d\n" + "end %d\n" + "width %d\n" + "height %d\n" + "rate %d\n" + "ratescale %d\n", + rd->sfra, + rd->efra, + render_width, + render_height, + rd->frs_sec, + 1 + ); safe_puts(buf); return -1; @@ -262,7 +262,7 @@ int BKE_frameserver_loop(RenderData *rd, ReportList *UNUSED(reports)) { fd_set readfds; struct timeval tv; - struct sockaddr_in addr; + struct sockaddr_in addr; int len, rval; #ifdef FREE_WINDOWS int socklen; @@ -305,7 +305,7 @@ int BKE_frameserver_loop(RenderData *rd, ReportList *UNUSED(reports)) tv.tv_sec = 10; tv.tv_usec = 0; - rval = select(connsock + 1, &readfds, NULL, NULL, &tv); + rval = select(connsock + 1, &readfds, NULL, NULL, &tv); if (rval > 0) { break; } @@ -332,30 +332,30 @@ int BKE_frameserver_loop(RenderData *rd, ReportList *UNUSED(reports)) static void serve_ppm(int *pixels, int rectx, int recty) { - unsigned char* rendered_frame; - unsigned char* row = (unsigned char*) malloc(render_width * 3); + unsigned char *rendered_frame; + unsigned char *row = (unsigned char *) malloc(render_width * 3); int y; char header[1024]; sprintf(header, - "HTTP/1.1 200 OK\r\n" - "Content-Type: image/ppm\r\n" - "Connection: close\r\n" - "\r\n" - "P6\n" - "# Creator: blender frameserver v0.0.1\n" - "%d %d\n" - "255\n", - rectx, recty); + "HTTP/1.1 200 OK\r\n" + "Content-Type: image/ppm\r\n" + "Connection: close\r\n" + "\r\n" + "P6\n" + "# Creator: blender frameserver v0.0.1\n" + "%d %d\n" + "255\n", + rectx, recty); safe_puts(header); rendered_frame = (unsigned char *)pixels; for (y = recty - 1; y >= 0; y--) { - unsigned char* target = row; - unsigned char* src = rendered_frame + rectx * 4 * y; - unsigned char* end = src + rectx * 4; + unsigned char *target = row; + unsigned char *src = rendered_frame + rectx * 4 * y; + unsigned char *end = src + rectx * 4; while (src != end) { target[2] = src[2]; target[1] = src[1]; @@ -364,7 +364,7 @@ static void serve_ppm(int *pixels, int rectx, int recty) target += 3; src += 4; } - safe_write((char*)row, 3 * rectx); + safe_write((char *)row, 3 * rectx); } free(row); closesocket(connsock); @@ -372,7 +372,7 @@ static void serve_ppm(int *pixels, int rectx, int recty) } int BKE_frameserver_append(RenderData *UNUSED(rd), int UNUSED(start_frame), int frame, int *pixels, - int rectx, int recty, ReportList *UNUSED(reports)) + int rectx, int recty, ReportList *UNUSED(reports)) { fprintf(stderr, "Serving frame: %d\n", frame); if (write_ppm) { diff --git a/source/blender/blenlib/BLI_math_rotation.h b/source/blender/blenlib/BLI_math_rotation.h index 912534e0aca..a40d4ca8463 100644 --- a/source/blender/blenlib/BLI_math_rotation.h +++ b/source/blender/blenlib/BLI_math_rotation.h @@ -92,7 +92,7 @@ void print_qt(const char *str, const float q[4]); /******************************** Axis Angle *********************************/ /* conversion */ -void axis_angle_to_quat(float r[4], const float axis[3], float angle); +void axis_angle_to_quat(float r[4], const float axis[3], const float angle); void axis_angle_to_mat3(float R[3][3], const float axis[3], const float angle); void axis_angle_to_mat4(float R[4][4], const float axis[3], const float angle); @@ -107,9 +107,7 @@ void single_axis_angle_to_mat3(float R[3][3], const char axis, const float angle /* TODO: the following calls should probably be depreceated sometime */ /* conversion */ -void vec_rot_to_quat(float quat[4], const float vec[3], const float phi); void vec_rot_to_mat3(float mat[3][3], const float vec[3], const float phi); -void vec_rot_to_mat4(float mat[4][4], const float vec[3], const float phi); /******************************** XYZ Eulers *********************************/ diff --git a/source/blender/blenlib/BLI_memarena.h b/source/blender/blenlib/BLI_memarena.h index 2a2dd31b26f..092bb639b91 100644 --- a/source/blender/blenlib/BLI_memarena.h +++ b/source/blender/blenlib/BLI_memarena.h @@ -47,41 +47,44 @@ extern "C" { */ #define BLI_MEMARENA_STD_BUFSIZE (1 << 14) +/* some GNU attributes are only available from GCC 4.3 */ +#define MEM_GNU_ATTRIBUTES (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 403)) + struct MemArena; typedef struct MemArena MemArena; struct MemArena *BLI_memarena_new(const int bufsize, const char *name) -#ifdef __GNUC__ +#if MEM_GNU_ATTRIBUTES __attribute__((warn_unused_result)) __attribute__((nonnull(2))) #endif ; void BLI_memarena_free(struct MemArena *ma) -#ifdef __GNUC__ +#if MEM_GNU_ATTRIBUTES __attribute__((nonnull(1))) #endif ; void BLI_memarena_use_malloc(struct MemArena *ma) -#ifdef __GNUC__ +#if MEM_GNU_ATTRIBUTES __attribute__((nonnull(1))) #endif ; void BLI_memarena_use_calloc(struct MemArena *ma) -#ifdef __GNUC__ +#if MEM_GNU_ATTRIBUTES __attribute__((nonnull(1))) #endif ; void BLI_memarena_use_align(struct MemArena *ma, const int align) -#ifdef __GNUC__ +#if MEM_GNU_ATTRIBUTES __attribute__((nonnull(1))) #endif ; void *BLI_memarena_alloc(struct MemArena *ma, int size) -#ifdef __GNUC__ +#if MEM_GNU_ATTRIBUTES __attribute__((warn_unused_result)) __attribute__((nonnull(1))) __attribute__((alloc_size(2))) diff --git a/source/blender/blenlib/intern/BLI_args.c b/source/blender/blenlib/intern/BLI_args.c index 22b93948512..6a5952465fe 100644 --- a/source/blender/blenlib/intern/BLI_args.c +++ b/source/blender/blenlib/intern/BLI_args.c @@ -88,7 +88,7 @@ static unsigned int case_strhash(const void *ptr) static unsigned int keyhash(const void *ptr) { const bAKey *k = ptr; - return case_strhash(k->arg); // ^ BLI_ghashutil_inthash((void*)k->pass); + return case_strhash(k->arg); /* ^ BLI_ghashutil_inthash((void *)k->pass); */ } static int keycmp(const void *a, const void *b) diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c index 9a2b94b2c7e..2b3c314131b 100644 --- a/source/blender/blenlib/intern/BLI_kdopbvh.c +++ b/source/blender/blenlib/intern/BLI_kdopbvh.c @@ -648,7 +648,7 @@ static int implicit_leafs_index(BVHBuildHelper *data, int depth, int child_index // This functions returns the number of branches needed to have the requested number of leafs. static int implicit_needed_branches(int tree_type, int leafs) { - return MAX2(1, (leafs + tree_type - 3) / (tree_type - 1) ); + return maxi(1, (leafs + tree_type - 3) / (tree_type - 1) ); } /* diff --git a/source/blender/blenlib/intern/DLRB_tree.c b/source/blender/blenlib/intern/DLRB_tree.c index 53ae086782b..930ab4fc400 100644 --- a/source/blender/blenlib/intern/DLRB_tree.c +++ b/source/blender/blenlib/intern/DLRB_tree.c @@ -330,7 +330,7 @@ static void rotate_left(DLRBT_Tree *tree, DLRBT_Node *root) root_slot = &root->parent->right; } else - root_slot = ((DLRBT_Node **)&tree->root); //&((DLRBT_Node*)tree->root); + root_slot = ((DLRBT_Node **)&tree->root); /* &((DLRBT_Node *)tree->root); */ /* - pivot's left child becomes root's right child * - root now becomes pivot's left child @@ -364,7 +364,7 @@ static void rotate_right(DLRBT_Tree *tree, DLRBT_Node *root) root_slot = &root->parent->right; } else - root_slot = ((DLRBT_Node **)&tree->root); //&((DLRBT_Node*)tree->root); + root_slot = ((DLRBT_Node **)&tree->root); /* &((DLRBT_Node*)tree->root); */ /* - pivot's right child becomes root's left child * - root now becomes pivot's right child diff --git a/source/blender/blenlib/intern/bpath.c b/source/blender/blenlib/intern/bpath.c index 85391336c86..d030506f4a6 100644 --- a/source/blender/blenlib/intern/bpath.c +++ b/source/blender/blenlib/intern/bpath.c @@ -192,12 +192,14 @@ void BLI_bpath_absolute_convert(Main *bmain, const char *basedir, ReportList *re data.count_tot, data.count_changed, data.count_failed); } -/* find this file recursively, use the biggest file so thumbnails don't get used by mistake - * - dir: subdir to search - * - filename: set this filename - * - filesize: filesize for the file +/** + * find this file recursively, use the biggest file so thumbnails don't get used by mistake + * \param filename_new: the path will be copied here, caller must initialize as empyu string. + * \param dirname: subdir to search + * \param filename: set this filename + * \param filesize: filesize for the file * - * return found: 1/0. + * \returns found: 1/0. */ #define MAX_RECUR 16 static int findFileRecursive(char *filename_new, @@ -214,8 +216,6 @@ static int findFileRecursive(char *filename_new, int size; int found = FALSE; - filename_new[0] = '\0'; - dir = opendir(dirname); if (dir == NULL) @@ -272,6 +272,8 @@ static int findMissingFiles_visit_cb(void *userdata, char *path_dst, const char int recur_depth = 0; int found; + filename_new[0] = '\0'; + found = findFileRecursive(filename_new, data->searchdir, BLI_path_basename((char *)path_src), &filesize, &recur_depth); diff --git a/source/blender/blenlib/intern/freetypefont.c b/source/blender/blenlib/intern/freetypefont.c index 6ce8b9ecf91..774e37a8476 100644 --- a/source/blender/blenlib/intern/freetypefont.c +++ b/source/blender/blenlib/intern/freetypefont.c @@ -556,7 +556,7 @@ typedef struct FT_Outline_ * Type1 format. * * Each arc is described through a series of start, end and control points. Each point of the outline - * has a specific tag which indicates wether it is used to describe a line segment or an arc. + * has a specific tag which indicates whether it is used to describe a line segment or an arc. * * * The following rules are applied to decompose the contour's points into segments and arcs : diff --git a/source/blender/blenlib/intern/lasso.c b/source/blender/blenlib/intern/lasso.c index 29b967fcd37..7df4da80e16 100644 --- a/source/blender/blenlib/intern/lasso.c +++ b/source/blender/blenlib/intern/lasso.c @@ -95,7 +95,7 @@ int BLI_lasso_is_point_inside(int mcords[][2], short moves, p2 = mcords[a + 1]; } - if (fabs(angletot) > 4.0) return 1; + if (fabsf(angletot) > 4.0f) return 1; return 0; } diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c index b2d5392c596..97fc431d8fa 100644 --- a/source/blender/blenlib/intern/math_base_inline.c +++ b/source/blender/blenlib/intern/math_base_inline.c @@ -143,12 +143,20 @@ MINLINE float minf(float a, float b) { return (a < b) ? a : b; } - MINLINE float maxf(float a, float b) { return (a > b) ? a : b; } +MINLINE int mini(int a, int b) +{ + return (a < b) ? a : b; +} +MINLINE int maxi(int a, int b) +{ + return (b < a) ? a : b; +} + MINLINE float signf(float f) { return (f < 0.f) ? -1.f : 1.f; diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index f2ea93282c9..b908a32bf4c 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -583,17 +583,17 @@ static short IsectLLPt2Df(const float x0, const float y0, const float x1, const * compute slopes, note the cludge for infinity, however, this will * be close enough */ - if (fabs(x1 - x0) > 0.000001f) + if (fabsf(x1 - x0) > 0.000001f) m1 = (y1 - y0) / (x1 - x0); else return -1; /*m1 = (float)1e+10;*/ /* close enough to infinity */ - if (fabs(x3 - x2) > 0.000001f) + if (fabsf(x3 - x2) > 0.000001f) m2 = (y3 - y2) / (x3 - x2); else return -1; /*m2 = (float)1e+10;*/ /* close enough to infinity */ - if (fabs(m1 - m2) < 0.000001f) + if (fabsf(m1 - m2) < 0.000001f) return -1; /* parallel lines */ /* compute constants */ @@ -2367,7 +2367,8 @@ void resolve_quad_uv(float r_uv[2], const float st[2], const float st0[2], const /***************************** View & Projection *****************************/ -void orthographic_m4(float matrix[][4], const float left, const float right, const float bottom, const float top, const float nearClip, const float farClip) +void orthographic_m4(float matrix[][4], const float left, const float right, const float bottom, const float top, + const float nearClip, const float farClip) { float Xdelta, Ydelta, Zdelta; @@ -2386,7 +2387,8 @@ void orthographic_m4(float matrix[][4], const float left, const float right, con matrix[3][2] = -(farClip + nearClip) / Zdelta; } -void perspective_m4(float mat[4][4], const float left, const float right, const float bottom, const float top, const float nearClip, const float farClip) +void perspective_m4(float mat[4][4], const float left, const float right, const float bottom, const float top, + const float nearClip, const float farClip) { float Xdelta, Ydelta, Zdelta; diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c index ab5601fc2dc..a2da9f5f791 100644 --- a/source/blender/blenlib/intern/math_rotation.c +++ b/source/blender/blenlib/intern/math_rotation.c @@ -166,10 +166,9 @@ void sub_qt_qtqt(float q[4], const float q1[4], const float q2[4]) /* angular mult factor */ void mul_fac_qt_fl(float q[4], const float fac) { - float angle = fac * saacos(q[0]); /* quat[0] = cos(0.5 * angle), but now the 0.5 and 2.0 rule out */ - - float co = (float)cos(angle); - float si = (float)sin(angle); + const float angle = fac * saacos(q[0]); /* quat[0] = cos(0.5 * angle), but now the 0.5 and 2.0 rule out */ + const float co = cosf(angle); + const float si = sinf(angle); q[0] = co; normalize_v3(q + 1); mul_v3_fl(q + 1, si); @@ -342,8 +341,8 @@ void mat3_to_quat_is_ok(float q[4], float wmat[3][3]) co = mat[2][2]; angle = 0.5f * saacos(co); - co = (float)cos(angle); - si = (float)sin(angle); + co = cosf(angle); + si = sinf(angle); q1[0] = co; q1[1] = -nor[0] * si; /* negative here, but why? */ q1[2] = -nor[1] * si; @@ -357,8 +356,8 @@ void mat3_to_quat_is_ok(float q[4], float wmat[3][3]) /* and align x-axes */ angle = (float)(0.5 * atan2(mat[0][1], mat[0][0])); - co = (float)cos(angle); - si = (float)sin(angle); + co = cosf(angle); + si = sinf(angle); q2[0] = co; q2[1] = 0.0f; q2[2] = 0.0f; @@ -453,7 +452,7 @@ void vec_to_quat(float q[4], const float vec[3], short axis, const short upflag) nor[1] = -z2; nor[2] = y2; - if (fabs(y2) + fabs(z2) < 0.0001) + if (fabsf(y2) + fabsf(z2) < 0.0001f) nor[1] = 1.0; co = x2; @@ -463,7 +462,7 @@ void vec_to_quat(float q[4], const float vec[3], short axis, const short upflag) nor[1] = 0.0; nor[2] = -x2; - if (fabs(x2) + fabs(z2) < 0.0001) + if (fabsf(x2) + fabsf(z2) < 0.0001f) nor[2] = 1.0; co = y2; @@ -473,7 +472,7 @@ void vec_to_quat(float q[4], const float vec[3], short axis, const short upflag) nor[1] = x2; nor[2] = 0.0; - if (fabs(x2) + fabs(y2) < 0.0001) + if (fabsf(x2) + fabsf(y2) < 0.0001f) nor[0] = 1.0; co = z2; @@ -483,8 +482,8 @@ void vec_to_quat(float q[4], const float vec[3], short axis, const short upflag) normalize_v3(nor); angle = 0.5f * saacos(co); - si = (float)sin(angle); - q[0] = (float)cos(angle); + si = sinf(angle); + q[0] = cosf(angle); q[1] = nor[0] * si; q[2] = nor[1] * si; q[3] = nor[2] * si; @@ -615,16 +614,18 @@ void tri_to_quat(float quat[4], const float v1[3], const float v2[3], const floa /* move z-axis to face-normal */ normal_tri_v3(vec, v1, v2, v3); - n[0] = vec[1]; + n[0] = vec[1]; n[1] = -vec[0]; - n[2] = 0.0f; + n[2] = 0.0f; normalize_v3(n); - if (n[0] == 0.0f && n[1] == 0.0f) n[0] = 1.0f; + if (n[0] == 0.0f && n[1] == 0.0f) { + n[0] = 1.0f; + } angle = -0.5f * (float)saacos(vec[2]); - co = (float)cos(angle); - si = (float)sin(angle); + co = cosf(angle); + si = sinf(angle); q1[0] = co; q1[1] = n[0] * si; q1[2] = n[1] * si; @@ -641,8 +642,8 @@ void tri_to_quat(float quat[4], const float v1[3], const float v2[3], const floa normalize_v3(vec); angle = (float)(0.5 * atan2(vec[1], vec[0])); - co = (float)cos(angle); - si = (float)sin(angle); + co = cosf(angle); + si = sinf(angle); q2[0] = co; q2[1] = 0.0f; q2[2] = 0.0f; @@ -659,22 +660,22 @@ void print_qt(const char *str, const float q[4]) /******************************** Axis Angle *********************************/ /* Axis angle to Quaternions */ -void axis_angle_to_quat(float q[4], const float axis[3], float angle) +void axis_angle_to_quat(float q[4], const float axis[3], const float angle) { float nor[3]; - float si; - if (normalize_v3_v3(nor, axis) == 0.0f) { - unit_qt(q); - return; + if (LIKELY(normalize_v3_v3(nor, axis) != 0.0f)) { + const float phi = angle / 2.0f; + float si; + si = sinf(phi); + q[0] = cosf(phi); + q[1] = nor[0] * si; + q[2] = nor[1] * si; + q[3] = nor[2] * si; + } + else { + unit_qt(q); } - - angle /= 2; - si = (float)sin(angle); - q[0] = (float)cos(angle); - q[1] = nor[0] * si; - q[2] = nor[1] * si; - q[3] = nor[2] * si; } /* Quaternions to Axis Angle */ @@ -689,14 +690,14 @@ void quat_to_axis_angle(float axis[3], float *angle, const float q[4]) #endif /* calculate angle/2, and sin(angle/2) */ - ha = (float)acos(q[0]); - si = (float)sin(ha); + ha = acosf(q[0]); + si = sinf(ha); /* from half-angle to angle */ *angle = ha * 2; /* prevent division by zero for axis conversion */ - if (fabs(si) < 0.0005) + if (fabsf(si) < 0.0005f) si = 1.0f; axis[0] = q[1] / si; @@ -739,8 +740,8 @@ void axis_angle_to_mat3(float mat[3][3], const float axis[3], const float angle) } /* now convert this to a 3x3 matrix */ - co = (float)cos(angle); - si = (float)sin(angle); + co = cosf(angle); + si = sinf(angle); ico = (1.0f - co); nsi[0] = nor[0] * si; @@ -837,7 +838,7 @@ void single_axis_angle_to_mat3(float mat[3][3], const char axis, const float ang /****************************** Vector/Rotation ******************************/ /* TODO: the following calls should probably be depreceated sometime */ -/* ODO, replace use of this function with axis_angle_to_mat3() */ +/* TODO, replace use of this function with axis_angle_to_mat3() */ void vec_rot_to_mat3(float mat[][3], const float vec[3], const float phi) { /* rotation of phi radials around vec */ @@ -849,8 +850,8 @@ void vec_rot_to_mat3(float mat[][3], const float vec[3], const float phi) vx2 = vx * vx; vy2 = vy * vy; vz2 = vz * vz; - co = (float)cos(phi); - si = (float)sin(phi); + co = cosf(phi); + si = sinf(phi); mat[0][0] = vx2 + co * (1.0f - vx2); mat[0][1] = vx * vy * (1.0f - co) + vz * si; @@ -863,38 +864,6 @@ void vec_rot_to_mat3(float mat[][3], const float vec[3], const float phi) mat[2][2] = vz2 + co * (1.0f - vz2); } -/* axis angle to 4x4 matrix */ -void vec_rot_to_mat4(float mat[][4], const float vec[3], const float phi) -{ - float tmat[3][3]; - - vec_rot_to_mat3(tmat, vec, phi); - unit_m4(mat); - copy_m4_m3(mat, tmat); -} - -/* axis angle to quaternion */ -void vec_rot_to_quat(float *quat, const float vec[3], const float phi) -{ - /* rotation of phi radials around vec */ - float si; - - quat[1] = vec[0]; - quat[2] = vec[1]; - quat[3] = vec[2]; - - if (normalize_v3(quat + 1) == 0.0f) { - unit_qt(quat); - } - else { - quat[0] = (float)cos((double)phi / 2.0); - si = (float)sin((double)phi / 2.0); - quat[1] *= si; - quat[2] *= si; - quat[3] *= si; - } -} - /******************************** XYZ Eulers *********************************/ /* XYZ order */ @@ -998,7 +967,7 @@ void mat3_to_eul(float *eul, float tmat[][3]) mat3_to_eul2(tmat, eul1, eul2); /* return best, which is just the one with lowest values it in */ - if (fabs(eul1[0]) + fabs(eul1[1]) + fabs(eul1[2]) > fabs(eul2[0]) + fabs(eul2[1]) + fabs(eul2[2])) { + if (fabsf(eul1[0]) + fabsf(eul1[1]) + fabsf(eul1[2]) > fabsf(eul2[0]) + fabsf(eul2[1]) + fabsf(eul2[2])) { copy_v3_v3(eul, eul2); } else { @@ -1083,32 +1052,32 @@ void compatible_eul(float eul[3], const float oldrot[3]) dy = eul[1] - oldrot[1]; dz = eul[2] - oldrot[2]; - while (fabs(dx) > 5.1) { + while (fabsf(dx) > 5.1f) { if (dx > 0.0f) eul[0] -= 2.0f * (float)M_PI; else eul[0] += 2.0f * (float)M_PI; dx = eul[0] - oldrot[0]; } - while (fabs(dy) > 5.1) { + while (fabsf(dy) > 5.1f) { if (dy > 0.0f) eul[1] -= 2.0f * (float)M_PI; else eul[1] += 2.0f * (float)M_PI; dy = eul[1] - oldrot[1]; } - while (fabs(dz) > 5.1) { + while (fabsf(dz) > 5.1f) { if (dz > 0.0f) eul[2] -= 2.0f * (float)M_PI; else eul[2] += 2.0f * (float)M_PI; dz = eul[2] - oldrot[2]; } /* is 1 of the axis rotations larger than 180 degrees and the other small? NO ELSE IF!! */ - if (fabs(dx) > 3.2 && fabs(dy) < 1.6 && fabs(dz) < 1.6) { + if (fabsf(dx) > 3.2f && fabsf(dy) < 1.6f && fabsf(dz) < 1.6f) { if (dx > 0.0f) eul[0] -= 2.0f * (float)M_PI; else eul[0] += 2.0f * (float)M_PI; } - if (fabs(dy) > 3.2 && fabs(dz) < 1.6 && fabs(dx) < 1.6) { + if (fabsf(dy) > 3.2f && fabsf(dz) < 1.6f && fabsf(dx) < 1.6f) { if (dy > 0.0f) eul[1] -= 2.0f * (float)M_PI; else eul[1] += 2.0f * (float)M_PI; } - if (fabs(dz) > 3.2 && fabs(dx) < 1.6 && fabs(dy) < 1.6) { + if (fabsf(dz) > 3.2f && fabsf(dx) < 1.6f && fabsf(dy) < 1.6f) { if (dz > 0.0f) eul[2] -= 2.0f * (float)M_PI; else eul[2] += 2.0f * (float)M_PI; } @@ -1123,29 +1092,29 @@ void compatible_eul(float eul[3], const float oldrot[3]) /* special case, tested for x-z */ - if ((fabs(dx) > 3.1 && fabs(dz) > 1.5) || (fabs(dx) > 1.5 && fabs(dz) > 3.1)) { - if (dx > 0.0) eul[0] -= M_PI; + if ((fabsf(dx) > 3.1f && fabsf(dz) > 1.5f) || (fabsf(dx) > 1.5f && fabsf(dz) > 3.1f)) { + if (dx > 0.0f) eul[0] -= M_PI; else eul[0] += M_PI; if (eul[1] > 0.0) eul[1] = M_PI - eul[1]; else eul[1] = -M_PI - eul[1]; - if (dz > 0.0) eul[2] -= M_PI; + if (dz > 0.0f) eul[2] -= M_PI; else eul[2] += M_PI; } - else if ((fabs(dx) > 3.1 && fabs(dy) > 1.5) || (fabs(dx) > 1.5 && fabs(dy) > 3.1)) { - if (dx > 0.0) eul[0] -= M_PI; + else if ((fabsf(dx) > 3.1f && fabsf(dy) > 1.5f) || (fabsf(dx) > 1.5f && fabsf(dy) > 3.1f)) { + if (dx > 0.0f) eul[0] -= M_PI; else eul[0] += M_PI; - if (dy > 0.0) eul[1] -= M_PI; + if (dy > 0.0f) eul[1] -= M_PI; else eul[1] += M_PI; - if (eul[2] > 0.0) eul[2] = M_PI - eul[2]; + if (eul[2] > 0.0f) eul[2] = M_PI - eul[2]; else eul[2] = -M_PI - eul[2]; } - else if ((fabs(dy) > 3.1 && fabs(dz) > 1.5) || (fabs(dy) > 1.5 && fabs(dz) > 3.1)) { - if (eul[0] > 0.0) eul[0] = M_PI - eul[0]; + else if ((fabsf(dy) > 3.1f && fabsf(dz) > 1.5f) || (fabsf(dy) > 1.5f && fabsf(dz) > 3.f1)) { + if (eul[0] > 0.0f) eul[0] = M_PI - eul[0]; else eul[0] = -M_PI - eul[0]; - if (dy > 0.0) eul[1] -= M_PI; + if (dy > 0.0f) eul[1] -= M_PI; else eul[1] += M_PI; - if (dz > 0.0) eul[2] -= M_PI; + if (dz > 0.0f) eul[2] -= M_PI; else eul[2] += M_PI; } #endif @@ -1164,8 +1133,8 @@ void mat3_to_compatible_eul(float eul[3], const float oldrot[3], float mat[][3]) compatible_eul(eul1, oldrot); compatible_eul(eul2, oldrot); - d1 = (float)fabs(eul1[0] - oldrot[0]) + (float)fabs(eul1[1] - oldrot[1]) + (float)fabs(eul1[2] - oldrot[2]); - d2 = (float)fabs(eul2[0] - oldrot[0]) + (float)fabs(eul2[1] - oldrot[1]) + (float)fabs(eul2[2] - oldrot[2]); + d1 = fabsf(eul1[0] - oldrot[0]) + fabsf(eul1[1] - oldrot[1]) + fabsf(eul1[2] - oldrot[2]); + d2 = fabsf(eul2[0] - oldrot[0]) + fabsf(eul2[1] - oldrot[1]) + fabsf(eul2[2] - oldrot[2]); /* return best, which is just the one with lowest difference */ if (d1 > d2) { @@ -1360,7 +1329,7 @@ void mat3_to_eulO(float eul[3], const short order, float M[3][3]) mat3_to_eulo2(M, eul1, eul2, order); /* return best, which is just the one with lowest values it in */ - if (fabs(eul1[0]) + fabs(eul1[1]) + fabs(eul1[2]) > fabs(eul2[0]) + fabs(eul2[1]) + fabs(eul2[2])) { + if (fabsf(eul1[0]) + fabsf(eul1[1]) + fabsf(eul1[2]) > fabsf(eul2[0]) + fabsf(eul2[1]) + fabsf(eul2[2])) { copy_v3_v3(eul, eul2); } else { diff --git a/source/blender/blenlib/intern/pbvh.c b/source/blender/blenlib/intern/pbvh.c index 14f9001814c..b4b546d9167 100644 --- a/source/blender/blenlib/intern/pbvh.c +++ b/source/blender/blenlib/intern/pbvh.c @@ -189,8 +189,8 @@ static void BB_expand(BB *bb, float co[3]) { int i; for (i = 0; i < 3; ++i) { - bb->bmin[i] = MIN2(bb->bmin[i], co[i]); - bb->bmax[i] = MAX2(bb->bmax[i], co[i]); + bb->bmin[i] = minf(bb->bmin[i], co[i]); + bb->bmax[i] = maxf(bb->bmax[i], co[i]); } } @@ -199,8 +199,8 @@ static void BB_expand_with_bb(BB *bb, BB *bb2) { int i; for (i = 0; i < 3; ++i) { - bb->bmin[i] = MIN2(bb->bmin[i], bb2->bmin[i]); - bb->bmax[i] = MAX2(bb->bmax[i], bb2->bmax[i]); + bb->bmin[i] = minf(bb->bmin[i], bb2->bmin[i]); + bb->bmax[i] = maxf(bb->bmax[i], bb2->bmax[i]); } } @@ -663,7 +663,7 @@ void BLI_pbvh_build_grids(PBVH *bvh, CCGElem **grids, DMGridAdjacency *gridadj, bvh->totgrid = totgrid; bvh->gridkey = *key; bvh->grid_hidden = grid_hidden; - bvh->leaf_limit = MAX2(LEAF_LIMIT / ((gridsize - 1) * (gridsize - 1)), 1); + bvh->leaf_limit = maxi(LEAF_LIMIT / ((gridsize - 1) * (gridsize - 1)), 1); BB_reset(&cb); diff --git a/source/blender/blenlib/intern/scanfill.c b/source/blender/blenlib/intern/scanfill.c index 1f0bd445831..25191370130 100644 --- a/source/blender/blenlib/intern/scanfill.c +++ b/source/blender/blenlib/intern/scanfill.c @@ -658,7 +658,7 @@ static int scanfill(ScanFillContext *sf_ctx, PolyFill *pf) if (v1 == v2 || v2 == v3) break; /* printf("test verts %x %x %x\n",v1,v2,v3); */ miny = minf(v1->xy[1], v3->xy[1]); - /* miny= MIN2(v1->xy[1],v3->xy[1]); */ + /* miny= minf(v1->xy[1],v3->xy[1]); */ sc1 = sc + 1; test = 0; diff --git a/source/blender/blenlib/intern/voronoi.c b/source/blender/blenlib/intern/voronoi.c index dc76fb1493d..f61df9c11f5 100644 --- a/source/blender/blenlib/intern/voronoi.c +++ b/source/blender/blenlib/intern/voronoi.c @@ -259,9 +259,9 @@ static float voronoi_getXOfEdge(VoronoiProcess *process, VoronoiParabola *par, f x2 = (-b - sqrtf(disc)) / (2 * a); if (p[1] < r[1]) - ry = MAX2(x1, x2); + ry = maxf(x1, x2); else - ry = MIN2(x1, x2); + ry = minf(x1, x2); return ry; } diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 29e3f418dd3..29616898124 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -762,7 +762,7 @@ BHead *blo_firstbhead(FileData *fd) BHead *blo_prevbhead(FileData *UNUSED(fd), BHead *thisblock) { - BHeadN *bheadn = (BHeadN *) (((char *) thisblock) - GET_INT_FROM_POINTER( &((BHeadN*)0)->bhead) ); + BHeadN *bheadn = (BHeadN *) (((char *) thisblock) - offsetof(BHeadN, bhead)); BHeadN *prev = bheadn->prev; return (prev) ? &prev->bhead : NULL; @@ -774,11 +774,11 @@ BHead *blo_nextbhead(FileData *fd, BHead *thisblock) BHead *bhead = NULL; if (thisblock) { - // bhead is actually a sub part of BHeadN - // We calculate the BHeadN pointer from the BHead pointer below - new_bhead = (BHeadN *) (((char *) thisblock) - GET_INT_FROM_POINTER( &((BHeadN*)0)->bhead) ); + /* bhead is actually a sub part of BHeadN + * We calculate the BHeadN pointer from the BHead pointer below */ + new_bhead = (BHeadN *) (((char *) thisblock) - offsetof(BHeadN, bhead)); - // get the next BHeadN. If it doesn't exist we read in the next one + /* get the next BHeadN. If it doesn't exist we read in the next one */ new_bhead = new_bhead->next; if (new_bhead == NULL) { new_bhead = get_bhead(fd); @@ -786,8 +786,8 @@ BHead *blo_nextbhead(FileData *fd, BHead *thisblock) } if (new_bhead) { - // here we do the reverse: - // go from the BHeadN pointer to the BHead pointer + /* here we do the reverse: + * go from the BHeadN pointer to the BHead pointer */ bhead = &new_bhead->bhead; } @@ -1668,8 +1668,8 @@ static void lib_link_brush(FileData *fd, Main *main) /* only link ID pointers */ for (brush = main->brush.first; brush; brush = brush->id.next) { - if (brush->id.flag & LIB_NEEDLINK) { - brush->id.flag -= LIB_NEEDLINK; + if (brush->id.flag & LIB_NEED_LINK) { + brush->id.flag -= LIB_NEED_LINK; brush->mtex.tex = newlibadr_us(fd, brush->id.lib, brush->mtex.tex); brush->clone.image = newlibadr_us(fd, brush->id.lib, brush->clone.image); @@ -1740,13 +1740,13 @@ static void lib_link_ipo(FileData *fd, Main *main) Ipo *ipo; for (ipo = main->ipo.first; ipo; ipo = ipo->id.next) { - if (ipo->id.flag & LIB_NEEDLINK) { + if (ipo->id.flag & LIB_NEED_LINK) { IpoCurve *icu; for (icu = ipo->curve.first; icu; icu = icu->next) { if (icu->driver) icu->driver->ob = newlibadr(fd, ipo->id.lib, icu->driver->ob); } - ipo->id.flag -= LIB_NEEDLINK; + ipo->id.flag -= LIB_NEED_LINK; } } } @@ -1914,14 +1914,25 @@ static void direct_link_fcurves(FileData *fd, ListBase *list) /* group */ fcu->grp = newdataadr(fd, fcu->grp); + /* clear disabled flag - allows disabled drivers to be tried again ([#32155]), + * but also means that another method for "reviving disabled F-Curves" exists + */ + fcu->flag &= ~FCURVE_DISABLED; + /* driver */ fcu->driver= newdataadr(fd, fcu->driver); if (fcu->driver) { ChannelDriver *driver= fcu->driver; DriverVar *dvar; + /* compiled expression data will need to be regenerated (old pointer may still be set here) */ driver->expr_comp = NULL; + /* give the driver a fresh chance - the operating environment may be different now + * (addons, etc. may be different) so the driver namespace may be sane now [#32155] + */ + driver->flag &= ~DRIVER_FLAG_INVALID; + /* relink variables, targets and their paths */ link_list(fd, &driver->variables); for (dvar= driver->variables.first; dvar; dvar= dvar->next) { @@ -1950,8 +1961,8 @@ static void lib_link_action(FileData *fd, Main *main) bActionChannel *chan; for (act = main->action.first; act; act = act->id.next) { - if (act->id.flag & LIB_NEEDLINK) { - act->id.flag -= LIB_NEEDLINK; + if (act->id.flag & LIB_NEED_LINK) { + act->id.flag -= LIB_NEED_LINK; // XXX depreceated - old animation system <<< for (chan=act->chanbase.first; chan; chan=chan->next) { @@ -2177,8 +2188,8 @@ static void lib_link_nodetree(FileData *fd, Main *main) /* only link ID pointers */ for (ntree = main->nodetree.first; ntree; ntree = ntree->id.next) { - if (ntree->id.flag & LIB_NEEDLINK) { - ntree->id.flag -= LIB_NEEDLINK; + if (ntree->id.flag & LIB_NEED_LINK) { + ntree->id.flag -= LIB_NEED_LINK; lib_link_ntree(fd, &ntree->id, ntree); } } @@ -2600,9 +2611,9 @@ static void lib_link_armature(FileData *fd, Main *main) bArmature *arm; for (arm = main->armature.first; arm; arm = arm->id.next) { - if (arm->id.flag & LIB_NEEDLINK) { + if (arm->id.flag & LIB_NEED_LINK) { if (arm->adt) lib_link_animdata(fd, &arm->id, arm->adt); - arm->id.flag -= LIB_NEEDLINK; + arm->id.flag -= LIB_NEED_LINK; } } } @@ -2650,14 +2661,14 @@ static void lib_link_camera(FileData *fd, Main *main) Camera *ca; for (ca = main->camera.first; ca; ca = ca->id.next) { - if (ca->id.flag & LIB_NEEDLINK) { + if (ca->id.flag & LIB_NEED_LINK) { if (ca->adt) lib_link_animdata(fd, &ca->id, ca->adt); ca->ipo = newlibadr_us(fd, ca->id.lib, ca->ipo); // XXX depreceated - old animation system ca->dof_ob = newlibadr_us(fd, ca->id.lib, ca->dof_ob); - ca->id.flag -= LIB_NEEDLINK; + ca->id.flag -= LIB_NEED_LINK; } } } @@ -2678,7 +2689,7 @@ static void lib_link_lamp(FileData *fd, Main *main) int a; for (la = main->lamp.first; la; la = la->id.next) { - if (la->id.flag & LIB_NEEDLINK) { + if (la->id.flag & LIB_NEED_LINK) { if (la->adt) lib_link_animdata(fd, &la->id, la->adt); for (a = 0; a < MAX_MTEX; a++) { @@ -2694,7 +2705,7 @@ static void lib_link_lamp(FileData *fd, Main *main) if (la->nodetree) lib_link_ntree(fd, &la->id, la->nodetree); - la->id.flag -= LIB_NEEDLINK; + la->id.flag -= LIB_NEED_LINK; } } } @@ -2738,13 +2749,13 @@ static void lib_link_key(FileData *fd, Main *main) } } - if (key->id.flag & LIB_NEEDLINK) { + if (key->id.flag & LIB_NEED_LINK) { if (key->adt) lib_link_animdata(fd, &key->id, key->adt); key->ipo = newlibadr_us(fd, key->id.lib, key->ipo); // XXX depreceated - old animation system key->from = newlibadr(fd, key->id.lib, key->from); - key->id.flag -= LIB_NEEDLINK; + key->id.flag -= LIB_NEED_LINK; } } } @@ -2808,7 +2819,7 @@ static void lib_link_mball(FileData *fd, Main *main) int a; for (mb = main->mball.first; mb; mb = mb->id.next) { - if (mb->id.flag & LIB_NEEDLINK) { + if (mb->id.flag & LIB_NEED_LINK) { if (mb->adt) lib_link_animdata(fd, &mb->id, mb->adt); for (a = 0; a < mb->totcol; a++) @@ -2816,7 +2827,7 @@ static void lib_link_mball(FileData *fd, Main *main) mb->ipo = newlibadr_us(fd, mb->id.lib, mb->ipo); // XXX depreceated - old animation system - mb->id.flag -= LIB_NEEDLINK; + mb->id.flag -= LIB_NEED_LINK; } } } @@ -2847,7 +2858,7 @@ static void lib_link_world(FileData *fd, Main *main) int a; for (wrld = main->world.first; wrld; wrld = wrld->id.next) { - if (wrld->id.flag & LIB_NEEDLINK) { + if (wrld->id.flag & LIB_NEED_LINK) { if (wrld->adt) lib_link_animdata(fd, &wrld->id, wrld->adt); wrld->ipo = newlibadr_us(fd, wrld->id.lib, wrld->ipo); // XXX depreceated - old animation system @@ -2863,7 +2874,7 @@ static void lib_link_world(FileData *fd, Main *main) if (wrld->nodetree) lib_link_ntree(fd, &wrld->id, wrld->nodetree); - wrld->id.flag -= LIB_NEEDLINK; + wrld->id.flag -= LIB_NEED_LINK; } } } @@ -2894,8 +2905,8 @@ static void lib_link_vfont(FileData *UNUSED(fd), Main *main) VFont *vf; for (vf = main->vfont.first; vf; vf = vf->id.next) { - if (vf->id.flag & LIB_NEEDLINK) { - vf->id.flag -= LIB_NEEDLINK; + if (vf->id.flag & LIB_NEED_LINK) { + vf->id.flag -= LIB_NEED_LINK; } } } @@ -2913,8 +2924,8 @@ static void lib_link_text(FileData *UNUSED(fd), Main *main) Text *text; for (text = main->text.first; text; text = text->id.next) { - if (text->id.flag & LIB_NEEDLINK) { - text->id.flag -= LIB_NEEDLINK; + if (text->id.flag & LIB_NEED_LINK) { + text->id.flag -= LIB_NEED_LINK; } } } @@ -2966,10 +2977,10 @@ static void lib_link_image(FileData *fd, Main *main) Image *ima; for (ima = main->image.first; ima; ima = ima->id.next) { - if (ima->id.flag & LIB_NEEDLINK) { + if (ima->id.flag & LIB_NEED_LINK) { if (ima->id.properties) IDP_LibLinkProperty(ima->id.properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); - ima->id.flag -= LIB_NEEDLINK; + ima->id.flag -= LIB_NEED_LINK; } } } @@ -3036,7 +3047,7 @@ static void lib_link_curve(FileData *fd, Main *main) int a; for (cu = main->curve.first; cu; cu = cu->id.next) { - if (cu->id.flag & LIB_NEEDLINK) { + if (cu->id.flag & LIB_NEED_LINK) { if (cu->adt) lib_link_animdata(fd, &cu->id, cu->adt); for (a = 0; a < cu->totcol; a++) @@ -3053,7 +3064,7 @@ static void lib_link_curve(FileData *fd, Main *main) cu->ipo = newlibadr_us(fd, cu->id.lib, cu->ipo); // XXX depreceated - old animation system cu->key = newlibadr_us(fd, cu->id.lib, cu->key); - cu->id.flag -= LIB_NEEDLINK; + cu->id.flag -= LIB_NEED_LINK; } } } @@ -3138,7 +3149,7 @@ static void lib_link_texture(FileData *fd, Main *main) Tex *tex; for (tex = main->tex.first; tex; tex = tex->id.next) { - if (tex->id.flag & LIB_NEEDLINK) { + if (tex->id.flag & LIB_NEED_LINK) { if (tex->adt) lib_link_animdata(fd, &tex->id, tex->adt); tex->ima = newlibadr_us(fd, tex->id.lib, tex->ima); @@ -3155,7 +3166,7 @@ static void lib_link_texture(FileData *fd, Main *main) if (tex->nodetree) lib_link_ntree(fd, &tex->id, tex->nodetree); - tex->id.flag -= LIB_NEEDLINK; + tex->id.flag -= LIB_NEED_LINK; } } } @@ -3214,7 +3225,7 @@ static void lib_link_material(FileData *fd, Main *main) int a; for (ma = main->mat.first; ma; ma = ma->id.next) { - if (ma->id.flag & LIB_NEEDLINK) { + if (ma->id.flag & LIB_NEED_LINK) { if (ma->adt) lib_link_animdata(fd, &ma->id, ma->adt); /* Link ID Properties -- and copy this comment EXACTLY for easy finding @@ -3235,7 +3246,7 @@ static void lib_link_material(FileData *fd, Main *main) if (ma->nodetree) lib_link_ntree(fd, &ma->id, ma->nodetree); - ma->id.flag -= LIB_NEEDLINK; + ma->id.flag -= LIB_NEED_LINK; } } } @@ -3357,7 +3368,7 @@ static void lib_link_particlesettings(FileData *fd, Main *main) int a; for (part = main->particle.first; part; part = part->id.next) { - if (part->id.flag & LIB_NEEDLINK) { + if (part->id.flag & LIB_NEED_LINK) { if (part->adt) lib_link_animdata(fd, &part->id, part->adt); part->ipo = newlibadr_us(fd, part->id.lib, part->ipo); // XXX depreceated - old animation system @@ -3439,7 +3450,7 @@ static void lib_link_particlesettings(FileData *fd, Main *main) } } - part->id.flag -= LIB_NEEDLINK; + part->id.flag -= LIB_NEED_LINK; } } } @@ -3652,7 +3663,7 @@ static void lib_link_mesh(FileData *fd, Main *main) Mesh *me; for (me = main->mesh.first; me; me = me->id.next) { - if (me->id.flag & LIB_NEEDLINK) { + if (me->id.flag & LIB_NEED_LINK) { int i; /* Link ID Properties -- and copy this comment EXACTLY for easy finding @@ -3696,7 +3707,7 @@ static void lib_link_mesh(FileData *fd, Main *main) convert_tface_mt(fd, main); for (me = main->mesh.first; me; me = me->id.next) { - if (me->id.flag & LIB_NEEDLINK) { + if (me->id.flag & LIB_NEED_LINK) { /* * Re-tessellate, even if the polys were just created from tessfaces, this * is important because it: @@ -3713,7 +3724,7 @@ static void lib_link_mesh(FileData *fd, Main *main) BKE_mesh_tessface_clear(me); #endif - me->id.flag -= LIB_NEEDLINK; + me->id.flag -= LIB_NEED_LINK; } } } @@ -3955,13 +3966,13 @@ static void lib_link_latt(FileData *fd, Main *main) Lattice *lt; for (lt = main->latt.first; lt; lt = lt->id.next) { - if (lt->id.flag & LIB_NEEDLINK) { + if (lt->id.flag & LIB_NEED_LINK) { if (lt->adt) lib_link_animdata(fd, <->id, lt->adt); lt->ipo = newlibadr_us(fd, lt->id.lib, lt->ipo); // XXX depreceated - old animation system lt->key = newlibadr_us(fd, lt->id.lib, lt->key); - lt->id.flag -= LIB_NEEDLINK; + lt->id.flag -= LIB_NEED_LINK; } } } @@ -4008,7 +4019,7 @@ static void lib_link_object(FileData *fd, Main *main) int warn=0, a; for (ob = main->object.first; ob; ob = ob->id.next) { - if (ob->id.flag & LIB_NEEDLINK) { + if (ob->id.flag & LIB_NEED_LINK) { if (ob->id.properties) IDP_LibLinkProperty(ob->id.properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); if (ob->adt) lib_link_animdata(fd, &ob->id, ob->adt); @@ -4087,7 +4098,7 @@ static void lib_link_object(FileData *fd, Main *main) ob->gpd = newlibadr_us(fd, ob->id.lib, ob->gpd); ob->duplilist = NULL; - ob->id.flag -= LIB_NEEDLINK; + ob->id.flag -= LIB_NEED_LINK; /* if id.us==0 a new base will be created later on */ /* WARNING! Also check expand_object(), should reflect the stuff below. */ @@ -4784,7 +4795,7 @@ static void lib_link_scene(FileData *fd, Main *main) TimeMarker *marker; for (sce = main->scene.first; sce; sce = sce->id.next) { - if (sce->id.flag & LIB_NEEDLINK) { + if (sce->id.flag & LIB_NEED_LINK) { /* Link ID Properties -- and copy this comment EXACTLY for easy finding * of library blocks that implement this.*/ if (sce->id.properties) IDP_LibLinkProperty(sce->id.properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); @@ -4886,7 +4897,7 @@ static void lib_link_scene(FileData *fd, Main *main) /* Motion Tracking */ sce->clip = newlibadr_us(fd, sce->id.lib, sce->clip); - sce->id.flag -= LIB_NEEDLINK; + sce->id.flag -= LIB_NEED_LINK; } } } @@ -5155,11 +5166,11 @@ static void lib_link_windowmanager(FileData *fd, Main *main) wmWindow *win; for (wm = main->wm.first; wm; wm = wm->id.next) { - if (wm->id.flag & LIB_NEEDLINK) { + if (wm->id.flag & LIB_NEED_LINK) { for (win = wm->windows.first; win; win = win->next) win->screen = newlibadr(fd, NULL, win->screen); - wm->id.flag -= LIB_NEEDLINK; + wm->id.flag -= LIB_NEED_LINK; } } } @@ -5227,7 +5238,7 @@ static void lib_link_screen(FileData *fd, Main *main) ScrArea *sa; for (sc = main->screen.first; sc; sc = sc->id.next) { - if (sc->id.flag & LIB_NEEDLINK) { + if (sc->id.flag & LIB_NEED_LINK) { sc->id.us = 1; sc->scene = newlibadr(fd, sc->id.lib, sc->scene); sc->animtimer = NULL; /* saved in rare cases */ @@ -5300,7 +5311,8 @@ static void lib_link_screen(FileData *fd, Main *main) SpaceImage *sima = (SpaceImage *)sl; sima->image = newlibadr_us(fd, sc->id.lib, sima->image); - + sima->mask_info.mask = newlibadr_us(fd, sc->id.lib, sima->mask_info.mask); + /* NOTE: pre-2.5, this was local data not lib data, but now we need this as lib data * so fingers crossed this works fine! */ @@ -5386,7 +5398,7 @@ static void lib_link_screen(FileData *fd, Main *main) SpaceClip *sclip = (SpaceClip *)sl; sclip->clip = newlibadr_us(fd, sc->id.lib, sclip->clip); - sclip->mask = newlibadr_us(fd, sc->id.lib, sclip->mask); + sclip->mask_info.mask = newlibadr_us(fd, sc->id.lib, sclip->mask_info.mask); sclip->scopes.track_search = NULL; sclip->scopes.track_preview = NULL; @@ -5400,7 +5412,7 @@ static void lib_link_screen(FileData *fd, Main *main) } } } - sc->id.flag -= LIB_NEEDLINK; + sc->id.flag -= LIB_NEED_LINK; } } } @@ -5600,6 +5612,7 @@ void lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *curscene) * so assume that here we're doing for undo only... */ sima->gpd = restore_pointer_by_name(newmain, (ID *)sima->gpd, 1); + sima->mask_info.mask = restore_pointer_by_name(newmain, (ID *)sima->mask_info.mask, 1); } else if (sl->spacetype == SPACE_SEQ) { SpaceSeq *sseq = (SpaceSeq *)sl; @@ -5675,7 +5688,7 @@ void lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *curscene) SpaceClip *sclip = (SpaceClip *)sl; sclip->clip = restore_pointer_by_name(newmain, (ID *)sclip->clip, 1); - sclip->mask = restore_pointer_by_name(newmain, (ID *)sclip->mask, 1); + sclip->mask_info.mask = restore_pointer_by_name(newmain, (ID *)sclip->mask_info.mask, 1); sclip->scopes.ok = 0; } @@ -6085,7 +6098,7 @@ static void lib_link_speaker(FileData *fd, Main *main) Speaker *spk; for (spk = main->speaker.first; spk; spk = spk->id.next) { - if (spk->id.flag & LIB_NEEDLINK) { + if (spk->id.flag & LIB_NEED_LINK) { if (spk->adt) lib_link_animdata(fd, &spk->id, spk->adt); spk->sound= newlibadr(fd, spk->id.lib, spk->sound); @@ -6093,7 +6106,7 @@ static void lib_link_speaker(FileData *fd, Main *main) spk->sound->id.us++; } - spk->id.flag -= LIB_NEEDLINK; + spk->id.flag -= LIB_NEED_LINK; } } } @@ -6132,8 +6145,8 @@ static void lib_link_sound(FileData *fd, Main *main) bSound *sound; for (sound = main->sound.first; sound; sound = sound->id.next) { - if (sound->id.flag & LIB_NEEDLINK) { - sound->id.flag -= LIB_NEEDLINK; + if (sound->id.flag & LIB_NEED_LINK) { + sound->id.flag -= LIB_NEED_LINK; sound->ipo = newlibadr_us(fd, sound->id.lib, sound->ipo); // XXX depreceated - old animation system sound_load(main, sound); @@ -6154,8 +6167,8 @@ static void lib_link_group(FileData *fd, Main *main) int add_us; for (group = main->group.first; group; group = group->id.next) { - if (group->id.flag & LIB_NEEDLINK) { - group->id.flag -= LIB_NEEDLINK; + if (group->id.flag & LIB_NEED_LINK) { + group->id.flag -= LIB_NEED_LINK; add_us = 0; @@ -6244,7 +6257,7 @@ static void lib_link_movieclip(FileData *fd, Main *main) MovieClip *clip; for (clip = main->movieclip.first; clip; clip = clip->id.next) { - if (clip->id.flag & LIB_NEEDLINK) { + if (clip->id.flag & LIB_NEED_LINK) { MovieTracking *tracking = &clip->tracking; MovieTrackingObject *object; @@ -6259,7 +6272,7 @@ static void lib_link_movieclip(FileData *fd, Main *main) lib_link_movieTracks(fd, clip, &object->tracks); } - clip->id.flag -= LIB_NEEDLINK; + clip->id.flag -= LIB_NEED_LINK; } } } @@ -6315,7 +6328,7 @@ static void lib_link_mask(FileData *fd, Main *main) mask = main->mask.first; while (mask) { - if (mask->id.flag & LIB_NEEDLINK) { + if (mask->id.flag & LIB_NEED_LINK) { MaskLayer *masklay; if (mask->adt) @@ -6340,7 +6353,7 @@ static void lib_link_mask(FileData *fd, Main *main) } } - mask->id.flag -= LIB_NEEDLINK; + mask->id.flag -= LIB_NEED_LINK; } mask = mask->id.next; } @@ -6355,8 +6368,8 @@ static void lib_link_linestyle(FileData *fd, Main *main) linestyle = main->linestyle.first; while (linestyle) { - if (linestyle->id.flag & LIB_NEEDLINK) { - linestyle->id.flag -= LIB_NEEDLINK; + if (linestyle->id.flag & LIB_NEED_LINK) { + linestyle->id.flag -= LIB_NEED_LINK; if (linestyle->id.properties) IDP_LibLinkProperty(linestyle->id.properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd); if (linestyle->adt) lib_link_animdata(fd, &linestyle->id, linestyle->adt); @@ -6613,7 +6626,7 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, int flag, ID BLI_addtail(lb, id); /* clear first 8 bits */ - id->flag = (id->flag & 0xFF00) | flag | LIB_NEEDLINK; + id->flag = (id->flag & 0xFF00) | flag | LIB_NEED_LINK; id->lib = main->curlib; if (id->flag & LIB_FAKEUSER) id->us= 1; else id->us = 0; @@ -7204,6 +7217,24 @@ static void do_version_ntree_dilateerode_264(void *UNUSED(data), ID *UNUSED(id), } } +static void do_version_ntree_mask_264(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree) +{ + bNode *node; + + for (node = ntree->nodes.first; node; node = node->next) { + if (node->type == CMP_NODE_MASK) { + if (node->storage == NULL) { + NodeMask *data = MEM_callocN(sizeof(NodeMask), __func__); + /* move settings into own struct */ + data->size_x = node->custom3; + data->size_y = node->custom4; + node->custom3 = 0.5f; /* default shutter */ + node->storage = data; + } + } + } +} + static void do_version_ntree_keying_despill_balance(void *UNUSED(data), ID *UNUSED(id), bNodeTree *ntree) { bNode *node; @@ -8040,6 +8071,13 @@ static void do_versions(FileData *fd, Library *lib, Main *main) ntreetype->foreach_nodetree(main, NULL, do_version_ntree_keying_despill_balance); } + if (main->versionfile < 263 || (main->versionfile == 263 && main->subversionfile < 17)) { + bNodeTreeType *ntreetype = ntreeGetType(NTREE_COMPOSIT); + + if (ntreetype && ntreetype->foreach_nodetree) + ntreetype->foreach_nodetree(main, NULL, do_version_ntree_mask_264); + } + /* default values in Freestyle settings */ { Scene *sce; @@ -9119,6 +9157,38 @@ static void expand_movieclip(FileData *fd, Main *mainvar, MovieClip *clip) if (clip->adt) expand_animdata(fd, mainvar, clip->adt); } + +static void expand_mask_parent(FileData *fd, Main *mainvar, MaskParent *parent) +{ + if (parent->id) { + expand_doit(fd, mainvar, parent->id); + } +} + +static void expand_mask(FileData *fd, Main *mainvar, Mask *mask) +{ + MaskLayer *mask_layer; + + if (mask->adt) + expand_animdata(fd, mainvar, mask->adt); + + for (mask_layer = mask->masklayers.first; mask_layer; mask_layer = mask_layer->next) { + MaskSpline *spline; + + for (spline = mask_layer->splines.first; spline; spline = spline->next) { + int i; + + for (i = 0; i < spline->tot_point; i++) { + MaskSplinePoint *point = &spline->points[i]; + + expand_mask_parent(fd, mainvar, &point->parent); + } + + expand_mask_parent(fd, mainvar, &spline->parent); + } + } +} + static void expand_linestyle(FileData *fd, Main *mainvar, FreestyleLineStyle *linestyle) { LineStyleModifier *m; @@ -9154,7 +9224,7 @@ static void expand_main(FileData *fd, Main *mainvar) while (a--) { id= lbarray[a]->first; while (id) { - if (id->flag & LIB_TEST) { + if (id->flag & LIB_NEED_EXPAND) { switch (GS(id->name)) { case ID_OB: expand_object(fd, mainvar, (Object *)id); @@ -9222,13 +9292,16 @@ static void expand_main(FileData *fd, Main *mainvar) case ID_MC: expand_movieclip(fd, mainvar, (MovieClip *)id); break; + case ID_MSK: + expand_mask(fd, mainvar, (Mask *)id); + break; case ID_LS: expand_linestyle(fd, mainvar, (FreestyleLineStyle *)id); break; } do_it = TRUE; - id->flag -= LIB_TEST; + id->flag -= LIB_NEED_EXPAND; } id = id->next; @@ -9443,7 +9516,7 @@ static void append_id_part(FileData *fd, Main *mainvar, ID *id, ID **id_r) if (strcmp(id->name, bhead_id_name(fd, bhead))==0) { id->flag &= ~LIB_READ; - id->flag |= LIB_TEST; + id->flag |= LIB_NEED_EXPAND; // printf("read lib block %s\n", id->name); read_libblock(fd, mainvar, bhead, id->flag, id_r); diff --git a/source/blender/blenloader/intern/versioning_legacy.c b/source/blender/blenloader/intern/versioning_legacy.c index 46ef2716ade..c31906cbd80 100644 --- a/source/blender/blenloader/intern/versioning_legacy.c +++ b/source/blender/blenloader/intern/versioning_legacy.c @@ -569,7 +569,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main) /* tex->extend and tex->imageflag have changed: */ Tex *tex = main->tex.first; while (tex) { - if (tex->id.flag & LIB_NEEDLINK) { + if (tex->id.flag & LIB_NEED_LINK) { if (tex->extend == 0) { if (tex->xrepeat || tex->yrepeat) { @@ -3107,7 +3107,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main) part->id.lib = ob->id.lib; part->id.us--; - part->id.flag |= (ob->id.flag & LIB_NEEDLINK); + part->id.flag |= (ob->id.flag & LIB_NEED_LINK); psys->totpart = 0; psys->flag = PSYS_ENABLED|PSYS_CURRENT; diff --git a/source/blender/bmesh/bmesh_class.h b/source/blender/bmesh/bmesh_class.h index e180335cf06..998407c82ba 100644 --- a/source/blender/bmesh/bmesh_class.h +++ b/source/blender/bmesh/bmesh_class.h @@ -198,8 +198,6 @@ typedef struct BMesh { ListBase errorstack; void *py_handle; - - int opflag; /* current operator flag */ } BMesh; /* BMHeader->htype (char) */ diff --git a/source/blender/bmesh/intern/bmesh_interp.c b/source/blender/bmesh/intern/bmesh_interp.c index c39096d0800..74d3df01fd0 100644 --- a/source/blender/bmesh/intern/bmesh_interp.c +++ b/source/blender/bmesh/intern/bmesh_interp.c @@ -236,7 +236,7 @@ static float quad_coord(float aa[3], float bb[3], float cc[3], float dd[3], int f1 = fabsf(f1); f2 = fabsf(f2); - f1 = MIN2(f1, f2); + f1 = minf(f1, f2); CLAMP(f1, 0.0f, 1.0f + FLT_EPSILON); } else { diff --git a/source/blender/bmesh/intern/bmesh_mesh.c b/source/blender/bmesh/intern/bmesh_mesh.c index 385572cceff..cf593627e8d 100644 --- a/source/blender/bmesh/intern/bmesh_mesh.c +++ b/source/blender/bmesh/intern/bmesh_mesh.c @@ -290,47 +290,6 @@ void BM_mesh_normals_update(BMesh *bm, const short skip_hidden) MEM_freeN(edgevec); } -/* - * This function ensures correct normals for the mesh, but - * sets the flag BM_ELEM_TAG in flipped faces, to allow restoration - * of original normals. - * - * if undo is 0: calculate right normals - * if undo is 1: restore original normals - */ - -//keep in sycn with utils.c! -#define FACE_FLIP 8 -static void bm_rationalize_normals(BMesh *bm, int undo) -{ - BMOperator bmop; - BMFace *f; - BMIter iter; - - if (undo) { - BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) { - if (BM_elem_flag_test(f, BM_ELEM_TAG)) { - BM_face_normal_flip(bm, f); - } - BM_elem_flag_disable(f, BM_ELEM_TAG); - } - - return; - } - - BMO_op_initf(bm, &bmop, "recalc_face_normals faces=%af do_flip=%b", FALSE); - - BMO_push(bm, &bmop); - bmo_recalc_face_normals_exec(bm, &bmop); - - BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) { - BM_elem_flag_set(f, BM_ELEM_TAG, BMO_elem_flag_test(bm, f, FACE_FLIP)); - } - - BMO_pop(bm); - BMO_op_finish(bm, &bmop); -} - static void UNUSED_FUNCTION(bm_mdisps_space_set)(Object *ob, BMesh *bm, int from, int to) { /* switch multires data out of tangent space */ @@ -390,10 +349,8 @@ static void UNUSED_FUNCTION(bm_mdisps_space_set)(Object *ob, BMesh *bm, int from * the editing operations are done. These are called by the tools/operator * API for each time a tool is executed. */ -void bmesh_edit_begin(BMesh *bm, int flag) +void bmesh_edit_begin(BMesh *UNUSED(bm), int UNUSED(type_flag)) { - bm->opflag = flag; - /* Most operators seem to be using BMO_OP_FLAG_UNTAN_MULTIRES to change the MDisps to * absolute space during mesh edits. With this enabled, changes to the topology * (loop cuts, edge subdivides, etc) are not reflected in the higher levels of @@ -401,27 +358,20 @@ void bmesh_edit_begin(BMesh *bm, int flag) * until this is shown to be better for certain types of mesh edits. */ #if BMOP_UNTAN_MULTIRES_ENABLED /* switch multires data out of tangent space */ - if ((flag & BMO_OP_FLAG_UNTAN_MULTIRES) && CustomData_has_layer(&bm->ldata, CD_MDISPS)) { + if ((type_flag & BMO_OP_FLAG_UNTAN_MULTIRES) && CustomData_has_layer(&bm->ldata, CD_MDISPS)) { bmesh_mdisps_space_set(bm, MULTIRES_SPACE_TANGENT, MULTIRES_SPACE_ABSOLUTE); /* ensure correct normals, if possible */ bmesh_rationalize_normals(bm, 0); BM_mesh_normals_update(bm); } - else if (flag & BMO_OP_FLAG_RATIONALIZE_NORMALS) { - bmesh_rationalize_normals(bm, 0); - } -#else - if (flag & BMO_OP_FLAG_RATIONALIZE_NORMALS) { - bm_rationalize_normals(bm, 0); - } #endif } /** * \brief BMesh End Edit */ -void bmesh_edit_end(BMesh *bm, int flag) +void bmesh_edit_end(BMesh *bm, int UNUSED(flag)) { /* BMO_OP_FLAG_UNTAN_MULTIRES disabled for now, see comment above in bmesh_edit_begin. */ #if BMOP_UNTAN_MULTIRES_ENABLED @@ -434,14 +384,8 @@ void bmesh_edit_end(BMesh *bm, int flag) else if (flag & BMO_OP_FLAG_RATIONALIZE_NORMALS) { bmesh_rationalize_normals(bm, 1); } -#else - if (flag & BMO_OP_FLAG_RATIONALIZE_NORMALS) { - bm_rationalize_normals(bm, 1); - } #endif - bm->opflag = 0; - /* compute normals, clear temp flags and flush selections */ BM_mesh_normals_update(bm, TRUE); BM_mesh_select_mode_flush(bm); diff --git a/source/blender/bmesh/intern/bmesh_mesh.h b/source/blender/bmesh/intern/bmesh_mesh.h index 0441f38b429..8b6ef9aa3e0 100644 --- a/source/blender/bmesh/intern/bmesh_mesh.h +++ b/source/blender/bmesh/intern/bmesh_mesh.h @@ -37,8 +37,8 @@ void BM_mesh_clear(BMesh *bm); void BM_mesh_normals_update(BMesh *bm, const short skip_hidden); -void bmesh_edit_begin(BMesh *bm, int flag); -void bmesh_edit_end(BMesh *bm, int flag); +void bmesh_edit_begin(BMesh *bm, int type_flag); +void bmesh_edit_end(BMesh *bm, int type_flag); void BM_mesh_elem_index_ensure(BMesh *bm, const char hflag); void BM_mesh_elem_index_validate(BMesh *bm, const char *location, const char *func, diff --git a/source/blender/bmesh/intern/bmesh_opdefines.c b/source/blender/bmesh/intern/bmesh_opdefines.c index c80a88d280e..eacee8e12ad 100644 --- a/source/blender/bmesh/intern/bmesh_opdefines.c +++ b/source/blender/bmesh/intern/bmesh_opdefines.c @@ -104,6 +104,9 @@ static BMOpDefine bmo_smooth_vert_def = { {BMO_OP_SLOT_BOOL, "mirror_clip_y"}, /* set vertices close to the y axis before the operation to 0 */ {BMO_OP_SLOT_BOOL, "mirror_clip_z"}, /* set vertices close to the z axis before the operation to 0 */ {BMO_OP_SLOT_FLT, "clipdist"}, /* clipping threshod for the above three slots */ + {BMO_OP_SLOT_BOOL, "use_axis_x"}, /* smooth vertices along X axis */ + {BMO_OP_SLOT_BOOL, "use_axis_y"}, /* smooth vertices along Y axis */ + {BMO_OP_SLOT_BOOL, "use_axis_z"}, /* smooth vertices along Z axis */ {0} /* null-terminating sentinel */, }, bmo_smooth_vert_exec, diff --git a/source/blender/bmesh/intern/bmesh_operator_api.h b/source/blender/bmesh/intern/bmesh_operator_api.h index c4ebd4a6204..a2f14ef8388 100644 --- a/source/blender/bmesh/intern/bmesh_operator_api.h +++ b/source/blender/bmesh/intern/bmesh_operator_api.h @@ -135,13 +135,19 @@ typedef struct BMOpSlot { typedef struct BMOperator { int type; int slot_type; - int needflag; - int flag; + int type_flag; + int flag; /* runtime options */ struct BMOpSlot slot_args[BMO_OP_MAX_SLOTS]; void (*exec)(BMesh *bm, struct BMOperator *op); struct MemArena *arena; } BMOperator; +enum { + BMO_FLAG_RESPECT_HIDE = 1, +}; + +#define BMO_FLAG_DEFAULTS BMO_FLAG_RESPECT_HIDE + #define MAX_SLOTNAME 32 typedef struct BMOSlotType { @@ -153,17 +159,13 @@ typedef struct BMOpDefine { const char *name; BMOSlotType slot_types[BMO_OP_MAX_SLOTS]; void (*exec)(BMesh *bm, BMOperator *op); - int flag; + int type_flag; } BMOpDefine; -/* BMOpDefine->flag */ -#define BMO_OP_FLAG_UNTAN_MULTIRES 1 /*switch from multires tangent space to absolute coordinates*/ - -/* ensures consistent normals before operator execution, - * restoring the original ones windings/normals afterwards. - * keep in mind, this won't work if the input mesh isn't - * manifold.*/ -#define BMO_OP_FLAG_RATIONALIZE_NORMALS 2 +/* BMOpDefine->type_flag */ +enum { + BMO_OP_FLAG_UNTAN_MULTIRES = 1 /*switch from multires tangent space to absolute coordinates*/ +}; /*------------- Operator API --------------*/ @@ -171,7 +173,7 @@ typedef struct BMOpDefine { * have it set directly. and never use BMO_slot_ptr_set to * pass in a list of edges or any arrays, really.*/ -void BMO_op_init(BMesh *bm, BMOperator *op, const char *opname); +void BMO_op_init(BMesh *bm, BMOperator *op, const int flag, const char *opname); /* executes an operator, pushing and popping a new tool flag * layer as appropriate.*/ @@ -194,7 +196,7 @@ int BMO_mesh_disabled_flag_count(BMesh *bm, const char htype, const short oflag) * this system is used to execute or initialize an operator, * using a formatted-string system. * - * for example, BMO_op_callf(bm, "delete geom=%hf context=%i", BM_ELEM_SELECT, DEL_FACES); + * for example, BMO_op_callf(bm, BMO_FLAG_DEFAULTS, "delete geom=%hf context=%i", BM_ELEM_SELECT, DEL_FACES); * . . .will execute the delete operator, feeding in selected faces, deleting them. * * the basic format for the format string is: @@ -231,16 +233,16 @@ void BMO_push(BMesh *bm, BMOperator *op); void BMO_pop(BMesh *bm); /*executes an operator*/ -int BMO_op_callf(BMesh *bm, const char *fmt, ...); +int BMO_op_callf(BMesh *bm, const int flag, const char *fmt, ...); /* initializes, but doesn't execute an operator. this is so you can * gain access to the outputs of the operator. note that you have * to execute/finish (BMO_op_exec and BMO_op_finish) yourself. */ -int BMO_op_initf(BMesh *bm, BMOperator *op, const char *fmt, ...); +int BMO_op_initf(BMesh *bm, BMOperator *op, const int flag, const char *fmt, ...); /* va_list version, used to implement the above two functions, * plus EDBM_op_callf in editmesh_utils.c. */ -int BMO_op_vinitf(BMesh *bm, BMOperator *op, const char *fmt, va_list vlist); +int BMO_op_vinitf(BMesh *bm, BMOperator *op, const int flag, const char *fmt, va_list vlist); /* test whether a named slot exists */ int BMO_slot_exists(BMOperator *op, const char *slot_name); diff --git a/source/blender/bmesh/intern/bmesh_operators.c b/source/blender/bmesh/intern/bmesh_operators.c index 5447e6b5a55..0f2dc7041fa 100644 --- a/source/blender/bmesh/intern/bmesh_operators.c +++ b/source/blender/bmesh/intern/bmesh_operators.c @@ -126,7 +126,7 @@ void BMO_pop(BMesh *bm) * * Initializes an operator structure to a certain type */ -void BMO_op_init(BMesh *bm, BMOperator *op, const char *opname) +void BMO_op_init(BMesh *bm, BMOperator *op, const int flag, const char *opname) { int i, opcode = bmo_opname_to_opcode(opname); @@ -142,7 +142,8 @@ void BMO_op_init(BMesh *bm, BMOperator *op, const char *opname) memset(op, 0, sizeof(BMOperator)); op->type = opcode; - op->flag = opdefines[opcode]->flag; + op->type_flag = opdefines[opcode]->type_flag; + op->flag = flag; /* initialize the operator slot types */ for (i = 0; opdefines[opcode]->slot_types[i].type; i++) { @@ -173,11 +174,11 @@ void BMO_op_exec(BMesh *bm, BMOperator *op) BMO_push(bm, op); if (bm->stackdepth == 2) - bmesh_edit_begin(bm, op->flag); + bmesh_edit_begin(bm, op->type_flag); op->exec(bm, op); if (bm->stackdepth == 2) - bmesh_edit_end(bm, op->flag); + bmesh_edit_end(bm, op->type_flag); BMO_pop(bm); } @@ -697,13 +698,14 @@ static void bmo_slot_buffer_from_hflag(BMesh *bm, BMOperator *op, const char *sl { BMOpSlot *output = BMO_slot_get(op, slot_name); int totelement = 0, i = 0; + const int respecthide = (op->flag & BMO_FLAG_RESPECT_HIDE) != 0; BLI_assert(ELEM(test_for_enabled, TRUE, FALSE)); if (test_for_enabled) - totelement = BM_mesh_elem_hflag_count_enabled(bm, htype, hflag, TRUE); + totelement = BM_mesh_elem_hflag_count_enabled(bm, htype, hflag, respecthide); else - totelement = BM_mesh_elem_hflag_count_disabled(bm, htype, hflag, TRUE); + totelement = BM_mesh_elem_hflag_count_disabled(bm, htype, hflag, respecthide); if (totelement) { BMIter iter; @@ -715,7 +717,7 @@ static void bmo_slot_buffer_from_hflag(BMesh *bm, BMOperator *op, const char *sl if (htype & BM_VERT) { BM_ITER_MESH (ele, &iter, bm, BM_VERTS_OF_MESH) { - if (!BM_elem_flag_test(ele, BM_ELEM_HIDDEN) && + if ((!respecthide || !BM_elem_flag_test(ele, BM_ELEM_HIDDEN)) && BM_elem_flag_test_bool(ele, hflag) == test_for_enabled) { ((BMElem **)output->data.p)[i] = ele; @@ -726,7 +728,7 @@ static void bmo_slot_buffer_from_hflag(BMesh *bm, BMOperator *op, const char *sl if (htype & BM_EDGE) { BM_ITER_MESH (ele, &iter, bm, BM_EDGES_OF_MESH) { - if (!BM_elem_flag_test(ele, BM_ELEM_HIDDEN) && + if ((!respecthide || !BM_elem_flag_test(ele, BM_ELEM_HIDDEN)) && BM_elem_flag_test_bool(ele, hflag) == test_for_enabled) { ((BMElem **)output->data.p)[i] = ele; @@ -737,7 +739,7 @@ static void bmo_slot_buffer_from_hflag(BMesh *bm, BMOperator *op, const char *sl if (htype & BM_FACE) { BM_ITER_MESH (ele, &iter, bm, BM_FACES_OF_MESH) { - if (!BM_elem_flag_test(ele, BM_ELEM_HIDDEN) && + if ((!respecthide || !BM_elem_flag_test(ele, BM_ELEM_HIDDEN)) && BM_elem_flag_test_bool(ele, hflag) == test_for_enabled) { ((BMElem **)output->data.p)[i] = ele; @@ -1320,7 +1322,7 @@ static int bmo_opname_to_opcode(const char *opname) } /* Example: - * BMO_op_callf(bm, "delete %i %hv", DEL_ONLYFACES, BM_ELEM_SELECT); + * BMO_op_callf(bm, BMO_FLAG_DEFAULTS, "delete %i %hv", DEL_ONLYFACES, BM_ELEM_SELECT); * * i - int * b - boolean (same as int but 1/0 only) @@ -1336,7 +1338,7 @@ static int bmo_opname_to_opcode(const char *opname) * Hv, He, Hf, Fv, Fe, Ff, */ -int BMO_op_vinitf(BMesh *bm, BMOperator *op, const char *_fmt, va_list vlist) +int BMO_op_vinitf(BMesh *bm, BMOperator *op, const int flag, const char *_fmt, va_list vlist) { BMOpDefine *def; char *opname, *ofmt, *fmt; @@ -1376,7 +1378,7 @@ int BMO_op_vinitf(BMesh *bm, BMOperator *op, const char *_fmt, va_list vlist) return FALSE; } - BMO_op_init(bm, op, opname); + BMO_op_init(bm, op, flag, opname); def = opdefines[i]; i = 0; @@ -1556,12 +1558,12 @@ error: } -int BMO_op_initf(BMesh *bm, BMOperator *op, const char *fmt, ...) +int BMO_op_initf(BMesh *bm, BMOperator *op, const int flag, const char *fmt, ...) { va_list list; va_start(list, fmt); - if (!BMO_op_vinitf(bm, op, fmt, list)) { + if (!BMO_op_vinitf(bm, op, flag, fmt, list)) { printf("%s: failed\n", __func__); va_end(list); return FALSE; @@ -1571,13 +1573,13 @@ int BMO_op_initf(BMesh *bm, BMOperator *op, const char *fmt, ...) return TRUE; } -int BMO_op_callf(BMesh *bm, const char *fmt, ...) +int BMO_op_callf(BMesh *bm, const int flag, const char *fmt, ...) { va_list list; BMOperator op; va_start(list, fmt); - if (!BMO_op_vinitf(bm, &op, fmt, list)) { + if (!BMO_op_vinitf(bm, &op, flag, fmt, list)) { printf("%s: failed, format is:\n \"%s\"\n", __func__, fmt); va_end(list); return FALSE; diff --git a/source/blender/bmesh/intern/bmesh_polygon.c b/source/blender/bmesh/intern/bmesh_polygon.c index 03b72aefee6..5d63172dbfa 100644 --- a/source/blender/bmesh/intern/bmesh_polygon.c +++ b/source/blender/bmesh/intern/bmesh_polygon.c @@ -507,8 +507,8 @@ static int linecrossesf(const float v1[2], const float v2[2], const float v3[2], #define GETMIN2_AXIS(a, b, ma, mb, axis) \ { \ - ma[axis] = MIN2(a[axis], b[axis]); \ - mb[axis] = MAX2(a[axis], b[axis]); \ + ma[axis] = minf(a[axis], b[axis]); \ + mb[axis] = maxf(a[axis], b[axis]); \ } (void)0 #define GETMIN2(a, b, ma, mb) \ @@ -538,17 +538,17 @@ static int linecrossesf(const float v1[2], const float v2[2], const float v3[2], /* do an interval test on the x and y axes */ /* first do x axis */ - if (ABS(v1[1] - v2[1]) < EPS && - ABS(v3[1] - v4[1]) < EPS && - ABS(v1[1] - v3[1]) < EPS) + if (fabsf(v1[1] - v2[1]) < EPS && + fabsf(v3[1] - v4[1]) < EPS && + fabsf(v1[1] - v3[1]) < EPS) { return (mv4[0] >= mv1[0] && mv3[0] <= mv2[0]); } /* now do y axis */ - if (ABS(v1[0] - v2[0]) < EPS && - ABS(v3[0] - v4[0]) < EPS && - ABS(v1[0] - v3[0]) < EPS) + if (fabsf(v1[0] - v2[0]) < EPS && + fabsf(v3[0] - v4[0]) < EPS && + fabsf(v1[0] - v3[0]) < EPS) { return (mv4[1] >= mv1[1] && mv3[1] <= mv2[1]); } @@ -994,8 +994,8 @@ void BM_face_legal_splits(BMesh *bm, BMFace *f, BMLoop *(*loops)[2], int len) for (i = 0, l = BM_FACE_FIRST_LOOP(f); i < f->len; i++, l = l->next) { p1 = projverts[i]; - out[0] = MAX2(out[0], p1[0]) + 0.01f; - out[1] = MAX2(out[1], p1[1]) + 0.01f; + out[0] = maxf(out[0], p1[0]) + 0.01f; + out[1] = maxf(out[1], p1[1]) + 0.01f; out[2] = 0.0f; p1[2] = 0.0f; diff --git a/source/blender/bmesh/operators/bmo_bevel.c b/source/blender/bmesh/operators/bmo_bevel.c index ef4a2a215d6..8210ea973e6 100644 --- a/source/blender/bmesh/operators/bmo_bevel.c +++ b/source/blender/bmesh/operators/bmo_bevel.c @@ -865,7 +865,7 @@ void bmo_bevel_exec(BMesh *bm, BMOperator *op) } #endif - BMO_op_callf(bm, "delete geom=%fv context=%i", BEVEL_DEL, DEL_VERTS); + BMO_op_callf(bm, op->flag, "delete geom=%fv context=%i", BEVEL_DEL, DEL_VERTS); /* clean up any edges that might not get properly delete */ BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) { @@ -873,8 +873,8 @@ void bmo_bevel_exec(BMesh *bm, BMOperator *op) BMO_elem_flag_enable(bm, e, BEVEL_DEL); } - BMO_op_callf(bm, "delete geom=%fe context=%i", BEVEL_DEL, DEL_EDGES); - BMO_op_callf(bm, "delete geom=%ff context=%i", BEVEL_DEL, DEL_FACES); + BMO_op_callf(bm, op->flag, "delete geom=%fe context=%i", BEVEL_DEL, DEL_EDGES); + BMO_op_callf(bm, op->flag, "delete geom=%ff context=%i", BEVEL_DEL, DEL_FACES); BLI_smallhash_release(&hash); BLI_array_free(tags); diff --git a/source/blender/bmesh/operators/bmo_create.c b/source/blender/bmesh/operators/bmo_create.c index f1063d1ca42..c17f23eb658 100644 --- a/source/blender/bmesh/operators/bmo_create.c +++ b/source/blender/bmesh/operators/bmo_create.c @@ -1365,12 +1365,12 @@ void bmo_contextual_create_exec(BMesh *bm, BMOperator *op) /* call edgenet create */ /* call edgenet prepare op so additional face creation cases wore */ - BMO_op_initf(bm, &op2, "edgenet_prepare edges=%fe", ELE_NEW); + BMO_op_initf(bm, &op2, op->flag, "edgenet_prepare edges=%fe", ELE_NEW); BMO_op_exec(bm, &op2); BMO_slot_buffer_flag_enable(bm, &op2, "edgeout", BM_EDGE, ELE_NEW); BMO_op_finish(bm, &op2); - BMO_op_initf(bm, &op2, + BMO_op_initf(bm, &op2, op->flag, "edgenet_fill edges=%fe use_fill_check=%b mat_nr=%i use_smooth=%b", ELE_NEW, TRUE, mat_nr, use_smooth); @@ -1386,7 +1386,7 @@ void bmo_contextual_create_exec(BMesh *bm, BMOperator *op) BMO_op_finish(bm, &op2); /* now call dissolve face */ - BMO_op_initf(bm, &op2, "dissolve_faces faces=%ff", ELE_NEW); + BMO_op_initf(bm, &op2, op->flag, "dissolve_faces faces=%ff", ELE_NEW); BMO_op_exec(bm, &op2); /* if we dissolved anything, then return */ diff --git a/source/blender/bmesh/operators/bmo_dissolve.c b/source/blender/bmesh/operators/bmo_dissolve.c index f932b8c0766..b10556af04e 100644 --- a/source/blender/bmesh/operators/bmo_dissolve.c +++ b/source/blender/bmesh/operators/bmo_dissolve.c @@ -164,7 +164,7 @@ void bmo_dissolve_faces_exec(BMesh *bm, BMOperator *op) } - BMO_op_callf(bm, "delete geom=%ff context=%i", FACE_ORIG, DEL_FACES); + BMO_op_callf(bm, op->flag, "delete geom=%ff context=%i", FACE_ORIG, DEL_FACES); if (use_verts) { @@ -383,7 +383,7 @@ void bmo_dissolve_verts_exec(BMesh *bm, BMOperator *op) } } - BMO_op_callf(bm, "dissolve_faces faces=%ff", FACE_MARK); + BMO_op_callf(bm, op->flag, "dissolve_faces faces=%ff", FACE_MARK); if (BMO_error_occurred(bm)) { const char *msg; diff --git a/source/blender/bmesh/operators/bmo_dupe.c b/source/blender/bmesh/operators/bmo_dupe.c index 1421ae294bc..4d4d7e30a4e 100644 --- a/source/blender/bmesh/operators/bmo_dupe.c +++ b/source/blender/bmesh/operators/bmo_dupe.c @@ -381,8 +381,8 @@ void bmo_split_exec(BMesh *bm, BMOperator *op) const short use_only_faces = BMO_slot_bool_get(op, "use_only_faces"); /* initialize our sub-operator */ - BMO_op_init(bm, &dupeop, "duplicate"); - BMO_op_init(bm, &delop, "delete"); + BMO_op_init(bm, &dupeop, op->flag, "duplicate"); + BMO_op_init(bm, &delop, op->flag, "delete"); BMO_slot_copy(splitop, &dupeop, "geom", "geom"); BMO_op_exec(bm, &dupeop); @@ -487,18 +487,20 @@ void bmo_spin_exec(BMesh *bm, BMOperator *op) BMO_slot_copy(op, op, "geom", "lastout"); for (a = 0; a < steps; a++) { if (do_dupli) { - BMO_op_initf(bm, &dupop, "duplicate geom=%s", op, "lastout"); + BMO_op_initf(bm, &dupop, op->flag, "duplicate geom=%s", op, "lastout"); BMO_op_exec(bm, &dupop); - BMO_op_callf(bm, "rotate cent=%v mat=%m3 verts=%s", + BMO_op_callf(bm, op->flag, + "rotate cent=%v mat=%m3 verts=%s", cent, rmat, &dupop, "newout"); BMO_slot_copy(&dupop, op, "newout", "lastout"); BMO_op_finish(bm, &dupop); } else { - BMO_op_initf(bm, &extop, "extrude_face_region edgefacein=%s", + BMO_op_initf(bm, &extop, op->flag, "extrude_face_region edgefacein=%s", op, "lastout"); BMO_op_exec(bm, &extop); - BMO_op_callf(bm, "rotate cent=%v mat=%m3 verts=%s", + BMO_op_callf(bm, op->flag, + "rotate cent=%v mat=%m3 verts=%s", cent, rmat, &extop, "geomout"); BMO_slot_copy(&extop, op, "geomout", "lastout"); BMO_op_finish(bm, &extop); @@ -506,7 +508,9 @@ void bmo_spin_exec(BMesh *bm, BMOperator *op) if (usedvec) { mul_m3_v3(rmat, dvec); - BMO_op_callf(bm, "translate vec=%v verts=%s", dvec, op, "lastout"); + BMO_op_callf(bm, op->flag, + "translate vec=%v verts=%s", + dvec, op, "lastout"); } } } diff --git a/source/blender/bmesh/operators/bmo_extrude.c b/source/blender/bmesh/operators/bmo_extrude.c index b8993b41caf..7b59a4a9101 100644 --- a/source/blender/bmesh/operators/bmo_extrude.c +++ b/source/blender/bmesh/operators/bmo_extrude.c @@ -118,7 +118,9 @@ void bmo_extrude_discrete_faces_exec(BMesh *bm, BMOperator *op) BLI_array_free(edges); - BMO_op_callf(bm, "delete geom=%ff context=%i", EXT_DEL, DEL_ONLYFACES); + BMO_op_callf(bm, op->flag, + "delete geom=%ff context=%i", + EXT_DEL, DEL_ONLYFACES); BMO_slot_buffer_from_enabled_flag(bm, op, "faceout", BM_FACE, EXT_KEEP); } @@ -195,7 +197,7 @@ void bmo_extrude_edge_only_exec(BMesh *bm, BMOperator *op) BMO_elem_flag_enable(bm, e->v2, EXT_INPUT); } - BMO_op_initf(bm, &dupeop, "duplicate geom=%fve", EXT_INPUT); + BMO_op_initf(bm, &dupeop, op->flag, "duplicate geom=%fve", EXT_INPUT); BMO_op_exec(bm, &dupeop); /* disable root flag on all new skin nodes */ @@ -273,7 +275,7 @@ void bmo_extrude_face_region_exec(BMesh *bm, BMOperator *op) int found, fwd, delorig = FALSE; /* initialize our sub-operators */ - BMO_op_init(bm, &dupeop, "duplicate"); + BMO_op_init(bm, &dupeop, op->flag, "duplicate"); BMO_slot_buffer_flag_enable(bm, op, "edgefacein", BM_EDGE | BM_FACE, EXT_INPUT); @@ -341,7 +343,8 @@ void bmo_extrude_face_region_exec(BMesh *bm, BMOperator *op) } if (delorig == TRUE) { - BMO_op_initf(bm, &delop, "delete geom=%fvef context=%i", + BMO_op_initf(bm, &delop, op->flag, + "delete geom=%fvef context=%i", EXT_DEL, DEL_ONLYTAGGED); } @@ -647,13 +650,13 @@ void bmo_solidify_face_region_exec(BMesh *bm, BMOperator *op) thickness = BMO_slot_float_get(op, "thickness"); /* Flip original faces (so the shell is extruded inward) */ - BMO_op_init(bm, &reverseop, "reverse_faces"); + BMO_op_init(bm, &reverseop, op->flag, "reverse_faces"); BMO_slot_copy(op, &reverseop, "geom", "faces"); BMO_op_exec(bm, &reverseop); BMO_op_finish(bm, &reverseop); /* Extrude the region */ - BMO_op_initf(bm, &extrudeop, "extrude_face_region alwayskeeporig=%b", TRUE); + BMO_op_initf(bm, &extrudeop, op->flag, "extrude_face_region alwayskeeporig=%b", TRUE); BMO_slot_copy(op, &extrudeop, "geom", "edgefacein"); BMO_op_exec(bm, &extrudeop); diff --git a/source/blender/bmesh/operators/bmo_mesh_conv.c b/source/blender/bmesh/operators/bmo_mesh_conv.c index c550a17e696..c4b988ae82d 100644 --- a/source/blender/bmesh/operators/bmo_mesh_conv.c +++ b/source/blender/bmesh/operators/bmo_mesh_conv.c @@ -70,7 +70,9 @@ void bmo_object_load_bmesh_exec(BMesh *bm, BMOperator *op) /* Scene *scene = BMO_slot_ptr_get(op, "scene"); */ Mesh *me = ob->data; - BMO_op_callf(bm, "bmesh_to_mesh mesh=%p object=%p notessellation=%b", me, ob, TRUE); + BMO_op_callf(bm, op->flag, + "bmesh_to_mesh mesh=%p object=%p notessellation=%b", + me, ob, TRUE); } void bmo_bmesh_to_mesh_exec(BMesh *bm, BMOperator *op) diff --git a/source/blender/bmesh/operators/bmo_mirror.c b/source/blender/bmesh/operators/bmo_mirror.c index 1ab439b38bb..c6b228b988e 100644 --- a/source/blender/bmesh/operators/bmo_mirror.c +++ b/source/blender/bmesh/operators/bmo_mirror.c @@ -62,7 +62,7 @@ void bmo_mirror_exec(BMesh *bm, BMOperator *op) BMO_slot_mat4_get(op, "mat", mtx); invert_m4_m4(imtx, mtx); - BMO_op_initf(bm, &dupeop, "duplicate geom=%s", op, "geom"); + BMO_op_initf(bm, &dupeop, op->flag, "duplicate geom=%s", op, "geom"); BMO_op_exec(bm, &dupeop); BMO_slot_buffer_flag_enable(bm, &dupeop, "newout", BM_ALL, ELE_NEW); @@ -80,11 +80,11 @@ void bmo_mirror_exec(BMesh *bm, BMOperator *op) /* feed old data to transform bmo */ scale[axis] = -1.0f; - BMO_op_callf(bm, "transform verts=%fv mat=%m4", ELE_NEW, mtx); - BMO_op_callf(bm, "scale verts=%fv vec=%v", ELE_NEW, scale); - BMO_op_callf(bm, "transform verts=%fv mat=%m4", ELE_NEW, imtx); + BMO_op_callf(bm, op->flag, "transform verts=%fv mat=%m4", ELE_NEW, mtx); + BMO_op_callf(bm, op->flag, "scale verts=%fv vec=%v", ELE_NEW, scale); + BMO_op_callf(bm, op->flag, "transform verts=%fv mat=%m4", ELE_NEW, imtx); - BMO_op_init(bm, &weldop, "weld_verts"); + BMO_op_init(bm, &weldop, op->flag, "weld_verts"); v = BM_iter_new(&iter, bm, BM_VERTS_OF_MESH, NULL); for (i = 0; i < ototvert; i++) { diff --git a/source/blender/bmesh/operators/bmo_primitive.c b/source/blender/bmesh/operators/bmo_primitive.c index d59a90ba3a1..70173d942a1 100644 --- a/source/blender/bmesh/operators/bmo_primitive.c +++ b/source/blender/bmesh/operators/bmo_primitive.c @@ -267,19 +267,19 @@ void bmo_create_grid_exec(BMesh *bm, BMOperator *op) for (a = 0; a < seg - 1; a++) { if (a) { - BMO_op_initf(bm, &bmop, "extrude_edge_only edges=%s", &prevop, "geomout"); + BMO_op_initf(bm, &bmop, op->flag, "extrude_edge_only edges=%s", &prevop, "geomout"); BMO_op_exec(bm, &bmop); BMO_op_finish(bm, &prevop); BMO_slot_buffer_flag_enable(bm, &bmop, "geomout", BM_VERT, VERT_MARK); } else { - BMO_op_initf(bm, &bmop, "extrude_edge_only edges=%fe", EDGE_ORIG); + BMO_op_initf(bm, &bmop, op->flag, "extrude_edge_only edges=%fe", EDGE_ORIG); BMO_op_exec(bm, &bmop); BMO_slot_buffer_flag_enable(bm, &bmop, "geomout", BM_VERT, VERT_MARK); } - BMO_op_callf(bm, "translate vec=%v verts=%s", vec, &bmop, "geomout"); + BMO_op_callf(bm, op->flag, "translate vec=%v verts=%s", vec, &bmop, "geomout"); prevop = bmop; } @@ -333,17 +333,17 @@ void bmo_create_uvsphere_exec(BMesh *bm, BMOperator *op) for (a = 0; a < seg; a++) { if (a) { - BMO_op_initf(bm, &bmop, "extrude_edge_only edges=%s", &prevop, "geomout"); + BMO_op_initf(bm, &bmop, op->flag, "extrude_edge_only edges=%s", &prevop, "geomout"); BMO_op_exec(bm, &bmop); BMO_op_finish(bm, &prevop); } else { - BMO_op_initf(bm, &bmop, "extrude_edge_only edges=%fe", EDGE_ORIG); + BMO_op_initf(bm, &bmop, op->flag, "extrude_edge_only edges=%fe", EDGE_ORIG); BMO_op_exec(bm, &bmop); } BMO_slot_buffer_flag_enable(bm, &bmop, "geomout", BM_VERT, VERT_MARK); - BMO_op_callf(bm, "rotate cent=%v mat=%m3 verts=%s", vec, cmat, &bmop, "geomout"); + BMO_op_callf(bm, op->flag, "rotate cent=%v mat=%m3 verts=%s", vec, cmat, &bmop, "geomout"); prevop = bmop; } @@ -365,7 +365,7 @@ void bmo_create_uvsphere_exec(BMesh *bm, BMOperator *op) len2 = len_v3v3(vec, vec2); /* use shortest segment length divided by 3 as merge threshold */ - BMO_op_callf(bm, "remove_doubles verts=%fv dist=%f", VERT_MARK, MIN2(len, len2) / 3.0f); + BMO_op_callf(bm, op->flag, "remove_doubles verts=%fv dist=%f", VERT_MARK, MIN2(len, len2) / 3.0f); } /* and now do imat */ @@ -426,7 +426,7 @@ void bmo_create_icosphere_exec(BMesh *bm, BMOperator *op) if (subdiv > 1) { BMOperator bmop; - BMO_op_initf(bm, &bmop, + BMO_op_initf(bm, &bmop, op->flag, "subdivide_edges edges=%fe " "smooth=%f " "numcuts=%i " @@ -563,7 +563,7 @@ void bmo_create_circle_exec(BMesh *bm, BMOperator *op) } if (!cap_tris) { - BMO_op_callf(bm, "dissolve_faces faces=%ff", FACE_NEW); + BMO_op_callf(bm, op->flag, "dissolve_faces faces=%ff", FACE_NEW); } BMO_slot_buffer_from_enabled_flag(bm, op, "vertout", BM_VERT, VERT_MARK); @@ -656,12 +656,12 @@ void bmo_create_cone_exec(BMesh *bm, BMOperator *op) } if (!cap_tris) { - BMO_op_callf(bm, "dissolve_faces faces=%ff", FACE_NEW); + BMO_op_callf(bm, op->flag, "dissolve_faces faces=%ff", FACE_NEW); } BM_face_create_quad_tri(bm, v1, v2, firstv2, firstv1, NULL, FALSE); - BMO_op_callf(bm, "remove_doubles verts=%fv dist=%f", VERT_MARK, 0.000001); + BMO_op_callf(bm, op->flag, "remove_doubles verts=%fv dist=%f", VERT_MARK, 0.000001); BMO_slot_buffer_from_enabled_flag(bm, op, "vertout", BM_VERT, VERT_MARK); } diff --git a/source/blender/bmesh/operators/bmo_removedoubles.c b/source/blender/bmesh/operators/bmo_removedoubles.c index b3c348a330c..e1a5ef9f905 100644 --- a/source/blender/bmesh/operators/bmo_removedoubles.c +++ b/source/blender/bmesh/operators/bmo_removedoubles.c @@ -227,7 +227,7 @@ void bmo_weld_verts_exec(BMesh *bm, BMOperator *op) } } - BMO_op_callf(bm, "delete geom=%fvef context=%i", ELE_DEL, DEL_ONLYTAGGED); + BMO_op_callf(bm, op->flag, "delete geom=%fvef context=%i", ELE_DEL, DEL_ONLYTAGGED); BLI_array_free(edges); BLI_array_free(loops); @@ -347,8 +347,8 @@ void bmo_pointmerge_exec(BMesh *bm, BMOperator *op) BMO_slot_vec_get(op, "merge_co", vec); - //BMO_op_callf(bm, "collapse_uvs edges=%s", op, "edges"); - BMO_op_init(bm, &weldop, "weld_verts"); + //BMO_op_callf(bm, op->flag, "collapse_uvs edges=%s", op, "edges"); + BMO_op_init(bm, &weldop, op->flag, "weld_verts"); BMO_ITER (v, &siter, bm, op, "verts", BM_VERT) { if (!snapv) { @@ -374,8 +374,8 @@ void bmo_collapse_exec(BMesh *bm, BMOperator *op) float min[3], max[3]; int i, tot; - BMO_op_callf(bm, "collapse_uvs edges=%s", op, "edges"); - BMO_op_init(bm, &weldop, "weld_verts"); + BMO_op_callf(bm, op->flag, "collapse_uvs edges=%s", op, "edges"); + BMO_op_init(bm, &weldop, op->flag, "weld_verts"); BMO_slot_buffer_flag_enable(bm, op, "edges", BM_EDGE, EDGE_MARK); @@ -561,7 +561,7 @@ void bmo_remove_doubles_exec(BMesh *bm, BMOperator *op) { BMOperator weldop; - BMO_op_init(bm, &weldop, "weld_verts"); + BMO_op_init(bm, &weldop, op->flag, "weld_verts"); bmesh_find_doubles_common(bm, op, &weldop, "targetmap"); BMO_op_exec(bm, &weldop); BMO_op_finish(bm, &weldop); @@ -591,12 +591,12 @@ void bmo_automerge_exec(BMesh *bm, BMOperator *op) /* Search for doubles among all vertices, but only merge non-VERT_KEEP * vertices into VERT_KEEP vertices. */ - BMO_op_initf(bm, &findop, "find_doubles verts=%av keep_verts=%fv", VERT_KEEP); + BMO_op_initf(bm, &findop, op->flag, "find_doubles verts=%av keep_verts=%fv", VERT_KEEP); BMO_slot_copy(op, &findop, "dist", "dist"); BMO_op_exec(bm, &findop); /* weld the vertices */ - BMO_op_init(bm, &weldop, "weld_verts"); + BMO_op_init(bm, &weldop, op->flag, "weld_verts"); BMO_slot_copy(&findop, &weldop, "targetmapout", "targetmap"); BMO_op_exec(bm, &weldop); diff --git a/source/blender/bmesh/operators/bmo_subdivide.c b/source/blender/bmesh/operators/bmo_subdivide.c index ee3e34c527f..a03aa0caf10 100644 --- a/source/blender/bmesh/operators/bmo_subdivide.c +++ b/source/blender/bmesh/operators/bmo_subdivide.c @@ -1037,7 +1037,7 @@ void BM_mesh_esubdivide(BMesh *bm, const char edge_hflag, BMOperator op; /* use_sphere isnt exposed here since its only used for new primitives */ - BMO_op_initf(bm, &op, + BMO_op_initf(bm, &op, BMO_FLAG_DEFAULTS, "subdivide_edges edges=%he " "smooth=%f fractal=%f along_normal=%f " "numcuts=%i " diff --git a/source/blender/bmesh/operators/bmo_triangulate.c b/source/blender/bmesh/operators/bmo_triangulate.c index 0903620f9a0..de876477e5a 100644 --- a/source/blender/bmesh/operators/bmo_triangulate.c +++ b/source/blender/bmesh/operators/bmo_triangulate.c @@ -212,7 +212,7 @@ void bmo_triangle_fill_exec(BMesh *bm, BMOperator *op) BLI_smallhash_release(&hash); /* clean up fill */ - BMO_op_initf(bm, &bmop, "beautify_fill faces=%ff constrain_edges=%fe", ELE_NEW, EDGE_MARK); + BMO_op_initf(bm, &bmop, op->flag, "beautify_fill faces=%ff constrain_edges=%fe", ELE_NEW, EDGE_MARK); BMO_op_exec(bm, &bmop); BMO_slot_buffer_flag_enable(bm, &bmop, "geomout", BM_FACE | BM_EDGE, ELE_NEW); BMO_op_finish(bm, &bmop); diff --git a/source/blender/bmesh/operators/bmo_utils.c b/source/blender/bmesh/operators/bmo_utils.c index 916ae6ac785..d91a8e56227 100644 --- a/source/blender/bmesh/operators/bmo_utils.c +++ b/source/blender/bmesh/operators/bmo_utils.c @@ -73,7 +73,7 @@ void bmo_translate_exec(BMesh *bm, BMOperator *op) unit_m4(mat); copy_v3_v3(mat[3], vec); - BMO_op_callf(bm, "transform mat=%m4 verts=%s", mat, op, "verts"); + BMO_op_callf(bm, op->flag, "transform mat=%m4 verts=%s", mat, op, "verts"); } void bmo_scale_exec(BMesh *bm, BMOperator *op) @@ -87,7 +87,7 @@ void bmo_scale_exec(BMesh *bm, BMOperator *op) mat[1][1] = vec[1]; mat[2][2] = vec[2]; - BMO_op_callf(bm, "transform mat=%m3 verts=%s", mat, op, "verts"); + BMO_op_callf(bm, op->flag, "transform mat=%m3 verts=%s", mat, op, "verts"); } void bmo_rotate_exec(BMesh *bm, BMOperator *op) @@ -100,12 +100,12 @@ void bmo_rotate_exec(BMesh *bm, BMOperator *op) * this is how editmesh did it and I'm too tired to think * through the math right now. */ mul_v3_fl(vec, -1.0f); - BMO_op_callf(bm, "translate verts=%s vec=%v", op, "verts", vec); + BMO_op_callf(bm, op->flag, "translate verts=%s vec=%v", op, "verts", vec); - BMO_op_callf(bm, "transform mat=%s verts=%s", op, "mat", op, "verts"); + BMO_op_callf(bm, op->flag, "transform mat=%s verts=%s", op, "mat", op, "verts"); mul_v3_fl(vec, -1.0f); - BMO_op_callf(bm, "translate verts=%s vec=%v", op, "verts", vec); + BMO_op_callf(bm, op->flag, "translate verts=%s vec=%v", op, "verts", vec); } void bmo_reverse_faces_exec(BMesh *bm, BMOperator *op) @@ -304,7 +304,7 @@ void bmo_recalc_face_normals_exec(BMesh *bm, BMOperator *op) BLI_array_declare(fstack); BMLoop *l, *l2; float maxx, maxx_test, cent[3]; - int i, maxi, flagflip = BMO_slot_bool_get(op, "do_flip"); + int i, i_max, flagflip = BMO_slot_bool_get(op, "do_flip"); startf = NULL; maxx = -1.0e10; @@ -353,7 +353,7 @@ void bmo_recalc_face_normals_exec(BMesh *bm, BMOperator *op) BMO_elem_flag_enable(bm, startf, FACE_VIS); i = 0; - maxi = 1; + i_max = 1; while (i >= 0) { f = fstack[i]; i--; @@ -381,9 +381,9 @@ void bmo_recalc_face_normals_exec(BMesh *bm, BMOperator *op) } } - if (i == maxi) { + if (i == i_max) { BLI_array_grow_one(fstack); - maxi++; + i_max++; } fstack[i] = l2->f; @@ -413,11 +413,16 @@ void bmo_smooth_vert_exec(BMesh *bm, BMOperator *op) float (*cos)[3] = NULL; float *co, *co2, clipdist = BMO_slot_float_get(op, "clipdist"); int i, j, clipx, clipy, clipz; + int xaxis, yaxis, zaxis; clipx = BMO_slot_bool_get(op, "mirror_clip_x"); clipy = BMO_slot_bool_get(op, "mirror_clip_y"); clipz = BMO_slot_bool_get(op, "mirror_clip_z"); + xaxis = BMO_slot_bool_get(op, "use_axis_x"); + yaxis = BMO_slot_bool_get(op, "use_axis_y"); + zaxis = BMO_slot_bool_get(op, "use_axis_z"); + i = 0; BMO_ITER (v, &siter, bm, op, "verts", BM_VERT) { BLI_array_grow_one(cos); @@ -451,7 +456,13 @@ void bmo_smooth_vert_exec(BMesh *bm, BMOperator *op) i = 0; BMO_ITER (v, &siter, bm, op, "verts", BM_VERT) { - copy_v3_v3(v->co, cos[i]); + if (xaxis) + v->co[0] = cos[i][0]; + if (yaxis) + v->co[1] = cos[i][1]; + if (zaxis) + v->co[2] = cos[i][2]; + i++; } diff --git a/source/blender/collada/AnimationImporter.cpp b/source/blender/collada/AnimationImporter.cpp index 4182a9c4c93..9c11358ce7f 100644 --- a/source/blender/collada/AnimationImporter.cpp +++ b/source/blender/collada/AnimationImporter.cpp @@ -916,7 +916,7 @@ void AnimationImporter::translate_Animations(COLLADAFW::Node *node, } } - if ( (animType->camera) != 0) { + if (animType->camera != 0) { Camera *camera = (Camera *) ob->data; if (!camera->adt || !camera->adt->action) act = verify_adt_action((ID *)&camera->id, 1); diff --git a/source/blender/collada/GeometryExporter.cpp b/source/blender/collada/GeometryExporter.cpp index c3d1106b288..d30f9b86a5a 100644 --- a/source/blender/collada/GeometryExporter.cpp +++ b/source/blender/collada/GeometryExporter.cpp @@ -135,7 +135,7 @@ void GeometryExporter::operator()(Object *ob) // XXX slow if (ob->totcol) { - for (int a = 0; a < ob->totcol; a++) { + for (int a = 0; a < ob->totcol; a++) { createPolylist(a, has_uvs, has_color, ob, me, geom_id, norind); } } diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.cpp b/source/blender/compositor/intern/COM_MemoryBuffer.cpp index 0aae8853795..f8c842d8e67 100644 --- a/source/blender/compositor/intern/COM_MemoryBuffer.cpp +++ b/source/blender/compositor/intern/COM_MemoryBuffer.cpp @@ -87,6 +87,33 @@ float *MemoryBuffer::convertToValueBuffer() return result; } +float MemoryBuffer::getMaximumValue() +{ + float result = this->m_buffer[0]; + const unsigned int size = this->determineBufferSize(); + unsigned int i; + + const float *fp_src = this->m_buffer; + + for (i = 0; i < size; i++, fp_src += COM_NUMBER_OF_CHANNELS) { + float value = *fp_src; + if (value > result) { + result = value; + } + } + + return result; +} + +float MemoryBuffer::getMaximumValue(rcti* rect) +{ + MemoryBuffer *temp = new MemoryBuffer(NULL, rect); + temp->copyContentFrom(this); + float result = temp->getMaximumValue(); + delete temp; + return result; +} + MemoryBuffer::~MemoryBuffer() { if (this->m_buffer) { diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.h b/source/blender/compositor/intern/COM_MemoryBuffer.h index 5077a9e3228..411c5b9ad8a 100644 --- a/source/blender/compositor/intern/COM_MemoryBuffer.h +++ b/source/blender/compositor/intern/COM_MemoryBuffer.h @@ -122,11 +122,13 @@ public: /** * @brief after execution the state will be set to available by calling this method */ - void setCreatedState() { + void setCreatedState() + { this->m_state = COM_MB_AVAILABLE; } - inline void read(float result[4], int x, int y) { + inline void read(float result[4], int x, int y) + { if (x >= this->m_rect.xmin && x < this->m_rect.xmax && y >= this->m_rect.ymin && y < this->m_rect.ymax) { @@ -140,7 +142,8 @@ public: } } - inline void readNoCheck(float result[4], int x, int y) { + inline void readNoCheck(float result[4], int x, int y) + { const int dx = x - this->m_rect.xmin; const int dy = y - this->m_rect.ymin; const int offset = (this->m_chunkWidth * dy + dx) * COM_NUMBER_OF_CHANNELS; @@ -150,42 +153,42 @@ public: void writePixel(int x, int y, const float color[4]); void addPixel(int x, int y, const float color[4]); inline void readCubic(float result[4], float x, float y) - { - int x1 = floor(x); - int x2 = x1 + 1; - int y1 = floor(y); - int y2 = y1 + 1; - - float valuex = x - x1; - float valuey = y - y1; - float mvaluex = 1.0f - valuex; - float mvaluey = 1.0f - valuey; - - float color1[4]; - float color2[4]; - float color3[4]; - float color4[4]; - - read(color1, x1, y1); - read(color2, x1, y2); - read(color3, x2, y1); - read(color4, x2, y2); - - color1[0] = color1[0] * mvaluey + color2[0] * valuey; - color1[1] = color1[1] * mvaluey + color2[1] * valuey; - color1[2] = color1[2] * mvaluey + color2[2] * valuey; - color1[3] = color1[3] * mvaluey + color2[3] * valuey; - - color3[0] = color3[0] * mvaluey + color4[0] * valuey; - color3[1] = color3[1] * mvaluey + color4[1] * valuey; - color3[2] = color3[2] * mvaluey + color4[2] * valuey; - color3[3] = color3[3] * mvaluey + color4[3] * valuey; - - result[0] = color1[0] * mvaluex + color3[0] * valuex; - result[1] = color1[1] * mvaluex + color3[1] * valuex; - result[2] = color1[2] * mvaluex + color3[2] * valuex; - result[3] = color1[3] * mvaluex + color3[3] * valuex; - } + { + int x1 = floor(x); + int x2 = x1 + 1; + int y1 = floor(y); + int y2 = y1 + 1; + + float valuex = x - x1; + float valuey = y - y1; + float mvaluex = 1.0f - valuex; + float mvaluey = 1.0f - valuey; + + float color1[4]; + float color2[4]; + float color3[4]; + float color4[4]; + + read(color1, x1, y1); + read(color2, x1, y2); + read(color3, x2, y1); + read(color4, x2, y2); + + color1[0] = color1[0] * mvaluey + color2[0] * valuey; + color1[1] = color1[1] * mvaluey + color2[1] * valuey; + color1[2] = color1[2] * mvaluey + color2[2] * valuey; + color1[3] = color1[3] * mvaluey + color2[3] * valuey; + + color3[0] = color3[0] * mvaluey + color4[0] * valuey; + color3[1] = color3[1] * mvaluey + color4[1] * valuey; + color3[2] = color3[2] * mvaluey + color4[2] * valuey; + color3[3] = color3[3] * mvaluey + color4[3] * valuey; + + result[0] = color1[0] * mvaluex + color3[0] * valuex; + result[1] = color1[1] * mvaluex + color3[1] * valuex; + result[2] = color1[2] * mvaluex + color3[2] * valuex; + result[3] = color1[3] * mvaluex + color3[3] * valuex; + } @@ -225,6 +228,8 @@ public: MemoryBuffer *duplicate(); float *convertToValueBuffer(); + float getMaximumValue(); + float getMaximumValue(rcti* rect); private: unsigned int determineBufferSize(); diff --git a/source/blender/compositor/intern/COM_OpenCLDevice.h b/source/blender/compositor/intern/COM_OpenCLDevice.h index 577df5caf77..f1a1e31c930 100644 --- a/source/blender/compositor/intern/COM_OpenCLDevice.h +++ b/source/blender/compositor/intern/COM_OpenCLDevice.h @@ -92,9 +92,9 @@ public: */ void execute(WorkPackage *work); - cl_context getContext(){ return this->m_context; } + cl_context getContext() { return this->m_context; } - cl_command_queue getQueue(){ return this->m_queue; } + cl_command_queue getQueue() { return this->m_queue; } cl_mem COM_clAttachMemoryBufferToKernelParameter(cl_kernel kernel, int parameterIndex, int offsetIndex, list *cleanup, MemoryBuffer **inputMemoryBuffers, SocketReader *reader); cl_mem COM_clAttachMemoryBufferToKernelParameter(cl_kernel kernel, int parameterIndex, int offsetIndex, list *cleanup, MemoryBuffer **inputMemoryBuffers, ReadBufferOperation *reader); diff --git a/source/blender/compositor/nodes/COM_BilateralBlurNode.cpp b/source/blender/compositor/nodes/COM_BilateralBlurNode.cpp index 683093302c1..399d2adf0be 100644 --- a/source/blender/compositor/nodes/COM_BilateralBlurNode.cpp +++ b/source/blender/compositor/nodes/COM_BilateralBlurNode.cpp @@ -21,7 +21,6 @@ */ #include "COM_BilateralBlurNode.h" -#include "DNA_scene_types.h" #include "DNA_node_types.h" #include "COM_ExecutionSystem.h" #include "COM_BilateralBlurOperation.h" diff --git a/source/blender/compositor/nodes/COM_BlurNode.cpp b/source/blender/compositor/nodes/COM_BlurNode.cpp index 9b945887ec2..059b01e2c05 100644 --- a/source/blender/compositor/nodes/COM_BlurNode.cpp +++ b/source/blender/compositor/nodes/COM_BlurNode.cpp @@ -21,7 +21,6 @@ */ #include "COM_BlurNode.h" -#include "DNA_scene_types.h" #include "DNA_node_types.h" #include "COM_GaussianXBlurOperation.h" #include "COM_GaussianYBlurOperation.h" diff --git a/source/blender/compositor/nodes/COM_BokehBlurNode.cpp b/source/blender/compositor/nodes/COM_BokehBlurNode.cpp index 300193da842..f45572fe4ae 100644 --- a/source/blender/compositor/nodes/COM_BokehBlurNode.cpp +++ b/source/blender/compositor/nodes/COM_BokehBlurNode.cpp @@ -21,7 +21,6 @@ */ #include "COM_BokehBlurNode.h" -#include "DNA_scene_types.h" #include "DNA_camera_types.h" #include "DNA_object_types.h" #include "DNA_node_types.h" diff --git a/source/blender/compositor/nodes/COM_BokehImageNode.cpp b/source/blender/compositor/nodes/COM_BokehImageNode.cpp index 75f5e07d552..f6abbbb9a9a 100644 --- a/source/blender/compositor/nodes/COM_BokehImageNode.cpp +++ b/source/blender/compositor/nodes/COM_BokehImageNode.cpp @@ -21,7 +21,6 @@ */ #include "COM_BokehImageNode.h" -#include "DNA_scene_types.h" #include "COM_BokehImageOperation.h" #include "COM_ExecutionSystem.h" diff --git a/source/blender/compositor/nodes/COM_BoxMaskNode.cpp b/source/blender/compositor/nodes/COM_BoxMaskNode.cpp index 789ff265a5c..0580a32ed8c 100644 --- a/source/blender/compositor/nodes/COM_BoxMaskNode.cpp +++ b/source/blender/compositor/nodes/COM_BoxMaskNode.cpp @@ -21,7 +21,6 @@ */ #include "COM_BoxMaskNode.h" -#include "DNA_scene_types.h" #include "COM_BoxMaskOperation.h" #include "COM_ExecutionSystem.h" diff --git a/source/blender/compositor/nodes/COM_BrightnessNode.cpp b/source/blender/compositor/nodes/COM_BrightnessNode.cpp index 1e1fbdbc301..cd230a23a5c 100644 --- a/source/blender/compositor/nodes/COM_BrightnessNode.cpp +++ b/source/blender/compositor/nodes/COM_BrightnessNode.cpp @@ -21,7 +21,6 @@ */ #include "COM_BrightnessNode.h" -#include "DNA_scene_types.h" #include "COM_BrightnessOperation.h" #include "COM_ExecutionSystem.h" diff --git a/source/blender/compositor/nodes/COM_ColorCorrectionNode.cpp b/source/blender/compositor/nodes/COM_ColorCorrectionNode.cpp index 41b3bebbd7b..a05abaf17d3 100644 --- a/source/blender/compositor/nodes/COM_ColorCorrectionNode.cpp +++ b/source/blender/compositor/nodes/COM_ColorCorrectionNode.cpp @@ -21,7 +21,6 @@ */ #include "COM_ColorCorrectionNode.h" -#include "DNA_scene_types.h" #include "COM_ColorCorrectionOperation.h" #include "COM_ExecutionSystem.h" diff --git a/source/blender/compositor/nodes/COM_ColorCurveNode.cpp b/source/blender/compositor/nodes/COM_ColorCurveNode.cpp index 9ae11c22b6a..93ff304afd8 100644 --- a/source/blender/compositor/nodes/COM_ColorCurveNode.cpp +++ b/source/blender/compositor/nodes/COM_ColorCurveNode.cpp @@ -21,7 +21,6 @@ */ #include "COM_ColorCurveNode.h" -#include "DNA_scene_types.h" #include "COM_ColorCurveOperation.h" #include "COM_ExecutionSystem.h" diff --git a/source/blender/compositor/nodes/COM_ColorNode.cpp b/source/blender/compositor/nodes/COM_ColorNode.cpp index 65480c7aeb2..088f8bbb19d 100644 --- a/source/blender/compositor/nodes/COM_ColorNode.cpp +++ b/source/blender/compositor/nodes/COM_ColorNode.cpp @@ -21,7 +21,6 @@ */ #include "COM_ColorNode.h" -#include "DNA_scene_types.h" #include "COM_SetColorOperation.h" #include "COM_ExecutionSystem.h" diff --git a/source/blender/compositor/nodes/COM_CompositorNode.cpp b/source/blender/compositor/nodes/COM_CompositorNode.cpp index 28e466203c4..d0d66a81c77 100644 --- a/source/blender/compositor/nodes/COM_CompositorNode.cpp +++ b/source/blender/compositor/nodes/COM_CompositorNode.cpp @@ -31,15 +31,19 @@ CompositorNode::CompositorNode(bNode *editorNode) : Node(editorNode) void CompositorNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context) { + bNode *editorNode = this->getbNode(); + InputSocket *imageSocket = this->getInputSocket(0); InputSocket *alphaSocket = this->getInputSocket(1); - if (imageSocket->isConnected()) { - CompositorOperation *colorAlphaProg = new CompositorOperation(); - colorAlphaProg->setRenderData(context->getRenderData()); - colorAlphaProg->setbNodeTree(context->getbNodeTree()); - imageSocket->relinkConnections(colorAlphaProg->getInputSocket(0)); - alphaSocket->relinkConnections(colorAlphaProg->getInputSocket(1)); - graph->addOperation(colorAlphaProg); - addPreviewOperation(graph, colorAlphaProg->getInputSocket(0)); - } + InputSocket *depthSocket = this->getInputSocket(2); + + CompositorOperation *compositorOperation = new CompositorOperation(); + compositorOperation->setSceneName(editorNode->id->name); + compositorOperation->setRenderData(context->getRenderData()); + compositorOperation->setbNodeTree(context->getbNodeTree()); + imageSocket->relinkConnections(compositorOperation->getInputSocket(0), 0, graph); + alphaSocket->relinkConnections(compositorOperation->getInputSocket(1)); + depthSocket->relinkConnections(compositorOperation->getInputSocket(2)); + graph->addOperation(compositorOperation); + addPreviewOperation(graph, compositorOperation->getInputSocket(0)); } diff --git a/source/blender/compositor/nodes/COM_DilateErodeNode.cpp b/source/blender/compositor/nodes/COM_DilateErodeNode.cpp index 043ae367fbb..cecc3bf6e86 100644 --- a/source/blender/compositor/nodes/COM_DilateErodeNode.cpp +++ b/source/blender/compositor/nodes/COM_DilateErodeNode.cpp @@ -21,7 +21,6 @@ */ #include "COM_DilateErodeNode.h" -#include "DNA_scene_types.h" #include "COM_ExecutionSystem.h" #include "COM_DilateErodeOperation.h" #include "COM_AntiAliasOperation.h" diff --git a/source/blender/compositor/nodes/COM_DirectionalBlurNode.cpp b/source/blender/compositor/nodes/COM_DirectionalBlurNode.cpp index 85fc63ae8cb..eb30f6952ba 100644 --- a/source/blender/compositor/nodes/COM_DirectionalBlurNode.cpp +++ b/source/blender/compositor/nodes/COM_DirectionalBlurNode.cpp @@ -21,7 +21,6 @@ */ #include "COM_DirectionalBlurNode.h" -#include "DNA_scene_types.h" #include "DNA_node_types.h" #include "COM_ExecutionSystem.h" #include "COM_DirectionalBlurOperation.h" diff --git a/source/blender/compositor/nodes/COM_DoubleEdgeMaskNode.cpp b/source/blender/compositor/nodes/COM_DoubleEdgeMaskNode.cpp index ab1d83385c7..40a9d1fa275 100644 --- a/source/blender/compositor/nodes/COM_DoubleEdgeMaskNode.cpp +++ b/source/blender/compositor/nodes/COM_DoubleEdgeMaskNode.cpp @@ -22,7 +22,6 @@ #include "COM_DoubleEdgeMaskNode.h" #include "COM_DoubleEdgeMaskOperation.h" -#include "DNA_scene_types.h" #include "COM_ExecutionSystem.h" DoubleEdgeMaskNode::DoubleEdgeMaskNode(bNode *editorNode) : Node(editorNode) diff --git a/source/blender/compositor/nodes/COM_EllipseMaskNode.cpp b/source/blender/compositor/nodes/COM_EllipseMaskNode.cpp index 23410c6a115..dc4421abb25 100644 --- a/source/blender/compositor/nodes/COM_EllipseMaskNode.cpp +++ b/source/blender/compositor/nodes/COM_EllipseMaskNode.cpp @@ -21,7 +21,6 @@ */ #include "COM_EllipseMaskNode.h" -#include "DNA_scene_types.h" #include "COM_EllipseMaskOperation.h" #include "COM_ExecutionSystem.h" diff --git a/source/blender/compositor/nodes/COM_GammaNode.cpp b/source/blender/compositor/nodes/COM_GammaNode.cpp index 52699c83bf9..33a5cb282a1 100644 --- a/source/blender/compositor/nodes/COM_GammaNode.cpp +++ b/source/blender/compositor/nodes/COM_GammaNode.cpp @@ -21,7 +21,6 @@ */ #include "COM_GammaNode.h" -#include "DNA_scene_types.h" #include "COM_GammaOperation.h" #include "COM_ExecutionSystem.h" diff --git a/source/blender/compositor/nodes/COM_IDMaskNode.cpp b/source/blender/compositor/nodes/COM_IDMaskNode.cpp index 31d2ccb391e..12a508c75f5 100644 --- a/source/blender/compositor/nodes/COM_IDMaskNode.cpp +++ b/source/blender/compositor/nodes/COM_IDMaskNode.cpp @@ -21,7 +21,6 @@ */ #include "COM_IDMaskNode.h" -#include "DNA_scene_types.h" #include "COM_IDMaskOperation.h" #include "COM_ExecutionSystem.h" #include "COM_AntiAliasOperation.h" diff --git a/source/blender/compositor/nodes/COM_InvertNode.cpp b/source/blender/compositor/nodes/COM_InvertNode.cpp index c468bda1b67..9c4e28a2971 100644 --- a/source/blender/compositor/nodes/COM_InvertNode.cpp +++ b/source/blender/compositor/nodes/COM_InvertNode.cpp @@ -21,7 +21,6 @@ */ #include "COM_InvertNode.h" -#include "DNA_scene_types.h" #include "COM_InvertOperation.h" #include "COM_ExecutionSystem.h" #include "BKE_node.h" diff --git a/source/blender/compositor/nodes/COM_KeyingNode.cpp b/source/blender/compositor/nodes/COM_KeyingNode.cpp index efd50a44a51..6bc9afba32c 100644 --- a/source/blender/compositor/nodes/COM_KeyingNode.cpp +++ b/source/blender/compositor/nodes/COM_KeyingNode.cpp @@ -30,6 +30,8 @@ #include "COM_KeyingDespillOperation.h" #include "COM_KeyingClipOperation.h" +#include "COM_MathBaseOperation.h" + #include "COM_SeparateChannelOperation.h" #include "COM_CombineChannelsOperation.h" #include "COM_ConvertRGBToYCCOperation.h" @@ -239,8 +241,6 @@ void KeyingNode::convertToOperations(ExecutionSystem *graph, CompositorContext * keyingOperation->setScreenBalance(keying_data->screen_balance); inputScreen->relinkConnections(keyingOperation->getInputSocket(1), 1, graph); - inputGarbageMatte->relinkConnections(keyingOperation->getInputSocket(2), 2, graph); - inputCoreMatte->relinkConnections(keyingOperation->getInputSocket(3), 3, graph); if (keying_data->blur_pre) { /* chroma preblur operation for input of keying operation */ @@ -256,18 +256,54 @@ void KeyingNode::convertToOperations(ExecutionSystem *graph, CompositorContext * postprocessedMatte = keyingOperation->getOutputSocket(); + /* black / white clipping */ if (keying_data->clip_black > 0.0f || keying_data->clip_white < 1.0f) { postprocessedMatte = setupClip(graph, postprocessedMatte, keying_data->edge_kernel_radius, keying_data->edge_kernel_tolerance, keying_data->clip_black, keying_data->clip_white, false); } + /* output edge matte */ if (outputEdges->isConnected()) { edgesMatte = setupClip(graph, postprocessedMatte, keying_data->edge_kernel_radius, keying_data->edge_kernel_tolerance, keying_data->clip_black, keying_data->clip_white, true); } + /* apply garbage matte */ + if (inputGarbageMatte->isConnected()) { + SetValueOperation *valueOperation = new SetValueOperation(); + MathSubtractOperation *subtractOperation = new MathSubtractOperation(); + MathMinimumOperation *minOperation = new MathMinimumOperation(); + + valueOperation->setValue(1.0f); + + addLink(graph, valueOperation->getOutputSocket(), subtractOperation->getInputSocket(0)); + inputGarbageMatte->relinkConnections(subtractOperation->getInputSocket(1), 0, graph); + + addLink(graph, subtractOperation->getOutputSocket(), minOperation->getInputSocket(0)); + addLink(graph, postprocessedMatte, minOperation->getInputSocket(1)); + + postprocessedMatte = minOperation->getOutputSocket(); + + graph->addOperation(valueOperation); + graph->addOperation(subtractOperation); + graph->addOperation(minOperation); + } + + /* apply core matte */ + if (inputCoreMatte->isConnected()) { + MathMaximumOperation *maxOperation = new MathMaximumOperation(); + + inputCoreMatte->relinkConnections(maxOperation->getInputSocket(0), 0, graph); + + addLink(graph, postprocessedMatte, maxOperation->getInputSocket(1)); + + postprocessedMatte = maxOperation->getOutputSocket(); + + graph->addOperation(maxOperation); + } + /* apply blur on matte if needed */ if (keying_data->blur_post) postprocessedMatte = setupPostBlur(graph, postprocessedMatte, keying_data->blur_post); diff --git a/source/blender/compositor/nodes/COM_LensDistortionNode.cpp b/source/blender/compositor/nodes/COM_LensDistortionNode.cpp index 3913b4ac2b6..94c2fc885fb 100644 --- a/source/blender/compositor/nodes/COM_LensDistortionNode.cpp +++ b/source/blender/compositor/nodes/COM_LensDistortionNode.cpp @@ -21,7 +21,6 @@ */ #include "COM_LensDistortionNode.h" -#include "DNA_scene_types.h" #include "COM_ExecutionSystem.h" #include "COM_ProjectorLensDistortionOperation.h" #include "COM_ScreenLensDistortionOperation.h" diff --git a/source/blender/compositor/nodes/COM_MaskNode.cpp b/source/blender/compositor/nodes/COM_MaskNode.cpp index b6300300f6f..8d549d09362 100644 --- a/source/blender/compositor/nodes/COM_MaskNode.cpp +++ b/source/blender/compositor/nodes/COM_MaskNode.cpp @@ -36,18 +36,30 @@ MaskNode::MaskNode(bNode *editorNode) : Node(editorNode) void MaskNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context) { - const RenderData *data = context->getRenderData(); + const RenderData *rd = context->getRenderData(); OutputSocket *outputMask = this->getOutputSocket(0); bNode *editorNode = this->getbNode(); + NodeMask *data = (NodeMask *)editorNode->storage; Mask *mask = (Mask *)editorNode->id; // always connect the output image MaskOperation *operation = new MaskOperation(); operation->setbNode(editorNode); - operation->setMaskWidth(data->xsch * data->size / 100.0f); - operation->setMaskHeight(data->ysch * data->size / 100.0f); + + if (editorNode->custom1 & CMP_NODEFLAG_MASK_FIXED) { + operation->setMaskWidth(data->size_x); + operation->setMaskHeight(data->size_y); + } + else if (editorNode->custom1 & CMP_NODEFLAG_MASK_FIXED_SCENE) { + operation->setMaskWidth(data->size_x * (rd->size / 100.0f)); + operation->setMaskHeight(data->size_y * (rd->size / 100.0f)); + } + else { + operation->setMaskWidth(rd->xsch * rd->size / 100.0f); + operation->setMaskHeight(rd->ysch * rd->size / 100.0f); + } if (outputMask->isConnected()) { outputMask->relinkConnections(operation->getOutputSocket()); @@ -58,5 +70,13 @@ void MaskNode::convertToOperations(ExecutionSystem *graph, CompositorContext *co operation->setSmooth((bool)(editorNode->custom1 & CMP_NODEFLAG_MASK_AA) != 0); operation->setFeather((bool)(editorNode->custom1 & CMP_NODEFLAG_MASK_NO_FEATHER) == 0); + if ((editorNode->custom1 & CMP_NODEFLAG_MASK_MOTION_BLUR) && + (editorNode->custom2 > 1) && + (editorNode->custom3 > FLT_EPSILON)) + { + operation->setMotionBlurSamples(editorNode->custom2); + operation->setMotionBlurShutter(editorNode->custom3); + } + graph->addOperation(operation); } diff --git a/source/blender/compositor/nodes/COM_MuteNode.cpp b/source/blender/compositor/nodes/COM_MuteNode.cpp index f52b7216cca..2c96473a556 100644 --- a/source/blender/compositor/nodes/COM_MuteNode.cpp +++ b/source/blender/compositor/nodes/COM_MuteNode.cpp @@ -20,14 +20,16 @@ * Monique Dewanchand */ -#include - #include "COM_MuteNode.h" #include "COM_SocketConnection.h" #include "COM_SetValueOperation.h" #include "COM_SetVectorOperation.h" #include "COM_SetColorOperation.h" +extern "C" { + #include "BLI_listbase.h" +} + MuteNode::MuteNode(bNode *editorNode) : Node(editorNode) { /* pass */ @@ -45,7 +47,12 @@ void MuteNode::reconnect(ExecutionSystem *graph, OutputSocket *output) } } } - + + createDefaultOutput(graph, output); +} + +void MuteNode::createDefaultOutput(ExecutionSystem *graph, OutputSocket *output) +{ NodeOperation *operation = NULL; switch (output->getDataType()) { case COM_DT_VALUE: @@ -84,14 +91,59 @@ void MuteNode::reconnect(ExecutionSystem *graph, OutputSocket *output) output->clearConnections(); } +template void MuteNode::fillSocketMap(vector &sockets, SocketMap &socketMap) +{ + for (typename vector::iterator it = sockets.begin(); it != sockets.end(); it++) { + Socket *socket = (Socket *) *it; + + socketMap.insert(std::pair(socket->getbNodeSocket(), socket)); + } +} + void MuteNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context) { + bNode *editorNode = this->getbNode(); vector &outputsockets = this->getOutputSockets(); - for (unsigned int index = 0; index < outputsockets.size(); index++) { - OutputSocket *output = outputsockets[index]; - if (output->isConnected()) { - reconnect(graph, output); + /* mute node is also used for unknown nodes and couple of nodes in fast mode + * can't use generic routines in that case + */ + if ((editorNode->flag & NODE_MUTED) && editorNode->typeinfo->internal_connect) { + vector &inputsockets = this->getInputSockets(); + bNodeTree *editorTree = (bNodeTree *) context->getbNodeTree(); + SocketMap socketMap; + ListBase intlinks; + bNodeLink *link; + + intlinks = editorNode->typeinfo->internal_connect(editorTree, editorNode); + + this->fillSocketMap(outputsockets, socketMap); + this->fillSocketMap(inputsockets, socketMap); + + for (link = (bNodeLink *) intlinks.first; link; link = link->next) { + if (link->fromnode == editorNode) { + InputSocket *fromSocket = (InputSocket *) socketMap.find(link->fromsock)->second; + OutputSocket *toSocket = (OutputSocket *) socketMap.find(link->tosock)->second; + + if (toSocket->isConnected()) { + if (fromSocket->isConnected()) { + toSocket->relinkConnections(fromSocket->getConnection()->getFromSocket(), false); + } + else { + createDefaultOutput(graph, toSocket); + } + } + } + } + + BLI_freelistN(&intlinks); + } + else { + for (unsigned int index = 0; index < outputsockets.size(); index++) { + OutputSocket *output = outputsockets[index]; + if (output->isConnected()) { + reconnect(graph, output); + } } } } diff --git a/source/blender/compositor/nodes/COM_MuteNode.h b/source/blender/compositor/nodes/COM_MuteNode.h index aab37e5f888..2e5250e625e 100644 --- a/source/blender/compositor/nodes/COM_MuteNode.h +++ b/source/blender/compositor/nodes/COM_MuteNode.h @@ -23,8 +23,14 @@ #ifndef _COM_MuteNode_h_ #define _COM_MuteNode_h_ +#include + #include "COM_Node.h" +extern "C" { + #include "BKE_node.h" +} + /** * @brief MuteNode * @ingroup Node @@ -34,7 +40,12 @@ public: MuteNode(bNode *editorNode); void convertToOperations(ExecutionSystem *graph, CompositorContext *context); private: + typedef std::map SocketMap; + void reconnect(ExecutionSystem *graph, OutputSocket *output); + void createDefaultOutput(ExecutionSystem *graph, OutputSocket *output); + + template void fillSocketMap(vector &sockets, SocketMap &socketMap); }; #endif diff --git a/source/blender/compositor/nodes/COM_ScaleNode.cpp b/source/blender/compositor/nodes/COM_ScaleNode.cpp index 95b048b6cad..c51782b77af 100644 --- a/source/blender/compositor/nodes/COM_ScaleNode.cpp +++ b/source/blender/compositor/nodes/COM_ScaleNode.cpp @@ -64,7 +64,7 @@ void ScaleNode::convertToOperations(ExecutionSystem *graph, CompositorContext *c break; case CMP_SCALE_RENDERPERCENT: { - const RenderData *data = context->getRenderData(); + const RenderData *rd = context->getRenderData(); ScaleFixedSizeOperation *operation = new ScaleFixedSizeOperation(); /* framing options */ @@ -72,8 +72,8 @@ void ScaleNode::convertToOperations(ExecutionSystem *graph, CompositorContext *c operation->setIsCrop((bnode->custom2 & CMP_SCALE_RENDERSIZE_FRAME_CROP) != 0); operation->setOffset(bnode->custom3, bnode->custom4); - operation->setNewWidth(data->xsch * data->size / 100.0f); - operation->setNewHeight(data->ysch * data->size / 100.0f); + operation->setNewWidth(rd->xsch * rd->size / 100.0f); + operation->setNewHeight(rd->ysch * rd->size / 100.0f); inputSocket->relinkConnections(operation->getInputSocket(0), 0, graph); outputSocket->relinkConnections(operation->getOutputSocket(0)); operation->getInputSocket(0)->getConnection()->setIgnoreResizeCheck(true); diff --git a/source/blender/compositor/nodes/COM_TimeNode.cpp b/source/blender/compositor/nodes/COM_TimeNode.cpp index 8e155e375e1..84ee4e77b06 100644 --- a/source/blender/compositor/nodes/COM_TimeNode.cpp +++ b/source/blender/compositor/nodes/COM_TimeNode.cpp @@ -21,7 +21,6 @@ */ #include "COM_TimeNode.h" -#include "DNA_scene_types.h" #include "COM_SetValueOperation.h" #include "COM_ExecutionSystem.h" extern "C" { diff --git a/source/blender/compositor/nodes/COM_TonemapNode.cpp b/source/blender/compositor/nodes/COM_TonemapNode.cpp index 68e322e9dcf..440e6b62414 100644 --- a/source/blender/compositor/nodes/COM_TonemapNode.cpp +++ b/source/blender/compositor/nodes/COM_TonemapNode.cpp @@ -21,7 +21,6 @@ */ #include "COM_TonemapNode.h" -#include "DNA_scene_types.h" #include "COM_TonemapOperation.h" #include "COM_ExecutionSystem.h" diff --git a/source/blender/compositor/nodes/COM_TrackPositionNode.cpp b/source/blender/compositor/nodes/COM_TrackPositionNode.cpp index 243f63a0149..f4efcfe27f0 100644 --- a/source/blender/compositor/nodes/COM_TrackPositionNode.cpp +++ b/source/blender/compositor/nodes/COM_TrackPositionNode.cpp @@ -52,17 +52,20 @@ void TrackPositionNode::convertToOperations(ExecutionSystem *graph, CompositorCo operationX->setTrackName(trackpos_data->track_name); operationX->setFramenumber(context->getFramenumber()); operationX->setAxis(0); - operationX->setRelative(editorNode->custom1); + operationX->setPosition(editorNode->custom1); + operationX->setRelativeFrame(editorNode->custom2); operationY->setMovieClip(clip); operationY->setTrackingObject(trackpos_data->tracking_object); operationY->setTrackName(trackpos_data->track_name); operationY->setFramenumber(context->getFramenumber()); operationY->setAxis(1); - operationY->setRelative(editorNode->custom1); + operationY->setPosition(editorNode->custom1); + operationY->setRelativeFrame(editorNode->custom2); outputX->relinkConnections(operationX->getOutputSocket()); outputY->relinkConnections(operationY->getOutputSocket()); graph->addOperation(operationX); + graph->addOperation(operationY); } diff --git a/source/blender/compositor/nodes/COM_ValueNode.cpp b/source/blender/compositor/nodes/COM_ValueNode.cpp index 89b0602f8b0..593d74952ee 100644 --- a/source/blender/compositor/nodes/COM_ValueNode.cpp +++ b/source/blender/compositor/nodes/COM_ValueNode.cpp @@ -21,7 +21,6 @@ */ #include "COM_ValueNode.h" -#include "DNA_scene_types.h" #include "COM_SetValueOperation.h" #include "COM_ExecutionSystem.h" diff --git a/source/blender/compositor/nodes/COM_VectorCurveNode.cpp b/source/blender/compositor/nodes/COM_VectorCurveNode.cpp index ee32c3b77a3..dcf1059ece6 100644 --- a/source/blender/compositor/nodes/COM_VectorCurveNode.cpp +++ b/source/blender/compositor/nodes/COM_VectorCurveNode.cpp @@ -21,7 +21,6 @@ */ #include "COM_VectorCurveNode.h" -#include "DNA_scene_types.h" #include "COM_VectorCurveOperation.h" #include "COM_ExecutionSystem.h" diff --git a/source/blender/compositor/nodes/COM_ViewLevelsNode.cpp b/source/blender/compositor/nodes/COM_ViewLevelsNode.cpp index 309568c3aec..6bb873e0dec 100644 --- a/source/blender/compositor/nodes/COM_ViewLevelsNode.cpp +++ b/source/blender/compositor/nodes/COM_ViewLevelsNode.cpp @@ -21,7 +21,6 @@ */ #include "COM_ViewLevelsNode.h" -#include "DNA_scene_types.h" #include "COM_ExecutionSystem.h" #include "COM_CalculateMeanOperation.h" #include "COM_CalculateStandardDeviationOperation.h" diff --git a/source/blender/compositor/nodes/COM_ViewerNode.cpp b/source/blender/compositor/nodes/COM_ViewerNode.cpp index 1205767cb28..88ce0ff2016 100644 --- a/source/blender/compositor/nodes/COM_ViewerNode.cpp +++ b/source/blender/compositor/nodes/COM_ViewerNode.cpp @@ -35,23 +35,32 @@ void ViewerNode::convertToOperations(ExecutionSystem *graph, CompositorContext * { InputSocket *imageSocket = this->getInputSocket(0); InputSocket *alphaSocket = this->getInputSocket(1); + InputSocket *depthSocket = this->getInputSocket(2); Image *image = (Image *)this->getbNode()->id; ImageUser *imageUser = (ImageUser *) this->getbNode()->storage; bNode *editorNode = this->getbNode(); - if (imageSocket->isConnected()) { - ViewerOperation *viewerOperation = new ViewerOperation(); - viewerOperation->setColorManagement(context->getRenderData()->color_mgt_flag & R_COLOR_MANAGEMENT); - viewerOperation->setColorPredivide(context->getRenderData()->color_mgt_flag & R_COLOR_MANAGEMENT_PREDIVIDE); - viewerOperation->setbNodeTree(context->getbNodeTree()); - viewerOperation->setImage(image); - viewerOperation->setImageUser(imageUser); - viewerOperation->setActive((editorNode->flag & NODE_DO_OUTPUT) && this->isInActiveGroup()); - viewerOperation->setChunkOrder((OrderOfChunks)editorNode->custom1); - viewerOperation->setCenterX(editorNode->custom3); - viewerOperation->setCenterY(editorNode->custom4); - imageSocket->relinkConnections(viewerOperation->getInputSocket(0), 0, graph); - alphaSocket->relinkConnections(viewerOperation->getInputSocket(1)); - graph->addOperation(viewerOperation); - addPreviewOperation(graph, viewerOperation->getInputSocket(0)); + ViewerOperation *viewerOperation = new ViewerOperation(); + viewerOperation->setColorManagement(context->getRenderData()->color_mgt_flag & R_COLOR_MANAGEMENT); + viewerOperation->setColorPredivide(context->getRenderData()->color_mgt_flag & R_COLOR_MANAGEMENT_PREDIVIDE); + viewerOperation->setbNodeTree(context->getbNodeTree()); + viewerOperation->setImage(image); + viewerOperation->setImageUser(imageUser); + viewerOperation->setActive((editorNode->flag & NODE_DO_OUTPUT) && this->isInActiveGroup()); + viewerOperation->setChunkOrder((OrderOfChunks)editorNode->custom1); + viewerOperation->setCenterX(editorNode->custom3); + viewerOperation->setCenterY(editorNode->custom4); + + viewerOperation->setResolutionInputSocketIndex(0); + if (!imageSocket->isConnected()) + { + if (alphaSocket->isConnected()) { + viewerOperation->setResolutionInputSocketIndex(1); + } } + + imageSocket->relinkConnections(viewerOperation->getInputSocket(0), 0, graph); + alphaSocket->relinkConnections(viewerOperation->getInputSocket(1)); + depthSocket->relinkConnections(viewerOperation->getInputSocket(2)); + graph->addOperation(viewerOperation); + addPreviewOperation(graph, viewerOperation->getInputSocket(0)); } diff --git a/source/blender/compositor/operations/COM_BokehBlurOperation.cpp b/source/blender/compositor/operations/COM_BokehBlurOperation.cpp index ff9bfb73396..a3d685de9a6 100644 --- a/source/blender/compositor/operations/COM_BokehBlurOperation.cpp +++ b/source/blender/compositor/operations/COM_BokehBlurOperation.cpp @@ -94,9 +94,14 @@ void BokehBlurOperation::executePixel(float *color, int x, int y, void *data) int bufferstartx = inputBuffer->getRect()->xmin; int bufferstarty = inputBuffer->getRect()->ymin; int pixelSize = this->m_size * this->getWidth() / 100.0f; - if (pixelSize==0){ - this->m_inputProgram->read(color, x, y, COM_PS_NEAREST); - return; + zero_v4(color_accum); + + if (pixelSize<2) { + this->m_inputProgram->read(color_accum, x, y, COM_PS_NEAREST); + multiplier_accum[0] = 1.0f; + multiplier_accum[1] = 1.0f; + multiplier_accum[2] = 1.0f; + multiplier_accum[3] = 1.0f; } int miny = y - pixelSize; int maxy = y + pixelSize; @@ -107,7 +112,6 @@ void BokehBlurOperation::executePixel(float *color, int x, int y, void *data) maxy = min(maxy, inputBuffer->getRect()->ymax); maxx = min(maxx, inputBuffer->getRect()->xmax); - zero_v4(color_accum); int step = getStep(); int offsetadd = getOffsetAdd(); diff --git a/source/blender/compositor/operations/COM_CompositorOperation.cpp b/source/blender/compositor/operations/COM_CompositorOperation.cpp index 43aad4f19d9..cba8c753d6a 100644 --- a/source/blender/compositor/operations/COM_CompositorOperation.cpp +++ b/source/blender/compositor/operations/COM_CompositorOperation.cpp @@ -23,7 +23,6 @@ #include "COM_CompositorOperation.h" #include "COM_SocketConnection.h" #include "BLI_listbase.h" -#include "DNA_scene_types.h" #include "BKE_image.h" extern "C" { @@ -41,11 +40,16 @@ CompositorOperation::CompositorOperation() : NodeOperation() { this->addInputSocket(COM_DT_COLOR); this->addInputSocket(COM_DT_VALUE); + this->addInputSocket(COM_DT_VALUE); this->setRenderData(NULL); this->m_outputBuffer = NULL; + this->m_depthBuffer = NULL; this->m_imageInput = NULL; this->m_alphaInput = NULL; + this->m_depthInput = NULL; + + this->m_sceneName[0] = '\0'; } void CompositorOperation::initExecution() @@ -53,16 +57,19 @@ void CompositorOperation::initExecution() // When initializing the tree during initial load the width and height can be zero. this->m_imageInput = getInputSocketReader(0); this->m_alphaInput = getInputSocketReader(1); + this->m_depthInput = getInputSocketReader(2); if (this->getWidth() * this->getHeight() != 0) { this->m_outputBuffer = (float *) MEM_callocN(this->getWidth() * this->getHeight() * 4 * sizeof(float), "CompositorOperation"); } + if (this->m_depthInput != NULL) { + this->m_depthBuffer = (float *) MEM_callocN(this->getWidth() * this->getHeight() * sizeof(float), "CompositorOperation"); + } } void CompositorOperation::deinitExecution() { if (!isBreaked()) { - const RenderData *rd = this->m_rd; - Render *re = RE_GetRender_FromData(rd); + Render *re = RE_GetRender(this->m_sceneName); RenderResult *rr = RE_AcquireResultWrite(re); if (rr) { @@ -70,11 +77,18 @@ void CompositorOperation::deinitExecution() MEM_freeN(rr->rectf); } rr->rectf = this->m_outputBuffer; + if (rr->rectz != NULL) { + MEM_freeN(rr->rectz); + } + rr->rectz = this->m_depthBuffer; } else { if (this->m_outputBuffer) { MEM_freeN(this->m_outputBuffer); } + if (this->m_depthBuffer) { + MEM_freeN(this->m_depthBuffer); + } } BLI_lock_thread(LOCK_DRAW_IMAGE); @@ -90,11 +104,16 @@ void CompositorOperation::deinitExecution() if (this->m_outputBuffer) { MEM_freeN(this->m_outputBuffer); } + if (this->m_depthBuffer) { + MEM_freeN(this->m_depthBuffer); + } } this->m_outputBuffer = NULL; + this->m_depthBuffer = NULL; this->m_imageInput = NULL; this->m_alphaInput = NULL; + this->m_depthInput = NULL; } @@ -102,13 +121,16 @@ void CompositorOperation::executeRegion(rcti *rect, unsigned int tileNumber) { float color[8]; // 7 is enough float *buffer = this->m_outputBuffer; + float *zbuffer = this->m_depthBuffer; if (!buffer) return; int x1 = rect->xmin; int y1 = rect->ymin; int x2 = rect->xmax; int y2 = rect->ymax; - int offset = (y1 * this->getWidth() + x1) * COM_NUMBER_OF_CHANNELS; + int offset = (y1 * this->getWidth() + x1); + int add = (this->getWidth() - (x2 - x1)); + int offset4 = offset * COM_NUMBER_OF_CHANNELS; int x; int y; bool breaked = false; @@ -119,13 +141,20 @@ void CompositorOperation::executeRegion(rcti *rect, unsigned int tileNumber) if (this->m_alphaInput != NULL) { this->m_alphaInput->read(&(color[3]), x, y, COM_PS_NEAREST); } - copy_v4_v4(buffer + offset, color); - offset += COM_NUMBER_OF_CHANNELS; + copy_v4_v4(buffer + offset4, color); + + if (this->m_depthInput != NULL) { + this->m_depthInput->read(color, x, y, COM_PS_NEAREST); + zbuffer[offset] = color[0]; + } + offset4 += COM_NUMBER_OF_CHANNELS; + offset++; if (isBreaked()) { breaked = true; } } - offset += (this->getWidth() - (x2 - x1)) * COM_NUMBER_OF_CHANNELS; + offset += add; + offset4 += add * COM_NUMBER_OF_CHANNELS; } } @@ -136,7 +165,7 @@ void CompositorOperation::determineResolution(unsigned int resolution[], unsigne // check actual render resolution with cropping it may differ with cropped border.rendering // FIX for: [31777] Border Crop gives black (easy) - Render *re = RE_GetRender_FromData(this->m_rd); + Render *re = RE_GetRender(this->m_sceneName); if (re) { RenderResult *rr = RE_AcquireResultRead(re); if (rr) { diff --git a/source/blender/compositor/operations/COM_CompositorOperation.h b/source/blender/compositor/operations/COM_CompositorOperation.h index 23d34abbfff..882e50b4922 100644 --- a/source/blender/compositor/operations/COM_CompositorOperation.h +++ b/source/blender/compositor/operations/COM_CompositorOperation.h @@ -23,14 +23,16 @@ #ifndef _COM_CompositorOperation_h #define _COM_CompositorOperation_h #include "COM_NodeOperation.h" -#include "DNA_scene_types.h" #include "BLI_rect.h" +#include "BLI_string.h" /** * @brief Compositor output operation */ class CompositorOperation : public NodeOperation { private: + char m_sceneName[MAX_ID_NAME]; + /** * @brief local reference to the scene */ @@ -41,6 +43,11 @@ private: */ float *m_outputBuffer; + /** + * @brief reference to the output depth float buffer + */ + float *m_depthBuffer; + /** * @brief local reference to the input image operation */ @@ -50,9 +57,15 @@ private: * @brief local reference to the input alpha operation */ SocketReader *m_alphaInput; + + /** + * @brief local reference to the depth operation + */ + SocketReader *m_depthInput; public: CompositorOperation(); void executeRegion(rcti *rect, unsigned int tileNumber); + void setSceneName(const char *sceneName) { BLI_strncpy(this->m_sceneName, sceneName, sizeof(this->m_sceneName)); } void setRenderData(const RenderData *rd) { this->m_rd = rd; } bool isOutputOperation(bool rendering) const { return true; } void initExecution(); diff --git a/source/blender/compositor/operations/COM_DilateErodeOperation.cpp b/source/blender/compositor/operations/COM_DilateErodeOperation.cpp index 71be94bf2a7..2752c6a7b90 100644 --- a/source/blender/compositor/operations/COM_DilateErodeOperation.cpp +++ b/source/blender/compositor/operations/COM_DilateErodeOperation.cpp @@ -384,7 +384,7 @@ void DilateStepOperation::deinitExecution() this->m_inputProgram = NULL; this->deinitMutex(); if (this->m_cached_buffer) { - delete this->m_cached_buffer; + delete [] this->m_cached_buffer; this->m_cached_buffer = NULL; } } diff --git a/source/blender/compositor/operations/COM_DoubleEdgeMaskOperation.cpp b/source/blender/compositor/operations/COM_DoubleEdgeMaskOperation.cpp index f647629815b..7c5614c0de1 100644 --- a/source/blender/compositor/operations/COM_DoubleEdgeMaskOperation.cpp +++ b/source/blender/compositor/operations/COM_DoubleEdgeMaskOperation.cpp @@ -1273,8 +1273,8 @@ void *DoubleEdgeMaskOperation::initializeTileData(rcti *rect) float *imask = innerMask->convertToValueBuffer(); float *omask = outerMask->convertToValueBuffer(); doDoubleEdgeMask(imask, omask, data); - delete imask; - delete omask; + delete [] imask; + delete [] omask; this->m_cachedInstance = data; } unlockMutex(); @@ -1282,12 +1282,9 @@ void *DoubleEdgeMaskOperation::initializeTileData(rcti *rect) } void DoubleEdgeMaskOperation::executePixel(float *color, int x, int y, void *data) { - float *buffer = (float *) data; + float *buffer = (float *)data; int index = (y * this->getWidth() + x); - color[0] = buffer[index]; - color[1] = buffer[index + 1]; - color[2] = buffer[index + 2]; - color[3] = buffer[index + 3]; + copy_v4_v4(color, buffer + index); } void DoubleEdgeMaskOperation::deinitExecution() diff --git a/source/blender/compositor/operations/COM_GlareFogGlowOperation.cpp b/source/blender/compositor/operations/COM_GlareFogGlowOperation.cpp index 5452e779968..7f7429bf2e6 100644 --- a/source/blender/compositor/operations/COM_GlareFogGlowOperation.cpp +++ b/source/blender/compositor/operations/COM_GlareFogGlowOperation.cpp @@ -260,6 +260,7 @@ void convolve(float *dst, MemoryBuffer *in1, MemoryBuffer *in2) float *imageBuffer = in1->getBuffer(); MemoryBuffer *rdst = new MemoryBuffer(NULL, in1->getRect()); + memset(rdst->getBuffer(), 0, rdst->getWidth() * rdst->getHeight() * COM_NUMBER_OF_CHANNELS * sizeof(float)); // convolution result width & height w2 = 2 * kernelWidth - 1; diff --git a/source/blender/compositor/operations/COM_ImageOperation.cpp b/source/blender/compositor/operations/COM_ImageOperation.cpp index 729b3f8f18f..36cc6ca8d6d 100644 --- a/source/blender/compositor/operations/COM_ImageOperation.cpp +++ b/source/blender/compositor/operations/COM_ImageOperation.cpp @@ -23,7 +23,6 @@ #include "COM_ImageOperation.h" #include "BLI_listbase.h" -#include "DNA_scene_types.h" #include "DNA_image_types.h" #include "BKE_image.h" #include "BLI_math.h" diff --git a/source/blender/compositor/operations/COM_ImageOperation.h b/source/blender/compositor/operations/COM_ImageOperation.h index 847096c7d43..ed7b10cd4f5 100644 --- a/source/blender/compositor/operations/COM_ImageOperation.h +++ b/source/blender/compositor/operations/COM_ImageOperation.h @@ -25,7 +25,6 @@ #define _COM_ImageOperation_h #include "COM_NodeOperation.h" -#include "DNA_scene_types.h" #include "BLI_listbase.h" #include "BKE_image.h" extern "C" { diff --git a/source/blender/compositor/operations/COM_KeyingOperation.cpp b/source/blender/compositor/operations/COM_KeyingOperation.cpp index 5912c206a84..ed9e4f1df16 100644 --- a/source/blender/compositor/operations/COM_KeyingOperation.cpp +++ b/source/blender/compositor/operations/COM_KeyingOperation.cpp @@ -57,45 +57,33 @@ KeyingOperation::KeyingOperation() : NodeOperation() { this->addInputSocket(COM_DT_COLOR); this->addInputSocket(COM_DT_COLOR); - this->addInputSocket(COM_DT_VALUE); - this->addInputSocket(COM_DT_VALUE); this->addOutputSocket(COM_DT_VALUE); this->m_screenBalance = 0.5f; this->m_pixelReader = NULL; this->m_screenReader = NULL; - this->m_garbageReader = NULL; - this->m_coreReader = NULL; } void KeyingOperation::initExecution() { this->m_pixelReader = this->getInputSocketReader(0); this->m_screenReader = this->getInputSocketReader(1); - this->m_garbageReader = this->getInputSocketReader(2); - this->m_coreReader = this->getInputSocketReader(3); } void KeyingOperation::deinitExecution() { this->m_pixelReader = NULL; this->m_screenReader = NULL; - this->m_garbageReader = NULL; - this->m_coreReader = NULL; } void KeyingOperation::executePixel(float *color, float x, float y, PixelSampler sampler) { float pixelColor[4]; float screenColor[4]; - float garbageValue[4]; - float coreValue[4]; this->m_pixelReader->read(pixelColor, x, y, sampler); this->m_screenReader->read(screenColor, x, y, sampler); - this->m_garbageReader->read(garbageValue, x, y, sampler); - this->m_coreReader->read(coreValue, x, y, sampler); int primary_channel = get_pixel_primary_channel(screenColor); @@ -130,10 +118,4 @@ void KeyingOperation::executePixel(float *color, float x, float y, PixelSampler color[0] = distance; } } - - /* apply garbage matte */ - color[0] = MIN2(color[0], 1.0f - garbageValue[0]); - - /* apply core matte */ - color[0] = MAX2(color[0], coreValue[0]); } diff --git a/source/blender/compositor/operations/COM_KeyingOperation.h b/source/blender/compositor/operations/COM_KeyingOperation.h index 413aaf6a81e..5ca4db7fc75 100644 --- a/source/blender/compositor/operations/COM_KeyingOperation.h +++ b/source/blender/compositor/operations/COM_KeyingOperation.h @@ -38,8 +38,6 @@ class KeyingOperation : public NodeOperation { protected: SocketReader *m_pixelReader; SocketReader *m_screenReader; - SocketReader *m_garbageReader; - SocketReader *m_coreReader; float m_screenBalance; diff --git a/source/blender/compositor/operations/COM_KeyingScreenOperation.cpp b/source/blender/compositor/operations/COM_KeyingScreenOperation.cpp index 87a8fd22758..33bdd892fe8 100644 --- a/source/blender/compositor/operations/COM_KeyingScreenOperation.cpp +++ b/source/blender/compositor/operations/COM_KeyingScreenOperation.cpp @@ -29,8 +29,6 @@ #include "BLI_math.h" #include "BLI_math_color.h" -#include "DNA_scene_types.h" - extern "C" { #include "BKE_movieclip.h" #include "BKE_tracking.h" diff --git a/source/blender/compositor/operations/COM_KeyingScreenOperation.h b/source/blender/compositor/operations/COM_KeyingScreenOperation.h index f6982ef09f3..04e47e6e77f 100644 --- a/source/blender/compositor/operations/COM_KeyingScreenOperation.h +++ b/source/blender/compositor/operations/COM_KeyingScreenOperation.h @@ -29,7 +29,6 @@ #include "COM_NodeOperation.h" -#include "DNA_scene_types.h" #include "DNA_movieclip_types.h" #include "BLI_listbase.h" diff --git a/source/blender/compositor/operations/COM_MaskOperation.cpp b/source/blender/compositor/operations/COM_MaskOperation.cpp index c648f3e6f08..1812b7372bb 100644 --- a/source/blender/compositor/operations/COM_MaskOperation.cpp +++ b/source/blender/compositor/operations/COM_MaskOperation.cpp @@ -28,12 +28,8 @@ #include "BLI_listbase.h" #include "BLI_math.h" -#include "DNA_scene_types.h" - -#ifdef USE_RASKTER - extern "C" { - #include "../../../../intern/raskter/raskter.h" + #include "BKE_mask.h" } MaskOperation::MaskOperation() : NodeOperation() @@ -42,124 +38,74 @@ MaskOperation::MaskOperation() : NodeOperation() this->m_mask = NULL; this->m_maskWidth = 0; this->m_maskHeight = 0; - this->m_framenumber = 0; - this->m_rasterizedMask = NULL; - setComplex(true); + this->m_maskWidthInv = 0.0f; + this->m_maskHeightInv = 0.0f; + this->m_frame_shutter = 0.0f; + this->m_frame_number = 0; + this->m_rasterMaskHandleTot = 1; + memset(this->m_rasterMaskHandles, 0, sizeof(this->m_rasterMaskHandles)); } void MaskOperation::initExecution() { - initMutex(); + if (this->m_mask && this->m_rasterMaskHandles[0] == NULL) { + if (this->m_rasterMaskHandleTot == 1) { + this->m_rasterMaskHandles[0] = BKE_maskrasterize_handle_new(); - this->m_rasterizedMask = NULL; - this->m_maskLayers.first = this->m_maskLayers.last = NULL; - - if (this->m_mask) { - BKE_mask_layer_copy_list(&this->m_maskLayers, &this->m_mask->masklayers); - } -} - -void MaskOperation::deinitExecution() -{ - BKE_mask_layer_free_list(&this->m_maskLayers); - - if (this->m_rasterizedMask) { - MEM_freeN(this->m_rasterizedMask); - this->m_rasterizedMask = NULL; - } -} - -void *MaskOperation::initializeTileData(rcti *rect) -{ - if (this->m_rasterizedMask) - return this->m_rasterizedMask; - - if (!this->m_mask) - return NULL; - - lockMutex(); - if (this->m_rasterizedMask == NULL) { - int width = this->getWidth(); - int height = this->getHeight(); - float *buffer; - - buffer = (float *)MEM_callocN(sizeof(float) * width * height, "rasterized mask"); - - BKE_mask_rasterize_layers(&this->m_maskLayers, width, height, buffer, TRUE, - this->m_do_smooth, this->m_do_feather); - - if (this->m_do_smooth) { - PLX_antialias_buffer(buffer, width, height); + BKE_maskrasterize_handle_init(this->m_rasterMaskHandles[0], this->m_mask, + this->m_maskWidth, this->m_maskHeight, + TRUE, this->m_do_smooth, this->m_do_feather); } + else { + /* make a throw away copy of the mask */ + const float frame = (float)this->m_frame_number - this->m_frame_shutter; + const float frame_step = (this->m_frame_shutter * 2.0f) / this->m_rasterMaskHandleTot; + float frame_iter = frame; - this->m_rasterizedMask = buffer; - } - unlockMutex(); - return this->m_rasterizedMask; -} + Mask *mask_temp; -void MaskOperation::determineResolution(unsigned int resolution[], unsigned int preferredResolution[]) -{ - if (this->m_maskWidth == 0 || this->m_maskHeight == 0) { - NodeOperation::determineResolution(resolution, preferredResolution); - } - else { - unsigned int nr[2]; + mask_temp = BKE_mask_copy_nolib(this->m_mask); - nr[0] = this->m_maskWidth; - nr[1] = this->m_maskHeight; + /* trick so we can get unkeyed edits to display */ + { + MaskLayer *masklay; + MaskLayerShape *masklay_shape; - NodeOperation::determineResolution(resolution, nr); + for (masklay = (MaskLayer *)mask_temp->masklayers.first; + masklay; + masklay = (MaskLayer *)masklay->next) + { + masklay_shape = BKE_mask_layer_shape_varify_frame(masklay, this->m_frame_number); + BKE_mask_layer_shape_from_mask(masklay, masklay_shape); + } + } - resolution[0] = this->m_maskWidth; - resolution[1] = this->m_maskHeight; - } -} + for (unsigned int i = 0; i < this->m_rasterMaskHandleTot; i++) { + this->m_rasterMaskHandles[i] = BKE_maskrasterize_handle_new(); -void MaskOperation::executePixel(float *color, int x, int y, void *data) -{ - if (!data) { - color[0] = 0.0f; - } - else { - float *buffer = (float *) data; - int index = (y * this->getWidth() + x); + /* re-eval frame info */ + BKE_mask_evaluate(mask_temp, frame_iter, TRUE); - color[0] = buffer[index]; - } -} + BKE_maskrasterize_handle_init(this->m_rasterMaskHandles[i], mask_temp, + this->m_maskWidth, this->m_maskHeight, + TRUE, this->m_do_smooth, this->m_do_feather); -#else /* mask rasterizer by campbell wip */ + frame_iter += frame_step; + } -MaskOperation::MaskOperation() : NodeOperation() -{ - this->addOutputSocket(COM_DT_VALUE); - this->m_mask = NULL; - this->m_maskWidth = 0; - this->m_maskHeight = 0; - this->m_framenumber = 0; - this->m_rasterMaskHandle = NULL; -} - -void MaskOperation::initExecution() -{ - if (this->m_mask) { - if (this->m_rasterMaskHandle == NULL) { - const int width = this->getWidth(); - const int height = this->getHeight(); - - this->m_rasterMaskHandle = BKE_maskrasterize_handle_new(); - - BKE_maskrasterize_handle_init(this->m_rasterMaskHandle, this->m_mask, width, height, TRUE, this->m_do_smooth, this->m_do_feather); + BKE_mask_free(mask_temp); + MEM_freeN(mask_temp); } } } void MaskOperation::deinitExecution() { - if (this->m_rasterMaskHandle) { - BKE_maskrasterize_handle_free(this->m_rasterMaskHandle); - this->m_rasterMaskHandle = NULL; + for (unsigned int i = 0; i < this->m_rasterMaskHandleTot; i++) { + if (this->m_rasterMaskHandles[i]) { + BKE_maskrasterize_handle_free(this->m_rasterMaskHandles[i]); + this->m_rasterMaskHandles[i] = NULL; + } } } @@ -183,13 +129,27 @@ void MaskOperation::determineResolution(unsigned int resolution[], unsigned int void MaskOperation::executePixel(float *color, float x, float y, PixelSampler sampler) { - const float xy[2] = {x / (float)this->m_maskWidth, y / (float)this->m_maskHeight}; - if (this->m_rasterMaskHandle) { - color[0] = BKE_maskrasterize_handle_sample(this->m_rasterMaskHandle, xy); + const float xy[2] = {x * this->m_maskWidthInv, y * this->m_maskHeightInv}; + + if (this->m_rasterMaskHandleTot == 1) { + if (this->m_rasterMaskHandles[0]) { + color[0] = BKE_maskrasterize_handle_sample(this->m_rasterMaskHandles[0], xy); + } + else { + color[0] = 0.0f; + } } else { + /* incase loop below fails */ color[0] = 0.0f; + + for (unsigned int i = 0; i < this->m_rasterMaskHandleTot; i++) { + if (this->m_rasterMaskHandles[i]) { + color[0] += BKE_maskrasterize_handle_sample(this->m_rasterMaskHandles[i], xy); + } + } + + /* until we get better falloff */ + color[0] /= this->m_rasterMaskHandleTot; } } - -#endif /* USE_RASKTER */ diff --git a/source/blender/compositor/operations/COM_MaskOperation.h b/source/blender/compositor/operations/COM_MaskOperation.h index f367298b3d6..6e1735bcf9d 100644 --- a/source/blender/compositor/operations/COM_MaskOperation.h +++ b/source/blender/compositor/operations/COM_MaskOperation.h @@ -21,45 +21,37 @@ * Sergey Sharybin */ - #ifndef _COM_MaskOperation_h #define _COM_MaskOperation_h -/* XXX, remove when the USE_RASKTER option is also removed */ -extern "C" { - #include "BKE_mask.h" -} #include "COM_NodeOperation.h" -#include "DNA_scene_types.h" #include "DNA_mask_types.h" #include "BLI_listbase.h" #include "IMB_imbuf_types.h" -#ifdef __PLX_RASKTER_MT__ -#include "../../../../intern/raskter/raskter.h" -#endif - /** * Class with implementation of mask rasterization */ class MaskOperation : public NodeOperation { protected: Mask *m_mask; - int m_maskWidth; - int m_maskHeight; - int m_framenumber; + + /* note, these are used more like aspect, + * but they _do_ impact on mask detail */ + int m_maskWidth; + int m_maskHeight; + float m_maskWidthInv; /* 1 / m_maskWidth */ + float m_maskHeightInv; /* 1 / m_maskHeight */ + + float m_frame_shutter; + int m_frame_number; + bool m_do_smooth; bool m_do_feather; -#ifdef USE_RASKTER - float *m_rasterizedMask; - - ListBase m_maskLayers; - -#else /* USE_RASKTER */ - struct MaskRasterHandle *m_rasterMaskHandle; -#endif /* USE_RASKTER */ + struct MaskRasterHandle *m_rasterMaskHandles[CMP_NODE_MASK_MBLUR_SAMPLES_MAX]; + unsigned int m_rasterMaskHandleTot; /** * Determine the output resolution. The resolution is retrieved from the Renderer @@ -74,18 +66,24 @@ public: void setMask(Mask *mask) { this->m_mask = mask; } - void setMaskWidth(int width) { this->m_maskWidth = width; } - void setMaskHeight(int height) { this->m_maskHeight = height; } - void setFramenumber(int framenumber) { this->m_framenumber = framenumber; } + void setMaskWidth(int width) + { + this->m_maskWidth = width; + this->m_maskWidthInv = 1.0f / (float)width; + } + void setMaskHeight(int height) + { + this->m_maskHeight = height; + this->m_maskHeightInv = 1.0f / (float)height; + } + void setFramenumber(int frame_number) { this->m_frame_number = frame_number; } void setSmooth(bool smooth) { this->m_do_smooth = smooth; } void setFeather(bool feather) { this->m_do_feather = feather; } -#ifdef USE_RASKTER - void *initializeTileData(rcti *rect); - void executePixel(float *color, int x, int y, void *data); -#else /* USE_RASKTER */ + void setMotionBlurSamples(int samples) { this->m_rasterMaskHandleTot = min(max(1, samples), CMP_NODE_MASK_MBLUR_SAMPLES_MAX); } + void setMotionBlurShutter(float shutter) { this->m_frame_shutter = shutter; } + void executePixel(float *color, float x, float y, PixelSampler sampler); -#endif /* USE_RASKTER */ }; #endif diff --git a/source/blender/compositor/operations/COM_MovieClipOperation.cpp b/source/blender/compositor/operations/COM_MovieClipOperation.cpp index 8b88f5c7d14..ea267830b86 100644 --- a/source/blender/compositor/operations/COM_MovieClipOperation.cpp +++ b/source/blender/compositor/operations/COM_MovieClipOperation.cpp @@ -23,7 +23,6 @@ #include "COM_MovieClipOperation.h" #include "BLI_listbase.h" -#include "DNA_scene_types.h" #include "BLI_math.h" extern "C" { #include "BKE_movieclip.h" diff --git a/source/blender/compositor/operations/COM_MovieClipOperation.h b/source/blender/compositor/operations/COM_MovieClipOperation.h index f3e95818bd7..6ca10e2fa9d 100644 --- a/source/blender/compositor/operations/COM_MovieClipOperation.h +++ b/source/blender/compositor/operations/COM_MovieClipOperation.h @@ -25,7 +25,6 @@ #define _COM_ImageOperation_h #include "COM_NodeOperation.h" -#include "DNA_scene_types.h" #include "DNA_movieclip_types.h" #include "BLI_listbase.h" #include "IMB_imbuf_types.h" diff --git a/source/blender/compositor/operations/COM_OutputFileOperation.cpp b/source/blender/compositor/operations/COM_OutputFileOperation.cpp index 83dae7475fb..b72875ab2f9 100644 --- a/source/blender/compositor/operations/COM_OutputFileOperation.cpp +++ b/source/blender/compositor/operations/COM_OutputFileOperation.cpp @@ -27,7 +27,6 @@ #include "BLI_listbase.h" #include "BLI_path_util.h" #include "BLI_string.h" -#include "DNA_scene_types.h" #include "BKE_image.h" #include "BKE_global.h" #include "BKE_main.h" diff --git a/source/blender/compositor/operations/COM_PreviewOperation.cpp b/source/blender/compositor/operations/COM_PreviewOperation.cpp index 8008c95c734..a400402417b 100644 --- a/source/blender/compositor/operations/COM_PreviewOperation.cpp +++ b/source/blender/compositor/operations/COM_PreviewOperation.cpp @@ -23,7 +23,6 @@ #include "COM_PreviewOperation.h" #include "COM_SocketConnection.h" #include "BLI_listbase.h" -#include "DNA_scene_types.h" #include "BKE_image.h" #include "WM_api.h" #include "WM_types.h" diff --git a/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.cpp b/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.cpp index daf517876e5..e28e77a5f5e 100644 --- a/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.cpp +++ b/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.cpp @@ -95,7 +95,7 @@ void ProjectorLensDistortionOperation::updateDispersion() float result[4]; this->getInputSocketReader(1)->read(result, 0, 0, COM_PS_NEAREST); this->m_dispersion = result[0]; - this->m_kr = 0.25f * MAX2(MIN2(this->m_dispersion, 1.f), 0.f); + this->m_kr = 0.25f * maxf(minf(this->m_dispersion, 1.0f), 0.0f); this->m_kr2 = this->m_kr * 20; this->m_dispersionAvailable = true; } diff --git a/source/blender/compositor/operations/COM_ScaleOperation.cpp b/source/blender/compositor/operations/COM_ScaleOperation.cpp index f4a3dc5fa25..642d1878049 100644 --- a/source/blender/compositor/operations/COM_ScaleOperation.cpp +++ b/source/blender/compositor/operations/COM_ScaleOperation.cpp @@ -184,6 +184,7 @@ ScaleFixedSizeOperation::ScaleFixedSizeOperation() : NodeOperation() this->addOutputSocket(COM_DT_COLOR); this->setResolutionInputSocketIndex(0); this->m_inputOperation = NULL; + this->m_is_offset = false; } void ScaleFixedSizeOperation::initExecution() { diff --git a/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cpp b/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cpp index d431ce29554..f8628be3ff8 100644 --- a/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cpp +++ b/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cpp @@ -301,11 +301,11 @@ bool ScreenLensDistortionOperation::determineDependingAreaOfInterest(rcti *input void ScreenLensDistortionOperation::updateVariables(float distortion, float dispersion) { - this->m_kg = MAX2(MIN2(distortion, 1.f), -0.999f); + this->m_kg = maxf(minf(distortion, 1.0f), -0.999f); // smaller dispersion range for somewhat more control - const float d = 0.25f * MAX2(MIN2(dispersion, 1.f), 0.f); - this->m_kr = MAX2(MIN2((this->m_kg + d), 1.0f), -0.999f); - this->m_kb = MAX2(MIN2((this->m_kg - d), 1.0f), -0.999f); + const float d = 0.25f * maxf(minf(dispersion, 1.0f), 0.0f); + this->m_kr = maxf(minf((this->m_kg + d), 1.0f), -0.999f); + this->m_kb = maxf(minf((this->m_kg - d), 1.0f), -0.999f); this->m_maxk = MAX3(this->m_kr, this->m_kg, this->m_kb); this->m_sc = (this->m_data->fit && (this->m_maxk > 0.f)) ? (1.f / (1.f + 2.f * this->m_maxk)) : (1.f / (1.f + this->m_maxk)); this->m_drg = 4.f * (this->m_kg - this->m_kr); diff --git a/source/blender/compositor/operations/COM_SplitViewerOperation.cpp b/source/blender/compositor/operations/COM_SplitViewerOperation.cpp index 80de4e71fce..d59d1f9f10d 100644 --- a/source/blender/compositor/operations/COM_SplitViewerOperation.cpp +++ b/source/blender/compositor/operations/COM_SplitViewerOperation.cpp @@ -23,7 +23,6 @@ #include "COM_SplitViewerOperation.h" #include "COM_SocketConnection.h" #include "BLI_listbase.h" -#include "DNA_scene_types.h" #include "BKE_image.h" #include "BLI_utildefines.h" #include "BLI_math_color.h" diff --git a/source/blender/compositor/operations/COM_TextureOperation.cpp b/source/blender/compositor/operations/COM_TextureOperation.cpp index 4cf935799cb..5a32bcb76ac 100644 --- a/source/blender/compositor/operations/COM_TextureOperation.cpp +++ b/source/blender/compositor/operations/COM_TextureOperation.cpp @@ -23,7 +23,6 @@ #include "COM_TextureOperation.h" #include "BLI_listbase.h" -#include "DNA_scene_types.h" TextureBaseOperation::TextureBaseOperation() : NodeOperation() { diff --git a/source/blender/compositor/operations/COM_TextureOperation.h b/source/blender/compositor/operations/COM_TextureOperation.h index 8735aff19dc..3631f8d24ff 100644 --- a/source/blender/compositor/operations/COM_TextureOperation.h +++ b/source/blender/compositor/operations/COM_TextureOperation.h @@ -25,7 +25,6 @@ #define _COM_TextureOperation_h #include "COM_NodeOperation.h" -#include "DNA_scene_types.h" #include "DNA_texture_types.h" #include "BLI_listbase.h" extern "C" { diff --git a/source/blender/compositor/operations/COM_TrackPositionOperation.cpp b/source/blender/compositor/operations/COM_TrackPositionOperation.cpp index cf516401a3c..869ec71614a 100644 --- a/source/blender/compositor/operations/COM_TrackPositionOperation.cpp +++ b/source/blender/compositor/operations/COM_TrackPositionOperation.cpp @@ -29,8 +29,6 @@ #include "BLI_math.h" #include "BLI_math_color.h" -#include "DNA_scene_types.h" - extern "C" { #include "BKE_movieclip.h" #include "BKE_tracking.h" @@ -39,58 +37,78 @@ extern "C" { TrackPositionOperation::TrackPositionOperation() : NodeOperation() { this->addOutputSocket(COM_DT_VALUE); - this->movieClip = NULL; - this->framenumber = 0; - this->trackingObject[0] = 0; - this->trackName[0] = 0; - this->axis = 0; - this->relative = false; + this->m_movieClip = NULL; + this->m_framenumber = 0; + this->m_trackingObjectName[0] = 0; + this->m_trackName[0] = 0; + this->m_axis = 0; + this->m_position = POSITION_ABSOLUTE;; + this->m_relativeFrame = 0; } -void TrackPositionOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]) +void TrackPositionOperation::initExecution() { + MovieTracking *tracking = NULL; MovieClipUser user = {0}; - MovieTracking *tracking = &movieClip->tracking; - MovieTrackingObject *object = BKE_tracking_object_get_named(tracking, this->trackingObject); - MovieTrackingTrack *track; - MovieTrackingMarker *marker; - int width, height; + MovieTrackingObject *object; - outputValue[0] = 0.0f; + zero_v2(this->m_markerPos); + zero_v2(this->m_relativePos); - if (!object) + if (!this->m_movieClip) return; - track = BKE_tracking_track_get_named(tracking, object, this->trackName); + tracking = &this->m_movieClip->tracking; - if (!track) - return; + BKE_movieclip_user_set_frame(&user, this->m_framenumber); + BKE_movieclip_get_size(this->m_movieClip, &user, &this->m_width, &this->m_height); - BKE_movieclip_user_set_frame(&user, this->framenumber); - BKE_movieclip_get_size(this->movieClip, &user, &width, &height); + object = BKE_tracking_object_get_named(tracking, this->m_trackingObjectName); + if (object) { + MovieTrackingTrack *track; - marker = BKE_tracking_marker_get(track, this->framenumber); + track = BKE_tracking_track_get_named(tracking, object, this->m_trackName); - outputValue[0] = marker->pos[this->axis]; + if (track) { + MovieTrackingMarker *marker; + int clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(this->m_movieClip, this->m_framenumber); - if (this->relative) { - int i; + marker = BKE_tracking_marker_get(track, clip_framenr); - for (i = 0; i < track->markersnr; i++) { - marker = &track->markers[i]; + copy_v2_v2(this->m_markerPos, marker->pos); - if ((marker->flag & MARKER_DISABLED) == 0) { - outputValue[0] -= marker->pos[this->axis]; + if (this->m_position == POSITION_RELATIVE_START) { + int i; - break; + for (i = 0; i < track->markersnr; i++) { + marker = &track->markers[i]; + + if ((marker->flag & MARKER_DISABLED) == 0) { + copy_v2_v2(this->m_relativePos, marker->pos); + + break; + } + } + } + else if (this->m_position == POSITION_RELATIVE_FRAME) { + int relative_clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(this->m_movieClip, + this->m_relativeFrame); + + marker = BKE_tracking_marker_get(track, relative_clip_framenr); + copy_v2_v2(this->m_relativePos, marker->pos); } } } +} - if (this->axis == 0) - outputValue[0] *= width; +void TrackPositionOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler) +{ + outputValue[0] = this->m_markerPos[this->m_axis] - this->m_relativePos[this->m_axis]; + + if (this->m_axis == 0) + outputValue[0] *= this->m_width; else - outputValue[0] *= height; + outputValue[0] *= this->m_height; } void TrackPositionOperation::determineResolution(unsigned int resolution[], unsigned int preferredResolution[]) diff --git a/source/blender/compositor/operations/COM_TrackPositionOperation.h b/source/blender/compositor/operations/COM_TrackPositionOperation.h index caf444db0d5..fe4f703d26c 100644 --- a/source/blender/compositor/operations/COM_TrackPositionOperation.h +++ b/source/blender/compositor/operations/COM_TrackPositionOperation.h @@ -29,8 +29,8 @@ #include "COM_NodeOperation.h" -#include "DNA_scene_types.h" #include "DNA_movieclip_types.h" +#include "DNA_tracking_types.h" #include "BLI_listbase.h" @@ -39,12 +39,23 @@ */ class TrackPositionOperation : public NodeOperation { protected: - MovieClip *movieClip; - int framenumber; - char trackingObject[64]; - char trackName[64]; - int axis; - bool relative; + enum { + POSITION_ABSOLUTE = 0, + POSITION_RELATIVE_START, + POSITION_RELATIVE_FRAME + }; + + MovieClip *m_movieClip; + int m_framenumber; + char m_trackingObjectName[64]; + char m_trackName[64]; + int m_axis; + int m_position; + int m_relativeFrame; + + int m_width, m_height; + float m_markerPos[2]; + float m_relativePos[2]; /** * Determine the output resolution. The resolution is retrieved from the Renderer @@ -54,14 +65,17 @@ protected: public: TrackPositionOperation(); - void setMovieClip(MovieClip *clip) {this->movieClip = clip;} - void setTrackingObject(char *object) {strncpy(this->trackingObject, object, sizeof(this->trackingObject));} - void setTrackName(char *track) {strncpy(this->trackName, track, sizeof(this->trackName));} - void setFramenumber(int framenumber) {this->framenumber = framenumber;} - void setAxis(int value) {this->axis = value;} - void setRelative(bool value) {this->relative = value;} + void setMovieClip(MovieClip *clip) {this->m_movieClip = clip;} + void setTrackingObject(char *object) {strncpy(this->m_trackingObjectName, object, sizeof(this->m_trackingObjectName));} + void setTrackName(char *track) {strncpy(this->m_trackName, track, sizeof(this->m_trackName));} + void setFramenumber(int framenumber) {this->m_framenumber = framenumber;} + void setAxis(int value) {this->m_axis = value;} + void setPosition(int value) {this->m_position = value;} + void setRelativeFrame(int value) {this->m_relativeFrame = value;} - void executePixel(float *color, float x, float y, PixelSampler sampler, MemoryBuffer * inputBuffers[]); + void initExecution(); + + void executePixel(float *color, float x, float y, PixelSampler sampler); const bool isSetOperation() const { return true; } }; diff --git a/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp b/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp index 8faa571dc38..66d7e9d4d99 100644 --- a/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp +++ b/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp @@ -61,28 +61,41 @@ void VariableSizeBokehBlurOperation::initExecution() #endif QualityStepHelper::initExecution(COM_QH_INCREASE); } +struct VariableSizeBokehBlurTileData +{ + MemoryBuffer* color; + MemoryBuffer* bokeh; + MemoryBuffer* size; + int maxBlur; +}; void *VariableSizeBokehBlurOperation::initializeTileData(rcti *rect) { - MemoryBuffer** result = new MemoryBuffer*[3]; - result[0] = (MemoryBuffer*)this->m_inputProgram->initializeTileData(rect); - result[1] = (MemoryBuffer*)this->m_inputBokehProgram->initializeTileData(rect); - result[2] = (MemoryBuffer*)this->m_inputSizeProgram->initializeTileData(rect); - return result; + VariableSizeBokehBlurTileData *data = new VariableSizeBokehBlurTileData(); + data->color = (MemoryBuffer*)this->m_inputProgram->initializeTileData(rect); + data->bokeh = (MemoryBuffer*)this->m_inputBokehProgram->initializeTileData(rect); + data->size = (MemoryBuffer*)this->m_inputSizeProgram->initializeTileData(rect); + + + rcti rect2; + this->determineDependingAreaOfInterest(rect, (ReadBufferOperation*)this->m_inputSizeProgram, &rect2); + data->maxBlur = (int)data->size->getMaximumValue(&rect2); + CLAMP(data->maxBlur, 1.0f, this->m_maxBlur); + return data; } void VariableSizeBokehBlurOperation::deinitializeTileData(rcti *rect, void *data) { - MemoryBuffer** result = (MemoryBuffer**)data; - delete[] result; + VariableSizeBokehBlurTileData* result = (VariableSizeBokehBlurTileData*)data; + delete result; } void VariableSizeBokehBlurOperation::executePixel(float *color, int x, int y, void *data) { - MemoryBuffer** buffers = (MemoryBuffer**)data; - MemoryBuffer* inputProgramBuffer = buffers[0]; - MemoryBuffer* inputBokehBuffer = buffers[1]; - MemoryBuffer* inputSizeBuffer = buffers[2]; + VariableSizeBokehBlurTileData* tileData = (VariableSizeBokehBlurTileData*)data; + MemoryBuffer* inputProgramBuffer = tileData->color; + MemoryBuffer* inputBokehBuffer = tileData->bokeh; + MemoryBuffer* inputSizeBuffer = tileData->size; float* inputSizeFloatBuffer = inputSizeBuffer->getBuffer(); float* inputProgramFloatBuffer = inputProgramBuffer->getBuffer(); float readColor[4]; @@ -90,6 +103,7 @@ void VariableSizeBokehBlurOperation::executePixel(float *color, int x, int y, vo float tempSize[4]; float multiplier_accum[4] = {0.0f, 0.0f, 0.0f, 0.0f}; float color_accum[4] = {0.0f, 0.0f, 0.0f, 0.0f}; + int maxBlur = tileData->maxBlur; #ifdef COM_DEFOCUS_SEARCH float search[4]; @@ -99,10 +113,10 @@ void VariableSizeBokehBlurOperation::executePixel(float *color, int x, int y, vo int maxx = search[2]; int maxy = search[3]; #else - int minx = MAX2(x - this->m_maxBlur, 0.0f); - int miny = MAX2(y - this->m_maxBlur, 0.0f); - int maxx = MIN2(x + this->m_maxBlur, m_width); - int maxy = MIN2(y + this->m_maxBlur, m_height); + int minx = MAX2(x - maxBlur, 0.0f); + int miny = MAX2(y - maxBlur, 0.0f); + int maxx = MIN2(x + maxBlur, m_width); + int maxy = MIN2(y + maxBlur, m_height); #endif { inputSizeBuffer->readNoCheck(tempSize, x, y); @@ -156,9 +170,13 @@ void VariableSizeBokehBlurOperation::executeOpenCL(OpenCLDevice* device, cl_kernel defocusKernel = device->COM_clCreateKernel("defocusKernel", NULL); cl_int step = this->getStep(); - cl_int maxBlur = this->m_maxBlur; + cl_int maxBlur; cl_float threshold = this->m_threshold; + MemoryBuffer *sizeMemoryBuffer = (MemoryBuffer *)this->m_inputSizeProgram->getInputMemoryBuffer(inputMemoryBuffers); + maxBlur = (cl_int)sizeMemoryBuffer->getMaximumValue(); + maxBlur = MIN2(maxBlur, this->m_maxBlur); + device->COM_clAttachMemoryBufferToKernelParameter(defocusKernel, 0, -1, clMemToCleanUp, inputMemoryBuffers, this->m_inputProgram); device->COM_clAttachMemoryBufferToKernelParameter(defocusKernel, 1, -1, clMemToCleanUp, inputMemoryBuffers, this->m_inputBokehProgram); device->COM_clAttachMemoryBufferToKernelParameter(defocusKernel, 2, 4, clMemToCleanUp, inputMemoryBuffers, this->m_inputSizeProgram); diff --git a/source/blender/compositor/operations/COM_VectorBlurOperation.cpp b/source/blender/compositor/operations/COM_VectorBlurOperation.cpp index 8934dd80ad8..134597531c2 100644 --- a/source/blender/compositor/operations/COM_VectorBlurOperation.cpp +++ b/source/blender/compositor/operations/COM_VectorBlurOperation.cpp @@ -66,7 +66,7 @@ void VectorBlurOperation::deinitExecution() this->m_inputSpeedProgram = NULL; this->m_inputZProgram = NULL; if (this->m_cachedInstance) { - delete this->m_cachedInstance; + delete [] this->m_cachedInstance; this->m_cachedInstance = NULL; } } @@ -115,6 +115,6 @@ void VectorBlurOperation::generateVectorBlur(float *data, MemoryBuffer *inputIma blurdata.curved = this->m_settings->curved; blurdata.fac = this->m_settings->fac; RE_zbuf_accumulate_vecblur(&blurdata, this->getWidth(), this->getHeight(), data, inputImage->getBuffer(), inputSpeed->getBuffer(), zbuf); - delete zbuf; + delete [] zbuf; return; } diff --git a/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp b/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp index 2470b239987..f443c33cd54 100644 --- a/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp +++ b/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp @@ -23,7 +23,6 @@ #include "COM_ViewerBaseOperation.h" #include "COM_SocketConnection.h" #include "BLI_listbase.h" -#include "DNA_scene_types.h" #include "BKE_image.h" #include "WM_api.h" #include "WM_types.h" @@ -43,9 +42,11 @@ ViewerBaseOperation::ViewerBaseOperation() : NodeOperation() this->setImage(NULL); this->setImageUser(NULL); this->m_outputBuffer = NULL; + this->m_depthBuffer = NULL; this->m_outputBufferDisplay = NULL; this->m_active = false; this->m_doColorManagement = true; + this->m_doDepthBuffer = false; } void ViewerBaseOperation::initExecution() @@ -61,8 +62,8 @@ void ViewerBaseOperation::initImage() ImBuf *ibuf = BKE_image_acquire_ibuf(anImage, this->m_imageUser, &this->m_lock); if (!ibuf) return; + BLI_lock_thread(LOCK_DRAW_IMAGE); if (ibuf->x != (int)getWidth() || ibuf->y != (int)getHeight()) { - BLI_lock_thread(LOCK_DRAW_IMAGE); imb_freerectImBuf(ibuf); imb_freerectfloatImBuf(ibuf); @@ -73,12 +74,21 @@ void ViewerBaseOperation::initImage() imb_addrectfloatImBuf(ibuf); anImage->ok = IMA_OK_LOADED; - BLI_unlock_thread(LOCK_DRAW_IMAGE); } + if (m_doDepthBuffer) + { + addzbuffloatImBuf(ibuf); + } + BLI_unlock_thread(LOCK_DRAW_IMAGE); + /* now we combine the input with ibuf */ this->m_outputBuffer = ibuf->rect_float; this->m_outputBufferDisplay = (unsigned char *)ibuf->rect; + if (m_doDepthBuffer) + { + this->m_depthBuffer = ibuf->zbuf_float; + } BKE_image_release_ibuf(this->m_image, this->m_lock); } diff --git a/source/blender/compositor/operations/COM_ViewerBaseOperation.h b/source/blender/compositor/operations/COM_ViewerBaseOperation.h index f3fd1e9c9df..d90eb343f6c 100644 --- a/source/blender/compositor/operations/COM_ViewerBaseOperation.h +++ b/source/blender/compositor/operations/COM_ViewerBaseOperation.h @@ -29,6 +29,7 @@ class ViewerBaseOperation : public NodeOperation { protected: float *m_outputBuffer; + float *m_depthBuffer; unsigned char *m_outputBufferDisplay; Image *m_image; ImageUser *m_imageUser; @@ -39,6 +40,7 @@ protected: OrderOfChunks m_chunkOrder; bool m_doColorManagement; bool m_doColorPredivide; + bool m_doDepthBuffer; public: bool isOutputOperation(bool rendering) const { return isActiveViewerOutput(); } diff --git a/source/blender/compositor/operations/COM_ViewerOperation.cpp b/source/blender/compositor/operations/COM_ViewerOperation.cpp index f7c2ff93b3e..b85b86bddc3 100644 --- a/source/blender/compositor/operations/COM_ViewerOperation.cpp +++ b/source/blender/compositor/operations/COM_ViewerOperation.cpp @@ -23,7 +23,6 @@ #include "COM_ViewerOperation.h" #include "COM_SocketConnection.h" #include "BLI_listbase.h" -#include "DNA_scene_types.h" #include "BKE_image.h" #include "WM_api.h" #include "WM_types.h" @@ -43,9 +42,11 @@ ViewerOperation::ViewerOperation() : ViewerBaseOperation() { this->addInputSocket(COM_DT_COLOR); this->addInputSocket(COM_DT_VALUE); + this->addInputSocket(COM_DT_VALUE); this->m_imageInput = NULL; this->m_alphaInput = NULL; + this->m_depthInput = NULL; } void ViewerOperation::initExecution() @@ -53,6 +54,8 @@ void ViewerOperation::initExecution() // When initializing the tree during initial load the width and height can be zero. this->m_imageInput = getInputSocketReader(0); this->m_alphaInput = getInputSocketReader(1); + this->m_depthInput = getInputSocketReader(2); + this->m_doDepthBuffer = (this->m_depthInput != NULL); ViewerBaseOperation::initExecution(); } @@ -60,6 +63,7 @@ void ViewerOperation::deinitExecution() { this->m_imageInput = NULL; this->m_alphaInput = NULL; + this->m_depthInput = NULL; ViewerBaseOperation::deinitExecution(); } @@ -67,47 +71,55 @@ void ViewerOperation::deinitExecution() void ViewerOperation::executeRegion(rcti *rect, unsigned int tileNumber) { float *buffer = this->m_outputBuffer; + float *depthbuffer = this->m_depthBuffer; unsigned char *bufferDisplay = this->m_outputBufferDisplay; if (!buffer) return; const int x1 = rect->xmin; const int y1 = rect->ymin; const int x2 = rect->xmax; const int y2 = rect->ymax; - const int offsetadd = (this->getWidth() - (x2 - x1)) * 4; - int offset = (y1 * this->getWidth() + x1) * 4; - float alpha[4], srgb[4]; + const int offsetadd = (this->getWidth() - (x2 - x1)); + const int offsetadd4 = offsetadd * 4; + int offset = (y1 * this->getWidth() + x1); + int offset4 = offset * 4; + float alpha[4], srgb[4], depth[4]; int x; int y; bool breaked = false; for (y = y1; y < y2 && (!breaked); y++) { for (x = x1; x < x2; x++) { - this->m_imageInput->read(&(buffer[offset]), x, y, COM_PS_NEAREST); + this->m_imageInput->read(&(buffer[offset4]), x, y, COM_PS_NEAREST); if (this->m_alphaInput != NULL) { this->m_alphaInput->read(alpha, x, y, COM_PS_NEAREST); - buffer[offset + 3] = alpha[0]; + buffer[offset4 + 3] = alpha[0]; } + if (m_depthInput) { + this->m_depthInput->read(depth, x, y, COM_PS_NEAREST); + depthbuffer[offset] = depth[0]; + } if (this->m_doColorManagement) { if (this->m_doColorPredivide) { - linearrgb_to_srgb_predivide_v4(srgb, buffer + offset); + linearrgb_to_srgb_predivide_v4(srgb, buffer + offset4); } else { - linearrgb_to_srgb_v4(srgb, buffer + offset); + linearrgb_to_srgb_v4(srgb, buffer + offset4); } } else { - copy_v4_v4(srgb, buffer + offset); + copy_v4_v4(srgb, buffer + offset4); } - rgba_float_to_uchar(bufferDisplay + offset, srgb); + rgba_float_to_uchar(bufferDisplay + offset4, srgb); - offset += 4; + offset ++; + offset4 += 4; } if (isBreaked()) { breaked = true; } - offset += offsetadd; + offset4 += offsetadd4; } updateImage(rect); } diff --git a/source/blender/compositor/operations/COM_ViewerOperation.h b/source/blender/compositor/operations/COM_ViewerOperation.h index d900d8db408..262efd87dba 100644 --- a/source/blender/compositor/operations/COM_ViewerOperation.h +++ b/source/blender/compositor/operations/COM_ViewerOperation.h @@ -31,6 +31,7 @@ class ViewerOperation : public ViewerBaseOperation { private: SocketReader *m_imageInput; SocketReader *m_alphaInput; + SocketReader *m_depthInput; public: ViewerOperation(); diff --git a/source/blender/editors/animation/anim_channels_defines.c b/source/blender/editors/animation/anim_channels_defines.c index e890b8f2aba..66147f20e91 100644 --- a/source/blender/editors/animation/anim_channels_defines.c +++ b/source/blender/editors/animation/anim_channels_defines.c @@ -88,12 +88,9 @@ #define ANIM_CHAN_NAME_SIZE 256 -/* macros used for type defines */ - -/* get the pointer used for some flag and return */ +/* get the pointer used for some flag */ #define GET_ACF_FLAG_PTR(ptr, type) ((*(type) = sizeof((ptr))), &(ptr)) - /* *********************************************** */ /* Generic Functions (Type independent) */ @@ -120,7 +117,7 @@ static void acf_generic_root_backdrop(bAnimContext *ac, bAnimListElem *ale, floa glColor3fv(color); /* rounded corners on LHS only - top only when expanded, but bottom too when collapsed */ - uiSetRoundBox(expanded ? UI_CNR_TOP_LEFT : (UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT)); + uiSetRoundBox((expanded) ? UI_CNR_TOP_LEFT : (UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT)); uiDrawBox(GL_POLYGON, offset, yminc, v2d->cur.xmax + EXTRA_SCROLL_PAD, ymaxc, 8); } diff --git a/source/blender/editors/animation/anim_filter.c b/source/blender/editors/animation/anim_filter.c index 035641b2888..d6f9049ef01 100644 --- a/source/blender/editors/animation/anim_filter.c +++ b/source/blender/editors/animation/anim_filter.c @@ -1868,11 +1868,18 @@ static size_t animdata_filter_ds_obdata(bAnimContext *ac, ListBase *anim_data, b /* sub-data filtering... */ switch (ob->type) { - case OB_LAMP: /* lamp - textures */ + case OB_LAMP: /* lamp - textures + nodetree */ { + Lamp *la = ob->data; + bNodeTree *ntree = la->nodetree; + + /* nodetree */ + if ((ntree) && !(ads->filterflag & ADS_FILTER_NONTREE)) + tmp_items += animdata_filter_ds_nodetree(ac, &tmp_data, ads, &la->id, ntree, filter_mode); + /* textures */ if (!(ads->filterflag & ADS_FILTER_NOTEX)) - tmp_items += animdata_filter_ds_textures(ac, &tmp_data, ads, ob->data, filter_mode); + tmp_items += animdata_filter_ds_textures(ac, &tmp_data, ads, &la->id, filter_mode); } break; } diff --git a/source/blender/editors/animation/keyframes_draw.c b/source/blender/editors/animation/keyframes_draw.c index 85731933168..d024e2b0393 100644 --- a/source/blender/editors/animation/keyframes_draw.c +++ b/source/blender/editors/animation/keyframes_draw.c @@ -796,7 +796,7 @@ void draw_action_channel(View2D *v2d, AnimData *adt, bAction *act, float ypos) { DLRBT_Tree keys, blocks; - short locked = (act->id.lib != 0); + short locked = (act && act->id.lib != 0); BLI_dlrbTree_init(&keys); BLI_dlrbTree_init(&blocks); diff --git a/source/blender/editors/armature/editarmature_retarget.c b/source/blender/editors/armature/editarmature_retarget.c index caadee5f941..fad06f0d020 100644 --- a/source/blender/editors/armature/editarmature_retarget.c +++ b/source/blender/editors/armature/editarmature_retarget.c @@ -2379,7 +2379,7 @@ static void findCorrespondingArc(RigGraph *rigg, RigArc *start_arc, RigNode *sta // printf("CANDIDATES\n"); // for (i = 0; i < enode->degree; i++) // { -// next_earc = (ReebArc*)enode->arcs[i]; +// next_earc = (ReebArc *)enode->arcs[i]; // printf("flag %i -- level %i -- flag %i -- group %i\n", next_earc->flag, next_earc->symmetry_level, next_earc->symmetry_flag, next_earc->symmetry_group); // } diff --git a/source/blender/editors/include/ED_clip.h b/source/blender/editors/include/ED_clip.h index 2670fb5b042..3a1d63574a6 100644 --- a/source/blender/editors/include/ED_clip.h +++ b/source/blender/editors/include/ED_clip.h @@ -39,7 +39,6 @@ struct Main; struct Mask; struct MovieClip; struct SpaceClip; -struct wmEvent; /* ** clip_editor.c ** */ @@ -52,8 +51,9 @@ int ED_space_clip_tracking_poll(struct bContext *C); int ED_space_clip_maskedit_poll(struct bContext *C); int ED_space_clip_maskedit_mask_poll(bContext *C); -void ED_space_clip_get_size(const struct bContext *C, int *width, int *height); -void ED_space_clip_get_zoom(const struct bContext *C, float *zoomx, float *zoomy); +void ED_space_clip_get_size(struct SpaceClip *sc, int *width, int *height); +void ED_space_clip_get_size_fl(struct SpaceClip *sc, float size[2]); +void ED_space_clip_get_zoom(struct SpaceClip *sc, struct ARegion *ar, float *zoomx, float *zoomy); void ED_space_clip_get_aspect(struct SpaceClip *sc, float *aspx, float *aspy); void ED_space_clip_get_aspect_dimension_aware(struct SpaceClip *sc, float *aspx, float *aspy); @@ -65,10 +65,10 @@ struct ImBuf *ED_space_clip_get_stable_buffer(struct SpaceClip *sc, float loc[2] void ED_clip_update_frame(const struct Main *mainp, int cfra); int ED_clip_view_selection(const struct bContext *C, struct ARegion *ar, int fit); -void ED_clip_point_undistorted_pos(SpaceClip *sc, const float co[2], float r_co[2]); -void ED_clip_point_stable_pos(const struct bContext *C, float x, float y, float *xr, float *yr); -void ED_clip_point_stable_pos__reverse(const struct bContext *C, const float co[2], float r_co[2]); -void ED_clip_mouse_pos(const struct bContext *C, struct wmEvent *event, float co[2]); +void ED_clip_point_undistorted_pos(struct SpaceClip *sc, const float co[2], float r_co[2]); +void ED_clip_point_stable_pos(struct SpaceClip *sc, struct ARegion *ar, float x, float y, float *xr, float *yr); +void ED_clip_point_stable_pos__reverse(struct SpaceClip *sc, struct ARegion *ar, const float co[2], float r_co[2]); +void ED_clip_mouse_pos(struct SpaceClip *sc, struct ARegion *ar, const int mval[2], float co[2]); int ED_space_clip_check_show_trackedit(struct SpaceClip *sc); int ED_space_clip_check_show_maskedit(struct SpaceClip *sc); diff --git a/source/blender/editors/include/ED_image.h b/source/blender/editors/include/ED_image.h index b95615ce365..d291c500547 100644 --- a/source/blender/editors/include/ED_image.h +++ b/source/blender/editors/include/ED_image.h @@ -38,32 +38,43 @@ struct ImageUser; struct ToolSettings; struct uiBlock; struct wmWindowManager; +struct ARegion; -/* space_image.c, exported for transform */ +/* image_edit.c, exported for transform */ struct Image *ED_space_image(struct SpaceImage *sima); -void ED_space_image_set(struct SpaceImage *sima, struct Scene *scene, struct Object *obedit, struct Image *ima); +void ED_space_image_set(struct SpaceImage *sima, struct Scene *scene, struct Object *obedit, struct Image *ima); +struct Mask *ED_space_image_get_mask(struct SpaceImage *sima); +void ED_space_image_set_mask(struct bContext *C, struct SpaceImage *sima, struct Mask *mask); struct ImBuf *ED_space_image_acquire_buffer(struct SpaceImage *sima, void **lock_r); void ED_space_image_release_buffer(struct SpaceImage *sima, void *lock); int ED_space_image_has_buffer(struct SpaceImage *sima); -void ED_space_image_size(struct SpaceImage *sima, int *width, int *height); -void ED_space_image_aspect(struct SpaceImage *sima, float *aspx, float *aspy); -void ED_space_image_zoom(struct SpaceImage *sima, struct ARegion *ar, float *zoomx, float *zoomy); -void ED_space_image_uv_aspect(struct SpaceImage *sima, float *aspx, float *aspy); +void ED_space_image_get_size(struct SpaceImage *sima, int *width, int *height); +void ED_space_image_get_size_fl(struct SpaceImage *sima, float size[2]); +void ED_space_image_get_aspect(struct SpaceImage *sima, float *aspx, float *aspy); +void ED_space_image_get_zoom(struct SpaceImage *sima, struct ARegion *ar, float *zoomx, float *zoomy); +void ED_space_image_get_uv_aspect(struct SpaceImage *sima, float *aspx, float *aspy); void ED_space_image_paint_update(struct wmWindowManager *wm, struct ToolSettings *settings); void ED_space_image_uv_sculpt_update(struct wmWindowManager *wm, struct ToolSettings *settings); -void ED_image_size(struct Image *ima, int *width, int *height); -void ED_image_aspect(struct Image *ima, float *aspx, float *aspy); -void ED_image_uv_aspect(struct Image *ima, float *aspx, float *aspy); +void ED_image_get_size(struct Image *ima, int *width, int *height); +void ED_image_get_aspect(struct Image *ima, float *aspx, float *aspy); +void ED_image_get_uv_aspect(struct Image *ima, float *aspx, float *aspy); +void ED_image_mouse_pos(struct SpaceImage *sima, struct ARegion *ar, const int mval[2], float co[2]); +void ED_image_point_pos(struct SpaceImage *sima, struct ARegion *ar, float x, float y, float *xr, float *yr); +void ED_image_point_pos__reverse(struct SpaceImage *sima, struct ARegion *ar, const float co[2], float r_co[2]); int ED_space_image_show_render(struct SpaceImage *sima); int ED_space_image_show_paint(struct SpaceImage *sima); int ED_space_image_show_uvedit(struct SpaceImage *sima, struct Object *obedit); int ED_space_image_show_uvshadow(struct SpaceImage *sima, struct Object *obedit); +int ED_space_image_check_show_maskedit(struct Scene *scene, struct SpaceImage *sima); +int ED_space_image_maskedit_poll(struct bContext *C); +int ED_space_image_maskedit_mask_poll(struct bContext *C); + /* UI level image (texture) updating... render calls own stuff (too) */ void ED_image_update_frame(const struct Main *mainp, int cfra); diff --git a/source/blender/editors/include/ED_mask.h b/source/blender/editors/include/ED_mask.h index 773da04bc7b..88667729eee 100644 --- a/source/blender/editors/include/ED_mask.h +++ b/source/blender/editors/include/ED_mask.h @@ -34,14 +34,34 @@ struct wmKeyConfig; struct MaskLayer; struct MaskLayerShape; +struct wmEvent; + +/* mask_edit.c */ +void ED_mask_get_size(struct ScrArea *sa, int *width, int *height); +void ED_mask_zoom(struct ScrArea *sa, struct ARegion *ar, float *zoomx, float *zoomy); +void ED_mask_get_aspect(struct ScrArea *sa, struct ARegion *ar, float *aspx, float *aspy); + +void ED_mask_pixelspace_factor(struct ScrArea *sa, struct ARegion *ar, float *scalex, float *scaley); +void ED_mask_mouse_pos(struct ScrArea *sa, struct ARegion *ar, const int mval[2], float co[2]); + +void ED_mask_point_pos(struct ScrArea *sa, struct ARegion *ar, float x, float y, float *xr, float *yr); +void ED_mask_point_pos__reverse(struct ScrArea *sa, struct ARegion *ar, + float x, float y, float *xr, float *yr); -/* mask_editor.c */ void ED_operatortypes_mask(void); void ED_keymap_mask(struct wmKeyConfig *keyconf); void ED_operatormacros_mask(void); /* mask_draw.c */ void ED_mask_draw(const bContext *C, const char draw_flag, const char draw_type); +void ED_mask_draw_region(struct Mask *mask, struct ARegion *ar, + const char draw_flag, const char draw_type, + int width, int height, + const short do_scale_applied, const short do_post_draw, + float stabmat[4][4], + const bContext *C); + +void ED_mask_draw_frames(struct Mask *mask, struct ARegion *ar, const int cfra, const int sfra, const int efra); /* mask_shapekey.c */ void ED_mask_layer_shape_auto_key(struct MaskLayer *masklay, const int frame); diff --git a/source/blender/editors/include/ED_node.h b/source/blender/editors/include/ED_node.h index 6f86d01fb98..ca468a15771 100644 --- a/source/blender/editors/include/ED_node.h +++ b/source/blender/editors/include/ED_node.h @@ -51,9 +51,9 @@ typedef enum { } NodeBorder; /* drawnode.c */ -void ED_init_node_butfuncs(void); - -void drawnodesnap(struct View2D *v2d, const float cent[2], float size, NodeBorder border); +void ED_node_init_butfuncs(void); +void ED_node_sample_set(const float col[4]); +void ED_node_draw_snap(struct View2D *v2d, const float cent[2], float size, NodeBorder border); /* node_draw.c */ void ED_node_tree_update(struct SpaceNode *snode, struct Scene *scene); @@ -61,19 +61,18 @@ void ED_node_changed_update(struct ID *id, struct bNode *node); void ED_node_generic_update(struct Main *bmain, struct bNodeTree *ntree, struct bNode *node); void ED_node_sort(struct bNodeTree *ntree); +/* node_relationships.c */ +void ED_node_link_intersect_test(struct ScrArea *sa, int test); +void ED_node_link_insert(struct ScrArea *sa); + /* node_edit.c */ void ED_node_shader_default(struct Scene *scene, struct ID *id); void ED_node_composit_default(struct Scene *sce); void ED_node_texture_default(struct Tex *tex); -void ED_node_link_intersect_test(struct ScrArea *sa, int test); -void ED_node_link_insert(struct ScrArea *sa); - +int ED_node_select_check(ListBase *lb); void ED_node_post_apply_transform(struct bContext *C, struct bNodeTree *ntree); - void ED_node_set_active(struct Main *bmain, struct bNodeTree *ntree, struct bNode *node); -void ED_node_sample_set(const float col[4]); - /* node ops.c */ void ED_operatormacros_node(void); diff --git a/source/blender/editors/include/ED_object.h b/source/blender/editors/include/ED_object.h index 38f0077c368..d876d311d30 100644 --- a/source/blender/editors/include/ED_object.h +++ b/source/blender/editors/include/ED_object.h @@ -41,6 +41,7 @@ struct bContext; struct bPoseChannel; struct Curve; struct EnumPropertyItem; +struct ID; struct KeyBlock; struct Lattice; struct Main; @@ -178,11 +179,14 @@ int ED_object_modifier_apply(struct ReportList *reports, struct Scene *scene, int ED_object_modifier_copy(struct ReportList *reports, struct Object *ob, struct ModifierData *md); int ED_object_iter_other(struct Main *bmain, struct Object *orig_ob, int include_orig, - int (*callback)(struct Object *ob, void *callback_data), - void *callback_data); + int (*callback)(struct Object *ob, void *callback_data), + void *callback_data); int ED_object_multires_update_totlevels_cb(struct Object *ob, void *totlevel_v); +/* ibject_select.c */ +void ED_object_select_linked_by_id(struct bContext *C, struct ID *id); + #ifdef __cplusplus } #endif diff --git a/source/blender/editors/include/ED_sequencer.h b/source/blender/editors/include/ED_sequencer.h index 7ba26f30c39..7807f06594e 100644 --- a/source/blender/editors/include/ED_sequencer.h +++ b/source/blender/editors/include/ED_sequencer.h @@ -29,10 +29,15 @@ struct Scene; struct Sequence; +struct SpaceSeq; void ED_sequencer_select_sequence_single(struct Scene *scene, struct Sequence *seq, int deselect_all); void ED_sequencer_deselect_all(struct Scene *scene); +int ED_space_sequencer_maskedit_mask_poll(struct bContext *C); +int ED_space_sequencer_check_show_maskedit(struct SpaceSeq *sseq, struct Scene *scene); +int ED_space_sequencer_maskedit_poll(bContext *C); + void ED_operatormacros_sequencer(void); #endif /* __ED_SEQUENCER_H__ */ diff --git a/source/blender/editors/include/ED_uvedit.h b/source/blender/editors/include/ED_uvedit.h index 2427ed1a333..56f8a455c52 100644 --- a/source/blender/editors/include/ED_uvedit.h +++ b/source/blender/editors/include/ED_uvedit.h @@ -85,6 +85,7 @@ void ED_uvedit_live_unwrap(struct Scene *scene, struct Object *obedit); void ED_unwrap_lscm(struct Scene *scene, struct Object *obedit, const short sel); /* uvedit_draw.c */ +void draw_image_cursor(struct SpaceImage *sima, struct ARegion *ar); void draw_uvedit_main(struct SpaceImage *sima, struct ARegion *ar, struct Scene *scene, struct Object *obedit, struct Object *obact); /* uvedit_buttons.c */ diff --git a/source/blender/editors/include/UI_resources.h b/source/blender/editors/include/UI_resources.h index ac59d2a6983..77aa2ce154d 100644 --- a/source/blender/editors/include/UI_resources.h +++ b/source/blender/editors/include/UI_resources.h @@ -127,6 +127,7 @@ enum { TH_BONE_SOLID, TH_BONE_POSE, + TH_BONE_POSE_ACTIVE, TH_STRIP, TH_STRIP_SELECT, diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 60f071f2ad2..7b1150669e8 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -2134,7 +2134,7 @@ uiBlock *uiBeginBlock(const bContext *C, ARegion *region, const char *name, shor /* TODO - investigate why block->winmat[0][0] is negative * in the image view when viewRedrawForce is called */ - block->aspect = 2.0 / fabs( (getsizex) * block->winmat[0][0]); + block->aspect = 2.0f / fabsf(getsizex * block->winmat[0][0]); } else { /* no subwindow created yet, for menus for example, so we @@ -2143,7 +2143,7 @@ uiBlock *uiBeginBlock(const bContext *C, ARegion *region, const char *name, shor wm_subwindow_getmatrix(window, window->screen->mainwin, block->winmat); wm_subwindow_getsize(window, window->screen->mainwin, &getsizex, &getsizey); - block->aspect = 2.0 / fabs(getsizex * block->winmat[0][0]); + block->aspect = 2.0f / fabsf(getsizex * block->winmat[0][0]); block->auto_open = TRUE; block->flag |= UI_BLOCK_LOOP; /* tag as menu */ } @@ -2243,8 +2243,12 @@ void ui_check_but(uiBut *but) UI_GET_BUT_VALUE_INIT(but, value); if (ui_is_but_float(but)) { - if (value == (double) FLT_MAX) BLI_snprintf(but->drawstr, sizeof(but->drawstr), "%sinf", but->str); - else if (value == (double) -FLT_MAX) BLI_snprintf(but->drawstr, sizeof(but->drawstr), "%s-inf", but->str); + if (value == (double) FLT_MAX) { + BLI_snprintf(but->drawstr, sizeof(but->drawstr), "%sinf", but->str); + } + else if (value == (double) -FLT_MAX) { + BLI_snprintf(but->drawstr, sizeof(but->drawstr), "%s-inf", but->str); + } /* support length type buttons */ else if (ui_is_but_unit(but)) { char new_str[sizeof(but->drawstr)]; @@ -2550,7 +2554,9 @@ void ui_block_do_align(uiBlock *block) * - \a a2 Number of decimal point values to display. 0 defaults to 3 (0.000) * 1,2,3, and a maximum of 4, all greater values will be clamped to 4. */ -static uiBut *ui_def_but(uiBlock *block, int type, int retval, const char *str, int x1, int y1, short x2, short y2, void *poin, float min, float max, float a1, float a2, const char *tip) +static uiBut *ui_def_but(uiBlock *block, int type, int retval, const char *str, + int x1, int y1, short x2, short y2, + void *poin, float min, float max, float a1, float a2, const char *tip) { uiBut *but; int slen; @@ -2622,10 +2628,14 @@ static uiBut *ui_def_but(uiBlock *block, int type, int retval, const char *str, } } - if ((block->flag & UI_BLOCK_LOOP) || ELEM8(but->type, MENU, TEX, LABEL, IDPOIN, BLOCK, BUTM, SEARCH_MENU, PROGRESSBAR)) + if ((block->flag & UI_BLOCK_LOOP) || + ELEM8(but->type, MENU, TEX, LABEL, IDPOIN, BLOCK, BUTM, SEARCH_MENU, PROGRESSBAR)) + { but->flag |= (UI_TEXT_LEFT | UI_ICON_LEFT); - else if (but->type == BUT_TOGDUAL) + } + else if (but->type == BUT_TOGDUAL) { but->flag |= UI_ICON_LEFT; + } but->flag |= (block->flag & UI_BUT_ALIGN); @@ -2664,13 +2674,17 @@ static uiBut *ui_def_but(uiBlock *block, int type, int retval, const char *str, * of our UI functions take prop rather then propname. */ -#define UI_DEF_BUT_RNA_DISABLE(but) \ - but->flag |= UI_BUT_DISABLED; \ - but->lock = 1; \ - but->lockstr = "" +#define UI_DEF_BUT_RNA_DISABLE(but) { \ + but->flag |= UI_BUT_DISABLED; \ + but->lock = TRUE; \ + but->lockstr = ""; \ + } (void)0 -static uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, const char *str, int x1, int y1, short x2, short y2, PointerRNA *ptr, PropertyRNA *prop, int index, float min, float max, float a1, float a2, const char *tip) +static uiBut *ui_def_but_rna(uiBlock *block, int type, int retval, const char *str, + int x1, int y1, short x2, short y2, + PointerRNA *ptr, PropertyRNA *prop, int index, + float min, float max, float a1, float a2, const char *tip) { const PropertyType proptype = RNA_property_type(prop); uiBut *but; @@ -3700,7 +3714,7 @@ void uiButGetStrInfo(bContext *C, uiBut *but, int nbr, ...) va_start(args, nbr); while (nbr--) { - uiStringInfo *si = (uiStringInfo*) va_arg(args, void*); + uiStringInfo *si = (uiStringInfo *) va_arg(args, void *); int type = si->type; char *tmp = NULL; @@ -3714,14 +3728,15 @@ void uiButGetStrInfo(bContext *C, uiBut *but, int nbr, ...) tmp = BLI_strdup(but->str); } else - type = BUT_GET_RNA_LABEL; /* Fail-safe solution... */ + type = BUT_GET_RNA_LABEL; /* Fail-safe solution... */ } else if (type == BUT_GET_TIP) { if (but->tip && but->tip[0]) tmp = BLI_strdup(but->tip); else - type = BUT_GET_RNA_TIP; /* Fail-safe solution... */ + type = BUT_GET_RNA_TIP; /* Fail-safe solution... */ } + if (type == BUT_GET_RNAPROP_IDENTIFIER) { if (but->rnaprop) tmp = BLI_strdup(RNA_property_identifier(but->rnaprop)); @@ -3759,12 +3774,15 @@ void uiButGetStrInfo(bContext *C, uiBut *but, int nbr, ...) else if (ELEM(but->type, MENU, PULLDOWN)) { MenuType *mt = uiButGetMenuType(but); if (mt) { - if (type == BUT_GET_RNA_LABEL) - tmp = BLI_strdup(RNA_struct_ui_name(mt->ext.srna)); - else { - const char *t = RNA_struct_ui_description(mt->ext.srna); - if (t && t[0]) - tmp = BLI_strdup(t); + /* not all menus are from python */ + if (mt->ext.srna) { + if (type == BUT_GET_RNA_LABEL) + tmp = BLI_strdup(RNA_struct_ui_name(mt->ext.srna)); + else { + const char *t = RNA_struct_ui_description(mt->ext.srna); + if (t && t[0]) + tmp = BLI_strdup(t); + } } } } diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c index 1d88838ecc5..d8eb1b011bd 100644 --- a/source/blender/editors/interface/interface_draw.c +++ b/source/blender/editors/interface/interface_draw.c @@ -714,6 +714,8 @@ static void histogram_draw_one(float r, float g, float b, float alpha, } } +#define HISTOGRAM_TOT_GRID_LINES 4 + void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *recti) { Histogram *hist = (Histogram *)but->poin; @@ -749,9 +751,16 @@ void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol) glColor4f(1.f, 1.f, 1.f, 0.08f); /* draw grid lines here */ - for (i = 1; i < 4; i++) { - fdrawline(rect.xmin, rect.ymin + (i / 4.f) * h, rect.xmax, rect.ymin + (i / 4.f) * h); - fdrawline(rect.xmin + (i / 4.f) * w, rect.ymin, rect.xmin + (i / 4.f) * w, rect.ymax); + for (i = 1; i < (HISTOGRAM_TOT_GRID_LINES + 1); i++) { + const float fac = (float)i / (float)HISTOGRAM_TOT_GRID_LINES; + + /* so we can tell the 1.0 color point */ + if (i == HISTOGRAM_TOT_GRID_LINES) { + glColor4f(1.0f, 1.0f, 1.0f, 0.5f); + } + + fdrawline(rect.xmin, rect.ymin + fac * h, rect.xmax, rect.ymin + fac * h); + fdrawline(rect.xmin + fac * w, rect.ymin, rect.xmin + fac * w, rect.ymax); } if (hist->mode == HISTO_MODE_LUMA) { @@ -773,6 +782,8 @@ void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol) draw_scope_end(&rect, scissor); } +#undef HISTOGRAM_TOT_GRID_LINES + void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *recti) { Scopes *scopes = (Scopes *)but->poin; diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 2a93ab794af..ce9e63076fb 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -3725,7 +3725,7 @@ static int ui_do_but_CURVE(bContext *C, uiBlock *block, uiBut *but, uiHandleButt offsy = cumap->curr.ymin; if (event->ctrl) { - fx = ((float)my - but->x1) / zoomx + offsx; + fx = ((float)mx - but->x1) / zoomx + offsx; fy = ((float)my - but->y1) / zoomy + offsy; curvemap_insert(cuma, fx, fy); @@ -3868,11 +3868,12 @@ static int ui_numedit_but_HISTOGRAM(uiBut *but, uiHandleButtonData *data, int mx hist->height = (but->y2 - but->y1) + (data->dragstarty - my); } else { - /* scale histogram values */ + /* scale histogram values (dy / 10 for better control) */ const float yfac = minf(powf(hist->ymax, 2.0f), 1.0f) * 0.5f; - hist->ymax += dy * yfac; + hist->ymax += (dy * 0.1f) * yfac; - CLAMP(hist->ymax, 1.f, 100.f); + /* 0.1 allows us to see HDR colors up to 10 */ + CLAMP(hist->ymax, 0.1f, 100.f); } data->draglastx = mx; @@ -5845,6 +5846,8 @@ static int ui_handle_list_event(bContext *C, wmEvent *event, ARegion *ar) else value++; + CLAMP(value, 0, pa->list_last_len - 1); + if (value < pa->list_scroll) pa->list_scroll = value; else if (value >= pa->list_scroll + pa->list_size) diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c index 737c0377f27..2bfead708be 100644 --- a/source/blender/editors/interface/interface_icons.c +++ b/source/blender/editors/interface/interface_icons.c @@ -861,7 +861,8 @@ static void icon_set_image(bContext *C, ID *id, PreviewImage *prv_img, enum eIco prv_img->w[size], prv_img->h[size]); } -static void icon_draw_rect(float x, float y, int w, int h, float UNUSED(aspect), int rw, int rh, unsigned int *rect, float alpha, const float rgb[3], short is_preview) +static void icon_draw_rect(float x, float y, int w, int h, float UNUSED(aspect), int rw, int rh, + unsigned int *rect, float alpha, const float rgb[3], short is_preview) { ImBuf *ima = NULL; @@ -914,7 +915,8 @@ static void icon_draw_rect(float x, float y, int w, int h, float UNUSED(aspect), } } -static void icon_draw_texture(float x, float y, float w, float h, int ix, int iy, int UNUSED(iw), int ih, float alpha, const float rgb[3]) +static void icon_draw_texture(float x, float y, float w, float h, int ix, int iy, + int UNUSED(iw), int ih, float alpha, const float rgb[3]) { float x1, x2, y1, y2; @@ -957,7 +959,8 @@ static int get_draw_size(enum eIconSizes size) return 0; } -static void icon_draw_size(float x, float y, int icon_id, float aspect, float alpha, const float rgb[3], enum eIconSizes size, int draw_size, int UNUSED(nocreate), short is_preview) +static void icon_draw_size(float x, float y, int icon_id, float aspect, float alpha, const float rgb[3], + enum eIconSizes size, int draw_size, int UNUSED(nocreate), short is_preview) { bTheme *btheme = UI_GetTheme(); Icon *icon = NULL; @@ -1088,7 +1091,7 @@ static int ui_id_brush_get_icon(bContext *C, ID *id) mode = OB_MODE_TEXTURE_PAINT; } else if ((sima = CTX_wm_space_image(C)) && - (sima->flag & SI_DRAWTOOL)) + (sima->mode == SI_MODE_PAINT)) { mode = OB_MODE_TEXTURE_PAINT; } diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index 3270015271a..10fde402acc 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -1960,6 +1960,7 @@ static void ui_litem_estimate_column_flow(uiLayout *litem) x += maxw + litem->space; maxw = 0; y = 0; + emy = 0; /* need to reset height again for next column */ col++; } } @@ -2010,6 +2011,7 @@ static void ui_litem_layout_column_flow(uiLayout *litem) if (col < flow->totcol - 1 && emy <= -emh) { x += itemw + style->columnspace; y = litem->y; + emy = 0; /* need to reset height again for next column */ col++; } } diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c index 76485571096..d04c1af2769 100644 --- a/source/blender/editors/interface/interface_panel.c +++ b/source/blender/editors/interface/interface_panel.c @@ -831,14 +831,15 @@ static void ui_do_animate(const bContext *C, Panel *panel) float fac; fac = (PIL_check_seconds_timer() - data->starttime) / ANIMATION_TIME; - fac = sqrt(fac); - fac = MIN2(fac, 1.0f); + fac = minf(sqrt(fac), 1.0f); /* for max 1 second, interpolate positions */ - if (uiAlignPanelStep(sa, ar, fac, 0)) + if (uiAlignPanelStep(sa, ar, fac, 0)) { ED_region_tag_redraw(ar); - else + } + else { fac = 1.0f; + } if (fac >= 1.0f) { panel_activate_state(C, panel, PANEL_STATE_EXIT); diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index 83366ec204b..70f2bf7b028 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -2418,7 +2418,7 @@ static uiBlock *ui_block_func_POPUP(bContext *C, uiPopupBlockHandle *handle, voi * on the first item */ offset[0] = 0; for (bt = block->buttons.first; bt; bt = bt->next) - offset[0] = MIN2(offset[0], -(bt->x1 + 0.8f * (bt->x2 - bt->x1))); + offset[0] = mini(offset[0], -(bt->x1 + 0.8f * (bt->x2 - bt->x1))); offset[1] = 1.5 * UI_UNIT_Y; } @@ -2649,7 +2649,7 @@ void uiPupMenuOkee(bContext *C, const char *opname, const char *str, ...) * The operator state for this is implicitly OPERATOR_RUNNING_MODAL */ void uiPupMenuSaveOver(bContext *C, wmOperator *op, const char *filename) { - confirm_operator(C, op, "Save Over", filename); + confirm_operator(C, op, "Save Over?", filename); } void uiPupMenuNotice(bContext *C, const char *str, ...) diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 5d62b010555..733c88c0980 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -254,7 +254,7 @@ static void template_id_cb(bContext *C, void *arg_litem, void *arg_event) break; case UI_ID_OPEN: case UI_ID_ADD_NEW: - /* these call uiIDContextPropertySet */ + /* these call uiIDContextProperty */ break; case UI_ID_DELETE: memset(&idptr, 0, sizeof(idptr)); @@ -1636,7 +1636,7 @@ static void curvemap_buttons_delete(bContext *C, void *cb_v, void *cumap_v) } /* NOTE: this is a block-menu, needs 0 events, otherwise the menu closes */ -static uiBlock *curvemap_clipping_func(bContext *C, struct ARegion *ar, void *cumap_v) +static uiBlock *curvemap_clipping_func(bContext *C, ARegion *ar, void *cumap_v) { CurveMapping *cumap = cumap_v; uiBlock *block; @@ -1697,7 +1697,7 @@ static void curvemap_tools_dofunc(bContext *C, void *cumap_v, int event) ED_region_tag_redraw(CTX_wm_region(C)); } -static uiBlock *curvemap_tools_func(bContext *C, struct ARegion *ar, void *cumap_v) +static uiBlock *curvemap_tools_func(bContext *C, ARegion *ar, void *cumap_v) { uiBlock *block; short yco = 0, menuwidth = 10 * UI_UNIT_X; @@ -1719,7 +1719,7 @@ static uiBlock *curvemap_tools_func(bContext *C, struct ARegion *ar, void *cumap return block; } -static uiBlock *curvemap_brush_tools_func(bContext *C, struct ARegion *ar, void *cumap_v) +static uiBlock *curvemap_brush_tools_func(bContext *C, ARegion *ar, void *cumap_v) { uiBlock *block; short yco = 0, menuwidth = 10 * UI_UNIT_X; diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index 7b139d81a1c..b439271b23d 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -346,7 +346,8 @@ static void round_box__edges(uiWidgetBase *wt, int roundboxalign, rcti *rect, fl const int vnum = ((roundboxalign & (UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT)) == (UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT) || (roundboxalign & (UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT)) == (UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT)) ? 1 : 2; - minsize = MIN2((rect->xmax - rect->xmin) * hnum, (rect->ymax - rect->ymin) * vnum); + minsize = mini((rect->xmax - rect->xmin) * hnum, + (rect->ymax - rect->ymin) * vnum); if (2.0f * rad > minsize) rad = 0.5f * minsize; diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c index 6c03feeb26a..729f2b031e2 100644 --- a/source/blender/editors/interface/resources.c +++ b/source/blender/editors/interface/resources.c @@ -303,6 +303,8 @@ const unsigned char *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colo cp = ts->bone_solid; break; case TH_BONE_POSE: cp = ts->bone_pose; break; + case TH_BONE_POSE_ACTIVE: + cp = ts->bone_pose_active; break; case TH_STRIP: cp = ts->strip; break; case TH_STRIP_SELECT: @@ -745,6 +747,7 @@ void ui_theme_init_default(void) rgba_char_args_set(btheme->tv3d.bone_solid, 200, 200, 200, 255); /* alpha 80 is not meant editable, used for wire+action draw */ rgba_char_args_set(btheme->tv3d.bone_pose, 80, 200, 255, 80); + rgba_char_args_set(btheme->tv3d.bone_pose_active, 140, 255, 255, 80); rgba_char_args_set(btheme->tv3d.bundle_solid, 200, 200, 200, 255); rgba_char_args_set(btheme->tv3d.camera_path, 0x00, 0x00, 0x00, 255); @@ -1219,7 +1222,8 @@ void UI_GetColorPtrShade3ubv(const unsigned char cp[3], unsigned char col[3], in } // get a 3 byte color, blended and shaded between two other char color pointers -void UI_GetColorPtrBlendShade3ubv(const unsigned char cp1[3], const unsigned char cp2[3], unsigned char col[3], float fac, int offset) +void UI_GetColorPtrBlendShade3ubv(const unsigned char cp1[3], const unsigned char cp2[3], unsigned char col[3], + float fac, int offset) { int r, g, b; @@ -1746,7 +1750,8 @@ void init_userdef_do_versions(void) } if (bmain->versionfile < 257) { - /* clear "AUTOKEY_FLAG_ONLYKEYINGSET" flag from userprefs, so that it doesn't linger around from old configs like a ghost */ + /* clear "AUTOKEY_FLAG_ONLYKEYINGSET" flag from userprefs, + * so that it doesn't linger around from old configs like a ghost */ U.autokey_flag &= ~AUTOKEY_FLAG_ONLYKEYINGSET; } @@ -1918,6 +1923,25 @@ void init_userdef_do_versions(void) } } + if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 15)) { + bTheme *btheme; + for (btheme = U.themes.first; btheme; btheme = btheme->next) { + rgba_char_args_set(btheme->tv3d.bone_pose_active, 140, 255, 255, 80); + } + } + + if (bmain->versionfile < 263 || (bmain->versionfile == 263 && bmain->subversionfile < 16)) { + bTheme *btheme; + + for (btheme = U.themes.first; btheme; btheme = btheme->next) { + if (btheme->tact.anim_active[3] == 0) + rgba_char_args_set(btheme->tact.anim_active, 204, 112, 26, 102); + + if (btheme->tnla.anim_active[3] == 0) + rgba_char_args_set(btheme->tnla.anim_active, 204, 112, 26, 102); + } + } + /* Freestyle color settings */ { bTheme *btheme; diff --git a/source/blender/editors/interface/view2d_ops.c b/source/blender/editors/interface/view2d_ops.c index 3be41d1f46e..244a4ea15de 100644 --- a/source/blender/editors/interface/view2d_ops.c +++ b/source/blender/editors/interface/view2d_ops.c @@ -499,15 +499,15 @@ static void VIEW2D_OT_scroll_up(wmOperatorType *ot) /* ********************************************************* */ /* SINGLE-STEP VIEW ZOOMING OPERATOR */ -/* This group of operators come in several forms: - * 1) Scrollwheel 'steps' - rolling mousewheel by one step zooms view by predefined amount - * 2) Scrollwheel 'steps' + alt + ctrl/shift - zooms view on one axis only (ctrl=x, shift=y) // XXX this could be implemented... - * 3) Pad +/- Keys - pressing each key moves the zooms the view by a predefined amount +/* This group of operators come in several forms: + * 1) Scrollwheel 'steps' - rolling mousewheel by one step zooms view by predefined amount + * 2) Scrollwheel 'steps' + alt + ctrl/shift - zooms view on one axis only (ctrl=x, shift=y) // XXX this could be implemented... + * 3) Pad +/- Keys - pressing each key moves the zooms the view by a predefined amount * - * In order to make sure this works, each operator must define the following RNA-Operator Props: - * zoomfacx, zoomfacy - These two zoom factors allow for non-uniform scaling. - * It is safe to scale by 0, as these factors are used to determine - * amount to enlarge 'cur' by + * In order to make sure this works, each operator must define the following RNA-Operator Props: + * zoomfacx, zoomfacy - These two zoom factors allow for non-uniform scaling. + * It is safe to scale by 0, as these factors are used to determine + * amount to enlarge 'cur' by */ /* ------------------ 'Shared' stuff ------------------------ */ diff --git a/source/blender/editors/mask/mask_add.c b/source/blender/editors/mask/mask_add.c index c9f6dc0c5fb..c928e90b422 100644 --- a/source/blender/editors/mask/mask_add.c +++ b/source/blender/editors/mask/mask_add.c @@ -38,6 +38,7 @@ #include "BKE_mask.h" #include "DNA_scene_types.h" +#include "DNA_screen_types.h" #include "DNA_mask_types.h" #include "DNA_object_types.h" /* SELECT */ @@ -57,17 +58,19 @@ static int find_nearest_diff_point(const bContext *C, Mask *mask, const float no float *u_r, float tangent[2], const short use_deform) { + ScrArea *sa = CTX_wm_area(C); + ARegion *ar = CTX_wm_region(C); + MaskLayer *masklay, *point_masklay; MaskSpline *point_spline; MaskSplinePoint *point = NULL; float dist, co[2]; int width, height; float u; - float scalex, scaley, aspx, aspy; + float scalex, scaley; - ED_mask_size(C, &width, &height); - ED_mask_aspect(C, &aspx, &aspy); - ED_mask_pixelspace_factor(C, &scalex, &scaley); + ED_mask_get_size(sa, &width, &height); + ED_mask_pixelspace_factor(sa, ar, &scalex, &scaley); co[0] = normal_co[0] * scalex; co[1] = normal_co[1] * scaley; @@ -180,6 +183,8 @@ static void setup_vertex_point(const bContext *C, Mask *mask, MaskSpline *spline const float point_co[2], const float tangent[2], const float u, MaskSplinePoint *reference_point, const short reference_adjacent) { + ScrArea *sa = CTX_wm_area(C); + MaskSplinePoint *prev_point = NULL; MaskSplinePoint *next_point = NULL; BezTriple *bezt; @@ -190,7 +195,7 @@ static void setup_vertex_point(const bContext *C, Mask *mask, MaskSpline *spline copy_v2_v2(co, point_co); co[2] = 0.0f; - ED_mask_size(C, &width, &height); + ED_mask_get_size(sa, &width, &height); /* point coordinate */ bezt = &new_point->bezt; @@ -610,9 +615,12 @@ static int add_vertex_exec(bContext *C, wmOperator *op) static int add_vertex_invoke(bContext *C, wmOperator *op, wmEvent *event) { + ScrArea *sa = CTX_wm_area(C); + ARegion *ar = CTX_wm_region(C); + float co[2]; - ED_mask_mouse_pos(C, event, co); + ED_mask_mouse_pos(sa, ar, event->mval, co); RNA_float_set_array(op->ptr, "location", co); @@ -681,9 +689,12 @@ static int add_feather_vertex_exec(bContext *C, wmOperator *op) static int add_feather_vertex_invoke(bContext *C, wmOperator *op, wmEvent *event) { + ScrArea *sa = CTX_wm_area(C); + ARegion *ar = CTX_wm_region(C); + float co[2]; - ED_mask_mouse_pos(C, event, co); + ED_mask_mouse_pos(sa, ar, event->mval, co); RNA_float_set_array(op->ptr, "location", co); diff --git a/source/blender/editors/mask/mask_draw.c b/source/blender/editors/mask/mask_draw.c index f378d5452a4..2f5a918a488 100644 --- a/source/blender/editors/mask/mask_draw.c +++ b/source/blender/editors/mask/mask_draw.c @@ -32,17 +32,21 @@ #include "MEM_guardedalloc.h" #include "BLI_utildefines.h" +#include "BLI_math.h" #include "BKE_context.h" #include "BKE_mask.h" #include "DNA_mask_types.h" +#include "DNA_screen_types.h" #include "DNA_object_types.h" /* SELECT */ #include "ED_mask.h" /* own include */ +#include "ED_space_api.h" #include "BIF_gl.h" #include "UI_resources.h" +#include "UI_view2d.h" #include "mask_intern.h" /* own include */ @@ -129,7 +133,8 @@ static void draw_spline_points(MaskLayer *masklay, MaskSpline *spline, if (!spline->tot_point) return; - hsize = UI_GetThemeValuef(TH_HANDLE_VERTEX_SIZE); + /* TODO, add this to sequence editor */ + hsize = 4; /* UI_GetThemeValuef(TH_HANDLE_VERTEX_SIZE); */ glPointSize(hsize); @@ -451,13 +456,116 @@ static void draw_masklays(Mask *mask, const char draw_flag, const char draw_type void ED_mask_draw(const bContext *C, const char draw_flag, const char draw_type) { + ScrArea *sa = CTX_wm_area(C); + Mask *mask = CTX_data_edit_mask(C); int width, height; if (!mask) return; - ED_mask_size(C, &width, &height); + ED_mask_get_size(sa, &width, &height); draw_masklays(mask, draw_flag, draw_type, width, height); } + +/* sets up the opengl context. + * width, height are to match the values from ED_mask_get_size() */ +void ED_mask_draw_region(Mask *mask, ARegion *ar, + const char draw_flag, const char draw_type, + int width, int height, + const short do_scale_applied, const short do_post_draw, + float stabmat[4][4], /* optional - only used by clip */ + const bContext *C /* optional - only used when do_post_draw is set */ + ) +{ + struct View2D *v2d = &ar->v2d; + + int x, y; + /* int w, h; */ + float zoomx, zoomy; + + /* frame image */ + float maxdim; + float xofs, yofs; + + /* find window pixel coordinates of origin */ + UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &x, &y); + + + /* w = v2d->tot.xmax - v2d->tot.xmin; */ + /* h = v2d->tot.ymax - v2d->tot.ymin;/*/ + + + zoomx = (float)(ar->winrct.xmax - ar->winrct.xmin + 1) / (float)((ar->v2d.cur.xmax - ar->v2d.cur.xmin)); + zoomy = (float)(ar->winrct.ymax - ar->winrct.ymin + 1) / (float)((ar->v2d.cur.ymax - ar->v2d.cur.ymin)); + + if (do_scale_applied) { + zoomx /= width; + zoomy /= height; + } + + x += v2d->tot.xmin * zoomx; + y += v2d->tot.ymin * zoomy; + + /* frame the image */ + maxdim = maxf(width, height); + if (width == height) { + xofs = yofs = 0; + } + else if (width < height) { + xofs = ((height - width) / -2.0f) * zoomx; + yofs = 0.0f; + } + else { /* (width > height) */ + xofs = 0.0f; + yofs = ((width - height) / -2.0f) * zoomy; + } + + /* apply transformation so mask editing tools will assume drawing from the origin in normalized space */ + glPushMatrix(); + glTranslatef(x + xofs, y + yofs, 0); + glScalef(maxdim * zoomx, maxdim * zoomy, 0); + + if (stabmat) { + glMultMatrixf(stabmat); + } + + /* draw! */ + draw_masklays(mask, draw_flag, draw_type, width, height); + + if (do_post_draw) { + ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW); + } + + glPopMatrix(); +} + +void ED_mask_draw_frames(Mask *mask, ARegion *ar, const int cfra, const int sfra, const int efra) +{ + const float framelen = ar->winx / (float)(efra - sfra + 1); + + MaskLayer *masklay = BKE_mask_layer_active(mask); + + glBegin(GL_LINES); + glColor4ub(255, 175, 0, 255); + + if (masklay) { + MaskLayerShape *masklay_shape; + + for (masklay_shape = masklay->splines_shapes.first; + masklay_shape; + masklay_shape = masklay_shape->next) + { + int frame = masklay_shape->frame; + + /* draw_keyframe(i, CFRA, sfra, framelen, 1); */ + int height = (frame == cfra) ? 22 : 10; + int x = (frame - sfra) * framelen; + glVertex2i(x, 0); + glVertex2i(x, height); + } + } + + glEnd(); +} diff --git a/source/blender/editors/mask/mask_edit.c b/source/blender/editors/mask/mask_edit.c index b9522540e67..85a8ae11111 100644 --- a/source/blender/editors/mask/mask_edit.c +++ b/source/blender/editors/mask/mask_edit.c @@ -42,10 +42,14 @@ #include "ED_screen.h" #include "ED_mask.h" /* own include */ +#include "ED_image.h" #include "ED_object.h" /* ED_keymap_proportional_maskmode only */ #include "ED_clip.h" +#include "ED_sequencer.h" #include "ED_transform.h" +#include "UI_view2d.h" + #include "RNA_access.h" #include "mask_intern.h" /* own include */ @@ -54,55 +58,113 @@ int ED_maskedit_poll(bContext *C) { - SpaceClip *sc = CTX_wm_space_clip(C); - - if (sc) { - return ED_space_clip_maskedit_poll(C); + ScrArea *sa = CTX_wm_area(C); + if (sa) { + switch (sa->spacetype) { + case SPACE_CLIP: + return ED_space_clip_maskedit_poll(C); + case SPACE_SEQ: + return ED_space_sequencer_maskedit_poll(C); + case SPACE_IMAGE: + return ED_space_image_maskedit_poll(C); + } } - return FALSE; } int ED_maskedit_mask_poll(bContext *C) { - SpaceClip *sc = CTX_wm_space_clip(C); - - if (sc) { - return ED_space_clip_maskedit_mask_poll(C); + ScrArea *sa = CTX_wm_area(C); + if (sa) { + switch (sa->spacetype) { + case SPACE_CLIP: + return ED_space_clip_maskedit_mask_poll(C); + case SPACE_SEQ: + return ED_space_sequencer_maskedit_mask_poll(C); + case SPACE_IMAGE: + return ED_space_image_maskedit_mask_poll(C); + } } - return FALSE; } /********************** registration *********************/ -void ED_mask_mouse_pos(const bContext *C, wmEvent *event, float co[2]) +/* takes event->mval */ +void ED_mask_mouse_pos(ScrArea *sa, ARegion *ar, const int mval[2], float co[2]) { - SpaceClip *sc = CTX_wm_space_clip(C); - - if (sc) { - ED_clip_mouse_pos(C, event, co); - BKE_mask_coord_from_movieclip(sc->clip, &sc->user, co, co); + if (sa) { + switch (sa->spacetype) { + case SPACE_CLIP: + { + SpaceClip *sc = sa->spacedata.first; + ED_clip_mouse_pos(sc, ar, mval, co); + BKE_mask_coord_from_movieclip(sc->clip, &sc->user, co, co); + break; + } + case SPACE_SEQ: + { + UI_view2d_region_to_view(&ar->v2d, mval[0], mval[1], &co[0], &co[1]); + break; + } + case SPACE_IMAGE: + { + float frame_size[2]; + SpaceImage *sima = sa->spacedata.first; + ED_space_image_get_size_fl(sima, frame_size); + ED_image_mouse_pos(sima, ar, mval, co); + BKE_mask_coord_from_frame(co, co, frame_size); + break; + } + default: + /* possible other spaces from which mask editing is available */ + BLI_assert(0); + zero_v2(co); + break; + } } else { - /* possible other spaces from which mask editing is available */ + BLI_assert(0); zero_v2(co); } } /* input: x/y - mval space * output: xr/yr - mask point space */ -void ED_mask_point_pos(const bContext *C, float x, float y, float *xr, float *yr) +void ED_mask_point_pos(ScrArea *sa, ARegion *ar, float x, float y, float *xr, float *yr) { - SpaceClip *sc = CTX_wm_space_clip(C); float co[2]; - if (sc) { - ED_clip_point_stable_pos(C, x, y, &co[0], &co[1]); - BKE_mask_coord_from_movieclip(sc->clip, &sc->user, co, co); + if (sa) { + switch (sa->spacetype) { + case SPACE_CLIP: + { + SpaceClip *sc = sa->spacedata.first; + ED_clip_point_stable_pos(sc, ar, x, y, &co[0], &co[1]); + BKE_mask_coord_from_movieclip(sc->clip, &sc->user, co, co); + break; + } + case SPACE_SEQ: + zero_v2(co); /* MASKTODO */ + break; + case SPACE_IMAGE: + { + float frame_size[2]; + SpaceImage *sima = sa->spacedata.first; + ED_space_image_get_size_fl(sima, frame_size); + ED_image_point_pos(sima, ar, x, y, &co[0], &co[1]); + BKE_mask_coord_from_frame(co, co, frame_size); + break; + } + default: + /* possible other spaces from which mask editing is available */ + BLI_assert(0); + zero_v2(co); + break; + } } else { - /* possible other spaces from which mask editing is available */ + BLI_assert(0); zero_v2(co); } @@ -110,21 +172,45 @@ void ED_mask_point_pos(const bContext *C, float x, float y, float *xr, float *yr *yr = co[1]; } -void ED_mask_point_pos__reverse(const bContext *C, float x, float y, float *xr, float *yr) +void ED_mask_point_pos__reverse(ScrArea *sa, ARegion *ar, float x, float y, float *xr, float *yr) { - SpaceClip *sc = CTX_wm_space_clip(C); - ARegion *ar = CTX_wm_region(C); - float co[2]; - if (sc && ar) { - co[0] = x; - co[1] = y; - BKE_mask_coord_to_movieclip(sc->clip, &sc->user, co, co); - ED_clip_point_stable_pos__reverse(C, co, co); + if (sa) { + switch (sa->spacetype) { + case SPACE_CLIP: + { + SpaceClip *sc = sa->spacedata.first; + co[0] = x; + co[1] = y; + BKE_mask_coord_to_movieclip(sc->clip, &sc->user, co, co); + ED_clip_point_stable_pos__reverse(sc, ar, co, co); + break; + } + case SPACE_SEQ: + zero_v2(co); /* MASKTODO */ + break; + case SPACE_IMAGE: + { + float frame_size[2]; + SpaceImage *sima = sa->spacedata.first; + ED_space_image_get_size_fl(sima, frame_size); + + co[0] = x; + co[1] = y; + BKE_mask_coord_to_frame(co, co, frame_size); + ED_image_point_pos__reverse(sima, ar, co, co); + break; + } + default: + /* possible other spaces from which mask editing is available */ + BLI_assert(0); + zero_v2(co); + break; + } } else { - /* possible other spaces from which mask editing is available */ + BLI_assert(0); zero_v2(co); } @@ -132,60 +218,159 @@ void ED_mask_point_pos__reverse(const bContext *C, float x, float y, float *xr, *yr = co[1]; } -void ED_mask_size(const bContext *C, int *width, int *height) +void ED_mask_get_size(ScrArea *sa, int *width, int *height) { - ScrArea *sa = CTX_wm_area(C); if (sa && sa->spacedata.first) { - if (sa->spacetype == SPACE_CLIP) { - ED_space_clip_get_size(C, width, height); - return; + switch (sa->spacetype) { + case SPACE_CLIP: + { + SpaceClip *sc = sa->spacedata.first; + ED_space_clip_get_size(sc, width, height); + break; + } + case SPACE_SEQ: + { +// Scene *scene = CTX_data_scene(C); +// *width = (scene->r.size * scene->r.xsch) / 100; +// *height = (scene->r.size * scene->r.ysch) / 100; + break; + } + case SPACE_IMAGE: + { + SpaceImage *sima = sa->spacedata.first; + ED_space_image_get_size(sima, width, height); + break; + } + default: + /* possible other spaces from which mask editing is available */ + BLI_assert(0); + *width = 0; + *height = 0; + break; } - else if (sa->spacetype == SPACE_SEQ) { - Scene *scene = CTX_data_scene(C); - *width = (scene->r.size * scene->r.xsch) / 100; - *height = (scene->r.size * scene->r.ysch) / 100; - return; - } - } - - /* possible other spaces from which mask editing is available */ - *width = 0; - *height = 0; -} - -void ED_mask_aspect(const bContext *C, float *aspx, float *aspy) -{ - SpaceClip *sc = CTX_wm_space_clip(C); - - if (sc) { - ED_space_clip_get_aspect(sc, aspx, aspy); } else { - /* possible other spaces from which mask editing is available */ - *aspx = 1.0f; - *aspy = 1.0f; + BLI_assert(0); + *width = 0; + *height = 0; } } -void ED_mask_pixelspace_factor(const bContext *C, float *scalex, float *scaley) +void ED_mask_zoom(ScrArea *sa, ARegion *ar, float *zoomx, float *zoomy) { - SpaceClip *sc = CTX_wm_space_clip(C); - - if (sc) { - int width, height; - float zoomx, zoomy, aspx, aspy; - - ED_space_clip_get_size(C, &width, &height); - ED_space_clip_get_zoom(C, &zoomx, &zoomy); - ED_space_clip_get_aspect(sc, &aspx, &aspy); - - *scalex = ((float)width * aspx) * zoomx; - *scaley = ((float)height * aspy) * zoomy; + if (sa && sa->spacedata.first) { + switch (sa->spacetype) { + case SPACE_CLIP: + { + SpaceClip *sc = sa->spacedata.first; + ED_space_clip_get_zoom(sc, ar, zoomx, zoomy); + break; + } + case SPACE_SEQ: + { + *zoomx = *zoomy = 1.0f; + break; + } + case SPACE_IMAGE: + { + SpaceImage *sima = sa->spacedata.first; + ED_space_image_get_zoom(sima, ar, zoomx, zoomy); + break; + } + default: + /* possible other spaces from which mask editing is available */ + BLI_assert(0); + *zoomx = *zoomy = 1.0f; + break; + } } else { - /* possible other spaces from which mask editing is available */ - *scalex = 1.0f; - *scaley = 1.0f; + BLI_assert(0); + *zoomx = *zoomy = 1.0f; + } +} + +void ED_mask_get_aspect(ScrArea *sa, ARegion *UNUSED(ar), float *aspx, float *aspy) +{ + if (sa && sa->spacedata.first) { + switch (sa->spacetype) { + case SPACE_CLIP: + { + SpaceClip *sc = sa->spacedata.first; + ED_space_clip_get_aspect(sc, aspx, aspy); + break; + } + case SPACE_SEQ: + { + *aspx = *aspy = 1.0f; /* MASKTODO - render aspect? */ + break; + } + case SPACE_IMAGE: + { + SpaceImage *sima = sa->spacedata.first; + ED_space_image_get_aspect(sima, aspx, aspy); + break; + } + default: + /* possible other spaces from which mask editing is available */ + BLI_assert(0); + *aspx = *aspy = 1.0f; + break; + } + } + else { + BLI_assert(0); + *aspx = *aspy = 1.0f; + } +} + +void ED_mask_pixelspace_factor(ScrArea *sa, ARegion *ar, float *scalex, float *scaley) +{ + if (sa && sa->spacedata.first) { + switch (sa->spacetype) { + case SPACE_CLIP: + { + SpaceClip *sc = sa->spacedata.first; + int width, height; + float zoomx, zoomy, aspx, aspy; + + ED_space_clip_get_size(sc, &width, &height); + ED_space_clip_get_zoom(sc, ar, &zoomx, &zoomy); + ED_space_clip_get_aspect(sc, &aspx, &aspy); + + *scalex = ((float)width * aspx) * zoomx; + *scaley = ((float)height * aspy) * zoomy; + break; + } + case SPACE_SEQ: + { + *scalex = *scaley = 1.0f; /* MASKTODO? */ + break; + } + case SPACE_IMAGE: + { + SpaceImage *sima = sa->spacedata.first; + int width, height; + float zoomx, zoomy, aspx, aspy; + + ED_space_image_get_size(sima, &width, &height); + ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy); + ED_space_image_get_aspect(sima, &aspx, &aspy); + + *scalex = ((float)width * aspx) * zoomx; + *scaley = ((float)height * aspy) * zoomy; + break; + } + default: + /* possible other spaces from which mask editing is available */ + BLI_assert(0); + *scalex = *scaley = 1.0f; + break; + } + } + else { + BLI_assert(0); + *scalex = *scaley = 1.0f; } } @@ -313,8 +498,6 @@ void ED_keymap_mask(wmKeyConfig *keyconf) WM_keymap_add_item(keymap, "MASK_OT_normals_make_consistent", NKEY, KM_PRESS, KM_CTRL, 0); // WM_keymap_add_item(keymap, "MASK_OT_feather_weight_clear", SKEY, KM_PRESS, KM_ALT, 0); /* ... matches curve editmode */ - RNA_enum_set(WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, KM_ALT, 0)->ptr, - "mode", TFM_MASK_SHRINKFATTEN); /* relationships */ WM_keymap_add_item(keymap, "MASK_OT_parent_set", PKEY, KM_PRESS, KM_CTRL, 0); @@ -323,8 +506,16 @@ void ED_keymap_mask(wmKeyConfig *keyconf) WM_keymap_add_item(keymap, "MASK_OT_shape_key_insert", IKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "MASK_OT_shape_key_clear", IKEY, KM_PRESS, KM_ALT, 0); + /* for image editor only */ + WM_keymap_add_item(keymap, "UV_OT_cursor_set", ACTIONMOUSE, KM_PRESS, 0, 0); - transform_keymap_for_space(keyconf, keymap, SPACE_CLIP); + /* Transform (don't use transform_keymap_for_space() since this maps to different spaces) */ + WM_keymap_add_item(keymap, "TRANSFORM_OT_translate", GKEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "TRANSFORM_OT_translate", EVT_TWEAK_S, KM_ANY, 0, 0); + WM_keymap_add_item(keymap, "TRANSFORM_OT_resize", SKEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "TRANSFORM_OT_rotate", RKEY, KM_PRESS, 0, 0); + kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, KM_ALT, 0); + RNA_enum_set(kmi->ptr, "mode", TFM_MASK_SHRINKFATTEN); } void ED_operatormacros_mask(void) diff --git a/source/blender/editors/mask/mask_intern.h b/source/blender/editors/mask/mask_intern.h index bad0a9c28a8..ffd4afca182 100644 --- a/source/blender/editors/mask/mask_intern.h +++ b/source/blender/editors/mask/mask_intern.h @@ -99,15 +99,6 @@ void ED_mask_select_flush_all(struct Mask *mask); int ED_maskedit_poll(struct bContext *C); int ED_maskedit_mask_poll(struct bContext *C); -void ED_mask_size(const struct bContext *C, int *width, int *height); -void ED_mask_aspect(const struct bContext *C, float *aspx, float *aspy); - -void ED_mask_pixelspace_factor(const struct bContext *C, float *scalex, float *scaley); -void ED_mask_mouse_pos(const struct bContext *C, struct wmEvent *event, float co[2]); - -void ED_mask_point_pos(const struct bContext *C, float x, float y, float *xr, float *yr); -void ED_mask_point_pos__reverse(const struct bContext *C, float x, float y, float *xr, float *yr); - /* mask_shapekey.c */ void MASK_OT_shape_key_insert(struct wmOperatorType *ot); void MASK_OT_shape_key_clear(struct wmOperatorType *ot); diff --git a/source/blender/editors/mask/mask_ops.c b/source/blender/editors/mask/mask_ops.c index c8246fd53bc..1df1e5a66fe 100644 --- a/source/blender/editors/mask/mask_ops.c +++ b/source/blender/editors/mask/mask_ops.c @@ -45,10 +45,11 @@ #include "WM_api.h" #include "WM_types.h" -#include "ED_screen.h" -#include "ED_mask.h" #include "ED_clip.h" +#include "ED_image.h" #include "ED_keyframing.h" +#include "ED_mask.h" +#include "ED_screen.h" #include "RNA_access.h" #include "RNA_define.h" @@ -61,17 +62,19 @@ MaskSplinePoint *ED_mask_point_find_nearest(const bContext *C, Mask *mask, float MaskLayer **masklay_r, MaskSpline **spline_r, int *is_handle_r, float *score) { + ScrArea *sa = CTX_wm_area(C); + ARegion *ar = CTX_wm_region(C); + MaskLayer *masklay; MaskLayer *point_masklay = NULL; MaskSpline *point_spline = NULL; MaskSplinePoint *point = NULL; - float co[2], aspx, aspy; + float co[2]; float len = FLT_MAX, scalex, scaley; int is_handle = FALSE, width, height; - ED_mask_size(C, &width, &height); - ED_mask_aspect(C, &aspx, &aspy); - ED_mask_pixelspace_factor(C, &scalex, &scaley); + ED_mask_get_size(sa, &width, &height); + ED_mask_pixelspace_factor(sa, ar, &scalex, &scaley); co[0] = normal_co[0] * scalex; co[1] = normal_co[1] * scaley; @@ -157,17 +160,19 @@ int ED_mask_feather_find_nearest(const bContext *C, Mask *mask, float normal_co[ MaskLayer **masklay_r, MaskSpline **spline_r, MaskSplinePoint **point_r, MaskSplinePointUW **uw_r, float *score) { + ScrArea *sa = CTX_wm_area(C); + ARegion *ar = CTX_wm_region(C); + MaskLayer *masklay, *point_masklay = NULL; MaskSpline *point_spline = NULL; MaskSplinePoint *point = NULL; MaskSplinePointUW *uw = NULL; float len = FLT_MAX, co[2]; - float scalex, scaley, aspx, aspy; + float scalex, scaley; int width, height; - ED_mask_size(C, &width, &height); - ED_mask_aspect(C, &aspx, &aspy); - ED_mask_pixelspace_factor(C, &scalex, &scaley); + ED_mask_get_size(sa, &width, &height); + ED_mask_pixelspace_factor(sa, ar, &scalex, &scaley); co[0] = normal_co[0] * scalex; co[1] = normal_co[1] * scaley; @@ -255,7 +260,7 @@ int ED_mask_feather_find_nearest(const bContext *C, Mask *mask, float normal_co[ static int mask_new_exec(bContext *C, wmOperator *op) { - SpaceClip *sc = CTX_wm_space_clip(C); + ScrArea *sa = CTX_wm_area(C); Mask *mask; char name[MAX_ID_NAME - 2]; @@ -263,8 +268,27 @@ static int mask_new_exec(bContext *C, wmOperator *op) mask = BKE_mask_new(name); - if (sc) - ED_space_clip_set_mask(C, sc, mask); + if (sa && sa->spacedata.first) { + switch (sa->spacetype) { + case SPACE_CLIP: + { + SpaceClip *sc = sa->spacedata.first; + ED_space_clip_set_mask(C, sc, mask); + break; + } + case SPACE_SEQ: + { + /* do nothing */ + break; + } + case SPACE_IMAGE: + { + SpaceImage *sima = sa->spacedata.first; + ED_space_image_set_mask(C, sima, mask); + break; + } + } + } return OPERATOR_FINISHED; } @@ -406,6 +430,9 @@ static int slide_point_check_initial_feather(MaskSpline *spline) static void *slide_point_customdata(bContext *C, wmOperator *op, wmEvent *event) { + ScrArea *sa = CTX_wm_area(C); + ARegion *ar = CTX_wm_region(C); + Mask *mask = CTX_data_edit_mask(C); SlidePointData *customdata = NULL; MaskLayer *masklay, *cv_masklay, *feather_masklay; @@ -417,8 +444,8 @@ static void *slide_point_customdata(bContext *C, wmOperator *op, wmEvent *event) float co[2], cv_score, feather_score; const float threshold = 19; - ED_mask_mouse_pos(C, event, co); - ED_mask_size(C, &width, &height); + ED_mask_mouse_pos(sa, ar, event->mval, co); + ED_mask_get_size(sa, &width, &height); cv_point = ED_mask_point_find_nearest(C, mask, co, threshold, &cv_masklay, &cv_spline, &is_handle, &cv_score); @@ -482,7 +509,7 @@ static void *slide_point_customdata(bContext *C, wmOperator *op, wmEvent *event) copy_m3_m3(customdata->vec, point->bezt.vec); if (BKE_mask_point_has_handle(point)) BKE_mask_point_handle(point, customdata->handle); - ED_mask_mouse_pos(C, event, customdata->co); + ED_mask_mouse_pos(sa, ar, event->mval, customdata->co); } return customdata; @@ -499,6 +526,7 @@ static int slide_point_invoke(bContext *C, wmOperator *op, wmEvent *event) WM_event_add_modal_handler(C, op); +#if 0 if (slidedata->uw) { if ((slidedata->uw->flag & SELECT) == 0) { ED_mask_select_toggle_all(mask, SEL_DESELECT); @@ -515,6 +543,7 @@ static int slide_point_invoke(bContext *C, wmOperator *op, wmEvent *event) ED_mask_select_flush_all(mask); } +#endif slidedata->masklay->act_spline = slidedata->spline; slidedata->masklay->act_point = slidedata->point; @@ -602,24 +631,28 @@ static int slide_point_modal(bContext *C, wmOperator *op, wmEvent *event) float co[2], dco[2]; switch (event->type) { - case LEFTCTRLKEY: - case RIGHTCTRLKEY: + case LEFTALTKEY: + case RIGHTALTKEY: case LEFTSHIFTKEY: case RIGHTSHIFTKEY: - if (ELEM(event->type, LEFTCTRLKEY, RIGHTCTRLKEY)) { + if (ELEM(event->type, LEFTALTKEY, RIGHTALTKEY)) { if (data->action == SLIDE_ACTION_FEATHER) - data->overall_feather = event->val == KM_PRESS; + data->overall_feather = (event->val == KM_PRESS); else - data->curvature_only = event->val == KM_PRESS; + data->curvature_only = (event->val == KM_PRESS); } if (ELEM(event->type, LEFTSHIFTKEY, RIGHTSHIFTKEY)) - data->accurate = event->val == KM_PRESS; + data->accurate = (event->val == KM_PRESS); /* no break! update CV position */ case MOUSEMOVE: - ED_mask_mouse_pos(C, event, co); + { + ScrArea *sa = CTX_wm_area(C); + ARegion *ar = CTX_wm_region(C); + + ED_mask_mouse_pos(sa, ar, event->mval, co); sub_v2_v2v2(dco, co, data->co); if (data->action == SLIDE_ACTION_HANDLE) { @@ -748,6 +781,7 @@ static int slide_point_modal(bContext *C, wmOperator *op, wmEvent *event) DAG_id_tag_update(&data->mask->id, 0); break; + } case LEFTMOUSE: if (event->val == KM_RELEASE) { diff --git a/source/blender/editors/mask/mask_select.c b/source/blender/editors/mask/mask_select.c index a2a7a07d089..e746f4258a5 100644 --- a/source/blender/editors/mask/mask_select.c +++ b/source/blender/editors/mask/mask_select.c @@ -147,7 +147,26 @@ void ED_mask_select_toggle_all(Mask *mask, int action) continue; } - ED_mask_layer_select_set(masklay, (action == SEL_SELECT) ? TRUE : FALSE); + if (action == SEL_INVERT) { + /* we don't have generic functons for this, its restricted to this operator + * if one day we need to re-use such functionality, they can be split out */ + + MaskSpline *spline; + if (masklay->restrictflag & MASK_RESTRICT_SELECT) { + continue; + } + for (spline = masklay->splines.first; spline; spline = spline->next) { + int i; + for (i = 0; i < spline->tot_point; i++) { + MaskSplinePoint *point = &spline->points[i]; + BKE_mask_point_select_set(point, !MASKPOINT_ISSEL_ANY(point)); + } + } + + } + else { + ED_mask_layer_select_set(masklay, (action == SEL_SELECT) ? TRUE : FALSE); + } } } @@ -343,9 +362,12 @@ static int select_exec(bContext *C, wmOperator *op) static int select_invoke(bContext *C, wmOperator *op, wmEvent *event) { + ScrArea *sa = CTX_wm_area(C); + ARegion *ar = CTX_wm_region(C); + float co[2]; - ED_mask_mouse_pos(C, event, co); + ED_mask_mouse_pos(sa, ar, event->mval, co); RNA_float_set_array(op->ptr, "location", co); @@ -380,6 +402,9 @@ void MASK_OT_select(wmOperatorType *ot) static int border_select_exec(bContext *C, wmOperator *op) { + ScrArea *sa = CTX_wm_area(C); + ARegion *ar = CTX_wm_region(C); + Mask *mask = CTX_data_edit_mask(C); MaskLayer *masklay; int i; @@ -394,8 +419,8 @@ static int border_select_exec(bContext *C, wmOperator *op) rect.xmax = RNA_int_get(op->ptr, "xmax"); rect.ymax = RNA_int_get(op->ptr, "ymax"); - ED_mask_point_pos(C, rect.xmin, rect.ymin, &rectf.xmin, &rectf.ymin); - ED_mask_point_pos(C, rect.xmax, rect.ymax, &rectf.xmax, &rectf.ymax); + ED_mask_point_pos(sa, ar, rect.xmin, rect.ymin, &rectf.xmin, &rectf.ymin); + ED_mask_point_pos(sa, ar, rect.xmax, rect.ymax, &rectf.xmax, &rectf.ymax); mode = RNA_int_get(op->ptr, "gesture_mode"); extend = RNA_boolean_get(op->ptr, "extend"); @@ -465,6 +490,9 @@ void MASK_OT_select_border(wmOperatorType *ot) static int do_lasso_select_mask(bContext *C, int mcords[][2], short moves, short select) { + ScrArea *sa = CTX_wm_area(C); + ARegion *ar = CTX_wm_region(C); + Mask *mask = CTX_data_edit_mask(C); MaskLayer *masklay; int i; @@ -496,7 +524,7 @@ static int do_lasso_select_mask(bContext *C, int mcords[][2], short moves, short float screen_co[2]; /* marker in screen coords */ - ED_mask_point_pos__reverse(C, + ED_mask_point_pos__reverse(sa, ar, point_deform->bezt.vec[1][0], point_deform->bezt.vec[1][1], &screen_co[0], &screen_co[1]); @@ -577,6 +605,9 @@ static int mask_spline_point_inside_ellipse(BezTriple *bezt, float offset[2], fl static int circle_select_exec(bContext *C, wmOperator *op) { + ScrArea *sa = CTX_wm_area(C); + ARegion *ar = CTX_wm_region(C); + Mask *mask = CTX_data_edit_mask(C); MaskLayer *masklay; int i; @@ -591,16 +622,15 @@ static int circle_select_exec(bContext *C, wmOperator *op) mode = RNA_int_get(op->ptr, "gesture_mode"); - /* TODO - make generic! - this is SpaceClip only! */ /* compute ellipse and position in unified coordinates */ - ED_space_clip_get_size(C, &width, &height); - ED_space_clip_get_zoom(C, &zoomx, &zoomy); + ED_mask_get_size(sa, &width, &height); + ED_mask_zoom(sa, ar, &zoomx, &zoomy); width = height = MAX2(width, height); ellipse[0] = width * zoomx / radius; ellipse[1] = height * zoomy / radius; - ED_mask_point_pos(C, x, y, &offset[0], &offset[1]); + ED_mask_point_pos(sa, ar, x, y, &offset[0], &offset[1]); /* do actual selection */ for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) { @@ -663,6 +693,9 @@ void MASK_OT_select_circle(wmOperatorType *ot) static int mask_select_linked_pick_invoke(bContext *C, wmOperator *op, wmEvent *event) { + ScrArea *sa = CTX_wm_area(C); + ARegion *ar = CTX_wm_region(C); + Mask *mask = CTX_data_edit_mask(C); MaskLayer *masklay; MaskSpline *spline; @@ -674,7 +707,7 @@ static int mask_select_linked_pick_invoke(bContext *C, wmOperator *op, wmEvent * const float threshold = 19; int change = FALSE; - ED_mask_mouse_pos(C, event, co); + ED_mask_mouse_pos(sa, ar, event->mval, co); point = ED_mask_point_find_nearest(C, mask, co, threshold, &masklay, &spline, &is_handle, NULL); diff --git a/source/blender/editors/mesh/editmesh_knife.c b/source/blender/editors/mesh/editmesh_knife.c index 882d3115ba0..8a3cf87e96a 100644 --- a/source/blender/editors/mesh/editmesh_knife.c +++ b/source/blender/editors/mesh/editmesh_knife.c @@ -84,6 +84,7 @@ typedef struct KnifeColors { typedef struct KnifeVert { BMVert *v; /* non-NULL if this is an original vert */ ListBase edges; + ListBase faces; float co[3], cageco[3], sco[3]; /* sco is screen coordinates for cageco */ short flag, draw, isface, inspace; @@ -277,6 +278,32 @@ static void knife_add_to_vert_edges(KnifeTool_OpData *kcd, KnifeEdge *kfe) knife_append_list(kcd, &kfe->v2->edges, kfe); } +/* Add faces of an edge to a KnifeVert's faces list. No checks for dups. */ +static void knife_add_edge_faces_to_vert(KnifeTool_OpData *kcd, KnifeVert *kfv, BMEdge *e) +{ + BMIter bmiter; + BMFace *f; + + BM_ITER_ELEM(f, &bmiter, e, BM_FACES_OF_EDGE) { + knife_append_list(kcd, &kfv->faces, f); + } +} + +/* Find a face in common in the two faces lists. + If more than one, return the first; if none, return NULL */ +static BMFace *knife_find_common_face(ListBase *faces1, ListBase *faces2) +{ + Ref *ref1, *ref2; + + for (ref1 = faces1->first; ref1; ref1 = ref1->next) { + for (ref2 = faces2->first; ref2; ref2 = ref2->next) { + if (ref1->ref == ref2->ref) + return (BMFace *)(ref1->ref); + } + } + return NULL; +} + static KnifeVert *new_knife_vert(KnifeTool_OpData *kcd, const float co[3], float *cageco) { KnifeVert *kfv = BLI_mempool_calloc(kcd->kverts); @@ -298,9 +325,15 @@ static KnifeVert *get_bm_knife_vert(KnifeTool_OpData *kcd, BMVert *v) KnifeVert *kfv = BLI_ghash_lookup(kcd->origvertmap, v); if (!kfv) { + BMIter bmiter; + BMFace *f; + kfv = new_knife_vert(kcd, v->co, kcd->cagecos[BM_elem_index_get(v)]); kfv->v = v; BLI_ghash_insert(kcd->origvertmap, v, kfv); + BM_ITER_ELEM(f, &bmiter, v, BM_FACES_OF_VERT) { + knife_append_list(kcd, &kfv->faces, f); + } } return kfv; @@ -389,35 +422,9 @@ static ListBase *knife_get_face_kedges(KnifeTool_OpData *kcd, BMFace *f) } /* finds the proper face to restrict face fill to */ -static void knife_find_basef(KnifeTool_OpData *kcd, KnifeEdge *kfe) +static void knife_find_basef(KnifeEdge *kfe) { - if (!kfe->basef) { - Ref *r1, *r2, *r3, *r4; - - if (kfe->v1->isface || kfe->v2->isface) { - if (kfe->v2->isface) - kfe->basef = kcd->cur.bmface; - else - kfe->basef = kcd->prev.bmface; - } - else { - for (r1 = kfe->v1->edges.first; r1 && !kfe->basef; r1 = r1->next) { - KnifeEdge *ke1 = r1->ref; - for (r2 = ke1->faces.first; r2 && !kfe->basef; r2 = r2->next) { - for (r3 = kfe->v2->edges.first; r3 && !kfe->basef; r3 = r3->next) { - KnifeEdge *ke2 = r3->ref; - - for (r4 = ke2->faces.first; r4 && !kfe->basef; r4 = r4->next) { - if (r2->ref == r4->ref) { - kfe->basef = r2->ref; - } - } - } - } - } - } - /* ok, at this point kfe->basef should be set if any valid possibility exists */ - } + kfe->basef = knife_find_common_face(&kfe->v1->faces, &kfe->v2->faces); } static void knife_edge_append_face(KnifeTool_OpData *kcd, KnifeEdge *kfe, BMFace *f) @@ -430,6 +437,7 @@ static KnifeVert *knife_split_edge(KnifeTool_OpData *kcd, KnifeEdge *kfe, float { KnifeEdge *newkfe = new_knife_edge(kcd); Ref *ref; + BMFace *f; float perc, cageco[3], l12; l12 = len_v3v3(kfe->v1->co, kfe->v2->co); @@ -444,6 +452,17 @@ static KnifeVert *knife_split_edge(KnifeTool_OpData *kcd, KnifeEdge *kfe, float newkfe->v1 = kfe->v1; newkfe->v2 = new_knife_vert(kcd, co, cageco); newkfe->v2->draw = 1; + if (kfe->e) { + knife_add_edge_faces_to_vert(kcd, newkfe->v2, kfe->e); + } + else { + /* kfe cuts across an existing face. + If v1 and v2 are in multiple faces together (e.g., if they + are in doubled polys) then this arbitrarily chooses one of them */ + f = knife_find_common_face(&kfe->v1->faces, &kfe->v2->faces); + if (f) + knife_append_list(kcd, &newkfe->v2->faces, f); + } newkfe->basef = kfe->basef; ref = find_ref(&kfe->v1->edges, kfe); @@ -490,6 +509,8 @@ static void knife_add_single_cut(KnifeTool_OpData *kcd) kfe->v1->inspace = kcd->prev.is_space; kfe->draw = !kcd->prev.is_space; kfe->v1->isface = 1; + if (kfe->v1->draw && kcd->prev.bmface) + knife_append_list(kcd, &kfe->v1->faces, kcd->prev.bmface); } if (kcd->cur.vert) { @@ -504,6 +525,8 @@ static void knife_add_single_cut(KnifeTool_OpData *kcd) kfe->v2->draw = !kcd->cur.is_space; kfe->v2->isface = 1; kfe->v2->inspace = kcd->cur.is_space; + if (kfe->v2->draw && kcd->cur.bmface) + knife_append_list(kcd, &kfe->v2->faces, kcd->cur.bmface); if (kcd->cur.is_space) kfe->draw = 0; @@ -511,7 +534,7 @@ static void knife_add_single_cut(KnifeTool_OpData *kcd) kcd->cur.vert = kfe->v2; } - knife_find_basef(kcd, kfe); + knife_find_basef(kfe); knife_add_to_vert_edges(kcd, kfe); @@ -716,6 +739,7 @@ static void knife_add_cut(KnifeTool_OpData *kcd) BMEdgeHit *lh, *lastlh, *firstlh; int i; + /* TODO: not a stable sort! need to figure out what to do for equal lambdas */ qsort(kcd->linehits, kcd->totlinehit, sizeof(BMEdgeHit), verge_linehit); lh = kcd->linehits; @@ -1074,7 +1098,7 @@ static BMEdgeHit *knife_edge_tri_isect(KnifeTool_OpData *kcd, BMBVHTree *bmtree, /* for comparing distances, error of intersection depends on triangle scale. * need to scale down before squaring for accurate comparison */ - const float depsilon = 50 * FLT_EPSILON * len_v3_tri_side_max(v1, v2, v3); + const float depsilon = 50 *FLT_EPSILON *len_v3_tri_side_max(v1, v2, v3); const float depsilon_squared = depsilon * depsilon; copy_v3_v3(cos + 0, v1); @@ -1153,7 +1177,7 @@ static BMEdgeHit *knife_edge_tri_isect(KnifeTool_OpData *kcd, BMBVHTree *bmtree, hit.kfe = kfe; hit.v = NULL; - knife_find_basef(kcd, kfe); + knife_find_basef(kfe); hit.f = kfe->basef; hit.perc = len_v3v3(p, kfe->v1->cageco) / len_v3v3(kfe->v1->cageco, kfe->v2->cageco); copy_v3_v3(hit.cagehit, p); @@ -2008,9 +2032,9 @@ static void knifenet_fill_faces(KnifeTool_OpData *kcd) remerge_faces(kcd); /* delete left over faces */ - BMO_op_callf(bm, "delete geom=%ff context=%i", DEL, DEL_ONLYFACES); - BMO_op_callf(bm, "delete geom=%fe context=%i", DEL, DEL_EDGES); - BMO_op_callf(bm, "delete geom=%fv context=%i", DEL, DEL_VERTS); + BMO_op_callf(bm, BMO_FLAG_DEFAULTS, "delete geom=%ff context=%i", DEL, DEL_ONLYFACES); + BMO_op_callf(bm, BMO_FLAG_DEFAULTS, "delete geom=%fe context=%i", DEL, DEL_EDGES); + BMO_op_callf(bm, BMO_FLAG_DEFAULTS, "delete geom=%fv context=%i", DEL, DEL_VERTS); if (face_nets) MEM_freeN(face_nets); @@ -2921,7 +2945,8 @@ wmKeyMap *knifetool_modal_keymap(wmKeyConfig *keyconf) {KNF_MODAL_CUT_THROUGH_TOGGLE, "CUT_THROUGH_TOGGLE", 0, "Toggle Cut Through", ""}, {KNF_MODAL_NEW_CUT, "NEW_CUT", 0, "End Current Cut", ""}, {KNF_MODAL_ADD_CUT, "ADD_CUT", 0, "Add Cut", ""}, - {0, NULL, 0, NULL, NULL}}; + {0, NULL, 0, NULL, NULL} + }; wmKeyMap *keymap = WM_modalkeymap_get(keyconf, "Knife Tool Modal Map"); diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c index d9f09c0bc65..34b281a1c1e 100644 --- a/source/blender/editors/mesh/editmesh_select.c +++ b/source/blender/editors/mesh/editmesh_select.c @@ -113,7 +113,9 @@ void EDBM_automerge(Scene *scene, Object *obedit, int update) if (!em) return; - BMO_op_callf(em->bm, "automerge verts=%hv dist=%f", BM_ELEM_SELECT, scene->toolsettings->doublimit); + BMO_op_callf(em->bm, BMO_FLAG_DEFAULTS, + "automerge verts=%hv dist=%f", + BM_ELEM_SELECT, scene->toolsettings->doublimit); if (update) { DAG_id_tag_update(obedit->data, OB_RECALC_DATA); BMEdit_RecalcTessellation(em); diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index 622e34a1366..82b218c966b 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -31,6 +31,7 @@ #include "MEM_guardedalloc.h" +#include "DNA_key_types.h" #include "DNA_material_types.h" #include "DNA_mesh_types.h" #include "DNA_modifier_types.h" @@ -255,7 +256,7 @@ static short edbm_extrude_edge(Object *obedit, BMEditMesh *em, const char hflag, ModifierData *md; BMElem *ele; - BMO_op_init(bm, &extop, "extrude_face_region"); + BMO_op_init(bm, &extop, BMO_FLAG_DEFAULTS, "extrude_face_region"); BMO_slot_buffer_from_enabled_hflag(bm, &extop, "edgefacein", BM_VERT | BM_EDGE | BM_FACE, hflag); /* If a mirror modifier with clipping is on, we need to adjust some @@ -395,8 +396,10 @@ static int edbm_extrude_repeat_exec(bContext *C, wmOperator *op) for (a = 0; a < steps; a++) { edbm_extrude_edge(obedit, em, BM_ELEM_SELECT, nor); - //BMO_op_callf(em->bm, "extrude_face_region edgefacein=%hef", BM_ELEM_SELECT); - BMO_op_callf(em->bm, "translate vec=%v verts=%hv", (float *)dvec, BM_ELEM_SELECT); + //BMO_op_callf(em->bm, BMO_FLAG_DEFAULTS, "extrude_face_region edgefacein=%hef", BM_ELEM_SELECT); + BMO_op_callf(em->bm, BMO_FLAG_DEFAULTS, + "translate vec=%v verts=%hv", + (float *)dvec, BM_ELEM_SELECT); //extrudeflag(obedit, em, SELECT, nor); //translateflag(em, SELECT, dvec); } @@ -1530,6 +1533,10 @@ static int edbm_do_smooth_vertex_exec(bContext *C, wmOperator *op) int i, repeat; float clipdist = 0.0f; + int xaxis = RNA_boolean_get(op->ptr, "xaxis"); + int yaxis = RNA_boolean_get(op->ptr, "yaxis"); + int zaxis = RNA_boolean_get(op->ptr, "zaxis"); + /* mirror before smooth */ if (((Mesh *)obedit->data)->editflag & ME_EDIT_MIRROR_X) { EDBM_verts_mirror_cache_begin(em, TRUE); @@ -1561,8 +1568,9 @@ static int edbm_do_smooth_vertex_exec(bContext *C, wmOperator *op) for (i = 0; i < repeat; i++) { if (!EDBM_op_callf(em, op, - "smooth_vert verts=%hv mirror_clip_x=%b mirror_clip_y=%b mirror_clip_z=%b clipdist=%f", - BM_ELEM_SELECT, mirrx, mirry, mirrz, clipdist)) + "smooth_vert verts=%hv mirror_clip_x=%b mirror_clip_y=%b mirror_clip_z=%b clipdist=%f " + "use_axis_x=%b use_axis_y=%b use_axis_z=%b", + BM_ELEM_SELECT, mirrx, mirry, mirrz, clipdist, xaxis, yaxis, zaxis)) { return OPERATOR_CANCELLED; } @@ -1594,6 +1602,9 @@ void MESH_OT_vertices_smooth(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; RNA_def_int(ot->srna, "repeat", 1, 1, 100, "Number of times to smooth the mesh", "", 1, INT_MAX); + RNA_def_boolean(ot->srna, "xaxis", 1, "X-Axis", "Smooth along the X axis"); + RNA_def_boolean(ot->srna, "yaxis", 1, "Y-Axis", "Smooth along the Y axis"); + RNA_def_boolean(ot->srna, "zaxis", 1, "Z-Axis", "Smooth along the Z axis"); } /********************** Smooth/Solid Operators *************************/ @@ -2229,6 +2240,8 @@ static int edbm_blend_from_shape_exec(bContext *C, wmOperator *op) { Object *obedit = CTX_data_edit_object(C); Mesh *me = obedit->data; + Key *key = me->key; + KeyBlock *kb = NULL; BMEditMesh *em = me->edit_btmesh; BMVert *eve; BMIter iter; @@ -2242,24 +2255,34 @@ static int edbm_blend_from_shape_exec(bContext *C, wmOperator *op) totshape = CustomData_number_of_layers(&em->bm->vdata, CD_SHAPEKEY); if (totshape == 0 || shape < 0 || shape >= totshape) return OPERATOR_CANCELLED; - + + /* get shape key - needed for finding reference shape (for add mode only) */ + if (key) { + kb = BLI_findlink(&key->block, shape); + } + + /* perform blending on selected vertices*/ BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { if (!BM_elem_flag_test(eve, BM_ELEM_SELECT) || BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) continue; - + + /* get coordinates of shapekey we're blending from */ sco = CustomData_bmesh_get_n(&em->bm->vdata, eve->head.data, CD_SHAPEKEY, shape); copy_v3_v3(co, sco); - - + if (add) { - mul_v3_fl(co, blend); - add_v3_v3v3(eve->co, eve->co, co); + /* in add mode, we add relative shape key offset */ + if (kb) { + float *rco = CustomData_bmesh_get_n(&em->bm->vdata, eve->head.data, CD_SHAPEKEY, kb->relative); + sub_v3_v3v3(co, co, rco); + } + + madd_v3_v3fl(eve->co, co, blend); } else { + /* in blend mode, we interpolate to the shape key */ interp_v3_v3v3(eve->co, eve->co, co, blend); } - - copy_v3_v3(sco, co); } EDBM_update_generic(C, em, TRUE); @@ -2601,21 +2624,21 @@ static float bm_edge_seg_isect(BMEdge *e, CutCurve *c, int len, char mode, m1 = MAXSLOPE; b1 = x12; } - x2max = MAX2(x21, x22) + 0.001f; /* prevent missed edges */ - x2min = MIN2(x21, x22) - 0.001f; /* due to round off error */ - y2max = MAX2(y21, y22) + 0.001f; - y2min = MIN2(y21, y22) - 0.001f; + x2max = maxf(x21, x22) + 0.001f; /* prevent missed edges */ + x2min = minf(x21, x22) - 0.001f; /* due to round off error */ + y2max = maxf(y21, y22) + 0.001f; + y2min = minf(y21, y22) - 0.001f; /* Found an intersect, calc intersect point */ if (m1 == m2) { /* co-incident lines */ /* cut at 50% of overlap area */ - x1max = MAX2(x11, x12); - x1min = MIN2(x11, x12); - xi = (MIN2(x2max, x1max) + MAX2(x2min, x1min)) / 2.0f; + x1max = maxf(x11, x12); + x1min = minf(x11, x12); + xi = (minf(x2max, x1max) + maxf(x2min, x1min)) / 2.0f; - y1max = MAX2(y11, y12); - y1min = MIN2(y11, y12); - yi = (MIN2(y2max, y1max) + MAX2(y2min, y1min)) / 2.0f; + y1max = maxf(y11, y12); + y1min = minf(y11, y12); + yi = (minf(y2max, y1max) + maxf(y2min, y1min)) / 2.0f; } else if (m2 == MAXSLOPE) { xi = x22; @@ -2816,26 +2839,21 @@ static int mesh_separate_tagged(Main *bmain, Scene *scene, Base *base_old, BMesh ED_base_object_select(base_new, BA_SELECT); - BMO_op_callf(bm_old, "duplicate geom=%hvef dest=%p", BM_ELEM_TAG, bm_new); - BMO_op_callf(bm_old, "delete geom=%hvef context=%i", BM_ELEM_TAG, DEL_FACES); + BMO_op_callf(bm_old, (BMO_FLAG_DEFAULTS & ~BMO_FLAG_RESPECT_HIDE), + "duplicate geom=%hvef dest=%p", BM_ELEM_TAG, bm_new); + BMO_op_callf(bm_old, (BMO_FLAG_DEFAULTS & ~BMO_FLAG_RESPECT_HIDE), + "delete geom=%hvef context=%i", BM_ELEM_TAG, DEL_FACES); - /* clean up any loose edges */ + /* deselect loose data - this used to get deleted */ BM_ITER_MESH (e, &iter, bm_old, BM_EDGES_OF_MESH) { - if (!BM_edge_is_wire(e)) { - BM_elem_flag_disable(e, BM_ELEM_TAG); - } + BM_edge_select_set(bm_old, e, FALSE); } - BMO_op_callf(bm_old, "delete geom=%hvef context=%i", BM_ELEM_TAG, DEL_EDGES); /* clean up any loose verts */ BM_ITER_MESH (v, &iter, bm_old, BM_VERTS_OF_MESH) { - if (BM_vert_edge_count(v) != 0) { - BM_elem_flag_disable(v, BM_ELEM_TAG); - } + BM_vert_select_set(bm_old, v, FALSE); } - BMO_op_callf(bm_old, "delete geom=%hvef context=%i", BM_ELEM_TAG, DEL_VERTS); - BM_mesh_normals_update(bm_new, FALSE); BM_mesh_bm_to_me(bm_new, base_new->object->data, FALSE); @@ -2959,13 +2977,13 @@ static int mesh_separate_loose(Main *bmain, Scene *scene, Base *base_old, BMesh } /* Select the seed explicitly, in case it has no edges */ - BM_elem_flag_enable(v_seed, BM_ELEM_TAG); + if (!BM_elem_flag_test(v_seed, BM_ELEM_TAG)) { BM_elem_flag_enable(v_seed, BM_ELEM_TAG); tot++; } /* Walk from the single vertex, selecting everything connected * to it */ BMW_init(&walker, bm_old, BMW_SHELL, BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP, - BMW_FLAG_NOP, /* BMESH_TODO - should be BMW_FLAG_TEST_HIDDEN ? */ + BMW_FLAG_NOP, BMW_NIL_LAY); e = BMW_begin(&walker, v_seed); @@ -3769,13 +3787,13 @@ static int bmelemsort_comp(const void *v1, const void *v2) } /* Reorders vertices/edges/faces using a given methods. Loops are not supported. */ -static void sort_bmelem_flag(bContext *C, const int types, const int flag, const int action, +static void sort_bmelem_flag(Scene *scene, Object *ob, + View3D *v3d, RegionView3D *rv3d, + const int types, const int flag, const int action, const int reverse, const unsigned int seed) { - Scene *scene = CTX_data_scene(C); - Object *ob = CTX_data_edit_object(C); - ViewContext vc; - BMEditMesh *em; + BMEditMesh *em = BMEdit_FromObject(ob); + BMVert *ve; BMEdge *ed; BMFace *fa; @@ -3793,9 +3811,6 @@ static void sort_bmelem_flag(bContext *C, const int types, const int flag, const if (!(types && flag && action)) return; - em_setup_viewcontext(C, &vc); - em = vc.em; - if (types & BM_VERT) totelem[0] = em->bm->totvert; if (types & BM_EDGE) @@ -3804,7 +3819,6 @@ static void sort_bmelem_flag(bContext *C, const int types, const int flag, const totelem[2] = em->bm->totface; if (ELEM(action, SRT_VIEW_ZAXIS, SRT_VIEW_XAXIS)) { - RegionView3D *rv3d = ED_view3d_context_rv3d(C); float mat[4][4]; float fact = reverse ? -1.0 : 1.0; int coidx = (action == SRT_VIEW_ZAXIS) ? 2 : 0; @@ -3872,7 +3886,6 @@ static void sort_bmelem_flag(bContext *C, const int types, const int flag, const } else if (action == SRT_CURSOR_DISTANCE) { - View3D *v3d = CTX_wm_view3d(C); float cur[3]; float mat[4][4]; float fact = reverse ? -1.0 : 1.0; @@ -4202,18 +4215,32 @@ static void sort_bmelem_flag(bContext *C, const int types, const int flag, const static int edbm_sort_elements_exec(bContext *C, wmOperator *op) { + Scene *scene = CTX_data_scene(C); + Object *ob = CTX_data_edit_object(C); + + /* may be NULL */ + View3D *v3d = CTX_wm_view3d(C); + RegionView3D *rv3d = ED_view3d_context_rv3d(C); + int action = RNA_enum_get(op->ptr, "type"); PropertyRNA *prop_elem_types = RNA_struct_find_property(op->ptr, "elements"); - int elem_types = 0; int reverse = RNA_boolean_get(op->ptr, "reverse"); unsigned int seed = RNA_int_get(op->ptr, "seed"); + int elem_types = 0; + + if (ELEM(action, SRT_VIEW_ZAXIS, SRT_VIEW_XAXIS)) { + if (rv3d == NULL) { + BKE_report(op->reports, RPT_ERROR, "View not found, can't sort by view axis"); + return OPERATOR_CANCELLED; + } + } /* If no elem_types set, use current selection mode to set it! */ if (RNA_property_is_set(op->ptr, prop_elem_types)) { elem_types = RNA_property_enum_get(op->ptr, prop_elem_types); } else { - BMEditMesh *em = BMEdit_FromObject(CTX_data_edit_object(C)); + BMEditMesh *em = BMEdit_FromObject(ob); if (em->selectmode & SCE_SELECT_VERTEX) elem_types |= BM_VERT; if (em->selectmode & SCE_SELECT_EDGE) @@ -4223,7 +4250,8 @@ static int edbm_sort_elements_exec(bContext *C, wmOperator *op) RNA_enum_set(op->ptr, "elements", elem_types); } - sort_bmelem_flag(C, elem_types, BM_ELEM_SELECT, action, reverse, seed); + sort_bmelem_flag(scene, ob, v3d, rv3d, + elem_types, BM_ELEM_SELECT, action, reverse, seed); return OPERATOR_FINISHED; } @@ -4636,6 +4664,7 @@ static int edbm_bevel_modal(bContext *C, wmOperator *op, wmEvent *event) return OPERATOR_RUNNING_MODAL; } } + switch (event->type) { case ESCKEY: case RIGHTMOUSE: @@ -4668,7 +4697,7 @@ static int edbm_bevel_modal(bContext *C, wmOperator *op, wmEvent *event) edbm_bevel_calc(C, op); edbm_bevel_update_header(op, C); } - return OPERATOR_RUNNING_MODAL; + break; case LEFTMOUSE: case PADENTER: @@ -4685,7 +4714,7 @@ static int edbm_bevel_modal(bContext *C, wmOperator *op, wmEvent *event) edbm_bevel_calc(C, op); edbm_bevel_update_header(op, C); } - return OPERATOR_RUNNING_MODAL; + break; case DKEY: if (event->val == KM_PRESS) { @@ -4695,7 +4724,7 @@ static int edbm_bevel_modal(bContext *C, wmOperator *op, wmEvent *event) edbm_bevel_calc(C, op); edbm_bevel_update_header(op, C); } - return OPERATOR_RUNNING_MODAL; + break; } return OPERATOR_RUNNING_MODAL; @@ -4775,7 +4804,12 @@ static void edbm_inset_update_header(wmOperator *op, bContext *C) { InsetData *opdata = op->customdata; - static char str[] = "Confirm: Enter/LClick, Cancel: (Esc/RClick), thickness: %s, depth (Ctrl to tweak): %s (%s), Outset (O): (%s)"; + static const char str[] = "Confirm: Enter/LClick, " + "Cancel: (Esc/RClick), " + "thickness: %s, " + "depth (Ctrl to tweak): %s (%s), " + "Outset (O): (%s), " + "Boundary (B): (%s)"; char msg[HEADER_LENGTH]; ScrArea *sa = CTX_wm_area(C); @@ -4792,7 +4826,8 @@ static void edbm_inset_update_header(wmOperator *op, bContext *C) flts_str, flts_str + NUM_STR_REP_LEN, opdata->modify_depth ? "On" : "Off", - RNA_boolean_get(op->ptr, "use_outset") ? "On" : "Off" + RNA_boolean_get(op->ptr, "use_outset") ? "On" : "Off", + RNA_boolean_get(op->ptr, "use_boundary") ? "On" : "Off" ); ED_area_headerprint(sa, msg); @@ -4958,7 +4993,7 @@ static int edbm_inset_modal(bContext *C, wmOperator *op, wmEvent *event) if (handleNumInput(&opdata->num_input, event)) { applyNumInput(&opdata->num_input, amounts); - amounts[0] = MAX2(amounts[0], 0.0f); + amounts[0] = maxf(amounts[0], 0.0f); RNA_float_set(op->ptr, "thickness", amounts[0]); RNA_float_set(op->ptr, "depth", amounts[1]); @@ -4972,6 +5007,7 @@ static int edbm_inset_modal(bContext *C, wmOperator *op, wmEvent *event) } } } + switch (event->type) { case ESCKEY: case RIGHTMOUSE: @@ -4998,7 +5034,7 @@ static int edbm_inset_modal(bContext *C, wmOperator *op, wmEvent *event) if (opdata->modify_depth) RNA_float_set(op->ptr, "depth", amount); else { - amount = MAX2(amount, 0.0f); + amount = maxf(amount, 0.0f); RNA_float_set(op->ptr, "thickness", amount); } @@ -5009,7 +5045,7 @@ static int edbm_inset_modal(bContext *C, wmOperator *op, wmEvent *event) return OPERATOR_CANCELLED; } } - return OPERATOR_RUNNING_MODAL; + break; case LEFTMOUSE: case PADENTER: @@ -5031,7 +5067,7 @@ static int edbm_inset_modal(bContext *C, wmOperator *op, wmEvent *event) opdata->shift_amount = 0.0f; opdata->shift = FALSE; } - return OPERATOR_RUNNING_MODAL; + break; case LEFTCTRLKEY: case RIGHTCTRLKEY: @@ -5056,7 +5092,7 @@ static int edbm_inset_modal(bContext *C, wmOperator *op, wmEvent *event) opdata->initial_length = len_v2(mlen); edbm_inset_update_header(op, C); - return OPERATOR_RUNNING_MODAL; + break; } case OKEY: @@ -5065,13 +5101,26 @@ static int edbm_inset_modal(bContext *C, wmOperator *op, wmEvent *event) RNA_boolean_set(op->ptr, "use_outset", !use_outset); if (edbm_inset_calc(C, op)) { edbm_inset_update_header(op, C); - return OPERATOR_RUNNING_MODAL; } else { edbm_inset_cancel(C, op); return OPERATOR_CANCELLED; } } + break; + case BKEY: + if (event->val == KM_PRESS) { + int use_boundary = RNA_boolean_get(op->ptr, "use_boundary"); + RNA_boolean_set(op->ptr, "use_boundary", !use_boundary); + if (edbm_inset_calc(C, op)) { + edbm_inset_update_header(op, C); + } + else { + edbm_inset_cancel(C, op); + return OPERATOR_CANCELLED; + } + } + break; } return OPERATOR_RUNNING_MODAL; @@ -5136,7 +5185,9 @@ static int edbm_wireframe_exec(bContext *C, wmOperator *op) BM_mesh_elem_hflag_disable_all(em->bm, BM_FACE, BM_ELEM_TAG, FALSE); BMO_slot_buffer_hflag_enable(em->bm, &bmop, "faces", BM_FACE, BM_ELEM_TAG, FALSE); - BMO_op_callf(em->bm, "delete geom=%hvef context=%i", BM_ELEM_TAG, DEL_FACES); + BMO_op_callf(em->bm, BMO_FLAG_DEFAULTS, + "delete geom=%hvef context=%i", + BM_ELEM_TAG, DEL_FACES); } BM_mesh_elem_hflag_disable_all(em->bm, BM_VERT | BM_EDGE | BM_FACE, BM_ELEM_SELECT, FALSE); diff --git a/source/blender/editors/mesh/editmesh_utils.c b/source/blender/editors/mesh/editmesh_utils.c index 274789a7b96..6b7409cd031 100644 --- a/source/blender/editors/mesh/editmesh_utils.c +++ b/source/blender/editors/mesh/editmesh_utils.c @@ -166,7 +166,7 @@ int EDBM_op_init(BMEditMesh *em, BMOperator *bmop, wmOperator *op, const char *f va_start(list, fmt); - if (!BMO_op_vinitf(bm, bmop, fmt, list)) { + if (!BMO_op_vinitf(bm, bmop, BMO_FLAG_DEFAULTS, fmt, list)) { BKE_reportf(op->reports, RPT_ERROR, "Parse error in %s", __func__); va_end(list); return 0; @@ -235,7 +235,7 @@ int EDBM_op_callf(BMEditMesh *em, wmOperator *op, const char *fmt, ...) va_start(list, fmt); - if (!BMO_op_vinitf(bm, &bmop, fmt, list)) { + if (!BMO_op_vinitf(bm, &bmop, BMO_FLAG_DEFAULTS, fmt, list)) { BKE_reportf(op->reports, RPT_ERROR, "Parse error in %s", __func__); va_end(list); return 0; @@ -259,7 +259,7 @@ int EDBM_op_call_and_selectf(BMEditMesh *em, wmOperator *op, const char *selects va_start(list, fmt); - if (!BMO_op_vinitf(bm, &bmop, fmt, list)) { + if (!BMO_op_vinitf(bm, &bmop, BMO_FLAG_DEFAULTS, fmt, list)) { BKE_reportf(op->reports, RPT_ERROR, "Parse error in %s", __func__); va_end(list); return 0; @@ -287,7 +287,7 @@ int EDBM_op_call_silentf(BMEditMesh *em, const char *fmt, ...) va_start(list, fmt); - if (!BMO_op_vinitf(bm, &bmop, fmt, list)) { + if (!BMO_op_vinitf(bm, &bmop, BMO_FLAG_DEFAULTS, fmt, list)) { va_end(list); return 0; } @@ -482,7 +482,7 @@ void EDBM_select_more(BMEditMesh *em) BMOperator bmop; int use_faces = em->selectmode == SCE_SELECT_FACE; - BMO_op_initf(em->bm, &bmop, + BMO_op_initf(em->bm, &bmop, BMO_FLAG_DEFAULTS, "region_extend geom=%hvef constrict=%b use_faces=%b", BM_ELEM_SELECT, FALSE, use_faces); BMO_op_exec(em->bm, &bmop); @@ -498,7 +498,7 @@ void EDBM_select_less(BMEditMesh *em) BMOperator bmop; int use_faces = em->selectmode == SCE_SELECT_FACE; - BMO_op_initf(em->bm, &bmop, + BMO_op_initf(em->bm, &bmop, BMO_FLAG_DEFAULTS, "region_extend geom=%hvef constrict=%b use_faces=%b", BM_ELEM_SELECT, TRUE, use_faces); BMO_op_exec(em->bm, &bmop); diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index 044c23092bd..2e75a779fed 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -1030,13 +1030,13 @@ static float *editmesh_get_mirror_uv(BMEditMesh *em, int axis, float *uv, float BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { uv_poly_center(em, efa, cent); - if ( (fabs(cent[0] - cent_vec[0]) < 0.001) && (fabs(cent[1] - cent_vec[1]) < 0.001) ) { + if ( (fabsf(cent[0] - cent_vec[0]) < 0.001f) && (fabsf(cent[1] - cent_vec[1]) < 0.001f) ) { BMIter liter; BMLoop *l; BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { MLoopUV *luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); - if ( (fabs(luv->uv[0] - vec[0]) < 0.001) && (fabs(luv->uv[1] - vec[1]) < 0.001) ) { + if ( (fabsf(luv->uv[0] - vec[0]) < 0.001f) && (fabsf(luv->uv[1] - vec[1]) < 0.001f) ) { return luv->uv; } diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c index 3d9e62b1a16..81639d05d6a 100644 --- a/source/blender/editors/object/object_modifier.c +++ b/source/blender/editors/object/object_modifier.c @@ -212,10 +212,10 @@ int ED_object_iter_other(Main *bmain, Object *orig_ob, int include_orig, int totfound = include_orig ? 0 : 1; for (ob = bmain->object.first; ob && totfound < users; - ob = ob->id.next) + ob = ob->id.next) { if (((ob != orig_ob) || include_orig) && - (ob->data == orig_ob->data)) + (ob->data == orig_ob->data)) { if (callback(ob, callback_data)) return TRUE; @@ -233,7 +233,7 @@ int ED_object_iter_other(Main *bmain, Object *orig_ob, int include_orig, static int object_has_modifier_cb(Object *ob, void *data) { - ModifierType type = *((ModifierType*)data); + ModifierType type = *((ModifierType *)data); return object_has_modifier(ob, NULL, type); } @@ -244,7 +244,7 @@ static int object_has_modifier_cb(Object *ob, void *data) int ED_object_multires_update_totlevels_cb(Object *ob, void *totlevel_v) { ModifierData *md; - int totlevel = *((int*)totlevel_v); + int totlevel = *((int *)totlevel_v); for (md = ob->modifiers.first; md; md = md->next) { if (md->type == eModifierType_Multires) { @@ -1148,8 +1148,8 @@ static int multires_higher_levels_delete_exec(bContext *C, wmOperator *op) multiresModifier_del_levels(mmd, ob, 1); ED_object_iter_other(CTX_data_main(C), ob, TRUE, - ED_object_multires_update_totlevels_cb, - &mmd->totlvl); + ED_object_multires_update_totlevels_cb, + &mmd->totlvl); WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); @@ -1192,8 +1192,8 @@ static int multires_subdivide_exec(bContext *C, wmOperator *op) multiresModifier_subdivide(mmd, ob, 0, mmd->simple); ED_object_iter_other(CTX_data_main(C), ob, TRUE, - ED_object_multires_update_totlevels_cb, - &mmd->totlvl); + ED_object_multires_update_totlevels_cb, + &mmd->totlvl); DAG_id_tag_update(&ob->id, OB_RECALC_DATA); WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob); @@ -1518,8 +1518,8 @@ static void skin_root_clear(BMesh *bm, BMVert *bm_vert, GHash *visited) static int skin_root_mark_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob = CTX_data_edit_object(C); - Mesh *me = ob->data; - BMesh *bm = me->edit_btmesh->bm; + BMEditMesh *em = BMEdit_FromObject(ob); + BMesh *bm = em->bm; BMVert *bm_vert; BMIter bm_iter; GHash *visited; @@ -1574,12 +1574,16 @@ typedef enum { static int skin_loose_mark_clear_exec(bContext *C, wmOperator *op) { Object *ob = CTX_data_edit_object(C); - Mesh *me = ob->data; - BMesh *bm = me->edit_btmesh->bm; + BMEditMesh *em = BMEdit_FromObject(ob); + BMesh *bm = em->bm; BMVert *bm_vert; BMIter bm_iter; SkinLooseAction action = RNA_enum_get(op->ptr, "action"); + if (!CustomData_has_layer(&bm->vdata, CD_MVERT_SKIN)) { + return OPERATOR_CANCELLED; + } + BM_ITER_MESH (bm_vert, &bm_iter, bm, BM_VERTS_OF_MESH) { if (bm_vert->head.hflag & BM_ELEM_SELECT) { MVertSkin *vs = CustomData_bmesh_get(&bm->vdata, @@ -1628,11 +1632,15 @@ void OBJECT_OT_skin_loose_mark_clear(wmOperatorType *ot) static int skin_radii_equalize_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob = CTX_data_edit_object(C); - Mesh *me = ob->data; - BMesh *bm = me->edit_btmesh->bm; + BMEditMesh *em = BMEdit_FromObject(ob); + BMesh *bm = em->bm; BMVert *bm_vert; BMIter bm_iter; + if (!CustomData_has_layer(&bm->vdata, CD_MVERT_SKIN)) { + return OPERATOR_CANCELLED; + } + BM_ITER_MESH (bm_vert, &bm_iter, bm, BM_VERTS_OF_MESH) { if (bm_vert->head.hflag & BM_ELEM_SELECT) { MVertSkin *vs = CustomData_bmesh_get(&bm->vdata, @@ -1804,9 +1812,15 @@ static int skin_armature_create_exec(bContext *C, wmOperator *op) Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C), *arm_ob; + Mesh *me = ob->data; ModifierData *skin_md; ArmatureModifierData *arm_md; + if (!CustomData_has_layer(&me->vdata, CD_MVERT_SKIN)) { + BKE_reportf(op->reports, RPT_WARNING, "Mesh '%s' has no skin vertex data", me->id.name + 2); + return OPERATOR_CANCELLED; + } + /* create new armature */ arm_ob = modifier_skin_armature_create(scene, ob); diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c index d25e41898ea..28a8b4f3b2d 100644 --- a/source/blender/editors/object/object_relations.c +++ b/source/blender/editors/object/object_relations.c @@ -135,6 +135,9 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op) em = me->edit_btmesh; + EDBM_mesh_normals_update(em); + BMEdit_RecalcTessellation(em); + /* derivedMesh might be needed for solving parenting, * so re-create it here */ makeDerivedMesh(scene, obedit, em, CD_MASK_BAREMESH, 0); @@ -677,7 +680,7 @@ static int parent_set_exec(bContext *C, wmOperator *op) Scene *scene = CTX_data_scene(C); Object *par = ED_object_active_context(C); int partype = RNA_enum_get(op->ptr, "type"); - int xmirror = RNA_enum_get(op->ptr, "xmirror"); + int xmirror = RNA_boolean_get(op->ptr, "xmirror"); int ok = 1; CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) diff --git a/source/blender/editors/object/object_select.c b/source/blender/editors/object/object_select.c index 3d3f4ef1260..c83331a8eb7 100644 --- a/source/blender/editors/object/object_select.c +++ b/source/blender/editors/object/object_select.c @@ -186,36 +186,217 @@ void OBJECT_OT_select_by_type(wmOperatorType *ot) /*********************** Selection by Links *********************/ +enum { + OBJECT_SELECT_LINKED_IPO = 1, + OBJECT_SELECT_LINKED_OBDATA, + OBJECT_SELECT_LINKED_MATERIAL, + OBJECT_SELECT_LINKED_TEXTURE, + OBJECT_SELECT_LINKED_DUPGROUP, + OBJECT_SELECT_LINKED_PARTICLE, + OBJECT_SELECT_LINKED_LIBRARY, + OBJECT_SELECT_LINKED_LIBRARY_OBDATA +}; + static EnumPropertyItem prop_select_linked_types[] = { - //{1, "IPO", 0, "Object IPO", ""}, // XXX depreceated animation system stuff... - {2, "OBDATA", 0, "Object Data", ""}, - {3, "MATERIAL", 0, "Material", ""}, - {4, "TEXTURE", 0, "Texture", ""}, - {5, "DUPGROUP", 0, "Dupligroup", ""}, - {6, "PARTICLE", 0, "Particle System", ""}, - {7, "LIBRARY", 0, "Library", ""}, - {8, "LIBRARY_OBDATA", 0, "Library (Object Data)", ""}, + //{OBJECT_SELECT_LINKED_IPO, "IPO", 0, "Object IPO", ""}, // XXX depreceated animation system stuff... + {OBJECT_SELECT_LINKED_OBDATA, "OBDATA", 0, "Object Data", ""}, + {OBJECT_SELECT_LINKED_MATERIAL, "MATERIAL", 0, "Material", ""}, + {OBJECT_SELECT_LINKED_TEXTURE, "TEXTURE", 0, "Texture", ""}, + {OBJECT_SELECT_LINKED_DUPGROUP, "DUPGROUP", 0, "Dupligroup", ""}, + {OBJECT_SELECT_LINKED_PARTICLE, "PARTICLE", 0, "Particle System", ""}, + {OBJECT_SELECT_LINKED_LIBRARY, "LIBRARY", 0, "Library", ""}, + {OBJECT_SELECT_LINKED_LIBRARY_OBDATA, "LIBRARY_OBDATA", 0, "Library (Object Data)", ""}, {0, NULL, 0, NULL, NULL} }; +// XXX old animation system +#if 0 +static int object_select_all_by_ipo(bContext *C, Ipo *ipo) +{ + int changed = FALSE; + + CTX_DATA_BEGIN (C, Base *, base, visible_bases) + { + if (base->object->ipo == ipo) { + base->flag |= SELECT; + base->object->flag = base->flag; + + changed = TRUE; + } + } + CTX_DATA_END; + + return changed; +} +#endif + +static int object_select_all_by_obdata(bContext *C, void *obdata) +{ + int changed = FALSE; + + CTX_DATA_BEGIN (C, Base *, base, visible_bases) + { + if (base->object->data == obdata) { + base->flag |= SELECT; + base->object->flag = base->flag; + + changed = TRUE; + } + } + CTX_DATA_END; + + return changed; +} + +static int object_select_all_by_material_texture(bContext *C, int use_texture, Material *mat, Tex *tex) +{ + int changed = FALSE; + + CTX_DATA_BEGIN (C, Base *, base, visible_bases) + { + Object *ob = base->object; + Material *mat1; + int a, b; + + for (a = 1; a <= ob->totcol; a++) { + mat1 = give_current_material(ob, a); + + if (!use_texture) { + if (mat1 == mat) { + base->flag |= SELECT; + changed = TRUE; + } + } + else if (mat1 && use_texture) { + for (b = 0; b < MAX_MTEX; b++) { + if (mat1->mtex[b]) { + if (tex == mat1->mtex[b]->tex) { + base->flag |= SELECT; + changed = TRUE; + break; + } + } + } + } + } + + base->object->flag = base->flag; + } + CTX_DATA_END; + + return changed; +} + +static int object_select_all_by_dup_group(bContext *C, Group *dup_group) +{ + int changed = FALSE; + + CTX_DATA_BEGIN (C, Base *, base, visible_bases) + { + if (base->object->dup_group == dup_group) { + base->flag |= SELECT; + base->object->flag = base->flag; + + changed = TRUE; + } + } + CTX_DATA_END; + + return changed; +} + +static int object_select_all_by_particle(bContext *C, Object *ob) +{ + int changed = FALSE; + + CTX_DATA_BEGIN (C, Base *, base, visible_bases) + { + /* loop through other, then actives particles*/ + ParticleSystem *psys; + ParticleSystem *psys_act; + + for (psys = base->object->particlesystem.first; psys; psys = psys->next) { + for (psys_act = ob->particlesystem.first; psys_act; psys_act = psys_act->next) { + if (psys->part == psys_act->part) { + base->flag |= SELECT; + changed = TRUE; + break; + } + } + + if (base->flag & SELECT) { + break; + } + } + + base->object->flag = base->flag; + } + CTX_DATA_END; + + return changed; +} + +static int object_select_all_by_library(bContext *C, Library *lib) +{ + int changed = FALSE; + + CTX_DATA_BEGIN (C, Base *, base, visible_bases) + { + if (lib == base->object->id.lib) { + base->flag |= SELECT; + base->object->flag = base->flag; + + changed = TRUE; + } + } + CTX_DATA_END; + + return changed; +} + +static int object_select_all_by_library_obdata(bContext *C, Library *lib) +{ + int changed = FALSE; + + CTX_DATA_BEGIN (C, Base *, base, visible_bases) + { + if (base->object->data && lib == ((ID *)base->object->data)->lib) { + base->flag |= SELECT; + base->object->flag = base->flag; + + changed = TRUE; + } + } + CTX_DATA_END; + + return changed; +} + +void ED_object_select_linked_by_id(bContext *C, ID *id) +{ + int gs = GS(id->name); + int changed = FALSE; + + if (ELEM8(gs, ID_ME, ID_CU, ID_MB, ID_LT, ID_LA, ID_CA, ID_TXT, ID_SPK)) { + changed = object_select_all_by_obdata(C, id); + } + else if (gs == ID_MA) { + changed = object_select_all_by_material_texture(C, FALSE, (Material *)id, NULL); + } + else if (gs == ID_LI) { + changed = object_select_all_by_library(C, (Library *) id); + } + + if (changed) + WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, CTX_data_scene(C)); +} + static int object_select_linked_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); Object *ob; - void *obdata = NULL; - Material *mat = NULL, *mat1; - Tex *tex = NULL; - int a, b; int nr = RNA_enum_get(op->ptr, "type"); - short changed = 0, extend; - /* events (nr): - * Object Ipo: 1 - * ObData: 2 - * Current Material: 3 - * Current Texture: 4 - * DupliGroup: 5 - * PSys: 6 - */ + short changed = FALSE, extend; extend = RNA_boolean_get(op->ptr, "extend"); @@ -233,113 +414,59 @@ static int object_select_linked_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - if (nr == 1) { + if (nr == OBJECT_SELECT_LINKED_IPO) { // XXX old animation system - //ipo= ob->ipo; - //if (ipo==0) return OPERATOR_CANCELLED; + //if (ob->ipo==0) return OPERATOR_CANCELLED; + //object_select_all_by_ipo(C, ob->ipo) return OPERATOR_CANCELLED; } - else if (nr == 2) { - if (ob->data == NULL) return OPERATOR_CANCELLED; - obdata = ob->data; + else if (nr == OBJECT_SELECT_LINKED_OBDATA) { + if (ob->data == 0) + return OPERATOR_CANCELLED; + + changed = object_select_all_by_obdata(C, ob->data); } - else if (nr == 3 || nr == 4) { + else if (nr == OBJECT_SELECT_LINKED_MATERIAL || nr == OBJECT_SELECT_LINKED_TEXTURE) { + Material *mat = NULL; + Tex *tex = NULL; + int use_texture = FALSE; + mat = give_current_material(ob, ob->actcol); if (mat == NULL) return OPERATOR_CANCELLED; - if (nr == 4) { + if (nr == OBJECT_SELECT_LINKED_TEXTURE) { + use_texture = TRUE; + if (mat->mtex[(int)mat->texact]) tex = mat->mtex[(int)mat->texact]->tex; if (tex == NULL) return OPERATOR_CANCELLED; } + + changed = object_select_all_by_material_texture(C, use_texture, mat, tex); } - else if (nr == 5) { - if (ob->dup_group == NULL) return OPERATOR_CANCELLED; + else if (nr == OBJECT_SELECT_LINKED_DUPGROUP) { + if (ob->dup_group == NULL) + return OPERATOR_CANCELLED; + + changed = object_select_all_by_dup_group(C, ob->dup_group); } - else if (nr == 6) { - if (ob->particlesystem.first == NULL) return OPERATOR_CANCELLED; + else if (nr == OBJECT_SELECT_LINKED_PARTICLE) { + if (ob->particlesystem.first == NULL) + return OPERATOR_CANCELLED; + + changed = object_select_all_by_particle(C, ob); } - else if (nr == 7) { + else if (nr == OBJECT_SELECT_LINKED_LIBRARY) { /* do nothing */ + changed = object_select_all_by_library(C, ob->id.lib); } - else if (nr == 8) { - if (ob->data == NULL) return OPERATOR_CANCELLED; + else if (nr == OBJECT_SELECT_LINKED_LIBRARY_OBDATA) { + if (ob->data == NULL) + return OPERATOR_CANCELLED; + + changed = object_select_all_by_library_obdata(C, ((ID *) ob->data)->lib); } else return OPERATOR_CANCELLED; - - CTX_DATA_BEGIN (C, Base *, base, visible_bases) - { - if (nr == 1) { - // XXX old animation system - //if (base->object->ipo == ipo) base->flag |= SELECT; - //changed = 1; - } - else if (nr == 2) { - if (base->object->data == obdata) base->flag |= SELECT; - changed = 1; - } - else if (nr == 3 || nr == 4) { - ob = base->object; - - for (a = 1; a <= ob->totcol; a++) { - mat1 = give_current_material(ob, a); - if (nr == 3) { - if (mat1 == mat) base->flag |= SELECT; - changed = 1; - } - else if (mat1 && nr == 4) { - for (b = 0; b < MAX_MTEX; b++) { - if (mat1->mtex[b]) { - if (tex == mat1->mtex[b]->tex) { - base->flag |= SELECT; - changed = 1; - break; - } - } - } - } - } - } - else if (nr == 5) { - if (base->object->dup_group == ob->dup_group) { - base->flag |= SELECT; - changed = 1; - } - } - else if (nr == 6) { - /* loop through other, then actives particles*/ - ParticleSystem *psys; - ParticleSystem *psys_act; - - for (psys = base->object->particlesystem.first; psys; psys = psys->next) { - for (psys_act = ob->particlesystem.first; psys_act; psys_act = psys_act->next) { - if (psys->part == psys_act->part) { - base->flag |= SELECT; - changed = 1; - break; - } - } - - if (base->flag & SELECT) { - break; - } - } - } - else if (nr == 7) { - if (ob->id.lib == base->object->id.lib) { - base->flag |= SELECT; - changed = 1; - } - } - else if (nr == 8) { - if (base->object->data && ((ID *)ob->data)->lib == ((ID *)base->object->data)->lib) { - base->flag |= SELECT; - changed = 1; - } - } - base->object->flag = base->flag; - } - CTX_DATA_END; - + if (changed) { WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, CTX_data_scene(C)); return OPERATOR_FINISHED; @@ -989,5 +1116,3 @@ void OBJECT_OT_select_random(wmOperatorType *ot) RNA_def_float_percentage(ot->srna, "percent", 50.f, 0.0f, 100.0f, "Percent", "Percentage of objects to select randomly", 0.f, 100.0f); RNA_def_boolean(ot->srna, "extend", FALSE, "Extend Selection", "Extend selection instead of deselecting everything first"); } - - diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 2e9652686da..11e98c970a0 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -954,7 +954,7 @@ static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, in dist = dists[i]; } else { - if (fabs(dist - distToBe) < fabs(dists[i] - distToBe)) { + if (fabsf(dist - distToBe) < fabsf(dists[i] - distToBe)) { upDown[i] = 0; changes[i][0] = vc; changes[i][1] = hc; @@ -963,7 +963,7 @@ static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, in else { upDown[i] = 1; } - if (fabs(dists[i] - distToBe) > fabs(distToStart - distToBe)) { + if (fabsf(dists[i] - distToBe) > fabsf(distToStart - distToBe)) { changes[i][0] = 0; changes[i][1] = 0; dists[i] = distToStart; @@ -979,7 +979,7 @@ static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, in for (i = k + 1; i < totweight; i++) { dist = dists[i]; - if (fabs(dist) > fabs(dists[i])) { + if (fabsf(dist) > fabsf(dists[i])) { bestIndex = i; } } @@ -1009,7 +1009,7 @@ static void moveCloserToDistanceFromPlane(Scene *scene, Object *ob, Mesh *me, in bestIndex = -1; /* find the best change with an acceptable horizontal change */ for (i = 0; i < totweight; i++) { - if (fabs(changes[i][0]) > fabs(changes[i][1] * 2.0f)) { + if (fabsf(changes[i][0]) > fabsf(changes[i][1] * 2.0f)) { bestIndex = i; break; } diff --git a/source/blender/editors/physics/particle_boids.c b/source/blender/editors/physics/particle_boids.c index 23ce4776b73..aff66b272fe 100644 --- a/source/blender/editors/physics/particle_boids.c +++ b/source/blender/editors/physics/particle_boids.c @@ -56,23 +56,18 @@ /************************ add/del boid rule operators *********************/ static int rule_add_exec(bContext *C, wmOperator *op) { - PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); - ParticleSystem *psys= ptr.data; - Object *ob= ptr.id.data; - ParticleSettings *part; + PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_settings", &RNA_ParticleSettings); + ParticleSettings *part = ptr.data; int type= RNA_enum_get(op->ptr, "type"); BoidRule *rule; BoidState *state; - if (!psys || !psys->part || psys->part->phystype != PART_PHYS_BOIDS) + if (!part || part->phystype != PART_PHYS_BOIDS) return OPERATOR_CANCELLED; - part = psys->part; - state = boid_get_current_state(part->boids); - for (rule=state->rules.first; rule; rule=rule->next) rule->flag &= ~BOIDRULE_CURRENT; @@ -82,7 +77,6 @@ static int rule_add_exec(bContext *C, wmOperator *op) BLI_addtail(&state->rules, rule); DAG_id_tag_update(&part->id, OB_RECALC_DATA|PSYS_RECALC_RESET); - WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); return OPERATOR_FINISHED; } @@ -107,25 +101,22 @@ static int rule_del_exec(bContext *C, wmOperator *UNUSED(op)) { Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); - PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); - ParticleSystem *psys= ptr.data; - Object *ob = ptr.id.data; + PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_settings", &RNA_ParticleSettings); + ParticleSettings *part = ptr.data; BoidRule *rule; BoidState *state; - if (!psys || !psys->part || psys->part->phystype != PART_PHYS_BOIDS) + if (!part || part->phystype != PART_PHYS_BOIDS) return OPERATOR_CANCELLED; - state = boid_get_current_state(psys->part->boids); + state = boid_get_current_state(part->boids); - for (rule=state->rules.first; rule; rule=rule->next) { if (rule->flag & BOIDRULE_CURRENT) { BLI_remlink(&state->rules, rule); MEM_freeN(rule); break; } - } rule = state->rules.first; @@ -133,10 +124,8 @@ static int rule_del_exec(bContext *C, wmOperator *UNUSED(op)) rule->flag |= BOIDRULE_CURRENT; DAG_scene_sort(bmain, scene); - DAG_id_tag_update(&psys->part->id, OB_RECALC_DATA|PSYS_RECALC_RESET); + DAG_id_tag_update(&part->id, OB_RECALC_DATA|PSYS_RECALC_RESET); - WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); - return OPERATOR_FINISHED; } @@ -157,23 +146,21 @@ void BOID_OT_rule_del(wmOperatorType *ot) /************************ move up/down boid rule operators *********************/ static int rule_move_up_exec(bContext *C, wmOperator *UNUSED(op)) { - PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); - ParticleSystem *psys= ptr.data; - Object *ob = ptr.id.data; + PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_settings", &RNA_ParticleSettings); + ParticleSettings *part = ptr.data; BoidRule *rule; BoidState *state; - if (!psys || !psys->part || psys->part->phystype != PART_PHYS_BOIDS) + if (!part || part->phystype != PART_PHYS_BOIDS) return OPERATOR_CANCELLED; - state = boid_get_current_state(psys->part->boids); + state = boid_get_current_state(part->boids); for (rule = state->rules.first; rule; rule=rule->next) { if (rule->flag & BOIDRULE_CURRENT && rule->prev) { BLI_remlink(&state->rules, rule); BLI_insertlink(&state->rules, rule->prev->prev, rule); - DAG_id_tag_update(&psys->part->id, OB_RECALC_DATA|PSYS_RECALC_RESET); - WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + DAG_id_tag_update(&part->id, OB_RECALC_DATA|PSYS_RECALC_RESET); break; } } @@ -195,23 +182,21 @@ void BOID_OT_rule_move_up(wmOperatorType *ot) static int rule_move_down_exec(bContext *C, wmOperator *UNUSED(op)) { - PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); - ParticleSystem *psys= ptr.data; - Object *ob = ptr.id.data; + PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_settings", &RNA_ParticleSettings); + ParticleSettings *part = ptr.data; BoidRule *rule; BoidState *state; - if (!psys || !psys->part || psys->part->phystype != PART_PHYS_BOIDS) + if (!part || part->phystype != PART_PHYS_BOIDS) return OPERATOR_CANCELLED; - state = boid_get_current_state(psys->part->boids); + state = boid_get_current_state(part->boids); for (rule = state->rules.first; rule; rule=rule->next) { if (rule->flag & BOIDRULE_CURRENT && rule->next) { BLI_remlink(&state->rules, rule); BLI_insertlink(&state->rules, rule->next, rule); - DAG_id_tag_update(&psys->part->id, OB_RECALC_DATA|PSYS_RECALC_RESET); - WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + DAG_id_tag_update(&part->id, OB_RECALC_DATA|PSYS_RECALC_RESET); break; } } @@ -235,17 +220,13 @@ void BOID_OT_rule_move_down(wmOperatorType *ot) /************************ add/del boid state operators *********************/ static int state_add_exec(bContext *C, wmOperator *UNUSED(op)) { - PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); - ParticleSystem *psys= ptr.data; - Object *ob= ptr.id.data; - ParticleSettings *part; + PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_settings", &RNA_ParticleSettings); + ParticleSettings *part = ptr.data; BoidState *state; - if (!psys || !psys->part || psys->part->phystype != PART_PHYS_BOIDS) + if (!part || part->phystype != PART_PHYS_BOIDS) return OPERATOR_CANCELLED; - part = psys->part; - for (state=part->boids->states.first; state; state=state->next) state->flag &= ~BOIDSTATE_CURRENT; @@ -254,8 +235,6 @@ static int state_add_exec(bContext *C, wmOperator *UNUSED(op)) BLI_addtail(&part->boids->states, state); - WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); - return OPERATOR_FINISHED; } @@ -276,24 +255,19 @@ static int state_del_exec(bContext *C, wmOperator *UNUSED(op)) { Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); - PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); - ParticleSystem *psys= ptr.data; - Object *ob = ptr.id.data; - ParticleSettings *part; + PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_settings", &RNA_ParticleSettings); + ParticleSettings *part = ptr.data; BoidState *state; - if (!psys || !psys->part || psys->part->phystype != PART_PHYS_BOIDS) + if (!part || part->phystype != PART_PHYS_BOIDS) return OPERATOR_CANCELLED; - part = psys->part; - for (state=part->boids->states.first; state; state=state->next) { if (state->flag & BOIDSTATE_CURRENT) { BLI_remlink(&part->boids->states, state); MEM_freeN(state); break; } - } /* there must be at least one state */ @@ -307,9 +281,7 @@ static int state_del_exec(bContext *C, wmOperator *UNUSED(op)) state->flag |= BOIDSTATE_CURRENT; DAG_scene_sort(bmain, scene); - DAG_id_tag_update(&psys->part->id, OB_RECALC_DATA|PSYS_RECALC_RESET); - - WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + DAG_id_tag_update(&part->id, OB_RECALC_DATA|PSYS_RECALC_RESET); return OPERATOR_FINISHED; } @@ -331,22 +303,20 @@ void BOID_OT_state_del(wmOperatorType *ot) /************************ move up/down boid state operators *********************/ static int state_move_up_exec(bContext *C, wmOperator *UNUSED(op)) { - PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); - ParticleSystem *psys= ptr.data; - Object *ob = ptr.id.data; + PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_settings", &RNA_ParticleSettings); + ParticleSettings *part = ptr.data; BoidSettings *boids; BoidState *state; - if (!psys || !psys->part || psys->part->phystype != PART_PHYS_BOIDS) + if (!part || part->phystype != PART_PHYS_BOIDS) return OPERATOR_CANCELLED; - boids = psys->part->boids; + boids = part->boids; for (state = boids->states.first; state; state=state->next) { if (state->flag & BOIDSTATE_CURRENT && state->prev) { BLI_remlink(&boids->states, state); BLI_insertlink(&boids->states, state->prev->prev, state); - WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); break; } } @@ -368,21 +338,21 @@ void BOID_OT_state_move_up(wmOperatorType *ot) static int state_move_down_exec(bContext *C, wmOperator *UNUSED(op)) { - PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); - ParticleSystem *psys= ptr.data; + PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_settings", &RNA_ParticleSettings); + ParticleSettings *part = ptr.data; BoidSettings *boids; BoidState *state; - if (!psys || !psys->part || psys->part->phystype != PART_PHYS_BOIDS) + if (!part || part->phystype != PART_PHYS_BOIDS) return OPERATOR_CANCELLED; - boids = psys->part->boids; + boids = part->boids; for (state = boids->states.first; state; state=state->next) { if (state->flag & BOIDSTATE_CURRENT && state->next) { BLI_remlink(&boids->states, state); BLI_insertlink(&boids->states, state->next, state); - DAG_id_tag_update(&psys->part->id, OB_RECALC_DATA|PSYS_RECALC_RESET); + DAG_id_tag_update(&part->id, OB_RECALC_DATA|PSYS_RECALC_RESET); break; } } diff --git a/source/blender/editors/render/render_internal.c b/source/blender/editors/render/render_internal.c index 8fa3c6f992f..b1776894959 100644 --- a/source/blender/editors/render/render_internal.c +++ b/source/blender/editors/render/render_internal.c @@ -452,10 +452,12 @@ static void render_drawlock(void *UNUSED(rjv), int lock) } /* catch esc */ -static int screen_render_modal(bContext *C, wmOperator *UNUSED(op), wmEvent *event) +static int screen_render_modal(bContext *C, wmOperator *op, wmEvent *event) { + Scene *scene = (Scene *) op->customdata; + /* no running blender, remove handler and pass through */ - if (0 == WM_jobs_test(CTX_wm_manager(C), CTX_data_scene(C))) { + if (0 == WM_jobs_test(CTX_wm_manager(C), scene)) { return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH; } @@ -584,6 +586,12 @@ static int screen_render_invoke(bContext *C, wmOperator *op, wmEvent *event) rj->re = re; G.afbreek = 0; + /* store actual owner of job, so modal operator could check for it, + * the reason of this is that active scene could change when rendering + * several layers from composistor [#31800] + */ + op->customdata = scene; + WM_jobs_start(CTX_wm_manager(C), steve); WM_cursor_wait(0); diff --git a/source/blender/editors/render/render_opengl.c b/source/blender/editors/render/render_opengl.c index 538b4b3884a..12f1e09f5be 100644 --- a/source/blender/editors/render/render_opengl.c +++ b/source/blender/editors/render/render_opengl.c @@ -476,6 +476,7 @@ static int screen_opengl_render_anim_step(bContext *C, wmOperator *op) int ok = 0; const short view_context = (oglrender->v3d != NULL); Object *camera = NULL; + int is_movie; /* go to next frame */ if (CFRA < oglrender->nfra) @@ -490,6 +491,21 @@ static int screen_opengl_render_anim_step(bContext *C, wmOperator *op) CFRA++; } + is_movie = BKE_imtype_is_movie(scene->r.im_format.imtype); + + if (!is_movie) { + BKE_makepicstring(name, scene->r.pic, oglrender->bmain->name, scene->r.cfra, scene->r.im_format.imtype, scene->r.scemode & R_EXTENSION, TRUE); + + if ((scene->r.mode & R_NO_OVERWRITE) && BLI_exists(name)) { + printf("skipping existing frame \"%s\"\n", name); + + /* go to next frame */ + oglrender->nfra += scene->r.frame_step; + + return 1; + } + } + /* update animated image textures for gpu, etc, * call before BKE_scene_update_for_newframe so modifiers with textures don't lag 1 frame */ ED_image_update_frame(bmain, CFRA); @@ -538,7 +554,7 @@ static int screen_opengl_render_anim_step(bContext *C, wmOperator *op) ibuf = ibuf_cpy; } - if (BKE_imtype_is_movie(scene->r.im_format.imtype)) { + if (is_movie) { ok = oglrender->mh->append_movie(&scene->r, SFRA, CFRA, (int *)ibuf->rect, oglrender->sizex, oglrender->sizey, oglrender->reports); if (ok) { @@ -547,7 +563,6 @@ static int screen_opengl_render_anim_step(bContext *C, wmOperator *op) } } else { - BKE_makepicstring(name, scene->r.pic, oglrender->bmain->name, scene->r.cfra, scene->r.im_format.imtype, scene->r.scemode & R_EXTENSION, TRUE); ok = BKE_imbuf_write_stamp(scene, camera, ibuf, name, &scene->r.im_format); if (ok == 0) { diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c index 0f1ffb856e7..5296c8615ab 100644 --- a/source/blender/editors/screen/glutil.c +++ b/source/blender/editors/screen/glutil.c @@ -624,8 +624,8 @@ void glaDrawPixelsSafe(float x, float y, int img_w, int img_h, int row_w, int fo * covers the entire screen). */ glGetFloatv(GL_SCISSOR_BOX, scissor); - draw_w = MIN2(img_w - off_x, ceil((scissor[2] - rast_x) / xzoom)); - draw_h = MIN2(img_h - off_y, ceil((scissor[3] - rast_y) / yzoom)); + draw_w = mini(img_w - off_x, ceil((scissor[2] - rast_x) / xzoom)); + draw_h = mini(img_h - off_y, ceil((scissor[3] - rast_y) / yzoom)); if (draw_w > 0 && draw_h > 0) { int old_row_length = glaGetOneInteger(GL_UNPACK_ROW_LENGTH); diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index 2391d6c909e..36353c43cbd 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -65,15 +65,16 @@ #include "WM_api.h" #include "WM_types.h" -#include "ED_util.h" -#include "ED_image.h" -#include "ED_screen.h" -#include "ED_object.h" #include "ED_armature.h" -#include "ED_screen_types.h" -#include "ED_keyframes_draw.h" -#include "ED_view3d.h" #include "ED_clip.h" +#include "ED_image.h" +#include "ED_keyframes_draw.h" +#include "ED_object.h" +#include "ED_screen.h" +#include "ED_screen_types.h" +#include "ED_sequencer.h" +#include "ED_util.h" +#include "ED_view3d.h" #include "RNA_access.h" #include "RNA_define.h" @@ -458,9 +459,30 @@ int ED_operator_editmball(bContext *C) int ED_operator_mask(bContext *C) { - SpaceClip *sc = CTX_wm_space_clip(C); + ScrArea *sa = CTX_wm_area(C); + if (sa && sa->spacedata.first) { + switch (sa->spacetype) { + case SPACE_CLIP: + { + SpaceClip *sc = sa->spacedata.first; + return ED_space_clip_check_show_maskedit(sc); + } + case SPACE_SEQ: + { + SpaceSeq *sseq = sa->spacedata.first; + Scene *scene = CTX_data_scene(C); + return ED_space_sequencer_check_show_maskedit(sseq, scene); + } + case SPACE_IMAGE: + { + SpaceImage *sima = sa->spacedata.first; + Scene *scene = CTX_data_scene(C); + return ED_space_image_check_show_maskedit(scene, sima); + } + } + } - return ED_space_clip_check_show_maskedit(sc); + return FALSE; } /* *************************** action zone operator ************************** */ @@ -1949,12 +1971,10 @@ static int keyframe_jump_exec(bContext *C, wmOperator *op) ob_to_keylist(&ads, ob, &keys, NULL); { - SpaceClip *sc = CTX_wm_space_clip(C); - if (sc) { - if ((sc->mode == SC_MODE_MASKEDIT) && sc->mask) { - MaskLayer *masklay = BKE_mask_layer_active(sc->mask); - mask_to_keylist(&ads, masklay, &keys); - } + Mask *mask = CTX_data_edit_mask(C); + if (mask) { + MaskLayer *masklay = BKE_mask_layer_active(mask); + mask_to_keylist(&ads, masklay, &keys); } } diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index 073e60ca87c..306724de301 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -4667,8 +4667,9 @@ static int image_paint_poll(bContext *C) if (sima) { ARegion *ar = CTX_wm_region(C); - if ((sima->flag & SI_DRAWTOOL) && ar->regiontype == RGN_TYPE_WINDOW) + if ((sima->mode == SI_MODE_PAINT) && ar->regiontype == RGN_TYPE_WINDOW) { return 1; + } } } @@ -5200,7 +5201,7 @@ int get_imapaint_zoom(bContext *C, float *zoomx, float *zoomy) SpaceImage *sima = CTX_wm_space_image(C); ARegion *ar = CTX_wm_region(C); - ED_space_image_zoom(sima, ar, zoomx, zoomy); + ED_space_image_get_zoom(sima, ar, zoomx, zoomy); return 1; } @@ -5235,7 +5236,7 @@ static void brush_drawcursor(bContext *C, int x, int y, void *UNUSED(customdata) !(ts->use_uv_sculpt && (scene->basact->object->mode == OB_MODE_EDIT)); if (use_zoom) { - pixel_size = MAX2(size * zoomx, size * zoomy); + pixel_size = size * maxf(zoomx, zoomy); } else { pixel_size = size; @@ -5311,7 +5312,7 @@ void ED_space_image_uv_sculpt_update(wmWindowManager *wm, ToolSettings *settings settings->uv_relax_method = UV_SCULPT_TOOL_RELAX_LAPLACIAN; } - paint_init(&settings->uvsculpt->paint, PAINT_CURSOR_SCULPT); + BKE_paint_init(&settings->uvsculpt->paint, PAINT_CURSOR_SCULPT); WM_paint_cursor_activate(wm, uv_sculpt_brush_poll, brush_drawcursor, NULL); @@ -5601,7 +5602,7 @@ static int texture_paint_toggle_exec(bContext *C, wmOperator *op) me->mtface = CustomData_add_layer(&me->fdata, CD_MTFACE, CD_DEFAULT, NULL, me->totface); - paint_init(&scene->toolsettings->imapaint.paint, PAINT_CURSOR_TEXTURE_PAINT); + BKE_paint_init(&scene->toolsettings->imapaint.paint, PAINT_CURSOR_TEXTURE_PAINT); if (U.glreslimit != 0) GPU_free_images(); diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c index 3c8f39a44b1..3f9e0051d2e 100644 --- a/source/blender/editors/sculpt_paint/paint_utils.c +++ b/source/blender/editors/sculpt_paint/paint_utils.c @@ -287,7 +287,7 @@ void imapaint_pick_uv(Scene *scene, Object *ob, unsigned int faceindex, const in /* the triangle with the largest absolute values is the one * with the most negative weights */ imapaint_tri_weights(ob, mv[0].co, mv[1].co, mv[3].co, p, w); - absw = fabs(w[0]) + fabs(w[1]) + fabs(w[2]); + absw = fabsf(w[0]) + fabsf(w[1]) + fabsf(w[2]); if (absw < minabsw) { uv[0] = tf->uv[0][0] * w[0] + tf->uv[1][0] * w[1] + tf->uv[3][0] * w[2]; uv[1] = tf->uv[0][1] * w[0] + tf->uv[1][1] * w[1] + tf->uv[3][1] * w[2]; @@ -295,7 +295,7 @@ void imapaint_pick_uv(Scene *scene, Object *ob, unsigned int faceindex, const in } imapaint_tri_weights(ob, mv[1].co, mv[2].co, mv[3].co, p, w); - absw = fabs(w[0]) + fabs(w[1]) + fabs(w[2]); + absw = fabsf(w[0]) + fabsf(w[1]) + fabsf(w[2]); if (absw < minabsw) { uv[0] = tf->uv[1][0] * w[0] + tf->uv[2][0] * w[1] + tf->uv[3][0] * w[2]; uv[1] = tf->uv[1][1] * w[0] + tf->uv[2][1] * w[1] + tf->uv[3][1] * w[2]; @@ -304,7 +304,7 @@ void imapaint_pick_uv(Scene *scene, Object *ob, unsigned int faceindex, const in } else { imapaint_tri_weights(ob, mv[0].co, mv[1].co, mv[2].co, p, w); - absw = fabs(w[0]) + fabs(w[1]) + fabs(w[2]); + absw = fabsf(w[0]) + fabsf(w[1]) + fabsf(w[2]); if (absw < minabsw) { uv[0] = tf->uv[0][0] * w[0] + tf->uv[1][0] * w[1] + tf->uv[2][0] * w[2]; uv[1] = tf->uv[0][1] * w[0] + tf->uv[1][1] * w[1] + tf->uv[2][1] * w[2]; diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 1b62ba8a7e0..3c389f97b34 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1997,7 +1997,7 @@ static int set_wpaint(bContext *C, wmOperator *UNUSED(op)) /* toggle */ if (wp == NULL) wp = scene->toolsettings->wpaint = new_vpaint(1); - paint_init(&wp->paint, PAINT_CURSOR_WEIGHT_PAINT); + BKE_paint_init(&wp->paint, PAINT_CURSOR_WEIGHT_PAINT); paint_cursor_start(C, weight_paint_poll); mesh_octree_table(ob, NULL, NULL, 's'); @@ -2574,7 +2574,7 @@ static int set_vpaint(bContext *C, wmOperator *op) /* toggle */ paint_cursor_start(C, vertex_paint_poll); - paint_init(&vp->paint, PAINT_CURSOR_VERTEX_PAINT); + BKE_paint_init(&vp->paint, PAINT_CURSOR_VERTEX_PAINT); } if (me) diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 35d508c5a1f..e2289bc9cfc 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -3064,12 +3064,19 @@ static void sculpt_update_tex(const Scene *scene, Sculpt *sd, SculptSession *ss) void sculpt_update_mesh_elements(Scene *scene, Sculpt *sd, Object *ob, int need_pmap) { - DerivedMesh *dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH); + DerivedMesh *dm; SculptSession *ss = ob->sculpt; + Mesh *me = ob->data; MultiresModifierData *mmd = sculpt_multires_active(scene, ob); ss->modifiers_active = sculpt_modifiers_active(scene, sd, ob); + /* BMESH ONLY --- at some point we should move sculpt code to use polygons only - but for now it needs tessfaces */ + BKE_mesh_tessface_ensure(me); + + /* needs to be called after we ensure tessface */ + dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH); + if (!mmd) ss->kb = ob_get_keyblock(ob); else ss->kb = NULL; @@ -3083,7 +3090,6 @@ void sculpt_update_mesh_elements(Scene *scene, Sculpt *sd, Object *ob, int need_ ss->face_normals = NULL; } else { - Mesh *me = BKE_mesh_from_object(ob); ss->totvert = me->totvert; ss->totpoly = me->totpoly; ss->mvert = me->mvert; @@ -3094,9 +3100,6 @@ void sculpt_update_mesh_elements(Scene *scene, Sculpt *sd, Object *ob, int need_ ss->vmask = CustomData_get_layer(&me->vdata, CD_PAINT_MASK); } - /* BMESH ONLY --- at some point we should move sculpt code to use polygons only - but for now it needs tessfaces */ - BKE_mesh_tessface_ensure(ob->data); - ss->pbvh = dm->getPBVH(ob, dm); ss->pmap = (need_pmap && dm->getPolyMap) ? dm->getPolyMap(ob, dm) : NULL; @@ -3106,14 +3109,14 @@ void sculpt_update_mesh_elements(Scene *scene, Sculpt *sd, Object *ob, int need_ free_sculptsession_deformMats(ss); - if (ss->kb) ss->orig_cos = key_to_vertcos(ob, ss->kb); - else ss->orig_cos = mesh_getVertexCos(ob->data, NULL); + ss->orig_cos = (ss->kb) ? key_to_vertcos(ob, ss->kb) : mesh_getVertexCos(me, NULL); crazyspace_build_sculpt(scene, ob, &ss->deform_imats, &ss->deform_cos); BLI_pbvh_apply_vertCos(ss->pbvh, ss->deform_cos); - for (a = 0; a < ((Mesh *)ob->data)->totvert; ++a) + for (a = 0; a < me->totvert; ++a) { invert_m3(ss->deform_imats[a]); + } } } else free_sculptsession_deformMats(ss); @@ -3254,9 +3257,9 @@ static void sculpt_omp_start(Sculpt *sd, SculptSession *ss) if (ss->multires) { int i, gridsize, array_mem_size; BLI_pbvh_node_get_grids(ss->pbvh, NULL, NULL, NULL, NULL, - &gridsize, NULL, NULL); + &gridsize, NULL, NULL); - array_mem_size = cache->num_threads * sizeof(void*); + array_mem_size = cache->num_threads * sizeof(void *); cache->tmpgrid_co = MEM_mallocN(array_mem_size, "tmpgrid_co array"); cache->tmprow_co = MEM_mallocN(array_mem_size, "tmprow_co array"); @@ -4194,7 +4197,7 @@ static int sculpt_toggle_mode(bContext *C, wmOperator *UNUSED(op)) if (flush_recalc) DAG_id_tag_update(&ob->id, OB_RECALC_DATA); - + /* Create persistent sculpt mode data */ if (!ts->sculpt) { ts->sculpt = MEM_callocN(sizeof(Sculpt), "sculpt mode data"); @@ -4212,7 +4215,7 @@ static int sculpt_toggle_mode(bContext *C, wmOperator *UNUSED(op)) /* Mask layer is required */ ED_sculpt_mask_layers_ensure(ob, mmd); - paint_init(&ts->sculpt->paint, PAINT_CURSOR_SCULPT); + BKE_paint_init(&ts->sculpt->paint, PAINT_CURSOR_SCULPT); paint_cursor_start(C, sculpt_poll); } diff --git a/source/blender/editors/sculpt_paint/sculpt_uv.c b/source/blender/editors/sculpt_paint/sculpt_uv.c index 95441600d77..fdce8ec04a4 100644 --- a/source/blender/editors/sculpt_paint/sculpt_uv.c +++ b/source/blender/editors/sculpt_paint/sculpt_uv.c @@ -315,8 +315,8 @@ static void uv_sculpt_stroke_apply(bContext *C, wmOperator *op, wmEvent *event, UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &co[0], &co[1]); sima = CTX_wm_space_image(C); - ED_space_image_size(sima, &width, &height); - ED_space_image_zoom(sima, ar, &zoomx, &zoomy); + ED_space_image_get_size(sima, &width, &height); + ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy); radius = BKE_brush_size_get(scene, brush) / (width * zoomx); aspectRatio = width / (float)height; @@ -683,8 +683,8 @@ static UvSculptData *uv_sculpt_stroke_init(bContext *C, wmOperator *op, wmEvent radius = BKE_brush_size_get(scene, brush); sima = CTX_wm_space_image(C); - ED_space_image_size(sima, &width, &height); - ED_space_image_zoom(sima, ar, &zoomx, &zoomy); + ED_space_image_get_size(sima, &width, &height); + ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy); aspectRatio = width / (float)height; radius /= (width * zoomx); diff --git a/source/blender/editors/space_action/space_action.c b/source/blender/editors/space_action/space_action.c index db1d4ed1155..1f641829e7e 100644 --- a/source/blender/editors/space_action/space_action.c +++ b/source/blender/editors/space_action/space_action.c @@ -129,8 +129,7 @@ static SpaceLink *action_new(const bContext *C) /* not spacelink itself */ static void action_free(SpaceLink *UNUSED(sl)) { -// SpaceAction *saction= (SpaceAction*) sl; - +// SpaceAction *saction= (SpaceAction *) sl; } diff --git a/source/blender/editors/space_buttons/buttons_context.c b/source/blender/editors/space_buttons/buttons_context.c index 6154a1cc5ce..c41d2521ee8 100644 --- a/source/blender/editors/space_buttons/buttons_context.c +++ b/source/blender/editors/space_buttons/buttons_context.c @@ -683,7 +683,7 @@ const char *buttons_context_dir[] = { "world", "object", "mesh", "armature", "lattice", "curve", "meta_ball", "lamp", "speaker", "camera", "material", "material_slot", "texture", "texture_slot", "texture_user", "bone", "edit_bone", - "pose_bone", "particle_system", "particle_system_editable", + "pose_bone", "particle_system", "particle_system_editable", "particle_settings", "cloth", "soft_body", "fluid", "smoke", "collision", "brush", "dynamic_paint", NULL }; @@ -890,6 +890,27 @@ int buttons_context(const bContext *C, const char *member, bContextDataResult *r CTX_data_pointer_set(result, NULL, &RNA_ParticleSystem, NULL); return 1; } + else if (CTX_data_equals(member, "particle_settings")) { + /* only available when pinned */ + PointerRNA *ptr = get_pointer_type(path, &RNA_ParticleSettings); + + if (ptr && ptr->data) { + CTX_data_pointer_set(result, ptr->id.data, &RNA_ParticleSettings, ptr->data); + return 1; + } + else { + /* get settings from active particle system instead */ + PointerRNA *ptr = get_pointer_type(path, &RNA_ParticleSystem); + + if (ptr && ptr->data) { + ParticleSettings *part = ((ParticleSystem *)ptr->data)->part; + CTX_data_pointer_set(result, ptr->id.data, &RNA_ParticleSettings, part); + return 1; + } + } + set_pointer_type(path, result, &RNA_ParticleSettings); + return 1; + } else if (CTX_data_equals(member, "cloth")) { PointerRNA *ptr = get_pointer_type(path, &RNA_Object); diff --git a/source/blender/editors/space_clip/clip_draw.c b/source/blender/editors/space_clip/clip_draw.c index 37da40e11b3..c24cdab29e5 100644 --- a/source/blender/editors/space_clip/clip_draw.c +++ b/source/blender/editors/space_clip/clip_draw.c @@ -53,6 +53,7 @@ #include "ED_screen.h" #include "ED_clip.h" +#include "ED_mask.h" #include "ED_gpencil.h" #include "BIF_gl.h" @@ -73,7 +74,7 @@ /*********************** main area drawing *************************/ -void clip_draw_curfra_label(SpaceClip *sc, float x, float y) +void clip_draw_curfra_label(const int framenr, const float x, const float y) { uiStyle *style = UI_GetStyle(); int fontid = style->widget.uifont_id; @@ -82,7 +83,7 @@ void clip_draw_curfra_label(SpaceClip *sc, float x, float y) /* frame number */ BLF_size(fontid, 11.0f, U.dpi); - BLI_snprintf(numstr, sizeof(numstr), "%d", sc->user.framenr); + BLI_snprintf(numstr, sizeof(numstr), "%d", framenr); BLF_width_and_height(fontid, numstr, &font_dims[0], &font_dims[1]); @@ -93,13 +94,30 @@ void clip_draw_curfra_label(SpaceClip *sc, float x, float y) BLF_draw(fontid, numstr, sizeof(numstr)); } +static void draw_keyframe(int frame, int cfra, int sfra, float framelen, int width) +{ + int height = (frame == cfra) ? 22 : 10; + int x = (frame - sfra) * framelen; + + if (width == 1) { + glBegin(GL_LINES); + glVertex2i(x, 0); + glVertex2i(x, height); + glEnd(); + } + else { + glRecti(x, 0, x + width, height); + } +} + static void draw_movieclip_cache(SpaceClip *sc, ARegion *ar, MovieClip *clip, Scene *scene) { float x; int *points, totseg, i, a; float sfra = SFRA, efra = EFRA, framelen = ar->winx / (efra - sfra + 1); + MovieTracking *tracking = &clip->tracking; MovieTrackingTrack *act_track = BKE_tracking_track_get_active(&clip->tracking); - MovieTrackingReconstruction *reconstruction = BKE_tracking_get_active_reconstruction(&clip->tracking); + MovieTrackingReconstruction *reconstruction = BKE_tracking_get_active_reconstruction(tracking); glEnable(GL_BLEND); @@ -195,32 +213,16 @@ static void draw_movieclip_cache(SpaceClip *sc, ARegion *ar, MovieClip *clip, Sc UI_ThemeColor(TH_CFRAME); glRecti(x, 0, x + framelen, 8); - clip_draw_curfra_label(sc, x, 8.0f); + clip_draw_curfra_label(sc->user.framenr, x, 8.0f); + + /* solver keyframes */ + glColor4ub(175, 255, 0, 255); + draw_keyframe(tracking->settings.keyframe1 + clip->start_frame - 1, CFRA, sfra, framelen, 2); + draw_keyframe(tracking->settings.keyframe2 + clip->start_frame - 1, CFRA, sfra, framelen, 2); /* movie clip animation */ - if ((sc->mode == SC_MODE_MASKEDIT) && sc->mask) { - MaskLayer *masklay = BKE_mask_layer_active(sc->mask); - if (masklay) { - MaskLayerShape *masklay_shape; - - glColor4ub(255, 175, 0, 255); - glBegin(GL_LINES); - - for (masklay_shape = masklay->splines_shapes.first; - masklay_shape; - masklay_shape = masklay_shape->next) - { - i = masklay_shape->frame; - - /* glRecti((i - sfra) * framelen, 0, (i - sfra + 1) * framelen, 4); */ - - /* use a line so we always see the keyframes */ - glVertex2i((i - sfra) * framelen, 0); - glVertex2i((i - sfra) * framelen, (i == CFRA) ? 22 : 10); - } - - glEnd(); - } + if ((sc->mode == SC_MODE_MASKEDIT) && sc->mask_info.mask) { + ED_mask_draw_frames(sc->mask_info.mask, ar, CFRA, sfra, efra); } } @@ -714,7 +716,7 @@ static float get_shortest_pattern_side(MovieTrackingMarker *marker) cur_len = len_v2v2(marker->pattern_corners[i], marker->pattern_corners[next]); - len = MIN2(cur_len, len); + len = minf(cur_len, len); } return len; @@ -786,11 +788,11 @@ static void draw_marker_slide_zones(SpaceClip *sc, MovieTrackingTrack *track, Mo dy = 6.0f / height / sc->zoom; side = get_shortest_pattern_side(marker); - patdx = MIN2(dx * 2.0f / 3.0f, side / 6.0f); - patdy = MIN2(dy * 2.0f / 3.0f, side * width / height / 6.0f); + patdx = minf(dx * 2.0f / 3.0f, side / 6.0f); + patdy = minf(dy * 2.0f / 3.0f, side * width / height / 6.0f); - searchdx = MIN2(dx, (marker->search_max[0] - marker->search_min[0]) / 6.0f); - searchdy = MIN2(dy, (marker->search_max[1] - marker->search_min[1]) / 6.0f); + searchdx = minf(dx, (marker->search_max[0] - marker->search_min[0]) / 6.0f); + searchdy = minf(dy, (marker->search_max[1] - marker->search_min[1]) / 6.0f); px[0] = 1.0f / sc->zoom / width / sc->scale; px[1] = 1.0f / sc->zoom / height / sc->scale; @@ -1408,17 +1410,16 @@ static void draw_distortion(SpaceClip *sc, ARegion *ar, MovieClip *clip, glPopMatrix(); } -void clip_draw_main(const bContext *C, ARegion *ar) +void clip_draw_main(const bContext *C, SpaceClip *sc, ARegion *ar) { - SpaceClip *sc = CTX_wm_space_clip(C); MovieClip *clip = ED_space_clip_get_clip(sc); Scene *scene = CTX_data_scene(C); ImBuf *ibuf; int width, height; float zoomx, zoomy; - ED_space_clip_get_size(C, &width, &height); - ED_space_clip_get_zoom(C, &zoomx, &zoomy); + ED_space_clip_get_size(sc, &width, &height); + ED_space_clip_get_zoom(sc, ar, &zoomx, &zoomy); /* if no clip, nothing to do */ if (!clip) { diff --git a/source/blender/editors/space_clip/clip_editor.c b/source/blender/editors/space_clip/clip_editor.c index 224a250fe4c..5e4ef1aa24a 100644 --- a/source/blender/editors/space_clip/clip_editor.c +++ b/source/blender/editors/space_clip/clip_editor.c @@ -115,7 +115,7 @@ int ED_space_clip_maskedit_mask_poll(bContext *C) if (clip) { SpaceClip *sc = CTX_wm_space_clip(C); - return sc->mask != NULL; + return sc->mask_info.mask != NULL; } } @@ -124,24 +124,29 @@ int ED_space_clip_maskedit_mask_poll(bContext *C) /* ******** common editing functions ******** */ -void ED_space_clip_get_size(const bContext *C, int *width, int *height) +void ED_space_clip_get_size(SpaceClip *sc, int *width, int *height) { - SpaceClip *sc = CTX_wm_space_clip(C); - - if (!sc->clip) { - *width = *height = 0; + if (sc->clip) { + BKE_movieclip_get_size(sc->clip, &sc->user, width, height); } else { - BKE_movieclip_get_size(sc->clip, &sc->user, width, height); + *width = *height = IMG_SIZE_FALLBACK; } } -void ED_space_clip_get_zoom(const bContext *C, float *zoomx, float *zoomy) +void ED_space_clip_get_size_fl(SpaceClip *sc, float size[2]) +{ + int size_i[2]; + ED_space_clip_get_size(sc, &size_i[0], &size_i[1]); + size[0] = size_i[0]; + size[1] = size_i[1]; +} + +void ED_space_clip_get_zoom(SpaceClip *sc, ARegion *ar, float *zoomx, float *zoomy) { - ARegion *ar = CTX_wm_region(C); int width, height; - ED_space_clip_get_size(C, &width, &height); + ED_space_clip_get_size(sc, &width, &height); *zoomx = (float)(ar->winrct.xmax - ar->winrct.xmin + 1) / (float)((ar->v2d.cur.xmax - ar->v2d.cur.xmin) * width); *zoomy = (float)(ar->winrct.ymax - ar->winrct.ymin + 1) / (float)((ar->v2d.cur.ymax - ar->v2d.cur.ymin) * height); @@ -265,9 +270,8 @@ void ED_clip_update_frame(const Main *mainp, int cfra) } } -static int selected_boundbox(const bContext *C, float min[2], float max[2]) +static int selected_boundbox(SpaceClip *sc, float min[2], float max[2]) { - SpaceClip *sc = CTX_wm_space_clip(C); MovieClip *clip = ED_space_clip_get_clip(sc); MovieTrackingTrack *track; int width, height, ok = FALSE; @@ -276,7 +280,7 @@ static int selected_boundbox(const bContext *C, float min[2], float max[2]) INIT_MINMAX2(min, max); - ED_space_clip_get_size(C, &width, &height); + ED_space_clip_get_size(sc, &width, &height); track = tracksbase->first; while (track) { @@ -319,17 +323,17 @@ int ED_clip_view_selection(const bContext *C, ARegion *ar, int fit) int w, h, frame_width, frame_height; float min[2], max[2]; - ED_space_clip_get_size(C, &frame_width, &frame_height); + ED_space_clip_get_size(sc, &frame_width, &frame_height); if (frame_width == 0 || frame_height == 0) return FALSE; - if (!selected_boundbox(C, min, max)) + if (!selected_boundbox(sc, min, max)) return FALSE; /* center view */ - clip_view_center_to_point(C, (max[0] + min[0]) / (2 * frame_width), - (max[1] + min[1]) / (2 * frame_height)); + clip_view_center_to_point(sc, (max[0] + min[0]) / (2 * frame_width), + (max[1] + min[1]) / (2 * frame_height)); w = max[0] - min[0]; h = max[1] - min[1]; @@ -347,7 +351,7 @@ int ED_clip_view_selection(const bContext *C, ARegion *ar, int fit) zoomx = (float)width / w / aspx; zoomy = (float)height / h / aspy; - newzoom = 1.0f / power_of_2(1.0f / MIN2(zoomx, zoomy)); + newzoom = 1.0f / power_of_2(1.0f / minf(zoomx, zoomy)); if (fit || sc->zoom > newzoom) sc->zoom = newzoom; @@ -377,15 +381,13 @@ void ED_clip_point_undistorted_pos(SpaceClip *sc, const float co[2], float r_co[ } } -void ED_clip_point_stable_pos(const bContext *C, float x, float y, float *xr, float *yr) +void ED_clip_point_stable_pos(SpaceClip *sc, ARegion *ar, float x, float y, float *xr, float *yr) { - ARegion *ar = CTX_wm_region(C); - SpaceClip *sc = CTX_wm_space_clip(C); int sx, sy, width, height; float zoomx, zoomy, pos[3], imat[4][4]; - ED_space_clip_get_zoom(C, &zoomx, &zoomy); - ED_space_clip_get_size(C, &width, &height); + ED_space_clip_get_zoom(sc, ar, &zoomx, &zoomy); + ED_space_clip_get_size(sc, &width, &height); UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &sx, &sy); @@ -416,18 +418,16 @@ void ED_clip_point_stable_pos(const bContext *C, float x, float y, float *xr, fl * \brief the reverse of ED_clip_point_stable_pos(), gets the marker region coords. * better name here? view_to_track / track_to_view or so? */ -void ED_clip_point_stable_pos__reverse(const bContext *C, const float co[2], float r_co[2]) +void ED_clip_point_stable_pos__reverse(SpaceClip *sc, ARegion *ar, const float co[2], float r_co[2]) { - SpaceClip *sc = CTX_wm_space_clip(C); - ARegion *ar = CTX_wm_region(C); float zoomx, zoomy; float pos[3]; int width, height; int sx, sy; UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &sx, &sy); - ED_space_clip_get_size(C, &width, &height); - ED_space_clip_get_zoom(C, &zoomx, &zoomy); + ED_space_clip_get_size(sc, &width, &height); + ED_space_clip_get_zoom(sc, ar, &zoomx, &zoomy); ED_clip_point_undistorted_pos(sc, co, pos); pos[2] = 0.0f; @@ -439,9 +439,10 @@ void ED_clip_point_stable_pos__reverse(const bContext *C, const float co[2], flo r_co[1] = (pos[1] * height * zoomy) + (float)sy; } -void ED_clip_mouse_pos(const bContext *C, wmEvent *event, float co[2]) +/* takes event->mval */ +void ED_clip_mouse_pos(SpaceClip *sc, ARegion *ar, const int mval[2], float co[2]) { - ED_clip_point_stable_pos(C, event->mval[0], event->mval[1], &co[0], &co[1]); + ED_clip_point_stable_pos(sc, ar, mval[0], mval[1], &co[0], &co[1]); } int ED_space_clip_check_show_trackedit(SpaceClip *sc) @@ -509,15 +510,15 @@ void ED_space_clip_set_clip(bContext *C, bScreen *screen, SpaceClip *sc, MovieCl Mask *ED_space_clip_get_mask(SpaceClip *sc) { - return sc->mask; + return sc->mask_info.mask; } void ED_space_clip_set_mask(bContext *C, SpaceClip *sc, Mask *mask) { - sc->mask = mask; + sc->mask_info.mask = mask; - if (sc->mask && sc->mask->id.us == 0) { - sc->clip->id.us = 1; + if (sc->mask_info.mask && sc->mask_info.mask->id.us == 0) { + sc->mask_info.mask->id.us = 1; } if (C) { diff --git a/source/blender/editors/space_clip/clip_graph_ops.c b/source/blender/editors/space_clip/clip_graph_ops.c index abf7f416b9c..c0b11dda5c7 100644 --- a/source/blender/editors/space_clip/clip_graph_ops.c +++ b/source/blender/editors/space_clip/clip_graph_ops.c @@ -345,6 +345,7 @@ static int border_select_graph_exec(bContext *C, wmOperator *op) { SpaceClip *sc = CTX_wm_space_clip(C); ARegion *ar = CTX_wm_region(C); + MovieClip *clip = ED_space_clip_get_clip(sc); MovieTracking *tracking = &clip->tracking; MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking); diff --git a/source/blender/editors/space_clip/clip_intern.h b/source/blender/editors/space_clip/clip_intern.h index c61a0baa82e..392367f9071 100644 --- a/source/blender/editors/space_clip/clip_intern.h +++ b/source/blender/editors/space_clip/clip_intern.h @@ -69,9 +69,9 @@ void clip_draw_dopesheet_channels(const struct bContext *C, struct ARegion *ar); void CLIP_OT_dopesheet_select_channel(struct wmOperatorType *ot); /* clip_draw.c */ -void clip_draw_main(const struct bContext *C, struct ARegion *ar); +void clip_draw_main(const struct bContext *C, struct SpaceClip *sc, struct ARegion *ar); void clip_draw_grease_pencil(struct bContext *C, int onlyv2d); -void clip_draw_curfra_label(struct SpaceClip *sc, float x, float y); +void clip_draw_curfra_label(const int framenr, const float x, const float y); /* clip_graph_draw.c */ void clip_draw_graph(struct SpaceClip *sc, struct ARegion *ar, struct Scene *scene); @@ -125,7 +125,7 @@ void clip_graph_tracking_iterate(struct SpaceClip *sc, int selected_only, int in void clip_delete_track(struct bContext *C, struct MovieClip *clip, struct ListBase *tracksbase, struct MovieTrackingTrack *track); void clip_delete_marker(struct bContext *C, struct MovieClip *clip, struct ListBase *tracksbase, struct MovieTrackingTrack *track, struct MovieTrackingMarker *marker); -void clip_view_center_to_point(const struct bContext *C, float x, float y); +void clip_view_center_to_point(SpaceClip *sc, float x, float y); void clip_draw_cfra(struct SpaceClip *sc, struct ARegion *ar, struct Scene *scene); void clip_draw_sfra_efra(struct View2D *v2d, struct Scene *scene); @@ -150,6 +150,8 @@ void CLIP_OT_hide_tracks(struct wmOperatorType *ot); void CLIP_OT_hide_tracks_clear(struct wmOperatorType *ot); void CLIP_OT_lock_tracks(struct wmOperatorType *ot); +void CLIP_OT_set_solver_keyframe(struct wmOperatorType *ot); + void CLIP_OT_set_origin(struct wmOperatorType *ot); void CLIP_OT_set_plane(struct wmOperatorType *ot); void CLIP_OT_set_axis(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_clip/clip_ops.c b/source/blender/editors/space_clip/clip_ops.c index 86d74ef4c78..20d47063cd4 100644 --- a/source/blender/editors/space_clip/clip_ops.c +++ b/source/blender/editors/space_clip/clip_ops.c @@ -74,6 +74,7 @@ static void sclip_zoom_set(const bContext *C, float zoom, float location[2]) { SpaceClip *sc = CTX_wm_space_clip(C); ARegion *ar = CTX_wm_region(C); + float oldzoom = sc->zoom; int width, height; @@ -81,7 +82,7 @@ static void sclip_zoom_set(const bContext *C, float zoom, float location[2]) if (sc->zoom < 0.1f || sc->zoom > 4.0f) { /* check zoom limits */ - ED_space_clip_get_size(C, &width, &height); + ED_space_clip_get_size(sc, &width, &height); width *= sc->zoom; height *= sc->zoom; @@ -95,7 +96,7 @@ static void sclip_zoom_set(const bContext *C, float zoom, float location[2]) } if ((U.uiflag & USER_ZOOM_TO_MOUSEPOS) && location) { - ED_space_clip_get_size(C, &width, &height); + ED_space_clip_get_size(sc, &width, &height); sc->xof += ((location[0] - 0.5f) * width - sc->xof) * (sc->zoom - oldzoom) / sc->zoom; sc->yof += ((location[1] - 0.5f) * height - sc->yof) * (sc->zoom - oldzoom) / sc->zoom; @@ -111,16 +112,20 @@ static void sclip_zoom_set_factor(const bContext *C, float zoomfac, float locati static void sclip_zoom_set_factor_exec(bContext *C, wmEvent *event, float factor) { + ARegion *ar = CTX_wm_region(C); + float location[2], *mpos = NULL; if (event) { - ED_clip_mouse_pos(C, event, location); + SpaceClip *sc = CTX_wm_space_clip(C); + + ED_clip_mouse_pos(sc, ar, event->mval, location); mpos = location; } sclip_zoom_set_factor(C, factor, mpos); - ED_region_tag_redraw(CTX_wm_region(C)); + ED_region_tag_redraw(ar); } /******************** open clip operator ********************/ @@ -466,6 +471,8 @@ typedef struct ViewZoomData { static void view_zoom_init(bContext *C, wmOperator *op, wmEvent *event) { SpaceClip *sc = CTX_wm_space_clip(C); + ARegion *ar = CTX_wm_region(C); + ViewZoomData *vpd; op->customdata = vpd = MEM_callocN(sizeof(ViewZoomData), "ClipViewZoomData"); @@ -476,7 +483,7 @@ static void view_zoom_init(bContext *C, wmOperator *op, wmEvent *event) vpd->zoom = sc->zoom; vpd->event_type = event->type; - ED_clip_mouse_pos(C, event, vpd->location); + ED_clip_mouse_pos(sc, ar, event->mval, vpd->location); WM_event_add_modal_handler(C, op); } @@ -593,9 +600,12 @@ static int view_zoom_in_exec(bContext *C, wmOperator *op) static int view_zoom_in_invoke(bContext *C, wmOperator *op, wmEvent *event) { + SpaceClip *sc = CTX_wm_space_clip(C); + ARegion *ar = CTX_wm_region(C); + float location[2]; - ED_clip_mouse_pos(C, event, location); + ED_clip_mouse_pos(sc, ar, event->mval, location); RNA_float_set_array(op->ptr, "location", location); return view_zoom_in_exec(C, op); @@ -633,9 +643,12 @@ static int view_zoom_out_exec(bContext *C, wmOperator *op) static int view_zoom_out_invoke(bContext *C, wmOperator *op, wmEvent *event) { + SpaceClip *sc = CTX_wm_space_clip(C); + ARegion *ar = CTX_wm_region(C); + float location[2]; - ED_clip_mouse_pos(C, event, location); + ED_clip_mouse_pos(sc, ar, event->mval, location); RNA_float_set_array(op->ptr, "location", location); return view_zoom_out_exec(C, op); @@ -706,7 +719,7 @@ static int view_all_exec(bContext *C, wmOperator *op) sc = CTX_wm_space_clip(C); ar = CTX_wm_region(C); - ED_space_clip_get_size(C, &w, &h); + ED_space_clip_get_size(sc, &w, &h); ED_space_clip_get_aspect(sc, &aspx, &aspy); w = w * aspx; @@ -722,7 +735,7 @@ static int view_all_exec(bContext *C, wmOperator *op) zoomx = (float) width / (w + 2 * margin); zoomy = (float) height / (h + 2 * margin); - sclip_zoom_set(C, MIN2(zoomx, zoomy), NULL); + sclip_zoom_set(C, minf(zoomx, zoomy), NULL); } else { if ((w >= width || h >= height) && (width > 0 && height > 0)) { @@ -730,7 +743,7 @@ static int view_all_exec(bContext *C, wmOperator *op) zoomy = (float) height / h; /* find the zoom value that will fit the image in the image space */ - sclip_zoom_set(C, 1.0f / power_of_2(1.0f / MIN2(zoomx, zoomy)), NULL); + sclip_zoom_set(C, 1.0f / power_of_2(1.0f / minf(zoomx, zoomy)), NULL); } else sclip_zoom_set(C, 1.0f, NULL); @@ -992,7 +1005,7 @@ static void proxy_startjob(void *pjv, short *stop, short *do_update, float *prog break; *do_update = TRUE; - *progress = ((float) cfra) / (efra - sfra); + *progress = ((float) cfra - sfra) / (efra - sfra); } if (distortion) diff --git a/source/blender/editors/space_clip/clip_toolbar.c b/source/blender/editors/space_clip/clip_toolbar.c index 3ffba75f2ef..d8c7bf3f809 100644 --- a/source/blender/editors/space_clip/clip_toolbar.c +++ b/source/blender/editors/space_clip/clip_toolbar.c @@ -224,7 +224,7 @@ static void clip_panel_operator_redo(const bContext *C, Panel *pa) if (op == NULL) return; - if (WM_operator_poll((bContext*)C, op->type) == 0) + if (WM_operator_poll((bContext *)C, op->type) == 0) return; block = uiLayoutGetBlock(pa->layout); diff --git a/source/blender/editors/space_clip/clip_utils.c b/source/blender/editors/space_clip/clip_utils.c index d9c9f63e4a3..ddc624b4cdf 100644 --- a/source/blender/editors/space_clip/clip_utils.c +++ b/source/blender/editors/space_clip/clip_utils.c @@ -223,13 +223,12 @@ void clip_delete_marker(bContext *C, MovieClip *clip, ListBase *tracksbase, } } -void clip_view_center_to_point(const bContext *C, float x, float y) +void clip_view_center_to_point(SpaceClip *sc, float x, float y) { - SpaceClip *sc = CTX_wm_space_clip(C); int width, height; float aspx, aspy; - ED_space_clip_get_size(C, &width, &height); + ED_space_clip_get_size(sc, &width, &height); ED_space_clip_get_aspect(sc, &aspx, &aspy); sc->xof = (x - 0.5f) * width * aspx; @@ -264,7 +263,7 @@ void clip_draw_cfra(SpaceClip *sc, ARegion *ar, Scene *scene) UI_view2d_getscale(v2d, &xscale, &yscale); glScalef(1.0f / xscale, 1.0f, 1.0f); - clip_draw_curfra_label(sc, (float)sc->user.framenr * xscale, 18); + clip_draw_curfra_label(sc->user.framenr, (float)sc->user.framenr * xscale, 18); /* restore view transform */ glScalef(xscale, 1.0, 1.0); diff --git a/source/blender/editors/space_clip/space_clip.c b/source/blender/editors/space_clip/space_clip.c index 3623cd1d58b..3428c47ff43 100644 --- a/source/blender/editors/space_clip/space_clip.c +++ b/source/blender/editors/space_clip/space_clip.c @@ -389,7 +389,6 @@ static void clip_listener(ScrArea *sa, wmNotifier *wmn) } switch (wmn->action) { case NA_SELECTED: - clip_scopes_tag_refresh(sa); ED_area_tag_redraw(sa); break; case NA_EDITED: @@ -478,6 +477,8 @@ static void clip_operatortypes(void) WM_operatortype_append(CLIP_OT_hide_tracks_clear); WM_operatortype_append(CLIP_OT_lock_tracks); + WM_operatortype_append(CLIP_OT_set_solver_keyframe); + /* orientation */ WM_operatortype_append(CLIP_OT_set_origin); WM_operatortype_append(CLIP_OT_set_plane); @@ -563,6 +564,12 @@ static void clip_keymap(struct wmKeyConfig *keyconf) WM_keymap_add_item(keymap, "CLIP_OT_solve_camera", SKEY, KM_PRESS, KM_SHIFT, 0); + kmi = WM_keymap_add_item(keymap, "CLIP_OT_set_solver_keyframe", QKEY, KM_PRESS, 0, 0); + RNA_enum_set(kmi->ptr, "keyframe", 0); + + kmi = WM_keymap_add_item(keymap, "CLIP_OT_set_solver_keyframe", EKEY, KM_PRESS, 0, 0); + RNA_enum_set(kmi->ptr, "keyframe", 1); + /* ******** Hotkeys avalaible for main region only ******** */ keymap = WM_keymap_find(keyconf, "Clip Editor", SPACE_CLIP, 0); @@ -766,8 +773,8 @@ static int clip_context(const bContext *C, const char *member, bContextDataResul return TRUE; } else if (CTX_data_equals(member, "edit_mask")) { - if (sc->mask) - CTX_data_id_pointer_set(result, &sc->mask->id); + if (sc->mask_info.mask) + CTX_data_id_pointer_set(result, &sc->mask_info.mask->id); return TRUE; } @@ -1017,7 +1024,7 @@ static void movieclip_main_area_set_view2d(const bContext *C, ARegion *ar) float x1, y1, w, h; int width, height, winx, winy; - ED_space_clip_get_size(C, &width, &height); + ED_space_clip_get_size(sc, &width, &height); w = width; h = height; @@ -1066,10 +1073,11 @@ static void clip_main_area_init(wmWindowManager *wm, ARegion *ar) UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy); - /* own keymap */ + /* mask polls mode */ keymap = WM_keymap_find(wm->defaultconf, "Mask Editing", 0, 0); WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + /* own keymap */ keymap = WM_keymap_find(wm->defaultconf, "Clip", SPACE_CLIP, 0); WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); @@ -1077,50 +1085,6 @@ static void clip_main_area_init(wmWindowManager *wm, ARegion *ar) WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); } -static void clip_main_area_draw_mask(const bContext *C, ARegion *ar) -{ - SpaceClip *sc = CTX_wm_space_clip(C); - int x, y; - int width, height; - float zoomx, zoomy; - - /* frame image */ - float maxdim; - float xofs, yofs; - - /* find window pixel coordinates of origin */ - UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &x, &y); - - ED_space_clip_get_size(C, &width, &height); - ED_space_clip_get_zoom(C, &zoomx, &zoomy); - - /* frame the image */ - maxdim = maxf(width, height); - if (width == height) { - xofs = yofs = 0; - } - else if (width < height) { - xofs = ((height - width) / -2.0f) * zoomx; - yofs = 0.0f; - } - else { /* (width > height) */ - xofs = 0.0f; - yofs = ((width - height) / -2.0f) * zoomy; - } - - /* apply transformation so mask editing tools will assume drawing from the origin in normalized space */ - glPushMatrix(); - glTranslatef(x + xofs, y + yofs, 0); - glScalef(maxdim * zoomx, maxdim * zoomy, 0); - glMultMatrixf(sc->stabmat); - - ED_mask_draw(C, sc->mask_draw_flag, sc->mask_draw_type); - - ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW); - - glPopMatrix(); -} - static void clip_main_area_draw(const bContext *C, ARegion *ar) { /* draw entirely, view changes should be handled here */ @@ -1155,10 +1119,23 @@ static void clip_main_area_draw(const bContext *C, ARegion *ar) /* data... */ movieclip_main_area_set_view2d(C, ar); - clip_draw_main(C, ar); + clip_draw_main(C, sc, ar); if (sc->mode == SC_MODE_MASKEDIT) { - clip_main_area_draw_mask(C, ar); + + Mask *mask = CTX_data_edit_mask(C); + if (mask) { + ScrArea *sa = CTX_wm_area(C); + int width, height; + ED_mask_get_size(sa, &width, &height); + ED_mask_draw_region(mask, ar, + sc->mask_info.draw_flag, sc->mask_info.draw_type, + width, height, + TRUE, TRUE, + sc->stabmat, C); + } + + } /* Grease Pencil */ diff --git a/source/blender/editors/space_clip/tracking_ops.c b/source/blender/editors/space_clip/tracking_ops.c index 2e4ba844646..153287eecdd 100644 --- a/source/blender/editors/space_clip/tracking_ops.c +++ b/source/blender/editors/space_clip/tracking_ops.c @@ -91,7 +91,7 @@ static void add_marker(const bContext *C, float x, float y) int width, height; int framenr = ED_space_clip_get_clip_frame_number(sc); - ED_space_clip_get_size(C, &width, &height); + ED_space_clip_get_size(sc, &width, &height); track = BKE_tracking_track_add(tracking, tracksbase, x, y, framenr, width, height); @@ -107,7 +107,7 @@ static int add_marker_exec(bContext *C, wmOperator *op) float pos[2]; int width, height; - ED_space_clip_get_size(C, &width, &height); + ED_space_clip_get_size(sc, &width, &height); if (!width || !height) return OPERATOR_CANCELLED; @@ -127,9 +127,12 @@ static int add_marker_exec(bContext *C, wmOperator *op) static int add_marker_invoke(bContext *C, wmOperator *op, wmEvent *event) { + SpaceClip *sc = CTX_wm_space_clip(C); + ARegion *ar = CTX_wm_region(C); + float co[2]; - ED_clip_mouse_pos(C, event, co); + ED_clip_mouse_pos(sc, ar, event->mval, co); RNA_float_set_array(op->ptr, "location", co); @@ -370,8 +373,8 @@ static int mouse_on_slide_zone(SpaceClip *sc, MovieTrackingMarker *marker, dx = size / width / sc->zoom; dy = size / height / sc->zoom; - dx = MIN2(dx, (max[0] - min[0]) / 6.0f); - dy = MIN2(dy, (max[1] - min[1]) / 6.0f); + dx = minf(dx, (max[0] - min[0]) / 6.0f); + dy = minf(dy, (max[1] - min[1]) / 6.0f); return IN_RANGE_INCL(co[0], slide_zone[0] - dx, slide_zone[0] + dx) && IN_RANGE_INCL(co[1], slide_zone[1] - dy, slide_zone[1] + dy); @@ -422,14 +425,14 @@ static int get_mouse_pattern_corner(SpaceClip *sc, MovieTrackingMarker *marker, cur_len = len_v2v2(marker->pattern_corners[i], marker->pattern_corners[next]); - len = MIN2(cur_len, len); + len = minf(cur_len, len); } dx = 12.0f / width / sc->zoom; dy = 12.0f / height / sc->zoom; - dx = MIN2(dx, len * 2.0f / 3.0f); - dy = MIN2(dy, len * width / height * 2.0f / 3.0f); + dx = minf(dx, len * 2.0f / 3.0f); + dy = minf(dy, len * width / height * 2.0f / 3.0f); for (i = 0; i < 4; i++) { float crn[2]; @@ -460,8 +463,8 @@ static int mouse_on_offset(SpaceClip *sc, MovieTrackingTrack *track, MovieTracki dx = 12.0f / width / sc->zoom; dy = 12.0f / height / sc->zoom; - dx = MIN2(dx, (pat_max[0] - pat_min[0]) / 2.0f); - dy = MIN2(dy, (pat_max[1] - pat_min[1]) / 2.0f); + dx = minf(dx, (pat_max[0] - pat_min[0]) / 2.0f); + dy = minf(dy, (pat_max[1] - pat_min[1]) / 2.0f); return co[0] >= pos[0] - dx && co[0] <= pos[0] + dx && co[1] >= pos[1] - dy && co[1] <= pos[1] + dy; } @@ -525,6 +528,8 @@ static void show_cursor(bContext *C) MovieTrackingTrack *tracking_marker_check_slide(bContext *C, wmEvent *event, int *area_r, int *action_r, int *corner_r) { SpaceClip *sc = CTX_wm_space_clip(C); + ARegion *ar = CTX_wm_region(C); + MovieClip *clip = ED_space_clip_get_clip(sc); MovieTrackingTrack *track; int width, height; @@ -533,12 +538,12 @@ MovieTrackingTrack *tracking_marker_check_slide(bContext *C, wmEvent *event, int int framenr = ED_space_clip_get_clip_frame_number(sc); int action = -1, area = 0, corner = -1; - ED_space_clip_get_size(C, &width, &height); + ED_space_clip_get_size(sc, &width, &height); if (width == 0 || height == 0) return NULL; - ED_clip_mouse_pos(C, event, co); + ED_clip_mouse_pos(sc, ar, event->mval, co); track = tracksbase->first; while (track) { @@ -622,6 +627,8 @@ MovieTrackingTrack *tracking_marker_check_slide(bContext *C, wmEvent *event, int static void *slide_marker_customdata(bContext *C, wmEvent *event) { SpaceClip *sc = CTX_wm_space_clip(C); + ARegion *ar = CTX_wm_region(C); + MovieTrackingTrack *track; int width, height; float co[2]; @@ -629,12 +636,12 @@ static void *slide_marker_customdata(bContext *C, wmEvent *event) int framenr = ED_space_clip_get_clip_frame_number(sc); int area, action, corner; - ED_space_clip_get_size(C, &width, &height); + ED_space_clip_get_size(sc, &width, &height); if (width == 0 || height == 0) return NULL; - ED_clip_mouse_pos(C, event, co); + ED_clip_mouse_pos(sc, ar, event->mval, co); track = tracking_marker_check_slide(C, event, &area, &action, &corner); if (track) { @@ -700,6 +707,8 @@ static void free_slide_data(SlideMarkerData *data) static int slide_marker_modal(bContext *C, wmOperator *op, wmEvent *event) { SpaceClip *sc = CTX_wm_space_clip(C); + ARegion *ar = CTX_wm_region(C); + SlideMarkerData *data = (SlideMarkerData *)op->customdata; float dx, dy, mdelta[2]; @@ -751,7 +760,7 @@ static int slide_marker_modal(bContext *C, wmOperator *op, wmEvent *event) float start[2], end[2]; float scale; - ED_clip_point_stable_pos(C, data->mval[0], data->mval[1], &start[0], &start[1]); + ED_clip_point_stable_pos(sc, ar, data->mval[0], data->mval[1], &start[0], &start[1]); sub_v2_v2(start, data->old_pos); @@ -767,7 +776,7 @@ static int slide_marker_modal(bContext *C, wmOperator *op, wmEvent *event) mval[1] = event->mval[1]; } - ED_clip_point_stable_pos(C, mval[0], mval[1], &end[0], &end[1]); + ED_clip_point_stable_pos(sc, ar, mval[0], mval[1], &end[0], &end[1]); sub_v2_v2(end, data->old_pos); @@ -825,7 +834,7 @@ static int slide_marker_modal(bContext *C, wmOperator *op, wmEvent *event) sub_v2_v2v2(start, data->spos, data->old_pos); - ED_clip_point_stable_pos(C, mval[0], mval[1], &end[0], &end[1]); + ED_clip_point_stable_pos(sc, ar, mval[0], mval[1], &end[0], &end[1]); sub_v2_v2(end, data->old_pos); if (len_v2(start) > 0.0f) { @@ -2842,6 +2851,51 @@ void CLIP_OT_lock_tracks(wmOperatorType *ot) RNA_def_enum(ot->srna, "action", actions_items, 0, "Action", "Lock action to execute"); } +/********************** set keyframe operator *********************/ + +static int set_solver_keyframe_exec(bContext *C, wmOperator *op) +{ + SpaceClip *sc = CTX_wm_space_clip(C); + MovieClip *clip = ED_space_clip_get_clip(sc); + MovieTracking *tracking = &clip->tracking; + MovieTrackingSettings *settings = &tracking->settings; + int keyframe = RNA_enum_get(op->ptr, "keyframe"); + int framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, sc->user.framenr); + + if (keyframe == 0) + settings->keyframe1 = framenr; + else + settings->keyframe2 = framenr; + + WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, clip); + + return OPERATOR_FINISHED; +} + +void CLIP_OT_set_solver_keyframe(wmOperatorType *ot) +{ + static EnumPropertyItem keyframe_items[] = { + {0, "KEYFRAME_A", 0, "Keyframe A", ""}, + {1, "KEYFRAME_B", 0, "Keyframe B", ""}, + {0, NULL, 0, NULL, NULL} + }; + + /* identifiers */ + ot->name = "Set Solver Keyframe"; + ot->description = "Set keyframe used by solver"; + ot->idname = "CLIP_OT_set_solver_keyframe"; + + /* api callbacks */ + ot->exec = set_solver_keyframe_exec; + ot->poll = ED_space_clip_tracking_poll; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + /* properties */ + RNA_def_enum(ot->srna, "keyframe", keyframe_items, 0, "Keyframe", "keyframe to set"); +} + /********************** track copy color operator *********************/ static int track_copy_color_exec(bContext *C, wmOperator *UNUSED(op)) diff --git a/source/blender/editors/space_clip/tracking_select.c b/source/blender/editors/space_clip/tracking_select.c index 0d933c1dff3..559fe8c840d 100644 --- a/source/blender/editors/space_clip/tracking_select.c +++ b/source/blender/editors/space_clip/tracking_select.c @@ -107,7 +107,7 @@ static int mouse_on_crns(float co[2], float pos[2], float crns[4][2], float epsx { float dist = dist_to_crns(co, pos, crns); - return dist < MAX2(epsx, epsy); + return dist < maxf(epsx, epsy); } static int track_mouse_area(const bContext *C, float co[2], MovieTrackingTrack *track) @@ -119,7 +119,7 @@ static int track_mouse_area(const bContext *C, float co[2], MovieTrackingTrack * float epsx, epsy; int width, height; - ED_space_clip_get_size(C, &width, &height); + ED_space_clip_get_size(sc, &width, &height); BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max); @@ -128,8 +128,8 @@ static int track_mouse_area(const bContext *C, float co[2], MovieTrackingTrack * epsy = MIN4(pat_min[1] - marker->search_min[1], marker->search_max[1] - pat_max[1], fabsf(pat_min[1]), fabsf(pat_max[1])) / 2; - epsx = MAX2(epsx, 2.0f / width); - epsy = MAX2(epsy, 2.0f / height); + epsx = maxf(epsx, 2.0f / width); + epsy = maxf(epsy, 2.0f / height); if (sc->flag & SC_SHOW_MARKER_SEARCH) { if (mouse_on_rect(co, marker->pos, marker->search_min, marker->search_max, epsx, epsy)) @@ -281,6 +281,9 @@ static int select_exec(bContext *C, wmOperator *op) static int select_invoke(bContext *C, wmOperator *op, wmEvent *event) { + SpaceClip *sc = CTX_wm_space_clip(C); + ARegion *ar = CTX_wm_region(C); + float co[2]; int extend = RNA_boolean_get(op->ptr, "extend"); @@ -299,7 +302,7 @@ static int select_invoke(bContext *C, wmOperator *op, wmEvent *event) } } - ED_clip_mouse_pos(C, event, co); + ED_clip_mouse_pos(sc, ar, event->mval, co); RNA_float_set_array(op->ptr, "location", co); return select_exec(C, op); @@ -333,6 +336,8 @@ void CLIP_OT_select(wmOperatorType *ot) static int border_select_exec(bContext *C, wmOperator *op) { SpaceClip *sc = CTX_wm_space_clip(C); + ARegion *ar = CTX_wm_region(C); + MovieClip *clip = ED_space_clip_get_clip(sc); MovieTracking *tracking = &clip->tracking; MovieTrackingTrack *track; @@ -348,8 +353,8 @@ static int border_select_exec(bContext *C, wmOperator *op) rect.xmax = RNA_int_get(op->ptr, "xmax"); rect.ymax = RNA_int_get(op->ptr, "ymax"); - ED_clip_point_stable_pos(C, rect.xmin, rect.ymin, &rectf.xmin, &rectf.ymin); - ED_clip_point_stable_pos(C, rect.xmax, rect.ymax, &rectf.xmax, &rectf.ymax); + ED_clip_point_stable_pos(sc, ar, rect.xmin, rect.ymin, &rectf.xmin, &rectf.ymin); + ED_clip_point_stable_pos(sc, ar, rect.xmax, rect.ymax, &rectf.xmax, &rectf.ymax); mode = RNA_int_get(op->ptr, "gesture_mode"); extend = RNA_boolean_get(op->ptr, "extend"); @@ -414,6 +419,8 @@ void CLIP_OT_select_border(wmOperatorType *ot) static int do_lasso_select_marker(bContext *C, int mcords[][2], short moves, short select) { SpaceClip *sc = CTX_wm_space_clip(C); + ARegion *ar = CTX_wm_region(C); + MovieClip *clip = ED_space_clip_get_clip(sc); MovieTracking *tracking = &clip->tracking; MovieTrackingTrack *track; @@ -435,7 +442,7 @@ static int do_lasso_select_marker(bContext *C, int mcords[][2], short moves, sho float screen_co[2]; /* marker in screen coords */ - ED_clip_point_stable_pos__reverse(C, marker->pos, screen_co); + ED_clip_point_stable_pos__reverse(sc, ar, marker->pos, screen_co); if (BLI_in_rcti(&rect, screen_co[0], screen_co[1]) && BLI_lasso_is_point_inside(mcords, moves, screen_co[0], screen_co[1], V2D_IS_CLIPPED)) @@ -519,6 +526,8 @@ static int marker_inside_ellipse(MovieTrackingMarker *marker, float offset[2], f static int circle_select_exec(bContext *C, wmOperator *op) { SpaceClip *sc = CTX_wm_space_clip(C); + ARegion *ar = CTX_wm_region(C); + MovieClip *clip = ED_space_clip_get_clip(sc); MovieTracking *tracking = &clip->tracking; MovieTrackingTrack *track; @@ -535,13 +544,13 @@ static int circle_select_exec(bContext *C, wmOperator *op) mode = RNA_int_get(op->ptr, "gesture_mode"); /* compute ellipse and position in unified coordinates */ - ED_space_clip_get_size(C, &width, &height); - ED_space_clip_get_zoom(C, &zoomx, &zoomy); + ED_space_clip_get_size(sc, &width, &height); + ED_space_clip_get_zoom(sc, ar, &zoomx, &zoomy); ellipse[0] = width * zoomx / radius; ellipse[1] = height * zoomy / radius; - ED_clip_point_stable_pos(C, x, y, &offset[0], &offset[1]); + ED_clip_point_stable_pos(sc, ar, x, y, &offset[0], &offset[1]); /* do selection */ track = tracksbase->first; diff --git a/source/blender/editors/space_console/console_draw.c b/source/blender/editors/space_console/console_draw.c index 2897c5d7d67..4c2f0ac73d4 100644 --- a/source/blender/editors/space_console/console_draw.c +++ b/source/blender/editors/space_console/console_draw.c @@ -191,7 +191,7 @@ static int console_textview_line_color(struct TextViewContext *tvc, unsigned cha } -static int console_textview_main__internal(struct SpaceConsole *sc, struct ARegion *ar, int draw, int mval[2], void **mouse_pick, int *pos_pick) +static int console_textview_main__internal(struct SpaceConsole *sc, ARegion *ar, int draw, int mval[2], void **mouse_pick, int *pos_pick) { ConsoleLine cl_dummy = {NULL}; int ret = 0; @@ -226,19 +226,19 @@ static int console_textview_main__internal(struct SpaceConsole *sc, struct ARegi } -void console_textview_main(struct SpaceConsole *sc, struct ARegion *ar) +void console_textview_main(struct SpaceConsole *sc, ARegion *ar) { int mval[2] = {INT_MAX, INT_MAX}; console_textview_main__internal(sc, ar, 1, mval, NULL, NULL); } -int console_textview_height(struct SpaceConsole *sc, struct ARegion *ar) +int console_textview_height(struct SpaceConsole *sc, ARegion *ar) { int mval[2] = {INT_MAX, INT_MAX}; return console_textview_main__internal(sc, ar, 0, mval, NULL, NULL); } -int console_char_pick(struct SpaceConsole *sc, struct ARegion *ar, int mval[2]) +int console_char_pick(struct SpaceConsole *sc, ARegion *ar, int mval[2]) { int pos_pick = 0; void *mouse_pick = NULL; diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 6856ce996e7..7630143acd1 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -70,7 +70,7 @@ #define INACTIVATE 2 /* ---------- FILE SELECTION ------------ */ -static FileSelection find_file_mouse_rect(SpaceFile *sfile, struct ARegion *ar, const rcti *rect) +static FileSelection find_file_mouse_rect(SpaceFile *sfile, ARegion *ar, const rcti *rect) { FileSelection sel; float fxmin, fymin, fxmax, fymax; @@ -1277,7 +1277,7 @@ void FILE_OT_hidedot(struct wmOperatorType *ot) ot->poll = ED_operator_file_active; /* <- important, handler is on window level */ } -struct ARegion *file_buttons_region(struct ScrArea *sa) +ARegion *file_buttons_region(ScrArea *sa) { ARegion *ar, *arnew; diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c index ef3e150b034..34f16c11537 100644 --- a/source/blender/editors/space_file/filesel.c +++ b/source/blender/editors/space_file/filesel.c @@ -265,7 +265,7 @@ void ED_fileselect_reset_params(SpaceFile *sfile) sfile->params->title[0] = '\0'; } -int ED_fileselect_layout_numfiles(FileLayout *layout, struct ARegion *ar) +int ED_fileselect_layout_numfiles(FileLayout *layout, ARegion *ar) { int numfiles; @@ -472,7 +472,7 @@ static void column_widths(struct FileList *files, struct FileLayout *layout) } } -void ED_fileselect_init_layout(struct SpaceFile *sfile, struct ARegion *ar) +void ED_fileselect_init_layout(struct SpaceFile *sfile, ARegion *ar) { FileSelectParams *params = ED_fileselect_get_params(sfile); FileLayout *layout = NULL; @@ -559,7 +559,7 @@ void ED_fileselect_init_layout(struct SpaceFile *sfile, struct ARegion *ar) layout->dirty = FALSE; } -FileLayout *ED_fileselect_get_layout(struct SpaceFile *sfile, struct ARegion *ar) +FileLayout *ED_fileselect_get_layout(struct SpaceFile *sfile, ARegion *ar) { if (!sfile->layout) { ED_fileselect_init_layout(sfile, ar); diff --git a/source/blender/editors/space_image/CMakeLists.txt b/source/blender/editors/space_image/CMakeLists.txt index f397f2387d7..3e3c6adcf8c 100644 --- a/source/blender/editors/space_image/CMakeLists.txt +++ b/source/blender/editors/space_image/CMakeLists.txt @@ -40,6 +40,7 @@ set(INC_SYS set(SRC image_buttons.c image_draw.c + image_edit.c image_ops.c space_image.c diff --git a/source/blender/editors/space_image/image_buttons.c b/source/blender/editors/space_image/image_buttons.c index 7d358bcfb8b..a736cc4cb73 100644 --- a/source/blender/editors/space_image/image_buttons.c +++ b/source/blender/editors/space_image/image_buttons.c @@ -27,8 +27,6 @@ * \ingroup spimage */ - - #include #include @@ -260,7 +258,7 @@ void image_preview_event(int event) /* nothing drawn here, we use it to store values */ -static void preview_cb(struct ScrArea *sa, struct uiBlock *block) +static void preview_cb(ScrArea *sa, struct uiBlock *block) { SpaceImage *sima = sa->spacedata.first; rctf dispf; diff --git a/source/blender/editors/space_image/image_draw.c b/source/blender/editors/space_image/image_draw.c index cf78eaabd88..52ed7fd1d0b 100644 --- a/source/blender/editors/space_image/image_draw.c +++ b/source/blender/editors/space_image/image_draw.c @@ -710,7 +710,7 @@ void draw_image_main(SpaceImage *sima, ARegion *ar, Scene *scene) what_image(sima); if (sima->image) { - ED_image_aspect(sima->image, &xuser_asp, &yuser_asp); + ED_image_get_aspect(sima->image, &xuser_asp, &yuser_asp); /* UGLY hack? until now iusers worked fine... but for flipbook viewer we need this */ if (sima->image->type == IMA_TYPE_COMPOSITE) { @@ -727,7 +727,7 @@ void draw_image_main(SpaceImage *sima, ARegion *ar, Scene *scene) /* retrieve the image and information about it */ ima = ED_space_image(sima); - ED_space_image_zoom(sima, ar, &zoomx, &zoomy); + ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy); show_viewer = (ima && ima->source == IMA_SRC_VIEWER); show_render = (show_viewer && ima->type == IMA_TYPE_R_RESULT); @@ -754,7 +754,7 @@ void draw_image_main(SpaceImage *sima, ARegion *ar, Scene *scene) draw_image_buffer(sima, ar, scene, ima, ibuf, 0.0f, 0.0f, zoomx, zoomy); /* paint helpers */ - if (sima->flag & SI_DRAWTOOL) + if (sima->mode == SI_MODE_PAINT) draw_image_paint_helpers(ar, scene, zoomx, zoomy); diff --git a/source/blender/editors/space_image/image_edit.c b/source/blender/editors/space_image/image_edit.c new file mode 100644 index 00000000000..c0b6dc656c2 --- /dev/null +++ b/source/blender/editors/space_image/image_edit.c @@ -0,0 +1,413 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2008 Blender Foundation. + * All rights reserved. + * + * + * Contributor(s): Blender Foundation + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/editors/space_image/image_editor.c + * \ingroup spimage + */ + +#include "DNA_mask_types.h" +#include "DNA_object_types.h" +#include "DNA_scene_types.h" + +#include "BLI_math.h" + +#include "BKE_context.h" +#include "BKE_global.h" +#include "BKE_image.h" +#include "BKE_main.h" +#include "BKE_tessmesh.h" + +#include "IMB_imbuf_types.h" + +#include "ED_image.h" /* own include */ +#include "ED_mesh.h" +#include "ED_screen.h" +#include "ED_uvedit.h" + +#include "UI_view2d.h" + +#include "WM_api.h" +#include "WM_types.h" + +/* note; image_panel_properties() uses pointer to sima->image directly */ +Image *ED_space_image(SpaceImage *sima) +{ + return sima->image; +} + +/* called to assign images to UV faces */ +void ED_space_image_set(SpaceImage *sima, Scene *scene, Object *obedit, Image *ima) +{ + /* context may be NULL, so use global */ + ED_uvedit_assign_image(G.main, scene, obedit, ima, sima->image); + + /* change the space ima after because uvedit_face_visible_test uses the space ima + * to check if the face is displayed in UV-localview */ + sima->image = ima; + + if (ima == NULL || ima->type == IMA_TYPE_R_RESULT || ima->type == IMA_TYPE_COMPOSITE) { + if (sima->mode == SI_MODE_PAINT) { + sima->mode = SI_MODE_VIEW; + } + } + + if (sima->image) + BKE_image_signal(sima->image, &sima->iuser, IMA_SIGNAL_USER_NEW_IMAGE); + + if (sima->image && sima->image->id.us == 0) + sima->image->id.us = 1; + + if (obedit) + WM_main_add_notifier(NC_GEOM | ND_DATA, obedit->data); + + WM_main_add_notifier(NC_SPACE | ND_SPACE_IMAGE, NULL); +} + +Mask *ED_space_image_get_mask(SpaceImage *sima) +{ + return sima->mask_info.mask; +} + +void ED_space_image_set_mask(bContext *C, SpaceImage *sima, Mask *mask) +{ + sima->mask_info.mask = mask; + + /* weak, but same as image/space */ + if (sima->mask_info.mask && sima->mask_info.mask->id.us == 0) + sima->mask_info.mask->id.us = 1; + + if (C) { + WM_event_add_notifier(C, NC_MASK | NA_SELECTED, mask); + } +} + +ImBuf *ED_space_image_acquire_buffer(SpaceImage *sima, void **lock_r) +{ + ImBuf *ibuf; + + if (sima && sima->image) { +#if 0 + if (sima->image->type == IMA_TYPE_R_RESULT && BIF_show_render_spare()) + return BIF_render_spare_imbuf(); + else +#endif + ibuf = BKE_image_acquire_ibuf(sima->image, &sima->iuser, lock_r); + + if (ibuf && (ibuf->rect || ibuf->rect_float)) + return ibuf; + } + + return NULL; +} + +void ED_space_image_release_buffer(SpaceImage *sima, void *lock) +{ + if (sima && sima->image) + BKE_image_release_ibuf(sima->image, lock); +} + +int ED_space_image_has_buffer(SpaceImage *sima) +{ + ImBuf *ibuf; + void *lock; + int has_buffer; + + ibuf = ED_space_image_acquire_buffer(sima, &lock); + has_buffer = (ibuf != NULL); + ED_space_image_release_buffer(sima, lock); + + return has_buffer; +} + +void ED_image_get_size(Image *ima, int *width, int *height) +{ + ImBuf *ibuf = NULL; + void *lock; + + if (ima) + ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); + + if (ibuf && ibuf->x > 0 && ibuf->y > 0) { + *width = ibuf->x; + *height = ibuf->y; + } + else { + *width = IMG_SIZE_FALLBACK; + *height = IMG_SIZE_FALLBACK; + } + + if (ima) + BKE_image_release_ibuf(ima, lock); +} + +void ED_space_image_get_size(SpaceImage *sima, int *width, int *height) +{ + Scene *scene = sima->iuser.scene; + ImBuf *ibuf; + void *lock; + + ibuf = ED_space_image_acquire_buffer(sima, &lock); + + if (ibuf && ibuf->x > 0 && ibuf->y > 0) { + *width = ibuf->x; + *height = ibuf->y; + } + else if (sima->image && sima->image->type == IMA_TYPE_R_RESULT && scene) { + /* not very important, just nice */ + *width = (scene->r.xsch * scene->r.size) / 100; + *height = (scene->r.ysch * scene->r.size) / 100; + + if ((scene->r.mode & R_BORDER) && (scene->r.mode & R_CROP)) { + *width *= (scene->r.border.xmax - scene->r.border.xmin); + *height *= (scene->r.border.ymax - scene->r.border.ymin); + } + + } + /* I know a bit weak... but preview uses not actual image size */ + // XXX else if (image_preview_active(sima, width, height)); + else { + *width = IMG_SIZE_FALLBACK; + *height = IMG_SIZE_FALLBACK; + } + + ED_space_image_release_buffer(sima, lock); +} + +void ED_space_image_get_size_fl(SpaceImage *sima, float size[2]) +{ + int size_i[2]; + ED_space_image_get_size(sima, &size_i[0], &size_i[1]); + size[0] = size_i[0]; + size[1] = size_i[1]; +} + +void ED_image_get_aspect(Image *ima, float *aspx, float *aspy) +{ + *aspx = *aspy = 1.0; + + if ((ima == NULL) || (ima->type == IMA_TYPE_R_RESULT) || (ima->type == IMA_TYPE_COMPOSITE) || + (ima->aspx == 0.0f || ima->aspy == 0.0f)) + { + return; + } + + /* x is always 1 */ + *aspy = ima->aspy / ima->aspx; +} + +void ED_space_image_get_aspect(SpaceImage *sima, float *aspx, float *aspy) +{ + ED_image_get_aspect(ED_space_image(sima), aspx, aspy); +} + +void ED_space_image_get_zoom(SpaceImage *sima, ARegion *ar, float *zoomx, float *zoomy) +{ + int width, height; + + ED_space_image_get_size(sima, &width, &height); + + *zoomx = (float)(ar->winrct.xmax - ar->winrct.xmin + 1) / (float)((ar->v2d.cur.xmax - ar->v2d.cur.xmin) * width); + *zoomy = (float)(ar->winrct.ymax - ar->winrct.ymin + 1) / (float)((ar->v2d.cur.ymax - ar->v2d.cur.ymin) * height); +} + +void ED_space_image_get_uv_aspect(SpaceImage *sima, float *aspx, float *aspy) +{ + int w, h; + + ED_space_image_get_aspect(sima, aspx, aspy); + ED_space_image_get_size(sima, &w, &h); + + *aspx *= (float)w; + *aspy *= (float)h; + + if (*aspx < *aspy) { + *aspy = *aspy / *aspx; + *aspx = 1.0f; + } + else { + *aspx = *aspx / *aspy; + *aspy = 1.0f; + } +} + +void ED_image_get_uv_aspect(Image *ima, float *aspx, float *aspy) +{ + int w, h; + + ED_image_get_aspect(ima, aspx, aspy); + ED_image_get_size(ima, &w, &h); + + *aspx *= (float)w; + *aspy *= (float)h; +} + +/* takes event->mval */ +void ED_image_mouse_pos(SpaceImage *sima, ARegion *ar, const int mval[2], float co[2]) +{ + int sx, sy, width, height; + float zoomx, zoomy; + + ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy); + ED_space_image_get_size(sima, &width, &height); + + UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &sx, &sy); + + co[0] = ((mval[0] - sx) / zoomx) / width; + co[1] = ((mval[1] - sy) / zoomy) / height; +} + +void ED_image_point_pos(SpaceImage *sima, ARegion *ar, float x, float y, float *xr, float *yr) +{ + int sx, sy, width, height; + float zoomx, zoomy; + + ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy); + ED_space_image_get_size(sima, &width, &height); + + UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &sx, &sy); + + *xr = ((x - sx) / zoomx) / width; + *yr = ((y - sy) / zoomy) / height; +} + +void ED_image_point_pos__reverse(SpaceImage *sima, ARegion *ar, const float co[2], float r_co[2]) +{ + float zoomx, zoomy; + int width, height; + int sx, sy; + + UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &sx, &sy); + ED_space_image_get_size(sima, &width, &height); + ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy); + + r_co[0] = (co[0] * width * zoomx) + (float)sx; + r_co[1] = (co[1] * height * zoomy) + (float)sy; +} + +int ED_space_image_show_render(SpaceImage *sima) +{ + return (sima->image && ELEM(sima->image->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE)); +} + +int ED_space_image_show_paint(SpaceImage *sima) +{ + if (ED_space_image_show_render(sima)) + return 0; + + return (sima->mode == SI_MODE_PAINT); +} + +int ED_space_image_show_uvedit(SpaceImage *sima, Object *obedit) +{ + if (sima && (ED_space_image_show_render(sima) || ED_space_image_show_paint(sima))) + return 0; + + if (obedit && obedit->type == OB_MESH) { + struct BMEditMesh *em = BMEdit_FromObject(obedit); + int ret; + + ret = EDBM_mtexpoly_check(em); + + return ret; + } + + return 0; +} + +int ED_space_image_show_uvshadow(SpaceImage *sima, Object *obedit) +{ + if (ED_space_image_show_render(sima)) + return 0; + + if (ED_space_image_show_paint(sima)) + if (obedit && obedit->type == OB_MESH) { + struct BMEditMesh *em = BMEdit_FromObject(obedit); + int ret; + + ret = EDBM_mtexpoly_check(em); + + return ret; + } + + return 0; +} + +/* matches clip function */ +int ED_space_image_check_show_maskedit(Scene *scene, SpaceImage *sima) +{ + /* check editmode - this is reserved for UV editing */ + Object *ob = OBACT; + if (ob && ob->mode & OB_MODE_EDIT && ED_space_image_show_uvedit(sima, ob)) { + return FALSE; + } + + return (sima->mode == SI_MODE_MASK); +} + +int ED_space_image_maskedit_poll(bContext *C) +{ + SpaceImage *sima = CTX_wm_space_image(C); + + if (sima && sima->image) { + Scene *scene = CTX_data_scene(C); + return ED_space_image_check_show_maskedit(scene, sima); + } + + return FALSE; +} + +int ED_space_image_maskedit_mask_poll(bContext *C) +{ + if (ED_space_image_maskedit_poll(C)) { + Image *ima = CTX_data_edit_image(C); + + if (ima) { + SpaceImage *sima = CTX_wm_space_image(C); + + return sima->mask_info.mask != NULL; + } + } + + return FALSE; +} + +/******************** TODO ********************/ + +/* XXX notifier? */ + +/* goes over all ImageUsers, and sets frame numbers if auto-refresh is set */ + +static void image_update_frame(struct Image *UNUSED(ima), struct ImageUser *iuser, void *customdata) +{ + int cfra = *(int *)customdata; + + BKE_image_user_check_frame_calc(iuser, cfra, 0); +} + +void ED_image_update_frame(const Main *mainp, int cfra) +{ + BKE_image_walk_all_users(mainp, &cfra, image_update_frame); +} diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index ca16558f3a6..aa44caac0af 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -91,7 +91,7 @@ static void sima_zoom_set(SpaceImage *sima, ARegion *ar, float zoom, float locat if (sima->zoom < 0.1f || sima->zoom > 4.0f) { /* check zoom limits */ - ED_space_image_size(sima, &width, &height); + ED_space_image_get_size(sima, &width, &height); width *= sima->zoom; height *= sima->zoom; @@ -107,8 +107,8 @@ static void sima_zoom_set(SpaceImage *sima, ARegion *ar, float zoom, float locat if ((U.uiflag & USER_ZOOM_TO_MOUSEPOS) && location) { float aspx, aspy, w, h; - ED_space_image_size(sima, &width, &height); - ED_space_image_aspect(sima, &aspx, &aspy); + ED_space_image_get_size(sima, &width, &height); + ED_space_image_get_aspect(sima, &aspx, &aspy); w = width * aspx; h = height * aspy; @@ -203,17 +203,27 @@ int space_image_main_area_not_uv_brush_poll(bContext *C) return 0; } -static int space_image_image_sample_poll(bContext *C) +static int image_sample_poll(bContext *C) { SpaceImage *sima = CTX_wm_space_image(C); - Object *obedit = CTX_data_edit_object(C); - ToolSettings *toolsettings = CTX_data_scene(C)->toolsettings; + if (sima) { + Scene *scene = CTX_data_scene(C); + Object *obedit = CTX_data_edit_object(C); + ToolSettings *toolsettings = scene->toolsettings; - if (obedit) { - if (ED_space_image_show_uvedit(sima, obedit) && (toolsettings->use_uv_sculpt)) - return 0; + if (obedit) { + if (ED_space_image_show_uvedit(sima, obedit) && (toolsettings->use_uv_sculpt)) + return FALSE; + } + else if (sima->mode != SI_MODE_VIEW) { + return FALSE; + } + + return space_image_main_area_poll(C); + } + else { + return FALSE; } - return space_image_main_area_poll(C); } /********************** view pan operator *********************/ @@ -564,8 +574,8 @@ static int image_view_all_exec(bContext *C, wmOperator *UNUSED(op)) sima = CTX_wm_space_image(C); ar = CTX_wm_region(C); - ED_space_image_size(sima, &width, &height); - ED_space_image_aspect(sima, &aspx, &aspy); + ED_space_image_get_size(sima, &width, &height); + ED_space_image_get_aspect(sima, &aspx, &aspy); w = width * aspx; h = height * aspy; @@ -578,7 +588,7 @@ static int image_view_all_exec(bContext *C, wmOperator *UNUSED(op)) /* find the zoom value that will fit the image in the image space */ zoomx = width / w; zoomy = height / h; - sima_zoom_set(sima, ar, 1.0f / power_of_2(1 / MIN2(zoomx, zoomy)), NULL); + sima_zoom_set(sima, ar, 1.0f / power_of_2(1.0f / minf(zoomx, zoomy)), NULL); } else sima_zoom_set(sima, ar, 1.0f, NULL); @@ -621,8 +631,8 @@ static int image_view_selected_exec(bContext *C, wmOperator *UNUSED(op)) obedit = CTX_data_edit_object(C); ima = ED_space_image(sima); - ED_space_image_size(sima, &width, &height); - ED_image_aspect(ima, &aspx, &aspy); + ED_space_image_get_size(sima, &width, &height); + ED_image_get_aspect(ima, &aspx, &aspy); width = width * aspx; height = height * aspy; @@ -901,6 +911,26 @@ static int image_open_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event) ima = tex->ima; } + if (ima == NULL) { + PointerRNA ptr; + PropertyRNA *prop; + + /* hook into UI */ + uiIDContextProperty(C, &ptr, &prop); + + if (prop) { + PointerRNA oldptr; + Image *oldima; + + oldptr = RNA_property_pointer_get(&ptr, prop); + oldima = (Image *)oldptr.id.data; + /* unlikely to fail but better avoid strange crash */ + if (oldima && GS(oldima->id.name) == ID_IM) { + ima = oldima; + } + } + } + if (ima) path = ima->name; @@ -2089,7 +2119,7 @@ void IMAGE_OT_sample(wmOperatorType *ot) ot->invoke = image_sample_invoke; ot->modal = image_sample_modal; ot->cancel = image_sample_cancel; - ot->poll = space_image_image_sample_poll; + ot->poll = image_sample_poll; /* flags */ ot->flag = OPTYPE_BLOCKING; @@ -2133,6 +2163,9 @@ static int image_sample_line_exec(bContext *C, wmOperator *op) BKE_histogram_update_sample_line(hist, ibuf, (scene->r.color_mgt_flag & R_COLOR_MANAGEMENT) != 0); + /* reset y zoom */ + hist->ymax = 1.0f; + ED_space_image_release_buffer(sima, lock); ED_area_tag_redraw(CTX_wm_area(C)); @@ -2403,22 +2436,3 @@ void IMAGE_OT_cycle_render_slot(wmOperatorType *ot) RNA_def_boolean(ot->srna, "reverse", 0, "Cycle in Reverse", ""); } - -/******************** TODO ********************/ - -/* XXX notifier? */ - -/* goes over all ImageUsers, and sets frame numbers if auto-refresh is set */ - -static void image_update_frame(struct Image *UNUSED(ima), struct ImageUser *iuser, void *customdata) -{ - int cfra = *(int*)customdata; - - BKE_image_user_check_frame_calc(iuser, cfra, 0); -} - -void ED_image_update_frame(const Main *mainp, int cfra) -{ - BKE_image_walk_all_users(mainp, &cfra, image_update_frame); -} - diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c index 59e47363a22..f97813d3dd3 100644 --- a/source/blender/editors/space_image/space_image.c +++ b/source/blender/editors/space_image/space_image.c @@ -28,11 +28,8 @@ * \ingroup spimage */ - -#include -#include - #include "DNA_mesh_types.h" +#include "DNA_mask_types.h" #include "DNA_meshdata_types.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" @@ -41,22 +38,19 @@ #include "BLI_blenlib.h" #include "BLI_math.h" -#include "BLI_rand.h" -#include "BLI_utildefines.h" #include "BKE_colortools.h" #include "BKE_context.h" #include "BKE_image.h" -#include "BKE_global.h" -#include "BKE_main.h" -#include "BKE_mesh.h" #include "BKE_scene.h" #include "BKE_screen.h" #include "BKE_tessmesh.h" +#include "BKE_sequencer.h" #include "IMB_imbuf_types.h" #include "ED_image.h" +#include "ED_mask.h" #include "ED_mesh.h" #include "ED_space_api.h" #include "ED_screen.h" @@ -76,238 +70,6 @@ /**************************** common state *****************************/ -/* note; image_panel_properties() uses pointer to sima->image directly */ -Image *ED_space_image(SpaceImage *sima) -{ - return sima->image; -} - -/* called to assign images to UV faces */ -void ED_space_image_set(SpaceImage *sima, Scene *scene, Object *obedit, Image *ima) -{ - /* context may be NULL, so use global */ - ED_uvedit_assign_image(G.main, scene, obedit, ima, sima->image); - - /* change the space ima after because uvedit_face_visible_test uses the space ima - * to check if the face is displayed in UV-localview */ - sima->image = ima; - - if (ima == NULL || ima->type == IMA_TYPE_R_RESULT || ima->type == IMA_TYPE_COMPOSITE) - sima->flag &= ~SI_DRAWTOOL; - - if (sima->image) - BKE_image_signal(sima->image, &sima->iuser, IMA_SIGNAL_USER_NEW_IMAGE); - - if (sima->image && sima->image->id.us == 0) - sima->image->id.us = 1; - - if (obedit) - WM_main_add_notifier(NC_GEOM | ND_DATA, obedit->data); - - WM_main_add_notifier(NC_SPACE | ND_SPACE_IMAGE, NULL); -} - -ImBuf *ED_space_image_acquire_buffer(SpaceImage *sima, void **lock_r) -{ - ImBuf *ibuf; - - if (sima && sima->image) { -#if 0 - if (sima->image->type == IMA_TYPE_R_RESULT && BIF_show_render_spare()) - return BIF_render_spare_imbuf(); - else -#endif - ibuf = BKE_image_acquire_ibuf(sima->image, &sima->iuser, lock_r); - - if (ibuf && (ibuf->rect || ibuf->rect_float)) - return ibuf; - } - - return NULL; -} - -void ED_space_image_release_buffer(SpaceImage *sima, void *lock) -{ - if (sima && sima->image) - BKE_image_release_ibuf(sima->image, lock); -} - -int ED_space_image_has_buffer(SpaceImage *sima) -{ - ImBuf *ibuf; - void *lock; - int has_buffer; - - ibuf = ED_space_image_acquire_buffer(sima, &lock); - has_buffer = (ibuf != NULL); - ED_space_image_release_buffer(sima, lock); - - return has_buffer; -} - -void ED_image_size(Image *ima, int *width, int *height) -{ - ImBuf *ibuf = NULL; - void *lock; - - if (ima) - ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); - - if (ibuf && ibuf->x > 0 && ibuf->y > 0) { - *width = ibuf->x; - *height = ibuf->y; - } - else { - *width = 256; - *height = 256; - } - - if (ima) - BKE_image_release_ibuf(ima, lock); -} - -void ED_space_image_size(SpaceImage *sima, int *width, int *height) -{ - Scene *scene = sima->iuser.scene; - ImBuf *ibuf; - void *lock; - - ibuf = ED_space_image_acquire_buffer(sima, &lock); - - if (ibuf && ibuf->x > 0 && ibuf->y > 0) { - *width = ibuf->x; - *height = ibuf->y; - } - else if (sima->image && sima->image->type == IMA_TYPE_R_RESULT && scene) { - /* not very important, just nice */ - *width = (scene->r.xsch * scene->r.size) / 100; - *height = (scene->r.ysch * scene->r.size) / 100; - - if ((scene->r.mode & R_BORDER) && (scene->r.mode & R_CROP)) { - *width *= (scene->r.border.xmax - scene->r.border.xmin); - *height *= (scene->r.border.ymax - scene->r.border.ymin); - } - - } - /* I know a bit weak... but preview uses not actual image size */ - // XXX else if (image_preview_active(sima, width, height)); - else { - *width = 256; - *height = 256; - } - - ED_space_image_release_buffer(sima, lock); -} - -void ED_image_aspect(Image *ima, float *aspx, float *aspy) -{ - *aspx = *aspy = 1.0; - - if ((ima == NULL) || (ima->type == IMA_TYPE_R_RESULT) || (ima->type == IMA_TYPE_COMPOSITE) || - (ima->aspx == 0.0f || ima->aspy == 0.0f)) - { - return; - } - - /* x is always 1 */ - *aspy = ima->aspy / ima->aspx; -} - -void ED_space_image_aspect(SpaceImage *sima, float *aspx, float *aspy) -{ - ED_image_aspect(ED_space_image(sima), aspx, aspy); -} - -void ED_space_image_zoom(SpaceImage *sima, ARegion *ar, float *zoomx, float *zoomy) -{ - int width, height; - - ED_space_image_size(sima, &width, &height); - - *zoomx = (float)(ar->winrct.xmax - ar->winrct.xmin + 1) / (float)((ar->v2d.cur.xmax - ar->v2d.cur.xmin) * width); - *zoomy = (float)(ar->winrct.ymax - ar->winrct.ymin + 1) / (float)((ar->v2d.cur.ymax - ar->v2d.cur.ymin) * height); -} - -void ED_space_image_uv_aspect(SpaceImage *sima, float *aspx, float *aspy) -{ - int w, h; - - ED_space_image_aspect(sima, aspx, aspy); - ED_space_image_size(sima, &w, &h); - - *aspx *= (float)w; - *aspy *= (float)h; - - if (*aspx < *aspy) { - *aspy = *aspy / *aspx; - *aspx = 1.0f; - } - else { - *aspx = *aspx / *aspy; - *aspy = 1.0f; - } -} - -void ED_image_uv_aspect(Image *ima, float *aspx, float *aspy) -{ - int w, h; - - ED_image_aspect(ima, aspx, aspy); - ED_image_size(ima, &w, &h); - - *aspx *= (float)w; - *aspy *= (float)h; -} - -int ED_space_image_show_render(SpaceImage *sima) -{ - return (sima->image && ELEM(sima->image->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE)); -} - -int ED_space_image_show_paint(SpaceImage *sima) -{ - if (ED_space_image_show_render(sima)) - return 0; - - return (sima->flag & SI_DRAWTOOL); -} - -int ED_space_image_show_uvedit(SpaceImage *sima, Object *obedit) -{ - if (sima && (ED_space_image_show_render(sima) || ED_space_image_show_paint(sima))) - return 0; - - if (obedit && obedit->type == OB_MESH) { - struct BMEditMesh *em = BMEdit_FromObject(obedit); - int ret; - - ret = EDBM_mtexpoly_check(em); - - return ret; - } - - return 0; -} - -int ED_space_image_show_uvshadow(SpaceImage *sima, Object *obedit) -{ - if (ED_space_image_show_render(sima)) - return 0; - - if (ED_space_image_show_paint(sima)) - if (obedit && obedit->type == OB_MESH) { - struct BMEditMesh *em = BMEdit_FromObject(obedit); - int ret; - - ret = EDBM_mtexpoly_check(em); - - return ret; - } - - return 0; -} - - static void image_scopes_tag_refresh(ScrArea *sa) { SpaceImage *sima = (SpaceImage *)sa->spacedata.first; @@ -384,10 +146,10 @@ static SpaceLink *image_new(const bContext *UNUSED(C)) simage = MEM_callocN(sizeof(SpaceImage), "initimage"); simage->spacetype = SPACE_IMAGE; - simage->zoom = 1; - simage->lock = 1; + simage->zoom = 1.0f; + simage->lock = TRUE; - simage->iuser.ok = 1; + simage->iuser.ok = TRUE; simage->iuser.fie_ima = 2; simage->iuser.frames = 100; @@ -580,7 +342,6 @@ static void image_dropboxes(void) } - static void image_refresh(const bContext *C, ScrArea *UNUSED(sa)) { Scene *scene = CTX_data_scene(C); @@ -668,6 +429,29 @@ static void image_listener(ScrArea *sa, wmNotifier *wmn) ED_area_tag_redraw(sa); } break; + case NC_MASK: + { + // Scene *scene = wmn->window->screen->scene; + /* ideally would check for: ED_space_image_check_show_maskedit(scene, sima) but we cant get the scene */ + if (sima->mode == SI_MODE_MASK) { + switch (wmn->data) { + case ND_SELECT: + case ND_DATA: + case ND_DRAW: + ED_area_tag_redraw(sa); + break; + } + switch (wmn->action) { + case NA_SELECTED: + ED_area_tag_redraw(sa); + break; + case NA_EDITED: + ED_area_tag_redraw(sa); + break; + } + } + break; + } case NC_GEOM: switch (wmn->data) { case ND_DATA: @@ -693,7 +477,7 @@ static void image_listener(ScrArea *sa, wmNotifier *wmn) } } -const char *image_context_dir[] = {"edit_image", NULL}; +const char *image_context_dir[] = {"edit_image", "edit_mask", NULL}; static int image_context(const bContext *C, const char *member, bContextDataResult *result) { @@ -706,7 +490,13 @@ static int image_context(const bContext *C, const char *member, bContextDataResu CTX_data_id_pointer_set(result, (ID *)ED_space_image(sima)); return 1; } - + else if (CTX_data_equals(member, "edit_mask")) { + Mask *mask = ED_space_image_get_mask(sima); + if (mask) { + CTX_data_id_pointer_set(result, &mask->id); + } + return TRUE; + } return 0; } @@ -723,7 +513,7 @@ static void image_main_area_set_view2d(SpaceImage *sima, ARegion *ar) if (image_preview_active(curarea, &width, &height)) ; else #endif - ED_space_image_size(sima, &width, &height); + ED_space_image_get_size(sima, &width, &height); w = width; h = height; @@ -773,6 +563,10 @@ static void image_main_area_init(wmWindowManager *wm, ARegion *ar) // image space manages own v2d // UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy); + /* mask polls mode */ + keymap = WM_keymap_find(wm->defaultconf, "Mask Editing", 0, 0); + WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + /* image paint polls for mode */ keymap = WM_keymap_find(wm->defaultconf, "Image Paint", 0, 0); WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); @@ -797,6 +591,7 @@ static void image_main_area_draw(const bContext *C, ARegion *ar) SpaceImage *sima = CTX_wm_space_image(C); Object *obact = CTX_data_active_object(C); Object *obedit = CTX_data_edit_object(C); + Mask *mask = NULL; Scene *scene = CTX_data_scene(C); View2D *v2d = &ar->v2d; //View2DScrollers *scrollers; @@ -815,7 +610,7 @@ static void image_main_area_draw(const bContext *C, ARegion *ar) /* we set view2d from own zoom and offset each time */ image_main_area_set_view2d(sima, ar); - + /* we draw image in pixelspace */ draw_image_main(sima, ar, scene); @@ -823,6 +618,15 @@ static void image_main_area_draw(const bContext *C, ARegion *ar) UI_view2d_view_ortho(v2d); draw_uvedit_main(sima, ar, scene, obedit, obact); + /* check for mask (delay draw) */ + if (ED_space_image_show_uvedit(sima, obedit)) { + /* pass */ + } + else if (sima->mode == SI_MODE_MASK) { + mask = ED_space_image_get_mask(sima); + draw_image_cursor(sima, ar); + } + ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW); /* Grease Pencil too (in addition to UV's) */ @@ -836,6 +640,20 @@ static void image_main_area_draw(const bContext *C, ARegion *ar) /* draw Grease Pencil - screen space only */ draw_image_grease_pencil((bContext *)C, 0); + if (mask) { + int width, height; + ED_space_image_get_size(sima, &width, &height); + ED_mask_draw_region(mask, ar, + sima->mask_info.draw_flag, sima->mask_info.draw_type, + width, height, + TRUE, FALSE, + NULL, C); + + ED_mask_draw_frames(mask, ar, CFRA, mask->sfra, mask->efra); + + draw_image_cursor(sima, ar); + } + /* scrollers? */ #if 0 scrollers = UI_view2d_scrollers_calc(C, v2d, V2D_UNIT_VALUES, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY); diff --git a/source/blender/editors/space_info/info_draw.c b/source/blender/editors/space_info/info_draw.c index 329917a9f7e..35e19bcce38 100644 --- a/source/blender/editors/space_info/info_draw.c +++ b/source/blender/editors/space_info/info_draw.c @@ -249,7 +249,7 @@ static int report_textview_line_color(struct TextViewContext *tvc, unsigned char #undef USE_INFO_NEWLINE -static int info_textview_main__internal(struct SpaceInfo *sinfo, struct ARegion *ar, ReportList *reports, int draw, int mval[2], void **mouse_pick, int *pos_pick) +static int info_textview_main__internal(struct SpaceInfo *sinfo, ARegion *ar, ReportList *reports, int draw, int mval[2], void **mouse_pick, int *pos_pick) { int ret = 0; @@ -279,7 +279,7 @@ static int info_textview_main__internal(struct SpaceInfo *sinfo, struct ARegion return ret; } -void *info_text_pick(struct SpaceInfo *sinfo, struct ARegion *ar, ReportList *reports, int mouse_y) +void *info_text_pick(struct SpaceInfo *sinfo, ARegion *ar, ReportList *reports, int mouse_y) { void *mouse_pick = NULL; int mval[2]; @@ -292,13 +292,13 @@ void *info_text_pick(struct SpaceInfo *sinfo, struct ARegion *ar, ReportList *re } -int info_textview_height(struct SpaceInfo *sinfo, struct ARegion *ar, ReportList *reports) +int info_textview_height(struct SpaceInfo *sinfo, ARegion *ar, ReportList *reports) { int mval[2] = {INT_MAX, INT_MAX}; return info_textview_main__internal(sinfo, ar, reports, 0, mval, NULL, NULL); } -void info_textview_main(struct SpaceInfo *sinfo, struct ARegion *ar, ReportList *reports) +void info_textview_main(struct SpaceInfo *sinfo, ARegion *ar, ReportList *reports) { int mval[2] = {INT_MAX, INT_MAX}; info_textview_main__internal(sinfo, ar, reports, 1, mval, NULL, NULL); diff --git a/source/blender/editors/space_logic/logic_ops.c b/source/blender/editors/space_logic/logic_ops.c index 1e976cebafd..f2013e405e2 100644 --- a/source/blender/editors/space_logic/logic_ops.c +++ b/source/blender/editors/space_logic/logic_ops.c @@ -64,25 +64,25 @@ /* ************* Generic Operator Helpers ************* */ static int edit_sensor_poll(bContext *C) { - PointerRNA ptr= CTX_data_pointer_get_type(C, "sensor", &RNA_Sensor); + PointerRNA ptr = CTX_data_pointer_get_type(C, "sensor", &RNA_Sensor); - if (ptr.data && ((ID*)ptr.id.data)->lib) return 0; + if (ptr.data && ((ID *)ptr.id.data)->lib) return 0; return 1; } static int edit_controller_poll(bContext *C) { - PointerRNA ptr= CTX_data_pointer_get_type(C, "controller", &RNA_Controller); + PointerRNA ptr = CTX_data_pointer_get_type(C, "controller", &RNA_Controller); - if (ptr.data && ((ID*)ptr.id.data)->lib) return 0; + if (ptr.data && ((ID *)ptr.id.data)->lib) return 0; return 1; } static int edit_actuator_poll(bContext *C) { - PointerRNA ptr= CTX_data_pointer_get_type(C, "actuator", &RNA_Actuator); + PointerRNA ptr = CTX_data_pointer_get_type(C, "actuator", &RNA_Actuator); - if (ptr.data && ((ID*)ptr.id.data)->lib) return 0; + if (ptr.data && ((ID *)ptr.id.data)->lib) return 0; return 1; } @@ -94,7 +94,7 @@ static void edit_sensor_properties(wmOperatorType *ot) static int edit_sensor_invoke_properties(bContext *C, wmOperator *op) { - PointerRNA ptr= CTX_data_pointer_get_type(C, "sensor", &RNA_Sensor); + PointerRNA ptr = CTX_data_pointer_get_type(C, "sensor", &RNA_Sensor); if (RNA_struct_property_is_set(op->ptr, "sensor") && RNA_struct_property_is_set(op->ptr, "object") ) return 1; @@ -104,7 +104,7 @@ static int edit_sensor_invoke_properties(bContext *C, wmOperator *op) Object *ob = ptr.id.data; RNA_string_set(op->ptr, "sensor", sens->name); - RNA_string_set(op->ptr, "object", ob->id.name+2); + RNA_string_set(op->ptr, "object", ob->id.name + 2); return 1; } @@ -123,7 +123,7 @@ static Object *edit_object_property_get(bContext *C, wmOperator *op) if (BLI_strnlen(ob_name, MAX_NAME) > 0) ob = BLI_findstring(&(CTX_data_main(C)->object), ob_name, offsetof(ID, name) + 2); else - ob= ED_object_active_context(C); + ob = ED_object_active_context(C); return ob; } @@ -135,7 +135,7 @@ static bSensor *edit_sensor_property_get(bContext *C, wmOperator *op, Object **o RNA_string_get(op->ptr, "sensor", sensor_name); - *ob= edit_object_property_get(C, op); + *ob = edit_object_property_get(C, op); if (!*ob) return NULL; sens = BLI_findstring(&((*ob)->sensors), sensor_name, offsetof(bSensor, name)); @@ -150,7 +150,7 @@ static void edit_controller_properties(wmOperatorType *ot) static int edit_controller_invoke_properties(bContext *C, wmOperator *op) { - PointerRNA ptr= CTX_data_pointer_get_type(C, "controller", &RNA_Controller); + PointerRNA ptr = CTX_data_pointer_get_type(C, "controller", &RNA_Controller); if (RNA_struct_property_is_set(op->ptr, "controller") && RNA_struct_property_is_set(op->ptr, "object") ) return 1; @@ -160,7 +160,7 @@ static int edit_controller_invoke_properties(bContext *C, wmOperator *op) Object *ob = ptr.id.data; RNA_string_set(op->ptr, "controller", cont->name); - RNA_string_set(op->ptr, "object", ob->id.name+2); + RNA_string_set(op->ptr, "object", ob->id.name + 2); return 1; } @@ -174,7 +174,7 @@ static bController *edit_controller_property_get(bContext *C, wmOperator *op, Ob RNA_string_get(op->ptr, "controller", controller_name); - *ob= edit_object_property_get(C, op); + *ob = edit_object_property_get(C, op); if (!*ob) return NULL; cont = BLI_findstring(&((*ob)->controllers), controller_name, offsetof(bController, name)); @@ -189,7 +189,7 @@ static void edit_actuator_properties(wmOperatorType *ot) static int edit_actuator_invoke_properties(bContext *C, wmOperator *op) { - PointerRNA ptr= CTX_data_pointer_get_type(C, "actuator", &RNA_Actuator); + PointerRNA ptr = CTX_data_pointer_get_type(C, "actuator", &RNA_Actuator); if (RNA_struct_property_is_set(op->ptr, "actuator") && RNA_struct_property_is_set(op->ptr, "object") ) return 1; @@ -199,7 +199,7 @@ static int edit_actuator_invoke_properties(bContext *C, wmOperator *op) Object *ob = ptr.id.data; RNA_string_set(op->ptr, "actuator", act->name); - RNA_string_set(op->ptr, "object", ob->id.name+2); + RNA_string_set(op->ptr, "object", ob->id.name + 2); return 1; } @@ -213,7 +213,7 @@ static bActuator *edit_actuator_property_get(bContext *C, wmOperator *op, Object RNA_string_get(op->ptr, "actuator", actuator_name); - *ob= edit_object_property_get(C, op); + *ob = edit_object_property_get(C, op); if (!*ob) return NULL; act = BLI_findstring(&((*ob)->actuators), actuator_name, offsetof(bActuator, name)); @@ -234,7 +234,7 @@ static int logicbricks_move_property_get(wmOperator *op) static int sensor_remove_exec(bContext *C, wmOperator *op) { - Object *ob=NULL; + Object *ob = NULL; bSensor *sens = edit_sensor_property_get(C, op, &ob); if (!sens) @@ -248,7 +248,7 @@ static int sensor_remove_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } - static int sensor_remove_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) +static int sensor_remove_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) { if (edit_sensor_invoke_properties(C, op)) return sensor_remove_exec(C, op); @@ -267,7 +267,7 @@ static void LOGIC_OT_sensor_remove(wmOperatorType *ot) ot->poll = edit_sensor_poll; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; edit_sensor_properties(ot); } @@ -279,13 +279,13 @@ static int sensor_add_exec(bContext *C, wmOperator *op) PropertyRNA *prop; const char *sens_name; char name[MAX_NAME]; - int type= RNA_enum_get(op->ptr, "type"); + int type = RNA_enum_get(op->ptr, "type"); - ob= edit_object_property_get(C, op); + ob = edit_object_property_get(C, op); if (!ob) return OPERATOR_CANCELLED; - sens= new_sensor(type); + sens = new_sensor(type); BLI_addtail(&(ob->sensors), sens); /* set the sensor name based on rna type enum */ @@ -323,10 +323,10 @@ static void LOGIC_OT_sensor_add(wmOperatorType *ot) ot->poll = ED_operator_object_active_editable; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ - ot->prop = prop= RNA_def_enum(ot->srna, "type", DummyRNA_NULL_items, SENS_ALWAYS, "Type", "Type of sensor to add"); + ot->prop = prop = RNA_def_enum(ot->srna, "type", DummyRNA_NULL_items, SENS_ALWAYS, "Type", "Type of sensor to add"); RNA_def_enum_funcs(prop, rna_Sensor_type_itemf); RNA_def_string(ot->srna, "name", "", MAX_NAME, "Name", "Name of the Sensor to add"); RNA_def_string(ot->srna, "object", "", MAX_NAME, "Object", "Name of the Object to add the Sensor to"); @@ -351,7 +351,7 @@ static int controller_remove_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } - static int controller_remove_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) +static int controller_remove_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) { if (edit_controller_invoke_properties(C, op)) return controller_remove_exec(C, op); @@ -370,7 +370,7 @@ static void LOGIC_OT_controller_remove(wmOperatorType *ot) ot->poll = edit_controller_poll; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; edit_controller_properties(ot); } @@ -383,13 +383,13 @@ static int controller_add_exec(bContext *C, wmOperator *op) const char *cont_name; int bit; char name[MAX_NAME]; - int type= RNA_enum_get(op->ptr, "type"); + int type = RNA_enum_get(op->ptr, "type"); - ob= edit_object_property_get(C, op); + ob = edit_object_property_get(C, op); if (!ob) return OPERATOR_CANCELLED; - cont= new_controller(type); + cont = new_controller(type); BLI_addtail(&(ob->controllers), cont); /* set the controller name based on rna type enum */ @@ -408,11 +408,11 @@ static int controller_add_exec(bContext *C, wmOperator *op) /* set the controller state mask from the current object state. * A controller is always in a single state, so select the lowest bit set * from the object state */ - for (bit=0; bitstate & (1<state & (1 << bit)) break; } - cont->state_mask = (1<state_mask = (1 << bit); if (cont->state_mask == 0) { /* shouldn't happen, object state is never 0 */ cont->state_mask = 1; @@ -438,7 +438,7 @@ static void LOGIC_OT_controller_add(wmOperatorType *ot) ot->poll = ED_operator_object_active_editable; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ ot->prop = RNA_def_enum(ot->srna, "type", controller_type_items, CONT_LOGIC_AND, "Type", "Type of controller to add"); @@ -450,7 +450,7 @@ static void LOGIC_OT_controller_add(wmOperatorType *ot) static int actuator_remove_exec(bContext *C, wmOperator *op) { - Object *ob=NULL; + Object *ob = NULL; bActuator *act = edit_actuator_property_get(C, op, &ob); if (!act) @@ -484,7 +484,7 @@ static void LOGIC_OT_actuator_remove(wmOperatorType *ot) ot->poll = edit_actuator_poll; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; edit_actuator_properties(ot); } @@ -495,14 +495,14 @@ static int actuator_add_exec(bContext *C, wmOperator *op) PointerRNA act_ptr; PropertyRNA *prop; const char *act_name; - char name[MAX_NAME]; - int type= RNA_enum_get(op->ptr, "type"); + char name[MAX_NAME]; + int type = RNA_enum_get(op->ptr, "type"); - ob= edit_object_property_get(C, op); + ob = edit_object_property_get(C, op); if (!ob) return OPERATOR_CANCELLED; - act= new_actuator(type); + act = new_actuator(type); BLI_addtail(&(ob->actuators), act); /* set the actuator name based on rna type enum */ @@ -540,27 +540,28 @@ static void LOGIC_OT_actuator_add(wmOperatorType *ot) ot->poll = ED_operator_object_active_editable; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ - ot->prop = prop= RNA_def_enum(ot->srna, "type", DummyRNA_NULL_items, CONT_LOGIC_AND, "Type", "Type of actuator to add"); + ot->prop = prop = RNA_def_enum(ot->srna, "type", DummyRNA_NULL_items, CONT_LOGIC_AND, "Type", "Type of actuator to add"); RNA_def_enum_funcs(prop, rna_Actuator_type_itemf); RNA_def_string(ot->srna, "name", "", MAX_NAME, "Name", "Name of the Actuator to add"); RNA_def_string(ot->srna, "object", "", MAX_NAME, "Object", "Name of the Object to add the Actuator to"); } /* ************* Move Logic Bricks Operator ************* */ -static EnumPropertyItem logicbricks_move_direction[] ={ - {1, "UP", 0, "Move Up", ""}, - {2, "DOWN", 0, "Move Down", ""}, - {0, NULL, 0, NULL, NULL}}; +static EnumPropertyItem logicbricks_move_direction[] = { + {1, "UP", 0, "Move Up", ""}, + {2, "DOWN", 0, "Move Down", ""}, + {0, NULL, 0, NULL, NULL} +}; static int sensor_move_exec(bContext *C, wmOperator *op) { - Object *ob=NULL; - bSensor *sens= edit_sensor_property_get(C, op, &ob); - int move_up= logicbricks_move_property_get(op); + Object *ob = NULL; + bSensor *sens = edit_sensor_property_get(C, op, &ob); + int move_up = logicbricks_move_property_get(op); if (!sens) return OPERATOR_CANCELLED; @@ -594,7 +595,7 @@ static void LOGIC_OT_sensor_move(wmOperatorType *ot) ot->poll = edit_sensor_poll; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ edit_sensor_properties(ot); @@ -603,9 +604,9 @@ static void LOGIC_OT_sensor_move(wmOperatorType *ot) static int controller_move_exec(bContext *C, wmOperator *op) { - Object *ob=NULL; - bController *cont= edit_controller_property_get(C, op, &ob); - int move_up= logicbricks_move_property_get(op); + Object *ob = NULL; + bController *cont = edit_controller_property_get(C, op, &ob); + int move_up = logicbricks_move_property_get(op); if (!cont) return OPERATOR_CANCELLED; @@ -639,7 +640,7 @@ static void LOGIC_OT_controller_move(wmOperatorType *ot) ot->poll = edit_controller_poll; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ edit_controller_properties(ot); @@ -648,9 +649,9 @@ static void LOGIC_OT_controller_move(wmOperatorType *ot) static int actuator_move_exec(bContext *C, wmOperator *op) { - Object *ob=NULL; + Object *ob = NULL; bActuator *act = edit_actuator_property_get(C, op, &ob); - int move_up= logicbricks_move_property_get(op); + int move_up = logicbricks_move_property_get(op); if (!act) return OPERATOR_CANCELLED; @@ -684,7 +685,7 @@ static void LOGIC_OT_actuator_move(wmOperatorType *ot) ot->poll = edit_actuator_poll; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ edit_actuator_properties(ot); @@ -694,7 +695,7 @@ static void LOGIC_OT_actuator_move(wmOperatorType *ot) /* ************* TexFace Converter Operator ************* */ static int texface_convert_exec(bContext *C, wmOperator *UNUSED(op)) { - Main *bmain= CTX_data_main(C); + Main *bmain = CTX_data_main(C); do_version_tface(bmain, 0); return OPERATOR_FINISHED; @@ -705,7 +706,7 @@ static int texface_convert_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(e return texface_convert_exec(C, op); } - static void LOGIC_OT_texface_convert(wmOperatorType *ot) +static void LOGIC_OT_texface_convert(wmOperatorType *ot) { /* identifiers */ ot->name = "TexFace to Material Converter"; @@ -718,7 +719,7 @@ static int texface_convert_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(e // ot->poll = texface_convert_poll; /* flags */ - ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } diff --git a/source/blender/editors/space_nla/nla_edit.c b/source/blender/editors/space_nla/nla_edit.c index 5c9994e46d3..a3e9ca1c4a2 100644 --- a/source/blender/editors/space_nla/nla_edit.c +++ b/source/blender/editors/space_nla/nla_edit.c @@ -266,8 +266,8 @@ static void get_nlastrip_extents(bAnimContext *ac, float *min, float *max, const /* only consider selected strips? */ if ((onlySel == 0) || (strip->flag & NLASTRIP_FLAG_SELECT)) { /* extend range if appropriate */ - *min = MIN2(*min, strip->start); - *max = MAX2(*max, strip->end); + *min = minf(*min, strip->start); + *max = maxf(*max, strip->end); } } } diff --git a/source/blender/editors/space_node/CMakeLists.txt b/source/blender/editors/space_node/CMakeLists.txt index 2d926a50f98..793a167b929 100644 --- a/source/blender/editors/space_node/CMakeLists.txt +++ b/source/blender/editors/space_node/CMakeLists.txt @@ -42,9 +42,12 @@ set(INC_SYS set(SRC drawnode.c + node_add.c node_buttons.c node_draw.c node_edit.c + node_group.c + node_relationships.c node_header.c node_ops.c node_select.c diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index 134b2d6fd99..c3d9336ae64 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -217,16 +217,20 @@ static void node_draw_output_default(const bContext *C, uiBlock *block, float slen; int ofs = 0; const char *ui_name = IFACE_(name); + int len = strlen(ui_name); UI_ThemeColor(TH_TEXT); slen = (UI_GetStringWidth(ui_name) + NODE_MARGIN_X) * snode->aspect_sqrt; - while (slen > node->width) { + while (slen > node->width && ofs < len) { ofs++; slen = (UI_GetStringWidth(ui_name + ofs) + NODE_MARGIN_X) * snode->aspect_sqrt; } - uiDefBut(block, LABEL, 0, ui_name + ofs, - (int)(sock->locx - slen), (int)(sock->locy - 9.0f), - (short)(node->width - NODE_DY), (short)NODE_DY, - NULL, 0, 0, 0, 0, ""); + + if (ofs < len) { + uiDefBut(block, LABEL, 0, ui_name + ofs, + (int)(sock->locx - slen), (int)(sock->locy - 9.0f), + (short)(node->width - NODE_DY), (short)NODE_DY, + NULL, 0, 0, 0, 0, ""); + } (void)snode; } @@ -848,7 +852,7 @@ static void node_draw_group(const bContext *C, ARegion *ar, SpaceNode *snode, bN layout = uiBlockLayout(gnode->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, (int)(rect.xmin + NODE_MARGIN_X), (int)(rect.ymax + (group_header - (2.5f * dpi_fac))), - MIN2((int)(rect.xmax - rect.xmin - 18.0f), node_group_frame + 20), group_header, UI_GetStyle()); + mini((int)(rect.xmax - rect.xmin - 18.0f), node_group_frame + 20), group_header, UI_GetStyle()); RNA_pointer_create(&ntree->id, &RNA_Node, gnode, &ptr); uiTemplateIDBrowse(layout, (bContext *)C, &ptr, "node_tree", NULL, NULL, NULL); uiBlockLayoutResolve(gnode->block, NULL, NULL); @@ -1032,7 +1036,7 @@ static void node_draw_frame(const bContext *C, ARegion *ar, SpaceNode *snode, bN glDisable(GL_BLEND); /* outline active and selected emphasis */ - if (node->flag & (NODE_ACTIVE | SELECT)) { + if (node->flag & SELECT) { glEnable(GL_BLEND); glEnable(GL_LINE_SMOOTH); @@ -2490,10 +2494,24 @@ static void node_composit_buts_viewer_but(uiLayout *layout, bContext *UNUSED(C), static void node_composit_buts_mask(uiLayout *layout, bContext *C, PointerRNA *ptr) { + bNode *node = ptr->data; + uiTemplateID(layout, C, ptr, "mask", NULL, NULL, NULL); uiItemR(layout, ptr, "use_antialiasing", 0, NULL, ICON_NONE); uiItemR(layout, ptr, "use_feather", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "size_source", 0, "", ICON_NONE); + + if (node->custom1 & (CMP_NODEFLAG_MASK_FIXED | CMP_NODEFLAG_MASK_FIXED_SCENE)) { + uiItemR(layout, ptr, "size_x", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "size_y", 0, NULL, ICON_NONE); + } + + uiItemR(layout, ptr, "use_motion_blur", 0, NULL, ICON_NONE); + if (node->custom1 & CMP_NODEFLAG_MASK_MOTION_BLUR) { + uiItemR(layout, ptr, "motion_blur_samples", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "motion_blur_shutter", 0, NULL, ICON_NONE); + } } static void node_composit_buts_keyingscreen(uiLayout *layout, bContext *C, PointerRNA *ptr) @@ -2563,7 +2581,11 @@ static void node_composit_buts_trackpos(uiLayout *layout, bContext *C, PointerRN uiItemR(layout, ptr, "track_name", 0, "", ICON_ANIM_DATA); } - uiItemR(layout, ptr, "use_relative", 0, NULL, ICON_NONE); + uiItemR(layout, ptr, "position", 0, NULL, ICON_NONE); + + if (node->custom1 == 2) { + uiItemR(layout, ptr, "relative_frame", 0, NULL, ICON_NONE); + } } } @@ -2928,7 +2950,7 @@ static void node_texture_set_butfunc(bNodeType *ntype) /* ******* init draw callbacks for all tree types, only called in usiblender.c, once ************* */ -void ED_init_node_butfuncs(void) +void ED_node_init_butfuncs(void) { bNodeTreeType *treetype; bNodeType *ntype; @@ -3133,7 +3155,7 @@ static void draw_nodespace_back_tex(ScrArea *sa, SpaceNode *snode) float zoomx, zoomy; zoomx = (float)sa->winx / ibuf->x; zoomy = (float)sa->winy / ibuf->y; - zoom = MIN2(zoomx, zoomy); + zoom = minf(zoomx, zoomy); } x = (sa->winx - zoom * ibuf->x) / 2 + snode->xof; @@ -3476,7 +3498,7 @@ void node_draw_link(View2D *v2d, SpaceNode *snode, bNodeLink *link) // node_draw_link_straight(v2d, snode, link, th_col1, do_shaded, th_col2, do_triple, th_col3); } -void drawnodesnap(View2D *v2d, const float cent[2], float size, NodeBorder border) +void ED_node_draw_snap(View2D *v2d, const float cent[2], float size, NodeBorder border) { glBegin(GL_LINES); diff --git a/source/blender/editors/space_node/node_add.c b/source/blender/editors/space_node/node_add.c new file mode 100644 index 00000000000..5e58737606f --- /dev/null +++ b/source/blender/editors/space_node/node_add.c @@ -0,0 +1,431 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2005 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): David Millan Escriva, Juho Vepsäläinen, Nathan Letwory + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/editors/space_node/node_relationships.c + * \ingroup spnode + */ + +#include +#include +#include +#include +#include + +#include "MEM_guardedalloc.h" + +#include "DNA_ID.h" +#include "DNA_lamp_types.h" +#include "DNA_material_types.h" +#include "DNA_node_types.h" +#include "DNA_object_types.h" +#include "DNA_particle_types.h" +#include "DNA_scene_types.h" +#include "DNA_world_types.h" +#include "DNA_action_types.h" +#include "DNA_anim_types.h" + +#include "BLI_math.h" +#include "BLI_blenlib.h" +#include "BLI_utildefines.h" + +#include "BKE_action.h" +#include "BKE_animsys.h" +#include "BKE_context.h" +#include "BKE_depsgraph.h" +#include "BKE_global.h" +#include "BKE_image.h" +#include "BKE_library.h" +#include "BKE_main.h" +#include "BKE_node.h" +#include "BKE_material.h" +#include "BKE_modifier.h" +#include "BKE_paint.h" +#include "BKE_scene.h" +#include "BKE_screen.h" +#include "BKE_texture.h" +#include "BKE_report.h" + +#include "RE_pipeline.h" + +#include "IMB_imbuf_types.h" + +#include "ED_node.h" +#include "ED_image.h" +#include "ED_screen.h" +#include "ED_space_api.h" +#include "ED_render.h" + +#include "RNA_access.h" +#include "RNA_define.h" +#include "RNA_enum_types.h" + +#include "WM_api.h" +#include "WM_types.h" + +#include "UI_interface.h" +#include "UI_resources.h" +#include "UI_view2d.h" + +#include "IMB_imbuf.h" + +#include "RNA_enum_types.h" + +#include "GPU_material.h" + +#include "node_intern.h" +#include "NOD_socket.h" + + +/* can be called from menus too, but they should do own undopush and redraws */ +bNode *node_add_node(SpaceNode *snode, Main *bmain, Scene *scene, + bNodeTemplate *ntemp, float locx, float locy) +{ + bNode *node = NULL, *gnode; + + node_deselect_all(snode); + + node = nodeAddNode(snode->edittree, ntemp); + + /* generics */ + if (node) { + node_select(node); + + gnode = node_tree_get_editgroup(snode->nodetree); + // arbitrary y offset of 60 so its visible + if (gnode) { + nodeFromView(gnode, locx, locy + 60.0f, &node->locx, &node->locy); + } + else { + node->locx = locx; + node->locy = locy + 60.0f; + } + + ntreeUpdateTree(snode->edittree); + ED_node_set_active(bmain, snode->edittree, node); + + if (snode->nodetree->type == NTREE_COMPOSIT) { + if (ELEM4(node->type, CMP_NODE_R_LAYERS, CMP_NODE_COMPOSITE, CMP_NODE_DEFOCUS, CMP_NODE_OUTPUT_FILE)) { + node->id = &scene->id; + } + else if (ELEM3(node->type, CMP_NODE_MOVIECLIP, CMP_NODE_MOVIEDISTORTION, CMP_NODE_STABILIZE2D)) { + node->id = (ID *)scene->clip; + } + + ntreeCompositForceHidden(snode->edittree, scene); + } + + if (node->id) + id_us_plus(node->id); + + + if (snode->flag & SNODE_USE_HIDDEN_PREVIEW) + node->flag &= ~NODE_PREVIEW; + + snode_update(snode, node); + } + + if (snode->nodetree->type == NTREE_TEXTURE) { + ntreeTexCheckCyclics(snode->edittree); + } + + return node; +} + +/* ********************** Add reroute operator ***************** */ +static int add_reroute_intersect_check(bNodeLink *link, float mcoords[][2], int tot, float result[2]) +{ + float coord_array[NODE_LINK_RESOL + 1][2]; + int i, b; + + if (node_link_bezier_points(NULL, NULL, link, coord_array, NODE_LINK_RESOL)) { + + for (i = 0; i < tot - 1; i++) + for (b = 0; b < NODE_LINK_RESOL; b++) + if (isect_line_line_v2(mcoords[i], mcoords[i + 1], coord_array[b], coord_array[b + 1]) > 0) { + result[0] = (mcoords[i][0] + mcoords[i + 1][0]) / 2.0f; + result[1] = (mcoords[i][1] + mcoords[i + 1][1]) / 2.0f; + return 1; + } + } + return 0; +} + +static int add_reroute_exec(bContext *C, wmOperator *op) +{ + SpaceNode *snode = CTX_wm_space_node(C); + ARegion *ar = CTX_wm_region(C); + bNode *gnode = node_tree_get_editgroup(snode->nodetree); + float mcoords[256][2]; + int i = 0; + + RNA_BEGIN(op->ptr, itemptr, "path") + { + float loc[2]; + + RNA_float_get_array(&itemptr, "loc", loc); + UI_view2d_region_to_view(&ar->v2d, (short)loc[0], (short)loc[1], + &mcoords[i][0], &mcoords[i][1]); + i++; + if (i >= 256) break; + } + RNA_END; + + if (i > 1) { + bNodeLink *link; + float insertPoint[2]; + + ED_preview_kill_jobs(C); + + for (link = snode->edittree->links.first; link; link = link->next) { + if (add_reroute_intersect_check(link, mcoords, i, insertPoint)) { + bNodeTemplate ntemp; + bNode *rerouteNode; + + node_deselect_all(snode); + + ntemp.type = NODE_REROUTE; + rerouteNode = nodeAddNode(snode->edittree, &ntemp); + if (gnode) { + nodeFromView(gnode, insertPoint[0], insertPoint[1], &rerouteNode->locx, &rerouteNode->locy); + } + else { + rerouteNode->locx = insertPoint[0]; + rerouteNode->locy = insertPoint[1]; + } + + nodeAddLink(snode->edittree, link->fromnode, link->fromsock, rerouteNode, rerouteNode->inputs.first); + link->fromnode = rerouteNode; + link->fromsock = rerouteNode->outputs.first; + + break; // add one reroute at the time. + } + } + + ntreeUpdateTree(snode->edittree); + snode_notify(C, snode); + snode_dag_update(C, snode); + + return OPERATOR_FINISHED; + } + + return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH; +} + +void NODE_OT_add_reroute(wmOperatorType *ot) +{ + PropertyRNA *prop; + + ot->name = "Add reroute"; + ot->idname = "NODE_OT_add_reroute"; + + ot->invoke = WM_gesture_lines_invoke; + ot->modal = WM_gesture_lines_modal; + ot->exec = add_reroute_exec; + ot->cancel = WM_gesture_lines_cancel; + + ot->poll = ED_operator_node_active; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + prop = RNA_def_property(ot->srna, "path", PROP_COLLECTION, PROP_NONE); + RNA_def_property_struct_runtime(prop, &RNA_OperatorMousePath); + /* internal */ + RNA_def_int(ot->srna, "cursor", BC_CROSSCURSOR, 0, INT_MAX, "Cursor", "", 0, INT_MAX); +} + + +/* ****************** Add File Node Operator ******************* */ + +static int node_add_file_exec(bContext *C, wmOperator *op) +{ + Main *bmain = CTX_data_main(C); + Scene *scene = CTX_data_scene(C); + SpaceNode *snode = CTX_wm_space_node(C); + bNode *node; + Image *ima = NULL; + bNodeTemplate ntemp; + + /* check input variables */ + if (RNA_struct_property_is_set(op->ptr, "filepath")) { + char path[FILE_MAX]; + RNA_string_get(op->ptr, "filepath", path); + + errno = 0; + + ima = BKE_image_load_exists(path); + + if (!ima) { + BKE_reportf(op->reports, RPT_ERROR, "Can't read image: \"%s\", %s", path, errno ? strerror(errno) : "Unsupported format"); + return OPERATOR_CANCELLED; + } + } + else if (RNA_struct_property_is_set(op->ptr, "name")) { + char name[MAX_ID_NAME - 2]; + RNA_string_get(op->ptr, "name", name); + ima = (Image *)BKE_libblock_find_name(ID_IM, name); + + if (!ima) { + BKE_reportf(op->reports, RPT_ERROR, "Image named \"%s\", not found", name); + return OPERATOR_CANCELLED; + } + } + + node_deselect_all(snode); + + switch (snode->nodetree->type) { + case NTREE_SHADER: + ntemp.type = SH_NODE_TEX_IMAGE; + break; + case NTREE_TEXTURE: + ntemp.type = TEX_NODE_IMAGE; + break; + case NTREE_COMPOSIT: + ntemp.type = CMP_NODE_IMAGE; + break; + default: + return OPERATOR_CANCELLED; + } + + ED_preview_kill_jobs(C); + + node = node_add_node(snode, bmain, scene, &ntemp, snode->mx, snode->my); + + if (!node) { + BKE_report(op->reports, RPT_WARNING, "Could not add an image node"); + return OPERATOR_CANCELLED; + } + + node->id = (ID *)ima; + id_us_plus(node->id); + + snode_notify(C, snode); + snode_dag_update(C, snode); + + return OPERATOR_FINISHED; +} + +static int node_add_file_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + ARegion *ar = CTX_wm_region(C); + SpaceNode *snode = CTX_wm_space_node(C); + + /* convert mouse coordinates to v2d space */ + UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], + &snode->mx, &snode->my); + + if (RNA_struct_property_is_set(op->ptr, "filepath") || RNA_struct_property_is_set(op->ptr, "name")) + return node_add_file_exec(C, op); + else + return WM_operator_filesel(C, op, event); +} + +void NODE_OT_add_file(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Add File Node"; + ot->description = "Add a file node to the current node editor"; + ot->idname = "NODE_OT_add_file"; + + /* callbacks */ + ot->exec = node_add_file_exec; + ot->invoke = node_add_file_invoke; + ot->poll = ED_operator_node_active; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + WM_operator_properties_filesel(ot, FOLDERFILE | IMAGEFILE, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY); //XXX TODO, relative_path + RNA_def_string(ot->srna, "name", "Image", MAX_ID_NAME - 2, "Name", "Datablock name to assign"); +} + + +/********************** New node tree operator *********************/ + +static int new_node_tree_exec(bContext *C, wmOperator *op) +{ + SpaceNode *snode; + bNodeTree *ntree; + PointerRNA ptr, idptr; + PropertyRNA *prop; + int treetype; + char treename[MAX_ID_NAME - 2] = "NodeTree"; + + /* retrieve state */ + snode = CTX_wm_space_node(C); + + if (RNA_struct_property_is_set(op->ptr, "type")) + treetype = RNA_enum_get(op->ptr, "type"); + else + treetype = snode->treetype; + + if (RNA_struct_property_is_set(op->ptr, "name")) + RNA_string_get(op->ptr, "name", treename); + + ntree = ntreeAddTree(treename, treetype, 0); + if (!ntree) + return OPERATOR_CANCELLED; + + /* hook into UI */ + uiIDContextProperty(C, &ptr, &prop); + + if (prop) { + RNA_id_pointer_create(&ntree->id, &idptr); + RNA_property_pointer_set(&ptr, prop, idptr); + /* RNA_property_pointer_set increases the user count, + * fixed here as the editor is the initial user. + */ + --ntree->id.us; + RNA_property_update(C, &ptr, prop); + } + else if (snode) { + Scene *scene = CTX_data_scene(C); + snode->nodetree = ntree; + + ED_node_tree_update(snode, scene); + } + + return OPERATOR_FINISHED; +} + +void NODE_OT_new_node_tree(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "New Node Tree"; + ot->idname = "NODE_OT_new_node_tree"; + ot->description = "Create a new node tree"; + + /* api callbacks */ + ot->exec = new_node_tree_exec; + ot->poll = ED_operator_node_active; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + RNA_def_enum(ot->srna, "type", nodetree_type_items, NTREE_COMPOSIT, "Tree Type", ""); + RNA_def_string(ot->srna, "name", "NodeTree", MAX_ID_NAME - 2, "Name", ""); +} diff --git a/source/blender/editors/space_node/node_draw.c b/source/blender/editors/space_node/node_draw.c index 8c9f057efc1..92b1fca673d 100644 --- a/source/blender/editors/space_node/node_draw.c +++ b/source/blender/editors/space_node/node_draw.c @@ -413,7 +413,7 @@ static void node_update_basis(const bContext *C, bNodeTree *ntree, bNode *node) node->totr.xmin = locx; node->totr.xmax = locx + node->width; node->totr.ymax = locy; - node->totr.ymin = MIN2(dy, locy - 2 * NODE_DY); + node->totr.ymin = minf(dy, locy - 2 * NODE_DY); /* Set the block bounds to clip mouse events from underlying nodes. * Add a margin for sockets on each side. @@ -813,7 +813,7 @@ static void node_draw_basis(const bContext *C, ARegion *ar, SpaceNode *snode, bN glDisable(GL_BLEND); /* outline active and selected emphasis */ - if (node->flag & (NODE_ACTIVE | SELECT)) { + if (node->flag & SELECT) { glEnable(GL_BLEND); glEnable(GL_LINE_SMOOTH); diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c index a0df2aefab1..481c6544255 100644 --- a/source/blender/editors/space_node/node_edit.c +++ b/source/blender/editors/space_node/node_edit.c @@ -100,12 +100,6 @@ #include "node_intern.h" #include "NOD_socket.h" -static EnumPropertyItem socket_in_out_items[] = { - { SOCK_IN, "SOCK_IN", 0, "Input", "" }, - { SOCK_OUT, "SOCK_OUT", 0, "Output", "" }, - { 0, NULL, 0, NULL, NULL }, -}; - /* ***************** composite job manager ********************** */ typedef struct CompoJob { @@ -223,7 +217,7 @@ void snode_composite_job(const bContext *C, ScrArea *sa) /* ***************************************** */ /* operator poll callback */ -static int composite_node_active(bContext *C) +int composite_node_active(bContext *C) { if (ED_operator_node_active(C)) { SpaceNode *snode = CTX_wm_space_node(C); @@ -234,7 +228,7 @@ static int composite_node_active(bContext *C) } /* also checks for edited groups */ -static bNode *editnode_get_active(bNodeTree *ntree) +bNode *editnode_get_active(bNodeTree *ntree) { bNode *node; @@ -610,7 +604,7 @@ void snode_set_context(SpaceNode *snode, Scene *scene) node_tree_from_ID(snode->id, &snode->nodetree, &snode->edittree, NULL); } -static void snode_update(SpaceNode *snode, bNode *node) +void snode_update(SpaceNode *snode, bNode *node) { bNode *gnode; @@ -789,730 +783,6 @@ static void edit_node_properties_get(wmOperator *op, bNodeTree *ntree, bNode **r } #endif -/* ***************** Edit Group operator ************* */ - -void snode_make_group_editable(SpaceNode *snode, bNode *gnode) -{ - bNode *node; - - /* make sure nothing has group editing on */ - for (node = snode->nodetree->nodes.first; node; node = node->next) - nodeGroupEditClear(node); - - if (gnode == NULL) { - /* with NULL argument we do a toggle */ - if (snode->edittree == snode->nodetree) - gnode = nodeGetActive(snode->nodetree); - } - - if (gnode) { - snode->edittree = nodeGroupEditSet(gnode, 1); - - /* deselect all other nodes, so we can also do grabbing of entire subtree */ - for (node = snode->nodetree->nodes.first; node; node = node->next) - node_deselect(node); - node_select(gnode); - } - else - snode->edittree = snode->nodetree; -} - -static int node_group_edit_exec(bContext *C, wmOperator *UNUSED(op)) -{ - SpaceNode *snode = CTX_wm_space_node(C); - - ED_preview_kill_jobs(C); - - if (snode->nodetree == snode->edittree) { - bNode *gnode = nodeGetActive(snode->edittree); - snode_make_group_editable(snode, gnode); - } - else - snode_make_group_editable(snode, NULL); - - WM_event_add_notifier(C, NC_SCENE | ND_NODES, NULL); - - return OPERATOR_FINISHED; -} - -static int node_group_edit_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) -{ - SpaceNode *snode = CTX_wm_space_node(C); - bNode *gnode; - - /* XXX callback? */ - if (snode->nodetree == snode->edittree) { - gnode = nodeGetActive(snode->edittree); - if (gnode && gnode->id && GS(gnode->id->name) == ID_NT && gnode->id->lib) { - uiPupMenuOkee(C, op->type->idname, "Make group local?"); - return OPERATOR_CANCELLED; - } - } - - return node_group_edit_exec(C, op); -} - -void NODE_OT_group_edit(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Edit Group"; - ot->description = "Edit node group"; - ot->idname = "NODE_OT_group_edit"; - - /* api callbacks */ - ot->invoke = node_group_edit_invoke; - ot->exec = node_group_edit_exec; - ot->poll = ED_operator_node_active; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; -} - -/* ***************** Add Group Socket operator ************* */ - -static int node_group_socket_add_exec(bContext *C, wmOperator *op) -{ - SpaceNode *snode = CTX_wm_space_node(C); - int in_out = -1; - char name[MAX_NAME] = ""; - int type = SOCK_FLOAT; - bNodeTree *ngroup = snode->edittree; - /* bNodeSocket *sock; */ /* UNUSED */ - - ED_preview_kill_jobs(C); - - if (RNA_struct_property_is_set(op->ptr, "name")) - RNA_string_get(op->ptr, "name", name); - - if (RNA_struct_property_is_set(op->ptr, "type")) - type = RNA_enum_get(op->ptr, "type"); - - if (RNA_struct_property_is_set(op->ptr, "in_out")) - in_out = RNA_enum_get(op->ptr, "in_out"); - else - return OPERATOR_CANCELLED; - - /* using placeholder subtype first */ - /* sock = */ /* UNUSED */ node_group_add_socket(ngroup, name, type, in_out); - - ntreeUpdateTree(ngroup); - - snode_notify(C, snode); - - return OPERATOR_FINISHED; -} - -void NODE_OT_group_socket_add(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Add Group Socket"; - ot->description = "Add node group socket"; - ot->idname = "NODE_OT_group_socket_add"; - - /* api callbacks */ - ot->exec = node_group_socket_add_exec; - ot->poll = ED_operator_node_active; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - RNA_def_enum(ot->srna, "in_out", socket_in_out_items, SOCK_IN, "Socket Type", "Input or Output"); - RNA_def_string(ot->srna, "name", "", MAX_NAME, "Name", "Group socket name"); - RNA_def_enum(ot->srna, "type", node_socket_type_items, SOCK_FLOAT, "Type", "Type of the group socket"); -} - -/* ***************** Remove Group Socket operator ************* */ - -static int node_group_socket_remove_exec(bContext *C, wmOperator *op) -{ - SpaceNode *snode = CTX_wm_space_node(C); - int index = -1; - int in_out = -1; - bNodeTree *ngroup = snode->edittree; - bNodeSocket *sock; - - ED_preview_kill_jobs(C); - - if (RNA_struct_property_is_set(op->ptr, "index")) - index = RNA_int_get(op->ptr, "index"); - else - return OPERATOR_CANCELLED; - - if (RNA_struct_property_is_set(op->ptr, "in_out")) - in_out = RNA_enum_get(op->ptr, "in_out"); - else - return OPERATOR_CANCELLED; - - sock = (bNodeSocket *)BLI_findlink(in_out == SOCK_IN ? &ngroup->inputs : &ngroup->outputs, index); - if (sock) { - node_group_remove_socket(ngroup, sock, in_out); - ntreeUpdateTree(ngroup); - - snode_notify(C, snode); - } - - return OPERATOR_FINISHED; -} - -void NODE_OT_group_socket_remove(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Remove Group Socket"; - ot->description = "Remove a node group socket"; - ot->idname = "NODE_OT_group_socket_remove"; - - /* api callbacks */ - ot->exec = node_group_socket_remove_exec; - ot->poll = ED_operator_node_active; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "", 0, INT_MAX); - RNA_def_enum(ot->srna, "in_out", socket_in_out_items, SOCK_IN, "Socket Type", "Input or Output"); -} - -/* ***************** Move Group Socket Up operator ************* */ - -static int node_group_socket_move_up_exec(bContext *C, wmOperator *op) -{ - SpaceNode *snode = CTX_wm_space_node(C); - int index = -1; - int in_out = -1; - bNodeTree *ngroup = snode->edittree; - bNodeSocket *sock, *prev; - - ED_preview_kill_jobs(C); - - if (RNA_struct_property_is_set(op->ptr, "index")) - index = RNA_int_get(op->ptr, "index"); - else - return OPERATOR_CANCELLED; - - if (RNA_struct_property_is_set(op->ptr, "in_out")) - in_out = RNA_enum_get(op->ptr, "in_out"); - else - return OPERATOR_CANCELLED; - - /* swap */ - if (in_out == SOCK_IN) { - sock = (bNodeSocket *)BLI_findlink(&ngroup->inputs, index); - prev = sock->prev; - /* can't move up the first socket */ - if (!prev) - return OPERATOR_CANCELLED; - BLI_remlink(&ngroup->inputs, sock); - BLI_insertlinkbefore(&ngroup->inputs, prev, sock); - - ngroup->update |= NTREE_UPDATE_GROUP_IN; - } - else if (in_out == SOCK_OUT) { - sock = (bNodeSocket *)BLI_findlink(&ngroup->outputs, index); - prev = sock->prev; - /* can't move up the first socket */ - if (!prev) - return OPERATOR_CANCELLED; - BLI_remlink(&ngroup->outputs, sock); - BLI_insertlinkbefore(&ngroup->outputs, prev, sock); - - ngroup->update |= NTREE_UPDATE_GROUP_OUT; - } - ntreeUpdateTree(ngroup); - - snode_notify(C, snode); - - return OPERATOR_FINISHED; -} - -void NODE_OT_group_socket_move_up(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Move Group Socket Up"; - ot->description = "Move up node group socket"; - ot->idname = "NODE_OT_group_socket_move_up"; - - /* api callbacks */ - ot->exec = node_group_socket_move_up_exec; - ot->poll = ED_operator_node_active; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "", 0, INT_MAX); - RNA_def_enum(ot->srna, "in_out", socket_in_out_items, SOCK_IN, "Socket Type", "Input or Output"); -} - -/* ***************** Move Group Socket Up operator ************* */ - -static int node_group_socket_move_down_exec(bContext *C, wmOperator *op) -{ - SpaceNode *snode = CTX_wm_space_node(C); - int index = -1; - int in_out = -1; - bNodeTree *ngroup = snode->edittree; - bNodeSocket *sock, *next; - - ED_preview_kill_jobs(C); - - if (RNA_struct_property_is_set(op->ptr, "index")) - index = RNA_int_get(op->ptr, "index"); - else - return OPERATOR_CANCELLED; - - if (RNA_struct_property_is_set(op->ptr, "in_out")) - in_out = RNA_enum_get(op->ptr, "in_out"); - else - return OPERATOR_CANCELLED; - - /* swap */ - if (in_out == SOCK_IN) { - sock = (bNodeSocket *)BLI_findlink(&ngroup->inputs, index); - next = sock->next; - /* can't move down the last socket */ - if (!next) - return OPERATOR_CANCELLED; - BLI_remlink(&ngroup->inputs, sock); - BLI_insertlinkafter(&ngroup->inputs, next, sock); - - ngroup->update |= NTREE_UPDATE_GROUP_IN; - } - else if (in_out == SOCK_OUT) { - sock = (bNodeSocket *)BLI_findlink(&ngroup->outputs, index); - next = sock->next; - /* can't move down the last socket */ - if (!next) - return OPERATOR_CANCELLED; - BLI_remlink(&ngroup->outputs, sock); - BLI_insertlinkafter(&ngroup->outputs, next, sock); - - ngroup->update |= NTREE_UPDATE_GROUP_OUT; - } - ntreeUpdateTree(ngroup); - - snode_notify(C, snode); - - return OPERATOR_FINISHED; -} - -void NODE_OT_group_socket_move_down(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Move Group Socket Down"; - ot->description = "Move down node group socket"; - ot->idname = "NODE_OT_group_socket_move_down"; - - /* api callbacks */ - ot->exec = node_group_socket_move_down_exec; - ot->poll = ED_operator_node_active; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "", 0, INT_MAX); - RNA_def_enum(ot->srna, "in_out", socket_in_out_items, SOCK_IN, "Socket Type", "Input or Output"); -} - -/* ******************** Ungroup operator ********************** */ - -/* returns 1 if its OK */ -static int node_group_ungroup(bNodeTree *ntree, bNode *gnode) -{ - bNodeLink *link, *linkn; - bNode *node, *nextn; - bNodeTree *ngroup, *wgroup; - ListBase anim_basepaths = {NULL, NULL}; - - ngroup = (bNodeTree *)gnode->id; - if (ngroup == NULL) return 0; - - /* clear new pointers, set in copytree */ - for (node = ntree->nodes.first; node; node = node->next) - node->new_node = NULL; - - /* wgroup is a temporary copy of the NodeTree we're merging in - * - all of wgroup's nodes are transferred across to their new home - * - ngroup (i.e. the source NodeTree) is left unscathed - */ - wgroup = ntreeCopyTree(ngroup); - - /* add the nodes into the ntree */ - for (node = wgroup->nodes.first; node; node = nextn) { - nextn = node->next; - - /* keep track of this node's RNA "base" path (the part of the path identifying the node) - * if the old nodetree has animation data which potentially covers this node - */ - if (wgroup->adt) { - PointerRNA ptr; - char *path; - - RNA_pointer_create(&wgroup->id, &RNA_Node, node, &ptr); - path = RNA_path_from_ID_to_struct(&ptr); - - if (path) - BLI_addtail(&anim_basepaths, BLI_genericNodeN(path)); - } - - /* migrate node */ - BLI_remlink(&wgroup->nodes, node); - BLI_addtail(&ntree->nodes, node); - - /* ensure unique node name in the nodee tree */ - nodeUniqueName(ntree, node); - - node->locx += gnode->locx; - node->locy += gnode->locy; - - node->flag |= NODE_SELECT; - } - - /* restore external links to and from the gnode */ - for (link = ntree->links.first; link; link = link->next) { - if (link->fromnode == gnode) { - if (link->fromsock->groupsock) { - bNodeSocket *gsock = link->fromsock->groupsock; - if (gsock->link) { - if (gsock->link->fromnode) { - /* NB: using the new internal copies here! the groupsock pointer still maps to the old tree */ - link->fromnode = (gsock->link->fromnode ? gsock->link->fromnode->new_node : NULL); - link->fromsock = gsock->link->fromsock->new_sock; - } - else { - /* group output directly maps to group input */ - bNodeSocket *insock = node_group_find_input(gnode, gsock->link->fromsock); - if (insock->link) { - link->fromnode = insock->link->fromnode; - link->fromsock = insock->link->fromsock; - } - } - } - else { - /* copy the default input value from the group socket default to the external socket */ - node_socket_convert_default_value(link->tosock->type, link->tosock->default_value, gsock->type, gsock->default_value); - } - } - } - } - /* remove internal output links, these are not used anymore */ - for (link = wgroup->links.first; link; link = linkn) { - linkn = link->next; - if (!link->tonode) - nodeRemLink(wgroup, link); - } - /* restore links from internal nodes */ - for (link = wgroup->links.first; link; link = linkn) { - linkn = link->next; - /* indicates link to group input */ - if (!link->fromnode) { - /* NB: can't use find_group_node_input here, - * because gnode sockets still point to the old tree! - */ - bNodeSocket *insock; - for (insock = gnode->inputs.first; insock; insock = insock->next) - if (insock->groupsock->new_sock == link->fromsock) - break; - if (insock->link) { - link->fromnode = insock->link->fromnode; - link->fromsock = insock->link->fromsock; - } - else { - /* copy the default input value from the group node socket default to the internal socket */ - node_socket_convert_default_value(link->tosock->type, link->tosock->default_value, insock->type, insock->default_value); - nodeRemLink(wgroup, link); - } - } - } - - /* add internal links to the ntree */ - for (link = wgroup->links.first; link; link = linkn) { - linkn = link->next; - BLI_remlink(&wgroup->links, link); - BLI_addtail(&ntree->links, link); - } - - /* and copy across the animation, - * note that the animation data's action can be NULL here */ - if (wgroup->adt) { - LinkData *ld, *ldn = NULL; - bAction *waction; - - /* firstly, wgroup needs to temporary dummy action that can be destroyed, as it shares copies */ - waction = wgroup->adt->action = BKE_action_copy(wgroup->adt->action); - - /* now perform the moving */ - BKE_animdata_separate_by_basepath(&wgroup->id, &ntree->id, &anim_basepaths); - - /* paths + their wrappers need to be freed */ - for (ld = anim_basepaths.first; ld; ld = ldn) { - ldn = ld->next; - - MEM_freeN(ld->data); - BLI_freelinkN(&anim_basepaths, ld); - } - - /* free temp action too */ - if (waction) { - BKE_libblock_free(&G.main->action, waction); - } - } - - /* delete the group instance. this also removes old input links! */ - nodeFreeNode(ntree, gnode); - - /* free the group tree (takes care of user count) */ - BKE_libblock_free(&G.main->nodetree, wgroup); - - ntree->update |= NTREE_UPDATE_NODES | NTREE_UPDATE_LINKS; - - return 1; -} - -static int node_group_ungroup_exec(bContext *C, wmOperator *op) -{ - SpaceNode *snode = CTX_wm_space_node(C); - bNode *gnode; - - ED_preview_kill_jobs(C); - - /* are we inside of a group? */ - gnode = node_tree_get_editgroup(snode->nodetree); - if (gnode) - snode_make_group_editable(snode, NULL); - - gnode = nodeGetActive(snode->edittree); - if (gnode == NULL) - return OPERATOR_CANCELLED; - - if (gnode->type != NODE_GROUP) { - BKE_report(op->reports, RPT_WARNING, "Not a group"); - return OPERATOR_CANCELLED; - } - else if (node_group_ungroup(snode->nodetree, gnode)) { - ntreeUpdateTree(snode->nodetree); - } - else { - BKE_report(op->reports, RPT_WARNING, "Can't ungroup"); - return OPERATOR_CANCELLED; - } - - snode_notify(C, snode); - snode_dag_update(C, snode); - - return OPERATOR_FINISHED; -} - -void NODE_OT_group_ungroup(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Ungroup"; - ot->description = "Ungroup selected nodes"; - ot->idname = "NODE_OT_group_ungroup"; - - /* api callbacks */ - ot->exec = node_group_ungroup_exec; - ot->poll = ED_operator_node_active; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; -} - -/* ******************** Separate operator ********************** */ - -/* returns 1 if its OK */ -static int node_group_separate_selected(bNodeTree *ntree, bNode *gnode, int make_copy) -{ - bNodeLink *link, *link_next; - bNode *node, *node_next, *newnode; - bNodeTree *ngroup; - ListBase anim_basepaths = {NULL, NULL}; - - ngroup = (bNodeTree *)gnode->id; - if (ngroup == NULL) return 0; - - /* deselect all nodes in the target tree */ - for (node = ntree->nodes.first; node; node = node->next) - node_deselect(node); - - /* clear new pointers, set in nodeCopyNode */ - for (node = ngroup->nodes.first; node; node = node->next) - node->new_node = NULL; - - /* add selected nodes into the ntree */ - for (node = ngroup->nodes.first; node; node = node_next) { - node_next = node->next; - if (!(node->flag & NODE_SELECT)) - continue; - - if (make_copy) { - /* make a copy */ - newnode = nodeCopyNode(ngroup, node); - } - else { - /* use the existing node */ - newnode = node; - } - - /* keep track of this node's RNA "base" path (the part of the path identifying the node) - * if the old nodetree has animation data which potentially covers this node - */ - if (ngroup->adt) { - PointerRNA ptr; - char *path; - - RNA_pointer_create(&ngroup->id, &RNA_Node, newnode, &ptr); - path = RNA_path_from_ID_to_struct(&ptr); - - if (path) - BLI_addtail(&anim_basepaths, BLI_genericNodeN(path)); - } - - /* ensure valid parent pointers, detach if parent stays inside the group */ - if (newnode->parent && !(newnode->parent->flag & NODE_SELECT)) - nodeDetachNode(newnode); - - /* migrate node */ - BLI_remlink(&ngroup->nodes, newnode); - BLI_addtail(&ntree->nodes, newnode); - - /* ensure unique node name in the node tree */ - nodeUniqueName(ntree, newnode); - - newnode->locx += gnode->locx; - newnode->locy += gnode->locy; - } - - /* add internal links to the ntree */ - for (link = ngroup->links.first; link; link = link_next) { - int fromselect = (link->fromnode && (link->fromnode->flag & NODE_SELECT)); - int toselect = (link->tonode && (link->tonode->flag & NODE_SELECT)); - link_next = link->next; - - if (make_copy) { - /* make a copy of internal links */ - if (fromselect && toselect) - nodeAddLink(ntree, link->fromnode->new_node, link->fromsock->new_sock, link->tonode->new_node, link->tosock->new_sock); - } - else { - /* move valid links over, delete broken links */ - if (fromselect && toselect) { - BLI_remlink(&ngroup->links, link); - BLI_addtail(&ntree->links, link); - } - else if (fromselect || toselect) { - nodeRemLink(ngroup, link); - } - } - } - - /* and copy across the animation, - * note that the animation data's action can be NULL here */ - if (ngroup->adt) { - LinkData *ld, *ldn = NULL; - - /* now perform the moving */ - BKE_animdata_separate_by_basepath(&ngroup->id, &ntree->id, &anim_basepaths); - - /* paths + their wrappers need to be freed */ - for (ld = anim_basepaths.first; ld; ld = ldn) { - ldn = ld->next; - - MEM_freeN(ld->data); - BLI_freelinkN(&anim_basepaths, ld); - } - } - - ntree->update |= NTREE_UPDATE_NODES | NTREE_UPDATE_LINKS; - if (!make_copy) - ngroup->update |= NTREE_UPDATE_NODES | NTREE_UPDATE_LINKS; - - return 1; -} - -typedef enum eNodeGroupSeparateType { - NODE_GS_COPY, - NODE_GS_MOVE -} eNodeGroupSeparateType; - -/* Operator Property */ -EnumPropertyItem node_group_separate_types[] = { - {NODE_GS_COPY, "COPY", 0, "Copy", "Copy to parent node tree, keep group intact"}, - {NODE_GS_MOVE, "MOVE", 0, "Move", "Move to parent node tree, remove from group"}, - {0, NULL, 0, NULL, NULL} -}; - -static int node_group_separate_exec(bContext *C, wmOperator *op) -{ - SpaceNode *snode = CTX_wm_space_node(C); - bNode *gnode; - int type = RNA_enum_get(op->ptr, "type"); - - ED_preview_kill_jobs(C); - - /* are we inside of a group? */ - gnode = node_tree_get_editgroup(snode->nodetree); - if (!gnode) { - BKE_report(op->reports, RPT_WARNING, "Not inside node group"); - return OPERATOR_CANCELLED; - } - - switch (type) { - case NODE_GS_COPY: - if (!node_group_separate_selected(snode->nodetree, gnode, 1)) { - BKE_report(op->reports, RPT_WARNING, "Can't separate nodes"); - return OPERATOR_CANCELLED; - } - break; - case NODE_GS_MOVE: - if (!node_group_separate_selected(snode->nodetree, gnode, 0)) { - BKE_report(op->reports, RPT_WARNING, "Can't separate nodes"); - return OPERATOR_CANCELLED; - } - break; - } - - /* switch to parent tree */ - snode_make_group_editable(snode, NULL); - - ntreeUpdateTree(snode->nodetree); - - snode_notify(C, snode); - snode_dag_update(C, snode); - - return OPERATOR_FINISHED; -} - -static int node_group_separate_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *UNUSED(event)) -{ - uiPopupMenu *pup = uiPupMenuBegin(C, "Separate", ICON_NONE); - uiLayout *layout = uiPupMenuLayout(pup); - - uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT); - uiItemEnumO(layout, "NODE_OT_group_separate", NULL, 0, "type", NODE_GS_COPY); - uiItemEnumO(layout, "NODE_OT_group_separate", NULL, 0, "type", NODE_GS_MOVE); - - uiPupMenuEnd(C, pup); - - return OPERATOR_CANCELLED; -} - -void NODE_OT_group_separate(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Separate"; - ot->description = "Separate selected nodes from the node group"; - ot->idname = "NODE_OT_group_separate"; - - /* api callbacks */ - ot->invoke = node_group_separate_invoke; - ot->exec = node_group_separate_exec; - ot->poll = ED_operator_node_active; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - RNA_def_enum(ot->srna, "type", node_group_separate_types, NODE_GS_COPY, "Type", ""); -} - /* ************************** Node generic ************** */ /* is rct in visible part of node? */ @@ -1562,8 +832,6 @@ static int snode_bg_viewmove_modal(bContext *C, wmOperator *op, wmEvent *event) MEM_freeN(nvm); op->customdata = NULL; - - WM_event_add_notifier(C, NC_SPACE | ND_SPACE_NODE, NULL); return OPERATOR_FINISHED; } @@ -2070,140 +1338,6 @@ void node_set_hidden_sockets(SpaceNode *snode, bNode *node, int set) } } -static int node_link_viewer(const bContext *C, bNode *tonode) -{ - SpaceNode *snode = CTX_wm_space_node(C); - bNode *node; - bNodeLink *link; - bNodeSocket *sock; - - /* context check */ - if (tonode == NULL || tonode->outputs.first == NULL) - return OPERATOR_CANCELLED; - if (ELEM(tonode->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) - return OPERATOR_CANCELLED; - - /* get viewer */ - for (node = snode->edittree->nodes.first; node; node = node->next) - if (ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) - if (node->flag & NODE_DO_OUTPUT) - break; - /* no viewer, we make one active */ - if (node == NULL) { - for (node = snode->edittree->nodes.first; node; node = node->next) { - if (ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) { - node->flag |= NODE_DO_OUTPUT; - break; - } - } - } - - sock = NULL; - - /* try to find an already connected socket to cycle to the next */ - if (node) { - link = NULL; - for (link = snode->edittree->links.first; link; link = link->next) - if (link->tonode == node && link->fromnode == tonode) - if (link->tosock == node->inputs.first) - break; - if (link) { - /* unlink existing connection */ - sock = link->fromsock; - nodeRemLink(snode->edittree, link); - - /* find a socket after the previously connected socket */ - for (sock = sock->next; sock; sock = sock->next) - if (!nodeSocketIsHidden(sock)) - break; - } - } - - /* find a socket starting from the first socket */ - if (!sock) { - for (sock = tonode->outputs.first; sock; sock = sock->next) - if (!nodeSocketIsHidden(sock)) - break; - } - - if (sock) { - /* add a new viewer if none exists yet */ - if (!node) { - Main *bmain = CTX_data_main(C); - Scene *scene = CTX_data_scene(C); - bNodeTemplate ntemp; - - ntemp.type = CMP_NODE_VIEWER; - /* XXX location is a quick hack, just place it next to the linked socket */ - node = node_add_node(snode, bmain, scene, &ntemp, sock->locx + 100, sock->locy); - if (!node) - return OPERATOR_CANCELLED; - - link = NULL; - } - else { - /* get link to viewer */ - for (link = snode->edittree->links.first; link; link = link->next) - if (link->tonode == node && link->tosock == node->inputs.first) - break; - } - - if (link == NULL) { - nodeAddLink(snode->edittree, tonode, sock, node, node->inputs.first); - } - else { - link->fromnode = tonode; - link->fromsock = sock; - /* make sure the dependency sorting is updated */ - snode->edittree->update |= NTREE_UPDATE_LINKS; - } - ntreeUpdateTree(snode->edittree); - snode_update(snode, node); - } - - return OPERATOR_FINISHED; -} - - -static int node_active_link_viewer(bContext *C, wmOperator *UNUSED(op)) -{ - SpaceNode *snode = CTX_wm_space_node(C); - bNode *node; - - node = editnode_get_active(snode->edittree); - - if (!node) - return OPERATOR_CANCELLED; - - ED_preview_kill_jobs(C); - - if (node_link_viewer(C, node) == OPERATOR_CANCELLED) - return OPERATOR_CANCELLED; - - snode_notify(C, snode); - - return OPERATOR_FINISHED; -} - - - -void NODE_OT_link_viewer(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Link to Viewer Node"; - ot->description = "Link to viewer node"; - ot->idname = "NODE_OT_link_viewer"; - - /* api callbacks */ - ot->exec = node_active_link_viewer; - ot->poll = composite_node_active; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; -} - - - /* return 0, nothing done */ static int UNUSED_FUNCTION(node_mouse_groupheader) (SpaceNode * snode) { @@ -2320,274 +1454,6 @@ int node_find_indicated_socket(SpaceNode *snode, bNode **nodep, bNodeSocket **so return 0; } -static int outside_group_rect(SpaceNode *snode) -{ - bNode *gnode = node_tree_get_editgroup(snode->nodetree); - if (gnode) { - return (snode->mx < gnode->totr.xmin || - snode->mx >= gnode->totr.xmax || - snode->my < gnode->totr.ymin || - snode->my >= gnode->totr.ymax); - } - return 0; -} - -/* ****************** Add *********************** */ - - -typedef struct bNodeListItem { - struct bNodeListItem *next, *prev; - struct bNode *node; -} bNodeListItem; - -static int sort_nodes_locx(void *a, void *b) -{ - bNodeListItem *nli1 = (bNodeListItem *)a; - bNodeListItem *nli2 = (bNodeListItem *)b; - bNode *node1 = nli1->node; - bNode *node2 = nli2->node; - - if (node1->locx > node2->locx) - return 1; - else - return 0; -} - -static int socket_is_available(bNodeTree *UNUSED(ntree), bNodeSocket *sock, int allow_used) -{ - if (nodeSocketIsHidden(sock)) - return 0; - - if (!allow_used && (sock->flag & SOCK_IN_USE)) - return 0; - - return 1; -} - -static bNodeSocket *best_socket_output(bNodeTree *ntree, bNode *node, bNodeSocket *sock_target, int allow_multiple) -{ - bNodeSocket *sock; - - /* first look for selected output */ - for (sock = node->outputs.first; sock; sock = sock->next) { - if (!socket_is_available(ntree, sock, allow_multiple)) - continue; - - if (sock->flag & SELECT) - return sock; - } - - /* try to find a socket with a matching name */ - for (sock = node->outputs.first; sock; sock = sock->next) { - if (!socket_is_available(ntree, sock, allow_multiple)) - continue; - - /* check for same types */ - if (sock->type == sock_target->type) { - if (strcmp(sock->name, sock_target->name) == 0) - return sock; - } - } - - /* otherwise settle for the first available socket of the right type */ - for (sock = node->outputs.first; sock; sock = sock->next) { - - if (!socket_is_available(ntree, sock, allow_multiple)) - continue; - - /* check for same types */ - if (sock->type == sock_target->type) { - return sock; - } - } - - return NULL; -} - -/* this is a bit complicated, but designed to prioritize finding - * sockets of higher types, such as image, first */ -static bNodeSocket *best_socket_input(bNodeTree *ntree, bNode *node, int num, int replace) -{ - bNodeSocket *sock; - int socktype, maxtype = 0; - int a = 0; - - for (sock = node->inputs.first; sock; sock = sock->next) { - maxtype = MAX2(sock->type, maxtype); - } - - /* find sockets of higher 'types' first (i.e. image) */ - for (socktype = maxtype; socktype >= 0; socktype--) { - for (sock = node->inputs.first; sock; sock = sock->next) { - - if (!socket_is_available(ntree, sock, replace)) { - a++; - continue; - } - - if (sock->type == socktype) { - /* increment to make sure we don't keep finding - * the same socket on every attempt running this function */ - a++; - if (a > num) - return sock; - } - } - } - - return NULL; -} - -static int snode_autoconnect_input(SpaceNode *snode, bNode *node_fr, bNodeSocket *sock_fr, bNode *node_to, bNodeSocket *sock_to, int replace) -{ - bNodeTree *ntree = snode->edittree; - bNodeLink *link; - - /* then we can connect */ - if (replace) - nodeRemSocketLinks(ntree, sock_to); - - link = nodeAddLink(ntree, node_fr, sock_fr, node_to, sock_to); - /* validate the new link */ - ntreeUpdateTree(ntree); - if (!(link->flag & NODE_LINK_VALID)) { - nodeRemLink(ntree, link); - return 0; - } - - snode_update(snode, node_to); - return 1; -} - -void snode_autoconnect(SpaceNode *snode, int allow_multiple, int replace) -{ - bNodeTree *ntree = snode->edittree; - ListBase *nodelist = MEM_callocN(sizeof(ListBase), "items_list"); - bNodeListItem *nli; - bNode *node; - int i, numlinks = 0; - - for (node = ntree->nodes.first; node; node = node->next) { - if (node->flag & NODE_SELECT) { - nli = MEM_mallocN(sizeof(bNodeListItem), "temporary node list item"); - nli->node = node; - BLI_addtail(nodelist, nli); - } - } - - /* sort nodes left to right */ - BLI_sortlist(nodelist, sort_nodes_locx); - - for (nli = nodelist->first; nli; nli = nli->next) { - bNode *node_fr, *node_to; - bNodeSocket *sock_fr, *sock_to; - int has_selected_inputs = 0; - - if (nli->next == NULL) break; - - node_fr = nli->node; - node_to = nli->next->node; - - /* if there are selected sockets, connect those */ - for (sock_to = node_to->inputs.first; sock_to; sock_to = sock_to->next) { - if (sock_to->flag & SELECT) { - has_selected_inputs = 1; - - if (!socket_is_available(ntree, sock_to, replace)) - continue; - - /* check for an appropriate output socket to connect from */ - sock_fr = best_socket_output(ntree, node_fr, sock_to, allow_multiple); - if (!sock_fr) - continue; - - if (snode_autoconnect_input(snode, node_fr, sock_fr, node_to, sock_to, replace)) - ++numlinks; - } - } - - if (!has_selected_inputs) { - /* no selected inputs, connect by finding suitable match */ - int num_inputs = BLI_countlist(&node_to->inputs); - - for (i = 0; i < num_inputs; i++) { - - /* find the best guess input socket */ - sock_to = best_socket_input(ntree, node_to, i, replace); - if (!sock_to) - continue; - - /* check for an appropriate output socket to connect from */ - sock_fr = best_socket_output(ntree, node_fr, sock_to, allow_multiple); - if (!sock_fr) - continue; - - if (snode_autoconnect_input(snode, node_fr, sock_fr, node_to, sock_to, replace)) { - ++numlinks; - break; - } - } - } - } - - if (numlinks > 0) { - ntreeUpdateTree(ntree); - } - - BLI_freelistN(nodelist); - MEM_freeN(nodelist); -} - -/* can be called from menus too, but they should do own undopush and redraws */ -bNode *node_add_node(SpaceNode *snode, Main *bmain, Scene *scene, bNodeTemplate *ntemp, float locx, float locy) -{ - bNode *node = NULL, *gnode; - - node_deselect_all(snode); - - node = nodeAddNode(snode->edittree, ntemp); - - /* generics */ - if (node) { - node_select(node); - - gnode = node_tree_get_editgroup(snode->nodetree); - // arbitrary y offset of 60 so its visible - if (gnode) { - nodeFromView(gnode, locx, locy + 60.0f, &node->locx, &node->locy); - } - else { - node->locx = locx; - node->locy = locy + 60.0f; - } - - ntreeUpdateTree(snode->edittree); - ED_node_set_active(bmain, snode->edittree, node); - - if (snode->nodetree->type == NTREE_COMPOSIT) { - if (ELEM4(node->type, CMP_NODE_R_LAYERS, CMP_NODE_COMPOSITE, CMP_NODE_DEFOCUS, CMP_NODE_OUTPUT_FILE)) { - node->id = &scene->id; - } - else if (ELEM3(node->type, CMP_NODE_MOVIECLIP, CMP_NODE_MOVIEDISTORTION, CMP_NODE_STABILIZE2D)) { - node->id = (ID *)scene->clip; - } - - ntreeCompositForceHidden(snode->edittree, scene); - } - - if (node->id) - id_us_plus(node->id); - - snode_update(snode, node); - } - - if (snode->nodetree->type == NTREE_TEXTURE) { - ntreeTexCheckCyclics(snode->edittree); - } - - return node; -} - /* ****************** Duplicate *********************** */ static void node_duplicate_reparent_recursive(bNode *node) @@ -2727,770 +1593,19 @@ void NODE_OT_duplicate(wmOperatorType *ot) RNA_def_boolean(ot->srna, "keep_inputs", 0, "Keep Inputs", "Keep the input links to duplicated nodes"); } -/* *************************** add link op ******************** */ - -static void node_remove_extra_links(SpaceNode *snode, bNodeSocket *tsock, bNodeLink *link) -{ - bNodeLink *tlink; - bNodeSocket *sock; - - if (tsock && nodeCountSocketLinks(snode->edittree, link->tosock) > tsock->limit) { - - for (tlink = snode->edittree->links.first; tlink; tlink = tlink->next) { - if (link != tlink && tlink->tosock == link->tosock) - break; - } - if (tlink) { - /* try to move the existing link to the next available socket */ - if (tlink->tonode) { - /* is there a free input socket with the target type? */ - for (sock = tlink->tonode->inputs.first; sock; sock = sock->next) { - if (sock->type == tlink->tosock->type) - if (nodeCountSocketLinks(snode->edittree, sock) < sock->limit) - break; - } - if (sock) { - tlink->tosock = sock; - sock->flag &= ~SOCK_HIDDEN; - } - else { - nodeRemLink(snode->edittree, tlink); - } - } - else - nodeRemLink(snode->edittree, tlink); - - snode->edittree->update |= NTREE_UPDATE_LINKS; - } - } -} - -/* loop that adds a nodelink, called by function below */ -/* in_out = starting socket */ -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; - bNodeTree *ntree = snode->edittree; - bNode *tnode; - bNodeSocket *tsock = NULL; - bNodeLink *link; - LinkData *linkdata; - int in_out; - - in_out = nldrag->in_out; - - UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], - &snode->mx, &snode->my); - - switch (event->type) { - case MOUSEMOVE: - - if (in_out == SOCK_OUT) { - if (node_find_indicated_socket(snode, &tnode, &tsock, SOCK_IN)) { - 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 (BLI_findindex(&ntree->links, link) < 0) - BLI_addtail(&ntree->links, link); - - ntree->update |= NTREE_UPDATE_LINKS; - } - ntreeUpdateTree(ntree); - } - else { - int do_update = FALSE; - for (linkdata = nldrag->links.first; linkdata; linkdata = linkdata->next) { - link = linkdata->data; - - if (link->tonode || link->tosock) { - BLI_remlink(&ntree->links, link); - link->prev = link->next = NULL; - link->tonode = NULL; - link->tosock = NULL; - - ntree->update |= NTREE_UPDATE_LINKS; - do_update = TRUE; - } - } - if (do_update) { - ntreeUpdateTree(ntree); - } - } - } - else { - if (node_find_indicated_socket(snode, &tnode, &tsock, SOCK_OUT)) { - 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 (BLI_findindex(&ntree->links, link) < 0) - BLI_addtail(&ntree->links, link); - - ntree->update |= NTREE_UPDATE_LINKS; - } - ntreeUpdateTree(ntree); - } - else { - int do_update = FALSE; - for (linkdata = nldrag->links.first; linkdata; linkdata = linkdata->next) { - link = linkdata->data; - - if (link->fromnode || link->fromsock) { - BLI_remlink(&ntree->links, link); - link->prev = link->next = NULL; - link->fromnode = NULL; - link->fromsock = NULL; - - ntree->update |= NTREE_UPDATE_LINKS; - do_update = TRUE; - } - } - if (do_update) { - ntreeUpdateTree(ntree); - } - } - } - - ED_region_tag_redraw(ar); - break; - - case LEFTMOUSE: - case RIGHTMOUSE: - case MIDDLEMOUSE: { - for (linkdata = nldrag->links.first; linkdata; linkdata = linkdata->next) { - link = linkdata->data; - - 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); - } - } - 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(ntree, link->tosock, SOCK_IN); - link->fromnode = NULL; - if (BLI_findindex(&ntree->links, link) < 0) - BLI_addtail(&ntree->links, link); - - ntree->update |= NTREE_UPDATE_GROUP_IN | NTREE_UPDATE_LINKS; - } - else if (link->fromnode && link->fromsock) { - link->tosock = node_group_expose_socket(ntree, link->fromsock, SOCK_OUT); - link->tonode = NULL; - if (BLI_findindex(&ntree->links, link) < 0) - BLI_addtail(&ntree->links, link); - - ntree->update |= NTREE_UPDATE_GROUP_OUT | NTREE_UPDATE_LINKS; - } - } - else - nodeRemLink(ntree, link); - } - - ntreeUpdateTree(ntree); - 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 bNodeLinkDrag *node_link_init(SpaceNode *snode, int detach) +int ED_node_select_check(ListBase *lb) { 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, &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; - oplink->next = oplink->prev = NULL; - BLI_addtail(&nldrag->links, linkdata); - nodeRemLink(snode->edittree, link); - } - } - } - else { - /* 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); + + for (node = lb->first; node; node = node->next) { + if (node->flag & NODE_SELECT) { + return TRUE; } } - /* or an input? */ - 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; - oplink->next = oplink->prev = NULL; - BLI_addtail(&nldrag->links, linkdata); - nodeRemLink(snode->edittree, link); - - /* send changed event to original link->tonode */ - if (node) - snode_update(snode, node); - } - } - } - else { - /* 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 nldrag; + + return FALSE; } -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; - 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 = node_link_init(snode, detach); - - if (nldrag) { - op->customdata = nldrag; - BLI_addtail(&snode->linkdrag, nldrag); - - /* add modal handler */ - WM_event_add_modal_handler(C, op); - - return OPERATOR_RUNNING_MODAL; - } - 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; - - BLI_remlink(&snode->linkdrag, nldrag); - - BLI_freelistN(&nldrag->links); - MEM_freeN(nldrag); - - return OPERATOR_CANCELLED; -} - -void NODE_OT_link(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Link Nodes"; - ot->idname = "NODE_OT_link"; - ot->description = "Use the mouse to create a link between two nodes"; - - /* api callbacks */ - ot->invoke = node_link_invoke; - ot->modal = node_link_modal; -// ot->exec = node_link_exec; - ot->poll = ED_operator_node_active; - ot->cancel = node_link_cancel; - - /* 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 ***************** */ - -/* makes a link between selected output and input sockets */ -static int node_make_link_exec(bContext *C, wmOperator *op) -{ - SpaceNode *snode = CTX_wm_space_node(C); - int replace = RNA_boolean_get(op->ptr, "replace"); - - ED_preview_kill_jobs(C); - - snode_autoconnect(snode, 1, replace); - - /* deselect sockets after linking */ - node_deselect_all_input_sockets(snode, 0); - node_deselect_all_output_sockets(snode, 0); - - ntreeUpdateTree(snode->edittree); - snode_notify(C, snode); - snode_dag_update(C, snode); - - return OPERATOR_FINISHED; -} - -void NODE_OT_link_make(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Make Links"; - ot->description = "Makes a link between selected output in input sockets"; - ot->idname = "NODE_OT_link_make"; - - /* callbacks */ - ot->exec = node_make_link_exec; - ot->poll = ED_operator_node_active; // XXX we need a special poll which checks that there are selected input/output sockets - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - RNA_def_boolean(ot->srna, "replace", 0, "Replace", "Replace socket connections with the new links"); -} - -/* ********************** Add reroute operator ***************** */ -#define LINK_RESOL 12 -static int add_reroute_intersect_check(bNodeLink *link, float mcoords[][2], int tot, float result[2]) -{ - float coord_array[LINK_RESOL + 1][2]; - int i, b; - - if (node_link_bezier_points(NULL, NULL, link, coord_array, LINK_RESOL)) { - - for (i = 0; i < tot - 1; i++) - for (b = 0; b < LINK_RESOL; b++) - if (isect_line_line_v2(mcoords[i], mcoords[i + 1], coord_array[b], coord_array[b + 1]) > 0) { - result[0] = (mcoords[i][0] + mcoords[i + 1][0]) / 2.0f; - result[1] = (mcoords[i][1] + mcoords[i + 1][1]) / 2.0f; - return 1; - } - } - return 0; -} - -static int add_reroute_exec(bContext *C, wmOperator *op) -{ - SpaceNode *snode = CTX_wm_space_node(C); - ARegion *ar = CTX_wm_region(C); - bNode *gnode = node_tree_get_editgroup(snode->nodetree); - float mcoords[256][2]; - int i = 0; - - RNA_BEGIN(op->ptr, itemptr, "path") - { - float loc[2]; - - RNA_float_get_array(&itemptr, "loc", loc); - UI_view2d_region_to_view(&ar->v2d, (short)loc[0], (short)loc[1], - &mcoords[i][0], &mcoords[i][1]); - i++; - if (i >= 256) break; - } - RNA_END; - - if (i > 1) { - bNodeLink *link; - float insertPoint[2]; - - ED_preview_kill_jobs(C); - - for (link = snode->edittree->links.first; link; link = link->next) { - if (add_reroute_intersect_check(link, mcoords, i, insertPoint)) { - bNodeTemplate ntemp; - bNode *rerouteNode; - - node_deselect_all(snode); - - ntemp.type = NODE_REROUTE; - rerouteNode = nodeAddNode(snode->edittree, &ntemp); - if (gnode) { - nodeFromView(gnode, insertPoint[0], insertPoint[1], &rerouteNode->locx, &rerouteNode->locy); - } - else { - rerouteNode->locx = insertPoint[0]; - rerouteNode->locy = insertPoint[1]; - } - - nodeAddLink(snode->edittree, link->fromnode, link->fromsock, rerouteNode, rerouteNode->inputs.first); - link->fromnode = rerouteNode; - link->fromsock = rerouteNode->outputs.first; - - break; // add one reroute at the time. - } - } - - ntreeUpdateTree(snode->edittree); - snode_notify(C, snode); - snode_dag_update(C, snode); - - return OPERATOR_FINISHED; - } - - return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH; -} - -void NODE_OT_add_reroute(wmOperatorType *ot) -{ - PropertyRNA *prop; - - ot->name = "Add reroute"; - ot->idname = "NODE_OT_add_reroute"; - - ot->invoke = WM_gesture_lines_invoke; - ot->modal = WM_gesture_lines_modal; - ot->exec = add_reroute_exec; - ot->cancel = WM_gesture_lines_cancel; - - ot->poll = ED_operator_node_active; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - prop = RNA_def_property(ot->srna, "path", PROP_COLLECTION, PROP_NONE); - RNA_def_property_struct_runtime(prop, &RNA_OperatorMousePath); - /* internal */ - RNA_def_int(ot->srna, "cursor", BC_CROSSCURSOR, 0, INT_MAX, "Cursor", "", 0, INT_MAX); -} - - -/* ********************** Cut Link operator ***************** */ -static int cut_links_intersect(bNodeLink *link, float mcoords[][2], int tot) -{ - float coord_array[LINK_RESOL + 1][2]; - int i, b; - - if (node_link_bezier_points(NULL, NULL, link, coord_array, LINK_RESOL)) { - - for (i = 0; i < tot - 1; i++) - for (b = 0; b < LINK_RESOL; b++) - if (isect_line_line_v2(mcoords[i], mcoords[i + 1], coord_array[b], coord_array[b + 1]) > 0) - return 1; - } - return 0; -} - -static int cut_links_exec(bContext *C, wmOperator *op) -{ - SpaceNode *snode = CTX_wm_space_node(C); - ARegion *ar = CTX_wm_region(C); - float mcoords[256][2]; - int i = 0; - - RNA_BEGIN(op->ptr, itemptr, "path") - { - float loc[2]; - - RNA_float_get_array(&itemptr, "loc", loc); - UI_view2d_region_to_view(&ar->v2d, (int)loc[0], (int)loc[1], - &mcoords[i][0], &mcoords[i][1]); - i++; - if (i >= 256) break; - } - RNA_END; - - if (i > 1) { - bNodeLink *link, *next; - - ED_preview_kill_jobs(C); - - for (link = snode->edittree->links.first; link; link = next) { - next = link->next; - - if (cut_links_intersect(link, mcoords, i)) { - snode_update(snode, link->tonode); - nodeRemLink(snode->edittree, link); - } - } - - ntreeUpdateTree(snode->edittree); - snode_notify(C, snode); - snode_dag_update(C, snode); - - return OPERATOR_FINISHED; - } - - return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH; -} - -void NODE_OT_links_cut(wmOperatorType *ot) -{ - PropertyRNA *prop; - - ot->name = "Cut links"; - ot->idname = "NODE_OT_links_cut"; - ot->description = "Use the mouse to cut (remove) some links"; - - ot->invoke = WM_gesture_lines_invoke; - ot->modal = WM_gesture_lines_modal; - ot->exec = cut_links_exec; - ot->cancel = WM_gesture_lines_cancel; - - ot->poll = ED_operator_node_active; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - prop = RNA_def_property(ot->srna, "path", PROP_COLLECTION, PROP_NONE); - RNA_def_property_struct_runtime(prop, &RNA_OperatorMousePath); - /* internal */ - RNA_def_int(ot->srna, "cursor", BC_KNIFECURSOR, 0, INT_MAX, "Cursor", "", 0, INT_MAX); -} - -/* ********************** Detach links operator ***************** */ - -static int detach_links_exec(bContext *C, wmOperator *UNUSED(op)) -{ - SpaceNode *snode = CTX_wm_space_node(C); - bNodeTree *ntree = snode->edittree; - bNode *node; - - ED_preview_kill_jobs(C); - - for (node = ntree->nodes.first; node; node = node->next) { - if (node->flag & SELECT) { - nodeInternalRelink(ntree, node); - } - } - - ntreeUpdateTree(ntree); - - snode_notify(C, snode); - snode_dag_update(C, snode); - - return OPERATOR_FINISHED; -} - -void NODE_OT_links_detach(wmOperatorType *ot) -{ - ot->name = "Detach Links"; - ot->idname = "NODE_OT_links_detach"; - ot->description = "Remove all links to selected nodes, and try to connect neighbor nodes together"; - - ot->exec = detach_links_exec; - ot->poll = ED_operator_node_active; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; -} - -/* ********************* automatic node insert on dragging ******************* */ - -/* assumes sockets in list */ -static bNodeSocket *socket_best_match(ListBase *sockets) -{ - bNodeSocket *sock; - int type, maxtype = 0; - - /* find type range */ - for (sock = sockets->first; sock; sock = sock->next) - maxtype = MAX2(sock->type, maxtype); - - /* try all types, starting from 'highest' (i.e. colors, vectors, values) */ - for (type = maxtype; type >= 0; --type) { - for (sock = sockets->first; sock; sock = sock->next) { - if (!nodeSocketIsHidden(sock) && type == sock->type) { - return sock; - } - } - } - - /* no visible sockets, unhide first of highest type */ - for (type = maxtype; type >= 0; --type) { - for (sock = sockets->first; sock; sock = sock->next) { - if (type == sock->type) { - sock->flag &= ~SOCK_HIDDEN; - return sock; - } - } - } - - return NULL; -} - -/* prevent duplicate testing code below */ -static SpaceNode *ed_node_link_conditions(ScrArea *sa, bNode **select) -{ - SpaceNode *snode = sa ? sa->spacedata.first : NULL; - bNode *node; - bNodeLink *link; - - /* no unlucky accidents */ - if (sa == NULL || sa->spacetype != SPACE_NODE) return NULL; - - *select = NULL; - - for (node = snode->edittree->nodes.first; node; node = node->next) { - if (node->flag & SELECT) { - if (*select) - break; - else - *select = node; - } - } - /* only one selected */ - if (node || *select == NULL) return NULL; - - /* correct node */ - if ((*select)->inputs.first == NULL || (*select)->outputs.first == NULL) return NULL; - - /* test node for links */ - for (link = snode->edittree->links.first; link; link = link->next) { - if (link->tonode == *select || link->fromnode == *select) - return NULL; - } - - return snode; -} - -/* assumes link with NODE_LINKFLAG_HILITE set */ -void ED_node_link_insert(ScrArea *sa) -{ - bNode *node, *select; - SpaceNode *snode = ed_node_link_conditions(sa, &select); - bNodeLink *link; - bNodeSocket *sockto; - - if (snode == NULL) return; - - /* get the link */ - for (link = snode->edittree->links.first; link; link = link->next) - if (link->flag & NODE_LINKFLAG_HILITE) - break; - - if (link) { - node = link->tonode; - sockto = link->tosock; - - link->tonode = select; - link->tosock = socket_best_match(&select->inputs); - link->flag &= ~NODE_LINKFLAG_HILITE; - - nodeAddLink(snode->edittree, select, socket_best_match(&select->outputs), node, sockto); - ntreeUpdateTree(snode->edittree); /* needed for pointers */ - snode_update(snode, select); - ED_node_changed_update(snode->id, select); - } -} - - -/* test == 0, clear all intersect flags */ -void ED_node_link_intersect_test(ScrArea *sa, int test) -{ - bNode *select; - SpaceNode *snode = ed_node_link_conditions(sa, &select); - bNodeLink *link, *selink = NULL; - float mcoords[6][2]; - - if (snode == NULL) return; - - /* clear flags */ - for (link = snode->edittree->links.first; link; link = link->next) - link->flag &= ~NODE_LINKFLAG_HILITE; - - if (test == 0) return; - - /* okay, there's 1 node, without links, now intersect */ - mcoords[0][0] = select->totr.xmin; - mcoords[0][1] = select->totr.ymin; - mcoords[1][0] = select->totr.xmax; - mcoords[1][1] = select->totr.ymin; - mcoords[2][0] = select->totr.xmax; - mcoords[2][1] = select->totr.ymax; - mcoords[3][0] = select->totr.xmin; - mcoords[3][1] = select->totr.ymax; - mcoords[4][0] = select->totr.xmin; - mcoords[4][1] = select->totr.ymin; - mcoords[5][0] = select->totr.xmax; - mcoords[5][1] = select->totr.ymax; - - /* we only tag a single link for intersect now */ - /* idea; use header dist when more? */ - for (link = snode->edittree->links.first; link; link = link->next) { - - if (cut_links_intersect(link, mcoords, 5)) { /* intersect code wants edges */ - if (selink) - break; - selink = link; - } - } - - if (link == NULL && selink) - selink->flag |= NODE_LINKFLAG_HILITE; -} - - /* ******************************** */ // XXX some code needing updating to operators... @@ -3611,7 +1726,6 @@ int node_render_changed_exec(bContext *C, wmOperator *UNUSED(op)) void NODE_OT_render_changed(wmOperatorType *ot) { - ot->name = "Render Changed Layer"; ot->idname = "NODE_OT_render_changed"; ot->description = "Render current scene, when input node's layer has been changed"; @@ -3624,326 +1738,6 @@ void NODE_OT_render_changed(wmOperatorType *ot) ot->flag = 0; } - -/* ****************** Make Group operator ******************* */ - -static int node_group_make_test(bNodeTree *ntree, bNode *gnode) -{ - bNode *node; - bNodeLink *link; - int totnode = 0; - - /* is there something to group? also do some clearing */ - for (node = ntree->nodes.first; node; node = node->next) { - if (node == gnode) - continue; - - if (node->flag & NODE_SELECT) { - /* no groups in groups */ - if (node->type == NODE_GROUP) - return 0; - totnode++; - } - - node->done = 0; - } - if (totnode == 0) return 0; - - /* check if all connections are OK, no unselected node has both - * inputs and outputs to a selection */ - for (link = ntree->links.first; link; link = link->next) { - if (link->fromnode && link->tonode && link->fromnode->flag & NODE_SELECT && link->fromnode != gnode) - link->tonode->done |= 1; - if (link->fromnode && link->tonode && link->tonode->flag & NODE_SELECT && link->tonode != gnode) - link->fromnode->done |= 2; - } - - for (node = ntree->nodes.first; node; node = node->next) { - if (node == gnode) - continue; - if ((node->flag & NODE_SELECT) == 0) - if (node->done == 3) - break; - } - if (node) - return 0; - - return 1; -} - -static void node_get_selected_minmax(bNodeTree *ntree, bNode *gnode, float *min, float *max) -{ - bNode *node; - INIT_MINMAX2(min, max); - for (node = ntree->nodes.first; node; node = node->next) { - if (node == gnode) - continue; - if (node->flag & NODE_SELECT) { - DO_MINMAX2((&node->locx), min, max); - } - } -} - -static int node_group_make_insert_selected(bNodeTree *ntree, bNode *gnode) -{ - bNodeTree *ngroup = (bNodeTree *)gnode->id; - bNodeLink *link, *linkn; - bNode *node, *nextn; - bNodeSocket *gsock; - ListBase anim_basepaths = {NULL, NULL}; - float min[2], max[2]; - - /* deselect all nodes in the target tree */ - for (node = ngroup->nodes.first; node; node = node->next) - node_deselect(node); - - node_get_selected_minmax(ntree, gnode, min, max); - - /* move nodes over */ - for (node = ntree->nodes.first; node; node = nextn) { - nextn = node->next; - if (node == gnode) - continue; - if (node->flag & NODE_SELECT) { - /* keep track of this node's RNA "base" path (the part of the pat identifying the node) - * if the old nodetree has animation data which potentially covers this node - */ - if (ntree->adt) { - PointerRNA ptr; - char *path; - - RNA_pointer_create(&ntree->id, &RNA_Node, node, &ptr); - path = RNA_path_from_ID_to_struct(&ptr); - - if (path) - BLI_addtail(&anim_basepaths, BLI_genericNodeN(path)); - } - - /* ensure valid parent pointers, detach if parent stays outside the group */ - if (node->parent && !(node->parent->flag & NODE_SELECT)) - nodeDetachNode(node); - - /* change node-collection membership */ - BLI_remlink(&ntree->nodes, node); - BLI_addtail(&ngroup->nodes, node); - - /* ensure unique node name in the ngroup */ - nodeUniqueName(ngroup, node); - - node->locx -= 0.5f * (min[0] + max[0]); - node->locy -= 0.5f * (min[1] + max[1]); - } - } - - /* move animation data over */ - if (ntree->adt) { - LinkData *ld, *ldn = NULL; - - BKE_animdata_separate_by_basepath(&ntree->id, &ngroup->id, &anim_basepaths); - - /* paths + their wrappers need to be freed */ - for (ld = anim_basepaths.first; ld; ld = ldn) { - ldn = ld->next; - - MEM_freeN(ld->data); - BLI_freelinkN(&anim_basepaths, ld); - } - } - - /* node groups don't use internal cached data */ - ntreeFreeCache(ngroup); - - /* relink external sockets */ - for (link = ntree->links.first; link; link = linkn) { - int fromselect = (link->fromnode && (link->fromnode->flag & NODE_SELECT) && link->fromnode != gnode); - int toselect = (link->tonode && (link->tonode->flag & NODE_SELECT) && link->tonode != gnode); - linkn = link->next; - - if (gnode && ((fromselect && link->tonode == gnode) || (toselect && link->fromnode == gnode))) { - /* remove all links to/from the gnode. - * this can remove link information, but there's no general way to preserve it. - */ - nodeRemLink(ntree, link); - } - else if (fromselect && toselect) { - BLI_remlink(&ntree->links, link); - BLI_addtail(&ngroup->links, link); - } - else if (toselect) { - gsock = node_group_expose_socket(ngroup, link->tosock, SOCK_IN); - link->tosock->link = nodeAddLink(ngroup, NULL, gsock, link->tonode, link->tosock); - link->tosock = node_group_add_extern_socket(ntree, &gnode->inputs, SOCK_IN, gsock); - link->tonode = gnode; - } - else if (fromselect) { - /* search for existing group node socket */ - for (gsock = ngroup->outputs.first; gsock; gsock = gsock->next) - if (gsock->link && gsock->link->fromsock == link->fromsock) - break; - if (!gsock) { - gsock = node_group_expose_socket(ngroup, link->fromsock, SOCK_OUT); - gsock->link = nodeAddLink(ngroup, link->fromnode, link->fromsock, NULL, gsock); - link->fromsock = node_group_add_extern_socket(ntree, &gnode->outputs, SOCK_OUT, gsock); - } - else - link->fromsock = node_group_find_output(gnode, gsock); - link->fromnode = gnode; - } - } - - /* update of the group tree */ - ngroup->update |= NTREE_UPDATE; - /* update of the tree containing the group instance node */ - ntree->update |= NTREE_UPDATE_NODES | NTREE_UPDATE_LINKS; - - return 1; -} - -static bNode *node_group_make_from_selected(bNodeTree *ntree) -{ - bNode *gnode; - bNodeTree *ngroup; - float min[2], max[2]; - bNodeTemplate ntemp; - - node_get_selected_minmax(ntree, NULL, min, max); - - /* new nodetree */ - ngroup = ntreeAddTree("NodeGroup", ntree->type, NODE_GROUP); - - /* make group node */ - ntemp.type = NODE_GROUP; - ntemp.ngroup = ngroup; - gnode = nodeAddNode(ntree, &ntemp); - gnode->locx = 0.5f * (min[0] + max[0]); - gnode->locy = 0.5f * (min[1] + max[1]); - - node_group_make_insert_selected(ntree, gnode); - - /* update of the tree containing the group instance node */ - ntree->update |= NTREE_UPDATE_NODES; - - return gnode; -} - -typedef enum eNodeGroupMakeType { - NODE_GM_NEW, - NODE_GM_INSERT -} eNodeGroupMakeType; - -/* Operator Property */ -EnumPropertyItem node_group_make_types[] = { - {NODE_GM_NEW, "NEW", 0, "New", "Create a new node group from selected nodes"}, - {NODE_GM_INSERT, "INSERT", 0, "Insert", "Insert into active node group"}, - {0, NULL, 0, NULL, NULL} -}; - -static int node_group_make_exec(bContext *C, wmOperator *op) -{ - SpaceNode *snode = CTX_wm_space_node(C); - bNode *gnode; - int type = RNA_enum_get(op->ptr, "type"); - - if (snode->edittree != snode->nodetree) { - BKE_report(op->reports, RPT_WARNING, "Can not add a new Group in a Group"); - return OPERATOR_CANCELLED; - } - - /* for time being... is too complex to handle */ - if (snode->treetype == NTREE_COMPOSIT) { - for (gnode = snode->nodetree->nodes.first; gnode; gnode = gnode->next) { - if (gnode->flag & SELECT) - if (gnode->type == CMP_NODE_R_LAYERS) - break; - } - - if (gnode) { - BKE_report(op->reports, RPT_WARNING, "Can not add RenderLayer in a Group"); - return OPERATOR_CANCELLED; - } - } - - ED_preview_kill_jobs(C); - - switch (type) { - case NODE_GM_NEW: - if (node_group_make_test(snode->nodetree, NULL)) { - gnode = node_group_make_from_selected(snode->nodetree); - } - else { - BKE_report(op->reports, RPT_WARNING, "Can not make Group"); - return OPERATOR_CANCELLED; - } - break; - case NODE_GM_INSERT: - gnode = nodeGetActive(snode->nodetree); - if (!gnode || gnode->type != NODE_GROUP) { - BKE_report(op->reports, RPT_WARNING, "No active Group node"); - return OPERATOR_CANCELLED; - } - if (node_group_make_test(snode->nodetree, gnode)) { - node_group_make_insert_selected(snode->nodetree, gnode); - } - else { - BKE_report(op->reports, RPT_WARNING, "Can not insert into Group"); - return OPERATOR_CANCELLED; - } - break; - } - - if (gnode) { - nodeSetActive(snode->nodetree, gnode); - snode_make_group_editable(snode, gnode); - } - - if (gnode) - ntreeUpdateTree((bNodeTree *)gnode->id); - ntreeUpdateTree(snode->nodetree); - - snode_notify(C, snode); - snode_dag_update(C, snode); - - return OPERATOR_FINISHED; -} - -static int node_group_make_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *UNUSED(event)) -{ - SpaceNode *snode = CTX_wm_space_node(C); - bNode *act = nodeGetActive(snode->edittree); - uiPopupMenu *pup = uiPupMenuBegin(C, "Make Group", ICON_NONE); - uiLayout *layout = uiPupMenuLayout(pup); - - uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT); - uiItemEnumO(layout, "NODE_OT_group_make", NULL, 0, "type", NODE_GM_NEW); - - /* if active node is a group, add insert option */ - if (act && act->type == NODE_GROUP) { - uiItemEnumO(layout, "NODE_OT_group_make", NULL, 0, "type", NODE_GM_INSERT); - } - - uiPupMenuEnd(C, pup); - - return OPERATOR_CANCELLED; -} - -void NODE_OT_group_make(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Group"; - ot->description = "Make group from selected nodes"; - ot->idname = "NODE_OT_group_make"; - - /* api callbacks */ - ot->invoke = node_group_make_invoke; - ot->exec = node_group_make_exec; - ot->poll = ED_operator_node_active; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - RNA_def_enum(ot->srna, "type", node_group_make_types, NODE_GM_NEW, "Type", ""); -} - /* ****************** Hide operator *********************** */ static void node_flag_toggle_exec(SpaceNode *snode, int toggle_flag) @@ -4251,202 +2045,6 @@ void NODE_OT_delete_reconnect(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } -/* ****************** Show Cyclic Dependencies Operator ******************* */ - -static int node_show_cycles_exec(bContext *C, wmOperator *UNUSED(op)) -{ - SpaceNode *snode = CTX_wm_space_node(C); - - /* this is just a wrapper around this call... */ - ntreeUpdateTree(snode->nodetree); - snode_notify(C, snode); - - return OPERATOR_FINISHED; -} - -void NODE_OT_show_cyclic_dependencies(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Show Cyclic Dependencies"; - ot->description = "Sort the nodes and show the cyclic dependencies between the nodes"; - ot->idname = "NODE_OT_show_cyclic_dependencies"; - - /* callbacks */ - ot->exec = node_show_cycles_exec; - ot->poll = ED_operator_node_active; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; -} - -/* ****************** Add File Node Operator ******************* */ - -static int node_add_file_exec(bContext *C, wmOperator *op) -{ - Main *bmain = CTX_data_main(C); - Scene *scene = CTX_data_scene(C); - SpaceNode *snode = CTX_wm_space_node(C); - bNode *node; - Image *ima = NULL; - bNodeTemplate ntemp; - - /* check input variables */ - if (RNA_struct_property_is_set(op->ptr, "filepath")) { - char path[FILE_MAX]; - RNA_string_get(op->ptr, "filepath", path); - - errno = 0; - - ima = BKE_image_load_exists(path); - - if (!ima) { - BKE_reportf(op->reports, RPT_ERROR, "Can't read: \"%s\", %s", path, errno ? strerror(errno) : "Unsupported image format"); - return OPERATOR_CANCELLED; - } - } - else if (RNA_struct_property_is_set(op->ptr, "name")) { - char name[MAX_ID_NAME - 2]; - RNA_string_get(op->ptr, "name", name); - ima = (Image *)BKE_libblock_find_name(ID_IM, name); - - if (!ima) { - BKE_reportf(op->reports, RPT_ERROR, "Image named \"%s\", not found", name); - return OPERATOR_CANCELLED; - } - } - - node_deselect_all(snode); - - switch (snode->nodetree->type) { - case NTREE_SHADER: - ntemp.type = SH_NODE_TEX_IMAGE; - break; - case NTREE_TEXTURE: - ntemp.type = TEX_NODE_IMAGE; - break; - case NTREE_COMPOSIT: - ntemp.type = CMP_NODE_IMAGE; - break; - default: - return OPERATOR_CANCELLED; - } - - ED_preview_kill_jobs(C); - - node = node_add_node(snode, bmain, scene, &ntemp, snode->mx, snode->my); - - if (!node) { - BKE_report(op->reports, RPT_WARNING, "Could not add an image node"); - return OPERATOR_CANCELLED; - } - - node->id = (ID *)ima; - - snode_notify(C, snode); - snode_dag_update(C, snode); - - return OPERATOR_FINISHED; -} - -static int node_add_file_invoke(bContext *C, wmOperator *op, wmEvent *event) -{ - ARegion *ar = CTX_wm_region(C); - SpaceNode *snode = CTX_wm_space_node(C); - - /* convert mouse coordinates to v2d space */ - UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], - &snode->mx, &snode->my); - - if (RNA_struct_property_is_set(op->ptr, "filepath") || RNA_struct_property_is_set(op->ptr, "name")) - return node_add_file_exec(C, op); - else - return WM_operator_filesel(C, op, event); -} - -void NODE_OT_add_file(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Add File Node"; - ot->description = "Add a file node to the current node editor"; - ot->idname = "NODE_OT_add_file"; - - /* callbacks */ - ot->exec = node_add_file_exec; - ot->invoke = node_add_file_invoke; - ot->poll = ED_operator_node_active; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - WM_operator_properties_filesel(ot, FOLDERFILE | IMAGEFILE, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY); //XXX TODO, relative_path - RNA_def_string(ot->srna, "name", "Image", MAX_ID_NAME - 2, "Name", "Datablock name to assign"); -} - -/********************** New node tree operator *********************/ - -static int new_node_tree_exec(bContext *C, wmOperator *op) -{ - SpaceNode *snode; - bNodeTree *ntree; - PointerRNA ptr, idptr; - PropertyRNA *prop; - int treetype; - char treename[MAX_ID_NAME - 2] = "NodeTree"; - - /* retrieve state */ - snode = CTX_wm_space_node(C); - - if (RNA_struct_property_is_set(op->ptr, "type")) - treetype = RNA_enum_get(op->ptr, "type"); - else - treetype = snode->treetype; - - if (RNA_struct_property_is_set(op->ptr, "name")) - RNA_string_get(op->ptr, "name", treename); - - ntree = ntreeAddTree(treename, treetype, 0); - if (!ntree) - return OPERATOR_CANCELLED; - - /* hook into UI */ - uiIDContextProperty(C, &ptr, &prop); - - if (prop) { - RNA_id_pointer_create(&ntree->id, &idptr); - RNA_property_pointer_set(&ptr, prop, idptr); - /* RNA_property_pointer_set increases the user count, - * fixed here as the editor is the initial user. - */ - --ntree->id.us; - RNA_property_update(C, &ptr, prop); - } - else if (snode) { - Scene *scene = CTX_data_scene(C); - snode->nodetree = ntree; - - ED_node_tree_update(snode, scene); - } - - return OPERATOR_FINISHED; -} - -void NODE_OT_new_node_tree(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "New Node Tree"; - ot->idname = "NODE_OT_new_node_tree"; - ot->description = "Create a new node tree"; - - /* api callbacks */ - ot->exec = new_node_tree_exec; - ot->poll = ED_operator_node_active; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - - RNA_def_enum(ot->srna, "type", nodetree_type_items, NTREE_COMPOSIT, "Tree Type", ""); - RNA_def_string(ot->srna, "name", "NodeTree", MAX_ID_NAME - 2, "Name", ""); -} /* ****************** File Output Add Socket ******************* */ @@ -4458,18 +2056,18 @@ static int node_output_file_add_socket_exec(bContext *C, wmOperator *op) bNodeTree *ntree; bNode *node; char file_path[MAX_NAME]; - + ptr = CTX_data_pointer_get(C, "node"); if (!ptr.data) return OPERATOR_CANCELLED; node = ptr.data; ntree = ptr.id.data; - + RNA_string_get(op->ptr, "file_path", file_path); ntreeCompositOutputFileAddSocket(ntree, node, file_path, &scene->r.im_format); - + snode_notify(C, snode); - + return OPERATOR_FINISHED; } @@ -4479,14 +2077,14 @@ void NODE_OT_output_file_add_socket(wmOperatorType *ot) ot->name = "Add File Node Socket"; ot->description = "Add a new input to a file output node"; ot->idname = "NODE_OT_output_file_add_socket"; - + /* callbacks */ ot->exec = node_output_file_add_socket_exec; ot->poll = composite_node_active; - + /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; - + RNA_def_string(ot->srna, "file_path", "Image", MAX_NAME, "File Path", "Sub-path of the output file"); } @@ -4639,308 +2237,3 @@ void NODE_OT_node_copy_color(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } - -/* ****************** Set Parent ******************* */ - -static int node_parent_set_exec(bContext *C, wmOperator *UNUSED(op)) -{ - SpaceNode *snode = CTX_wm_space_node(C); - bNodeTree *ntree = snode->edittree; - bNode *frame = nodeGetActive(ntree), *node; - if (!frame || frame->type != NODE_FRAME) - return OPERATOR_CANCELLED; - - for (node = ntree->nodes.first; node; node = node->next) { - if (node == frame) - continue; - if (node->flag & NODE_SELECT) { - nodeDetachNode(node); - nodeAttachNode(node, frame); - } - } - - ED_node_sort(ntree); - WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); - - return OPERATOR_FINISHED; -} - -void NODE_OT_parent_set(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Make Parent"; - ot->description = "Attach selected nodes"; - ot->idname = "NODE_OT_parent_set"; - - /* api callbacks */ - ot->exec = node_parent_set_exec; - ot->poll = ED_operator_node_active; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; -} - -/* ****************** Clear Parent ******************* */ - -static int node_parent_clear_exec(bContext *C, wmOperator *UNUSED(op)) -{ - SpaceNode *snode = CTX_wm_space_node(C); - bNodeTree *ntree = snode->edittree; - bNode *node; - - for (node = ntree->nodes.first; node; node = node->next) { - if (node->flag & NODE_SELECT) { - nodeDetachNode(node); - } - } - - WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); - - return OPERATOR_FINISHED; -} - -void NODE_OT_parent_clear(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Clear Parent"; - ot->description = "Detach selected nodes"; - ot->idname = "NODE_OT_parent_clear"; - - /* api callbacks */ - ot->exec = node_parent_clear_exec; - ot->poll = ED_operator_node_active; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; -} - -/* ****************** Join Nodes ******************* */ - -/* tags for depth-first search */ -#define NODE_JOIN_DONE 1 -#define NODE_JOIN_IS_DESCENDANT 2 - -static void node_join_attach_recursive(bNode *node, bNode *frame) -{ - node->done |= NODE_JOIN_DONE; - - if (node == frame) { - node->done |= NODE_JOIN_IS_DESCENDANT; - } - else if (node->parent) { - /* call recursively */ - if (!(node->parent->done & NODE_JOIN_DONE)) - node_join_attach_recursive(node->parent, frame); - - /* in any case: if the parent is a descendant, so is the child */ - if (node->parent->done & NODE_JOIN_IS_DESCENDANT) - node->done |= NODE_JOIN_IS_DESCENDANT; - else if (node->flag & NODE_TEST) { - /* if parent is not an decendant of the frame, reattach the node */ - nodeDetachNode(node); - nodeAttachNode(node, frame); - node->done |= NODE_JOIN_IS_DESCENDANT; - } - } - else if (node->flag & NODE_TEST) { - nodeAttachNode(node, frame); - node->done |= NODE_JOIN_IS_DESCENDANT; - } -} - -static int node_join_exec(bContext *C, wmOperator *UNUSED(op)) -{ - SpaceNode *snode = CTX_wm_space_node(C); - Main *bmain = CTX_data_main(C); - Scene *scene = CTX_data_scene(C); - bNodeTree *ntree = snode->edittree; - bNode *node, *frame; - bNodeTemplate ntemp; - - /* XXX save selection: node_add_node call below sets the new frame as single active+selected node */ - for (node = ntree->nodes.first; node; node = node->next) { - if (node->flag & NODE_SELECT) - node->flag |= NODE_TEST; - else - node->flag &= ~NODE_TEST; - } - - ntemp.main = bmain; - ntemp.scene = scene; - ntemp.type = NODE_FRAME; - frame = node_add_node(snode, bmain, scene, &ntemp, 0.0f, 0.0f); - - /* reset tags */ - for (node = ntree->nodes.first; node; node = node->next) - node->done = 0; - - for (node = ntree->nodes.first; node; node = node->next) { - if (!(node->done & NODE_JOIN_DONE)) - node_join_attach_recursive(node, frame); - } - - /* restore selection */ - for (node = ntree->nodes.first; node; node = node->next) { - if (node->flag & NODE_TEST) - node->flag |= NODE_SELECT; - } - - ED_node_sort(ntree); - WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); - - return OPERATOR_FINISHED; -} - -void NODE_OT_join(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Join Nodes"; - ot->description = "Attach selected nodes to a new common frame"; - ot->idname = "NODE_OT_join"; - - /* api callbacks */ - ot->exec = node_join_exec; - ot->poll = ED_operator_node_active; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; -} - -/* ****************** Attach ******************* */ - -static int node_attach_exec(bContext *C, wmOperator *UNUSED(op)) -{ - SpaceNode *snode = CTX_wm_space_node(C); - bNodeTree *ntree = snode->edittree; - bNode *frame; - - /* check nodes front to back */ - for (frame = ntree->nodes.last; frame; frame = frame->prev) { - /* skip selected, those are the nodes we want to attach */ - if ((frame->type != NODE_FRAME) || (frame->flag & NODE_SELECT)) - continue; - if (BLI_in_rctf(&frame->totr, snode->mx, snode->my)) - break; - } - if (frame) { - bNode *node, *parent; - for (node = ntree->nodes.last; node; node = node->prev) { - if (node->flag & NODE_SELECT) { - if (node->parent == NULL) { - /* attach all unparented nodes */ - nodeAttachNode(node, frame); - } - else { - /* attach nodes which share parent with the frame */ - for (parent = frame->parent; parent; parent = parent->parent) - if (parent == node->parent) - break; - if (parent) { - nodeDetachNode(node); - nodeAttachNode(node, frame); - } - } - } - } - } - - ED_node_sort(ntree); - WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); - - return OPERATOR_FINISHED; -} - -static int node_attach_invoke(bContext *C, wmOperator *op, wmEvent *event) -{ - ARegion *ar = CTX_wm_region(C); - SpaceNode *snode = CTX_wm_space_node(C); - - /* convert mouse coordinates to v2d space */ - UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &snode->mx, &snode->my); - - return node_attach_exec(C, op); -} - -void NODE_OT_attach(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Attach Nodes"; - ot->description = "Attach active node to a frame"; - ot->idname = "NODE_OT_attach"; - - /* api callbacks */ - ot->exec = node_attach_exec; - ot->invoke = node_attach_invoke; - ot->poll = ED_operator_node_active; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; -} - -/* ****************** Detach ******************* */ - -/* tags for depth-first search */ -#define NODE_DETACH_DONE 1 -#define NODE_DETACH_IS_DESCENDANT 2 - -static void node_detach_recursive(bNode *node) -{ - node->done |= NODE_DETACH_DONE; - - if (node->parent) { - /* call recursively */ - if (!(node->parent->done & NODE_DETACH_DONE)) - node_detach_recursive(node->parent); - - /* in any case: if the parent is a descendant, so is the child */ - if (node->parent->done & NODE_DETACH_IS_DESCENDANT) - node->done |= NODE_DETACH_IS_DESCENDANT; - else if (node->flag & NODE_SELECT) { - /* if parent is not a decendant of a selected node, detach */ - nodeDetachNode(node); - node->done |= NODE_DETACH_IS_DESCENDANT; - } - } - else if (node->flag & NODE_SELECT) { - node->done |= NODE_DETACH_IS_DESCENDANT; - } -} - -/* detach the root nodes in the current selection */ -static int node_detach_exec(bContext *C, wmOperator *UNUSED(op)) -{ - SpaceNode *snode = CTX_wm_space_node(C); - bNodeTree *ntree = snode->edittree; - bNode *node; - - /* reset tags */ - for (node = ntree->nodes.first; node; node = node->next) - node->done = 0; - /* detach nodes recursively - * relative order is preserved here! - */ - for (node = ntree->nodes.first; node; node = node->next) { - if (!(node->done & NODE_DETACH_DONE)) - node_detach_recursive(node); - } - - ED_node_sort(ntree); - WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); - - return OPERATOR_FINISHED; -} - -void NODE_OT_detach(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Detach Nodes"; - ot->description = "Detach selected nodes from parents"; - ot->idname = "NODE_OT_detach"; - - /* api callbacks */ - ot->exec = node_detach_exec; - ot->poll = ED_operator_node_active; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; -} diff --git a/source/blender/editors/space_node/node_group.c b/source/blender/editors/space_node/node_group.c new file mode 100644 index 00000000000..41924d926d2 --- /dev/null +++ b/source/blender/editors/space_node/node_group.c @@ -0,0 +1,1164 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2005 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): David Millan Escriva, Juho Vepsäläinen, Nathan Letwory + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/editors/space_node/node_group.c + * \ingroup spnode + */ + + +#include +#include +#include +#include +#include + +#include "MEM_guardedalloc.h" + +#include "DNA_ID.h" +#include "DNA_lamp_types.h" +#include "DNA_material_types.h" +#include "DNA_node_types.h" +#include "DNA_object_types.h" +#include "DNA_particle_types.h" +#include "DNA_scene_types.h" +#include "DNA_world_types.h" +#include "DNA_action_types.h" +#include "DNA_anim_types.h" + +#include "BLI_math.h" +#include "BLI_blenlib.h" +#include "BLI_utildefines.h" + +#include "BKE_action.h" +#include "BKE_animsys.h" +#include "BKE_context.h" +#include "BKE_depsgraph.h" +#include "BKE_global.h" +#include "BKE_image.h" +#include "BKE_library.h" +#include "BKE_main.h" +#include "BKE_node.h" +#include "BKE_material.h" +#include "BKE_modifier.h" +#include "BKE_paint.h" +#include "BKE_scene.h" +#include "BKE_screen.h" +#include "BKE_texture.h" +#include "BKE_report.h" + +#include "RE_pipeline.h" + +#include "IMB_imbuf_types.h" + +#include "ED_node.h" +#include "ED_image.h" +#include "ED_screen.h" +#include "ED_space_api.h" +#include "ED_render.h" + +#include "RNA_access.h" +#include "RNA_define.h" +#include "RNA_enum_types.h" + +#include "WM_api.h" +#include "WM_types.h" + +#include "UI_interface.h" +#include "UI_resources.h" +#include "UI_view2d.h" + +#include "IMB_imbuf.h" + +#include "RNA_enum_types.h" + +#include "GPU_material.h" + +#include "node_intern.h" +#include "NOD_socket.h" + +static EnumPropertyItem socket_in_out_items[] = { + { SOCK_IN, "SOCK_IN", 0, "Input", "" }, + { SOCK_OUT, "SOCK_OUT", 0, "Output", "" }, + { 0, NULL, 0, NULL, NULL }, +}; + +/* ***************** Edit Group operator ************* */ + +void snode_make_group_editable(SpaceNode *snode, bNode *gnode) +{ + bNode *node; + + /* make sure nothing has group editing on */ + for (node = snode->nodetree->nodes.first; node; node = node->next) { + nodeGroupEditClear(node); + + /* while we're here, clear texture active */ + if (node->typeinfo->nclass == NODE_CLASS_TEXTURE) { + /* this is not 100% sure to be reliable, see comment on the flag */ + node->flag &= ~NODE_ACTIVE_TEXTURE; + } + } + + if (gnode == NULL) { + /* with NULL argument we do a toggle */ + if (snode->edittree == snode->nodetree) + gnode = nodeGetActive(snode->nodetree); + } + + if (gnode) { + snode->edittree = nodeGroupEditSet(gnode, 1); + + /* deselect all other nodes, so we can also do grabbing of entire subtree */ + for (node = snode->nodetree->nodes.first; node; node = node->next) { + node_deselect(node); + + if (node->typeinfo->nclass == NODE_CLASS_TEXTURE) { + /* this is not 100% sure to be reliable, see comment on the flag */ + node->flag &= ~NODE_ACTIVE_TEXTURE; + } + } + node_select(gnode); + } + else + snode->edittree = snode->nodetree; +} + +static int node_group_edit_exec(bContext *C, wmOperator *UNUSED(op)) +{ + SpaceNode *snode = CTX_wm_space_node(C); + + ED_preview_kill_jobs(C); + + if (snode->nodetree == snode->edittree) { + bNode *gnode = nodeGetActive(snode->edittree); + snode_make_group_editable(snode, gnode); + } + else + snode_make_group_editable(snode, NULL); + + WM_event_add_notifier(C, NC_SCENE | ND_NODES, NULL); + + return OPERATOR_FINISHED; +} + +static int node_group_edit_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) +{ + SpaceNode *snode = CTX_wm_space_node(C); + bNode *gnode; + + /* XXX callback? */ + if (snode->nodetree == snode->edittree) { + gnode = nodeGetActive(snode->edittree); + if (gnode && gnode->id && GS(gnode->id->name) == ID_NT && gnode->id->lib) { + uiPupMenuOkee(C, op->type->idname, "Make group local?"); + return OPERATOR_CANCELLED; + } + } + + return node_group_edit_exec(C, op); +} + +void NODE_OT_group_edit(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Edit Group"; + ot->description = "Edit node group"; + ot->idname = "NODE_OT_group_edit"; + + /* api callbacks */ + ot->invoke = node_group_edit_invoke; + ot->exec = node_group_edit_exec; + ot->poll = ED_operator_node_active; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} + +/* ***************** Add Group Socket operator ************* */ + +static int node_group_socket_add_exec(bContext *C, wmOperator *op) +{ + SpaceNode *snode = CTX_wm_space_node(C); + int in_out = -1; + char name[MAX_NAME] = ""; + int type = SOCK_FLOAT; + bNodeTree *ngroup = snode->edittree; + /* bNodeSocket *sock; */ /* UNUSED */ + + ED_preview_kill_jobs(C); + + if (RNA_struct_property_is_set(op->ptr, "name")) + RNA_string_get(op->ptr, "name", name); + + if (RNA_struct_property_is_set(op->ptr, "type")) + type = RNA_enum_get(op->ptr, "type"); + + if (RNA_struct_property_is_set(op->ptr, "in_out")) + in_out = RNA_enum_get(op->ptr, "in_out"); + else + return OPERATOR_CANCELLED; + + /* using placeholder subtype first */ + /* sock = */ /* UNUSED */ node_group_add_socket(ngroup, name, type, in_out); + + ntreeUpdateTree(ngroup); + + snode_notify(C, snode); + + return OPERATOR_FINISHED; +} + +void NODE_OT_group_socket_add(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Add Group Socket"; + ot->description = "Add node group socket"; + ot->idname = "NODE_OT_group_socket_add"; + + /* api callbacks */ + ot->exec = node_group_socket_add_exec; + ot->poll = ED_operator_node_active; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + RNA_def_enum(ot->srna, "in_out", socket_in_out_items, SOCK_IN, "Socket Type", "Input or Output"); + RNA_def_string(ot->srna, "name", "", MAX_NAME, "Name", "Group socket name"); + RNA_def_enum(ot->srna, "type", node_socket_type_items, SOCK_FLOAT, "Type", "Type of the group socket"); +} + +/* ***************** Remove Group Socket operator ************* */ + +static int node_group_socket_remove_exec(bContext *C, wmOperator *op) +{ + SpaceNode *snode = CTX_wm_space_node(C); + int index = -1; + int in_out = -1; + bNodeTree *ngroup = snode->edittree; + bNodeSocket *sock; + + ED_preview_kill_jobs(C); + + if (RNA_struct_property_is_set(op->ptr, "index")) + index = RNA_int_get(op->ptr, "index"); + else + return OPERATOR_CANCELLED; + + if (RNA_struct_property_is_set(op->ptr, "in_out")) + in_out = RNA_enum_get(op->ptr, "in_out"); + else + return OPERATOR_CANCELLED; + + sock = (bNodeSocket *)BLI_findlink(in_out == SOCK_IN ? &ngroup->inputs : &ngroup->outputs, index); + if (sock) { + node_group_remove_socket(ngroup, sock, in_out); + ntreeUpdateTree(ngroup); + + snode_notify(C, snode); + } + + return OPERATOR_FINISHED; +} + +void NODE_OT_group_socket_remove(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Remove Group Socket"; + ot->description = "Remove a node group socket"; + ot->idname = "NODE_OT_group_socket_remove"; + + /* api callbacks */ + ot->exec = node_group_socket_remove_exec; + ot->poll = ED_operator_node_active; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "", 0, INT_MAX); + RNA_def_enum(ot->srna, "in_out", socket_in_out_items, SOCK_IN, "Socket Type", "Input or Output"); +} + +/* ***************** Move Group Socket Up operator ************* */ + +static int node_group_socket_move_up_exec(bContext *C, wmOperator *op) +{ + SpaceNode *snode = CTX_wm_space_node(C); + int index = -1; + int in_out = -1; + bNodeTree *ngroup = snode->edittree; + bNodeSocket *sock, *prev; + + ED_preview_kill_jobs(C); + + if (RNA_struct_property_is_set(op->ptr, "index")) + index = RNA_int_get(op->ptr, "index"); + else + return OPERATOR_CANCELLED; + + if (RNA_struct_property_is_set(op->ptr, "in_out")) + in_out = RNA_enum_get(op->ptr, "in_out"); + else + return OPERATOR_CANCELLED; + + /* swap */ + if (in_out == SOCK_IN) { + sock = (bNodeSocket *)BLI_findlink(&ngroup->inputs, index); + prev = sock->prev; + /* can't move up the first socket */ + if (!prev) + return OPERATOR_CANCELLED; + BLI_remlink(&ngroup->inputs, sock); + BLI_insertlinkbefore(&ngroup->inputs, prev, sock); + + ngroup->update |= NTREE_UPDATE_GROUP_IN; + } + else if (in_out == SOCK_OUT) { + sock = (bNodeSocket *)BLI_findlink(&ngroup->outputs, index); + prev = sock->prev; + /* can't move up the first socket */ + if (!prev) + return OPERATOR_CANCELLED; + BLI_remlink(&ngroup->outputs, sock); + BLI_insertlinkbefore(&ngroup->outputs, prev, sock); + + ngroup->update |= NTREE_UPDATE_GROUP_OUT; + } + ntreeUpdateTree(ngroup); + + snode_notify(C, snode); + + return OPERATOR_FINISHED; +} + +void NODE_OT_group_socket_move_up(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Move Group Socket Up"; + ot->description = "Move up node group socket"; + ot->idname = "NODE_OT_group_socket_move_up"; + + /* api callbacks */ + ot->exec = node_group_socket_move_up_exec; + ot->poll = ED_operator_node_active; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "", 0, INT_MAX); + RNA_def_enum(ot->srna, "in_out", socket_in_out_items, SOCK_IN, "Socket Type", "Input or Output"); +} + +/* ***************** Move Group Socket Up operator ************* */ + +static int node_group_socket_move_down_exec(bContext *C, wmOperator *op) +{ + SpaceNode *snode = CTX_wm_space_node(C); + int index = -1; + int in_out = -1; + bNodeTree *ngroup = snode->edittree; + bNodeSocket *sock, *next; + + ED_preview_kill_jobs(C); + + if (RNA_struct_property_is_set(op->ptr, "index")) + index = RNA_int_get(op->ptr, "index"); + else + return OPERATOR_CANCELLED; + + if (RNA_struct_property_is_set(op->ptr, "in_out")) + in_out = RNA_enum_get(op->ptr, "in_out"); + else + return OPERATOR_CANCELLED; + + /* swap */ + if (in_out == SOCK_IN) { + sock = (bNodeSocket *)BLI_findlink(&ngroup->inputs, index); + next = sock->next; + /* can't move down the last socket */ + if (!next) + return OPERATOR_CANCELLED; + BLI_remlink(&ngroup->inputs, sock); + BLI_insertlinkafter(&ngroup->inputs, next, sock); + + ngroup->update |= NTREE_UPDATE_GROUP_IN; + } + else if (in_out == SOCK_OUT) { + sock = (bNodeSocket *)BLI_findlink(&ngroup->outputs, index); + next = sock->next; + /* can't move down the last socket */ + if (!next) + return OPERATOR_CANCELLED; + BLI_remlink(&ngroup->outputs, sock); + BLI_insertlinkafter(&ngroup->outputs, next, sock); + + ngroup->update |= NTREE_UPDATE_GROUP_OUT; + } + ntreeUpdateTree(ngroup); + + snode_notify(C, snode); + + return OPERATOR_FINISHED; +} + +void NODE_OT_group_socket_move_down(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Move Group Socket Down"; + ot->description = "Move down node group socket"; + ot->idname = "NODE_OT_group_socket_move_down"; + + /* api callbacks */ + ot->exec = node_group_socket_move_down_exec; + ot->poll = ED_operator_node_active; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "", 0, INT_MAX); + RNA_def_enum(ot->srna, "in_out", socket_in_out_items, SOCK_IN, "Socket Type", "Input or Output"); +} + +/* ******************** Ungroup operator ********************** */ + +/* returns 1 if its OK */ +static int node_group_ungroup(bNodeTree *ntree, bNode *gnode) +{ + bNodeLink *link, *linkn; + bNode *node, *nextn; + bNodeTree *ngroup, *wgroup; + ListBase anim_basepaths = {NULL, NULL}; + + ngroup = (bNodeTree *)gnode->id; + if (ngroup == NULL) return 0; + + /* clear new pointers, set in copytree */ + for (node = ntree->nodes.first; node; node = node->next) + node->new_node = NULL; + + /* wgroup is a temporary copy of the NodeTree we're merging in + * - all of wgroup's nodes are transferred across to their new home + * - ngroup (i.e. the source NodeTree) is left unscathed + */ + wgroup = ntreeCopyTree(ngroup); + + /* add the nodes into the ntree */ + for (node = wgroup->nodes.first; node; node = nextn) { + nextn = node->next; + + /* keep track of this node's RNA "base" path (the part of the path identifying the node) + * if the old nodetree has animation data which potentially covers this node + */ + if (wgroup->adt) { + PointerRNA ptr; + char *path; + + RNA_pointer_create(&wgroup->id, &RNA_Node, node, &ptr); + path = RNA_path_from_ID_to_struct(&ptr); + + if (path) + BLI_addtail(&anim_basepaths, BLI_genericNodeN(path)); + } + + /* migrate node */ + BLI_remlink(&wgroup->nodes, node); + BLI_addtail(&ntree->nodes, node); + + /* ensure unique node name in the nodee tree */ + nodeUniqueName(ntree, node); + + node->locx += gnode->locx; + node->locy += gnode->locy; + + node->flag |= NODE_SELECT; + } + + /* restore external links to and from the gnode */ + for (link = ntree->links.first; link; link = link->next) { + if (link->fromnode == gnode) { + if (link->fromsock->groupsock) { + bNodeSocket *gsock = link->fromsock->groupsock; + if (gsock->link) { + if (gsock->link->fromnode) { + /* NB: using the new internal copies here! the groupsock pointer still maps to the old tree */ + link->fromnode = (gsock->link->fromnode ? gsock->link->fromnode->new_node : NULL); + link->fromsock = gsock->link->fromsock->new_sock; + } + else { + /* group output directly maps to group input */ + bNodeSocket *insock = node_group_find_input(gnode, gsock->link->fromsock); + if (insock->link) { + link->fromnode = insock->link->fromnode; + link->fromsock = insock->link->fromsock; + } + } + } + else { + /* copy the default input value from the group socket default to the external socket */ + node_socket_convert_default_value(link->tosock->type, link->tosock->default_value, gsock->type, gsock->default_value); + } + } + } + } + /* remove internal output links, these are not used anymore */ + for (link = wgroup->links.first; link; link = linkn) { + linkn = link->next; + if (!link->tonode) + nodeRemLink(wgroup, link); + } + /* restore links from internal nodes */ + for (link = wgroup->links.first; link; link = linkn) { + linkn = link->next; + /* indicates link to group input */ + if (!link->fromnode) { + /* NB: can't use find_group_node_input here, + * because gnode sockets still point to the old tree! + */ + bNodeSocket *insock; + for (insock = gnode->inputs.first; insock; insock = insock->next) + if (insock->groupsock->new_sock == link->fromsock) + break; + if (insock->link) { + link->fromnode = insock->link->fromnode; + link->fromsock = insock->link->fromsock; + } + else { + /* copy the default input value from the group node socket default to the internal socket */ + node_socket_convert_default_value(link->tosock->type, link->tosock->default_value, insock->type, insock->default_value); + nodeRemLink(wgroup, link); + } + } + } + + /* add internal links to the ntree */ + for (link = wgroup->links.first; link; link = linkn) { + linkn = link->next; + BLI_remlink(&wgroup->links, link); + BLI_addtail(&ntree->links, link); + } + + /* and copy across the animation, + * note that the animation data's action can be NULL here */ + if (wgroup->adt) { + LinkData *ld, *ldn = NULL; + bAction *waction; + + /* firstly, wgroup needs to temporary dummy action that can be destroyed, as it shares copies */ + waction = wgroup->adt->action = BKE_action_copy(wgroup->adt->action); + + /* now perform the moving */ + BKE_animdata_separate_by_basepath(&wgroup->id, &ntree->id, &anim_basepaths); + + /* paths + their wrappers need to be freed */ + for (ld = anim_basepaths.first; ld; ld = ldn) { + ldn = ld->next; + + MEM_freeN(ld->data); + BLI_freelinkN(&anim_basepaths, ld); + } + + /* free temp action too */ + if (waction) { + BKE_libblock_free(&G.main->action, waction); + } + } + + /* delete the group instance. this also removes old input links! */ + nodeFreeNode(ntree, gnode); + + /* free the group tree (takes care of user count) */ + BKE_libblock_free(&G.main->nodetree, wgroup); + + ntree->update |= NTREE_UPDATE_NODES | NTREE_UPDATE_LINKS; + + return 1; +} + +static int node_group_ungroup_exec(bContext *C, wmOperator *op) +{ + SpaceNode *snode = CTX_wm_space_node(C); + bNode *gnode; + + ED_preview_kill_jobs(C); + + /* are we inside of a group? */ + gnode = node_tree_get_editgroup(snode->nodetree); + if (gnode) + snode_make_group_editable(snode, NULL); + + gnode = nodeGetActive(snode->edittree); + if (gnode == NULL) + return OPERATOR_CANCELLED; + + if (gnode->type != NODE_GROUP) { + BKE_report(op->reports, RPT_WARNING, "Not a group"); + return OPERATOR_CANCELLED; + } + else if (node_group_ungroup(snode->nodetree, gnode)) { + ntreeUpdateTree(snode->nodetree); + } + else { + BKE_report(op->reports, RPT_WARNING, "Can't ungroup"); + return OPERATOR_CANCELLED; + } + + snode_notify(C, snode); + snode_dag_update(C, snode); + + return OPERATOR_FINISHED; +} + +void NODE_OT_group_ungroup(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Ungroup"; + ot->description = "Ungroup selected nodes"; + ot->idname = "NODE_OT_group_ungroup"; + + /* api callbacks */ + ot->exec = node_group_ungroup_exec; + ot->poll = ED_operator_node_active; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} + +/* ******************** Separate operator ********************** */ + +/* returns 1 if its OK */ +static int node_group_separate_selected(bNodeTree *ntree, bNode *gnode, int make_copy) +{ + bNodeLink *link, *link_next; + bNode *node, *node_next, *newnode; + bNodeTree *ngroup; + ListBase anim_basepaths = {NULL, NULL}; + + ngroup = (bNodeTree *)gnode->id; + if (ngroup == NULL) return 0; + + /* deselect all nodes in the target tree */ + for (node = ntree->nodes.first; node; node = node->next) + node_deselect(node); + + /* clear new pointers, set in nodeCopyNode */ + for (node = ngroup->nodes.first; node; node = node->next) + node->new_node = NULL; + + /* add selected nodes into the ntree */ + for (node = ngroup->nodes.first; node; node = node_next) { + node_next = node->next; + if (!(node->flag & NODE_SELECT)) + continue; + + if (make_copy) { + /* make a copy */ + newnode = nodeCopyNode(ngroup, node); + } + else { + /* use the existing node */ + newnode = node; + } + + /* keep track of this node's RNA "base" path (the part of the path identifying the node) + * if the old nodetree has animation data which potentially covers this node + */ + if (ngroup->adt) { + PointerRNA ptr; + char *path; + + RNA_pointer_create(&ngroup->id, &RNA_Node, newnode, &ptr); + path = RNA_path_from_ID_to_struct(&ptr); + + if (path) + BLI_addtail(&anim_basepaths, BLI_genericNodeN(path)); + } + + /* ensure valid parent pointers, detach if parent stays inside the group */ + if (newnode->parent && !(newnode->parent->flag & NODE_SELECT)) + nodeDetachNode(newnode); + + /* migrate node */ + BLI_remlink(&ngroup->nodes, newnode); + BLI_addtail(&ntree->nodes, newnode); + + /* ensure unique node name in the node tree */ + nodeUniqueName(ntree, newnode); + + newnode->locx += gnode->locx; + newnode->locy += gnode->locy; + } + + /* add internal links to the ntree */ + for (link = ngroup->links.first; link; link = link_next) { + int fromselect = (link->fromnode && (link->fromnode->flag & NODE_SELECT)); + int toselect = (link->tonode && (link->tonode->flag & NODE_SELECT)); + link_next = link->next; + + if (make_copy) { + /* make a copy of internal links */ + if (fromselect && toselect) + nodeAddLink(ntree, link->fromnode->new_node, link->fromsock->new_sock, link->tonode->new_node, link->tosock->new_sock); + } + else { + /* move valid links over, delete broken links */ + if (fromselect && toselect) { + BLI_remlink(&ngroup->links, link); + BLI_addtail(&ntree->links, link); + } + else if (fromselect || toselect) { + nodeRemLink(ngroup, link); + } + } + } + + /* and copy across the animation, + * note that the animation data's action can be NULL here */ + if (ngroup->adt) { + LinkData *ld, *ldn = NULL; + + /* now perform the moving */ + BKE_animdata_separate_by_basepath(&ngroup->id, &ntree->id, &anim_basepaths); + + /* paths + their wrappers need to be freed */ + for (ld = anim_basepaths.first; ld; ld = ldn) { + ldn = ld->next; + + MEM_freeN(ld->data); + BLI_freelinkN(&anim_basepaths, ld); + } + } + + ntree->update |= NTREE_UPDATE_NODES | NTREE_UPDATE_LINKS; + if (!make_copy) + ngroup->update |= NTREE_UPDATE_NODES | NTREE_UPDATE_LINKS; + + return 1; +} + +typedef enum eNodeGroupSeparateType { + NODE_GS_COPY, + NODE_GS_MOVE +} eNodeGroupSeparateType; + +/* Operator Property */ +EnumPropertyItem node_group_separate_types[] = { + {NODE_GS_COPY, "COPY", 0, "Copy", "Copy to parent node tree, keep group intact"}, + {NODE_GS_MOVE, "MOVE", 0, "Move", "Move to parent node tree, remove from group"}, + {0, NULL, 0, NULL, NULL} +}; + +static int node_group_separate_exec(bContext *C, wmOperator *op) +{ + SpaceNode *snode = CTX_wm_space_node(C); + bNode *gnode; + int type = RNA_enum_get(op->ptr, "type"); + + ED_preview_kill_jobs(C); + + /* are we inside of a group? */ + gnode = node_tree_get_editgroup(snode->nodetree); + if (!gnode) { + BKE_report(op->reports, RPT_WARNING, "Not inside node group"); + return OPERATOR_CANCELLED; + } + + switch (type) { + case NODE_GS_COPY: + if (!node_group_separate_selected(snode->nodetree, gnode, 1)) { + BKE_report(op->reports, RPT_WARNING, "Can't separate nodes"); + return OPERATOR_CANCELLED; + } + break; + case NODE_GS_MOVE: + if (!node_group_separate_selected(snode->nodetree, gnode, 0)) { + BKE_report(op->reports, RPT_WARNING, "Can't separate nodes"); + return OPERATOR_CANCELLED; + } + break; + } + + /* switch to parent tree */ + snode_make_group_editable(snode, NULL); + + ntreeUpdateTree(snode->nodetree); + + snode_notify(C, snode); + snode_dag_update(C, snode); + + return OPERATOR_FINISHED; +} + +static int node_group_separate_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *UNUSED(event)) +{ + uiPopupMenu *pup = uiPupMenuBegin(C, "Separate", ICON_NONE); + uiLayout *layout = uiPupMenuLayout(pup); + + uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT); + uiItemEnumO(layout, "NODE_OT_group_separate", NULL, 0, "type", NODE_GS_COPY); + uiItemEnumO(layout, "NODE_OT_group_separate", NULL, 0, "type", NODE_GS_MOVE); + + uiPupMenuEnd(C, pup); + + return OPERATOR_CANCELLED; +} + +void NODE_OT_group_separate(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Separate"; + ot->description = "Separate selected nodes from the node group"; + ot->idname = "NODE_OT_group_separate"; + + /* api callbacks */ + ot->invoke = node_group_separate_invoke; + ot->exec = node_group_separate_exec; + ot->poll = ED_operator_node_active; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + RNA_def_enum(ot->srna, "type", node_group_separate_types, NODE_GS_COPY, "Type", ""); +} + +/* ****************** Make Group operator ******************* */ + +static int node_group_make_test(bNodeTree *ntree, bNode *gnode) +{ + bNode *node; + bNodeLink *link; + int totnode = 0; + + /* is there something to group? also do some clearing */ + for (node = ntree->nodes.first; node; node = node->next) { + if (node == gnode) + continue; + + if (node->flag & NODE_SELECT) { + /* no groups in groups */ + if (node->type == NODE_GROUP) + return 0; + totnode++; + } + + node->done = 0; + } + if (totnode == 0) return 0; + + /* check if all connections are OK, no unselected node has both + * inputs and outputs to a selection */ + for (link = ntree->links.first; link; link = link->next) { + if (link->fromnode && link->tonode && link->fromnode->flag & NODE_SELECT && link->fromnode != gnode) + link->tonode->done |= 1; + if (link->fromnode && link->tonode && link->tonode->flag & NODE_SELECT && link->tonode != gnode) + link->fromnode->done |= 2; + } + + for (node = ntree->nodes.first; node; node = node->next) { + if (node == gnode) + continue; + if ((node->flag & NODE_SELECT) == 0) + if (node->done == 3) + break; + } + if (node) + return 0; + + return 1; +} + + +static void node_get_selected_minmax(bNodeTree *ntree, bNode *gnode, float *min, float *max) +{ + bNode *node; + INIT_MINMAX2(min, max); + for (node = ntree->nodes.first; node; node = node->next) { + if (node == gnode) + continue; + if (node->flag & NODE_SELECT) { + DO_MINMAX2((&node->locx), min, max); + } + } +} + +static int node_group_make_insert_selected(bNodeTree *ntree, bNode *gnode) +{ + bNodeTree *ngroup = (bNodeTree *)gnode->id; + bNodeLink *link, *linkn; + bNode *node, *nextn; + bNodeSocket *gsock; + ListBase anim_basepaths = {NULL, NULL}; + float min[2], max[2]; + + /* deselect all nodes in the target tree */ + for (node = ngroup->nodes.first; node; node = node->next) + node_deselect(node); + + node_get_selected_minmax(ntree, gnode, min, max); + + /* move nodes over */ + for (node = ntree->nodes.first; node; node = nextn) { + nextn = node->next; + if (node == gnode) + continue; + if (node->flag & NODE_SELECT) { + /* keep track of this node's RNA "base" path (the part of the pat identifying the node) + * if the old nodetree has animation data which potentially covers this node + */ + if (ntree->adt) { + PointerRNA ptr; + char *path; + + RNA_pointer_create(&ntree->id, &RNA_Node, node, &ptr); + path = RNA_path_from_ID_to_struct(&ptr); + + if (path) + BLI_addtail(&anim_basepaths, BLI_genericNodeN(path)); + } + + /* ensure valid parent pointers, detach if parent stays outside the group */ + if (node->parent && !(node->parent->flag & NODE_SELECT)) + nodeDetachNode(node); + + /* change node-collection membership */ + BLI_remlink(&ntree->nodes, node); + BLI_addtail(&ngroup->nodes, node); + + /* ensure unique node name in the ngroup */ + nodeUniqueName(ngroup, node); + + node->locx -= 0.5f * (min[0] + max[0]); + node->locy -= 0.5f * (min[1] + max[1]); + } + } + + /* move animation data over */ + if (ntree->adt) { + LinkData *ld, *ldn = NULL; + + BKE_animdata_separate_by_basepath(&ntree->id, &ngroup->id, &anim_basepaths); + + /* paths + their wrappers need to be freed */ + for (ld = anim_basepaths.first; ld; ld = ldn) { + ldn = ld->next; + + MEM_freeN(ld->data); + BLI_freelinkN(&anim_basepaths, ld); + } + } + + /* node groups don't use internal cached data */ + ntreeFreeCache(ngroup); + + /* relink external sockets */ + for (link = ntree->links.first; link; link = linkn) { + int fromselect = (link->fromnode && (link->fromnode->flag & NODE_SELECT) && link->fromnode != gnode); + int toselect = (link->tonode && (link->tonode->flag & NODE_SELECT) && link->tonode != gnode); + linkn = link->next; + + if (gnode && ((fromselect && link->tonode == gnode) || (toselect && link->fromnode == gnode))) { + /* remove all links to/from the gnode. + * this can remove link information, but there's no general way to preserve it. + */ + nodeRemLink(ntree, link); + } + else if (fromselect && toselect) { + BLI_remlink(&ntree->links, link); + BLI_addtail(&ngroup->links, link); + } + else if (toselect) { + gsock = node_group_expose_socket(ngroup, link->tosock, SOCK_IN); + link->tosock->link = nodeAddLink(ngroup, NULL, gsock, link->tonode, link->tosock); + link->tosock = node_group_add_extern_socket(ntree, &gnode->inputs, SOCK_IN, gsock); + link->tonode = gnode; + } + else if (fromselect) { + /* search for existing group node socket */ + for (gsock = ngroup->outputs.first; gsock; gsock = gsock->next) + if (gsock->link && gsock->link->fromsock == link->fromsock) + break; + if (!gsock) { + gsock = node_group_expose_socket(ngroup, link->fromsock, SOCK_OUT); + gsock->link = nodeAddLink(ngroup, link->fromnode, link->fromsock, NULL, gsock); + link->fromsock = node_group_add_extern_socket(ntree, &gnode->outputs, SOCK_OUT, gsock); + } + else + link->fromsock = node_group_find_output(gnode, gsock); + link->fromnode = gnode; + } + } + + /* update of the group tree */ + ngroup->update |= NTREE_UPDATE; + /* update of the tree containing the group instance node */ + ntree->update |= NTREE_UPDATE_NODES | NTREE_UPDATE_LINKS; + + return 1; +} + +static bNode *node_group_make_from_selected(bNodeTree *ntree) +{ + bNode *gnode; + bNodeTree *ngroup; + float min[2], max[2]; + bNodeTemplate ntemp; + + node_get_selected_minmax(ntree, NULL, min, max); + + /* new nodetree */ + ngroup = ntreeAddTree("NodeGroup", ntree->type, NODE_GROUP); + + /* make group node */ + ntemp.type = NODE_GROUP; + ntemp.ngroup = ngroup; + gnode = nodeAddNode(ntree, &ntemp); + gnode->locx = 0.5f * (min[0] + max[0]); + gnode->locy = 0.5f * (min[1] + max[1]); + + node_group_make_insert_selected(ntree, gnode); + + /* update of the tree containing the group instance node */ + ntree->update |= NTREE_UPDATE_NODES; + + return gnode; +} + +typedef enum eNodeGroupMakeType { + NODE_GM_NEW, + NODE_GM_INSERT +} eNodeGroupMakeType; + +/* Operator Property */ +EnumPropertyItem node_group_make_types[] = { + {NODE_GM_NEW, "NEW", 0, "New", "Create a new node group from selected nodes"}, + {NODE_GM_INSERT, "INSERT", 0, "Insert", "Insert into active node group"}, + {0, NULL, 0, NULL, NULL} +}; + +static int node_group_make_exec(bContext *C, wmOperator *op) +{ + SpaceNode *snode = CTX_wm_space_node(C); + bNode *gnode; + int type = RNA_enum_get(op->ptr, "type"); + + if (snode->edittree != snode->nodetree) { + BKE_report(op->reports, RPT_WARNING, "Can not add a new Group in a Group"); + return OPERATOR_CANCELLED; + } + + /* for time being... is too complex to handle */ + if (snode->treetype == NTREE_COMPOSIT) { + for (gnode = snode->nodetree->nodes.first; gnode; gnode = gnode->next) { + if (gnode->flag & SELECT) + if (gnode->type == CMP_NODE_R_LAYERS) + break; + } + + if (gnode) { + BKE_report(op->reports, RPT_WARNING, "Can not add RenderLayer in a Group"); + return OPERATOR_CANCELLED; + } + } + + ED_preview_kill_jobs(C); + + switch (type) { + case NODE_GM_NEW: + if (node_group_make_test(snode->nodetree, NULL)) { + gnode = node_group_make_from_selected(snode->nodetree); + } + else { + BKE_report(op->reports, RPT_WARNING, "Can not make Group"); + return OPERATOR_CANCELLED; + } + break; + case NODE_GM_INSERT: + gnode = nodeGetActive(snode->nodetree); + if (!gnode || gnode->type != NODE_GROUP) { + BKE_report(op->reports, RPT_WARNING, "No active Group node"); + return OPERATOR_CANCELLED; + } + if (node_group_make_test(snode->nodetree, gnode)) { + node_group_make_insert_selected(snode->nodetree, gnode); + } + else { + BKE_report(op->reports, RPT_WARNING, "Can not insert into Group"); + return OPERATOR_CANCELLED; + } + break; + } + + if (gnode) { + nodeSetActive(snode->nodetree, gnode); + snode_make_group_editable(snode, gnode); + } + + if (gnode) + ntreeUpdateTree((bNodeTree *)gnode->id); + ntreeUpdateTree(snode->nodetree); + + snode_notify(C, snode); + snode_dag_update(C, snode); + + return OPERATOR_FINISHED; +} + +static int node_group_make_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *UNUSED(event)) +{ + SpaceNode *snode = CTX_wm_space_node(C); + bNode *act = nodeGetActive(snode->edittree); + uiPopupMenu *pup = uiPupMenuBegin(C, "Make Group", ICON_NONE); + uiLayout *layout = uiPupMenuLayout(pup); + + uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT); + uiItemEnumO(layout, "NODE_OT_group_make", NULL, 0, "type", NODE_GM_NEW); + + /* if active node is a group, add insert option */ + if (act && act->type == NODE_GROUP) { + uiItemEnumO(layout, "NODE_OT_group_make", NULL, 0, "type", NODE_GM_INSERT); + } + + uiPupMenuEnd(C, pup); + + return OPERATOR_CANCELLED; +} + +void NODE_OT_group_make(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Group"; + ot->description = "Make group from selected nodes"; + ot->idname = "NODE_OT_group_make"; + + /* api callbacks */ + ot->invoke = node_group_make_invoke; + ot->exec = node_group_make_exec; + ot->poll = ED_operator_node_active; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + RNA_def_enum(ot->srna, "type", node_group_make_types, NODE_GM_NEW, "Type", ""); +} diff --git a/source/blender/editors/space_node/node_intern.h b/source/blender/editors/space_node/node_intern.h index 9cd62342e19..5c6a91195a6 100644 --- a/source/blender/editors/space_node/node_intern.h +++ b/source/blender/editors/space_node/node_intern.h @@ -121,16 +121,56 @@ int node_link_bezier_points(View2D *v2d, SpaceNode *snode, bNodeLink *link, floa // void node_draw_link_straight(View2D *v2d, SpaceNode *snode, bNodeLink *link, int th_col1, int do_shaded, int th_col2, int do_triple, int th_col3 ); void draw_nodespace_back_pix(ARegion *ar, SpaceNode *snode, int color_manage); + +/* node_add.c */ +bNode *node_add_node(struct SpaceNode *snode, struct Main *bmain, struct Scene *scene, + struct bNodeTemplate *ntemp, float locx, float locy); +void NODE_OT_add_reroute(struct wmOperatorType *ot); + + +/* node_group.c */ +void NODE_OT_group_make(struct wmOperatorType *ot); +void NODE_OT_group_ungroup(struct wmOperatorType *ot); +void NODE_OT_group_separate(struct wmOperatorType *ot); +void NODE_OT_group_edit(struct wmOperatorType *ot); +void NODE_OT_group_socket_add(struct wmOperatorType *ot); +void NODE_OT_group_socket_remove(struct wmOperatorType *ot); +void NODE_OT_group_socket_move_up(struct wmOperatorType *ot); +void NODE_OT_group_socket_move_down(struct wmOperatorType *ot); + + +/* note_add.c */ +void NODE_OT_add_file(struct wmOperatorType *ot); +void NODE_OT_new_node_tree(struct wmOperatorType *ot); + + +/* node_relationships.c */ +void NODE_OT_link(struct wmOperatorType *ot); +void NODE_OT_link_make(struct wmOperatorType *ot); +void NODE_OT_links_cut(struct wmOperatorType *ot); +void NODE_OT_links_detach(struct wmOperatorType *ot); + +void NODE_OT_parent_set(struct wmOperatorType *ot); +void NODE_OT_parent_clear(struct wmOperatorType *ot); +void NODE_OT_join(struct wmOperatorType *ot); +void NODE_OT_attach(struct wmOperatorType *ot); +void NODE_OT_detach(struct wmOperatorType *ot); + +void NODE_OT_show_cyclic_dependencies(struct wmOperatorType *ot); +void NODE_OT_link_viewer(struct wmOperatorType *ot); + /* node_edit.c */ void node_tree_from_ID(ID *id, bNodeTree **ntree, bNodeTree **edittree, int *treetype); void snode_notify(bContext *C, SpaceNode *snode); void snode_dag_update(bContext *C, SpaceNode *snode); -bNode *node_add_node(struct SpaceNode *snode, struct Main *bmain, struct Scene *scene, struct bNodeTemplate *ntemp, float locx, float locy); void snode_set_context(SpaceNode *snode, Scene *scene); void snode_make_group_editable(SpaceNode *snode, bNode *gnode); void snode_composite_job(const struct bContext *C, ScrArea *sa); bNode *node_tree_get_editgroup(bNodeTree *ntree); -void snode_autoconnect(SpaceNode *snode, int allow_multiple, int replace); +void snode_update(struct SpaceNode *snode, struct bNode *node); +bNode *editnode_get_active(bNodeTree *ntree); +int composite_node_active(struct bContext *C); + int node_has_hidden_sockets(bNode *node); void node_set_hidden_sockets(SpaceNode *snode, bNode *node, int set); int node_render_changed_exec(bContext *, wmOperator *); @@ -141,21 +181,6 @@ void NODE_OT_delete(struct wmOperatorType *ot); void NODE_OT_delete_reconnect(struct wmOperatorType *ot); void NODE_OT_resize(struct wmOperatorType *ot); -void NODE_OT_link(struct wmOperatorType *ot); -void NODE_OT_link_make(struct wmOperatorType *ot); -void NODE_OT_links_cut(struct wmOperatorType *ot); -void NODE_OT_links_detach(struct wmOperatorType *ot); -void NODE_OT_add_reroute(struct wmOperatorType *ot); - -void NODE_OT_group_make(struct wmOperatorType *ot); -void NODE_OT_group_ungroup(struct wmOperatorType *ot); -void NODE_OT_group_separate(struct wmOperatorType *ot); -void NODE_OT_group_edit(struct wmOperatorType *ot); -void NODE_OT_group_socket_add(struct wmOperatorType *ot); -void NODE_OT_group_socket_remove(struct wmOperatorType *ot); -void NODE_OT_group_socket_move_up(struct wmOperatorType *ot); -void NODE_OT_group_socket_move_down(struct wmOperatorType *ot); - void NODE_OT_mute_toggle(struct wmOperatorType *ot); void NODE_OT_hide_toggle(struct wmOperatorType *ot); void NODE_OT_hide_socket_toggle(struct wmOperatorType *ot); @@ -163,8 +188,6 @@ void NODE_OT_preview_toggle(struct wmOperatorType *ot); void NODE_OT_options_toggle(struct wmOperatorType *ot); void NODE_OT_node_copy_color(struct wmOperatorType *ot); -void NODE_OT_show_cyclic_dependencies(struct wmOperatorType *ot); -void NODE_OT_link_viewer(struct wmOperatorType *ot); void NODE_OT_read_fullsamplelayers(struct wmOperatorType *ot); void NODE_OT_read_renderlayers(struct wmOperatorType *ot); void NODE_OT_render_changed(struct wmOperatorType *ot); @@ -173,20 +196,10 @@ void NODE_OT_backimage_move(struct wmOperatorType *ot); void NODE_OT_backimage_zoom(struct wmOperatorType *ot); void NODE_OT_backimage_sample(wmOperatorType *ot); -void NODE_OT_add_file(struct wmOperatorType *ot); - -void NODE_OT_new_node_tree(struct wmOperatorType *ot); - void NODE_OT_output_file_add_socket(struct wmOperatorType *ot); void NODE_OT_output_file_remove_active_socket(struct wmOperatorType *ot); void NODE_OT_output_file_move_active_socket(struct wmOperatorType *ot); -void NODE_OT_parent_set(struct wmOperatorType *ot); -void NODE_OT_parent_clear(struct wmOperatorType *ot); -void NODE_OT_join(struct wmOperatorType *ot); -void NODE_OT_attach(struct wmOperatorType *ot); -void NODE_OT_detach(struct wmOperatorType *ot); - extern const char *node_context_dir[]; // XXXXXX @@ -198,6 +211,7 @@ extern const char *node_context_dir[]; #define NODE_DY U.widget_unit #define NODE_MARGIN_X 15 #define NODE_SOCKSIZE 5 +#define NODE_LINK_RESOL 12 // XXX button events (butspace) enum { diff --git a/source/blender/editors/space_node/node_ops.c b/source/blender/editors/space_node/node_ops.c index ff1661f0327..0ce72848c56 100644 --- a/source/blender/editors/space_node/node_ops.c +++ b/source/blender/editors/space_node/node_ops.c @@ -261,7 +261,11 @@ void node_keymap(struct wmKeyConfig *keyconf) WM_keymap_add_item(keymap, "NODE_OT_delete", DELKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "NODE_OT_delete_reconnect", XKEY, KM_PRESS, KM_CTRL, 0); - WM_keymap_add_item(keymap, "NODE_OT_select_all", AKEY, KM_PRESS, 0, 0); + kmi = WM_keymap_add_item(keymap, "NODE_OT_select_all", AKEY, KM_PRESS, 0, 0); + RNA_enum_set(kmi->ptr, "action", SEL_TOGGLE); + kmi = WM_keymap_add_item(keymap, "NODE_OT_select_all", IKEY, KM_PRESS, KM_CTRL, 0); + RNA_enum_set(kmi->ptr, "action", SEL_INVERT); + WM_keymap_add_item(keymap, "NODE_OT_select_linked_to", LKEY, KM_PRESS, KM_SHIFT, 0); WM_keymap_add_item(keymap, "NODE_OT_select_linked_from", LKEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "NODE_OT_select_same_type", GKEY, KM_PRESS, KM_SHIFT, 0); diff --git a/source/blender/editors/space_node/node_relationships.c b/source/blender/editors/space_node/node_relationships.c new file mode 100644 index 00000000000..4fcc2abece4 --- /dev/null +++ b/source/blender/editors/space_node/node_relationships.c @@ -0,0 +1,1446 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2005 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): David Millan Escriva, Juho Vepsäläinen, Nathan Letwory + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/editors/space_node/node_relationships.c + * \ingroup spnode + */ + +#include +#include +#include +#include +#include + +#include "MEM_guardedalloc.h" + +#include "DNA_ID.h" +#include "DNA_lamp_types.h" +#include "DNA_material_types.h" +#include "DNA_node_types.h" +#include "DNA_object_types.h" +#include "DNA_particle_types.h" +#include "DNA_scene_types.h" +#include "DNA_world_types.h" +#include "DNA_action_types.h" +#include "DNA_anim_types.h" + +#include "BLI_math.h" +#include "BLI_blenlib.h" +#include "BLI_utildefines.h" + +#include "BKE_action.h" +#include "BKE_animsys.h" +#include "BKE_context.h" +#include "BKE_depsgraph.h" +#include "BKE_global.h" +#include "BKE_image.h" +#include "BKE_library.h" +#include "BKE_main.h" +#include "BKE_node.h" +#include "BKE_material.h" +#include "BKE_modifier.h" +#include "BKE_paint.h" +#include "BKE_scene.h" +#include "BKE_screen.h" +#include "BKE_texture.h" +#include "BKE_report.h" + +#include "RE_pipeline.h" + +#include "IMB_imbuf_types.h" + +#include "ED_node.h" +#include "ED_image.h" +#include "ED_screen.h" +#include "ED_space_api.h" +#include "ED_render.h" + +#include "RNA_access.h" +#include "RNA_define.h" +#include "RNA_enum_types.h" + +#include "WM_api.h" +#include "WM_types.h" + +#include "UI_interface.h" +#include "UI_resources.h" +#include "UI_view2d.h" + +#include "IMB_imbuf.h" + +#include "RNA_enum_types.h" + +#include "GPU_material.h" + +#include "node_intern.h" +#include "NOD_socket.h" + + +/* ****************** Add *********************** */ + + +typedef struct bNodeListItem { + struct bNodeListItem *next, *prev; + struct bNode *node; +} bNodeListItem; + +static int sort_nodes_locx(void *a, void *b) +{ + bNodeListItem *nli1 = (bNodeListItem *)a; + bNodeListItem *nli2 = (bNodeListItem *)b; + bNode *node1 = nli1->node; + bNode *node2 = nli2->node; + + if (node1->locx > node2->locx) + return 1; + else + return 0; +} + +static int socket_is_available(bNodeTree *UNUSED(ntree), bNodeSocket *sock, int allow_used) +{ + if (nodeSocketIsHidden(sock)) + return 0; + + if (!allow_used && (sock->flag & SOCK_IN_USE)) + return 0; + + return 1; +} + +static bNodeSocket *best_socket_output(bNodeTree *ntree, bNode *node, bNodeSocket *sock_target, int allow_multiple) +{ + bNodeSocket *sock; + + /* first look for selected output */ + for (sock = node->outputs.first; sock; sock = sock->next) { + if (!socket_is_available(ntree, sock, allow_multiple)) + continue; + + if (sock->flag & SELECT) + return sock; + } + + /* try to find a socket with a matching name */ + for (sock = node->outputs.first; sock; sock = sock->next) { + if (!socket_is_available(ntree, sock, allow_multiple)) + continue; + + /* check for same types */ + if (sock->type == sock_target->type) { + if (strcmp(sock->name, sock_target->name) == 0) + return sock; + } + } + + /* otherwise settle for the first available socket of the right type */ + for (sock = node->outputs.first; sock; sock = sock->next) { + + if (!socket_is_available(ntree, sock, allow_multiple)) + continue; + + /* check for same types */ + if (sock->type == sock_target->type) { + return sock; + } + } + + return NULL; +} + +/* this is a bit complicated, but designed to prioritize finding + * sockets of higher types, such as image, first */ +static bNodeSocket *best_socket_input(bNodeTree *ntree, bNode *node, int num, int replace) +{ + bNodeSocket *sock; + int socktype, maxtype = 0; + int a = 0; + + for (sock = node->inputs.first; sock; sock = sock->next) { + maxtype = MAX2(sock->type, maxtype); + } + + /* find sockets of higher 'types' first (i.e. image) */ + for (socktype = maxtype; socktype >= 0; socktype--) { + for (sock = node->inputs.first; sock; sock = sock->next) { + + if (!socket_is_available(ntree, sock, replace)) { + a++; + continue; + } + + if (sock->type == socktype) { + /* increment to make sure we don't keep finding + * the same socket on every attempt running this function */ + a++; + if (a > num) + return sock; + } + } + } + + return NULL; +} + +static int snode_autoconnect_input(SpaceNode *snode, bNode *node_fr, bNodeSocket *sock_fr, bNode *node_to, bNodeSocket *sock_to, int replace) +{ + bNodeTree *ntree = snode->edittree; + bNodeLink *link; + + /* then we can connect */ + if (replace) + nodeRemSocketLinks(ntree, sock_to); + + link = nodeAddLink(ntree, node_fr, sock_fr, node_to, sock_to); + /* validate the new link */ + ntreeUpdateTree(ntree); + if (!(link->flag & NODE_LINK_VALID)) { + nodeRemLink(ntree, link); + return 0; + } + + snode_update(snode, node_to); + return 1; +} + +static void snode_autoconnect(SpaceNode *snode, int allow_multiple, int replace) +{ + bNodeTree *ntree = snode->edittree; + ListBase *nodelist = MEM_callocN(sizeof(ListBase), "items_list"); + bNodeListItem *nli; + bNode *node; + int i, numlinks = 0; + + for (node = ntree->nodes.first; node; node = node->next) { + if (node->flag & NODE_SELECT) { + nli = MEM_mallocN(sizeof(bNodeListItem), "temporary node list item"); + nli->node = node; + BLI_addtail(nodelist, nli); + } + } + + /* sort nodes left to right */ + BLI_sortlist(nodelist, sort_nodes_locx); + + for (nli = nodelist->first; nli; nli = nli->next) { + bNode *node_fr, *node_to; + bNodeSocket *sock_fr, *sock_to; + int has_selected_inputs = 0; + + if (nli->next == NULL) break; + + node_fr = nli->node; + node_to = nli->next->node; + + /* if there are selected sockets, connect those */ + for (sock_to = node_to->inputs.first; sock_to; sock_to = sock_to->next) { + if (sock_to->flag & SELECT) { + has_selected_inputs = 1; + + if (!socket_is_available(ntree, sock_to, replace)) + continue; + + /* check for an appropriate output socket to connect from */ + sock_fr = best_socket_output(ntree, node_fr, sock_to, allow_multiple); + if (!sock_fr) + continue; + + if (snode_autoconnect_input(snode, node_fr, sock_fr, node_to, sock_to, replace)) + ++numlinks; + } + } + + if (!has_selected_inputs) { + /* no selected inputs, connect by finding suitable match */ + int num_inputs = BLI_countlist(&node_to->inputs); + + for (i = 0; i < num_inputs; i++) { + + /* find the best guess input socket */ + sock_to = best_socket_input(ntree, node_to, i, replace); + if (!sock_to) + continue; + + /* check for an appropriate output socket to connect from */ + sock_fr = best_socket_output(ntree, node_fr, sock_to, allow_multiple); + if (!sock_fr) + continue; + + if (snode_autoconnect_input(snode, node_fr, sock_fr, node_to, sock_to, replace)) { + ++numlinks; + break; + } + } + } + } + + if (numlinks > 0) { + ntreeUpdateTree(ntree); + } + + BLI_freelistN(nodelist); + MEM_freeN(nodelist); +} + +/* *************************** link viewer op ******************** */ + +static int node_link_viewer(const bContext *C, bNode *tonode) +{ + SpaceNode *snode = CTX_wm_space_node(C); + bNode *node; + bNodeLink *link; + bNodeSocket *sock; + + /* context check */ + if (tonode == NULL || tonode->outputs.first == NULL) + return OPERATOR_CANCELLED; + if (ELEM(tonode->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) + return OPERATOR_CANCELLED; + + /* get viewer */ + for (node = snode->edittree->nodes.first; node; node = node->next) + if (ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) + if (node->flag & NODE_DO_OUTPUT) + break; + /* no viewer, we make one active */ + if (node == NULL) { + for (node = snode->edittree->nodes.first; node; node = node->next) { + if (ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) { + node->flag |= NODE_DO_OUTPUT; + break; + } + } + } + + sock = NULL; + + /* try to find an already connected socket to cycle to the next */ + if (node) { + link = NULL; + for (link = snode->edittree->links.first; link; link = link->next) + if (link->tonode == node && link->fromnode == tonode) + if (link->tosock == node->inputs.first) + break; + if (link) { + /* unlink existing connection */ + sock = link->fromsock; + nodeRemLink(snode->edittree, link); + + /* find a socket after the previously connected socket */ + for (sock = sock->next; sock; sock = sock->next) + if (!nodeSocketIsHidden(sock)) + break; + } + } + + /* find a socket starting from the first socket */ + if (!sock) { + for (sock = tonode->outputs.first; sock; sock = sock->next) + if (!nodeSocketIsHidden(sock)) + break; + } + + if (sock) { + /* add a new viewer if none exists yet */ + if (!node) { + Main *bmain = CTX_data_main(C); + Scene *scene = CTX_data_scene(C); + bNodeTemplate ntemp; + + ntemp.type = CMP_NODE_VIEWER; + /* XXX location is a quick hack, just place it next to the linked socket */ + node = node_add_node(snode, bmain, scene, &ntemp, sock->locx + 100, sock->locy); + if (!node) + return OPERATOR_CANCELLED; + + link = NULL; + } + else { + /* get link to viewer */ + for (link = snode->edittree->links.first; link; link = link->next) + if (link->tonode == node && link->tosock == node->inputs.first) + break; + } + + if (link == NULL) { + nodeAddLink(snode->edittree, tonode, sock, node, node->inputs.first); + } + else { + link->fromnode = tonode; + link->fromsock = sock; + /* make sure the dependency sorting is updated */ + snode->edittree->update |= NTREE_UPDATE_LINKS; + } + ntreeUpdateTree(snode->edittree); + snode_update(snode, node); + } + + return OPERATOR_FINISHED; +} + + +static int node_active_link_viewer(bContext *C, wmOperator *UNUSED(op)) +{ + SpaceNode *snode = CTX_wm_space_node(C); + bNode *node; + + node = editnode_get_active(snode->edittree); + + if (!node) + return OPERATOR_CANCELLED; + + ED_preview_kill_jobs(C); + + if (node_link_viewer(C, node) == OPERATOR_CANCELLED) + return OPERATOR_CANCELLED; + + snode_notify(C, snode); + + return OPERATOR_FINISHED; +} + + +void NODE_OT_link_viewer(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Link to Viewer Node"; + ot->description = "Link to viewer node"; + ot->idname = "NODE_OT_link_viewer"; + + /* api callbacks */ + ot->exec = node_active_link_viewer; + ot->poll = composite_node_active; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} + + +/* *************************** add link op ******************** */ + +static void node_remove_extra_links(SpaceNode *snode, bNodeSocket *tsock, bNodeLink *link) +{ + bNodeLink *tlink; + bNodeSocket *sock; + + if (tsock && nodeCountSocketLinks(snode->edittree, link->tosock) > tsock->limit) { + + for (tlink = snode->edittree->links.first; tlink; tlink = tlink->next) { + if (link != tlink && tlink->tosock == link->tosock) + break; + } + if (tlink) { + /* try to move the existing link to the next available socket */ + if (tlink->tonode) { + /* is there a free input socket with the target type? */ + for (sock = tlink->tonode->inputs.first; sock; sock = sock->next) { + if (sock->type == tlink->tosock->type) + if (nodeCountSocketLinks(snode->edittree, sock) < sock->limit) + break; + } + if (sock) { + tlink->tosock = sock; + sock->flag &= ~SOCK_HIDDEN; + } + else { + nodeRemLink(snode->edittree, tlink); + } + } + else + nodeRemLink(snode->edittree, tlink); + + snode->edittree->update |= NTREE_UPDATE_LINKS; + } + } +} + +static int outside_group_rect(SpaceNode *snode) +{ + bNode *gnode = node_tree_get_editgroup(snode->nodetree); + if (gnode) { + return (snode->mx < gnode->totr.xmin || + snode->mx >= gnode->totr.xmax || + snode->my < gnode->totr.ymin || + snode->my >= gnode->totr.ymax); + } + return 0; +} + +/* loop that adds a nodelink, called by function below */ +/* in_out = starting socket */ +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; + bNodeTree *ntree = snode->edittree; + bNode *tnode; + bNodeSocket *tsock = NULL; + bNodeLink *link; + LinkData *linkdata; + int in_out; + + in_out = nldrag->in_out; + + UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], + &snode->mx, &snode->my); + + switch (event->type) { + case MOUSEMOVE: + + if (in_out == SOCK_OUT) { + if (node_find_indicated_socket(snode, &tnode, &tsock, SOCK_IN)) { + 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 (BLI_findindex(&ntree->links, link) < 0) + BLI_addtail(&ntree->links, link); + + ntree->update |= NTREE_UPDATE_LINKS; + } + ntreeUpdateTree(ntree); + } + else { + int do_update = FALSE; + for (linkdata = nldrag->links.first; linkdata; linkdata = linkdata->next) { + link = linkdata->data; + + if (link->tonode || link->tosock) { + BLI_remlink(&ntree->links, link); + link->prev = link->next = NULL; + link->tonode = NULL; + link->tosock = NULL; + + ntree->update |= NTREE_UPDATE_LINKS; + do_update = TRUE; + } + } + if (do_update) { + ntreeUpdateTree(ntree); + } + } + } + else { + if (node_find_indicated_socket(snode, &tnode, &tsock, SOCK_OUT)) { + 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 (BLI_findindex(&ntree->links, link) < 0) + BLI_addtail(&ntree->links, link); + + ntree->update |= NTREE_UPDATE_LINKS; + } + ntreeUpdateTree(ntree); + } + else { + int do_update = FALSE; + for (linkdata = nldrag->links.first; linkdata; linkdata = linkdata->next) { + link = linkdata->data; + + if (link->fromnode || link->fromsock) { + BLI_remlink(&ntree->links, link); + link->prev = link->next = NULL; + link->fromnode = NULL; + link->fromsock = NULL; + + ntree->update |= NTREE_UPDATE_LINKS; + do_update = TRUE; + } + } + if (do_update) { + ntreeUpdateTree(ntree); + } + } + } + + ED_region_tag_redraw(ar); + break; + + case LEFTMOUSE: + case RIGHTMOUSE: + case MIDDLEMOUSE: { + for (linkdata = nldrag->links.first; linkdata; linkdata = linkdata->next) { + link = linkdata->data; + + 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); + } + } + 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(ntree, link->tosock, SOCK_IN); + link->fromnode = NULL; + if (BLI_findindex(&ntree->links, link) < 0) + BLI_addtail(&ntree->links, link); + + ntree->update |= NTREE_UPDATE_GROUP_IN | NTREE_UPDATE_LINKS; + } + else if (link->fromnode && link->fromsock) { + link->tosock = node_group_expose_socket(ntree, link->fromsock, SOCK_OUT); + link->tonode = NULL; + if (BLI_findindex(&ntree->links, link) < 0) + BLI_addtail(&ntree->links, link); + + ntree->update |= NTREE_UPDATE_GROUP_OUT | NTREE_UPDATE_LINKS; + } + } + else + nodeRemLink(ntree, link); + } + + ntreeUpdateTree(ntree); + 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 bNodeLinkDrag *node_link_init(SpaceNode *snode, int detach) +{ + 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, &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; + oplink->next = oplink->prev = NULL; + BLI_addtail(&nldrag->links, linkdata); + nodeRemLink(snode->edittree, link); + } + } + } + else { + /* 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, &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; + oplink->next = oplink->prev = NULL; + BLI_addtail(&nldrag->links, linkdata); + nodeRemLink(snode->edittree, link); + + /* send changed event to original link->tonode */ + if (node) + snode_update(snode, node); + } + } + } + else { + /* 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 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; + 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 = node_link_init(snode, detach); + + if (nldrag) { + op->customdata = nldrag; + BLI_addtail(&snode->linkdrag, nldrag); + + /* add modal handler */ + WM_event_add_modal_handler(C, op); + + return OPERATOR_RUNNING_MODAL; + } + 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; + + BLI_remlink(&snode->linkdrag, nldrag); + + BLI_freelistN(&nldrag->links); + MEM_freeN(nldrag); + + return OPERATOR_CANCELLED; +} + +void NODE_OT_link(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Link Nodes"; + ot->idname = "NODE_OT_link"; + ot->description = "Use the mouse to create a link between two nodes"; + + /* api callbacks */ + ot->invoke = node_link_invoke; + ot->modal = node_link_modal; +// ot->exec = node_link_exec; + ot->poll = ED_operator_node_active; + ot->cancel = node_link_cancel; + + /* 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 ***************** */ + +/* makes a link between selected output and input sockets */ +static int node_make_link_exec(bContext *C, wmOperator *op) +{ + SpaceNode *snode = CTX_wm_space_node(C); + int replace = RNA_boolean_get(op->ptr, "replace"); + + ED_preview_kill_jobs(C); + + snode_autoconnect(snode, 1, replace); + + /* deselect sockets after linking */ + node_deselect_all_input_sockets(snode, 0); + node_deselect_all_output_sockets(snode, 0); + + ntreeUpdateTree(snode->edittree); + snode_notify(C, snode); + snode_dag_update(C, snode); + + return OPERATOR_FINISHED; +} + +void NODE_OT_link_make(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Make Links"; + ot->description = "Makes a link between selected output in input sockets"; + ot->idname = "NODE_OT_link_make"; + + /* callbacks */ + ot->exec = node_make_link_exec; + ot->poll = ED_operator_node_active; // XXX we need a special poll which checks that there are selected input/output sockets + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + RNA_def_boolean(ot->srna, "replace", 0, "Replace", "Replace socket connections with the new links"); +} + +/* ********************** Cut Link operator ***************** */ +static int cut_links_intersect(bNodeLink *link, float mcoords[][2], int tot) +{ + float coord_array[NODE_LINK_RESOL + 1][2]; + int i, b; + + if (node_link_bezier_points(NULL, NULL, link, coord_array, NODE_LINK_RESOL)) { + + for (i = 0; i < tot - 1; i++) + for (b = 0; b < NODE_LINK_RESOL; b++) + if (isect_line_line_v2(mcoords[i], mcoords[i + 1], coord_array[b], coord_array[b + 1]) > 0) + return 1; + } + return 0; +} + +static int cut_links_exec(bContext *C, wmOperator *op) +{ + SpaceNode *snode = CTX_wm_space_node(C); + ARegion *ar = CTX_wm_region(C); + float mcoords[256][2]; + int i = 0; + + RNA_BEGIN(op->ptr, itemptr, "path") + { + float loc[2]; + + RNA_float_get_array(&itemptr, "loc", loc); + UI_view2d_region_to_view(&ar->v2d, (int)loc[0], (int)loc[1], + &mcoords[i][0], &mcoords[i][1]); + i++; + if (i >= 256) break; + } + RNA_END; + + if (i > 1) { + bNodeLink *link, *next; + + ED_preview_kill_jobs(C); + + for (link = snode->edittree->links.first; link; link = next) { + next = link->next; + + if (cut_links_intersect(link, mcoords, i)) { + snode_update(snode, link->tonode); + nodeRemLink(snode->edittree, link); + } + } + + ntreeUpdateTree(snode->edittree); + snode_notify(C, snode); + snode_dag_update(C, snode); + + return OPERATOR_FINISHED; + } + + return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH; +} + +void NODE_OT_links_cut(wmOperatorType *ot) +{ + PropertyRNA *prop; + + ot->name = "Cut links"; + ot->idname = "NODE_OT_links_cut"; + ot->description = "Use the mouse to cut (remove) some links"; + + ot->invoke = WM_gesture_lines_invoke; + ot->modal = WM_gesture_lines_modal; + ot->exec = cut_links_exec; + ot->cancel = WM_gesture_lines_cancel; + + ot->poll = ED_operator_node_active; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + prop = RNA_def_property(ot->srna, "path", PROP_COLLECTION, PROP_NONE); + RNA_def_property_struct_runtime(prop, &RNA_OperatorMousePath); + /* internal */ + RNA_def_int(ot->srna, "cursor", BC_KNIFECURSOR, 0, INT_MAX, "Cursor", "", 0, INT_MAX); +} + +/* ********************** Detach links operator ***************** */ + +static int detach_links_exec(bContext *C, wmOperator *UNUSED(op)) +{ + SpaceNode *snode = CTX_wm_space_node(C); + bNodeTree *ntree = snode->edittree; + bNode *node; + + ED_preview_kill_jobs(C); + + for (node = ntree->nodes.first; node; node = node->next) { + if (node->flag & SELECT) { + nodeInternalRelink(ntree, node); + } + } + + ntreeUpdateTree(ntree); + + snode_notify(C, snode); + snode_dag_update(C, snode); + + return OPERATOR_FINISHED; +} + +void NODE_OT_links_detach(wmOperatorType *ot) +{ + ot->name = "Detach Links"; + ot->idname = "NODE_OT_links_detach"; + ot->description = "Remove all links to selected nodes, and try to connect neighbor nodes together"; + + ot->exec = detach_links_exec; + ot->poll = ED_operator_node_active; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} + + +/* ****************** Show Cyclic Dependencies Operator ******************* */ + +static int node_show_cycles_exec(bContext *C, wmOperator *UNUSED(op)) +{ + SpaceNode *snode = CTX_wm_space_node(C); + + /* this is just a wrapper around this call... */ + ntreeUpdateTree(snode->nodetree); + snode_notify(C, snode); + + return OPERATOR_FINISHED; +} + +void NODE_OT_show_cyclic_dependencies(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Show Cyclic Dependencies"; + ot->description = "Sort the nodes and show the cyclic dependencies between the nodes"; + ot->idname = "NODE_OT_show_cyclic_dependencies"; + + /* callbacks */ + ot->exec = node_show_cycles_exec; + ot->poll = ED_operator_node_active; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} + +/* ****************** Set Parent ******************* */ + +static int node_parent_set_exec(bContext *C, wmOperator *UNUSED(op)) +{ + SpaceNode *snode = CTX_wm_space_node(C); + bNodeTree *ntree = snode->edittree; + bNode *frame = nodeGetActive(ntree), *node; + if (!frame || frame->type != NODE_FRAME) + return OPERATOR_CANCELLED; + + for (node = ntree->nodes.first; node; node = node->next) { + if (node == frame) + continue; + if (node->flag & NODE_SELECT) { + nodeDetachNode(node); + nodeAttachNode(node, frame); + } + } + + ED_node_sort(ntree); + WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); + + return OPERATOR_FINISHED; +} + +void NODE_OT_parent_set(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Make Parent"; + ot->description = "Attach selected nodes"; + ot->idname = "NODE_OT_parent_set"; + + /* api callbacks */ + ot->exec = node_parent_set_exec; + ot->poll = ED_operator_node_active; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} + +/* ****************** Clear Parent ******************* */ + +static int node_parent_clear_exec(bContext *C, wmOperator *UNUSED(op)) +{ + SpaceNode *snode = CTX_wm_space_node(C); + bNodeTree *ntree = snode->edittree; + bNode *node; + + for (node = ntree->nodes.first; node; node = node->next) { + if (node->flag & NODE_SELECT) { + nodeDetachNode(node); + } + } + + WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); + + return OPERATOR_FINISHED; +} + +void NODE_OT_parent_clear(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Clear Parent"; + ot->description = "Detach selected nodes"; + ot->idname = "NODE_OT_parent_clear"; + + /* api callbacks */ + ot->exec = node_parent_clear_exec; + ot->poll = ED_operator_node_active; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} + +/* ****************** Join Nodes ******************* */ + +/* tags for depth-first search */ +#define NODE_JOIN_DONE 1 +#define NODE_JOIN_IS_DESCENDANT 2 + +static void node_join_attach_recursive(bNode *node, bNode *frame) +{ + node->done |= NODE_JOIN_DONE; + + if (node == frame) { + node->done |= NODE_JOIN_IS_DESCENDANT; + } + else if (node->parent) { + /* call recursively */ + if (!(node->parent->done & NODE_JOIN_DONE)) + node_join_attach_recursive(node->parent, frame); + + /* in any case: if the parent is a descendant, so is the child */ + if (node->parent->done & NODE_JOIN_IS_DESCENDANT) + node->done |= NODE_JOIN_IS_DESCENDANT; + else if (node->flag & NODE_TEST) { + /* if parent is not an decendant of the frame, reattach the node */ + nodeDetachNode(node); + nodeAttachNode(node, frame); + node->done |= NODE_JOIN_IS_DESCENDANT; + } + } + else if (node->flag & NODE_TEST) { + nodeAttachNode(node, frame); + node->done |= NODE_JOIN_IS_DESCENDANT; + } +} + +static int node_join_exec(bContext *C, wmOperator *UNUSED(op)) +{ + SpaceNode *snode = CTX_wm_space_node(C); + Main *bmain = CTX_data_main(C); + Scene *scene = CTX_data_scene(C); + bNodeTree *ntree = snode->edittree; + bNode *node, *frame; + bNodeTemplate ntemp; + + /* XXX save selection: node_add_node call below sets the new frame as single active+selected node */ + for (node = ntree->nodes.first; node; node = node->next) { + if (node->flag & NODE_SELECT) + node->flag |= NODE_TEST; + else + node->flag &= ~NODE_TEST; + } + + ntemp.main = bmain; + ntemp.scene = scene; + ntemp.type = NODE_FRAME; + frame = node_add_node(snode, bmain, scene, &ntemp, 0.0f, 0.0f); + + /* reset tags */ + for (node = ntree->nodes.first; node; node = node->next) + node->done = 0; + + for (node = ntree->nodes.first; node; node = node->next) { + if (!(node->done & NODE_JOIN_DONE)) + node_join_attach_recursive(node, frame); + } + + /* restore selection */ + for (node = ntree->nodes.first; node; node = node->next) { + if (node->flag & NODE_TEST) + node->flag |= NODE_SELECT; + } + + ED_node_sort(ntree); + WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); + + return OPERATOR_FINISHED; +} + +void NODE_OT_join(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Join Nodes"; + ot->description = "Attach selected nodes to a new common frame"; + ot->idname = "NODE_OT_join"; + + /* api callbacks */ + ot->exec = node_join_exec; + ot->poll = ED_operator_node_active; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} + +/* ****************** Attach ******************* */ + +static int node_attach_exec(bContext *C, wmOperator *UNUSED(op)) +{ + SpaceNode *snode = CTX_wm_space_node(C); + bNodeTree *ntree = snode->edittree; + bNode *frame; + + /* check nodes front to back */ + for (frame = ntree->nodes.last; frame; frame = frame->prev) { + /* skip selected, those are the nodes we want to attach */ + if ((frame->type != NODE_FRAME) || (frame->flag & NODE_SELECT)) + continue; + if (BLI_in_rctf(&frame->totr, snode->mx, snode->my)) + break; + } + if (frame) { + bNode *node, *parent; + for (node = ntree->nodes.last; node; node = node->prev) { + if (node->flag & NODE_SELECT) { + if (node->parent == NULL) { + /* attach all unparented nodes */ + nodeAttachNode(node, frame); + } + else { + /* attach nodes which share parent with the frame */ + for (parent = frame->parent; parent; parent = parent->parent) + if (parent == node->parent) + break; + if (parent) { + nodeDetachNode(node); + nodeAttachNode(node, frame); + } + } + } + } + } + + ED_node_sort(ntree); + WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); + + return OPERATOR_FINISHED; +} + +static int node_attach_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + ARegion *ar = CTX_wm_region(C); + SpaceNode *snode = CTX_wm_space_node(C); + + /* convert mouse coordinates to v2d space */ + UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &snode->mx, &snode->my); + + return node_attach_exec(C, op); +} + +void NODE_OT_attach(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Attach Nodes"; + ot->description = "Attach active node to a frame"; + ot->idname = "NODE_OT_attach"; + + /* api callbacks */ + ot->exec = node_attach_exec; + ot->invoke = node_attach_invoke; + ot->poll = ED_operator_node_active; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} + +/* ****************** Detach ******************* */ + +/* tags for depth-first search */ +#define NODE_DETACH_DONE 1 +#define NODE_DETACH_IS_DESCENDANT 2 + +static void node_detach_recursive(bNode *node) +{ + node->done |= NODE_DETACH_DONE; + + if (node->parent) { + /* call recursively */ + if (!(node->parent->done & NODE_DETACH_DONE)) + node_detach_recursive(node->parent); + + /* in any case: if the parent is a descendant, so is the child */ + if (node->parent->done & NODE_DETACH_IS_DESCENDANT) + node->done |= NODE_DETACH_IS_DESCENDANT; + else if (node->flag & NODE_SELECT) { + /* if parent is not a decendant of a selected node, detach */ + nodeDetachNode(node); + node->done |= NODE_DETACH_IS_DESCENDANT; + } + } + else if (node->flag & NODE_SELECT) { + node->done |= NODE_DETACH_IS_DESCENDANT; + } +} + + +/* detach the root nodes in the current selection */ +static int node_detach_exec(bContext *C, wmOperator *UNUSED(op)) +{ + SpaceNode *snode = CTX_wm_space_node(C); + bNodeTree *ntree = snode->edittree; + bNode *node; + + /* reset tags */ + for (node = ntree->nodes.first; node; node = node->next) + node->done = 0; + /* detach nodes recursively + * relative order is preserved here! + */ + for (node = ntree->nodes.first; node; node = node->next) { + if (!(node->done & NODE_DETACH_DONE)) + node_detach_recursive(node); + } + + ED_node_sort(ntree); + WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL); + + return OPERATOR_FINISHED; +} + +void NODE_OT_detach(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Detach Nodes"; + ot->description = "Detach selected nodes from parents"; + ot->idname = "NODE_OT_detach"; + + /* api callbacks */ + ot->exec = node_detach_exec; + ot->poll = ED_operator_node_active; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} + +/* ********************* automatic node insert on dragging ******************* */ + + +/* prevent duplicate testing code below */ +static SpaceNode *ed_node_link_conditions(ScrArea *sa, bNode **select) +{ + SpaceNode *snode = sa ? sa->spacedata.first : NULL; + bNode *node; + bNodeLink *link; + + /* no unlucky accidents */ + if (sa == NULL || sa->spacetype != SPACE_NODE) return NULL; + + *select = NULL; + + for (node = snode->edittree->nodes.first; node; node = node->next) { + if (node->flag & SELECT) { + if (*select) + break; + else + *select = node; + } + } + /* only one selected */ + if (node || *select == NULL) return NULL; + + /* correct node */ + if ((*select)->inputs.first == NULL || (*select)->outputs.first == NULL) return NULL; + + /* test node for links */ + for (link = snode->edittree->links.first; link; link = link->next) { + if (link->tonode == *select || link->fromnode == *select) + return NULL; + } + + return snode; +} + +/* test == 0, clear all intersect flags */ +void ED_node_link_intersect_test(ScrArea *sa, int test) +{ + bNode *select; + SpaceNode *snode = ed_node_link_conditions(sa, &select); + bNodeLink *link, *selink = NULL; + float mcoords[6][2]; + + if (snode == NULL) return; + + /* clear flags */ + for (link = snode->edittree->links.first; link; link = link->next) + link->flag &= ~NODE_LINKFLAG_HILITE; + + if (test == 0) return; + + /* okay, there's 1 node, without links, now intersect */ + mcoords[0][0] = select->totr.xmin; + mcoords[0][1] = select->totr.ymin; + mcoords[1][0] = select->totr.xmax; + mcoords[1][1] = select->totr.ymin; + mcoords[2][0] = select->totr.xmax; + mcoords[2][1] = select->totr.ymax; + mcoords[3][0] = select->totr.xmin; + mcoords[3][1] = select->totr.ymax; + mcoords[4][0] = select->totr.xmin; + mcoords[4][1] = select->totr.ymin; + mcoords[5][0] = select->totr.xmax; + mcoords[5][1] = select->totr.ymax; + + /* we only tag a single link for intersect now */ + /* idea; use header dist when more? */ + for (link = snode->edittree->links.first; link; link = link->next) { + + if (cut_links_intersect(link, mcoords, 5)) { /* intersect code wants edges */ + if (selink) + break; + selink = link; + } + } + + if (link == NULL && selink) + selink->flag |= NODE_LINKFLAG_HILITE; +} + +/* assumes sockets in list */ +static bNodeSocket *socket_best_match(ListBase *sockets) +{ + bNodeSocket *sock; + int type, maxtype = 0; + + /* find type range */ + for (sock = sockets->first; sock; sock = sock->next) + maxtype = MAX2(sock->type, maxtype); + + /* try all types, starting from 'highest' (i.e. colors, vectors, values) */ + for (type = maxtype; type >= 0; --type) { + for (sock = sockets->first; sock; sock = sock->next) { + if (!nodeSocketIsHidden(sock) && type == sock->type) { + return sock; + } + } + } + + /* no visible sockets, unhide first of highest type */ + for (type = maxtype; type >= 0; --type) { + for (sock = sockets->first; sock; sock = sock->next) { + if (type == sock->type) { + sock->flag &= ~SOCK_HIDDEN; + return sock; + } + } + } + + return NULL; +} + +/* assumes link with NODE_LINKFLAG_HILITE set */ +void ED_node_link_insert(ScrArea *sa) +{ + bNode *node, *select; + SpaceNode *snode = ed_node_link_conditions(sa, &select); + bNodeLink *link; + bNodeSocket *sockto; + + if (snode == NULL) return; + + /* get the link */ + for (link = snode->edittree->links.first; link; link = link->next) + if (link->flag & NODE_LINKFLAG_HILITE) + break; + + if (link) { + node = link->tonode; + sockto = link->tosock; + + link->tonode = select; + link->tosock = socket_best_match(&select->inputs); + link->flag &= ~NODE_LINKFLAG_HILITE; + + nodeAddLink(snode->edittree, select, socket_best_match(&select->outputs), node, sockto); + ntreeUpdateTree(snode->edittree); /* needed for pointers */ + snode_update(snode, select); + ED_node_changed_update(snode->id, select); + } +} diff --git a/source/blender/editors/space_node/node_select.c b/source/blender/editors/space_node/node_select.c index 1ea763a413d..603603b9f07 100644 --- a/source/blender/editors/space_node/node_select.c +++ b/source/blender/editors/space_node/node_select.c @@ -537,26 +537,34 @@ void NODE_OT_select_border(wmOperatorType *ot) /* ****** Select/Deselect All ****** */ -static int node_select_all_exec(bContext *C, wmOperator *UNUSED(op)) +static int node_select_all_exec(bContext *C, wmOperator *op) { SpaceNode *snode = CTX_wm_space_node(C); - bNode *first = snode->edittree->nodes.first; + ListBase *node_lb = &snode->edittree->nodes; bNode *node; - int count= 0; + int action = RNA_enum_get(op->ptr, "action"); - for (node=first; node; node=node->next) - if (node->flag & NODE_SELECT) - count++; + if (action == SEL_TOGGLE) { + if (ED_node_select_check(node_lb)) + action = SEL_DESELECT; + else + action = SEL_SELECT; + } - if (count) { - for (node=first; node; node=node->next) - node_deselect(node); + for (node = node_lb->first; node; node = node->next) { + switch (action) { + case SEL_SELECT: + node_select(node); + break; + case SEL_DESELECT: + node_deselect(node); + break; + case SEL_INVERT: + ((node->flag & SELECT) ? node_deselect : node_select)(node); + break; + } } - else { - for (node=first; node; node=node->next) - node_select(node); - } - + ED_node_sort(snode->edittree); WM_event_add_notifier(C, NC_NODE|NA_SELECTED, NULL); @@ -576,6 +584,8 @@ void NODE_OT_select_all(wmOperatorType *ot) /* flags */ ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO; + + WM_operator_properties_select_all(ot); } /* ****** Select Linked To ****** */ diff --git a/source/blender/editors/space_node/space_node.c b/source/blender/editors/space_node/space_node.c index ce187c46625..bfc83018dbb 100644 --- a/source/blender/editors/space_node/space_node.c +++ b/source/blender/editors/space_node/space_node.c @@ -263,7 +263,7 @@ static void node_area_listener(ScrArea *sa, wmNotifier *wmn) } } -static void node_area_refresh(const struct bContext *C, struct ScrArea *sa) +static void node_area_refresh(const struct bContext *C, ScrArea *sa) { /* default now: refresh node is starting preview */ SpaceNode *snode = sa->spacedata.first; diff --git a/source/blender/editors/space_outliner/outliner_tools.c b/source/blender/editors/space_outliner/outliner_tools.c index 3d01de1c67a..bf76fdda61e 100644 --- a/source/blender/editors/space_outliner/outliner_tools.c +++ b/source/blender/editors/space_outliner/outliner_tools.c @@ -324,6 +324,14 @@ static void id_fake_user_clear_cb(bContext *UNUSED(C), Scene *UNUSED(scene), Tre } } +static void id_select_linked_cb(bContext *C, Scene *UNUSED(scene), TreeElement *UNUSED(te), + TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem) +{ + ID *id = tselem->id; + + ED_object_select_linked_by_id(C, id); +} + static void singleuser_action_cb(bContext *C, Scene *UNUSED(scene), TreeElement *UNUSED(te), TreeStoreElem *tsep, TreeStoreElem *tselem) { @@ -522,6 +530,18 @@ static void sequence_cb(int event, TreeElement *te, TreeStoreElem *tselem, void (void)tselem; } +static void data_select_linked_cb(int event, TreeElement *te, TreeStoreElem *UNUSED(tselem), void *C_v) +{ + if (event == 5) { + if (RNA_struct_is_ID(te->rnaptr.type)) { + bContext *C = (bContext *) C_v; + ID *id = te->rnaptr.data; + + ED_object_select_linked_by_id(C, id); + } + } +} + static void outliner_do_data_operation(SpaceOops *soops, int type, int event, ListBase *lb, void (*operation_cb)(int, TreeElement *, TreeStoreElem *, void *), void *arg) @@ -728,7 +748,9 @@ typedef enum eOutlinerIdOpTypes { OUTLINER_IDOP_FAKE_ADD, OUTLINER_IDOP_FAKE_CLEAR, - OUTLINER_IDOP_RENAME + OUTLINER_IDOP_RENAME, + + OUTLINER_IDOP_SELECT_LINKED } eOutlinerIdOpTypes; // TODO: implement support for changing the ID-block used @@ -740,6 +762,7 @@ static EnumPropertyItem prop_id_op_types[] = { "Ensure datablock gets saved even if it isn't in use (e.g. for motion and material libraries)"}, {OUTLINER_IDOP_FAKE_CLEAR, "CLEAR_FAKE", 0, "Clear Fake User", ""}, {OUTLINER_IDOP_RENAME, "RENAME", 0, "Rename", ""}, + {OUTLINER_IDOP_SELECT_LINKED, "SELECT_LINKED", 0, "Select Linked", ""}, {0, NULL, 0, NULL, NULL} }; @@ -855,6 +878,11 @@ static int outliner_id_operation_exec(bContext *C, wmOperator *op) ED_undo_push(C, "Rename"); } break; + + case OUTLINER_IDOP_SELECT_LINKED: + outliner_do_libdata_operation(C, scene, soops, &soops->tree, id_select_linked_cb); + ED_undo_push(C, "Select"); + break; default: // invalid - unhandled @@ -1115,6 +1143,7 @@ static EnumPropertyItem prop_data_op_types[] = { {2, "DESELECT", 0, "Deselect", ""}, {3, "HIDE", 0, "Hide", ""}, {4, "UNHIDE", 0, "Unhide", ""}, + {5, "SELECT_LINKED", 0, "Select Linked", ""}, {0, NULL, 0, NULL, NULL} }; @@ -1158,6 +1187,11 @@ static int outliner_data_operation_exec(bContext *C, wmOperator *op) outliner_do_data_operation(soops, datalevel, event, &soops->tree, sequence_cb, scene); } } + else if (datalevel == TSE_RNA_STRUCT) { + if (event == 5) { + outliner_do_data_operation(soops, datalevel, event, &soops->tree, data_select_linked_cb, C); + } + } return OPERATOR_FINISHED; } diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index 38f29e8816e..9cbb9006187 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -990,55 +990,28 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq /* draw grease-pencil (screen aligned) */ draw_gpencil_view2d(C, 0); + + + /* NOTE: sequencer mask editing isnt finished, the draw code is working but editing not, + * for now just disable drawing since the strip frame will likely be offset */ + //if (sc->mode == SC_MODE_MASKEDIT) { - if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) { - Sequence *seq_act = BKE_sequencer_active_get(scene); + if (0 && sseq->mainb == SEQ_DRAW_IMG_IMBUF) { + Mask *mask = BKE_sequencer_mask_get(scene); - if (seq_act && seq_act->type == SEQ_TYPE_MASK && seq_act->mask) { - int x, y; + if (mask) { int width, height; - float zoomx, zoomy; + // ED_mask_get_size(C, &width, &height); - /* frame image */ - float maxdim; - float xofs, yofs; + //Scene *scene = CTX_data_scene(C); + width = (scene->r.size * scene->r.xsch) / 100; + height = (scene->r.size * scene->r.ysch) / 100; - /* find window pixel coordinates of origin */ - UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &x, &y); - - width = v2d->tot.xmax - v2d->tot.xmin; - height = v2d->tot.ymax - v2d->tot.ymin; - - zoomx = (float)(ar->winrct.xmax - ar->winrct.xmin + 1) / (float)((ar->v2d.cur.xmax - ar->v2d.cur.xmin)); - zoomy = (float)(ar->winrct.ymax - ar->winrct.ymin + 1) / (float)((ar->v2d.cur.ymax - ar->v2d.cur.ymin)); - - x += v2d->tot.xmin * zoomx; - y += v2d->tot.ymin * zoomy; - - /* frame the image */ - maxdim = maxf(width, height); - if (width == height) { - xofs = yofs = 0; - } - else if (width < height) { - xofs = ((height - width) / -2.0f) * zoomx; - yofs = 0.0f; - } - else { /* (width > height) */ - xofs = 0.0f; - yofs = ((width - height) / -2.0f) * zoomy; - } - - /* apply transformation so mask editing tools will assume drawing from the origin in normalized space */ - glPushMatrix(); - glTranslatef(x + xofs, y + yofs, 0); - glScalef(maxdim * zoomx, maxdim * zoomy, 0); - - ED_mask_draw((bContext *)C, 0, 0); // sc->mask_draw_flag, sc->mask_draw_type - - ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW); - - glPopMatrix(); + ED_mask_draw_region(mask, ar, + 0, 0, /* TODO */ + width, height, + FALSE, TRUE, + NULL, C); } } @@ -1081,7 +1054,7 @@ static void draw_seq_backdrop(View2D *v2d) glRectf(v2d->cur.xmin, -1.0, v2d->cur.xmax, 1.0); /* Alternating horizontal stripes */ - i = MAX2(1, ((int)v2d->cur.ymin) - 1); + i = maxi(1, ((int)v2d->cur.ymin) - 1); glBegin(GL_QUADS); while (i < v2d->cur.ymax) { @@ -1100,7 +1073,7 @@ static void draw_seq_backdrop(View2D *v2d) glEnd(); /* Darker lines separating the horizontal bands */ - i = MAX2(1, ((int)v2d->cur.ymin) - 1); + i = maxi(1, ((int)v2d->cur.ymin) - 1); UI_ThemeColor(TH_GRID); glBegin(GL_LINES); diff --git a/source/blender/editors/space_sequencer/sequencer_edit.c b/source/blender/editors/space_sequencer/sequencer_edit.c index 82e2730c59e..4034c9f98f0 100644 --- a/source/blender/editors/space_sequencer/sequencer_edit.c +++ b/source/blender/editors/space_sequencer/sequencer_edit.c @@ -466,6 +466,33 @@ void recurs_sel_seq(Sequence *seqm) } } +int ED_space_sequencer_maskedit_mask_poll(bContext *C) +{ + /* in this case both funcs are the same, for clip editor not */ + return ED_space_sequencer_maskedit_poll(C); +} + +int ED_space_sequencer_check_show_maskedit(SpaceSeq *sseq, Scene *scene) +{ + if (sseq && sseq->mainb == SEQ_DRAW_IMG_IMBUF) { + return (BKE_sequencer_mask_get(scene) != NULL); + } + + return FALSE; +} + +int ED_space_sequencer_maskedit_poll(bContext *C) +{ + SpaceSeq *sseq = CTX_wm_space_seq(C); + + if (sseq) { + Scene *scene = CTX_data_scene(C); + return ED_space_sequencer_check_show_maskedit(sseq, scene); + } + + return FALSE; +} + int seq_effect_find_selected(Scene *scene, Sequence *activeseq, int type, Sequence **selseq1, Sequence **selseq2, Sequence **selseq3, const char **error_str) { Editing *ed = BKE_sequencer_editing_get(scene, FALSE); @@ -2084,7 +2111,7 @@ static int sequencer_view_all_preview_exec(bContext *C, wmOperator *UNUSED(op)) zoomY = ((float)height) / ((float)imgheight); sseq->zoom = (zoomX < zoomY) ? zoomX : zoomY; - sseq->zoom = 1.0f / power_of_2(1 / MIN2(zoomX, zoomY) ); + sseq->zoom = 1.0f / power_of_2(1 / minf(zoomX, zoomY)); } else { sseq->zoom = 1.0f; @@ -2113,13 +2140,13 @@ void SEQUENCER_OT_view_all_preview(wmOperatorType *ot) static int sequencer_view_zoom_ratio_exec(bContext *C, wmOperator *op) { - RenderData *r = &CTX_data_scene(C)->r; + RenderData *rd = &CTX_data_scene(C)->r; View2D *v2d = UI_view2d_fromcontext(C); float ratio = RNA_float_get(op->ptr, "ratio"); - float winx = (int)(r->size * r->xsch) / 100; - float winy = (int)(r->size * r->ysch) / 100; + float winx = (int)(rd->size * rd->xsch) / 100; + float winy = (int)(rd->size * rd->ysch) / 100; float facx = (v2d->mask.xmax - v2d->mask.xmin) / winx; float facy = (v2d->mask.ymax - v2d->mask.ymin) / winy; diff --git a/source/blender/editors/space_sequencer/space_sequencer.c b/source/blender/editors/space_sequencer/space_sequencer.c index cabc761161e..34ca26a3176 100644 --- a/source/blender/editors/space_sequencer/space_sequencer.c +++ b/source/blender/editors/space_sequencer/space_sequencer.c @@ -300,7 +300,10 @@ static void sequencer_main_area_init(wmWindowManager *wm, ARegion *ar) ListBase *lb; UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy); - + +// keymap = WM_keymap_find(wm->defaultconf, "Mask Editing", 0, 0); +// WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + keymap = WM_keymap_find(wm->defaultconf, "SequencerCommon", SPACE_SEQ, 0); WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); @@ -409,9 +412,9 @@ static int sequencer_context(const bContext *C, const char *member, bContextData return TRUE; } else if (CTX_data_equals(member, "edit_mask")) { - Sequence *seq_act = BKE_sequencer_active_get(scene); - if (seq_act && seq_act->type == SEQ_TYPE_MASK && seq_act->mask) { - CTX_data_id_pointer_set(result, &seq_act->mask->id); + Mask *mask = BKE_sequencer_mask_get(scene); + if (mask) { + CTX_data_id_pointer_set(result, &mask->id); } return TRUE; } @@ -468,6 +471,9 @@ static void sequencer_preview_area_init(wmWindowManager *wm, ARegion *ar) UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy); +// keymap = WM_keymap_find(wm->defaultconf, "Mask Editing", 0, 0); +// WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); + keymap = WM_keymap_find(wm->defaultconf, "SequencerCommon", SPACE_SEQ, 0); WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); diff --git a/source/blender/editors/space_view3d/drawarmature.c b/source/blender/editors/space_view3d/drawarmature.c index 48b3672c144..a05bc5eddc7 100644 --- a/source/blender/editors/space_view3d/drawarmature.c +++ b/source/blender/editors/space_view3d/drawarmature.c @@ -171,7 +171,7 @@ static short set_pchan_glColor(short colCode, int boneflag, short constflag) } else { if ((boneflag & BONE_DRAW_ACTIVE) && (boneflag & BONE_SELECTED)) { - UI_ThemeColorShade(TH_BONE_POSE, 40); + UI_ThemeColor(TH_BONE_POSE_ACTIVE); } else if (boneflag & BONE_DRAW_ACTIVE) { UI_ThemeColorBlend(TH_WIRE, TH_BONE_POSE, 0.15f); /* unselected active */ diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index ad6df39869a..2d3cf72643f 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -849,7 +849,7 @@ void view3d_cached_text_draw_add(const float co[3], BLI_addtail(strings, vos); copy_v3_v3(vos->vec, co); - vos->col.pack = *((int *)col); + copy_v4_v4_char((char *)vos->col.ub, (const char *)col); vos->xoffs = xoffs; vos->flag = flag; vos->str_len = alloc_len - 1; @@ -4317,7 +4317,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv ParticleDrawData *pdd = psys->pdd; Material *ma; float vel[3], imat[4][4]; - float timestep, pixsize_scale, pa_size, r_tilt, r_length; + float timestep, pixsize_scale = 1.0f, pa_size, r_tilt, r_length; float pa_time, pa_birthtime, pa_dietime, pa_health, intensity; float cfra; float ma_col[3] = {0.0f, 0.0f, 0.0f}; @@ -6221,9 +6221,9 @@ static void get_local_bounds(Object *ob, float center[3], float size[3]) copy_v3_v3(size, ob->size); } else { - size[0] = 0.5 * fabs(bb->vec[0][0] - bb->vec[4][0]); - size[1] = 0.5 * fabs(bb->vec[0][1] - bb->vec[2][1]); - size[2] = 0.5 * fabs(bb->vec[0][2] - bb->vec[1][2]); + size[0] = 0.5 * fabsf(bb->vec[0][0] - bb->vec[4][0]); + size[1] = 0.5 * fabsf(bb->vec[0][1] - bb->vec[2][1]); + size[2] = 0.5 * fabsf(bb->vec[0][2] - bb->vec[1][2]); center[0] = (bb->vec[0][0] + bb->vec[4][0]) / 2.0; center[1] = (bb->vec[0][1] + bb->vec[2][1]) / 2.0; @@ -6472,14 +6472,12 @@ static void draw_hooks(Object *ob) } } -static void draw_rigid_body_pivot(bRigidBodyJointConstraint *data, const unsigned char ob_wire_col[4]) +static void draw_rigid_body_pivot(bRigidBodyJointConstraint *data, const short dflag, unsigned char ob_wire_col[4]) { const char *axis_str[3] = {"px", "py", "pz"}; int axis; float mat[4][4]; - /* color */ - eul_to_mat4(mat, &data->axX); glLineWidth(4.0f); setlinestyle(2); @@ -6489,7 +6487,7 @@ static void draw_rigid_body_pivot(bRigidBodyJointConstraint *data, const unsigne copy_v3_v3(v, &data->pivX); - dir[axis] = 1.f; + dir[axis] = 1.0f; glBegin(GL_LINES); mul_m4_v3(mat, dir); add_v3_v3(v, dir); @@ -6497,7 +6495,11 @@ static void draw_rigid_body_pivot(bRigidBodyJointConstraint *data, const unsigne glVertex3fv(v); glEnd(); - view3d_cached_text_draw_add(v, axis_str[axis], 0, V3D_CACHE_TEXT_ASCII, ob_wire_col); + /* when const color is set wirecolor is NULL - we could get the current color but + * with selection and group instancing its not needed to draw the text */ + if ((dflag & DRAW_CONSTCOLOR) == 0) { + view3d_cached_text_draw_add(v, axis_str[axis], 0, V3D_CACHE_TEXT_ASCII, ob_wire_col); + } } glLineWidth(1.0f); setlinestyle(0); @@ -6712,8 +6714,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, const short /* draw outline for selected objects, mesh does itself */ if ((v3d->flag & V3D_SELECT_OUTLINE) && ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) && ob->type != OB_MESH) { if (dt > OB_WIRE && (ob->mode & OB_MODE_EDIT) == 0 && (dflag & DRAW_SCENESET) == 0) { - if (!(ob->dtx & OB_DRAWWIRE) && (ob->flag & SELECT) && !(dflag & DRAW_PICKING)) { - + if (!(ob->dtx & OB_DRAWWIRE) && (ob->flag & SELECT) && !(dflag & (DRAW_PICKING | DRAW_CONSTCOLOR))) { drawObjectSelect(scene, v3d, ar, base, ob_wire_col); } } @@ -7098,7 +7099,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, const short if (con->type == CONSTRAINT_TYPE_RIGIDBODYJOINT) { bRigidBodyJointConstraint *data = (bRigidBodyJointConstraint *)con->data; if (data->flag & CONSTRAINT_DRAW_PIVOT) - draw_rigid_body_pivot(data, ob_wire_col); + draw_rigid_body_pivot(data, dflag, ob_wire_col); } } diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c index 88d08d937be..1e371cb074d 100644 --- a/source/blender/editors/space_view3d/space_view3d.c +++ b/source/blender/editors/space_view3d/space_view3d.c @@ -984,7 +984,7 @@ static void view3d_props_area_listener(ARegion *ar, wmNotifier *wmn) } /*area (not region) level listener*/ -static void space_view3d_listener(struct ScrArea *sa, struct wmNotifier *wmn) +static void space_view3d_listener(ScrArea *sa, struct wmNotifier *wmn) { View3D *v3d = sa->spacedata.first; diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 1dbc40a0c07..85a4d911df5 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -1716,7 +1716,7 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d, /* for some reason; zoomlevels down refuses to use GL_ALPHA_SCALE */ if (zoomx < 1.0f || zoomy < 1.0f) { - float tzoom = MIN2(zoomx, zoomy); + float tzoom = minf(zoomx, zoomy); int mip = 0; if ((ibuf->userflags & IB_MIPMAP_INVALID) != 0) { @@ -1779,8 +1779,12 @@ static void view3d_draw_bgpic_test(Scene *scene, ARegion *ar, View3D *v3d, if ((v3d->flag & V3D_DISPBGPICS) == 0) return; + /* disabled - mango request, since footage /w only render is quite useful + * and this option is easy to disable all background images at once */ +#if 0 if (v3d->flag2 & V3D_RENDER_OVERRIDE) return; +#endif if ((rv3d->view == RV3D_VIEW_USER) || (rv3d->persp != RV3D_ORTHO)) { if (rv3d->persp == RV3D_CAMOB) { diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 97123767211..ba665cfb89c 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -2435,7 +2435,7 @@ static int view3d_center_camera_exec(bContext *C, wmOperator *UNUSED(op)) /* was xfac = (float)ar->winx / (float)(size[0] + 4); yfac = (float)ar->winy / (float)(size[1] + 4); - rv3d->camzoom = BKE_screen_view3d_zoom_from_fac(MIN2(xfac, yfac)); + rv3d->camzoom = BKE_screen_view3d_zoom_from_fac(minf(xfac, yfac)); CLAMP(rv3d->camzoom, RV3D_CAMZOOM_MIN, RV3D_CAMZOOM_MAX); WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, CTX_wm_view3d(C)); @@ -2873,7 +2873,7 @@ static int viewnumpad_exec(bContext *C, wmOperator *op) break; case RV3D_VIEW_BACK: - axis_set_view(C, v3d, ar, 0.0, 0.0, -cosf(M_PI / 4.0), -cosf(M_PI / 4.0), + axis_set_view(C, v3d, ar, 0.0, 0.0, -M_SQRT1_2, -M_SQRT1_2, viewnum, nextperspo, align_active); break; @@ -2888,7 +2888,7 @@ static int viewnumpad_exec(bContext *C, wmOperator *op) break; case RV3D_VIEW_FRONT: - axis_set_view(C, v3d, ar, cosf(M_PI / 4.0), -sinf(M_PI / 4.0), 0.0, 0.0, + axis_set_view(C, v3d, ar, M_SQRT1_2, -M_SQRT1_2, 0.0, 0.0, viewnum, nextperspo, align_active); break; @@ -3008,7 +3008,6 @@ static int vieworbit_exec(bContext *C, wmOperator *op) View3D *v3d; ARegion *ar; RegionView3D *rv3d; - float phi, q1[4], new_quat[4]; int orbitdir; /* no NULL check is needed, poll checks */ @@ -3019,36 +3018,40 @@ static int vieworbit_exec(bContext *C, wmOperator *op) if (rv3d->viewlock == 0) { if ((rv3d->persp != RV3D_CAMOB) || ED_view3d_camera_lock_check(v3d, rv3d)) { - if (orbitdir == V3D_VIEW_STEPLEFT || orbitdir == V3D_VIEW_STEPRIGHT) { - float si; + float angle = DEG2RADF((float)U.pad_rot_angle); + float quat_mul[4]; + float quat_new[4]; + + if (ELEM(orbitdir, V3D_VIEW_STEPLEFT, V3D_VIEW_STEPRIGHT)) { + const float zvec[3] = {0.0f, 0.0f, 1.0f}; + + if (orbitdir == V3D_VIEW_STEPRIGHT) { + angle = -angle; + } + /* z-axis */ - phi = (float)(M_PI / 360.0) * U.pad_rot_angle; - if (orbitdir == V3D_VIEW_STEPRIGHT) phi = -phi; - si = (float)sin(phi); - q1[0] = (float)cos(phi); - q1[1] = q1[2] = 0.0; - q1[3] = si; - mul_qt_qtqt(new_quat, rv3d->viewquat, q1); - rv3d->view = RV3D_VIEW_USER; + axis_angle_to_quat(quat_mul, zvec, angle); } - else if (orbitdir == V3D_VIEW_STEPDOWN || orbitdir == V3D_VIEW_STEPUP) { + else { + + if (orbitdir == V3D_VIEW_STEPDOWN) { + angle = -angle; + } + /* horizontal axis */ - copy_v3_v3(q1 + 1, rv3d->viewinv[0]); - - normalize_v3(q1 + 1); - phi = (float)(M_PI / 360.0) * U.pad_rot_angle; - if (orbitdir == V3D_VIEW_STEPDOWN) phi = -phi; - q1[0] = (float)cos(phi); - mul_v3_fl(q1 + 1, sin(phi)); - mul_qt_qtqt(new_quat, rv3d->viewquat, q1); - rv3d->view = RV3D_VIEW_USER; + axis_angle_to_quat(quat_mul, rv3d->viewinv[0], angle); } - smooth_view(C, CTX_wm_view3d(C), ar, NULL, NULL, NULL, new_quat, NULL, NULL); + mul_qt_qtqt(quat_new, rv3d->viewquat, quat_mul); + rv3d->view = RV3D_VIEW_USER; + + smooth_view(C, CTX_wm_view3d(C), ar, NULL, NULL, NULL, quat_new, NULL, NULL); + + return OPERATOR_FINISHED; } } - return OPERATOR_FINISHED; + return OPERATOR_CANCELLED; } void VIEW3D_OT_view_orbit(wmOperatorType *ot) @@ -3645,7 +3648,7 @@ int ED_view3d_autodist_simple(ARegion *ar, const int mval[2], float mouse_worldl return 1; } -int ED_view3d_autodist_depth(struct ARegion *ar, const int mval[2], int margin, float *depth) +int ED_view3d_autodist_depth(ARegion *ar, const int mval[2], int margin, float *depth) { *depth = view_autodist_depth_margin(ar, mval, margin); @@ -3654,7 +3657,7 @@ int ED_view3d_autodist_depth(struct ARegion *ar, const int mval[2], int margin, static int depth_segment_cb(int x, int y, void *userData) { - struct { struct ARegion *ar; int margin; float depth; } *data = userData; + struct { ARegion *ar; int margin; float depth; } *data = userData; int mval[2]; float depth; @@ -3672,10 +3675,10 @@ static int depth_segment_cb(int x, int y, void *userData) } } -int ED_view3d_autodist_depth_seg(struct ARegion *ar, const int mval_sta[2], const int mval_end[2], +int ED_view3d_autodist_depth_seg(ARegion *ar, const int mval_sta[2], const int mval_end[2], int margin, float *depth) { - struct { struct ARegion *ar; int margin; float depth; } data = {NULL}; + struct { ARegion *ar; int margin; float depth; } data = {NULL}; int p1[2]; int p2[2]; diff --git a/source/blender/editors/space_view3d/view3d_fly.c b/source/blender/editors/space_view3d/view3d_fly.c index 40837d00409..561e97a8393 100644 --- a/source/blender/editors/space_view3d/view3d_fly.c +++ b/source/blender/editors/space_view3d/view3d_fly.c @@ -219,7 +219,7 @@ typedef struct FlyInfo { } FlyInfo; -static void drawFlyPixel(const struct bContext *UNUSED(C), struct ARegion *UNUSED(ar), void *arg) +static void drawFlyPixel(const struct bContext *UNUSED(C), ARegion *UNUSED(ar), void *arg) { FlyInfo *fly = arg; @@ -333,8 +333,9 @@ static int initFlyInfo(bContext *C, FlyInfo *fly, wmOperator *op, wmEvent *event upvec[2] = 0.0f; copy_m3_m4(mat, fly->rv3d->viewinv); mul_m3_v3(mat, upvec); - if (fabs(upvec[2]) < 0.1) + if (fabsf(upvec[2]) < 0.1f) { fly->zlock = 1; + } upvec[0] = 0; upvec[1] = 0; upvec[2] = 0; @@ -548,7 +549,7 @@ static void flyEvent(FlyInfo *fly, wmEvent *event) time_wheel = (float)(time_currwheel - fly->time_lastwheel); fly->time_lastwheel = time_currwheel; /* Mouse wheel delays range from (0.5 == slow) to (0.01 == fast) */ - time_wheel = 1.0f + (10.0f - (20.0f * MIN2(time_wheel, 0.5f))); /* 0-0.5 -> 0-5.0 */ + time_wheel = 1.0f + (10.0f - (20.0f * minf(time_wheel, 0.5f))); /* 0-0.5 -> 0-5.0 */ if (fly->speed < 0.0f) { fly->speed = 0.0f; @@ -566,7 +567,7 @@ static void flyEvent(FlyInfo *fly, wmEvent *event) time_currwheel = PIL_check_seconds_timer(); time_wheel = (float)(time_currwheel - fly->time_lastwheel); fly->time_lastwheel = time_currwheel; - time_wheel = 1.0f + (10.0f - (20.0f * MIN2(time_wheel, 0.5f))); /* 0-0.5 -> 0-5.0 */ + time_wheel = 1.0f + (10.0f - (20.0f * minf(time_wheel, 0.5f))); /* 0-0.5 -> 0-5.0 */ if (fly->speed > 0.0f) { fly->speed = 0; @@ -842,7 +843,7 @@ static int flyApply(bContext *C, FlyInfo *fly) #endif time_current = PIL_check_seconds_timer(); time_redraw = (float)(time_current - fly->time_lastdraw); - time_redraw_clamped = MIN2(0.05f, time_redraw); /* clamp redraw time to avoid jitter in roll correction */ + time_redraw_clamped = minf(0.05f, time_redraw); /* clamp redraw time to avoid jitter in roll correction */ fly->time_lastdraw = time_current; /* Scale the time to use shift to scale the speed down- just like diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index 3abfda78ec3..f9776855d61 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -1125,7 +1125,7 @@ int ED_view3d_lock(RegionView3D *rv3d) break; case RV3D_VIEW_BACK: - QUATSET(rv3d->viewquat, 0.0, 0.0, -cosf(M_PI / 4.0), -cosf(M_PI / 4.0)); + QUATSET(rv3d->viewquat, 0.0, 0.0, -M_SQRT1_2, -M_SQRT1_2); break; case RV3D_VIEW_LEFT: @@ -1137,7 +1137,7 @@ int ED_view3d_lock(RegionView3D *rv3d) break; case RV3D_VIEW_FRONT: - QUATSET(rv3d->viewquat, (float)cos(M_PI / 4.0), -sinf(M_PI / 4.0), 0.0, 0.0); + QUATSET(rv3d->viewquat, M_SQRT1_2, -M_SQRT1_2, 0.0, 0.0); break; case RV3D_VIEW_RIGHT: diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index b1358c9f275..303f477503d 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -74,6 +74,7 @@ #include "ED_view3d.h" #include "ED_mesh.h" #include "ED_clip.h" +#include "ED_mask.h" #include "UI_view2d.h" #include "WM_types.h" @@ -93,7 +94,7 @@ #include -static void drawTransformApply(const struct bContext *C, struct ARegion *ar, void *arg); +static void drawTransformApply(const struct bContext *C, ARegion *ar, void *arg); static int doEdgeSlide(TransInfo *t, float perc); /* ************************** SPACE DEPENDANT CODE **************************** */ @@ -120,16 +121,44 @@ void setTransformViewMatrices(TransInfo *t) calculateCenter2D(t); } -static void convertViewVec2D(View2D *v2d, float vec[3], int dx, int dy) +static void convertViewVec2D(View2D *v2d, float r_vec[3], int dx, int dy) { float divx, divy; divx = v2d->mask.xmax - v2d->mask.xmin; divy = v2d->mask.ymax - v2d->mask.ymin; - vec[0] = (v2d->cur.xmax - v2d->cur.xmin) * dx / divx; - vec[1] = (v2d->cur.ymax - v2d->cur.ymin) * dy / divy; - vec[2] = 0.0f; + r_vec[0] = (v2d->cur.xmax - v2d->cur.xmin) * dx / divx; + r_vec[1] = (v2d->cur.ymax - v2d->cur.ymin) * dy / divy; + r_vec[2] = 0.0f; +} + +static void convertViewVec2D_mask(View2D *v2d, float r_vec[3], int dx, int dy) +{ + float divx, divy; + float mulx, muly; + + divx = v2d->mask.xmax - v2d->mask.xmin; + divy = v2d->mask.ymax - v2d->mask.ymin; + + mulx = (v2d->cur.xmax - v2d->cur.xmin); + muly = (v2d->cur.ymax - v2d->cur.ymin); + + /* difference with convertViewVec2D */ + /* clamp w/h, mask only */ + if (mulx / divx < muly / divy) { + divy = divx; + muly = mulx; + } + else { + divx = divy; + mulx = muly; + } + /* end difference */ + + r_vec[0] = mulx * dx / divx; + r_vec[1] = muly * dy / divy; + r_vec[2] = 0.0f; } void convertViewVec(TransInfo *t, float r_vec[3], int dx, int dy) @@ -143,9 +172,17 @@ void convertViewVec(TransInfo *t, float r_vec[3], int dx, int dy) else if (t->spacetype == SPACE_IMAGE) { float aspx, aspy; - convertViewVec2D(t->view, r_vec, dx, dy); + if (t->options & CTX_MASK) { + + convertViewVec2D_mask(t->view, r_vec, dx, dy); + + ED_space_image_get_aspect(t->sa->spacedata.first, &aspx, &aspy); + } + else { + convertViewVec2D(t->view, r_vec, dx, dy); + ED_space_image_get_uv_aspect(t->sa->spacedata.first, &aspx, &aspy); + } - ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy); r_vec[0] *= aspx; r_vec[1] *= aspy; } @@ -156,32 +193,14 @@ void convertViewVec(TransInfo *t, float r_vec[3], int dx, int dy) convertViewVec2D(&t->ar->v2d, r_vec, dx, dy); } else if (t->spacetype == SPACE_CLIP) { - View2D *v2d = t->view; - float divx, divy; - float mulx, muly; - float aspx = 1.0f, aspy = 1.0f; - - divx = v2d->mask.xmax - v2d->mask.xmin; - divy = v2d->mask.ymax - v2d->mask.ymin; - - mulx = (v2d->cur.xmax - v2d->cur.xmin); - muly = (v2d->cur.ymax - v2d->cur.ymin); + float aspx, aspy; if (t->options & CTX_MASK) { - /* clamp w/h, mask only */ - if (mulx / divx < muly / divy) { - divy = divx; - muly = mulx; - } - else { - divx = divy; - mulx = muly; - } + convertViewVec2D_mask(t->view, r_vec, dx, dy); + } + else { + convertViewVec2D(t->view, r_vec, dx, dy); } - - r_vec[0] = mulx * (dx) / divx; - r_vec[1] = muly * (dy) / divy; - r_vec[2] = 0.0f; if (t->options & CTX_MOVIECLIP) { ED_space_clip_get_aspect_dimension_aware(t->sa->spacedata.first, &aspx, &aspy); @@ -207,13 +226,21 @@ void projectIntView(TransInfo *t, const float vec[3], int adr[2]) project_int_noclip(t->ar, vec, adr); } else if (t->spacetype == SPACE_IMAGE) { - float aspx, aspy, v[2]; + if (t->options & CTX_MASK) { + float v[2]; + ED_mask_point_pos__reverse(t->sa, t->ar, vec[0], vec[1], &v[0], &v[1]); + adr[0] = v[0]; + adr[1] = v[1]; + } + else { + float aspx, aspy, v[2]; - ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy); - v[0] = vec[0] / aspx; - v[1] = vec[1] / aspy; + ED_space_image_get_uv_aspect(t->sa->spacedata.first, &aspx, &aspy); + v[0] = vec[0] / aspx; + v[1] = vec[1] / aspy; - UI_view2d_to_region_no_clip(t->view, v[0], v[1], adr, adr + 1); + UI_view2d_to_region_no_clip(t->view, v[0], v[1], adr, adr + 1); + } } else if (t->spacetype == SPACE_ACTION) { int out[2] = {0, 0}; @@ -254,10 +281,13 @@ void projectIntView(TransInfo *t, const float vec[3], int adr[2]) copy_v2_v2(v, vec); - if (t->options & CTX_MOVIECLIP) + if (t->options & CTX_MOVIECLIP) { ED_space_clip_get_aspect_dimension_aware(t->sa->spacedata.first, &aspx, &aspy); - else if (t->options & CTX_MASK) + } + else if (t->options & CTX_MASK) { + /* MASKTODO - not working as expected */ ED_space_clip_get_aspect(t->sa->spacedata.first, &aspx, &aspy); + } v[0] /= aspx; v[1] /= aspy; @@ -304,13 +334,13 @@ void applyAspectRatio(TransInfo *t, float vec[2]) if ((sima->flag & SI_COORDFLOATS) == 0) { int width, height; - ED_space_image_size(sima, &width, &height); + ED_space_image_get_size(sima, &width, &height); vec[0] *= width; vec[1] *= height; } - ED_space_image_uv_aspect(sima, &aspx, &aspy); + ED_space_image_get_uv_aspect(sima, &aspx, &aspy); vec[0] /= aspx; vec[1] /= aspy; } @@ -344,13 +374,13 @@ void removeAspectRatio(TransInfo *t, float vec[2]) if ((sima->flag & SI_COORDFLOATS) == 0) { int width, height; - ED_space_image_size(sima, &width, &height); + ED_space_image_get_size(sima, &width, &height); vec[0] /= width; vec[1] /= height; } - ED_space_image_uv_aspect(sima, &aspx, &aspy); + ED_space_image_get_uv_aspect(sima, &aspx, &aspy); vec[0] *= aspx; vec[1] *= aspy; } @@ -406,10 +436,17 @@ static void viewRedrawForce(const bContext *C, TransInfo *t) WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, NULL); } else if (t->spacetype == SPACE_IMAGE) { - // XXX how to deal with lock? - SpaceImage *sima = (SpaceImage *)t->sa->spacedata.first; - if (sima->lock) WM_event_add_notifier(C, NC_GEOM | ND_DATA, t->obedit->data); - else ED_area_tag_redraw(t->sa); + if (t->options & CTX_MASK) { + Mask *mask = CTX_data_edit_mask(C); + + WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask); + } + else { + // XXX how to deal with lock? + SpaceImage *sima = (SpaceImage *)t->sa->spacedata.first; + if (sima->lock) WM_event_add_notifier(C, NC_GEOM | ND_DATA, t->obedit->data); + else ED_area_tag_redraw(t->sa); + } } else if (t->spacetype == SPACE_CLIP) { SpaceClip *sc = (SpaceClip *)t->sa->spacedata.first; @@ -423,7 +460,7 @@ static void viewRedrawForce(const bContext *C, TransInfo *t) WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip); } else if (ED_space_clip_check_show_maskedit(sc)) { - Mask *mask = ED_space_clip_get_mask(sc); + Mask *mask = CTX_data_edit_mask(C); WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask); } @@ -932,7 +969,7 @@ int transformEvent(TransInfo *t, wmEvent *event) if (t->flag & T_PROP_EDIT) { t->prop_size *= 1.1f; if (t->spacetype == SPACE_VIEW3D && t->persp != RV3D_ORTHO) - t->prop_size = MIN2(t->prop_size, ((View3D *)t->view)->far); + t->prop_size = minf(t->prop_size, ((View3D *)t->view)->far); calculatePropRatio(t); } t->redraw |= TREDRAW_HARD; @@ -1102,7 +1139,7 @@ int transformEvent(TransInfo *t, wmEvent *event) if (event->alt && t->flag & T_PROP_EDIT) { t->prop_size *= 1.1f; if (t->spacetype == SPACE_VIEW3D && t->persp != RV3D_ORTHO) - t->prop_size = MIN2(t->prop_size, ((View3D *)t->view)->far); + t->prop_size = minf(t->prop_size, ((View3D *)t->view)->far); calculatePropRatio(t); } t->redraw = 1; @@ -1303,10 +1340,11 @@ static void drawArc(float size, float angle_start, float angle_end, int segments { float delta = (angle_end - angle_start) / segments; float angle; + int a; glBegin(GL_LINE_STRIP); - for (angle = angle_start; angle < angle_end; angle += delta) { + for (angle = angle_start, a = 0; a < segments; angle += delta, a++) { glVertex2f(cosf(angle) * size, sinf(angle) * size); } glVertex2f(cosf(angle_end) * size, sinf(angle_end) * size); @@ -1456,7 +1494,7 @@ static void drawHelpline(bContext *UNUSED(C), int x, int y, void *customdata) } } -static void drawTransformView(const struct bContext *C, struct ARegion *UNUSED(ar), void *arg) +static void drawTransformView(const struct bContext *C, ARegion *UNUSED(ar), void *arg) { TransInfo *t = arg; @@ -1467,7 +1505,7 @@ static void drawTransformView(const struct bContext *C, struct ARegion *UNUSED(a } #if 0 -static void drawTransformPixel(const struct bContext *UNUSED(C), struct ARegion *UNUSED(ar), void *UNUSED(arg)) +static void drawTransformPixel(const struct bContext *UNUSED(C), ARegion *UNUSED(ar), void *UNUSED(arg)) { // TransInfo *t = arg; // @@ -1911,7 +1949,7 @@ void transformApply(bContext *C, TransInfo *t) t->context = NULL; } -static void drawTransformApply(const bContext *C, struct ARegion *UNUSED(ar), void *arg) +static void drawTransformApply(const bContext *C, ARegion *UNUSED(ar), void *arg) { TransInfo *t = arg; diff --git a/source/blender/editors/transform/transform_constraints.c b/source/blender/editors/transform/transform_constraints.c index 7c0d4f10186..b5b1fbde184 100644 --- a/source/blender/editors/transform/transform_constraints.c +++ b/source/blender/editors/transform/transform_constraints.c @@ -288,7 +288,7 @@ static void planeProjection(TransInfo *t, float in[3], float out[3]) sub_v3_v3v3(vec, out, in); factor = dot_v3v3(vec, norm); - if (fabs(factor) <= 0.001) { + if (fabsf(factor) <= 0.001f) { return; /* prevent divide by zero */ } factor = dot_v3v3(vec, vec) / factor; @@ -722,7 +722,7 @@ void drawPropCircle(const struct bContext *C, TransInfo *t) else if (t->spacetype == SPACE_IMAGE) { float aspx, aspy; - ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy); + ED_space_image_get_uv_aspect(t->sa->spacedata.first, &aspx, &aspy); glScalef(1.0f / aspx, 1.0f / aspy, 1.0); } diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c index 949266a0cc2..02101b9d02d 100644 --- a/source/blender/editors/transform/transform_conversions.c +++ b/source/blender/editors/transform/transform_conversions.c @@ -438,7 +438,7 @@ static short apply_targetless_ik(Object *ob) /* rotation */ /* [#22409] is partially caused by this, as slight numeric error introduced during * the solving process leads to locked-axis values changing. However, we cannot modify - * the values here, or else there are huge discreptancies between IK-solver (interactive) + * the values here, or else there are huge discrepancies between IK-solver (interactive) * and applied poses. */ if (parchan->rotmode > 0) @@ -2320,7 +2320,7 @@ static void UVsToTransData(SpaceImage *sima, TransData *td, TransData2D *td2d, f { float aspx, aspy; - ED_space_image_uv_aspect(sima, &aspx, &aspy); + ED_space_image_get_uv_aspect(sima, &aspx, &aspy); /* uv coords are scaled by aspects. this is needed for rotations and * proportional editing to be consistent with the stretched uv coords @@ -2428,8 +2428,8 @@ void flushTransUVs(TransInfo *t) int a, width, height; float aspx, aspy, invx, invy; - ED_space_image_uv_aspect(sima, &aspx, &aspy); - ED_space_image_size(sima, &width, &height); + ED_space_image_get_uv_aspect(sima, &aspx, &aspy); + ED_space_image_get_size(sima, &width, &height); invx = 1.0f / aspx; invy = 1.0f / aspy; @@ -2451,7 +2451,7 @@ int clipUVTransform(TransInfo *t, float *vec, int resize) int a, clipx = 1, clipy = 1; float aspx, aspy, min[2], max[2]; - ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy); + ED_space_image_get_uv_aspect(t->sa->spacedata.first, &aspx, &aspy); min[0] = min[1] = 0.0f; max[0] = aspx; max[1] = aspy; @@ -4964,6 +4964,36 @@ void autokeyframe_pose_cb_func(bContext *C, Scene *scene, View3D *v3d, Object *o } } +static void special_aftertrans_update__mask(bContext *C, TransInfo *t) +{ + Mask *mask; + + if (t->spacetype == SPACE_CLIP) { + SpaceClip *sc = t->sa->spacedata.first; + mask = ED_space_clip_get_mask(sc); + } + else if (t->spacetype == SPACE_IMAGE) { + SpaceImage *sima = t->sa->spacedata.first; + mask = ED_space_image_get_mask(sima); + } + else { + BLI_assert(0); + } + + if (t->scene->nodetree) { + /* tracks can be used for stabilization nodes, + * flush update for such nodes */ + nodeUpdateID(t->scene->nodetree, &mask->id); + WM_event_add_notifier(C, NC_SCENE | ND_NODES, NULL); + } + + /* TODO - dont key all masks... */ + if (IS_AUTOKEY_ON(t->scene)) { + Scene *scene = t->scene; + + ED_mask_layer_shape_auto_key_select(mask, CFRA); + } +} /* inserting keys, pointcache, redraw events... */ /* @@ -5009,7 +5039,8 @@ void special_aftertrans_update(bContext *C, TransInfo *t) } } } - + + if (t->spacetype == SPACE_SEQ) { /* freeSeqData in transform_conversions.c does this * keep here so the else at the end wont run... */ @@ -5030,7 +5061,11 @@ void special_aftertrans_update(bContext *C, TransInfo *t) ED_markers_post_apply_transform(&t->scene->markers, t->scene, TFM_TIME_EXTEND, t->values[0], t->frame_side); } } - + } + else if (t->spacetype == SPACE_IMAGE) { + if (t->options & CTX_MASK) { + special_aftertrans_update__mask(C, t); + } } else if (t->spacetype == SPACE_NODE) { SpaceNode *snode = (SpaceNode *)t->sa->spacedata.first; @@ -5056,22 +5091,7 @@ void special_aftertrans_update(bContext *C, TransInfo *t) } } else if (t->options & CTX_MASK) { - SpaceClip *sc = t->sa->spacedata.first; - Mask *mask = ED_space_clip_get_mask(sc); - - if (t->scene->nodetree) { - /* tracks can be used for stabilization nodes, - * flush update for such nodes */ - nodeUpdateID(t->scene->nodetree, &mask->id); - WM_event_add_notifier(C, NC_SCENE | ND_NODES, NULL); - } - - /* TODO - dont key all masks... */ - if (IS_AUTOKEY_ON(t->scene)) { - Scene *scene = t->scene; - - ED_mask_layer_shape_auto_key_select(mask, CFRA); - } + special_aftertrans_update__mask(C, t); } } else if (t->spacetype == SPACE_ACTION) { @@ -5356,6 +5376,8 @@ void special_aftertrans_update(bContext *C, TransInfo *t) else { /* Objects */ int i, recalcObPaths = 0; + BLI_assert(t->flag & T_OBJECT); + for (i = 0; i < t->total; i++) { TransData *td = t->data + i; ListBase pidlist; @@ -6069,19 +6091,17 @@ typedef struct TransDataMasking { MaskSplinePoint *point; } TransDataMasking; -static void MaskPointToTransData(SpaceClip *sc, MaskSplinePoint *point, - TransData *td, TransData2D *td2d, TransDataMasking *tdm, int propmode) +static void MaskPointToTransData(MaskSplinePoint *point, + TransData *td, TransData2D *td2d, TransDataMasking *tdm, + const int propmode, const float asp[2]) { BezTriple *bezt = &point->bezt; - float aspx, aspy; short is_sel_point = MASKPOINT_ISSEL_KNOT(point); short is_sel_any = MASKPOINT_ISSEL_ANY(point); tdm->point = point; copy_m3_m3(tdm->vec, bezt->vec); - ED_space_clip_get_aspect(sc, &aspx, &aspy); - if (propmode || is_sel_point) { int i; for (i = 0; i < 3; i++) { @@ -6089,8 +6109,8 @@ static void MaskPointToTransData(SpaceClip *sc, MaskSplinePoint *point, * proportional editing to be consistent with the stretched CV coords * that are displayed. this also means that for display and numinput, * and when the the CV coords are flushed, these are converted each time */ - td2d->loc[0] = bezt->vec[i][0] * aspx; - td2d->loc[1] = bezt->vec[i][1] * aspy; + td2d->loc[0] = bezt->vec[i][0] * asp[0]; + td2d->loc[1] = bezt->vec[i][1] * asp[1]; td2d->loc[2] = 0.0f; td2d->loc2d = bezt->vec[i]; @@ -6132,8 +6152,8 @@ static void MaskPointToTransData(SpaceClip *sc, MaskSplinePoint *point, copy_v2_v2(tdm->orig_handle, tdm->handle); - td2d->loc[0] = tdm->handle[0] * aspx; - td2d->loc[1] = tdm->handle[1] * aspy; + td2d->loc[0] = tdm->handle[0] * asp[0]; + td2d->loc[1] = tdm->handle[1] * asp[1]; td2d->loc[2] = 0.0f; td2d->loc2d = tdm->handle; @@ -6164,7 +6184,6 @@ static void MaskPointToTransData(SpaceClip *sc, MaskSplinePoint *point, static void createTransMaskingData(bContext *C, TransInfo *t) { - SpaceClip *sc = CTX_wm_space_clip(C); Mask *mask = CTX_data_edit_mask(C); MaskLayer *masklay; TransData *td = NULL; @@ -6172,6 +6191,7 @@ static void createTransMaskingData(bContext *C, TransInfo *t) TransDataMasking *tdm = NULL; int count = 0, countsel = 0; int propmode = t->flag & T_PROP_EDIT; + float asp[2]; t->total = 0; @@ -6206,7 +6226,11 @@ static void createTransMaskingData(bContext *C, TransInfo *t) } /* note: in prop mode we need at least 1 selected */ - if (countsel == 0) return; + if (countsel == 0) { + return; + } + + ED_mask_get_aspect(t->sa, t->ar, &asp[0], &asp[1]); t->total = (propmode) ? count : countsel; td = t->data = MEM_callocN(t->total * sizeof(TransData), "TransObData(Mask Editing)"); @@ -6232,7 +6256,7 @@ static void createTransMaskingData(bContext *C, TransInfo *t) MaskSplinePoint *point = &spline->points[i]; if (propmode || MASKPOINT_ISSEL_ANY(point)) { - MaskPointToTransData(sc, point, td, td2d, tdm, propmode); + MaskPointToTransData(point, td, td2d, tdm, propmode, asp); if (propmode || MASKPOINT_ISSEL_KNOT(point)) { td += 3; @@ -6252,20 +6276,19 @@ static void createTransMaskingData(bContext *C, TransInfo *t) void flushTransMasking(TransInfo *t) { - SpaceClip *sc = t->sa->spacedata.first; TransData2D *td; TransDataMasking *tdm; int a; - float aspx, aspy, invx, invy; + float asp[2], inv[2]; - ED_space_clip_get_aspect(sc, &aspx, &aspy); - invx = 1.0f / aspx; - invy = 1.0f / aspy; + ED_mask_get_aspect(t->sa, t->ar, &asp[0], &asp[1]); + inv[0] = 1.0f / asp[0]; + inv[1] = 1.0f / asp[1]; /* flush to 2d vector from internally used 3d vector */ for (a = 0, td = t->data2d, tdm = t->customData; a < t->total; a++, td++, tdm++) { - td->loc2d[0] = td->loc[0] * invx; - td->loc2d[1] = td->loc[1] * invy; + td->loc2d[0] = td->loc[0] * inv[0]; + td->loc2d[1] = td->loc[1] * inv[1]; if (tdm->is_handle) BKE_mask_point_set_handle(tdm->point, td->loc2d, t->flag & T_ALT_TRANSFORM, tdm->orig_handle, tdm->vec); @@ -6297,11 +6320,23 @@ void createTransData(bContext *C, TransInfo *t) } else if (t->spacetype == SPACE_IMAGE) { t->flag |= T_POINTS | T_2D_EDIT; - createTransUVs(C, t); - if (t->data && (t->flag & T_PROP_EDIT)) { - sort_trans_data(t); // makes selected become first in array - set_prop_dist(t, 1); - sort_trans_data_dist(t); + if (t->options & CTX_MASK) { + /* copied from below */ + createTransMaskingData(C, t); + + if (t->data && (t->flag & T_PROP_EDIT)) { + sort_trans_data(t); // makes selected become first in array + set_prop_dist(t, TRUE); + sort_trans_data_dist(t); + } + } + else { + createTransUVs(C, t); + if (t->data && (t->flag & T_PROP_EDIT)) { + sort_trans_data(t); // makes selected become first in array + set_prop_dist(t, 1); + sort_trans_data_dist(t); + } } } else if (t->spacetype == SPACE_ACTION) { @@ -6342,6 +6377,7 @@ void createTransData(bContext *C, TransInfo *t) if (t->options & CTX_MOVIECLIP) createTransTrackingData(C, t); else if (t->options & CTX_MASK) { + /* copied from above */ createTransMaskingData(C, t); if (t->data && (t->flag & T_PROP_EDIT)) { diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c index dba597d316d..ff18b23dc91 100644 --- a/source/blender/editors/transform/transform_generics.c +++ b/source/blender/editors/transform/transform_generics.c @@ -73,6 +73,7 @@ #include "BKE_context.h" #include "BKE_tessmesh.h" #include "BKE_tracking.h" +#include "BKE_mask.h" #include "ED_anim_api.h" #include "ED_armature.h" @@ -607,6 +608,15 @@ static void recalcData_nla(TransInfo *t) } } +static void recalcData_mask_common(TransInfo *t) +{ + Mask *mask = CTX_data_edit_mask(t->context); + + flushTransMasking(t); + + DAG_id_tag_update(&mask->id, 0); +} + /* helper for recalcData() - for Image Editor transforms */ static void recalcData_image(TransInfo *t) { @@ -619,6 +629,9 @@ static void recalcData_image(TransInfo *t) DAG_id_tag_update(t->obedit->data, 0); } + else if (t->options & CTX_MASK) { + recalcData_mask_common(t); + } } /* helper for recalcData() - for Movie Clip transforms */ @@ -662,12 +675,8 @@ static void recalcData_spaceclip(TransInfo *t) DAG_id_tag_update(&clip->id, 0); } - else if (ED_space_clip_check_show_maskedit(sc)) { - Mask *mask = ED_space_clip_get_mask(sc); - - flushTransMasking(t); - - DAG_id_tag_update(&mask->id, 0); + else if (t->options & CTX_MASK) { + recalcData_mask_common(t); } } @@ -908,6 +917,10 @@ void recalcData(TransInfo *t) else if (t->spacetype == SPACE_CLIP) { recalcData_spaceclip(t); } + + if (t->options & CTX_MASK) { + + } } void drawLine(TransInfo *t, float *center, float *dir, char axis, short options) @@ -1099,6 +1112,16 @@ int initTransInfo(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event) // XXX for now, get View2D from the active region t->view = &ar->v2d; t->around = sima->around; + + if (t->obedit) { + /* UV transform */ + } + else if (sima->mode == SI_MODE_MASK) { + t->options |= CTX_MASK; + } + else { + BLI_assert(0); + } } else if (t->spacetype == SPACE_NODE) { // XXX for now, get View2D from the active region @@ -1280,9 +1303,14 @@ void postTrans(bContext *C, TransInfo *t) } if (t->spacetype == SPACE_IMAGE) { - SpaceImage *sima = t->sa->spacedata.first; - if (sima->flag & SI_LIVE_UNWRAP) - ED_uvedit_live_unwrap_end(t->state == TRANS_CANCEL); + if (t->options & CTX_MASK) { + /* pass */ + } + else { + SpaceImage *sima = t->sa->spacedata.first; + if (sima->flag & SI_LIVE_UNWRAP) + ED_uvedit_live_unwrap_end(t->state == TRANS_CANCEL); + } } else if (t->spacetype == SPACE_VIEW3D) { View3D *v3d = t->sa->spacedata.first; @@ -1417,13 +1445,28 @@ void calculateCenterCursor2D(TransInfo *t) if (t->spacetype == SPACE_IMAGE) { SpaceImage *sima = (SpaceImage *)t->sa->spacedata.first; /* only space supported right now but may change */ - ED_space_image_uv_aspect(sima, &aspx, &aspy); + ED_space_image_get_uv_aspect(sima, &aspx, &aspy); cursor = sima->cursor; } if (cursor) { - t->center[0] = cursor[0] * aspx; - t->center[1] = cursor[1] * aspy; + if (t->options & CTX_MASK) { + float co[2]; + float frame_size[2]; + SpaceImage *sima = (SpaceImage *)t->sa->spacedata.first; + ED_space_image_get_size_fl(sima, frame_size); + + BKE_mask_coord_from_frame(co, cursor, frame_size); + + ED_space_image_get_aspect(sima, &aspx, &aspy); + + t->center[0] = co[0] * aspx; + t->center[1] = co[1] * aspy; + } + else { + t->center[0] = cursor[0] * aspx; + t->center[1] = cursor[1] * aspy; + } } calculateCenter2D(t); diff --git a/source/blender/editors/transform/transform_manipulator.c b/source/blender/editors/transform/transform_manipulator.c index 1507dbfddda..31250e3a50c 100644 --- a/source/blender/editors/transform/transform_manipulator.c +++ b/source/blender/editors/transform/transform_manipulator.c @@ -607,7 +607,7 @@ static void test_manipulator_axis(const bContext *C) ED_view3d_global_to_vector(rv3d, rv3d->twmat[3], vec); - angle = fabs(angle_v3v3(rv3d->twmat[0], vec)); + angle = fabsf(angle_v3v3(rv3d->twmat[0], vec)); if (angle > (float)M_PI / 2.0f) { angle = (float)M_PI - angle; } @@ -616,7 +616,7 @@ static void test_manipulator_axis(const bContext *C) rv3d->twdrawflag &= ~(MAN_TRANS_X | MAN_SCALE_X); } - angle = fabs(angle_v3v3(rv3d->twmat[1], vec)); + angle = fabsf(angle_v3v3(rv3d->twmat[1], vec)); if (angle > (float)M_PI / 2.0f) { angle = (float)M_PI - angle; } @@ -625,7 +625,7 @@ static void test_manipulator_axis(const bContext *C) rv3d->twdrawflag &= ~(MAN_TRANS_Y | MAN_SCALE_Y); } - angle = fabs(angle_v3v3(rv3d->twmat[2], vec)); + angle = fabsf(angle_v3v3(rv3d->twmat[2], vec)); if (angle > (float)M_PI / 2.0f) { angle = (float)M_PI - angle; } diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c index 1286a520bb9..278acb72511 100644 --- a/source/blender/editors/transform/transform_snap.c +++ b/source/blender/editors/transform/transform_snap.c @@ -206,10 +206,10 @@ void drawSnapping(const struct bContext *C, TransInfo *t) myortho2(G.v2d->cur.xmin, G.v2d->cur.xmax, G.v2d->cur.ymin, G.v2d->cur.ymax); glLoadIdentity(); - ED_space_image_aspect(t->sa->spacedata.first, &xuser_aspx, &yuser_asp); + ED_space_image_get_aspect(t->sa->spacedata.first, &xuser_aspx, &yuser_asp); ED_space_image_width(t->sa->spacedata.first, &wi, &hi); - w = (((float)wi) / 256.0f) * G.sima->zoom * xuser_asp; - h = (((float)hi) / 256.0f) * G.sima->zoom * yuser_asp; + w = (((float)wi) / IMG_SIZE_FALLBACK) * G.sima->zoom * xuser_asp; + h = (((float)hi) / IMG_SIZE_FALLBACK) * G.sima->zoom * yuser_asp; cpack(0xFFFFFF); glTranslatef(t->tsnap.snapPoint[0], t->tsnap.snapPoint[1], 0.0f); @@ -246,13 +246,13 @@ void drawSnapping(const struct bContext *C, TransInfo *t) glColor4ubv(col); } - drawnodesnap(&ar->v2d, p->co, size, 0); + ED_node_draw_snap(&ar->v2d, p->co, size, 0); } if (t->tsnap.status & POINT_INIT) { glColor4ubv(activeCol); - drawnodesnap(&ar->v2d, t->tsnap.snapPoint, size, t->tsnap.snapNodeBorder); + ED_node_draw_snap(&ar->v2d, t->tsnap.snapPoint, size, t->tsnap.snapNodeBorder); } glDisable(GL_BLEND); @@ -927,7 +927,7 @@ static void CalcSnapGeometry(TransInfo *t, float *UNUSED(vec)) UI_view2d_region_to_view(&t->ar->v2d, t->mval[0], t->mval[1], co, co + 1); if (ED_uvedit_nearest_uv(t->scene, t->obedit, ima, co, t->tsnap.snapPoint)) { - ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy); + ED_space_image_get_uv_aspect(t->sa->spacedata.first, &aspx, &aspy); t->tsnap.snapPoint[0] *= aspx; t->tsnap.snapPoint[1] *= aspy; @@ -1081,7 +1081,7 @@ static void TargetSnapClosest(TransInfo *t) dist = t->tsnap.distance(t, loc, t->tsnap.snapPoint); - if (closest == NULL || fabs(dist) < fabs(t->tsnap.dist)) { + if (closest == NULL || fabsf(dist) < fabsf(t->tsnap.dist)) { copy_v3_v3(t->tsnap.snapTarget, loc); closest = td; t->tsnap.dist = dist; @@ -1097,7 +1097,7 @@ static void TargetSnapClosest(TransInfo *t) dist = t->tsnap.distance(t, loc, t->tsnap.snapPoint); - if (closest == NULL || fabs(dist) < fabs(t->tsnap.dist)) { + if (closest == NULL || fabsf(dist) < fabsf(t->tsnap.dist)) { copy_v3_v3(t->tsnap.snapTarget, loc); closest = td; t->tsnap.dist = dist; @@ -1120,7 +1120,7 @@ static void TargetSnapClosest(TransInfo *t) dist = t->tsnap.distance(t, loc, t->tsnap.snapPoint); - if (closest == NULL || fabs(dist) < fabs(t->tsnap.dist)) { + if (closest == NULL || fabsf(dist) < fabsf(t->tsnap.dist)) { copy_v3_v3(t->tsnap.snapTarget, loc); closest = td; t->tsnap.dist = dist; @@ -2135,7 +2135,7 @@ static void applyGrid(TransInfo *t, float *val, int max_index, float fac[3], Gea /* evil hack - snapping needs to be adapted for image aspect ratio */ if ((t->spacetype == SPACE_IMAGE) && (t->mode == TFM_TRANSLATION)) { - ED_space_image_uv_aspect(t->sa->spacedata.first, asp, asp + 1); + ED_space_image_get_uv_aspect(t->sa->spacedata.first, asp, asp + 1); } for (i = 0; i <= max_index; i++) { diff --git a/source/blender/editors/util/undo.c b/source/blender/editors/util/undo.c index 0c2bfff3b57..65b92168842 100644 --- a/source/blender/editors/util/undo.c +++ b/source/blender/editors/util/undo.c @@ -141,7 +141,7 @@ static int ed_undo_step(bContext *C, int step, const char *undoname) if (sa && (sa->spacetype == SPACE_IMAGE)) { SpaceImage *sima = (SpaceImage *)sa->spacedata.first; - if ((obact && (obact->mode & OB_MODE_TEXTURE_PAINT)) || (sima->flag & SI_DRAWTOOL)) { + if ((obact && (obact->mode & OB_MODE_TEXTURE_PAINT)) || (sima->mode == SI_MODE_PAINT)) { if (!ED_undo_paint_step(C, UNDO_PAINT_IMAGE, step, undoname) && undoname) if (U.uiflag & USER_GLOBALUNDO) BKE_undo_name(C, undoname); @@ -238,7 +238,7 @@ int ED_undo_valid(const bContext *C, const char *undoname) if (sa && sa->spacetype == SPACE_IMAGE) { SpaceImage *sima = (SpaceImage *)sa->spacedata.first; - if ((obact && (obact->mode & OB_MODE_TEXTURE_PAINT)) || (sima->flag & SI_DRAWTOOL)) { + if ((obact && (obact->mode & OB_MODE_TEXTURE_PAINT)) || (sima->mode == SI_MODE_PAINT)) { return 1; } } diff --git a/source/blender/editors/uvedit/uvedit_buttons.c b/source/blender/editors/uvedit/uvedit_buttons.c index ec645f86848..fa39a52444b 100644 --- a/source/blender/editors/uvedit/uvedit_buttons.c +++ b/source/blender/editors/uvedit/uvedit_buttons.c @@ -125,7 +125,7 @@ static void uvedit_vertex_buttons(const bContext *C, uiBlock *block) float center[2]; int imx, imy, step, digits; - ED_space_image_size(sima, &imx, &imy); + ED_space_image_get_size(sima, &imx, &imy); em = BMEdit_FromObject(obedit); @@ -168,7 +168,7 @@ static void do_uvedit_vertex(bContext *C, void *UNUSED(arg), int event) em = BMEdit_FromObject(obedit); - ED_space_image_size(sima, &imx, &imy); + ED_space_image_get_size(sima, &imx, &imy); uvedit_center(scene, em, ima, center); if (sima->flag & SI_COORDFLOATS) { diff --git a/source/blender/editors/uvedit/uvedit_draw.c b/source/blender/editors/uvedit/uvedit_draw.c index 17c57b1f6e4..1f78bc6bddf 100644 --- a/source/blender/editors/uvedit/uvedit_draw.c +++ b/source/blender/editors/uvedit/uvedit_draw.c @@ -63,13 +63,13 @@ #include "uvedit_intern.h" -static void drawcursor_sima(SpaceImage *sima, ARegion *ar) +void draw_image_cursor(SpaceImage *sima, ARegion *ar) { float zoomx, zoomy, w, h; int width, height; - ED_space_image_size(sima, &width, &height); - ED_space_image_zoom(sima, ar, &zoomx, &zoomy); + ED_space_image_get_size(sima, &width, &height); + ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy); w = zoomx * width / 256.0f; h = zoomy * height / 256.0f; @@ -174,7 +174,7 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTe float aspx, aspy, col[4], (*tf_uv)[2] = NULL, (*tf_uvorig)[2] = NULL; int i, j, nverts; - ED_space_image_uv_aspect(sima, &aspx, &aspy); + ED_space_image_get_uv_aspect(sima, &aspx, &aspy); switch (sima->dt_uvstretch) { case SI_UVDT_STRETCH_AREA: @@ -889,7 +889,7 @@ void draw_uvedit_main(SpaceImage *sima, ARegion *ar, Scene *scene, Object *obedi draw_uvs_texpaint(sima, scene, obact); if (show_uvedit && !(toolsettings->use_uv_sculpt)) - drawcursor_sima(sima, ar); + draw_image_cursor(sima, ar); } } diff --git a/source/blender/editors/uvedit/uvedit_ops.c b/source/blender/editors/uvedit/uvedit_ops.c index 7ef205b69f0..0e129cb4dcb 100644 --- a/source/blender/editors/uvedit/uvedit_ops.c +++ b/source/blender/editors/uvedit/uvedit_ops.c @@ -199,8 +199,8 @@ void ED_uvedit_assign_image(Main *bmain, Scene *scene, Object *obedit, Image *im float prev_aspect[2], fprev_aspect; float aspect[2], faspect; - ED_image_uv_aspect(previma, prev_aspect, prev_aspect + 1); - ED_image_uv_aspect(ima, aspect, aspect + 1); + ED_image_get_uv_aspect(previma, prev_aspect, prev_aspect + 1); + ED_image_get_uv_aspect(ima, aspect, aspect + 1); fprev_aspect = prev_aspect[0]/prev_aspect[1]; faspect = aspect[0]/aspect[1]; @@ -292,11 +292,11 @@ static void uvedit_pixel_to_float(SpaceImage *sima, float *dist, float pixeldist int width, height; if (sima) { - ED_space_image_size(sima, &width, &height); + ED_space_image_get_size(sima, &width, &height); } else { - width = 256; - height = 256; + width = IMG_SIZE_FALLBACK; + height = IMG_SIZE_FALLBACK; } dist[0] = pixeldist / width; @@ -733,7 +733,7 @@ static void find_nearest_uv_face(Scene *scene, Image *ima, BMEditMesh *em, const uv_poly_center(em, efa, cent); - dist = fabs(co[0] - cent[0]) + fabs(co[1] - cent[1]); + dist = fabsf(co[0] - cent[0]) + fabsf(co[1] - cent[1]); if (dist < mindist) { hit->tf = tf; @@ -869,7 +869,7 @@ int ED_uvedit_nearest_uv(Scene *scene, Object *obedit, Image *ima, const float c BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV); - dist = fabs(co[0] - luv->uv[0]) + fabs(co[1] - luv->uv[1]); + dist = fabsf(co[0] - luv->uv[0]) + fabsf(co[1] - luv->uv[1]); if (dist <= mindist) { mindist = dist; @@ -2604,8 +2604,8 @@ static int circle_select_exec(bContext *C, wmOperator *op) /* compute ellipse size and location, not a circle since we deal * with non square image. ellipse is normalized, r = 1.0. */ - ED_space_image_size(sima, &width, &height); - ED_space_image_zoom(sima, ar, &zoomx, &zoomy); + ED_space_image_get_size(sima, &width, &height); + ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy); ellipse[0] = width * zoomx / radius; ellipse[1] = height * zoomy / radius; @@ -2781,7 +2781,7 @@ static void snap_cursor_to_pixels(SpaceImage *sima) { int width = 0, height = 0; - ED_space_image_size(sima, &width, &height); + ED_space_image_get_size(sima, &width, &height); snap_uv_to_pixel(sima->cursor, width, height); } @@ -2936,7 +2936,7 @@ static int snap_uvs_to_pixels(SpaceImage *sima, Scene *scene, Object *obedit) float w, h; short change = 0; - ED_space_image_size(sima, &width, &height); + ED_space_image_get_size(sima, &width, &height); w = (float)width; h = (float)height; @@ -3380,14 +3380,11 @@ static void UV_OT_reveal(wmOperatorType *ot) static int set_2d_cursor_exec(bContext *C, wmOperator *op) { SpaceImage *sima = CTX_wm_space_image(C); - float location[2]; if (!sima) return OPERATOR_CANCELLED; - RNA_float_get_array(op->ptr, "location", location); - sima->cursor[0] = location[0]; - sima->cursor[1] = location[1]; + RNA_float_get_array(op->ptr, "location", sima->cursor); WM_event_add_notifier(C, NC_SPACE | ND_SPACE_IMAGE, NULL); diff --git a/source/blender/editors/uvedit/uvedit_parametrizer.c b/source/blender/editors/uvedit/uvedit_parametrizer.c index a2e276c09e3..c6ded2a91cf 100644 --- a/source/blender/editors/uvedit/uvedit_parametrizer.c +++ b/source/blender/editors/uvedit/uvedit_parametrizer.c @@ -3469,7 +3469,7 @@ static float p_chart_minimum_area_angle(PChart *chart) float rotated, minarea, minangle, area, len; float *angles, miny, maxy, v[2], a[4], mina; - int npoints, right, mini, maxi, i, idx[4], nextidx; + int npoints, right, i_min, i_max, i, idx[4], nextidx; PVert **points, *p1, *p2, *p3, *p4, *p1n; /* compute convex hull */ @@ -3479,7 +3479,7 @@ static float p_chart_minimum_area_angle(PChart *chart) /* find left/top/right/bottom points, and compute angle for each point */ angles = MEM_mallocN(sizeof(float) * npoints, "PMinAreaAngles"); - mini = maxi = 0; + i_min = i_max = 0; miny = 1e10; maxy = -1e10; @@ -3492,19 +3492,19 @@ static float p_chart_minimum_area_angle(PChart *chart) if (points[i]->uv[1] < miny) { miny = points[i]->uv[1]; - mini = i; + i_min = i; } if (points[i]->uv[1] > maxy) { maxy = points[i]->uv[1]; - maxi = i; + i_max = i; } } /* left, top, right, bottom */ idx[0] = 0; - idx[1] = maxi; + idx[1] = i_max; idx[2] = right; - idx[3] = mini; + idx[3] = i_min; v[0] = points[idx[0]]->uv[0]; v[1] = points[idx[0]]->uv[1] + 1.0f; @@ -3530,29 +3530,29 @@ static float p_chart_minimum_area_angle(PChart *chart) while (rotated <= (float)(M_PI / 2.0)) { /* INVESTIGATE: how far to rotate? */ /* rotate with the smallest angle */ - mini = 0; + i_min = 0; mina = 1e10; for (i = 0; i < 4; i++) if (a[i] < mina) { mina = a[i]; - mini = i; + i_min = i; } rotated += mina; - nextidx = (idx[mini] + 1) % npoints; + nextidx = (idx[i_min] + 1) % npoints; - a[mini] = angles[nextidx]; - a[(mini + 1) % 4] = a[(mini + 1) % 4] - mina; - a[(mini + 2) % 4] = a[(mini + 2) % 4] - mina; - a[(mini + 3) % 4] = a[(mini + 3) % 4] - mina; + a[i_min] = angles[nextidx]; + a[(i_min + 1) % 4] = a[(i_min + 1) % 4] - mina; + a[(i_min + 2) % 4] = a[(i_min + 2) % 4] - mina; + a[(i_min + 3) % 4] = a[(i_min + 3) % 4] - mina; /* compute area */ - p1 = points[idx[mini]]; + p1 = points[idx[i_min]]; p1n = points[nextidx]; - p2 = points[idx[(mini + 1) % 4]]; - p3 = points[idx[(mini + 2) % 4]]; - p4 = points[idx[(mini + 3) % 4]]; + p2 = points[idx[(i_min + 1) % 4]]; + p3 = points[idx[(i_min + 2) % 4]]; + p4 = points[idx[(i_min + 3) % 4]]; len = len_v2v2(p1->uv, p1n->uv); @@ -3570,7 +3570,7 @@ static float p_chart_minimum_area_angle(PChart *chart) } } - idx[mini] = nextidx; + idx[i_min] = nextidx; } /* try keeping rotation as small as possible */ diff --git a/source/blender/editors/uvedit/uvedit_smart_stitch.c b/source/blender/editors/uvedit/uvedit_smart_stitch.c index 5c2e57cf27f..4e0e7944e84 100644 --- a/source/blender/editors/uvedit/uvedit_smart_stitch.c +++ b/source/blender/editors/uvedit/uvedit_smart_stitch.c @@ -118,6 +118,8 @@ typedef struct StitchState { char midpoints; /* editmesh, cached for use in modal handler */ BMEditMesh *em; + /* clear seams of stitched edges after stitch */ + char clear_seams; /* element map for getting info about uv connectivity */ UvElementMap *element_map; /* edge container */ @@ -833,6 +835,15 @@ static int stitch_process_data(StitchState *state, Scene *scene, int final) } } + /* clear seams of stitched edges */ + if (final && state->clear_seams) { + for (i = 0; i < state->total_boundary_edges; i++) { + UvEdge *edge = state->edges + i; + if ((state->uvs[edge->uv1]->flag & STITCH_STITCHABLE) && (state->uvs[edge->uv2]->flag & STITCH_STITCHABLE)) + BM_elem_flag_disable(edge->element->l->e, BM_ELEM_SEAM); + } + } + for (i = 0; i < state->selection_size; i++) { UvElement *element = state->selection_stack[i]; if (!island_stitch_data[element->island].use_edge_rotation) { @@ -1004,6 +1015,7 @@ static int stitch_init(bContext *C, wmOperator *op) state->snap_islands = RNA_boolean_get(op->ptr, "snap_islands"); state->static_island = RNA_int_get(op->ptr, "static_island"); state->midpoints = RNA_boolean_get(op->ptr, "midpoint_snap"); + state->clear_seams = RNA_boolean_get(op->ptr, "clear_seams"); /* in uv synch selection, all uv's are visible */ if (ts->uv_flag & UV_SYNC_SELECTION) { state->element_map = EDBM_uv_element_map_create(state->em, 0, 1); @@ -1488,6 +1500,8 @@ void UV_OT_stitch(wmOperatorType *ot) "Island that stays in place when stitching islands", 0, INT_MAX); RNA_def_boolean(ot->srna, "midpoint_snap", 0, "Snap At Midpoint", "UVs are stitched at midpoint instead of at static island"); + RNA_def_boolean(ot->srna, "clear_seams", 1, "Clear Seams", + "Clear seams of stitched edges"); prop = RNA_def_collection_runtime(ot->srna, "selection", &RNA_SelectedUvElement, "Selection", ""); /* Selection should not be editable or viewed in toolbar */ RNA_def_property_flag(prop, PROP_HIDDEN); diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c b/source/blender/editors/uvedit/uvedit_unwrap_ops.c index 1def5caad87..4b6c0ef0e7b 100644 --- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c +++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c @@ -198,7 +198,7 @@ static ParamHandle *construct_param_handle(Scene *scene, BMEditMesh *em, float aspx, aspy; tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); - ED_image_uv_aspect(tf->tpage, &aspx, &aspy); + ED_image_get_uv_aspect(tf->tpage, &aspx, &aspy); if (aspx != aspy) param_aspect_ratio(handle, aspx, aspy); @@ -388,7 +388,7 @@ static ParamHandle *construct_param_handle_subsurfed(Scene *scene, BMEditMesh *e float aspx, aspy; tf = CustomData_bmesh_get(&em->bm->pdata, editFace->head.data, CD_MTEXPOLY); - ED_image_uv_aspect(tf->tpage, &aspx, &aspy); + ED_image_get_uv_aspect(tf->tpage, &aspx, &aspy); if (aspx != aspy) param_aspect_ratio(handle, aspx, aspy); @@ -1017,7 +1017,7 @@ static void correct_uv_aspect(BMEditMesh *em) MTexPoly *tf; tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); - ED_image_uv_aspect(tf->tpage, &aspx, &aspy); + ED_image_get_uv_aspect(tf->tpage, &aspx, &aspy); } if (aspx == aspy) diff --git a/source/blender/gpu/GPU_draw.h b/source/blender/gpu/GPU_draw.h index 59140b2be80..7a71f33d3d0 100644 --- a/source/blender/gpu/GPU_draw.h +++ b/source/blender/gpu/GPU_draw.h @@ -104,6 +104,7 @@ void GPU_render_text(struct MTFace *tface, int mode, * - these will free textures on changes */ void GPU_set_mipmap(int mipmap); +int GPU_get_mipmap(void); void GPU_set_linear_mipmap(int linear); void GPU_paint_set_mipmap(int mipmap); diff --git a/source/blender/gpu/GPU_material.h b/source/blender/gpu/GPU_material.h index 7f5ae0ba2a1..a725ff4385d 100644 --- a/source/blender/gpu/GPU_material.h +++ b/source/blender/gpu/GPU_material.h @@ -173,6 +173,11 @@ typedef enum GPUDynamicType { GPU_DYNAMIC_SAMPLER_2DBUFFER = 12, GPU_DYNAMIC_SAMPLER_2DIMAGE = 13, GPU_DYNAMIC_SAMPLER_2DSHADOW = 14, + GPU_DYNAMIC_LAMP_DISTANCE = 15, + GPU_DYNAMIC_LAMP_ATT1 = 16, + GPU_DYNAMIC_LAMP_ATT2 = 17, + GPU_DYNAMIC_LAMP_SPOTSIZE = 18, + GPU_DYNAMIC_LAMP_SPOTBLEND = 19, } GPUDynamicType; typedef enum GPUDataType { @@ -231,6 +236,8 @@ void GPU_lamp_shadow_buffer_unbind(GPULamp *lamp); void GPU_lamp_update(GPULamp *lamp, int lay, int hide, float obmat[][4]); void GPU_lamp_update_colors(GPULamp *lamp, float r, float g, float b, float energy); +void GPU_lamp_update_distance(GPULamp *lamp, float distance, float att1, float att2); +void GPU_lamp_update_spot(GPULamp *lamp, float spotsize, float spotblend); int GPU_lamp_shadow_layer(GPULamp *lamp); #ifdef __cplusplus diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c index f4e1e0c1147..0ad271e90bd 100644 --- a/source/blender/gpu/intern/gpu_draw.c +++ b/source/blender/gpu/intern/gpu_draw.c @@ -268,7 +268,7 @@ void GPU_set_linear_mipmap(int linear) } } -static int gpu_get_mipmap(void) +int GPU_get_mipmap(void) { return GTS.domipmap && !GTS.texpaint; } @@ -640,7 +640,7 @@ void GPU_create_gl_tex(unsigned int *bind, unsigned int *pix, float * frect, int /* scale if not a power of two. this is not strictly necessary for newer * GPUs (OpenGL version >= 2.0) since they support non-power-of-two-textures * Then don't bother scaling for hardware that supports NPOT textures! */ - if (!GLEW_ARB_texture_non_power_of_two && (!is_pow2_limit(rectw) || !is_pow2_limit(recth))) { + if (!GPU_non_power_of_two_support() && (!is_pow2_limit(rectw) || !is_pow2_limit(recth))) { rectw= smaller_pow2_limit(rectw); recth= smaller_pow2_limit(recth); @@ -662,7 +662,7 @@ void GPU_create_gl_tex(unsigned int *bind, unsigned int *pix, float * frect, int glGenTextures(1, (GLuint *)bind); glBindTexture(GL_TEXTURE_2D, *bind); - if (!(gpu_get_mipmap() && mipmap)) { + if (!(GPU_get_mipmap() && mipmap)) { if (use_high_bit_depth) glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16, rectw, recth, 0, GL_RGBA, GL_FLOAT, frect); else @@ -883,7 +883,7 @@ void GPU_paint_update_image(Image *ima, int x, int y, int w, int h, int mipmap) ibuf = BKE_image_get_ibuf(ima, NULL); - if (ima->repbind || (gpu_get_mipmap() && mipmap) || !ima->bindcode || !ibuf || + if (ima->repbind || (GPU_get_mipmap() && mipmap) || !ima->bindcode || !ibuf || (!is_power_of_2_i(ibuf->x) || !is_power_of_2_i(ibuf->y)) || (w == 0) || (h == 0)) { diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index 0fad5e47445..bd25a042ee4 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -117,6 +117,7 @@ struct GPULamp { float dynimat[4][4]; float spotsi, spotbl, k; + float dyndist, dynatt1, dynatt2; float dist, att1, att2; float shadow_color[3]; @@ -413,13 +414,13 @@ static GPUNodeLink *lamp_get_visibility(GPUMaterial *mat, GPULamp *lamp, GPUNode case LA_FALLOFF_CONSTANT: break; case LA_FALLOFF_INVLINEAR: - GPU_link(mat, "lamp_falloff_invlinear", GPU_uniform(&lamp->dist), *dist, &visifac); + GPU_link(mat, "lamp_falloff_invlinear", GPU_dynamic_uniform(&lamp->dist, GPU_DYNAMIC_LAMP_DISTANCE, lamp->ob), *dist, &visifac); break; case LA_FALLOFF_INVSQUARE: - GPU_link(mat, "lamp_falloff_invsquare", GPU_uniform(&lamp->dist), *dist, &visifac); + GPU_link(mat, "lamp_falloff_invsquare", GPU_dynamic_uniform(&lamp->dist, GPU_DYNAMIC_LAMP_DISTANCE, lamp->ob), *dist, &visifac); break; case LA_FALLOFF_SLIDERS: - GPU_link(mat, "lamp_falloff_sliders", GPU_uniform(&lamp->dist), GPU_uniform(&lamp->att1), GPU_uniform(&lamp->att2), *dist, &visifac); + GPU_link(mat, "lamp_falloff_sliders", GPU_dynamic_uniform(&lamp->dist, GPU_DYNAMIC_LAMP_DISTANCE, lamp->ob), GPU_dynamic_uniform(&lamp->att1, GPU_DYNAMIC_LAMP_ATT1, lamp->ob), GPU_dynamic_uniform(&lamp->att2, GPU_DYNAMIC_LAMP_ATT2, lamp->ob), *dist, &visifac); break; case LA_FALLOFF_CURVE: { @@ -427,13 +428,13 @@ static GPUNodeLink *lamp_get_visibility(GPUMaterial *mat, GPULamp *lamp, GPUNode int size; curvemapping_table_RGBA(lamp->curfalloff, &array, &size); - GPU_link(mat, "lamp_falloff_curve", GPU_uniform(&lamp->dist), GPU_texture(size, array), *dist, &visifac); + GPU_link(mat, "lamp_falloff_curve", GPU_dynamic_uniform(&lamp->dist, GPU_DYNAMIC_LAMP_DISTANCE, lamp->ob), GPU_texture(size, array), *dist, &visifac); } break; } if (lamp->mode & LA_SPHERE) - GPU_link(mat, "lamp_visibility_sphere", GPU_uniform(&lamp->dist), *dist, visifac, &visifac); + GPU_link(mat, "lamp_visibility_sphere", GPU_dynamic_uniform(&lamp->dist, GPU_DYNAMIC_LAMP_DISTANCE, lamp->ob), *dist, visifac, &visifac); if (lamp->type == LA_SPOT) { if (lamp->mode & LA_SQUARE) { @@ -445,7 +446,7 @@ static GPUNodeLink *lamp_get_visibility(GPUMaterial *mat, GPULamp *lamp, GPUNode GPU_link(mat, "lamp_visibility_spot_circle", GPU_dynamic_uniform(lamp->dynvec, GPU_DYNAMIC_LAMP_DYNVEC, lamp->ob), *lv, &inpr); } - GPU_link(mat, "lamp_visibility_spot", GPU_uniform(&lamp->spotsi), GPU_uniform(&lamp->spotbl), inpr, visifac, &visifac); + GPU_link(mat, "lamp_visibility_spot", GPU_dynamic_uniform(&lamp->spotsi, GPU_DYNAMIC_LAMP_SPOTSIZE, lamp->ob), GPU_dynamic_uniform(&lamp->spotbl, GPU_DYNAMIC_LAMP_SPOTSIZE, lamp->ob), inpr, visifac, &visifac); } GPU_link(mat, "lamp_visibility_clamp", visifac, &visifac); @@ -1347,6 +1348,7 @@ static void do_material_tex(GPUShadeInput *shi) void GPU_shadeinput_set(GPUMaterial *mat, Material *ma, GPUShadeInput *shi) { float hard = ma->har; + float one = 1.0f; memset(shi, 0, sizeof(*shi)); @@ -1356,7 +1358,12 @@ void GPU_shadeinput_set(GPUMaterial *mat, Material *ma, GPUShadeInput *shi) GPU_link(mat, "set_rgb", GPU_uniform(&ma->r), &shi->rgb); GPU_link(mat, "set_rgb", GPU_uniform(&ma->specr), &shi->specrgb); GPU_link(mat, "shade_norm", GPU_builtin(GPU_VIEW_NORMAL), &shi->vn); - GPU_link(mat, "set_value", GPU_uniform(&ma->alpha), &shi->alpha); + + if (ma->mode & MA_TRANSP) + GPU_link(mat, "set_value", GPU_uniform(&ma->alpha), &shi->alpha); + else + GPU_link(mat, "set_value", GPU_uniform(&one), &shi->alpha); + GPU_link(mat, "set_value", GPU_uniform(&ma->ref), &shi->refl); GPU_link(mat, "set_value", GPU_uniform(&ma->spec), &shi->spec); GPU_link(mat, "set_value", GPU_uniform(&ma->emit), &shi->emit); @@ -1570,6 +1577,19 @@ void GPU_lamp_update_colors(GPULamp *lamp, float r, float g, float b, float ener lamp->col[2]= b* lamp->energy; } +void GPU_lamp_update_distance(GPULamp *lamp, float distance, float att1, float att2) +{ + lamp->dist = distance; + lamp->att1 = att1; + lamp->att2 = att2; +} + +void GPU_lamp_update_spot(GPULamp *lamp, float spotsize, float spotblend) +{ + lamp->spotsi= cos(M_PI*spotsize/360.0); + lamp->spotbl= (1.0f - lamp->spotsi)*spotblend; +} + static void gpu_lamp_from_blender(Scene *scene, Object *ob, Object *par, Lamp *la, GPULamp *lamp) { float temp, angle, pixsize, wsize; diff --git a/source/blender/ikplugin/intern/iksolver_plugin.c b/source/blender/ikplugin/intern/iksolver_plugin.c index 21d50e4a71d..af15333ece5 100644 --- a/source/blender/ikplugin/intern/iksolver_plugin.c +++ b/source/blender/ikplugin/intern/iksolver_plugin.c @@ -334,9 +334,10 @@ static void execute_posetree(struct Scene *scene, Object *ob, PoseTree *tree) IK_SetStiffness(seg, IK_Z, pchan->stiffness[2]); if (tree->stretch && (pchan->ikstretch > 0.0f)) { - float ikstretch = pchan->ikstretch * pchan->ikstretch; - IK_SetStiffness(seg, IK_TRANS_Y, MIN2(1.0f - ikstretch, 0.99f)); - IK_SetLimit(seg, IK_TRANS_Y, 0.001, 1e10); + const float ikstretch = pchan->ikstretch * pchan->ikstretch; + /* this function does its own clamping */ + IK_SetStiffness(seg, IK_TRANS_Y, 1.0f - ikstretch); + IK_SetLimit(seg, IK_TRANS_Y, IK_STRETCH_STIFF_MIN, IK_STRETCH_STIFF_MAX); } } diff --git a/source/blender/ikplugin/intern/itasc_plugin.cpp b/source/blender/ikplugin/intern/itasc_plugin.cpp index 652b16a7c65..7a53fe247fe 100644 --- a/source/blender/ikplugin/intern/itasc_plugin.cpp +++ b/source/blender/ikplugin/intern/itasc_plugin.cpp @@ -1254,8 +1254,9 @@ static IK_Scene *convert_tree(Scene *blscene, Object *ob, bPoseChannel *pchan) joint = bone->name; joint += ":TY"; ret = arm->addSegment(joint, parent, KDL::Joint::TransY, rot[ikchan->ndof - 1]); - float ikstretch = pchan->ikstretch * pchan->ikstretch; - weight[1] = (1.0 - MIN2(1.0 - ikstretch, 0.99)); + const float ikstretch = pchan->ikstretch * pchan->ikstretch; + /* why invert twice here? */ + weight[1] = (1.0 - minf(1.0 - ikstretch, 1.0f - 0.001f)); weights.push_back(weight[1]); } if (!ret) diff --git a/source/blender/imbuf/intern/divers.c b/source/blender/imbuf/intern/divers.c index 1b68c520336..54903c83835 100644 --- a/source/blender/imbuf/intern/divers.c +++ b/source/blender/imbuf/intern/divers.c @@ -199,7 +199,6 @@ void IMB_buffer_byte_from_float(uchar *rect_to, const float *rect_from, BLI_assert(profile_to != IB_PROFILE_NONE); BLI_assert(profile_from != IB_PROFILE_NONE); - BLI_init_srgb_conversion(); if (dither) di = create_dither_context(width, dither); @@ -335,8 +334,6 @@ void IMB_buffer_float_from_byte(float *rect_to, const uchar *rect_from, BLI_assert(profile_to != IB_PROFILE_NONE); BLI_assert(profile_from != IB_PROFILE_NONE); - BLI_init_srgb_conversion(); - /* RGBA input */ for (y = 0; y < height; y++) { const uchar *from = rect_from + stride_from * y * 4; @@ -755,7 +752,7 @@ void IMB_buffer_float_clamp(float *buf, int width, int height) { int i, total = width * height * 4; for (i = 0; i < total; i++) { - buf[i] = MIN2(1.0, buf[i]); + buf[i] = minf(1.0, buf[i]); } } diff --git a/source/blender/imbuf/intern/filter.c b/source/blender/imbuf/intern/filter.c index a0434691807..7804ee1fdf1 100644 --- a/source/blender/imbuf/intern/filter.c +++ b/source/blender/imbuf/intern/filter.c @@ -211,6 +211,10 @@ void IMB_filterN(ImBuf *out, ImBuf *in) rowlen = in->x; + /* generate 32-bit version for float images if it is not already generated by other space */ + if (in->rect == NULL) + IMB_rect_from_float(in); + for (y = 0; y < in->y; y++) { /* setup rows */ row2 = (char *)(in->rect + y * rowlen); diff --git a/source/blender/makesdna/DNA_ID.h b/source/blender/makesdna/DNA_ID.h index 58964a16aee..476ee4fa369 100644 --- a/source/blender/makesdna/DNA_ID.h +++ b/source/blender/makesdna/DNA_ID.h @@ -86,7 +86,7 @@ typedef struct IDProperty { #define IDP_STRING_SUB_UTF8 0 /* default */ #define IDP_STRING_SUB_BYTE 1 /* arbitrary byte array, _not_ null terminated */ /*->flag*/ -#define IDP_FLAG_GHOST (1<<7) /* this means the propery is set but RNA will return +#define IDP_FLAG_GHOST (1<<7) /* this means the property is set but RNA will return * false when checking 'RNA_property_is_set', * currently this is a runtime flag */ @@ -239,11 +239,11 @@ typedef struct PreviewImage { #define LIB_LOCAL 0 #define LIB_EXTERN 1 #define LIB_INDIRECT 2 -#define LIB_TEST 8 -#define LIB_TESTEXT (LIB_TEST | LIB_EXTERN) -#define LIB_TESTIND (LIB_TEST | LIB_INDIRECT) +#define LIB_NEED_EXPAND 8 +#define LIB_TESTEXT (LIB_NEED_EXPAND | LIB_EXTERN) +#define LIB_TESTIND (LIB_NEED_EXPAND | LIB_INDIRECT) #define LIB_READ 16 -#define LIB_NEEDLINK 32 +#define LIB_NEED_LINK 32 #define LIB_NEW 256 #define LIB_FAKEUSER 512 diff --git a/source/blender/makesdna/DNA_mask_types.h b/source/blender/makesdna/DNA_mask_types.h index 60bc3ee0ffc..e7322263a6b 100644 --- a/source/blender/makesdna/DNA_mask_types.h +++ b/source/blender/makesdna/DNA_mask_types.h @@ -173,7 +173,8 @@ enum { MASK_BLEND_DARKEN = 3, MASK_BLEND_MUL = 4, MASK_BLEND_REPLACE = 5, - MASK_BLEND_DIFFERENCE = 6 + MASK_BLEND_DIFFERENCE = 6, + MASK_BLEND_MERGE = 7 }; /* masklay->blend_flag */ diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index a7f854f603c..731f44d2564 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -211,6 +211,11 @@ typedef struct bNode { /* automatic flag for nodes included in transforms */ #define NODE_TRANSFORM (1<<13) /* node is active texture */ + + /* note: take care with this flag since its possible it gets + * `stuck` inside/outside the active group - which makes buttons + * window texture not update, we try to avoid it by clearing the + * flag when toggling group editing - Campbell */ #define NODE_ACTIVE_TEXTURE (1<<14) /* use a custom color for the node */ #define NODE_CUSTOM_COLOR (1<<15) @@ -370,8 +375,13 @@ enum { }; enum { - CMP_NODEFLAG_MASK_AA = (1 << 0), - CMP_NODEFLAG_MASK_NO_FEATHER = (1 << 1) + CMP_NODEFLAG_MASK_AA = (1 << 0), + CMP_NODEFLAG_MASK_NO_FEATHER = (1 << 1), + CMP_NODEFLAG_MASK_MOTION_BLUR = (1 << 2), + + /* we may want multiple aspect options, exposed as an rna enum */ + CMP_NODEFLAG_MASK_FIXED = (1 << 8), + CMP_NODEFLAG_MASK_FIXED_SCENE = (1 << 9) }; enum { @@ -579,6 +589,10 @@ typedef struct NodeDilateErode { char pad[7]; } NodeDilateErode; +typedef struct NodeMask { + int size_x, size_y; +} NodeMask; + typedef struct NodeTexBase { TexMapping tex_mapping; ColorMapping color_mapping; @@ -748,4 +762,6 @@ typedef struct NodeTrackPosData { #define CMP_NODE_BLUR_ASPECT_Y 1 #define CMP_NODE_BLUR_ASPECT_X 2 +#define CMP_NODE_MASK_MBLUR_SAMPLES_MAX 64 + #endif diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h index 7e1094ef93b..b9603e2cdb1 100644 --- a/source/blender/makesdna/DNA_space_types.h +++ b/source/blender/makesdna/DNA_space_types.h @@ -513,6 +513,15 @@ typedef enum eSpaceSeq_Proxy_RenderSize { SEQ_PROXY_RENDER_SIZE_FULL = 100 } eSpaceSeq_Proxy_RenderSize; +typedef struct MaskSpaceInfo +{ + /* **** mask editing **** */ + struct Mask *mask; + /* draw options */ + char draw_flag; + char draw_type; + char pad3[6]; +} MaskSpaceInfo; /* File Selector ========================================== */ @@ -669,7 +678,7 @@ typedef struct SpaceImage { struct Image *image; struct ImageUser iuser; - struct CurveMapping *cumap; + struct CurveMapping *cumap; struct Scopes scopes; /* histogram waveform and vectorscope */ struct Histogram sample_line_hist; /* sample line histogram */ @@ -681,14 +690,17 @@ typedef struct SpaceImage { float zoom; /* user defined zoom level */ float centx, centy; /* storage for offset while render drawing */ - short curtile; /* the currently active tile of the image when tile is enabled, is kept in sync with the active faces tile */ + char mode; /* view/paint/mask */ + char pin; short pad; + short curtile; /* the currently active tile of the image when tile is enabled, is kept in sync with the active faces tile */ short lock; - short pin; char dt_uv; /* UV draw type */ char sticky; /* sticky selection type */ char dt_uvstretch; char around; + + MaskSpaceInfo mask_info; } SpaceImage; @@ -706,6 +718,13 @@ typedef enum eSpaceImage_UVDT_Stretch { SI_UVDT_STRETCH_AREA = 1, } eSpaceImage_UVDT_Stretch; +/* SpaceImage->mode */ +typedef enum eSpaceImage_Mode { + SI_MODE_VIEW = 0, + SI_MODE_PAINT = 1, + SI_MODE_MASK = 2 /* note: mesh edit mode overrides mask */ +} eSpaceImage_Mode; + /* SpaceImage->sticky * Note DISABLE should be 0, however would also need to re-arrange icon order, * also, sticky loc is the default mode so this means we don't need to 'do_versons' */ @@ -717,15 +736,15 @@ typedef enum eSpaceImage_Sticky { /* SpaceImage->flag */ typedef enum eSpaceImage_Flag { - SI_BE_SQUARE = (1 << 0), - SI_EDITTILE = (1 << 1), +/* SI_BE_SQUARE = (1 << 0), */ /* deprecated */ + SI_EDITTILE = (1 << 1), /* XXX - not used but should be? */ SI_CLIP_UV = (1 << 2), - SI_DRAWTOOL = (1 << 3), +/* SI_DRAWTOOL = (1 << 3), */ /* deprecated */ SI_NO_DRAWFACES = (1 << 4), SI_DRAWSHADOW = (1 << 5), -/* SI_SELACTFACE = (1 << 6), */ /* deprecated */ - SI_DEPRECATED2 = (1 << 7), - SI_DEPRECATED3 = (1 << 8), /* stick UV selection to mesh vertex (UVs wont always be touching) */ +/* SI_SELACTFACE = (1 << 6), */ /* deprecated */ +/* SI_DEPRECATED2 = (1 << 7), */ /* deprecated */ +/* SI_DEPRECATED3 = (1 << 8), */ /* deprecated */ SI_COORDFLOATS = (1 << 9), SI_PIXELSNAP = (1 << 10), SI_LIVE_UNWRAP = (1 << 11), @@ -737,8 +756,8 @@ typedef enum eSpaceImage_Flag { SI_PREVSPACE = (1 << 15), SI_FULLWINDOW = (1 << 16), - SI_DEPRECATED4 = (1 << 17), - SI_DEPRECATED5 = (1 << 18), +/* SI_DEPRECATED4 = (1 << 17), */ /* deprecated */ +/* SI_DEPRECATED5 = (1 << 18), */ /* deprecated */ /* this means that the image is drawn until it reaches the view edge, * in the image view, its unrelated to the 'tile' mode for texface @@ -746,7 +765,7 @@ typedef enum eSpaceImage_Flag { SI_DRAW_TILE = (1 << 19), SI_SMOOTH_UV = (1 << 20), SI_DRAW_STRETCH = (1 << 21), -/* SI_DISPGP = (1 << 22), */ /* DEPRECATED */ +/* SI_DISPGP = (1 << 22), */ /* deprecated */ SI_DRAW_OTHER = (1 << 23), SI_COLOR_CORRECTION = (1 << 24), @@ -884,6 +903,7 @@ typedef enum eSpaceNode_Flag { SNODE_SHOW_B = (1 << 9), SNODE_AUTO_RENDER = (1 << 5), SNODE_SHOW_HIGHLIGHT = (1 << 6), + SNODE_USE_HIDDEN_PREVIEW = (1 << 10), } eSpaceNode_Flag; /* snode->texfrom */ @@ -1012,12 +1032,7 @@ typedef struct SpaceClip { int around, pad4; /* pivot point for transforms */ - /* **** mask editing **** */ - struct Mask *mask; - /* draw options */ - char mask_draw_flag; - char mask_draw_type; - char pad3[6]; + MaskSpaceInfo mask_info; } SpaceClip; /* SpaceClip->flag */ @@ -1101,4 +1116,6 @@ typedef enum eSpace_Type { SPACEICONMAX = SPACE_CLIP } eSpace_Type; +#define IMG_SIZE_FALLBACK 256 + #endif diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h index fc0ce20e0c9..af24cfbad70 100644 --- a/source/blender/makesdna/DNA_userdef_types.h +++ b/source/blender/makesdna/DNA_userdef_types.h @@ -215,7 +215,7 @@ typedef struct ThemeSpace { char extra_edge_len[4], extra_face_angle[4], extra_face_area[4], pad3[4]; char normal[4]; char vertex_normal[4]; - char bone_solid[4], bone_pose[4]; + char bone_solid[4], bone_pose[4], bone_pose_active[4]; char strip[4], strip_select[4]; char cframe[4]; char freestyle_edge_mark[4], freestyle_face_mark[4]; @@ -265,8 +265,6 @@ typedef struct ThemeSpace { char skin_root[4]; /* Skin modifier root color */ - int pad4; - /* NLA */ char anim_active[4]; /* Active Action + Summary Channel */ char anim_non_active[4]; /* Active Action = NULL */ diff --git a/source/blender/makesdna/intern/makesdna.c b/source/blender/makesdna/intern/makesdna.c index ab320322f83..bd1266bba81 100644 --- a/source/blender/makesdna/intern/makesdna.c +++ b/source/blender/makesdna/intern/makesdna.c @@ -293,7 +293,7 @@ static int add_name(const char *str) if (str[0] == '(' && str[1] == '*') { /* we handle function pointer and special array cases here, e.g. * void (*function)(...) and float (*array)[..]. the array case - * name is still converted to (array*)() though because it is that + * name is still converted to (array *)() though because it is that * way in old dna too, and works correct with elementsize() */ int isfuncptr = (strchr(str + 1, '(')) != NULL; diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 8e9c0dbc4c4..5b5367654eb 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -2590,7 +2590,7 @@ void RNA_property_pointer_set(PointerRNA *ptr, PropertyRNA *prop, PointerRNA ptr PointerRNA RNA_property_pointer_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop)) { - /*PointerPropertyRNA *pprop = (PointerPropertyRNA*)prop; */ + /*PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop; */ /* BLI_assert(RNA_property_type(prop) == PROP_POINTER); */ @@ -2729,7 +2729,7 @@ int RNA_property_collection_length(PointerRNA *ptr, PropertyRNA *prop) void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *r_ptr) { IDProperty *idprop; -/* CollectionPropertyRNA *cprop = (CollectionPropertyRNA*)prop; */ +/* CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop; */ BLI_assert(RNA_property_type(prop) == PROP_COLLECTION); @@ -2788,7 +2788,7 @@ void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA int RNA_property_collection_remove(PointerRNA *ptr, PropertyRNA *prop, int key) { IDProperty *idprop; -/* CollectionPropertyRNA *cprop = (CollectionPropertyRNA*)prop; */ +/* CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop; */ BLI_assert(RNA_property_type(prop) == PROP_COLLECTION); @@ -3035,11 +3035,11 @@ int RNA_property_collection_raw_array(PointerRNA *ptr, PropertyRNA *prop, Proper #define RAW_GET(dtype, var, raw, a) \ { \ switch (raw.type) { \ - case PROP_RAW_CHAR: var = (dtype)((char*)raw.array)[a]; break; \ - case PROP_RAW_SHORT: var = (dtype)((short*)raw.array)[a]; break; \ - case PROP_RAW_INT: var = (dtype)((int*)raw.array)[a]; break; \ - case PROP_RAW_FLOAT: var = (dtype)((float*)raw.array)[a]; break; \ - case PROP_RAW_DOUBLE: var = (dtype)((double*)raw.array)[a]; break; \ + case PROP_RAW_CHAR: var = (dtype)((char *)raw.array)[a]; break; \ + case PROP_RAW_SHORT: var = (dtype)((short *)raw.array)[a]; break; \ + case PROP_RAW_INT: var = (dtype)((int *)raw.array)[a]; break; \ + case PROP_RAW_FLOAT: var = (dtype)((float *)raw.array)[a]; break; \ + case PROP_RAW_DOUBLE: var = (dtype)((double *)raw.array)[a]; break; \ default: var = (dtype)0; \ } \ } (void)0 @@ -3047,11 +3047,11 @@ int RNA_property_collection_raw_array(PointerRNA *ptr, PropertyRNA *prop, Proper #define RAW_SET(dtype, raw, a, var) \ { \ switch (raw.type) { \ - case PROP_RAW_CHAR: ((char*)raw.array)[a] = (char)var; break; \ - case PROP_RAW_SHORT: ((short*)raw.array)[a] = (short)var; break; \ - case PROP_RAW_INT: ((int*)raw.array)[a] = (int)var; break; \ - case PROP_RAW_FLOAT: ((float*)raw.array)[a] = (float)var; break; \ - case PROP_RAW_DOUBLE: ((double*)raw.array)[a] = (double)var; break; \ + case PROP_RAW_CHAR: ((char *)raw.array)[a] = (char)var; break; \ + case PROP_RAW_SHORT: ((short *)raw.array)[a] = (short)var; break; \ + case PROP_RAW_INT: ((int *)raw.array)[a] = (int)var; break; \ + case PROP_RAW_FLOAT: ((float *)raw.array)[a] = (float)var; break; \ + case PROP_RAW_DOUBLE: ((double *)raw.array)[a] = (double)var; break; \ default: break; \ } \ } (void)0 diff --git a/source/blender/makesrna/intern/rna_cloth.c b/source/blender/makesrna/intern/rna_cloth.c index 3b4f87d8b95..5f1ce4f2773 100644 --- a/source/blender/makesrna/intern/rna_cloth.c +++ b/source/blender/makesrna/intern/rna_cloth.c @@ -58,7 +58,7 @@ static void rna_cloth_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerR static void rna_cloth_pinning_changed(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr) { Object *ob = (Object *)ptr->id.data; -/* ClothSimSettings *settings = (ClothSimSettings*)ptr->data; */ +/* ClothSimSettings *settings = (ClothSimSettings *)ptr->data; */ ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth); cloth_free_modifier(clmd); diff --git a/source/blender/makesrna/intern/rna_curve.c b/source/blender/makesrna/intern/rna_curve.c index c333c56a6b8..b2a2bab0f4b 100644 --- a/source/blender/makesrna/intern/rna_curve.c +++ b/source/blender/makesrna/intern/rna_curve.c @@ -155,56 +155,38 @@ static StructRNA *rna_Curve_refine(PointerRNA *ptr) static void rna_BezTriple_handle1_get(PointerRNA *ptr, float *values) { - BezTriple *bt = (BezTriple *)ptr->data; - - values[0] = bt->vec[0][0]; - values[1] = bt->vec[0][1]; - values[2] = bt->vec[0][2]; + BezTriple *bezt = (BezTriple *)ptr->data; + copy_v3_v3(values, bezt->vec[0]); } static void rna_BezTriple_handle1_set(PointerRNA *ptr, const float *values) { - BezTriple *bt = (BezTriple *)ptr->data; - - bt->vec[0][0] = values[0]; - bt->vec[0][1] = values[1]; - bt->vec[0][2] = values[2]; + BezTriple *bezt = (BezTriple *)ptr->data; + copy_v3_v3(bezt->vec[0], values); } static void rna_BezTriple_handle2_get(PointerRNA *ptr, float *values) { - BezTriple *bt = (BezTriple *)ptr->data; - - values[0] = bt->vec[2][0]; - values[1] = bt->vec[2][1]; - values[2] = bt->vec[2][2]; + BezTriple *bezt = (BezTriple *)ptr->data; + copy_v3_v3(values, bezt->vec[2]); } static void rna_BezTriple_handle2_set(PointerRNA *ptr, const float *values) { - BezTriple *bt = (BezTriple *)ptr->data; - - bt->vec[2][0] = values[0]; - bt->vec[2][1] = values[1]; - bt->vec[2][2] = values[2]; + BezTriple *bezt = (BezTriple *)ptr->data; + copy_v3_v3(bezt->vec[2], values); } static void rna_BezTriple_ctrlpoint_get(PointerRNA *ptr, float *values) { - BezTriple *bt = (BezTriple *)ptr->data; - - values[0] = bt->vec[1][0]; - values[1] = bt->vec[1][1]; - values[2] = bt->vec[1][2]; + BezTriple *bezt = (BezTriple *)ptr->data; + copy_v3_v3(values, bezt->vec[1]); } static void rna_BezTriple_ctrlpoint_set(PointerRNA *ptr, const float *values) { - BezTriple *bt = (BezTriple *)ptr->data; - - bt->vec[1][0] = values[0]; - bt->vec[1][1] = values[1]; - bt->vec[1][2] = values[2]; + BezTriple *bezt = (BezTriple *)ptr->data; + copy_v3_v3(bezt->vec[1], values); } static void rna_Curve_texspace_set(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr) diff --git a/source/blender/makesrna/intern/rna_dynamicpaint.c b/source/blender/makesrna/intern/rna_dynamicpaint.c index 6739e5b71fa..4f9f2009a14 100644 --- a/source/blender/makesrna/intern/rna_dynamicpaint.c +++ b/source/blender/makesrna/intern/rna_dynamicpaint.c @@ -170,7 +170,7 @@ static PointerRNA rna_PaintSurface_active_get(PointerRNA *ptr) static void rna_DynamicPaint_surfaces_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) { DynamicPaintCanvasSettings *canvas = (DynamicPaintCanvasSettings *)ptr->data; - /*rna_iterator_array_begin(iter, (void*)canvas->surfaces, sizeof(PaintSurface), canvas->totsur, 0, 0); */ + /*rna_iterator_array_begin(iter, (void *)canvas->surfaces, sizeof(PaintSurface), canvas->totsur, 0, 0); */ rna_iterator_listbase_begin(iter, &canvas->surfaces, NULL); } diff --git a/source/blender/makesrna/intern/rna_main.c b/source/blender/makesrna/intern/rna_main.c index 69813172de7..17261c2c909 100644 --- a/source/blender/makesrna/intern/rna_main.c +++ b/source/blender/makesrna/intern/rna_main.c @@ -255,7 +255,7 @@ static void rna_Main_movieclips_begin(CollectionPropertyIterator *iter, PointerR static void rna_Main_masks_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) { - Main *bmain = (Main*)ptr->data; + Main *bmain = (Main *)ptr->data; rna_iterator_listbase_begin(iter, &bmain->mask, NULL); } diff --git a/source/blender/makesrna/intern/rna_mask.c b/source/blender/makesrna/intern/rna_mask.c index 2987057aeb6..9ee2bb99b4e 100644 --- a/source/blender/makesrna/intern/rna_mask.c +++ b/source/blender/makesrna/intern/rna_mask.c @@ -108,21 +108,21 @@ static void rna_Mask_update_parent(Main *bmain, Scene *scene, PointerRNA *ptr) /* note: this function exists only to avoid id refcounting */ static void rna_MaskParent_id_set(PointerRNA *ptr, PointerRNA value) { - MaskParent *mpar = (MaskParent*) ptr->data; + MaskParent *mpar = (MaskParent *) ptr->data; mpar->id = value.data; } static StructRNA *rna_MaskParent_id_typef(PointerRNA *ptr) { - MaskParent *mpar = (MaskParent*) ptr->data; + MaskParent *mpar = (MaskParent *) ptr->data; return ID_code_to_RNA_type(mpar->id_type); } static void rna_MaskParent_id_type_set(PointerRNA *ptr, int value) { - MaskParent *mpar = (MaskParent*) ptr->data; + MaskParent *mpar = (MaskParent *) ptr->data; /* change ID-type to the new type */ mpar->id_type = value; @@ -248,67 +248,49 @@ static void rna_MaskLayer_active_spline_point_set(PointerRNA *ptr, PointerRNA va static void rna_MaskSplinePoint_handle1_get(PointerRNA *ptr, float *values) { - MaskSplinePoint *point = (MaskSplinePoint*) ptr->data; + MaskSplinePoint *point = (MaskSplinePoint *) ptr->data; BezTriple *bezt = &point->bezt; - - values[0] = bezt->vec[0][0]; - values[1] = bezt->vec[0][1]; - values[2] = bezt->vec[0][2]; + copy_v2_v2(values, bezt->vec[0]); } static void rna_MaskSplinePoint_handle1_set(PointerRNA *ptr, const float *values) { - MaskSplinePoint *point = (MaskSplinePoint*) ptr->data; + MaskSplinePoint *point = (MaskSplinePoint *) ptr->data; BezTriple *bezt = &point->bezt; - - bezt->vec[0][0] = values[0]; - bezt->vec[0][1] = values[1]; - bezt->vec[0][2] = values[2]; + copy_v2_v2(bezt->vec[0], values); } static void rna_MaskSplinePoint_handle2_get(PointerRNA *ptr, float *values) { - MaskSplinePoint *point = (MaskSplinePoint*) ptr->data; + MaskSplinePoint *point = (MaskSplinePoint *) ptr->data; BezTriple *bezt = &point->bezt; - - values[0] = bezt->vec[2][0]; - values[1] = bezt->vec[2][1]; - values[2] = bezt->vec[2][2]; + copy_v2_v2(values, bezt->vec[2]); } static void rna_MaskSplinePoint_handle2_set(PointerRNA *ptr, const float *values) { - MaskSplinePoint *point = (MaskSplinePoint*) ptr->data; + MaskSplinePoint *point = (MaskSplinePoint *) ptr->data; BezTriple *bezt = &point->bezt; - - bezt->vec[2][0] = values[0]; - bezt->vec[2][1] = values[1]; - bezt->vec[2][2] = values[2]; + copy_v2_v2(bezt->vec[2], values); } static void rna_MaskSplinePoint_ctrlpoint_get(PointerRNA *ptr, float *values) { - MaskSplinePoint *point = (MaskSplinePoint*) ptr->data; + MaskSplinePoint *point = (MaskSplinePoint *) ptr->data; BezTriple *bezt = &point->bezt; - - values[0] = bezt->vec[1][0]; - values[1] = bezt->vec[1][1]; - values[2] = bezt->vec[1][2]; + copy_v2_v2(values, bezt->vec[1]); } static void rna_MaskSplinePoint_ctrlpoint_set(PointerRNA *ptr, const float *values) { - MaskSplinePoint *point = (MaskSplinePoint*) ptr->data; + MaskSplinePoint *point = (MaskSplinePoint *) ptr->data; BezTriple *bezt = &point->bezt; - - bezt->vec[1][0] = values[0]; - bezt->vec[1][1] = values[1]; - bezt->vec[1][2] = values[2]; + copy_v2_v2(bezt->vec[1], values); } static int rna_MaskSplinePoint_handle_type_get(PointerRNA *ptr) { - MaskSplinePoint *point = (MaskSplinePoint*) ptr->data; + MaskSplinePoint *point = (MaskSplinePoint *) ptr->data; BezTriple *bezt = &point->bezt; return bezt->h1; @@ -316,7 +298,7 @@ static int rna_MaskSplinePoint_handle_type_get(PointerRNA *ptr) static void rna_MaskSplinePoint_handle_type_set(PointerRNA *ptr, int value) { - MaskSplinePoint *point = (MaskSplinePoint*) ptr->data; + MaskSplinePoint *point = (MaskSplinePoint *) ptr->data; BezTriple *bezt = &point->bezt; bezt->h1 = bezt->h2 = value; @@ -324,7 +306,7 @@ static void rna_MaskSplinePoint_handle_type_set(PointerRNA *ptr, int value) /* ** API ** */ -static MaskLayer *rna_Mask_layer_new(Mask *mask, const char *name) +static MaskLayer *rna_Mask_layers_new(Mask *mask, const char *name) { MaskLayer *masklay = BKE_mask_layer_new(mask, name); @@ -333,16 +315,28 @@ static MaskLayer *rna_Mask_layer_new(Mask *mask, const char *name) return masklay; } -void rna_Mask_layer_remove(Mask *mask, MaskLayer *masklay) +void rna_Mask_layers_remove(Mask *mask, ReportList *reports, MaskLayer *masklay) { + if (BLI_findindex(&mask->masklayers, masklay) == -1) { + BKE_reportf(reports, RPT_ERROR, "MaskLayer '%s' not found in mask '%s'", masklay->name, mask->id.name + 2); + return; + } + BKE_mask_layer_remove(mask, masklay); WM_main_add_notifier(NC_MASK | NA_EDITED, mask); } +static void rna_Mask_layers_clear(Mask *mask) +{ + BKE_mask_layer_free_list(&mask->masklayers); + + WM_main_add_notifier(NC_MASK | NA_EDITED, mask); +} + static void rna_MaskLayer_spline_add(ID *id, MaskLayer *masklay, int number) { - Mask *mask = (Mask*) id; + Mask *mask = (Mask *) id; int i; for (i = 0; i < number; i++) @@ -467,19 +461,19 @@ static void rna_def_maskSplinePoint(BlenderRNA *brna) /* Vector values */ prop = RNA_def_property(srna, "handle_left", PROP_FLOAT, PROP_TRANSLATION); - RNA_def_property_array(prop, 3); + RNA_def_property_array(prop, 2); RNA_def_property_float_funcs(prop, "rna_MaskSplinePoint_handle1_get", "rna_MaskSplinePoint_handle1_set", NULL); RNA_def_property_ui_text(prop, "Handle 1", "Coordinates of the first handle"); RNA_def_property_update(prop, 0, "rna_Mask_update_data"); prop = RNA_def_property(srna, "co", PROP_FLOAT, PROP_TRANSLATION); - RNA_def_property_array(prop, 3); + RNA_def_property_array(prop, 2); RNA_def_property_float_funcs(prop, "rna_MaskSplinePoint_ctrlpoint_get", "rna_MaskSplinePoint_ctrlpoint_set", NULL); RNA_def_property_ui_text(prop, "Control Point", "Coordinates of the control point"); RNA_def_property_update(prop, 0, "rna_Mask_update_data"); prop = RNA_def_property(srna, "handle_right", PROP_FLOAT, PROP_TRANSLATION); - RNA_def_property_array(prop, 3); + RNA_def_property_array(prop, 2); RNA_def_property_float_funcs(prop, "rna_MaskSplinePoint_handle2_get", "rna_MaskSplinePoint_handle2_set", NULL); RNA_def_property_ui_text(prop, "Handle 2", "Coordinates of the second handle"); RNA_def_property_update(prop, 0, "rna_Mask_update_data"); @@ -579,6 +573,7 @@ static void rna_def_maskSpline(BlenderRNA *brna) static void rna_def_mask_layer(BlenderRNA *brna) { static EnumPropertyItem masklay_blend_mode_items[] = { + {MASK_BLEND_MERGE, "MERGE", 0, "Merge", ""}, {MASK_BLEND_ADD, "ADD", 0, "Add", ""}, {MASK_BLEND_SUBTRACT, "SUBTRACT", 0, "Subtract", ""}, {MASK_BLEND_LIGHTEN, "LIGHTEN", 0, "Lighten", ""}, @@ -680,16 +675,21 @@ static void rna_def_masklayers(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_struct_sdna(srna, "Mask"); RNA_def_struct_ui_text(srna, "Mask Layers", "Collection of layers used by mask"); - func = RNA_def_function(srna, "new", "rna_Mask_layer_new"); + func = RNA_def_function(srna, "new", "rna_Mask_layers_new"); RNA_def_function_ui_description(func, "Add layer to this mask"); RNA_def_string(func, "name", "", 0, "Name", "Name of new layer"); parm = RNA_def_pointer(func, "layer", "MaskLayer", "", "New mask layer"); RNA_def_function_return(func, parm); - func = RNA_def_function(srna, "remove", "rna_Mask_layer_remove"); + func = RNA_def_function(srna, "remove", "rna_Mask_layers_remove"); + RNA_def_function_flag(func, FUNC_USE_REPORTS); RNA_def_function_ui_description(func, "Remove layer from this mask"); RNA_def_pointer(func, "layer", "MaskLayer", "", "Shape to be removed"); + /* clear all layers */ + func = RNA_def_function(srna, "clear", "rna_Mask_layers_clear"); + RNA_def_function_ui_description(func, "Remove all mask layers"); + /* active layer */ prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE); RNA_def_property_struct_type(prop, "MaskLayer"); @@ -731,7 +731,7 @@ static void rna_def_mask(BlenderRNA *brna) RNA_def_property_int_funcs(prop, NULL, "rna_Mask_start_frame_set", NULL); RNA_def_property_range(prop, MINFRAME, MAXFRAME); RNA_def_property_ui_text(prop, "Start Frame", "First frame of the mask (used for sequencer)"); - RNA_def_property_update(prop, NC_SCENE | ND_FRAME_RANGE, NULL); + RNA_def_property_update(prop, NC_MASK | ND_DRAW, NULL); prop = RNA_def_property(srna, "frame_end", PROP_INT, PROP_TIME); RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); @@ -739,7 +739,7 @@ static void rna_def_mask(BlenderRNA *brna) RNA_def_property_int_funcs(prop, NULL, "rna_Mask_end_frame_set", NULL); RNA_def_property_range(prop, MINFRAME, MAXFRAME); RNA_def_property_ui_text(prop, "End Frame", "Final frame of the mask (used for sequencer)"); - RNA_def_property_update(prop, NC_SCENE | ND_FRAME_RANGE, NULL); + RNA_def_property_update(prop, NC_MASK | ND_DRAW, NULL); /* pointers */ rna_def_animdata_common(srna); diff --git a/source/blender/makesrna/intern/rna_nla.c b/source/blender/makesrna/intern/rna_nla.c index b47f957ac76..16753961852 100644 --- a/source/blender/makesrna/intern/rna_nla.c +++ b/source/blender/makesrna/intern/rna_nla.c @@ -362,7 +362,7 @@ static void rna_NlaStrip_remove(NlaTrack *track, bContext *C, ReportList *report */ void rna_NlaTrack_solo_set(PointerRNA *ptr, int value) { - NlaTrack *data = (NlaTrack*)ptr->data; + NlaTrack *data = (NlaTrack *)ptr->data; AnimData *adt = BKE_animdata_from_id(ptr->id.data); NlaTrack *nt; diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index 055c8dcbebb..472b0693ae5 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -24,7 +24,6 @@ * \ingroup RNA */ - #include #include @@ -225,7 +224,8 @@ static StructRNA *rna_Node_refine(struct PointerRNA *ptr) return &RNA_NodeWhileLoop; case NODE_FRAME: return &RNA_NodeFrame; - + case NODE_REROUTE: + return &RNA_NodeReroute; default: return &RNA_Node; } @@ -1054,11 +1054,11 @@ static void init(void) #include "rna_nodetree_types.h" - reg_node(NODE_GROUP, Category_GroupNode, "GROUP", "NodeGroup", "Node", "Group", ""); - reg_node(NODE_FORLOOP, Category_LoopNode, "FORLOOP", "NodeForLoop", "Node", "ForLoop", ""); - reg_node(NODE_WHILELOOP, Category_LoopNode, "WHILELOOP", "NodeWhileLoop", "Node", "WhileLoop", ""); - reg_node(NODE_FRAME, Category_LayoutNode, "FRAME", "NodeFrame", "Node", "Frame", ""); - reg_node(NODE_REROUTE, Category_LayoutNode, "REROUTE", "NodeReroute", "Node", "Reroute", ""); + reg_node(NODE_GROUP, Category_GroupNode, "GROUP", "NodeGroup", "SpecialNode", "Group", ""); + reg_node(NODE_FORLOOP, Category_LoopNode, "FORLOOP", "NodeForLoop", "SpecialNode", "ForLoop", ""); + reg_node(NODE_WHILELOOP, Category_LoopNode, "WHILELOOP", "NodeWhileLoop", "SpecialNode", "WhileLoop", ""); + reg_node(NODE_FRAME, Category_LayoutNode, "FRAME", "NodeFrame", "SpecialNode", "Frame", ""); + reg_node(NODE_REROUTE, Category_LayoutNode, "REROUTE", "NodeReroute", "SpecialNode", "Reroute", ""); } static StructRNA *def_node(BlenderRNA *brna, int node_id) @@ -3137,6 +3137,13 @@ static void def_cmp_mask(StructRNA *srna) { PropertyRNA *prop; + static EnumPropertyItem aspect_type_items[] = { + {0, "SCENE", 0, "Scene Size", ""}, + {CMP_NODEFLAG_MASK_FIXED, "FIXED", 0, "Fixed", "Use pixel size for the buffer"}, + {CMP_NODEFLAG_MASK_FIXED_SCENE, "FIXED_SCENE", 0, "Fixed/Scene", "Pixel size scaled by scene percentage"}, + {0, NULL, 0, NULL, NULL} + }; + prop = RNA_def_property(srna, "mask", PROP_POINTER, PROP_NONE); RNA_def_property_pointer_sdna(prop, NULL, "id"); RNA_def_property_struct_type(prop, "Mask"); @@ -3152,6 +3159,43 @@ static void def_cmp_mask(StructRNA *srna) RNA_def_property_boolean_negative_sdna(prop, NULL, "custom1", CMP_NODEFLAG_MASK_NO_FEATHER); RNA_def_property_ui_text(prop, "Feather", "Use feather information from the mask"); RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); + + prop = RNA_def_property(srna, "use_motion_blur", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "custom1", CMP_NODEFLAG_MASK_MOTION_BLUR); + RNA_def_property_ui_text(prop, "Motion Blur", "Use feather information from the mask"); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); + + prop = RNA_def_property(srna, "motion_blur_samples", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "custom2"); + RNA_def_property_range(prop, 1, CMP_NODE_MASK_MBLUR_SAMPLES_MAX); + RNA_def_property_ui_text(prop, "Samples", "Number of motion blur samples"); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); + + prop = RNA_def_property(srna, "motion_blur_shutter", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "custom3"); + RNA_def_property_range(prop, 0.0, 1.0f); + RNA_def_property_ui_text(prop, "Shutter", "Exposure for motion blur as a factor of FPS"); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); + + + prop = RNA_def_property(srna, "size_source", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_bitflag_sdna(prop, NULL, "custom1"); + RNA_def_property_enum_items(prop, aspect_type_items); + RNA_def_property_ui_text(prop, "Size Source", "Where to get the mask size from for aspect/size information"); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); + + + RNA_def_struct_sdna_from(srna, "NodeMask", "storage"); + + prop = RNA_def_property(srna, "size_x", PROP_INT, PROP_NONE); + RNA_def_property_range(prop, 1.0f, 10000.0f); + RNA_def_property_ui_text(prop, "X", ""); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); + + prop = RNA_def_property(srna, "size_y", PROP_INT, PROP_NONE); + RNA_def_property_range(prop, 1.0f, 10000.0f); + RNA_def_property_ui_text(prop, "Y", ""); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); } static void dev_cmd_transform(StructRNA *srna) @@ -3662,6 +3706,13 @@ static void def_cmp_trackpos(StructRNA *srna) { PropertyRNA *prop; + static EnumPropertyItem position_items[] = { + {0, "ABSOLUTE", 0, "Absolute", "Output absolute position of a marker"}, + {1, "RELATIVE_START", 0, "Relative Start", "Output position of a marker relative to first marker of a track"}, + {2, "RELATIVE_FRAME", 0, "Relative Frame", "Output position of a marker relative to marker at given frame number"}, + {0, NULL, 0, NULL, NULL} + }; + prop = RNA_def_property(srna, "clip", PROP_POINTER, PROP_NONE); RNA_def_property_pointer_sdna(prop, NULL, "id"); RNA_def_property_struct_type(prop, "MovieClip"); @@ -3669,9 +3720,15 @@ static void def_cmp_trackpos(StructRNA *srna) RNA_def_property_ui_text(prop, "Movie Clip", ""); RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); - prop = RNA_def_property(srna, "use_relative", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "custom1", 1); - RNA_def_property_ui_text(prop, "Relative", "Return relative position to first track's marker"); + prop = RNA_def_property(srna, "position", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "custom1"); + RNA_def_property_enum_items(prop, position_items); + RNA_def_property_ui_text(prop, "Position", "Which marker position to use for output"); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); + + prop = RNA_def_property(srna, "relative_frame", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "custom2"); + RNA_def_property_ui_text(prop, "Frame", "Frame to be used for relative position"); RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); RNA_def_struct_sdna_from(srna, "NodeTrackPosData", "storage"); @@ -3807,6 +3864,30 @@ static void rna_def_texture_node(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Type", ""); } +static void rna_def_special_node(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + static EnumPropertyItem specific_node_type_items[] = { + {NODE_GROUP, "GROUP", ICON_NODE, "Group", ""}, + {NODE_FORLOOP, "FORLOOP", ICON_NODE, "For Loop", ""}, + {NODE_WHILELOOP, "WHILELOOP", ICON_NODE, "While Loop", ""}, + {NODE_FRAME, "FRAME", ICON_NODE, "Frame", ""}, + {NODE_REROUTE, "REROUTE", ICON_NODE, "Reroute", ""}, + {0, NULL, 0, NULL, NULL} + }; + + srna = RNA_def_struct(brna, "SpecialNode", "Node"); + RNA_def_struct_ui_text(srna, "Special Node", ""); + RNA_def_struct_sdna(srna, "bNode"); + + prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_enum_items(prop, specific_node_type_items); + RNA_def_property_ui_text(prop, "Type", ""); +} + /* -------------------------------------------------------------------------- */ static void rna_def_nodetree_link_api(BlenderRNA *brna, PropertyRNA *cprop) @@ -4365,7 +4446,7 @@ static void rna_def_texture_nodetree(BlenderRNA *brna) static void define_specific_node(BlenderRNA *brna, int id, void (*func)(StructRNA *)) { StructRNA *srna = def_node(brna, id); - + if (func) func(srna); } @@ -4392,6 +4473,7 @@ void RNA_def_nodetree(BlenderRNA *brna) rna_def_shader_node(brna); rna_def_compositor_node(brna); rna_def_texture_node(brna); + rna_def_special_node(brna); rna_def_composite_nodetree(brna); rna_def_shader_nodetree(brna); diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c index ce6b028beb5..7aedbf40eba 100644 --- a/source/blender/makesrna/intern/rna_object.c +++ b/source/blender/makesrna/intern/rna_object.c @@ -1759,7 +1759,7 @@ static void rna_def_object_modifiers(BlenderRNA *brna, PropertyRNA *cprop) /* RNA_def_property_collection_active(prop, prop_act); */ #endif - /* add target */ + /* add modifier */ func = RNA_def_function(srna, "new", "rna_Object_modifier_new"); RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS); RNA_def_function_ui_description(func, "Add a new modifier"); @@ -1772,11 +1772,11 @@ static void rna_def_object_modifiers(BlenderRNA *brna, PropertyRNA *cprop) parm = RNA_def_pointer(func, "modifier", "Modifier", "", "Newly created modifier"); RNA_def_function_return(func, parm); - /* remove target */ + /* remove modifier */ func = RNA_def_function(srna, "remove", "rna_Object_modifier_remove"); RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS); RNA_def_function_ui_description(func, "Remove an existing modifier from the object"); - /* target to remove*/ + /* modifier to remove */ parm = RNA_def_pointer(func, "modifier", "Modifier", "", "Modifier to remove"); RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL); diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c index ae8c331bf1e..5cabc328778 100644 --- a/source/blender/makesrna/intern/rna_object_api.c +++ b/source/blender/makesrna/intern/rna_object_api.c @@ -87,6 +87,10 @@ Mesh *rna_Object_to_mesh(Object *ob, ReportList *reports, Scene *sce, int apply_ case OB_SURF: { ListBase dispbase = {NULL, NULL}; DerivedMesh *derivedFinal = NULL; + int uv_from_orco; + + int (*orco_index)[4] = NULL; + float (*orco)[3] = NULL; /* copies object and modifiers (but not the data) */ tmpobj = BKE_object_copy(ob); @@ -114,7 +118,37 @@ Mesh *rna_Object_to_mesh(Object *ob, ReportList *reports, Scene *sce, int apply_ tmpobj->derivedFinal = derivedFinal; - BKE_mesh_from_nurbs_displist(tmpobj, &dispbase); + uv_from_orco = (tmpcu->flag & CU_UV_ORCO) != 0; + + if (uv_from_orco) { + /* before curve conversion */ + orco = (float (*)[3])BKE_curve_make_orco(sce, tmpobj); + } + + /* convert object type to mesh */ + BKE_mesh_from_nurbs_displist(tmpobj, &dispbase, uv_from_orco ? (int **)&orco_index : NULL); + + tmpmesh = tmpobj->data; + + if (uv_from_orco && orco && orco_index) { + const char *uvname = "Orco"; + /* add UV's */ + MTexPoly *mtpoly = CustomData_add_layer_named(&tmpmesh->pdata, CD_MTEXPOLY, CD_DEFAULT, NULL, tmpmesh->totpoly, uvname); + MLoopUV *mloopuvs = CustomData_add_layer_named(&tmpmesh->ldata, CD_MLOOPUV, CD_DEFAULT, NULL, tmpmesh->totloop, uvname); + + BKE_mesh_nurbs_to_mdata_orco(tmpmesh->mpoly, tmpmesh->totpoly, + tmpmesh->mloop, mloopuvs, + orco, orco_index); + + (void)mtpoly; + } + + if (orco_index) { + MEM_freeN(orco_index); + } + if (orco) { + MEM_freeN(orco); + } BKE_displist_free(&dispbase); @@ -124,7 +158,7 @@ Mesh *rna_Object_to_mesh(Object *ob, ReportList *reports, Scene *sce, int apply_ BKE_report(reports, RPT_ERROR, "cant convert curve to mesh. Does the curve have any segments?"); return NULL; } - tmpmesh = tmpobj->data; + BKE_libblock_free_us(&G.main->object, tmpobj); break; } diff --git a/source/blender/makesrna/intern/rna_rna.c b/source/blender/makesrna/intern/rna_rna.c index aab3483e29b..db309ed8f1f 100644 --- a/source/blender/makesrna/intern/rna_rna.c +++ b/source/blender/makesrna/intern/rna_rna.c @@ -526,7 +526,7 @@ static int rna_Property_readonly_get(PointerRNA *ptr) { PropertyRNA *prop = (PropertyRNA *)ptr->data; - /* don't use this becaure it will call functions that check the internal + /* don't use this because it will call functions that check the internal * data for introspection we only need to know if it can be edited so the * flag is better for this */ /* return RNA_property_editable(ptr, prop); */ @@ -829,7 +829,7 @@ static void rna_EnumProperty_items_begin(CollectionPropertyIterator *iter, Point int totitem, free = 0; rna_idproperty_check(&prop, ptr); - /* eprop= (EnumPropertyRNA*)prop; */ + /* eprop= (EnumPropertyRNA *)prop; */ RNA_property_enum_items(NULL, ptr, prop, &item, &totitem, &free); rna_iterator_array_begin(iter, (void *)item, sizeof(EnumPropertyItem), totitem, free, rna_enum_check_separator); diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index e9b5debcc60..653743ccd90 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -37,6 +37,7 @@ #include "DNA_particle_types.h" #include "DNA_scene_types.h" #include "DNA_userdef_types.h" +#include "DNA_world_types.h" #include "DNA_linestyle_types.h" #include "BLI_math.h" @@ -146,7 +147,7 @@ EnumPropertyItem snap_node_element_items[] = { }; -/* workaround for duplice enums, +/* workaround for duplicate enums, * have each enum line as a defne then conditionally set it or not */ @@ -774,7 +775,7 @@ static EnumPropertyItem *rna_ImageFormatSettings_color_mode_itemf(bContext *C, P #ifdef WITH_FFMPEG /* a WAY more crappy case than B&W flag: depending on codec, file format MIGHT support * alpha channel. for example MPEG format with h264 codec can't do alpha channel, but - * the same MPEG format with QTRLE codec can easily handle alpga channel. + * the same MPEG format with QTRLE codec can easily handle alpha channel. * not sure how to deal with such cases in a nicer way (sergey) */ if (is_render) { Scene *scene = ptr->id.data; @@ -1108,7 +1109,7 @@ static void rna_RenderSettings_color_management_update(Main *bmain, Scene *UNUSE if (ntree && scene->use_nodes) { /* images are freed here, stop render and preview threads, until - * Image is threadsafe. when we are changing this propery from a + * Image is threadsafe. when we are changing this property from a * python script in the render thread, don't stop own thread */ if (BLI_thread_is_main()) WM_jobs_stop_all(bmain->wm.first); @@ -3056,13 +3057,13 @@ static void rna_def_scene_game_data(BlenderRNA *brna) /* mode */ prop = RNA_def_property(srna, "use_occlusion_culling", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "mode", (1 << 5)); /*XXX mode hardcoded *//* WO_DBVT_CULLING */ + RNA_def_property_boolean_sdna(prop, NULL, "mode", WO_DBVT_CULLING); RNA_def_property_ui_text(prop, "DBVT culling", "Use optimized Bullet DBVT tree for view frustum and occlusion culling"); /* not used *//* deprecated !!!!!!!!!!!!! */ prop = RNA_def_property(srna, "use_activity_culling", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "mode", (1 << 3)); /*XXX mode hardcoded */ + RNA_def_property_boolean_sdna(prop, NULL, "mode", WO_ACTIVITY_CULLING); RNA_def_property_ui_text(prop, "Activity Culling", "Activity culling is enabled"); /* not used *//* deprecated !!!!!!!!!!!!! */ @@ -3478,21 +3479,21 @@ static void rna_def_scene_ffmpeg_settings(BlenderRNA *brna) prop = RNA_def_property(srna, "video_bitrate", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "video_bitrate"); RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); - RNA_def_property_range(prop, 1, 14000); + RNA_def_property_range(prop, 1, 64000); RNA_def_property_ui_text(prop, "Bitrate", "Video bitrate (kb/s)"); RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL); prop = RNA_def_property(srna, "minrate", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "rc_min_rate"); RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); - RNA_def_property_range(prop, 0, 9000); + RNA_def_property_range(prop, 0, 48000); RNA_def_property_ui_text(prop, "Min Rate", "Rate control: min rate (kb/s)"); RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL); prop = RNA_def_property(srna, "maxrate", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "rc_max_rate"); RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); - RNA_def_property_range(prop, 1, 14000); + RNA_def_property_range(prop, 1, 96000); RNA_def_property_ui_text(prop, "Max Rate", "Rate control: max rate (kb/s)"); RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL); diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index 4473a9ef0f6..793eb2b7185 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -123,7 +123,7 @@ EnumPropertyItem clip_editor_mode_items[] = { {SC_MODE_RECONSTRUCTION, "RECONSTRUCTION", ICON_SNAP_FACE, "Reconstruction", "Show tracking/reconstruction tools"}, {SC_MODE_DISTORTION, "DISTORTION", ICON_GRID, "Distortion", "Show distortion tools"}, - {SC_MODE_MASKEDIT, "MASKEDIT", ICON_MOD_MASK, "Mask editing", "Show mask editing tools"}, + {SC_MODE_MASKEDIT, "MASK", ICON_MOD_MASK, "Mask", "Show mask editing tools"}, {0, NULL, 0, NULL, NULL} }; @@ -529,11 +529,14 @@ static PointerRNA rna_SpaceImageEditor_uvedit_get(PointerRNA *ptr) return rna_pointer_inherit_refine(ptr, &RNA_SpaceUVEditor, ptr->data); } -static void rna_SpaceImageEditor_paint_update(Main *bmain, Scene *scene, PointerRNA *UNUSED(ptr)) +static void rna_SpaceImageEditor_mode_update(Main *bmain, Scene *scene, PointerRNA *ptr) { - paint_init(&scene->toolsettings->imapaint.paint, PAINT_CURSOR_TEXTURE_PAINT); + SpaceImage *sima = (SpaceImage *)(ptr->data); + if (sima->mode == SI_MODE_PAINT) { + BKE_paint_init(&scene->toolsettings->imapaint.paint, PAINT_CURSOR_TEXTURE_PAINT); - ED_space_image_paint_update(bmain->wm.first, scene->toolsettings); + ED_space_image_paint_update(bmain->wm.first, scene->toolsettings); + } } static int rna_SpaceImageEditor_show_render_get(PointerRNA *ptr) @@ -555,6 +558,13 @@ static int rna_SpaceImageEditor_show_uvedit_get(PointerRNA *ptr) return ED_space_image_show_uvedit(sima, sc->scene->obedit); } +static int rna_SpaceImageEditor_show_maskedit_get(PointerRNA *ptr) +{ + SpaceImage *sima = (SpaceImage *)(ptr->data); + bScreen *sc = (bScreen *)ptr->id.data; + return ED_space_image_check_show_maskedit(sc->scene, sima); +} + static void rna_SpaceImageEditor_image_set(PointerRNA *ptr, PointerRNA value) { SpaceImage *sima = (SpaceImage *)(ptr->data); @@ -563,6 +573,13 @@ static void rna_SpaceImageEditor_image_set(PointerRNA *ptr, PointerRNA value) ED_space_image_set(sima, sc->scene, sc->scene->obedit, (Image *)value.data); } +static void rna_SpaceImageEditor_mask_set(PointerRNA *ptr, PointerRNA value) +{ + SpaceImage *sima = (SpaceImage *)(ptr->data); + + ED_space_image_set_mask(NULL, sima, (Mask *)value.data); +} + static EnumPropertyItem *rna_SpaceImageEditor_draw_channels_itemf(bContext *UNUSED(C), PointerRNA *ptr, PropertyRNA *UNUSED(prop), int *free) { @@ -610,7 +627,7 @@ static void rna_SpaceImageEditor_zoom_get(PointerRNA *ptr, float *values) sa = rna_area_from_space(ptr); /* can be NULL */ ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); if (ar) { - ED_space_image_zoom(sima, ar, &values[0], &values[1]); + ED_space_image_get_zoom(sima, ar, &values[0], &values[1]); } } @@ -623,7 +640,7 @@ static void rna_SpaceImageEditor_cursor_location_get(PointerRNA *ptr, float *val } else { int w, h; - ED_space_image_size(sima, &w, &h); + ED_space_image_get_size(sima, &w, &h); values[0] = sima->cursor[0] * w; values[1] = sima->cursor[1] * h; @@ -639,7 +656,7 @@ static void rna_SpaceImageEditor_cursor_location_set(PointerRNA *ptr, const floa } else { int w, h; - ED_space_image_size(sima, &w, &h); + ED_space_image_get_size(sima, &w, &h); sima->cursor[0] = values[0] / w; sima->cursor[1] = values[1] / h; @@ -1103,6 +1120,31 @@ static void rna_def_space(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Type", "Space data type"); } +/* for all spaces that use a mask */ +void rna_def_space_mask_info(StructRNA *srna, int noteflag, const char *mask_set_func) +{ + PropertyRNA *prop; + + prop = RNA_def_property(srna, "mask", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, NULL, "mask_info.mask"); + RNA_def_property_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Mask", "Mask displayed and edited in this space"); + RNA_def_property_pointer_funcs(prop, NULL, mask_set_func, NULL, NULL); + RNA_def_property_update(prop, noteflag, NULL); + + /* mask drawing */ + prop = RNA_def_property(srna, "mask_draw_type", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "mask_info.draw_type"); + RNA_def_property_enum_items(prop, dt_uv_items); + RNA_def_property_ui_text(prop, "Edge Draw Type", "Draw type for mask splines"); + RNA_def_property_update(prop, noteflag, NULL); + + prop = RNA_def_property(srna, "show_mask_smooth", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "mask_info.draw_flag", MASK_DRAWFLAG_SMOOTH); + RNA_def_property_ui_text(prop, "Draw Smooth Splines", ""); + RNA_def_property_update(prop, noteflag, NULL); +} + static void rna_def_space_image_uv(BlenderRNA *brna) { StructRNA *srna; @@ -1928,6 +1970,13 @@ static void rna_def_space_buttons(BlenderRNA *brna) static void rna_def_space_image(BlenderRNA *brna) { + static EnumPropertyItem image_space_mode_items[] = { + {SI_MODE_VIEW, "VIEW", ICON_FILE_IMAGE, "View", "View the image and UV edit in mesh editmode"}, + {SI_MODE_PAINT, "PAINT", ICON_TPAINT_HLT, "Paint", "2D image painting mode"}, + {SI_MODE_MASK, "MASK", ICON_MOD_MASK, "Mask", "Mask editing"}, + {0, NULL, 0, NULL, NULL} + }; + StructRNA *srna; PropertyRNA *prop; @@ -1997,12 +2046,12 @@ static void rna_def_space_image(BlenderRNA *brna) RNA_def_property_pointer_funcs(prop, "rna_SpaceImageEditor_uvedit_get", NULL, NULL, NULL); RNA_def_property_ui_text(prop, "UV Editor", "UV editor settings"); - /* paint */ - prop = RNA_def_property(srna, "use_image_paint", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "flag", SI_DRAWTOOL); - RNA_def_property_ui_text(prop, "Image Painting", "Enable image painting mode"); - RNA_def_property_ui_icon(prop, ICON_TPAINT_HLT, 0); - RNA_def_property_update(prop, NC_SPACE | ND_SPACE_IMAGE, "rna_SpaceImageEditor_paint_update"); + /* mode */ + prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "mode"); + RNA_def_property_enum_items(prop, image_space_mode_items); + RNA_def_property_ui_text(prop, "Mode", "Editing context being displayed"); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_IMAGE, "rna_SpaceImageEditor_mode_update"); /* grease pencil */ prop = RNA_def_property(srna, "grease_pencil", PROP_POINTER, PROP_NONE); @@ -2035,7 +2084,15 @@ static void rna_def_space_image(BlenderRNA *brna) RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Show UV Editor", "Show UV editing related properties"); + prop = RNA_def_property(srna, "show_maskedit", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_funcs(prop, "rna_SpaceImageEditor_show_maskedit_get", NULL); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Show Mask Editor", "Show Mask editing related properties"); + rna_def_space_image_uv(brna); + + /* mask */ + rna_def_space_mask_info(srna, NC_SPACE | ND_SPACE_IMAGE, "rna_SpaceImageEditor_mask_set"); } static void rna_def_space_sequencer(BlenderRNA *brna) @@ -2944,6 +3001,11 @@ static void rna_def_space_node(BlenderRNA *brna) RNA_def_property_boolean_sdna(prop, NULL, "flag", SNODE_SHOW_HIGHLIGHT); RNA_def_property_ui_text(prop, "Highlight", "Highlight nodes that are being calculated"); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_NODE_VIEW, NULL); + + prop = RNA_def_property(srna, "use_hidden_preview", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", SNODE_USE_HIDDEN_PREVIEW); + RNA_def_property_ui_text(prop, "Hide Preview", "Hide preview for newly creating nodes"); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_NODE_VIEW, NULL); } static void rna_def_space_logic(BlenderRNA *brna) @@ -3064,24 +3126,7 @@ static void rna_def_space_clip(BlenderRNA *brna) RNA_def_property_update(prop, NC_SPACE | ND_SPACE_CLIP, NULL); /* mask */ - prop = RNA_def_property(srna, "mask", PROP_POINTER, PROP_NONE); - RNA_def_property_flag(prop, PROP_EDITABLE); - RNA_def_property_ui_text(prop, "Mask", "Mask displayed and edited in this space"); - RNA_def_property_pointer_funcs(prop, NULL, "rna_SpaceClipEditor_mask_set", NULL, NULL); - RNA_def_property_update(prop, NC_SPACE | ND_SPACE_CLIP, NULL); - - /* mask drawing */ - prop = RNA_def_property(srna, "mask_draw_type", PROP_ENUM, PROP_NONE); - RNA_def_property_enum_sdna(prop, NULL, "mask_draw_type"); - RNA_def_property_enum_items(prop, dt_uv_items); - RNA_def_property_ui_text(prop, "Edge Draw Type", "Draw type for mask splines"); - RNA_def_property_update(prop, NC_SPACE | ND_SPACE_CLIP, NULL); - - prop = RNA_def_property(srna, "show_mask_smooth", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "mask_draw_flag", MASK_DRAWFLAG_SMOOTH); - RNA_def_property_ui_text(prop, "Draw Smooth Splines", ""); - RNA_def_property_update(prop, NC_SPACE | ND_SPACE_CLIP, NULL); - + rna_def_space_mask_info(srna, NC_SPACE | ND_SPACE_CLIP, "rna_SpaceClipEditor_mask_set"); /* mode */ prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE); diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index 0948438abc8..119c37484f0 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -1193,6 +1193,11 @@ static void rna_def_userdef_theme_space_view3d(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Bone Pose", ""); RNA_def_property_update(prop, 0, "rna_userdef_update"); + prop = RNA_def_property(srna, "bone_pose_active", PROP_FLOAT, PROP_COLOR_GAMMA); + RNA_def_property_array(prop, 3); + RNA_def_property_ui_text(prop, "Bone Pose Active", ""); + RNA_def_property_update(prop, 0, "rna_userdef_update"); + prop = RNA_def_property(srna, "frame_current", PROP_FLOAT, PROP_COLOR_GAMMA); RNA_def_property_float_sdna(prop, NULL, "cframe"); RNA_def_property_array(prop, 3); @@ -2991,6 +2996,7 @@ static void rna_def_userdef_system(BlenderRNA *brna) { 8, "FRENCH", 0, "French (Français)", "fr_FR"}, { 4, "ITALIAN", 0, "Italian (Italiano)", "it_IT"}, { 2, "JAPANESE", 0, "Japanese (日本語)", "ja_JP"}, + {12, "PORTUGUESE", 0, "Portuguese (Português)", "pt"}, {15, "RUSSIAN", 0, "Russian (Русский)", "ru_RU"}, {13, "SIMPLIFIED_CHINESE", 0, "Simplified Chinese (简体中文)", "zh_CN"}, { 9, "SPANISH", 0, "Spanish (Español)", "es"}, @@ -3014,7 +3020,6 @@ static void rna_def_userdef_system(BlenderRNA *brna) /* using the utf8 flipped form of Persian (فارسی) */ {26, "PERSIAN", 0, "Persian (ﯽﺳﺭﺎﻓ)", "fa_IR"}, {19, "POLISH", 0, "Polish (Polski)", "pl_PL"}, - {12, "BRAZILIAN_PORTUGUESE", 0, "Portuguese (Português)", "pt"}, /* {20, "ROMANIAN", 0, "Romanian (Român)", "ro_RO"}, */ /* XXX No po's yet. */ {17, "SERBIAN", 0, "Serbian (Српски)", "sr_RS"}, {28, "SERBIAN_LATIN", 0, "Serbian latin (Srpski latinica)", "sr_RS@latin"}, diff --git a/source/blender/modifiers/intern/MOD_array.c b/source/blender/modifiers/intern/MOD_array.c index 57c230fcde6..26682e30841 100644 --- a/source/blender/modifiers/intern/MOD_array.c +++ b/source/blender/modifiers/intern/MOD_array.c @@ -172,7 +172,7 @@ static int *find_doubles_index_map(BMesh *bm, BMOperator *dupe_op, BMElem *ele; int *index_map, i; - BMO_op_initf(bm, &find_op, + BMO_op_initf(bm, &find_op, (BMO_FLAG_DEFAULTS & ~BMO_FLAG_RESPECT_HIDE), "find_doubles verts=%av dist=%f keep_verts=%s", amd->merge_dist, dupe_op, "geom"); @@ -234,7 +234,7 @@ static void bm_merge_dm_transform(BMesh *bm, DerivedMesh *dm, float mat[4][4], BMOIter oiter; BMOperator find_op; - BMO_op_initf(bm, &find_op, + BMO_op_initf(bm, &find_op, (BMO_FLAG_DEFAULTS & ~BMO_FLAG_RESPECT_HIDE), "find_doubles verts=%Hv dist=%f keep_verts=%s", BM_ELEM_TAG, amd->merge_dist, dupe_op, dupe_slot_name); @@ -286,7 +286,7 @@ static void merge_first_last(BMesh *bm, BMOIter oiter; BMVert *v, *v2; - BMO_op_initf(bm, &find_op, + BMO_op_initf(bm, &find_op, (BMO_FLAG_DEFAULTS & ~BMO_FLAG_RESPECT_HIDE), "find_doubles verts=%s dist=%f keep_verts=%s", dupe_first, "geom", amd->merge_dist, dupe_first, "geom"); @@ -410,9 +410,11 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd, bmesh_edit_begin(em->bm, 0); if (amd->flags & MOD_ARR_MERGE) - BMO_op_init(em->bm, &weld_op, "weld_verts"); + BMO_op_init(em->bm, &weld_op, (BMO_FLAG_DEFAULTS & ~BMO_FLAG_RESPECT_HIDE), + "weld_verts"); - BMO_op_initf(em->bm, &dupe_op, "duplicate geom=%avef"); + BMO_op_initf(em->bm, &dupe_op, (BMO_FLAG_DEFAULTS & ~BMO_FLAG_RESPECT_HIDE), + "duplicate geom=%avef"); first_dupe_op = dupe_op; for (j = 0; j < count - 1; j++) { @@ -421,8 +423,11 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd, BMOpSlot *newout_slot; BMOIter oiter; - if (j != 0) - BMO_op_initf(em->bm, &dupe_op, "duplicate geom=%s", &old_dupe_op, "newout"); + if (j != 0) { + BMO_op_initf(em->bm, &dupe_op, + (BMO_FLAG_DEFAULTS & ~BMO_FLAG_RESPECT_HIDE), + "duplicate geom=%s", &old_dupe_op, "newout"); + } BMO_op_exec(em->bm, &dupe_op); geom_slot = BMO_slot_get(&dupe_op, "geom"); diff --git a/source/blender/modifiers/intern/MOD_bevel.c b/source/blender/modifiers/intern/MOD_bevel.c index 6c91cd6e2d1..cdb200ff180 100644 --- a/source/blender/modifiers/intern/MOD_bevel.c +++ b/source/blender/modifiers/intern/MOD_bevel.c @@ -143,7 +143,8 @@ static DerivedMesh *applyModifier(ModifierData *md, struct Object *UNUSED(ob), } } - BMO_op_callf(bm, "bevel geom=%fe percent=%f use_even=%b use_dist=%b", + BMO_op_callf(bm, BMO_FLAG_DEFAULTS, + "bevel geom=%fe percent=%f use_even=%b use_dist=%b", EDGE_MARK, bmd->value, (bmd->flags & BME_BEVEL_EVEN) != 0, (bmd->flags & BME_BEVEL_DIST) != 0); BMO_pop(bm); diff --git a/source/blender/modifiers/intern/MOD_boolean.c b/source/blender/modifiers/intern/MOD_boolean.c index 6cd8745f5d9..fb9788fb278 100644 --- a/source/blender/modifiers/intern/MOD_boolean.c +++ b/source/blender/modifiers/intern/MOD_boolean.c @@ -127,7 +127,19 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, if (!bmd->object) return derivedData; - dm = bmd->object->derivedFinal; + + /* 2.63 used this... */ + /* dm = bmd->object->derivedFinal; */ + + /* but we want to make sure we can get the object + * in some cases the depsgraph fails us - especially for objects + * in other scenes when compositing */ + if (bmd->object != ob) { + dm = mesh_get_derived_final(md->scene, bmd->object, CD_MASK_MESH); + } + else { + dm = NULL; + } if (dm) { DerivedMesh *result; diff --git a/source/blender/modifiers/intern/MOD_cast.c b/source/blender/modifiers/intern/MOD_cast.c index 5e791a9f748..c80b4dfa4de 100644 --- a/source/blender/modifiers/intern/MOD_cast.c +++ b/source/blender/modifiers/intern/MOD_cast.c @@ -381,9 +381,9 @@ static void cuboid_do( } /* we want a symmetric bound box around the origin */ - if (fabs(min[0]) > fabs(max[0])) max[0] = fabs(min[0]); - if (fabs(min[1]) > fabs(max[1])) max[1] = fabs(min[1]); - if (fabs(min[2]) > fabs(max[2])) max[2] = fabs(min[2]); + if (fabsf(min[0]) > fabsf(max[0])) max[0] = fabsf(min[0]); + if (fabsf(min[1]) > fabsf(max[1])) max[1] = fabsf(min[1]); + if (fabsf(min[2]) > fabsf(max[2])) max[2] = fabsf(min[2]); min[0] = -max[0]; min[1] = -max[1]; min[2] = -max[2]; diff --git a/source/blender/modifiers/intern/MOD_edgesplit.c b/source/blender/modifiers/intern/MOD_edgesplit.c index 471317a279c..b1c3459bf51 100644 --- a/source/blender/modifiers/intern/MOD_edgesplit.c +++ b/source/blender/modifiers/intern/MOD_edgesplit.c @@ -103,7 +103,8 @@ static DerivedMesh *doEdgeSplit(DerivedMesh *dm, EdgeSplitModifierData *emd, Obj } } - BMO_op_callf(bm, "split_edges edges=%fe", EDGE_MARK); + BMO_op_callf(bm, BMO_FLAG_DEFAULTS, + "split_edges edges=%fe", EDGE_MARK); BMO_pop(bm); diff --git a/source/blender/modifiers/intern/MOD_ocean.c b/source/blender/modifiers/intern/MOD_ocean.c index dfbfbd22475..21836453eed 100644 --- a/source/blender/modifiers/intern/MOD_ocean.c +++ b/source/blender/modifiers/intern/MOD_ocean.c @@ -242,13 +242,13 @@ static void dm_get_bounds(DerivedMesh *dm, float *sx, float *sy, float *ox, floa copy_v3_v3(max, mvert->co); for (v = 1; v < totvert; v++, mvert++) { - min[0] = MIN2(min[0], mvert->co[0]); - min[1] = MIN2(min[1], mvert->co[1]); - min[2] = MIN2(min[2], mvert->co[2]); + min[0] = minf(min[0], mvert->co[0]); + min[1] = minf(min[1], mvert->co[1]); + min[2] = minf(min[2], mvert->co[2]); - max[0] = MAX2(max[0], mvert->co[0]); - max[1] = MAX2(max[1], mvert->co[1]); - max[2] = MAX2(max[2], mvert->co[2]); + max[0] = maxf(max[0], mvert->co[0]); + max[1] = maxf(max[1], mvert->co[1]); + max[2] = maxf(max[2], mvert->co[2]); } sub_v3_v3v3(delta, max, min); diff --git a/source/blender/modifiers/intern/MOD_particlesystem.c b/source/blender/modifiers/intern/MOD_particlesystem.c index 0cf36677807..ecdc5b53460 100644 --- a/source/blender/modifiers/intern/MOD_particlesystem.c +++ b/source/blender/modifiers/intern/MOD_particlesystem.c @@ -176,6 +176,7 @@ static void deformVerts(ModifierData *md, Object *ob, psmd->dm->needsFree = 0; /* report change in mesh structure */ + DM_ensure_tessface(psmd->dm); if (psmd->dm->getNumVerts(psmd->dm) != psmd->totdmvert || psmd->dm->getNumEdges(psmd->dm) != psmd->totdmedge || psmd->dm->getNumTessFaces(psmd->dm) != psmd->totdmface) diff --git a/source/blender/modifiers/intern/MOD_simpledeform.c b/source/blender/modifiers/intern/MOD_simpledeform.c index 14735810cad..bf5f6cd095e 100644 --- a/source/blender/modifiers/intern/MOD_simpledeform.c +++ b/source/blender/modifiers/intern/MOD_simpledeform.c @@ -161,7 +161,7 @@ static void SimpleDeformModifier_do(SimpleDeformModifierData *smd, struct Object if (smd->limit[0] < 0.0f) smd->limit[0] = 0.0f; if (smd->limit[0] > 1.0f) smd->limit[0] = 1.0f; - smd->limit[0] = MIN2(smd->limit[0], smd->limit[1]); /* Upper limit >= than lower limit */ + smd->limit[0] = minf(smd->limit[0], smd->limit[1]); /* Upper limit >= than lower limit */ //Calculate matrixs do convert between coordinate spaces if (smd->origin) { @@ -190,8 +190,8 @@ static void SimpleDeformModifier_do(SimpleDeformModifierData *smd, struct Object if (transf) space_transform_apply(transf, tmp); - lower = MIN2(lower, tmp[limit_axis]); - upper = MAX2(upper, tmp[limit_axis]); + lower = minf(lower, tmp[limit_axis]); + upper = maxf(upper, tmp[limit_axis]); } diff --git a/source/blender/modifiers/intern/MOD_skin.c b/source/blender/modifiers/intern/MOD_skin.c index f24898ccee2..0eacfd392b9 100644 --- a/source/blender/modifiers/intern/MOD_skin.c +++ b/source/blender/modifiers/intern/MOD_skin.c @@ -236,7 +236,8 @@ static int build_hull(SkinOutput *so, Frame **frames, int totframe) * selected after the operator is run */ BM_mesh_elem_hflag_disable_all(bm, BM_ALL, BM_ELEM_SELECT, 0); - BMO_op_initf(bm, &op, "convex_hull input=%hv", BM_ELEM_TAG); + BMO_op_initf(bm, &op, (BMO_FLAG_DEFAULTS & ~BMO_FLAG_RESPECT_HIDE), + "convex_hull input=%hv", BM_ELEM_TAG); BMO_op_exec(bm, &op); if (BMO_error_occurred(bm)) { @@ -319,7 +320,9 @@ static int build_hull(SkinOutput *so, Frame **frames, int totframe) BMO_op_finish(bm, &op); - BMO_op_callf(bm, "delete geom=%hef context=%i", BM_ELEM_TAG, DEL_ONLYTAGGED); + BMO_op_callf(bm, BMO_FLAG_DEFAULTS, + "delete geom=%hef context=%i", + BM_ELEM_TAG, DEL_ONLYTAGGED); return TRUE; } @@ -351,7 +354,7 @@ static void merge_frame_corners(Frame **frames, int totframe) BLI_assert(frames[i] != frames[k]); side_b = frame_len(frames[k]); - thresh = MIN2(side_a, side_b) / 2.0f; + thresh = minf(side_a, side_b) / 2.0f; /* Compare with each corner of all other frames... */ for (l = 0; l < 4; l++) { @@ -1039,7 +1042,7 @@ static BMFace *collapse_face_corners(BMesh *bm, BMFace *f, int n, int i; shortest_edge = BM_face_find_shortest_loop(f)->e; - BMO_op_initf(bm, &op, "weld_verts"); + BMO_op_initf(bm, &op, (BMO_FLAG_DEFAULTS & ~BMO_FLAG_RESPECT_HIDE), "weld_verts"); /* Note: could probably calculate merges in one go to be * faster */ @@ -1179,7 +1182,8 @@ static void skin_fix_hole_no_good_verts(BMesh *bm, Frame *frame, BMFace *split_f /* Extrude the split face */ BM_mesh_elem_hflag_disable_all(bm, BM_FACE, BM_ELEM_TAG, FALSE); BM_elem_flag_enable(split_face, BM_ELEM_TAG); - BMO_op_initf(bm, &op, "extrude_discrete_faces faces=%hf", BM_ELEM_TAG); + BMO_op_initf(bm, &op, (BMO_FLAG_DEFAULTS & ~BMO_FLAG_RESPECT_HIDE), + "extrude_discrete_faces faces=%hf", BM_ELEM_TAG); BMO_op_exec(bm, &op); /* Update split face (should only be one new face created @@ -1202,7 +1206,8 @@ static void skin_fix_hole_no_good_verts(BMesh *bm, Frame *frame, BMFace *split_f BM_mesh_elem_hflag_disable_all(bm, BM_EDGE, BM_ELEM_TAG, FALSE); BM_elem_flag_enable(longest_edge, BM_ELEM_TAG); - BMO_op_callf(bm, "subdivide_edges edges=%he numcuts=%i quadcornertype=%i", + BMO_op_callf(bm, BMO_FLAG_DEFAULTS, + "subdivide_edges edges=%he numcuts=%i quadcornertype=%i", BM_ELEM_TAG, 1, SUBD_STRAIGHT_CUT); } else if (split_face->len > 4) { @@ -1234,7 +1239,8 @@ static void skin_fix_hole_no_good_verts(BMesh *bm, Frame *frame, BMFace *split_f /* Delete split face and merge */ BM_face_kill(bm, split_face); - BMO_op_init(bm, &op, "weld_verts"); + BMO_op_init(bm, &op, (BMO_FLAG_DEFAULTS & ~BMO_FLAG_RESPECT_HIDE), + "weld_verts"); for (i = 0; i < 4; i++) { BMO_slot_map_ptr_insert(bm, &op, "targetmap", verts[i], frame->verts[best_order[i]]); @@ -1399,7 +1405,9 @@ static void hull_merge_triangles(SkinOutput *so, const SkinModifierData *smd) } } - BMO_op_callf(so->bm, "delete geom=%hef context=%i", BM_ELEM_TAG, DEL_ONLYTAGGED); + BMO_op_callf(so->bm, BMO_FLAG_DEFAULTS, + "delete geom=%hef context=%i", + BM_ELEM_TAG, DEL_ONLYTAGGED); BLI_heap_free(heap, NULL); } diff --git a/source/blender/nodes/composite/nodes/node_composite_common.c b/source/blender/nodes/composite/nodes/node_composite_common.c index f3e0edfc691..3a3f94f05cc 100644 --- a/source/blender/nodes/composite/nodes/node_composite_common.c +++ b/source/blender/nodes/composite/nodes/node_composite_common.c @@ -114,7 +114,7 @@ static void move_stack(bNodeStack *to, bNodeStack *from) static void *group_initexec(bNode *node) { - bNodeTree *ngroup= (bNodeTree*)node->id; + bNodeTree *ngroup= (bNodeTree *)node->id; bNodeTreeExec *exec; bNodeSocket *sock; bNodeStack *ns; @@ -138,7 +138,7 @@ static void *group_initexec(bNode *node) static void group_freeexec(bNode *UNUSED(node), void *nodedata) { - bNodeTreeExec *gexec= (bNodeTreeExec*)nodedata; + bNodeTreeExec *gexec= (bNodeTreeExec *)nodedata; if (gexec) ntreeCompositEndExecTree(gexec, 0); @@ -193,7 +193,7 @@ static void group_free_internal(bNodeTreeExec *gexec) static void group_execute(void *data, int thread, struct bNode *node, void *nodedata, struct bNodeStack **in, struct bNodeStack **out) { - bNodeTreeExec *exec= (bNodeTreeExec*)nodedata; + bNodeTreeExec *exec= (bNodeTreeExec *)nodedata; if (!exec) return; @@ -265,7 +265,7 @@ static void loop_iteration_reset(bNodeTree *ngroup, bNodeStack *gstack) static void forloop_execute(void *data, int thread, struct bNode *node, void *nodedata, struct bNodeStack **in, struct bNodeStack **out) { - bNodeTreeExec *exec= (bNodeTreeExec*)nodedata; + bNodeTreeExec *exec= (bNodeTreeExec *)nodedata; int totiterations= (int)in[0]->vec[0]; bNodeSocket *sock; bNodeStack *ns; @@ -323,7 +323,7 @@ void register_node_type_cmp_forloop(bNodeTreeType *ttype) #if 0 /* XXX loop nodes don't work nicely with current trees */ static void whileloop_execute(void *data, int thread, struct bNode *node, void *nodedata, struct bNodeStack **in, struct bNodeStack **out) { - bNodeTreeExec *exec= (bNodeTreeExec*)nodedata; + bNodeTreeExec *exec= (bNodeTreeExec *)nodedata; int condition= (in[0]->vec[0] > 0.0f); bNodeSocket *sock; bNodeStack *ns; diff --git a/source/blender/nodes/composite/nodes/node_composite_defocus.c b/source/blender/nodes/composite/nodes/node_composite_defocus.c index 2ae3cd6ba56..d9ee067efe3 100644 --- a/source/blender/nodes/composite/nodes/node_composite_defocus.c +++ b/source/blender/nodes/composite/nodes/node_composite_defocus.c @@ -587,8 +587,8 @@ static void defocus_blur(bNode *node, CompBuf *new, CompBuf *img, CompBuf *zbuf, // n-agonal int ov, nv; float mind, maxd, lwt; - ys = MAX2((int)floor(bkh_b[2]*ct_crad + y), 0); - ye = MIN2((int)ceil(bkh_b[3]*ct_crad + y), new->y - 1); + ys = maxi((int)floor(bkh_b[2] * ct_crad + y), 0); + ye = mini((int)ceil(bkh_b[3] * ct_crad + y), new->y - 1); for (sy=ys; sy<=ye; sy++) { float fxs = 1e10f, fxe = -1e10f; float yf = (sy - y)/ct_crad; diff --git a/source/blender/nodes/composite/nodes/node_composite_mask.c b/source/blender/nodes/composite/nodes/node_composite_mask.c index 3cd3a732829..f4cbd1b7f6f 100644 --- a/source/blender/nodes/composite/nodes/node_composite_mask.c +++ b/source/blender/nodes/composite/nodes/node_composite_mask.c @@ -38,8 +38,6 @@ #include "node_composite_util.h" -#include "../../../../intern/raskter/raskter.h" - /* **************** Translate ******************** */ static bNodeSocketTemplate cmp_node_mask_out[] = { @@ -51,6 +49,7 @@ static void exec(void *data, bNode *node, bNodeStack **UNUSED(in), bNodeStack ** { if (node->id) { Mask *mask = (Mask *)node->id; + MaskRasterHandle *mr_handle; CompBuf *stackbuf; RenderData *rd = data; float *res; @@ -70,18 +69,32 @@ static void exec(void *data, bNode *node, bNodeStack **UNUSED(in), bNodeStack ** stackbuf = alloc_compbuf(sx, sy, CB_VAL, TRUE); res = stackbuf->rect; - BKE_mask_rasterize(mask, sx, sy, res, TRUE, - (node->custom1 & CMP_NODEFLAG_MASK_AA) != 0, - (node->custom1 & CMP_NODEFLAG_MASK_NO_FEATHER) == 0); + /* mask raster begin */ + mr_handle = BKE_maskrasterize_handle_new(); + BKE_maskrasterize_handle_init(mr_handle, mask, + sx, sy, + TRUE, + (node->custom1 & CMP_NODEFLAG_MASK_AA) != 0, + (node->custom1 & CMP_NODEFLAG_MASK_NO_FEATHER) == 0); + BKE_maskrasterize_buffer(mr_handle, sx, sy, res); + BKE_maskrasterize_handle_free(mr_handle); + /* mask raster end */ - if (node->custom1) { - PLX_antialias_buffer(res,sx,sy); - } /* pass on output and free */ out[0]->data = stackbuf; } } +static void node_composit_init_mask(bNodeTree *UNUSED(ntree), bNode* node, bNodeTemplate *UNUSED(ntemp)) +{ + NodeMask *data = MEM_callocN(sizeof(NodeMask), STRINGIFY(NodeMask)); + data->size_x = data->size_y = 256; + node->storage = data; + + node->custom2 = 16; /* samples */ + node->custom3 = 0.5f; /* shutter */ +} + void register_node_type_cmp_mask(bNodeTreeType *ttype) { static bNodeType ntype; @@ -89,7 +102,10 @@ void register_node_type_cmp_mask(bNodeTreeType *ttype) node_type_base(ttype, &ntype, CMP_NODE_MASK, "Mask", NODE_CLASS_INPUT, NODE_OPTIONS); node_type_socket_templates(&ntype, NULL, cmp_node_mask_out); node_type_size(&ntype, 140, 100, 320); + node_type_init(&ntype, node_composit_init_mask); node_type_exec(&ntype, exec); + node_type_storage(&ntype, "NodeMask", node_free_standard_storage, node_copy_standard_storage); + nodeRegisterType(ttype, &ntype); } diff --git a/source/blender/nodes/composite/nodes/node_composite_outputFile.c b/source/blender/nodes/composite/nodes/node_composite_outputFile.c index fcc8ed4a128..fd312d71f2c 100644 --- a/source/blender/nodes/composite/nodes/node_composite_outputFile.c +++ b/source/blender/nodes/composite/nodes/node_composite_outputFile.c @@ -123,6 +123,8 @@ bNodeSocket *ntreeCompositOutputFileAddSocket(bNodeTree *ntree, bNode *node, con sockdata->format.imtype= R_IMF_IMTYPE_OPENEXR; } } + else + BKE_imformat_defaults(&sockdata->format); /* use node data format by default */ sockdata->use_node_format = TRUE; @@ -174,9 +176,14 @@ static void init_output_file(bNodeTree *ntree, bNode* node, bNodeTemplate *ntemp RenderData *rd = &ntemp->scene->r; BLI_strncpy(nimf->base_path, rd->pic, sizeof(nimf->base_path)); nimf->format = rd->im_format; + if (BKE_imtype_is_movie(nimf->format.imtype)) { + nimf->format.imtype= R_IMF_IMTYPE_OPENEXR; + } - format = &rd->im_format; + format = &nimf->format; } + else + BKE_imformat_defaults(&nimf->format); /* add one socket by default */ ntreeCompositOutputFileAddSocket(ntree, node, "Image", format); diff --git a/source/blender/nodes/shader/nodes/node_shader_particle_info.c b/source/blender/nodes/shader/nodes/node_shader_particle_info.c index beefc0b6eae..5be8925b556 100644 --- a/source/blender/nodes/shader/nodes/node_shader_particle_info.c +++ b/source/blender/nodes/shader/nodes/node_shader_particle_info.c @@ -28,9 +28,10 @@ #include "../node_shader_util.h" static bNodeSocketTemplate outputs[] = { - { SOCK_FLOAT, 0, "Age" }, - { SOCK_FLOAT, 0, "Lifetime" }, - { -1, 0, "" } + { SOCK_FLOAT, 0, "Index" }, + { SOCK_FLOAT, 0, "Age" }, + { SOCK_FLOAT, 0, "Lifetime" }, + { -1, 0, "" } }; /* node type definition */ diff --git a/source/blender/nodes/texture/nodes/node_texture_texture.c b/source/blender/nodes/texture/nodes/node_texture_texture.c index 98382e24290..4832f19f2c7 100644 --- a/source/blender/nodes/texture/nodes/node_texture_texture.c +++ b/source/blender/nodes/texture/nodes/node_texture_texture.c @@ -65,7 +65,7 @@ static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor if (node->custom2 || node->need_exec==0) { /* this node refers to its own texture tree! */ - copy_v4_v4(out, (fabs(co[0] - co[1]) < 0.01) ? white : red); + copy_v4_v4(out, (fabsf(co[0] - co[1]) < 0.01f) ? white : red); } else if (nodetex) { TexResult texres; diff --git a/source/blender/python/bmesh/bmesh_py_ops.c b/source/blender/python/bmesh/bmesh_py_ops.c index 53ddcecd7a8..9c871f14a68 100644 --- a/source/blender/python/bmesh/bmesh_py_ops.c +++ b/source/blender/python/bmesh/bmesh_py_ops.c @@ -109,7 +109,8 @@ static PyObject *pyrna_op_call(BPy_BMeshOpFunc *self, PyObject *args, PyObject * } /* TODO - error check this!, though we do the error check on attribute access */ - BMO_op_init(bm, &bmop, self->opname); + /* TODO - make flags optional */ + BMO_op_init(bm, &bmop, BMO_FLAG_DEFAULTS, self->opname); if (kw && PyDict_Size(kw) > 0) { /* setup properties, see bpy_rna.c: pyrna_py_to_prop() diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c index a82562d4445..2867cba8129 100644 --- a/source/blender/python/bmesh/bmesh_py_types.c +++ b/source/blender/python/bmesh/bmesh_py_types.c @@ -2083,6 +2083,199 @@ static PyObject *bpy_bmelemseq_index_update(BPy_BMElemSeq *self) Py_RETURN_NONE; } +PyDoc_STRVAR(bpy_bmelemseq_sort_doc, +".. method:: sort(key=None, reverse=False)\n" +"\n" +" Sort the elements of this sequence, using an optional custom sort key.\n" +" Indices of elements are not changed, BMElemeSeq.index_update() can be used for that.\n" +"\n" +" :arg key: The key that sets the ordering of the elements.\n" +" :type key: :function: returning a number\n" +" :arg reverse: Reverse the order of the elements\n" +" :type reverse: :boolean:\n" +"\n" +" .. note::\n" +"\n" +" When the 'key' argument is not provided, the elements are reordered following their current index value.\n" +" In particular this can be used by setting indices manually before calling this method.\n" +"\n" +); + +/* Use a static variable here because there is the need to sort some array + * doing comparisons on elements of another array, qsort_r would have been + * wonderful to use here, but unfortunately it is not standard and it's not + * portable across different platforms. + * + * If a portable alternative to qsort_r becomes available, remove this static + * var hack! + * + * Note: the functions below assumes the keys array has been allocated and it + * has enough elements to complete the task. + */ +static double *keys = NULL; + +static int bpy_bmelemseq_sort_cmp_by_keys_ascending(const void *index1_v, const void *index2_v) +{ + const int *index1 = (int *)index1_v; + const int *index2 = (int *)index2_v; + + if (keys[*index1] < keys[*index2]) return -1; + else if (keys[*index1] > keys[*index2]) return 1; + else return 0; +} + +static int bpy_bmelemseq_sort_cmp_by_keys_descending(const void *index1_v, const void *index2_v) +{ + return -bpy_bmelemseq_sort_cmp_by_keys_ascending(index1_v, index2_v); +} + +static PyObject *bpy_bmelemseq_sort(BPy_BMElemSeq *self, PyObject *args, PyObject *kw) +{ + static const char *kwlist[] = {"key", "reverse", NULL}; + PyObject *keyfunc = NULL; /* optional */ + int reverse = FALSE; /* optional */ + + const char htype = bm_iter_itype_htype_map[self->itype]; + int n_elem; + + BMIter iter; + BMElem *ele; + + int *elem_idx; + int *elem_map_idx; + int (*elem_idx_compare_by_keys)(const void *, const void *); + + int *vert_idx = NULL; + int *edge_idx = NULL; + int *face_idx = NULL; + int i; + + BMesh *bm = self->bm; + + BPY_BM_CHECK_OBJ(self); + + if (args != NULL) { + if(!PyArg_ParseTupleAndKeywords(args, kw, + "|Oi:BMElemSeq.sort", + (char **)kwlist, + &keyfunc, &reverse)) + return NULL; + } + + if (keyfunc != NULL && !PyCallable_Check(keyfunc)) { + PyErr_SetString(PyExc_TypeError, + "the 'key' argument is not a callable object"); + return NULL; + } + + n_elem = BM_mesh_elem_count(bm, htype); + if (n_elem <= 1) { + /* 0 or 1 elements: sorted already */ + Py_RETURN_NONE; + } + + keys = PyMem_MALLOC(sizeof(*keys) * n_elem); + if (keys == NULL) { + PyErr_NoMemory(); + return NULL; + } + + i = 0; + BM_ITER_BPY_BM_SEQ (ele, &iter, self) { + if (keyfunc != NULL) { + PyObject *py_elem; + PyObject *index; + + py_elem = BPy_BMElem_CreatePyObject(self->bm, (BMHeader *)ele); + index = PyObject_CallFunctionObjArgs(keyfunc, py_elem, NULL); + Py_DECREF(py_elem); + if (index == NULL) { + /* No need to set the exception here, + * PyObject_CallFunctionObjArgs() does that */ + PyMem_FREE(keys); + return NULL; + } + + if ((keys[i] = PyFloat_AsDouble(index)) == -1 && PyErr_Occurred()) { + PyErr_SetString(PyExc_ValueError, + "the value returned by the 'key' function is not a number"); + Py_DECREF(index); + PyMem_FREE(keys); + return NULL; + } + + Py_DECREF(index); + } + else { + /* If the 'key' function is not provided we sort + * according to the current index values */ + keys[i] = ele->head.index; + } + + i++; + } + + elem_idx = PyMem_MALLOC(sizeof(*elem_idx) * n_elem); + if (elem_idx == NULL) { + PyErr_NoMemory(); + PyMem_FREE(keys); + return NULL; + } + + /* Initialize the element index array */ + range_vn_i(elem_idx, n_elem, 0); + + /* Sort the index array according to the order of the 'keys' array */ + if (reverse) + elem_idx_compare_by_keys = bpy_bmelemseq_sort_cmp_by_keys_descending; + else + elem_idx_compare_by_keys = bpy_bmelemseq_sort_cmp_by_keys_ascending; + + qsort(elem_idx, n_elem, sizeof(*elem_idx), elem_idx_compare_by_keys); + + elem_map_idx = PyMem_MALLOC(sizeof(*elem_map_idx) * n_elem); + if (elem_map_idx == NULL) { + PyErr_NoMemory(); + PyMem_FREE(elem_idx); + PyMem_FREE(keys); + return NULL; + } + + /* Initialize the map array + * + * We need to know the index such that if used as the new_index in + * BM_mesh_remap() will give the order of the sorted keys like in + * elem_idx */ + for (i = 0; i < n_elem; i++) { + elem_map_idx[elem_idx[i]] = i; + } + + switch ((BMIterType)self->itype) { + case BM_VERTS_OF_MESH: + vert_idx = elem_map_idx; + break; + case BM_EDGES_OF_MESH: + edge_idx = elem_map_idx; + break; + case BM_FACES_OF_MESH: + face_idx = elem_map_idx; + break; + default: + PyErr_Format(PyExc_TypeError, "element type %d not supported", self->itype); + PyMem_FREE(elem_map_idx); + PyMem_FREE(elem_idx); + PyMem_FREE(keys); + return NULL; + } + + BM_mesh_remap(bm, vert_idx, edge_idx, face_idx); + + PyMem_FREE(elem_map_idx); + PyMem_FREE(elem_idx); + PyMem_FREE(keys); + + Py_RETURN_NONE; +} static struct PyMethodDef bpy_bmesh_methods[] = { /* utility */ @@ -2175,6 +2368,7 @@ static struct PyMethodDef bpy_bmvertseq_methods[] = { /* odd function, initializes index values */ {"index_update", (PyCFunction)bpy_bmelemseq_index_update, METH_NOARGS, bpy_bmelemseq_index_update_doc}, + {"sort", (PyCFunction)bpy_bmelemseq_sort, METH_VARARGS | METH_KEYWORDS, bpy_bmelemseq_sort_doc}, {NULL, NULL, 0, NULL} }; @@ -2186,6 +2380,7 @@ static struct PyMethodDef bpy_bmedgeseq_methods[] = { /* odd function, initializes index values */ {"index_update", (PyCFunction)bpy_bmelemseq_index_update, METH_NOARGS, bpy_bmelemseq_index_update_doc}, + {"sort", (PyCFunction)bpy_bmelemseq_sort, METH_VARARGS | METH_KEYWORDS, bpy_bmelemseq_sort_doc}, {NULL, NULL, 0, NULL} }; @@ -2197,12 +2392,14 @@ static struct PyMethodDef bpy_bmfaceseq_methods[] = { /* odd function, initializes index values */ {"index_update", (PyCFunction)bpy_bmelemseq_index_update, METH_NOARGS, bpy_bmelemseq_index_update_doc}, + {"sort", (PyCFunction)bpy_bmelemseq_sort, METH_VARARGS | METH_KEYWORDS, bpy_bmelemseq_sort_doc}, {NULL, NULL, 0, NULL} }; static struct PyMethodDef bpy_bmloopseq_methods[] = { /* odd function, initializes index values */ /* no: index_update() function since we cant iterate over loops */ + /* no: sort() function since we cant iterate over loops */ {NULL, NULL, 0, NULL} }; diff --git a/source/blender/python/generic/bpy_internal_import.c b/source/blender/python/generic/bpy_internal_import.c index d4158210cc8..b9ef4b056ad 100644 --- a/source/blender/python/generic/bpy_internal_import.c +++ b/source/blender/python/generic/bpy_internal_import.c @@ -157,7 +157,8 @@ PyObject *bpy_text_import_name(const char *name, int *found) } /* we know this cant be importable, the name is too long for blender! */ - if (namelen >= (MAX_ID_NAME - 2) - 3) return NULL; + if (namelen >= (MAX_ID_NAME - 2) - 3) + return NULL; memcpy(txtname, name, namelen); memcpy(&txtname[namelen], ".py", 4); diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 609c549dfcb..03e20322a59 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -6736,20 +6736,24 @@ static int rna_function_arg_count(FunctionRNA *func) return count; } -static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_function) +static int bpy_class_validate_recursive(PointerRNA *dummyptr, StructRNA *srna, void *py_data, int *have_function) { const ListBase *lb; Link *link; FunctionRNA *func; PropertyRNA *prop; - StructRNA *srna = dummyptr->type; const char *class_type = RNA_struct_identifier(srna); + StructRNA *srna_base = RNA_struct_base(srna); PyObject *py_class = (PyObject *)py_data; PyObject *base_class = RNA_struct_py_type_get(srna); PyObject *item; int i, flag, arg_count, func_arg_count; const char *py_class_name = ((PyTypeObject *)py_class)->tp_name; // __name__ + if (srna_base) { + if (bpy_class_validate_recursive(dummyptr, srna_base, py_data, have_function) != 0) + return -1; + } if (base_class) { if (!PyObject_IsSubclass(py_class, base_class)) { @@ -6884,6 +6888,11 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun return 0; } +static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_function) +{ + return bpy_class_validate_recursive(dummyptr, dummyptr->type, py_data, have_function); +} + /* TODO - multiple return values like with rna functions */ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, ParameterList *parms) { diff --git a/source/blender/python/mathutils/mathutils_Quaternion.c b/source/blender/python/mathutils/mathutils_Quaternion.c index 5ac1214409f..40c0215ffd1 100644 --- a/source/blender/python/mathutils/mathutils_Quaternion.c +++ b/source/blender/python/mathutils/mathutils_Quaternion.c @@ -1085,12 +1085,15 @@ static PyObject *Quaternion_new(PyTypeObject *type, PyObject *args, PyObject *kw return NULL; break; case 2: - if (mathutils_array_parse(quat, 3, 3, seq, "mathutils.Quaternion()") == -1) + { + float axis[3]; + if (mathutils_array_parse(axis, 3, 3, seq, "mathutils.Quaternion()") == -1) return NULL; angle = angle_wrap_rad(angle); /* clamp because of precision issues */ - axis_angle_to_quat(quat, quat, angle); + axis_angle_to_quat(quat, axis, angle); break; /* PyArg_ParseTuple assures no more then 2 */ + } } return Quaternion_CreatePyObject(quat, Py_NEW, type); } diff --git a/source/blender/render/extern/include/RE_pipeline.h b/source/blender/render/extern/include/RE_pipeline.h index d6bd49f5621..4695f2ba44f 100644 --- a/source/blender/render/extern/include/RE_pipeline.h +++ b/source/blender/render/extern/include/RE_pipeline.h @@ -153,7 +153,6 @@ typedef struct RenderStats { /* calling a new render with same name, frees automatic existing render */ struct Render *RE_NewRender (const char *name); struct Render *RE_GetRender(const char *name); -struct Render *RE_GetRender_FromData(const struct RenderData *rd); /* returns 1 while render is working (or renders called from within render) */ int RE_RenderInProgress(struct Render *re); diff --git a/source/blender/render/intern/raytrace/bvh.h b/source/blender/render/intern/raytrace/bvh.h index 9318e1758a6..a0d730c5b8a 100644 --- a/source/blender/render/intern/raytrace/bvh.h +++ b/source/blender/render/intern/raytrace/bvh.h @@ -88,8 +88,8 @@ static inline int rayobject_bb_intersect_test(const Isect *isec, const float *_b RE_RC_COUNT(isec->raycounter->bb.test); - if (t1x > t2y || t2x < t1y || t1x > t2z || t2x < t1z || t1y > t2z || t2y < t1z) return 0; - if (t2x < 0.0 || t2y < 0.0 || t2z < 0.0) return 0; + if (t1x > t2y || t2x < t1y || t1x > t2z || t2x < t1z || t1y > t2z || t2y < t1z) return 0; + if (t2x < 0.0f || t2y < 0.0f || t2z < 0.0f) return 0; if (t1x > isec->dist || t1y > isec->dist || t1z > isec->dist) return 0; RE_RC_COUNT(isec->raycounter->bb.hit); diff --git a/source/blender/render/intern/raytrace/rayobject_octree.cpp b/source/blender/render/intern/raytrace/rayobject_octree.cpp index 538c5493282..5ae716ac942 100644 --- a/source/blender/render/intern/raytrace/rayobject_octree.cpp +++ b/source/blender/render/intern/raytrace/rayobject_octree.cpp @@ -649,9 +649,9 @@ static void RE_rayobject_octree_done(RayObject *tree) t02 = oc->max[2] - oc->min[2]; /* this minus 0.1 is old safety... seems to be needed? */ - oc->ocfacx = (oc->ocres - 0.1) / t00; - oc->ocfacy = (oc->ocres - 0.1) / t01; - oc->ocfacz = (oc->ocres - 0.1) / t02; + oc->ocfacx = (oc->ocres - 0.1f) / t00; + oc->ocfacy = (oc->ocres - 0.1f) / t01; + oc->ocfacz = (oc->ocres - 0.1f) / t02; oc->ocsize = sqrt(t00 * t00 + t01 * t01 + t02 * t02); /* global, max size octree */ diff --git a/source/blender/render/intern/source/convertblender.c b/source/blender/render/intern/source/convertblender.c index 50b7e526cac..451f16fc6ee 100644 --- a/source/blender/render/intern/source/convertblender.c +++ b/source/blender/render/intern/source/convertblender.c @@ -2375,9 +2375,8 @@ static void displace_render_face(Render *re, ObjectRen *obr, VlakRen *vlr, float displace_render_vert(re, obr, &shi, vlr->v4, 3, scale, mat, imat); /* closest in displace value. This will help smooth edges. */ - if ( fabs(vlr->v1->accum - vlr->v3->accum) > fabs(vlr->v2->accum - vlr->v4->accum)) - vlr->flag |= R_DIVIDE_24; - else vlr->flag &= ~R_DIVIDE_24; + if (fabsf(vlr->v1->accum - vlr->v3->accum) > fabsf(vlr->v2->accum - vlr->v4->accum)) vlr->flag |= R_DIVIDE_24; + else vlr->flag &= ~R_DIVIDE_24; } /* Recalculate the face normal - if flipped before, flip now */ @@ -4303,8 +4302,8 @@ static void check_non_flat_quads(ObjectRen *obr) normal_tri_v3(nor, vlr->v2->co, vlr->v3->co, vlr->v4->co); d2 = dot_v3v3(nor, vlr->v2->n); - if ( fabs(d1) < fabs(d2) ) vlr->flag |= R_DIVIDE_24; - else vlr->flag &= ~R_DIVIDE_24; + if (fabsf(d1) < fabsf(d2) ) vlr->flag |= R_DIVIDE_24; + else vlr->flag &= ~R_DIVIDE_24; /* new vertex pointers */ if (vlr->flag & R_DIVIDE_24) { diff --git a/source/blender/render/intern/source/imagetexture.c b/source/blender/render/intern/source/imagetexture.c index 3e6d0f281fd..c4c89bd06a6 100644 --- a/source/blender/render/intern/source/imagetexture.c +++ b/source/blender/render/intern/source/imagetexture.c @@ -980,9 +980,9 @@ static void alpha_clip_aniso(ImBuf *ibuf, float minx, float miny, float maxx, fl rf.ymin = miny*(ibuf->y); rf.ymax = maxy*(ibuf->y); - alphaclip = clipx_rctf(&rf, 0.0, (float)(ibuf->x)); - alphaclip*= clipy_rctf(&rf, 0.0, (float)(ibuf->y)); - alphaclip= MAX2(alphaclip, 0.0f); + alphaclip = clipx_rctf(&rf, 0.0, (float)(ibuf->x)); + alphaclip *= clipy_rctf(&rf, 0.0, (float)(ibuf->y)); + alphaclip = maxf(alphaclip, 0.0f); if (alphaclip!=1.0f) { /* premul it all */ @@ -1236,8 +1236,8 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex float fProbes; a *= ff; b *= ff; - a = MAX2(a, 1.f); - b = MAX2(b, 1.f); + a = maxf(a, 1.0f); + b = maxf(b, 1.0f); fProbes = 2.f*(a / b) - 1.f; AFD.iProbes = (int)floorf(fProbes + 0.5f); AFD.iProbes = MIN2(AFD.iProbes, tex->afmax); @@ -1253,8 +1253,8 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex if (ecc > (float)tex->afmax) b = a / (float)tex->afmax; b *= ff; } - maxd = MAX2(b, 1e-8f); - levf = ((float)M_LOG2E)*logf(maxd); + maxd = maxf(b, 1e-8f); + levf = ((float)M_LOG2E) * logf(maxd); curmap = 0; maxlev = 1; @@ -1338,8 +1338,8 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex imp2radangle(A, B, C, F, &a, &b, &th, &ecc); a *= ff; b *= ff; - a = MAX2(a, 1.f); - b = MAX2(b, 1.f); + a = maxf(a, 1.0f); + b = maxf(b, 1.0f); fProbes = 2.f*(a / b) - 1.f; /* no limit to number of Probes here */ AFD.iProbes = (int)floorf(fProbes + 0.5f); @@ -1622,12 +1622,12 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const ImBuf *previbuf, *curibuf; float bumpscale; - dx= minx; - dy= miny; - maxd= MAX2(dx, dy); - if (maxd>0.5f) maxd= 0.5f; + dx = minx; + dy = miny; + maxd = maxf(dx, dy); + if (maxd > 0.5f) maxd = 0.5f; - pixsize = 1.0f/ (float) MIN2(ibuf->x, ibuf->y); + pixsize = 1.0f / (float) MIN2(ibuf->x, ibuf->y); bumpscale= pixsize/maxd; if (bumpscale>1.0f) bumpscale= 1.0f; diff --git a/source/blender/render/intern/source/pipeline.c b/source/blender/render/intern/source/pipeline.c index 701d21fbbd0..7b5a5054432 100644 --- a/source/blender/render/intern/source/pipeline.c +++ b/source/blender/render/intern/source/pipeline.c @@ -248,18 +248,6 @@ Render *RE_GetRender(const char *name) return re; } -Render *RE_GetRender_FromData(const RenderData *rd) -{ - Render *re; - - /* search for existing renders */ - for (re = RenderGlobal.renderlist.first; re; re = re->next) - if (&re->r == rd) - break; - - return re; -} - /* if you want to know exactly what has been done */ RenderResult *RE_AcquireResultRead(Render *re) { diff --git a/source/blender/render/intern/source/rayshade.c b/source/blender/render/intern/source/rayshade.c index cb7122c834c..aa35d73f3b5 100644 --- a/source/blender/render/intern/source/rayshade.c +++ b/source/blender/render/intern/source/rayshade.c @@ -1515,7 +1515,7 @@ void ray_trace(ShadeInput *shi, ShadeResult *shr) if (!(shi->combinedflag & SCE_PASS_REFRACT)) sub_v3_v3v3(diff, diff, shr->refr); - shr->alpha= MIN2(1.0f, tracol[3]); + shr->alpha = minf(1.0f, tracol[3]); } if (do_mir) { diff --git a/source/blender/render/intern/source/render_texture.c b/source/blender/render/intern/source/render_texture.c index 74e2c094850..e5bbb212def 100644 --- a/source/blender/render/intern/source/render_texture.c +++ b/source/blender/render/intern/source/render_texture.c @@ -791,9 +791,9 @@ static int cubemap(MTex *mtex, VlakRen *vlr, const float n[3], float x, float y, float nor[3]; normal_tri_v3(nor, vlr->v1->orco, vlr->v2->orco, vlr->v3->orco); - if ( fabs(nor[0])puno |= ME_PROJXY; - else if ( fabs(nor[0])puno |= ME_PROJXZ; - else vlr->puno |= ME_PROJYZ; + if (fabsf(nor[0]) < fabsf(nor[2]) && fabsf(nor[1]) < fabsf(nor[2])) vlr->puno |= ME_PROJXY; + else if (fabsf(nor[0]) < fabsf(nor[1]) && fabsf(nor[2]) < fabsf(nor[1])) vlr->puno |= ME_PROJXZ; + else vlr->puno |= ME_PROJYZ; } else return cubemap_glob(n, x, y, z, adr1, adr2); } @@ -1733,7 +1733,7 @@ static int compatible_bump_compute(CompatibleBump *compat_bump, ShadeInput *shi, if (mtex->texco == TEXCO_UV) { /* for the uv case, use the same value for both du/dv, * since individually scaling the normal derivatives makes them useless... */ - du = MIN2(du, dv); + du = minf(du, dv); idu = (du < 1e-5f) ? bf : (bf/du); /* +u val */ @@ -3636,7 +3636,7 @@ void RE_sample_material_color(Material *mat, float color[3], float *alpha, const float *uv1, *uv2, *uv3; float l; CustomData *data = &orcoDm->faceData; - MTFace *tface = (MTFace*) data->layers[layer_index+i].data; + MTFace *tface = (MTFace *) data->layers[layer_index+i].data; float uv[3]; /* point layer name from actual layer data */ shi.uv[i].name = data->layers[i].name; diff --git a/source/blender/render/intern/source/rendercore.c b/source/blender/render/intern/source/rendercore.c index 63aa6cdd139..a6b2c98f9d3 100644 --- a/source/blender/render/intern/source/rendercore.c +++ b/source/blender/render/intern/source/rendercore.c @@ -1541,8 +1541,7 @@ static void shade_sample_sss(ShadeSample *ssamp, Material *mat, ObjectInstanceRe copy_v3_v3(shi->facenor, nor); shade_input_set_viewco(shi, x, y, sx, sy, z); - *area= len_v3(shi->dxco)*len_v3(shi->dyco); - *area= MIN2(*area, 2.0f*orthoarea); + *area = minf(len_v3(shi->dxco) * len_v3(shi->dyco), 2.0f * orthoarea); shade_input_set_uv(shi); shade_input_set_normals(shi); diff --git a/source/blender/render/intern/source/renderdatabase.c b/source/blender/render/intern/source/renderdatabase.c index b12753543e9..db045284d5b 100644 --- a/source/blender/render/intern/source/renderdatabase.c +++ b/source/blender/render/intern/source/renderdatabase.c @@ -1309,11 +1309,11 @@ void project_renderdata(Render *re, void (*projectfunc)(const float *, float mat /* the Zd value is still not really correct for pano */ - vec[2]-= har->hasize; /* z negative, otherwise it's clipped */ + vec[2] -= har->hasize; /* z negative, otherwise it's clipped */ projectfunc(vec, re->winmat, hoco); - zn= hoco[3]; - zn= fabs( (float)har->zs - 0x7FFFFF*(hoco[2]/zn)); - har->zd= CLAMPIS(zn, 0, INT_MAX); + zn = hoco[3]; + zn = fabsf((float)har->zs - 0x7FFFFF * (hoco[2] / zn)); + har->zd = CLAMPIS(zn, 0, INT_MAX); } diff --git a/source/blender/render/intern/source/shadbuf.c b/source/blender/render/intern/source/shadbuf.c index 9995a3cbd17..4c90c3b4a6f 100644 --- a/source/blender/render/intern/source/shadbuf.c +++ b/source/blender/render/intern/source/shadbuf.c @@ -322,8 +322,8 @@ static void compress_deepshadowbuf(Render *re, ShadBuf *shb, APixstr *apixbuf, A shsample= MEM_callocN(sizeof(ShadSampleBuf), "shad sample buf"); BLI_addtail(&shb->buffers, shsample); - shsample->totbuf= MEM_callocN(sizeof(int)*size*size, "deeptotbuf"); - shsample->deepbuf= MEM_callocN(sizeof(DeepSample*)*size*size, "deepbuf"); + shsample->totbuf = MEM_callocN(sizeof(int) * size * size, "deeptotbuf"); + shsample->deepbuf = MEM_callocN(sizeof(DeepSample *) * size * size, "deepbuf"); ap= apixbuf; aps= apixbufstrand; @@ -1176,8 +1176,8 @@ float testshadowbuf(Render *re, ShadBuf *shb, const float co[3], const float dxc dy[0]= xs1 - dy[0]; dy[1]= ys1 - dy[1]; - xres= fac*(fabs(dx[0]) + fabs(dy[0])); - yres= fac*(fabs(dx[1]) + fabs(dy[1])); + xres = fac * (fabsf(dx[0]) + fabsf(dy[0])); + yres = fac * (fabsf(dx[1]) + fabsf(dy[1])); if (xres<1.0f) xres= 1.0f; if (yres<1.0f) yres= 1.0f; @@ -1391,7 +1391,7 @@ float shadow_halo(LampRen *lar, const float p1[3], const float p2[3]) } } - labda= MIN2(labdax, labday); + labda = minf(labdax, labday); if (labda==labdao || labda>=1.0f) break; zf= zf1 + labda*(zf2-zf1); diff --git a/source/blender/render/intern/source/sss.c b/source/blender/render/intern/source/sss.c index 46d52e83eda..69e738e840d 100644 --- a/source/blender/render/intern/source/sss.c +++ b/source/blender/render/intern/source/sss.c @@ -305,7 +305,7 @@ ScatterSettings *scatter_settings_new(float refl, float radius, float ior, float ss->Fdr= -1.440f/ior*ior + 0.710f/ior + 0.668f + 0.0636f*ior; ss->A= (1.0f + ss->Fdr)/(1.0f - ss->Fdr); ss->ld= radius; - ss->ro= MIN2(refl, 0.999f); + ss->ro= minf(refl, 0.999f); ss->color= ss->ro*reflfac + (1.0f-reflfac); ss->alpha_= compute_reduced_albedo(ss); @@ -747,8 +747,8 @@ ScatterTree *scatter_tree_new(ScatterSettings *ss[3], float scale, float error, tree->ss[1]= ss[1]; tree->ss[2]= ss[2]; - points= MEM_callocN(sizeof(ScatterPoint)*totpoint, "ScatterPoints"); - refpoints= MEM_callocN(sizeof(ScatterPoint*)*totpoint, "ScatterRefPoints"); + points = MEM_callocN(sizeof(ScatterPoint) * totpoint, "ScatterPoints"); + refpoints = MEM_callocN(sizeof(ScatterPoint *) * totpoint, "ScatterRefPoints"); tree->points= points; tree->refpoints= refpoints; @@ -777,8 +777,8 @@ void scatter_tree_build(ScatterTree *tree) float mid[3], size[3]; int totpoint= tree->totpoint; - newpoints= MEM_callocN(sizeof(ScatterPoint)*totpoint, "ScatterPoints"); - tmppoints= MEM_callocN(sizeof(ScatterPoint*)*totpoint, "ScatterTmpPoints"); + newpoints = MEM_callocN(sizeof(ScatterPoint) * totpoint, "ScatterPoints"); + tmppoints = MEM_callocN(sizeof(ScatterPoint *) * totpoint, "ScatterTmpPoints"); tree->tmppoints= tmppoints; tree->arena= BLI_memarena_new(0x8000 * sizeof(ScatterNode), "sss tree arena"); diff --git a/source/blender/render/intern/source/strand.c b/source/blender/render/intern/source/strand.c index 0e7c8a13043..51be519d5b8 100644 --- a/source/blender/render/intern/source/strand.c +++ b/source/blender/render/intern/source/strand.c @@ -577,8 +577,8 @@ static void do_strand_fillac(void *handle, int x, int y, float u, float v, float /* add to pixel list */ if (zverg < bufferz && (spart->totapixbuf[offset] < MAX_ZROW)) { if (!spart->rectmask || zverg > maskz) { - t = u*spart->t[0] + v*spart->t[1] + (1.0f-u-v)*spart->t[2]; - s = fabs(u*spart->s[0] + v*spart->s[1] + (1.0f-u-v)*spart->s[2]); + t = u * spart->t[0] + v * spart->t[1] + (1.0f - u - v) * spart->t[2]; + s = fabsf(u * spart->s[0] + v * spart->s[1] + (1.0f - u - v) * spart->s[2]); apn= spart->apixbuf + offset; while (apn) { diff --git a/source/blender/render/intern/source/zbuf.c b/source/blender/render/intern/source/zbuf.c index fde25865577..8d228473de7 100644 --- a/source/blender/render/intern/source/zbuf.c +++ b/source/blender/render/intern/source/zbuf.c @@ -149,8 +149,8 @@ static void zbuf_add_to_span(ZSpan *zspan, const float *v1, const float *v2) xs0= dx0*(minv[1]-my2) + minv[0]; } else { - dx0= 0.0f; - xs0= MIN2(minv[0], maxv[0]); + dx0 = 0.0f; + xs0 = minf(minv[0], maxv[0]); } /* empty span */ @@ -443,7 +443,7 @@ static void zbuflineAc(ZSpan *zspan, int obi, int zvlnr, const float vec1[3], co mask= zspan->mask; - if (fabs(dx) > fabs(dy)) { + if (fabsf(dx) > fabsf(dy)) { /* all lines from left to right */ if (vec1[0] fabs(dy)) { + if (fabsf(dx) > fabsf(dy)) { /* all lines from left to right */ if (vec1[0] fabs(dy)) { + if (fabsf(dx) > fabsf(dy)) { /* all lines from left to right */ if (vec1[0]combined, shr->combined); - samp_shr->z= MIN2(samp_shr->z, shr->z); + samp_shr->z = minf(samp_shr->z, shr->z); if (addpassflag & SCE_PASS_VECTOR) { copy_v4_v4(samp_shr->winspeed, shr->winspeed); diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 5011c785e90..60efc3b3541 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -310,15 +310,15 @@ int WM_jobs_test(struct wmWindowManager *wm, void *owner); float WM_jobs_progress(struct wmWindowManager *wm, void *owner); char *WM_jobs_name(struct wmWindowManager *wm, void *owner); -int WM_jobs_is_running(struct wmJob *); -void* WM_jobs_get_customdata(struct wmJob *); -void WM_jobs_customdata(struct wmJob *, void *customdata, void (*free)(void *)); -void WM_jobs_timer(struct wmJob *, double timestep, unsigned int note, unsigned int endnote); -void WM_jobs_callbacks(struct wmJob *, - void (*startjob)(void *, short *, short *, float *), - void (*initjob)(void *), - void (*update)(void *), - void (*endjob)(void *)); +int WM_jobs_is_running(struct wmJob *); +void * WM_jobs_get_customdata(struct wmJob *); +void WM_jobs_customdata(struct wmJob *, void *customdata, void (*free)(void *)); +void WM_jobs_timer(struct wmJob *, double timestep, unsigned int note, unsigned int endnote); +void WM_jobs_callbacks(struct wmJob *, + void (*startjob)(void *, short *, short *, float *), + void (*initjob)(void *), + void (*update)(void *), + void (*endjob)(void *)); void WM_jobs_start(struct wmWindowManager *wm, struct wmJob *); void WM_jobs_stop(struct wmWindowManager *wm, void *owner, void *startjob); diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 202a9d46f33..2c641b217a8 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -648,7 +648,8 @@ int WM_operator_repeat_check(const bContext *UNUSED(C), wmOperator *op) return op->type->exec != NULL; } -static wmOperator *wm_operator_create(wmWindowManager *wm, wmOperatorType *ot, PointerRNA *properties, ReportList *reports) +static wmOperator *wm_operator_create(wmWindowManager *wm, wmOperatorType *ot, + PointerRNA *properties, ReportList *reports) { /* XXX operatortype names are static still. for debug */ wmOperator *op = MEM_callocN(sizeof(wmOperator), ot->idname); @@ -824,7 +825,8 @@ int WM_operator_last_properties_store(wmOperator *UNUSED(op)) #endif -static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, PointerRNA *properties, ReportList *reports, short poll_only) +static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, + PointerRNA *properties, ReportList *reports, short poll_only) { wmWindowManager *wm = CTX_wm_manager(C); int retval = OPERATOR_PASS_THROUGH; @@ -843,7 +845,8 @@ static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, P } if ((G.debug & G_DEBUG_EVENTS) && event && event->type != MOUSEMOVE) { - printf("%s: handle evt %d win %d op %s\n", __func__, event ? event->type : 0, CTX_wm_screen(C)->subwinactive, ot->idname); + printf("%s: handle evt %d win %d op %s\n", + __func__, event ? event->type : 0, CTX_wm_screen(C)->subwinactive, ot->idname); } if (op->type->invoke && event) { @@ -1082,7 +1085,8 @@ int WM_operator_name_call(bContext *C, const char *opstring, short context, Poin * - poll() must be called by python before this runs. * - reports can be passed to this function (so python can report them as exceptions) */ -int WM_operator_call_py(bContext *C, wmOperatorType *ot, short context, PointerRNA *properties, ReportList *reports, short is_undo) +int WM_operator_call_py(bContext *C, wmOperatorType *ot, short context, + PointerRNA *properties, ReportList *reports, short is_undo) { int retval = OPERATOR_CANCELLED; @@ -1664,22 +1668,40 @@ static int wm_action_not_handled(int action) static int wm_handlers_do(bContext *C, wmEvent *event, ListBase *handlers) { +#ifndef NDEBUG + const int do_debug_handler = (G.debug & G_DEBUG_EVENTS); +#endif wmWindowManager *wm = CTX_wm_manager(C); wmEventHandler *handler, *nexthandler; int action = WM_HANDLER_CONTINUE; int always_pass; - if (handlers == NULL) return action; + if (handlers == NULL) { + return action; + } + +#ifndef NDEBUG + if (do_debug_handler) { + printf("%s: handling event\n", __func__); + WM_event_print(event); + } +#endif + + /* modal handlers can get removed in this loop, we keep the loop this way + * + * note: check 'handlers->first' because in rare cases the handlers can be cleared + * by the event thats called, for eg: + * + * Calling a python script which changes the area.type, see [#32232] */ + for (handler = handlers->first; handler && handlers->first; handler = nexthandler) { - /* modal handlers can get removed in this loop, we keep the loop this way */ - for (handler = handlers->first; handler; handler = nexthandler) { - nexthandler = handler->next; /* during this loop, ui handlers for nested menus can tag multiple handlers free */ - if (handler->flag & WM_HANDLER_DO_FREE) ; - /* optional boundbox */ - else if (handler_boundbox_test(handler, event)) { + if (handler->flag & WM_HANDLER_DO_FREE) { + /* pass */ + } + else if (handler_boundbox_test(handler, event)) { /* optional boundbox */ /* in advance to avoid access to freed event on window close */ always_pass = wm_event_always_pass(event); @@ -1690,20 +1712,60 @@ static int wm_handlers_do(bContext *C, wmEvent *event, ListBase *handlers) if (handler->keymap) { wmKeyMap *keymap = WM_keymap_active(wm, handler->keymap); wmKeyMapItem *kmi; - + +#ifndef NDEBUG + if (do_debug_handler) { + printf("%s: checking '%s' ...", __func__, keymap->idname); + } +#endif + if (!keymap->poll || keymap->poll(C)) { + +#ifndef NDEBUG + if (do_debug_handler) { + printf("pass\n"); + } +#endif + for (kmi = keymap->items.first; kmi; kmi = kmi->next) { if (wm_eventmatch(event, kmi)) { +#ifndef NDEBUG + if (do_debug_handler) { + printf("%s: item matched '%s'\n", __func__, kmi->idname); + } +#endif + /* weak, but allows interactive callback to not use rawkey */ event->keymap_idname = kmi->idname; action |= wm_handler_operator_call(C, handlers, handler, event, kmi->ptr); - if (action & WM_HANDLER_BREAK) /* not always_pass here, it denotes removed handler */ + if (action & WM_HANDLER_BREAK) { + /* not always_pass here, it denotes removed handler */ +#ifndef NDEBUG + if (do_debug_handler) { + printf("%s: handled! '%s'...", __func__, kmi->idname); + } +#endif break; + } + else { +#ifndef NDEBUG + if (do_debug_handler) { + printf("%s: un-handled '%s'...", __func__, kmi->idname); + } +#endif + } } } } + else { +#ifndef NDEBUG + if (do_debug_handler) { + printf("fail\n"); + } +#endif + } } else if (handler->ui_handle) { action |= wm_handler_ui_call(C, handler, event, always_pass); @@ -1965,7 +2027,9 @@ void wm_event_do_handlers(bContext *C) CTX_wm_screen_set(C, win->screen); CTX_data_scene_set(C, scene); - if (((playing == 1) && (!ED_screen_animation_playing(wm))) || ((playing == 0) && (ED_screen_animation_playing(wm)))) { + if (((playing == 1) && (!ED_screen_animation_playing(wm))) || + ((playing == 0) && (ED_screen_animation_playing(wm)))) + { ED_screen_animation_play(C, -1, 1); } diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index e51625423cd..04035598a89 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -77,6 +77,7 @@ #include "BKE_global.h" #include "BKE_library.h" #include "BKE_main.h" +#include "BKE_multires.h" #include "BKE_packedFile.h" #include "BKE_report.h" #include "BKE_sound.h" @@ -933,6 +934,7 @@ void wm_autosave_timer(const bContext *C, wmWindowManager *wm, wmTimer *UNUSED(w wmEventHandler *handler; char filepath[FILE_MAX]; int fileflags; + Scene *scene = CTX_data_scene(C); WM_event_remove_timer(wm, NULL, wm->autosavetimer); @@ -945,7 +947,14 @@ void wm_autosave_timer(const bContext *C, wmWindowManager *wm, wmTimer *UNUSED(w } } } - + + if (scene) { + Object *ob = OBACT; + + if (ob && ob->mode & OB_MODE_SCULPT) + multires_force_update(ob); + } + wm_autosave_location(filepath); /* force save as regular blend file */ diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index 7a885d60bff..5bf6c34cfb3 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -32,6 +32,10 @@ #include #include +#if WIN32 +#include +#endif + #include "MEM_guardedalloc.h" #include "MEM_CacheLimiterC-Api.h" @@ -62,6 +66,7 @@ #include "BKE_tracking.h" /* free tracking clipboard */ #include "BLI_listbase.h" +#include "BLI_math_color.h" #include "BLI_string.h" #include "BLI_utildefines.h" @@ -137,10 +142,14 @@ void WM_init(bContext *C, int argc, const char **argv) ED_spacetypes_init(); /* editors/space_api/spacetype.c */ ED_file_init(); /* for fsmenu */ - ED_init_node_butfuncs(); + ED_node_init_butfuncs(); BLF_init(11, U.dpi); /* Please update source/gamengine/GamePlayer/GPG_ghost.cpp if you change this */ BLF_lang_init(); + + /* initialize color stuff */ + BLI_init_srgb_conversion(); + /* get the default database, plus a wm */ WM_read_homefile(C, NULL, G.factory_startup); @@ -330,6 +339,29 @@ extern void free_anim_drivers_copybuf(void); extern void free_fmodifiers_copybuf(void); extern void free_posebuf(void); +#if WIN32 +/* Read console events until there is a key event. Also returns on any error. */ +static void wait_for_console_key(void) +{ + HANDLE hConsoleInput = GetStdHandle(STD_INPUT_HANDLE); + + if (!ELEM(hConsoleInput, NULL, INVALID_HANDLE_VALUE) && FlushConsoleInputBuffer(hConsoleInput)) { + for(;;) { + INPUT_RECORD buffer; + DWORD ignored; + + if (!ReadConsoleInput(hConsoleInput, &buffer, 1, &ignored)) { + break; + } + + if (buffer.EventType == KEY_EVENT) { + break; + } + } + } +} +#endif + /* called in creator.c even... tsk, split this! */ /* note, doesnt run exit() call WM_exit() for that */ void WM_exit_ext(bContext *C, const short do_python) @@ -452,10 +484,10 @@ void WM_exit_ext(bContext *C, const short do_python) printf("\nBlender quit\n"); #ifdef WIN32 - /* ask user to press enter when in debug mode */ + /* ask user to press a key when in debug mode */ if (G.debug & G_DEBUG) { - printf("press enter key to exit...\n\n"); - getchar(); + printf("Press any key to exit . . .\n\n"); + wait_for_console_key(); } #endif } diff --git a/source/blenderplayer/bad_level_call_stubs/stubs.c b/source/blenderplayer/bad_level_call_stubs/stubs.c index beff41b2d55..ad9470b7590 100644 --- a/source/blenderplayer/bad_level_call_stubs/stubs.c +++ b/source/blenderplayer/bad_level_call_stubs/stubs.c @@ -66,6 +66,7 @@ struct LOD_Decimation_Info; struct MCol; struct MTex; struct Main; +struct Mask; struct Material; struct MenuType; struct Mesh; @@ -232,6 +233,7 @@ void ED_space_image_uv_sculpt_update(struct wmWindowManager *wm, struct ToolSett void ED_screen_set_scene(struct bContext *C, struct Scene *scene) {} void ED_space_clip_set_clip(struct bContext *C, struct SpaceClip *sc, struct MovieClip *clip) {} void ED_space_clip_set_mask(struct bContext *C, struct SpaceClip *sc, struct Mask *mask) {} +void ED_space_image_set_mask(struct bContext *C, struct SpaceImage *sima, struct Mask *mask) {} void ED_area_tag_redraw_regiontype(struct ScrArea *sa, int regiontype) {} void ED_render_engine_changed(struct Main *bmain) {} @@ -274,7 +276,7 @@ short ANIM_add_driver(struct ID *id, const char rna_path[], int array_index, sho short ANIM_remove_driver(struct ID *id, const char rna_path[], int array_index, short flag) {return 0;} void ED_space_image_release_buffer(struct SpaceImage *sima, void *lock) {} struct ImBuf *ED_space_image_acquire_buffer(struct SpaceImage *sima, void **lock_r) {return (struct ImBuf *) NULL;} -void ED_space_image_zoom(struct SpaceImage *sima, struct ARegion *ar, float *zoomx, float *zoomy) {} +void ED_space_image_get_zoom(struct SpaceImage *sima, struct ARegion *ar, float *zoomx, float *zoomy) {} char *ED_info_stats_string(struct Scene *scene) {return (char *) NULL;} void ED_area_tag_redraw(struct ScrArea *sa) {} void ED_area_tag_refresh(struct ScrArea *sa) {} @@ -348,7 +350,8 @@ intptr_t mesh_octree_table(struct Object *ob, struct BMEditMesh *em, float *co, void ED_sequencer_update_view(struct bContext *C, int view) {} float ED_rollBoneToVector(struct EditBone *bone, float new_up_axis[3]) {return 0.0f;} -void ED_space_image_size(struct SpaceImage *sima, int *width, int *height) {} +void ED_space_image_get_size(struct SpaceImage *sima, int *width, int *height) {} +int ED_space_image_check_show_maskedit(struct Scene *scene, struct SpaceImage *sima) {return 0;}; void ED_nurb_set_spline_type(struct Nurb *nu, int type) {} diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp index 8e2ff06a55c..cef068ccbaa 100644 --- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp +++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp @@ -520,7 +520,7 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *c PyObject *gameLogic_keys_new = PyDict_Keys(PyModule_GetDict(gameLogic)); const Py_ssize_t numitems= PyList_GET_SIZE(gameLogic_keys_new); Py_ssize_t listIndex; - for (listIndex=0; listIndex < numitems; listIndex++) { + for (listIndex=0; listIndex < numitems; listIndex++) { PyObject* item = PyList_GET_ITEM(gameLogic_keys_new, listIndex); if (!PySequence_Contains(gameLogic_keys, item)) { PyDict_DelItem( PyModule_GetDict(gameLogic), item); diff --git a/source/gameengine/Converter/BL_ActionActuator.cpp b/source/gameengine/Converter/BL_ActionActuator.cpp index cab6d0fc376..92d04115f10 100644 --- a/source/gameengine/Converter/BL_ActionActuator.cpp +++ b/source/gameengine/Converter/BL_ActionActuator.cpp @@ -145,7 +145,6 @@ void BL_ActionActuator::SetLocalTime(float curtime) case ACT_ACTION_PLAY: // Clamp m_localtime = m_endframe; - ((KX_GameObject*)GetParent())->StopAction(m_layer); break; case ACT_ACTION_LOOP_END: // Put the time back to the beginning @@ -339,7 +338,7 @@ bool BL_ActionActuator::Update(double curtime, bool frame) } } - return m_flag & ACT_FLAG_ATTEMPT_PLAY; + return m_flag & ACT_FLAG_ACTIVE; } #ifdef WITH_PYTHON diff --git a/source/gameengine/Converter/BL_MeshDeformer.h b/source/gameengine/Converter/BL_MeshDeformer.h index c73e4efd245..c84d31c72cd 100644 --- a/source/gameengine/Converter/BL_MeshDeformer.h +++ b/source/gameengine/Converter/BL_MeshDeformer.h @@ -63,16 +63,16 @@ public: m_lastDeformUpdate(-1) {}; virtual ~BL_MeshDeformer(); - virtual void SetSimulatedTime(double time){} + virtual void SetSimulatedTime(double time) {} virtual bool Apply(class RAS_IPolyMaterial *mat); - virtual bool Update(void){ return false; } - virtual bool UpdateBuckets(void){ return false; } - virtual RAS_Deformer* GetReplica(){return NULL;} + virtual bool Update(void) { return false; } + virtual bool UpdateBuckets(void) { return false; } + virtual RAS_Deformer* GetReplica() {return NULL;} virtual void ProcessReplica(); struct Mesh* GetMesh() { return m_bmesh; } virtual class RAS_MeshObject* GetRasMesh() { return (RAS_MeshObject*)m_pMeshObject; } virtual float (* GetTransVerts(int *tot))[3] { *tot= m_tvtot; return m_transverts; } - // virtual void InitDeform(double time){} + // virtual void InitDeform(double time) {} protected: class RAS_MeshObject* m_pMeshObject; diff --git a/source/gameengine/Converter/BL_SkinDeformer.cpp b/source/gameengine/Converter/BL_SkinDeformer.cpp index 9bbf07a3ed2..47cba81798d 100644 --- a/source/gameengine/Converter/BL_SkinDeformer.cpp +++ b/source/gameengine/Converter/BL_SkinDeformer.cpp @@ -238,6 +238,7 @@ void BL_SkinDeformer::BGEDeformVerts() MDeformVert *dverts = m_bmesh->dvert; bDeformGroup *dg; int defbase_tot = BLI_countlist(&m_objMesh->defbase); + Eigen::Matrix4f pre_mat, post_mat, chan_mat, norm_chan_mat; if (!dverts) return; @@ -257,15 +258,18 @@ void BL_SkinDeformer::BGEDeformVerts() } } + post_mat = Eigen::Matrix4f::Map((float*)m_obmat).inverse() * Eigen::Matrix4f::Map((float*)m_armobj->GetArmatureObject()->obmat); + pre_mat = post_mat.inverse(); + MDeformVert *dv= dverts; + MDeformWeight *dw; for (int i=0; itotvert; ++i, dv++) { - float contrib = 0.f, weight, max_weight=0.f; + float contrib = 0.f, weight, max_weight=-1.f; bPoseChannel *pchan=NULL; - Eigen::Map norm(m_transnors[i]); + Eigen::Map norm = Eigen::Vector3f::Map(m_transnors[i]); Eigen::Vector4f vec(0, 0, 0, 1); - Eigen::Matrix4f norm_chan_mat; Eigen::Vector4f co(m_transverts[i][0], m_transverts[i][1], m_transverts[i][2], @@ -274,7 +278,9 @@ void BL_SkinDeformer::BGEDeformVerts() if (!dv->totweight) continue; - MDeformWeight *dw= dv->dw; + co = pre_mat * co; + + dw= dv->dw; for (unsigned int j= dv->totweight; j != 0; j--, dw++) { @@ -286,12 +292,10 @@ void BL_SkinDeformer::BGEDeformVerts() if (weight) { - Eigen::Vector4f cop(co); - Eigen::Matrix4f chan_mat = Eigen::Matrix4f::Map((float*)pchan->chan_mat); + chan_mat = Eigen::Matrix4f::Map((float*)pchan->chan_mat); // Update Vertex Position - cop = chan_mat*cop; - vec += (cop - co)*weight; + vec.noalias() += (chan_mat*co - co)*weight; // Save the most influential channel so we can use it to update the vertex normal if (weight > max_weight) @@ -304,16 +308,14 @@ void BL_SkinDeformer::BGEDeformVerts() } } } - // Update Vertex Normal norm = norm_chan_mat.topLeftCorner<3, 3>()*norm; - - if (contrib > 0.0001f) - { - vec *= 1.f/contrib; - co += vec; - } + + co.noalias() += vec/contrib; + co[3] = 1.f; // Make sure we have a 1 for the w component! + + co = post_mat * co; m_transverts[i][0] = co[0]; m_transverts[i][1] = co[1]; diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp index 3961e6554a7..1c3352454a2 100644 --- a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp +++ b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp @@ -988,8 +988,7 @@ bool KX_BlenderSceneConverter::LinkBlendFile(BlendHandle *bpy_openlib, const cha load_datablocks(main_newlib, bpy_openlib, path, idcode); - if (idcode==ID_SCE) { - /* assume we want text blocks too */ + if (idcode==ID_SCE && options & LIB_LOAD_LOAD_SCRIPTS) { load_datablocks(main_newlib, bpy_openlib, path, ID_TXT); } @@ -1044,9 +1043,11 @@ bool KX_BlenderSceneConverter::LinkBlendFile(BlendHandle *bpy_openlib, const cha delete other; } +#ifdef WITH_PYTHON /* Handle any text datablocks */ - - addImportMain(main_newlib); + if (options & LIB_LOAD_LOAD_SCRIPTS) + addImportMain(main_newlib); +#endif /* Now handle all the actions */ if (options & LIB_LOAD_LOAD_ACTIONS) { @@ -1340,8 +1341,11 @@ bool KX_BlenderSceneConverter::FreeBlendFile(struct Main *maggie) } } - /* make sure this maggie is removed from the import list if it's there (this operation is safe if it isn't in the list) */ +#ifdef WITH_PYTHON + /* make sure this maggie is removed from the import list if it's there + * (this operation is safe if it isn't in the list) */ removeImportMain(maggie); +#endif free_main(maggie); diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.h b/source/gameengine/Converter/KX_BlenderSceneConverter.h index 906e3fed111..b51c2f21ca7 100644 --- a/source/gameengine/Converter/KX_BlenderSceneConverter.h +++ b/source/gameengine/Converter/KX_BlenderSceneConverter.h @@ -182,6 +182,7 @@ public: { LIB_LOAD_LOAD_ACTIONS = 1, LIB_LOAD_VERBOSE = 2, + LIB_LOAD_LOAD_SCRIPTS = 4, }; diff --git a/source/gameengine/Expressions/ListValue.h b/source/gameengine/Expressions/ListValue.h index 83f8232ca5e..4d104a4bd3a 100644 --- a/source/gameengine/Expressions/ListValue.h +++ b/source/gameengine/Expressions/ListValue.h @@ -57,7 +57,7 @@ public: void Remove(int i); void Resize(int num); void SetValue(int i,CValue* val); - CValue* GetValue(int i){ assertd(i < m_pValueArray.size()); return m_pValueArray[i];} + CValue* GetValue(int i) { assertd(i < m_pValueArray.size()); return m_pValueArray[i]; } int GetCount() { return m_pValueArray.size(); } virtual const STR_String & GetText(); diff --git a/source/gameengine/Expressions/VoidValue.h b/source/gameengine/Expressions/VoidValue.h index 5599b226a60..a1a82f8aa65 100644 --- a/source/gameengine/Expressions/VoidValue.h +++ b/source/gameengine/Expressions/VoidValue.h @@ -45,12 +45,19 @@ class CVoidValue : public CPropValue public: /// Construction/destruction - CVoidValue() : m_bDeleteOnDestruct(false), m_pAnything(NULL) { } - CVoidValue(void * voidptr, bool bDeleteOnDestruct, AllocationTYPE alloctype) : m_bDeleteOnDestruct(bDeleteOnDestruct), m_pAnything(voidptr) { if (alloctype == STACKVALUE) CValue::DisableRefCount(); } - virtual ~CVoidValue(); // Destruct void value, delete memory if we're owning it + CVoidValue() : m_bDeleteOnDestruct(false), m_pAnything(NULL) { } + CVoidValue(void * voidptr, bool bDeleteOnDestruct, AllocationTYPE alloctype) : + m_bDeleteOnDestruct(bDeleteOnDestruct), + m_pAnything(voidptr) + { + if (alloctype == STACKVALUE) { + CValue::DisableRefCount(); + } + } + virtual ~CVoidValue(); /* Destruct void value, delete memory if we're owning it */ /// Value -> String or number - virtual const STR_String & GetText(); // Get string description of void value (unimplemented) + virtual const STR_String & GetText(); /* Get string description of void value (unimplemented) */ virtual double GetNumber() { return -1; } /// Value calculation @@ -70,5 +77,5 @@ public: #endif }; -#endif // !defined _VOIDVALUE_H +#endif /* __VOIDVALUE_H__ */ diff --git a/source/gameengine/GameLogic/SCA_IObject.cpp b/source/gameengine/GameLogic/SCA_IObject.cpp index 5077ecaf816..b90952b2092 100644 --- a/source/gameengine/GameLogic/SCA_IObject.cpp +++ b/source/gameengine/GameLogic/SCA_IObject.cpp @@ -251,7 +251,7 @@ SCA_IActuator* SCA_IObject::FindActuator(const STR_String& actuatorname) void SCA_IObject::Suspend() { if ((!m_ignore_activity_culling) - && (!m_suspended)) { + && (!m_suspended)) { m_suspended = true; /* flag suspend for all sensors */ SCA_SensorList::iterator i = m_sensors.begin(); diff --git a/source/gameengine/GamePlayer/common/GPC_Canvas.h b/source/gameengine/GamePlayer/common/GPC_Canvas.h index 0e26c5ad729..25a50fbcac3 100644 --- a/source/gameengine/GamePlayer/common/GPC_Canvas.h +++ b/source/gameengine/GamePlayer/common/GPC_Canvas.h @@ -103,7 +103,7 @@ public: void Resize(int width, int height); - virtual void ResizeWindow(int width, int height){}; + virtual void ResizeWindow(int width, int height) {} /** * \section Methods inherited from abstract base class RAS_ICanvas. diff --git a/source/gameengine/Ketsji/BL_Texture.cpp b/source/gameengine/Ketsji/BL_Texture.cpp index f2d67e9131d..e4e3fb95543 100644 --- a/source/gameengine/Ketsji/BL_Texture.cpp +++ b/source/gameengine/Ketsji/BL_Texture.cpp @@ -29,6 +29,7 @@ #include "MEM_guardedalloc.h" #include "GPU_draw.h" +#include "GPU_extensions.h" extern "C" { // envmaps @@ -116,6 +117,7 @@ bool BL_Texture::InitFromImage(int unit, Image *img, bool mipmap) return mOk; } + mipmap = mipmap && GPU_get_mipmap(); mTexture = img->bindcode; mType = GL_TEXTURE_2D; @@ -169,7 +171,7 @@ bool BL_Texture::InitFromImage(int unit, Image *img, bool mipmap) void BL_Texture::InitGLTex(unsigned int *pix,int x,int y,bool mipmap) { - if (!GLEW_ARB_texture_non_power_of_two && (!is_power_of_2_i(x) || !is_power_of_2_i(y)) ) { + if (!GPU_non_power_of_two_support() && (!is_power_of_2_i(x) || !is_power_of_2_i(y)) ) { InitNonPow2Tex(pix, x,y,mipmap); return; } @@ -182,7 +184,7 @@ void BL_Texture::InitGLTex(unsigned int *pix,int x,int y,bool mipmap) } else { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, pix ); } diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp index 014c68e8bee..b28b8c86d33 100644 --- a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp +++ b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp @@ -884,7 +884,7 @@ KX_PYMETHODDEF_DOC( KX_BlenderMaterial, getShader , "getShader()") Py_RETURN_NONE; } - if (!GLEW_ARB_shader_objects) { + if (!GLEW_ARB_shader_objects) { if (!mModified) spit("GLSL not supported"); mModified = true; diff --git a/source/gameengine/Ketsji/KX_CameraActuator.cpp b/source/gameengine/Ketsji/KX_CameraActuator.cpp index e009478c803..4c63afa7f3e 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.cpp +++ b/source/gameengine/Ketsji/KX_CameraActuator.cpp @@ -33,6 +33,7 @@ * \ingroup ketsji */ +#include "BLI_math_vector.h" #include "KX_CameraActuator.h" #include @@ -42,7 +43,6 @@ #include "PyObjectPlus.h" - /* ------------------------------------------------------------------------- */ /* Native functions */ /* ------------------------------------------------------------------------- */ @@ -113,34 +113,7 @@ void KX_CameraActuator::Relink(CTR_Map *obj_map) } } -/* three functions copied from blender arith... don't know if there's an equivalent */ - -static float Kx_Normalize(float *n) -{ - float d; - - d= n[0]*n[0]+n[1]*n[1]+n[2]*n[2]; - /* FLT_EPSILON is too large! A larger value causes normalize errors in a scaled down utah teapot */ - if (d>0.0000000000001) { - d= sqrt(d); - - n[0]/=d; - n[1]/=d; - n[2]/=d; - } else { - n[0]=n[1]=n[2]= 0.0; - d= 0.0; - } - return d; -} - -static void Kx_Crossf(float *c, float *a, float *b) -{ - c[0] = a[1] * b[2] - a[2] * b[1]; - c[1] = a[2] * b[0] - a[0] * b[2]; - c[2] = a[0] * b[1] - a[1] * b[0]; -} - +/* copied from blender BLI_math ... don't know if there's an equivalent */ static void Kx_VecUpMat3(float vec[3], float mat[][3], short axis) { @@ -184,7 +157,7 @@ static void Kx_VecUpMat3(float vec[3], float mat[][3], short axis) mat[coz][0]= vec[0]; mat[coz][1]= vec[1]; mat[coz][2]= vec[2]; - if (Kx_Normalize((float *)mat[coz]) == 0.f) { + if (normalize_v3((float *)mat[coz]) == 0.f) { /* this is a very abnormal situation: the camera has reach the object center exactly * We will choose a completely arbitrary direction */ mat[coz][0] = 1.0f; @@ -197,15 +170,14 @@ static void Kx_VecUpMat3(float vec[3], float mat[][3], short axis) mat[coy][1] = - inp * mat[coz][1]; mat[coy][2] = 1.0f - inp * mat[coz][2]; - if (Kx_Normalize((float *)mat[coy]) == 0.f) { + if (normalize_v3((float *)mat[coy]) == 0.f) { /* the camera is vertical, chose the y axis arbitrary */ mat[coy][0] = 0.f; mat[coy][1] = 1.f; mat[coy][2] = 0.f; } - Kx_Crossf(mat[cox], mat[coy], mat[coz]); - + cross_v3_v3v3(mat[cox], mat[coy], mat[coz]); } bool KX_CameraActuator::Update(double curtime, bool frame) diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index c5145ef2171..496b3925456 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -1162,8 +1162,8 @@ void KX_GameObject::NodeSetWorldScale(const MT_Vector3& scale) { // Make sure the objects have some scale MT_Vector3 p_scale = parent->GetWorldScaling(); - if (fabs(p_scale[0]) < FLT_EPSILON || - fabs(p_scale[1]) < FLT_EPSILON || + if (fabs(p_scale[0]) < FLT_EPSILON || + fabs(p_scale[1]) < FLT_EPSILON || fabs(p_scale[2]) < FLT_EPSILON) { return; @@ -1190,8 +1190,8 @@ void KX_GameObject::NodeSetWorldPosition(const MT_Point3& trans) { // Make sure the objects have some scale MT_Vector3 scale = parent->GetWorldScaling(); - if (fabs(scale[0]) < FLT_EPSILON || - fabs(scale[1]) < FLT_EPSILON || + if (fabs(scale[0]) < FLT_EPSILON || + fabs(scale[1]) < FLT_EPSILON || fabs(scale[2]) < FLT_EPSILON) { return; @@ -1203,7 +1203,7 @@ void KX_GameObject::NodeSetWorldPosition(const MT_Point3& trans) MT_Vector3 newpos = invori*(trans-parent->GetWorldPosition())*scale; NodeSetLocalPosition(MT_Point3(newpos[0],newpos[1],newpos[2])); } - else + else { NodeSetLocalPosition(trans); } @@ -1291,8 +1291,7 @@ void KX_GameObject::Resume(void) void KX_GameObject::Suspend() { - if ((!m_ignore_activity_culling) - && (!m_suspended)) { + if ((!m_ignore_activity_culling) && (!m_suspended)) { SCA_IObject::Suspend(); if (GetPhysicsController()) GetPhysicsController()->SuspendDynamics(); diff --git a/source/gameengine/Ketsji/KX_IpoActuator.cpp b/source/gameengine/Ketsji/KX_IpoActuator.cpp index 7e7e7f8cef2..5599f3e31c6 100644 --- a/source/gameengine/Ketsji/KX_IpoActuator.cpp +++ b/source/gameengine/Ketsji/KX_IpoActuator.cpp @@ -379,7 +379,7 @@ bool KX_IpoActuator::Update(double curtime, bool frame) void KX_IpoActuator::ResetStartTime() { - this->m_starttime = -2.0*fabs(this->m_endframe - this->m_startframe) - 1.0; + this->m_starttime = -2.0f * fabsf(this->m_endframe - this->m_startframe) - 1.0f; } int KX_IpoActuator::string2mode(const char *modename) diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index 21c3198b8f9..a560b606f5b 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -503,6 +503,8 @@ bool KX_KetsjiEngine::BeginFrame() void KX_KetsjiEngine::EndFrame() { + m_rendertools->MotionBlur(m_rasterizer); + // Show profiling info m_logger->StartLog(tc_overhead, m_kxsystem->GetTimeInSeconds(), true); if (m_show_framerate || m_show_profile || (m_show_debug_properties && m_propertiesPresent)) @@ -782,21 +784,21 @@ else // Handle the animations independently of the logic time step if (GetRestrictAnimationFPS()) { - m_logger->StartLog(tc_animations, m_kxsystem->GetTimeInSeconds(), true); + double clocktime = m_kxsystem->GetTimeInSeconds(); + m_logger->StartLog(tc_animations, clocktime, true); SG_SetActiveStage(SG_STAGE_ANIMATION_UPDATE); double anim_timestep = 1.0/KX_GetActiveScene()->GetAnimationFPS(); - if (m_clockTime - m_previousAnimTime > anim_timestep) + if (clocktime - m_previousAnimTime > anim_timestep) { // Sanity/debug print to make sure we're actually going at the fps we want (should be close to anim_timestep) // printf("Anim fps: %f\n", 1.0/(m_clockTime - m_previousAnimTime)); - m_previousAnimTime = m_clockTime; + m_previousAnimTime = clocktime; for (sceneit = m_scenes.begin();sceneit != m_scenes.end(); ++sceneit) { - (*sceneit)->UpdateAnimations(m_frameTime); + (*sceneit)->UpdateAnimations(clocktime); } } - m_previousClockTime = m_clockTime; } // Start logging time spend outside main loop @@ -1344,7 +1346,6 @@ void KX_KetsjiEngine::PostRenderScene(KX_Scene* scene) m_canvas->SetViewPort(0, 0, m_canvas->GetWidth(), m_canvas->GetHeight()); m_rasterizer->FlushDebugShapes(); - m_rendertools->MotionBlur(m_rasterizer); scene->Render2DFilters(m_canvas); #ifdef WITH_PYTHON scene->RunDrawingCallbacks(scene->GetPostDrawCB()); diff --git a/source/gameengine/Ketsji/KX_Light.cpp b/source/gameengine/Ketsji/KX_Light.cpp index 5922e97aaf4..f5aa1bb3c75 100644 --- a/source/gameengine/Ketsji/KX_Light.cpp +++ b/source/gameengine/Ketsji/KX_Light.cpp @@ -29,11 +29,12 @@ * \ingroup ketsji */ - #if defined(WIN32) && !defined(FREE_WINDOWS) #pragma warning (disable : 4786) #endif +#include + #include "GL/glew.h" #include "KX_Light.h" @@ -67,10 +68,13 @@ KX_LightObject::KX_LightObject(void* sgReplicationInfo,SG_Callbacks callbacks, KX_LightObject::~KX_LightObject() { GPULamp *lamp; + Lamp *la = (Lamp*)GetBlenderObject()->data; if ((lamp = GetGPULamp())) { float obmat[4][4] = {{0}}; GPU_lamp_update(lamp, 0, 0, obmat); + GPU_lamp_update_distance(lamp, la->dist, la->att1, la->att2); + GPU_lamp_update_spot(lamp, la->spotsize, la->spotblend); } m_rendertools->RemoveLight(&m_lightobj); @@ -145,11 +149,12 @@ bool KX_LightObject::ApplyLight(KX_Scene *kxscene, int oblayer, int slot) //vec[1]= -base->object->obmat[2][1]; //vec[2]= -base->object->obmat[2][2]; glLightfv((GLenum)(GL_LIGHT0+slot), GL_SPOT_DIRECTION, vec); - glLightf((GLenum)(GL_LIGHT0+slot), GL_SPOT_CUTOFF, m_lightobj.m_spotsize/2.0); - glLightf((GLenum)(GL_LIGHT0+slot), GL_SPOT_EXPONENT, 128.0*m_lightobj.m_spotblend); + glLightf((GLenum)(GL_LIGHT0+slot), GL_SPOT_CUTOFF, m_lightobj.m_spotsize / 2.0f); + glLightf((GLenum)(GL_LIGHT0+slot), GL_SPOT_EXPONENT, 128.0f * m_lightobj.m_spotblend); } - else + else { glLightf((GLenum)(GL_LIGHT0+slot), GL_SPOT_CUTOFF, 180.0); + } } if (m_lightobj.m_nodiffuse) { @@ -206,6 +211,8 @@ void KX_LightObject::Update() GPU_lamp_update(lamp, m_lightobj.m_layer, 0, obmat); GPU_lamp_update_colors(lamp, m_lightobj.m_red, m_lightobj.m_green, m_lightobj.m_blue, m_lightobj.m_energy); + GPU_lamp_update_distance(lamp, m_lightobj.m_distance, m_lightobj.m_att1, m_lightobj.m_att2); + GPU_lamp_update_spot(lamp, m_lightobj.m_spotsize, m_lightobj.m_spotblend); } } diff --git a/source/gameengine/Ketsji/KX_PyMath.h b/source/gameengine/Ketsji/KX_PyMath.h index 8924567acde..aec871d7700 100644 --- a/source/gameengine/Ketsji/KX_PyMath.h +++ b/source/gameengine/Ketsji/KX_PyMath.h @@ -138,9 +138,9 @@ bool PyVecTo(PyObject* pyval, T& vec) #ifdef USE_MATHUTILS /* no need for BaseMath_ReadCallback() here, reading the sequences will do this */ - if(VectorObject_Check(pyval)) { + if (VectorObject_Check(pyval)) { VectorObject *pyvec= (VectorObject *)pyval; - if(BaseMath_ReadCallback(pyvec) == -1) { + if (BaseMath_ReadCallback(pyvec) == -1) { return false; /* exception raised */ } if (pyvec->size != Size(vec)) { @@ -150,9 +150,9 @@ bool PyVecTo(PyObject* pyval, T& vec) vec.setValue((float *) pyvec->vec); return true; } - else if(QuaternionObject_Check(pyval)) { + else if (QuaternionObject_Check(pyval)) { QuaternionObject *pyquat= (QuaternionObject *)pyval; - if(BaseMath_ReadCallback(pyquat) == -1) { + if (BaseMath_ReadCallback(pyquat) == -1) { return false; /* exception raised */ } if (4 != Size(vec)) { @@ -163,9 +163,9 @@ bool PyVecTo(PyObject* pyval, T& vec) vec.setValue((float *) pyquat->quat); return true; } - else if(EulerObject_Check(pyval)) { + else if (EulerObject_Check(pyval)) { EulerObject *pyeul= (EulerObject *)pyval; - if(BaseMath_ReadCallback(pyeul) == -1) { + if (BaseMath_ReadCallback(pyeul) == -1) { return false; /* exception raised */ } if (3 != Size(vec)) { @@ -174,10 +174,10 @@ bool PyVecTo(PyObject* pyval, T& vec) } vec.setValue((float *) pyeul->eul); return true; - } else + } + else #endif - if(PyTuple_Check(pyval)) - { + if (PyTuple_Check(pyval)) { unsigned int numitems = PyTuple_GET_SIZE(pyval); if (numitems != Size(vec)) { PyErr_Format(PyExc_AttributeError, "error setting vector, %d args, should be %d", numitems, Size(vec)); @@ -194,8 +194,8 @@ bool PyVecTo(PyObject* pyval, T& vec) return true; } - else if (PyObject_TypeCheck(pyval, (PyTypeObject *)&PyObjectPlus::Type)) - { /* note, include this check because PySequence_Check does too much introspection + else if (PyObject_TypeCheck(pyval, (PyTypeObject *)&PyObjectPlus::Type)) { + /* note, include this check because PySequence_Check does too much introspection * on the PyObject (like getting its __class__, on a BGE type this means searching up * the parent list each time only to discover its not a sequence. * GameObjects are often used as an alternative to vectors so this is a common case @@ -207,16 +207,14 @@ bool PyVecTo(PyObject* pyval, T& vec) PyErr_Format(PyExc_AttributeError, "expected a sequence type"); return false; } - else if (PySequence_Check(pyval)) - { + else if (PySequence_Check(pyval)) { unsigned int numitems = PySequence_Size(pyval); if (numitems != Size(vec)) { PyErr_Format(PyExc_AttributeError, "error setting vector, %d args, should be %d", numitems, Size(vec)); return false; } - for (unsigned int x = 0; x < numitems; x++) - { + for (unsigned int x = 0; x < numitems; x++) { PyObject *item = PySequence_GetItem(pyval, x); /* new ref */ vec[x] = PyFloat_AsDouble(item); Py_DECREF(item); @@ -228,8 +226,8 @@ bool PyVecTo(PyObject* pyval, T& vec) } return true; - } else - { + } + else { PyErr_Format(PyExc_AttributeError, "not a sequence type, expected a sequence of numbers size %d", Size(vec)); } diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 823363dfd11..536b32cbd77 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -676,12 +676,12 @@ static PyObject *gLibLoad(PyObject*, PyObject* args, PyObject* kwds) char *err_str= NULL; short options=0; - int load_actions=0, verbose=0; + int load_actions=0, verbose=0, load_scripts=1; - static const char *kwlist[] = {"path", "group", "buffer", "load_actions", "verbose", NULL}; + static const char *kwlist[] = {"path", "group", "buffer", "load_actions", "verbose", "load_scripts", NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "ss|y*ii:LibLoad", const_cast(kwlist), - &path, &group, &py_buffer, &load_actions, &verbose)) + if (!PyArg_ParseTupleAndKeywords(args, kwds, "ss|y*iii:LibLoad", const_cast(kwlist), + &path, &group, &py_buffer, &load_actions, &verbose, &load_scripts)) return NULL; /* setup options */ @@ -689,6 +689,8 @@ static PyObject *gLibLoad(PyObject*, PyObject* args, PyObject* kwds) options |= KX_BlenderSceneConverter::LIB_LOAD_LOAD_ACTIONS; if (verbose != 0) options |= KX_BlenderSceneConverter::LIB_LOAD_VERBOSE; + if (load_scripts != 0) + options |= KX_BlenderSceneConverter::LIB_LOAD_LOAD_SCRIPTS; if (!py_buffer.buf) { diff --git a/source/gameengine/Ketsji/KX_RadarSensor.h b/source/gameengine/Ketsji/KX_RadarSensor.h index f1ed5b3c982..2de58f8b3a0 100644 --- a/source/gameengine/Ketsji/KX_RadarSensor.h +++ b/source/gameengine/Ketsji/KX_RadarSensor.h @@ -90,10 +90,11 @@ public: KX_RADAR_AXIS_NEG_Z }; - /* python */ virtual sensortype GetSensorType() { return ST_RADAR; } - + /* python */ +#ifdef WITH_PYTHON static PyObject* pyattr_get_angle(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); +#endif }; #endif //__KX_RADARSENSOR_H__ diff --git a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp index 35c791e427d..f408b2cd7c9 100644 --- a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp @@ -27,7 +27,7 @@ /** \file gameengine/Ketsji/KX_SCA_DynamicActuator.cpp * \ingroup ketsji - * Adjust dynamics settins for this object + * Adjust dynamics settings for this object */ /* Previously existed as: diff --git a/source/gameengine/Ketsji/KX_Scene.h b/source/gameengine/Ketsji/KX_Scene.h index 7e3378bd13f..f8480753395 100644 --- a/source/gameengine/Ketsji/KX_Scene.h +++ b/source/gameengine/Ketsji/KX_Scene.h @@ -309,8 +309,8 @@ public: RAS_BucketManager* GetBucketManager(); RAS_MaterialBucket* FindBucket(RAS_IPolyMaterial* polymat, bool &bucketCreated); void RenderBuckets(const MT_Transform& cameratransform, - RAS_IRasterizer* rasty, - RAS_IRenderTools* rendertools); + RAS_IRasterizer* rasty, + RAS_IRenderTools* rendertools); /** * Update all transforms according to the scenegraph. @@ -325,18 +325,18 @@ public: m_groupGameObjects.find(gameobj) != m_groupGameObjects.end()); } SCA_IObject* AddReplicaObject(CValue* gameobj, - CValue* locationobj, - int lifespan=0); + CValue* locationobj, + int lifespan=0); KX_GameObject* AddNodeReplicaObject(SG_IObject* node, - CValue* gameobj); + CValue* gameobj); void RemoveNodeDestructObject(SG_IObject* node, - CValue* gameobj); + CValue* gameobj); void RemoveObject(CValue* gameobj); void DelayedRemoveObject(CValue* gameobj); int NewRemoveObject(CValue* gameobj); void ReplaceMesh(CValue* gameobj, - void* meshob, bool use_gfx, bool use_phys); + void* meshob, bool use_gfx, bool use_phys); void AddAnimatedObject(CValue* gameobj); void RemoveAnimatedObject(CValue* gameobj); diff --git a/source/gameengine/Ketsji/KX_WorldInfo.h b/source/gameengine/Ketsji/KX_WorldInfo.h index e4a73873fa1..5b35ca2ec54 100644 --- a/source/gameengine/Ketsji/KX_WorldInfo.h +++ b/source/gameengine/Ketsji/KX_WorldInfo.h @@ -43,7 +43,7 @@ class MT_CmMatrix4x4; class KX_WorldInfo { public: - KX_WorldInfo(){} + KX_WorldInfo() {} virtual ~KX_WorldInfo(); virtual bool hasWorld()=0; diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp index 0a105ee1c1a..ed2b9cfcb0b 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp @@ -632,6 +632,8 @@ CcdPhysicsController::~CcdPhysicsController() delete m_MotionState; if (m_bulletMotionState) delete m_bulletMotionState; + if (m_characterController) + delete m_characterController; delete m_object; DeleteControllerShape(); @@ -836,6 +838,11 @@ void CcdPhysicsController::SetPhysicsEnvironment(class PHY_IPhysicsEnvironment * if (m_cci.m_physicsEnv->removeCcdPhysicsController(this)) { physicsEnv->addCcdPhysicsController(this); + + // Set the object to be active so it can at least by evaluated once. + // This fixes issues with static objects not having their physics meshes + // in the right spot when lib loading. + this->GetCollisionObject()->setActivationState(ACTIVE_TAG); } m_cci.m_physicsEnv = physicsEnv; } diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index 3b49607ff1b..79898cdc0d4 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -830,16 +830,16 @@ void CcdPhysicsEnvironment::setCcdMode(int ccdMode) void CcdPhysicsEnvironment::setSolverSorConstant(float sor) { - m_solverInfo.m_sor = sor; + m_dynamicsWorld->getSolverInfo().m_sor = sor; } void CcdPhysicsEnvironment::setSolverTau(float tau) { - m_solverInfo.m_tau = tau; + m_dynamicsWorld->getSolverInfo().m_tau = tau; } void CcdPhysicsEnvironment::setSolverDamping(float damping) { - m_solverInfo.m_damping = damping; + m_dynamicsWorld->getSolverInfo().m_damping = damping; } diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h index 8d9c770b8c3..c499a1ef75c 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h @@ -83,8 +83,6 @@ protected: int m_profileTimings; bool m_enableSatCollisionDetection; - btContactSolverInfo m_solverInfo; - void processFhSprings(double curTime,float timeStep); public: diff --git a/source/gameengine/Physics/common/PHY_DynamicTypes.h b/source/gameengine/Physics/common/PHY_DynamicTypes.h index a72929d25c5..69bbc7745e0 100644 --- a/source/gameengine/Physics/common/PHY_DynamicTypes.h +++ b/source/gameengine/Physics/common/PHY_DynamicTypes.h @@ -96,18 +96,18 @@ enum PHY_NUM_RESPONSE }; - typedef struct PHY_CollData { - PHY__Vector3 m_point1; /* Point in object1 in world coordinates */ - PHY__Vector3 m_point2; /* Point in object2 in world coordinates */ - PHY__Vector3 m_normal; /* point2 - point1 */ - } PHY_CollData; +typedef struct PHY_CollData { + PHY__Vector3 m_point1; /* Point in object1 in world coordinates */ + PHY__Vector3 m_point2; /* Point in object2 in world coordinates */ + PHY__Vector3 m_normal; /* point2 - point1 */ +} PHY_CollData; - typedef bool (*PHY_ResponseCallback)(void *client_data, - void *client_object1, - void *client_object2, - const PHY_CollData *coll_data); - typedef void (*PHY_CullingCallback)(KX_ClientObjectInfo* info, void* param); +typedef bool (*PHY_ResponseCallback)(void *client_data, + void *client_object1, + void *client_object2, + const PHY_CollData *coll_data); +typedef void (*PHY_CullingCallback)(KX_ClientObjectInfo* info, void* param); /// PHY_PhysicsType enumerates all possible Physics Entities. diff --git a/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h b/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h index 8fde9e289dc..30d63e6695d 100644 --- a/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h +++ b/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h @@ -107,7 +107,7 @@ class PHY_IPhysicsEnvironment /// Perform an integration step of duration 'timeStep'. virtual bool proceedDeltaTime(double curTime,float timeStep,float interval)=0; ///draw debug lines (make sure to call this during the render phase, otherwise lines are not drawn properly) - virtual void debugDrawWorld(){} + virtual void debugDrawWorld() {} virtual void setFixedTimeStep(bool useFixedTimeStep,float fixedTimeStep)=0; //returns 0.f if no fixed timestep is used virtual float getFixedTimeStep()=0; @@ -117,7 +117,7 @@ class PHY_IPhysicsEnvironment ///setNumIterations set the number of iterations for iterative solvers virtual void setNumIterations(int numIter) {} ///setNumTimeSubSteps set the number of divisions of the timestep. Tradeoff quality versus performance. - virtual void setNumTimeSubSteps(int numTimeSubSteps){} + virtual void setNumTimeSubSteps(int numTimeSubSteps) {} ///setDeactivationTime sets the minimum time that an objects has to stay within the velocity tresholds until it gets fully deactivated virtual void setDeactivationTime(float dTime) {} ///setDeactivationLinearTreshold sets the linear velocity treshold, see setDeactivationTime @@ -150,7 +150,7 @@ class PHY_IPhysicsEnvironment float axis2X=0,float axis2Y=0,float axis2Z=0,int flag=0 )=0; virtual void removeConstraint(int constraintid)=0; - virtual float getAppliedImpulse(int constraintid){ return 0.f;} + virtual float getAppliedImpulse(int constraintid) { return 0.0f; } //complex constraint for vehicles diff --git a/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp b/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp index 097c2a9c824..92c390efd39 100644 --- a/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp +++ b/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp @@ -52,7 +52,6 @@ RAS_2DFilterManager::RAS_2DFilterManager(): texturewidth(-1), textureheight(-1), -canvaswidth(-1), canvasheight(-1), /* numberoffilters(0), */ /* UNUSED */ need_tex_update(true) { isshadersupported = GLEW_ARB_shader_objects && @@ -404,7 +403,7 @@ void RAS_2DFilterManager::RenderFilters(RAS_ICanvas* canvas) RAS_Rect rect = canvas->GetWindowArea(); int rect_width = rect.GetWidth()+1, rect_height = rect.GetHeight()+1; - if (canvaswidth != canvas->GetWidth() || canvasheight != canvas->GetHeight()) + if (texturewidth != rect_width || textureheight != rect_height) { UpdateOffsetMatrix(canvas); UpdateCanvasTextureCoord((unsigned int*)viewport); diff --git a/source/gameengine/Rasterizer/RAS_2DFilterManager.h b/source/gameengine/Rasterizer/RAS_2DFilterManager.h index 93d143dd3ce..ba74018d36b 100644 --- a/source/gameengine/Rasterizer/RAS_2DFilterManager.h +++ b/source/gameengine/Rasterizer/RAS_2DFilterManager.h @@ -62,8 +62,6 @@ private: unsigned int texname[3]; int texturewidth; int textureheight; - int canvaswidth; - int canvasheight; /* int numberoffilters; */ /* UNUSED */ /* bit 0: enable/disable depth texture * bit 1: enable/disable luminance texture*/ diff --git a/source/gameengine/Rasterizer/RAS_Deformer.h b/source/gameengine/Rasterizer/RAS_Deformer.h index 627db2b63fb..51c4da3c49d 100644 --- a/source/gameengine/Rasterizer/RAS_Deformer.h +++ b/source/gameengine/Rasterizer/RAS_Deformer.h @@ -49,8 +49,8 @@ class RAS_MeshObject; class RAS_Deformer { public: - RAS_Deformer() : m_pMesh(NULL), m_bDynamic(false) {}; - virtual ~RAS_Deformer(){}; + RAS_Deformer() : m_pMesh(NULL), m_bDynamic(false) {} + virtual ~RAS_Deformer() {} virtual void Relink(CTR_Map*map)=0; virtual bool Apply(class RAS_IPolyMaterial *polymat)=0; virtual bool Update(void)=0; diff --git a/source/gameengine/Rasterizer/RAS_FramingManager.h b/source/gameengine/Rasterizer/RAS_FramingManager.h index 6312f83737e..dd640bc6839 100644 --- a/source/gameengine/Rasterizer/RAS_FramingManager.h +++ b/source/gameengine/Rasterizer/RAS_FramingManager.h @@ -289,7 +289,7 @@ private : /** * Private constructor - this class is not meant - * for instanciation. + * for instantiation. */ RAS_FramingManager( diff --git a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h b/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h index 0f89af490d8..169bc6e4ee6 100644 --- a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h +++ b/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h @@ -174,7 +174,7 @@ public: virtual bool UsesObjectColor() const; virtual bool CastsShadows() const; - virtual void Replace_IScene(SCA_IScene *val) {}; /* overridden by KX_BlenderMaterial */ + virtual void Replace_IScene(SCA_IScene *val) {} /* overridden by KX_BlenderMaterial */ /** * \return the equivalent drawing mode for the material settings (equivalent to old TexFace tface->mode). @@ -184,7 +184,7 @@ public: /* * PreCalculate texture gen */ - virtual void OnConstruction(int layer){} + virtual void OnConstruction(int layer) {} #ifdef WITH_CXX_GUARDEDALLOC diff --git a/source/gameengine/Rasterizer/RAS_IRasterizer.h b/source/gameengine/Rasterizer/RAS_IRasterizer.h index d4c19410eb1..7749c4af9d6 100644 --- a/source/gameengine/Rasterizer/RAS_IRasterizer.h +++ b/source/gameengine/Rasterizer/RAS_IRasterizer.h @@ -64,8 +64,8 @@ typedef vector< KX_IndexArray* > vecIndexArrays; class RAS_IRasterizer { public: - RAS_IRasterizer(RAS_ICanvas* canv){}; - virtual ~RAS_IRasterizer(){}; + RAS_IRasterizer(RAS_ICanvas* canv) {}; + virtual ~RAS_IRasterizer() {}; /** * Drawing types @@ -401,8 +401,8 @@ public: virtual const MT_Matrix4x4& GetViewMatrix() const = 0; virtual const MT_Matrix4x4& GetViewInvMatrix() const = 0; - virtual bool QueryLists(){return false;} - virtual bool QueryArrays(){return false;} + virtual bool QueryLists() { return false; } + virtual bool QueryArrays() { return false; } virtual void EnableMotionBlur(float motionblurvalue)=0; virtual void DisableMotionBlur()=0; diff --git a/source/gameengine/Rasterizer/RAS_IRenderTools.h b/source/gameengine/Rasterizer/RAS_IRenderTools.h index 5d3efb8c38a..c02bc5e7a44 100644 --- a/source/gameengine/Rasterizer/RAS_IRenderTools.h +++ b/source/gameengine/Rasterizer/RAS_IRenderTools.h @@ -113,14 +113,14 @@ public: */ virtual void - RenderText3D(int fontid, - const char* text, - int size, - int dpi, - float* color, - double* mat, - float aspect - ) = 0; + RenderText3D(int fontid, + const char* text, + int size, + int dpi, + float* color, + double* mat, + float aspect + ) = 0; /** diff --git a/source/gameengine/Rasterizer/RAS_MaterialBucket.h b/source/gameengine/Rasterizer/RAS_MaterialBucket.h index 7cf7fee7845..295f2510313 100644 --- a/source/gameengine/Rasterizer/RAS_MaterialBucket.h +++ b/source/gameengine/Rasterizer/RAS_MaterialBucket.h @@ -54,7 +54,7 @@ class KX_ListSlot protected: int m_refcount; public: - KX_ListSlot(){ m_refcount=1; } + KX_ListSlot() { m_refcount = 1; } virtual ~KX_ListSlot() {} virtual int Release() { if (--m_refcount > 0) diff --git a/source/gameengine/Rasterizer/RAS_MeshObject.h b/source/gameengine/Rasterizer/RAS_MeshObject.h index 326110bea57..eb8655c8b1f 100644 --- a/source/gameengine/Rasterizer/RAS_MeshObject.h +++ b/source/gameengine/Rasterizer/RAS_MeshObject.h @@ -106,7 +106,7 @@ public: /* modification state */ bool MeshModified(); - void SetMeshModified(bool v){m_bMeshModified = v;} + void SetMeshModified(bool v) { m_bMeshModified = v; } /* original blender mesh */ Mesh* GetMesh() { return m_mesh; } diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h index 808c4f11dd8..a8eb2d5ffdf 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h @@ -72,7 +72,7 @@ public: virtual void SetDrawingMode(int drawingmode); - virtual bool QueryLists(){return true;} + virtual bool QueryLists() {return true;} #ifdef WITH_CXX_GUARDEDALLOC diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp index 7db433b5b4f..76d1a64a4c0 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp @@ -533,10 +533,10 @@ void RAS_OpenGLRasterizer::SetEye(const StereoEye eye) glDrawBuffer(m_curreye == RAS_STEREO_LEFTEYE ? GL_BACK_LEFT : GL_BACK_RIGHT); break; case RAS_STEREO_ANAGLYPH: - if (m_curreye == RAS_STEREO_LEFTEYE) - { + if (m_curreye == RAS_STEREO_LEFTEYE) { glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_FALSE); - } else { + } + else { //glAccum(GL_LOAD, 1.0); glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE); ClearDepthBuffer(); @@ -892,7 +892,8 @@ void RAS_OpenGLRasterizer::IndexPrimitivesInternal(RAS_MeshSlot& ms, bool multi) int current_blend_mode = GPU_get_material_alpha_blend(); ms.m_pDerivedMesh->drawFacesGLSL(ms.m_pDerivedMesh, CheckMaterialDM); GPU_set_material_alpha_blend(current_blend_mode); - } else { + } + else { //ms.m_pDerivedMesh->drawMappedFacesTex(ms.m_pDerivedMesh, CheckTexfaceDM, mcol); current_blmat_nr = current_polymat->GetMaterialIndex(); current_image = current_polymat->GetBlenderImage(); diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h index 36f768f6474..e5eba249175 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h @@ -302,9 +302,9 @@ public: virtual int GetMotionBlurState() { return m_motionblur; } virtual void SetMotionBlurState(int newstate) { - if(newstate<0) + if (newstate < 0) m_motionblur = 0; - else if(newstate>2) + else if (newstate > 2) m_motionblur = 2; else m_motionblur = newstate; diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_VAOpenGLRasterizer.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_VAOpenGLRasterizer.h index deda1c4603a..e881192171f 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_VAOpenGLRasterizer.h +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_VAOpenGLRasterizer.h @@ -58,8 +58,8 @@ public: private: virtual void EnableTextures(bool enable); - //virtual bool QueryArrays(){return true;} - //virtual bool QueryLists(){return m_Lock;} + //virtual bool QueryArrays() {return true;} + //virtual bool QueryLists() {return m_Lock;} #ifdef WITH_CXX_GUARDEDALLOC diff --git a/source/gameengine/SceneGraph/SG_BBox.cpp b/source/gameengine/SceneGraph/SG_BBox.cpp index 4b2fc5410fa..3911babd2b5 100644 --- a/source/gameengine/SceneGraph/SG_BBox.cpp +++ b/source/gameengine/SceneGraph/SG_BBox.cpp @@ -217,7 +217,8 @@ void SG_BBox::split(SG_BBox &left, SG_BBox &right) const right.m_min[2] = m_min[2]; right.m_max = m_max; std::cout << "splity" << std::endl; - } else { + } + else { left.m_min = m_min; left.m_max[0] = m_max[0]; left.m_max[1] = m_max[1]; @@ -229,9 +230,9 @@ void SG_BBox::split(SG_BBox &left, SG_BBox &right) const right.m_max = m_max; std::cout << "splitz" << std::endl; } - } else { - if (sizex > sizez) - { + } + else { + if (sizex > sizez) { left.m_min = m_min; left.m_max[0] = m_min[0] + sizex/2.0; left.m_max[1] = m_max[1]; @@ -242,7 +243,8 @@ void SG_BBox::split(SG_BBox &left, SG_BBox &right) const right.m_min[2] = m_min[2]; right.m_max = m_max; std::cout << "splitx" << std::endl; - } else { + } + else { left.m_min = m_min; left.m_max[0] = m_max[0]; left.m_max[1] = m_max[1]; diff --git a/source/gameengine/SceneGraph/SG_Spatial.cpp b/source/gameengine/SceneGraph/SG_Spatial.cpp index e026419ca67..f8c4b5165ee 100644 --- a/source/gameengine/SceneGraph/SG_Spatial.cpp +++ b/source/gameengine/SceneGraph/SG_Spatial.cpp @@ -151,10 +151,12 @@ RelativeTranslate( ) { if (local) { m_localPosition += m_localRotation * trans; - } else { + } + else { if (parent) { m_localPosition += trans * parent->GetWorldOrientation(); - } else { + } + else { m_localPosition += trans; } } diff --git a/source/gameengine/SceneGraph/SG_Tree.cpp b/source/gameengine/SceneGraph/SG_Tree.cpp index 738c0fdef22..0f8264985de 100644 --- a/source/gameengine/SceneGraph/SG_Tree.cpp +++ b/source/gameengine/SceneGraph/SG_Tree.cpp @@ -296,7 +296,8 @@ SG_Tree* SG_TreeFactory::MakeTreeDown(SG_BBox &bbox) { lefttree.Add(*it); hasleft++; - } else { + } + else { righttree.Add(*it); hasright++; } diff --git a/source/gameengine/VideoTexture/ImageBase.cpp b/source/gameengine/VideoTexture/ImageBase.cpp index 090b4f6ff4a..54c1939ce6b 100644 --- a/source/gameengine/VideoTexture/ImageBase.cpp +++ b/source/gameengine/VideoTexture/ImageBase.cpp @@ -246,7 +246,8 @@ bool ImageBase::checkSourceSizes (void) // set current size as reference refSize = curSize; // otherwise check with current size - } else if (curSize[0] != refSize[0] || curSize[1] != refSize[1]) { + } + else if (curSize[0] != refSize[0] || curSize[1] != refSize[1]) { // if they don't match, report it return false; } diff --git a/source/gameengine/VideoTexture/ImageRender.cpp b/source/gameengine/VideoTexture/ImageRender.cpp index 97e52e3af3d..9fdd0cd393b 100644 --- a/source/gameengine/VideoTexture/ImageRender.cpp +++ b/source/gameengine/VideoTexture/ImageRender.cpp @@ -208,11 +208,11 @@ void ImageRender::Render() frustrum.x1, frustrum.x2, frustrum.y1, frustrum.y2, frustrum.camnear, frustrum.camfar); m_camera->SetProjectionMatrix(projmat); - } else if (m_camera->hasValidProjectionMatrix()) - { + } + else if (m_camera->hasValidProjectionMatrix()) { m_rasterizer->SetProjectionMatrix(m_camera->GetProjectionMatrix()); - } else - { + } + else { float lens = m_camera->GetLens(); float sensor_x = m_camera->GetSensorWidth(); float sensor_y = m_camera->GetSensorHeight(); @@ -241,8 +241,8 @@ void ImageRender::Render() projmat = m_rasterizer->GetOrthoMatrix( frustrum.x1, frustrum.x2, frustrum.y1, frustrum.y2, frustrum.camnear, frustrum.camfar); - } else - { + } + else { RAS_FramingManager::ComputeDefaultFrustum( nearfrust, farfrust, @@ -604,13 +604,12 @@ ImageRender::ImageRender (KX_Scene * scene, KX_GameObject * observer, KX_GameObj mirrorVerts.push_back(v1); mirrorVerts.push_back(v2); mirrorVerts.push_back(v3); - if (polygon->VertexCount() == 4) - { + if (polygon->VertexCount() == 4) { v4 = polygon->GetVertex(3); mirrorVerts.push_back(v4); area = normal_quad_v3(normal,(float*)v1->getXYZ(), (float*)v2->getXYZ(), (float*)v3->getXYZ(), (float*)v4->getXYZ()); - } else - { + } + else { area = normal_tri_v3(normal,(float*)v1->getXYZ(), (float*)v2->getXYZ(), (float*)v3->getXYZ()); } area = fabs(area); @@ -637,8 +636,8 @@ ImageRender::ImageRender (KX_Scene * scene, KX_GameObject * observer, KX_GameObj // otherwise the Y axis is the up direction. // If the mirror is not perfectly vertical(horizontal), the Z(Y) axis projection on the mirror // plan by the normal will be the up direction. - if (fabs(mirrorNormal[2]) > fabs(mirrorNormal[1]) && - fabs(mirrorNormal[2]) > fabs(mirrorNormal[0])) + if (fabsf(mirrorNormal[2]) > fabsf(mirrorNormal[1]) && + fabsf(mirrorNormal[2]) > fabsf(mirrorNormal[0])) { // the mirror is more horizontal than vertical copy_v3_v3(axis, yaxis); @@ -649,7 +648,7 @@ ImageRender::ImageRender (KX_Scene * scene, KX_GameObject * observer, KX_GameObj copy_v3_v3(axis, zaxis); } dist = dot_v3v3(mirrorNormal, axis); - if (fabs(dist) < FLT_EPSILON) + if (fabsf(dist) < FLT_EPSILON) { // the mirror is already fully aligned with up axis copy_v3_v3(mirrorUp, axis); diff --git a/source/gameengine/VideoTexture/SConscript b/source/gameengine/VideoTexture/SConscript index 1e3f232a919..e66284948ed 100644 --- a/source/gameengine/VideoTexture/SConscript +++ b/source/gameengine/VideoTexture/SConscript @@ -15,7 +15,7 @@ incs += ' #source/blender/gpu #intern/string #intern/moto/include' incs += ' #intern/guardedalloc #intern/container #extern/glew/include' incs += ' #intern/ffmpeg' -defs = [] +defs = ['GLEW_STATIC'] if env['OURPLATFORM'] in ('win32-vc', 'win64-vc','win32-mingw', 'win64-mingw'): if env['BF_DEBUG']: defs.append('_DEBUG') diff --git a/source/gameengine/VideoTexture/Texture.cpp b/source/gameengine/VideoTexture/Texture.cpp index f08a5a4a0b3..a21300018eb 100644 --- a/source/gameengine/VideoTexture/Texture.cpp +++ b/source/gameengine/VideoTexture/Texture.cpp @@ -130,13 +130,12 @@ short getMaterialID(PyObject * obj, const char *name) if (mat == NULL) break; // name is a material name if it starts with MA and a UV texture name if it starts with IM - if (name[0] == 'I' && name[1] == 'M') - { + if (name[0] == 'I' && name[1] == 'M') { // if texture name matches if (strcmp(mat->GetTextureName().ReadPtr(), name) == 0) return matID; - } else - { + } + else { // if material name matches if (strcmp(mat->GetMaterialName().ReadPtr(), name) == 0) return matID;