├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── CMakePresets.json ├── libs ├── OpenSceneGraph-min │ ├── Export │ ├── LICENSE.txt │ ├── Math │ ├── README.md │ ├── Referenced │ ├── Referenced.cpp │ ├── Vec2 │ ├── Vec2f │ ├── Vec3 │ ├── Vec3f │ ├── Vec4 │ ├── Vec4f │ ├── obj.cpp │ ├── obj.h │ └── ref_ptr └── blender │ ├── BLI_alloca.h │ ├── BLI_allocator.hh │ ├── BLI_array.h │ ├── BLI_array.hh │ ├── BLI_array_store.h │ ├── BLI_array_store_utils.h │ ├── BLI_array_utils.h │ ├── BLI_assert.h │ ├── BLI_compiler_attrs.h │ ├── BLI_compiler_compat.h │ ├── BLI_compiler_typecheck.h │ ├── BLI_hash.h │ ├── BLI_hash.hh │ ├── BLI_hash_md5.h │ ├── BLI_hash_mm2a.h │ ├── BLI_hash_mm3.h │ ├── BLI_hash_tables.hh │ ├── BLI_index_range.hh │ ├── BLI_listbase.h │ ├── BLI_listbase_wrapper.hh │ ├── BLI_map.hh │ ├── BLI_map_slots.hh │ ├── BLI_math.h │ ├── BLI_math_base.h │ ├── BLI_math_base_safe.h │ ├── BLI_math_bits.h │ ├── BLI_math_boolean.hh │ ├── BLI_math_color.h │ ├── BLI_math_color_blend.h │ ├── BLI_math_geom.h │ ├── BLI_math_inline.h │ ├── BLI_math_interp.h │ ├── BLI_math_matrix.h │ ├── BLI_math_mpq.hh │ ├── BLI_math_rotation.h │ ├── BLI_math_solvers.h │ ├── BLI_math_statistics.h │ ├── BLI_math_time.h │ ├── BLI_math_vec_mpq_types.hh │ ├── BLI_math_vec_types.hh │ ├── BLI_math_vector.h │ ├── BLI_math_vector.hh │ ├── BLI_memory_utils.h │ ├── BLI_memory_utils.hh │ ├── BLI_path_util.h │ ├── BLI_probing_strategies.hh │ ├── BLI_simd.h │ ├── BLI_span.hh │ ├── BLI_strict_flags.h │ ├── BLI_string.h │ ├── BLI_string_cursor_utf8.h │ ├── BLI_string_ref.hh │ ├── BLI_string_search.h │ ├── BLI_string_utf8.h │ ├── BLI_string_utils.h │ ├── BLI_sys_types.h │ ├── BLI_system.h │ ├── BLI_utildefines.h │ ├── BLI_utildefines_variadic.h │ ├── BLI_vector.hh │ ├── BLI_vector_set.hh │ ├── BLI_vector_set_slots.hh │ ├── DNA_ID.h │ ├── DNA_ID_enums.h │ ├── DNA_action_types.h │ ├── DNA_color_types.h │ ├── DNA_customdata_types.h │ ├── DNA_defaults.h │ ├── DNA_defs.h │ ├── DNA_image_types.h │ ├── DNA_lineart_types.h │ ├── DNA_listBase.h │ ├── DNA_meshdata_types.h │ ├── DNA_object_defaults.h │ ├── DNA_object_enums.h │ ├── DNA_object_fluidsim_types.h │ ├── DNA_object_force_types.h │ ├── DNA_object_types.h │ ├── DNA_session_uuid_types.h │ ├── DNA_texture_types.h │ ├── DNA_userdef_types.h │ ├── DNA_vec_types.h │ ├── DNA_view2d_types.h │ ├── MEM_guardedalloc.h │ ├── atomic_ops.h │ ├── importer │ ├── IO_wavefront_obj.h │ ├── obj_export_io.hh │ ├── obj_export_mtl.hh │ ├── obj_import_file_reader.cc │ ├── obj_import_file_reader.hh │ ├── obj_import_objects.hh │ ├── obj_import_string_utils.cc │ ├── obj_import_string_utils.hh │ ├── obj_importer.cc │ └── obj_importer.hh │ ├── intern │ ├── BLI_assert.c │ ├── atomic_ops_ext.h │ ├── atomic_ops_msvc.h │ ├── atomic_ops_unix.h │ ├── atomic_ops_utils.h │ ├── fast_float.h │ ├── leak_detector.cc │ ├── mallocn.c │ ├── mallocn_guarded_impl.c │ ├── mallocn_inline.h │ ├── mallocn_intern.h │ ├── mallocn_lockfree_impl.c │ ├── math_base_inline.c │ ├── math_base_safe_inline.c │ ├── math_color_inline.c │ ├── math_geom_inline.c │ ├── math_vector_inline.c │ ├── path_util.c │ └── string.c │ └── pthreads │ ├── include │ ├── _ptw32.h │ ├── pthread.h │ ├── sched.h │ └── semaphore.h │ └── lib │ └── pthreadVC3.lib ├── obj_parse_tester.cpp ├── readme.md └── test_files ├── Blender3Splash.mtl ├── cube.mtl ├── cube.obj ├── monkey-subd6-30.mtl ├── monkey-subd6-nonormals.mtl ├── rungholt.mtl ├── simple.mtl ├── simple.obj └── sponza.mtl /.gitignore: -------------------------------------------------------------------------------- 1 | .vs/ 2 | out/ 3 | test_files/Blender3Splash.obj 4 | test_files/monkey-subd6-30.obj 5 | test_files/rungholt.obj 6 | test_files/sponza.obj 7 | bin/* 8 | .DS_Store 9 | test_files/monkey-subd6-nonormals.obj 10 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "libs/tinyobjloader"] 2 | path = libs/tinyobjloader 3 | url = https://github.com/tinyobjloader/tinyobjloader 4 | [submodule "libs/fast_obj"] 5 | path = libs/fast_obj 6 | url = https://github.com/thisistherk/fast_obj 7 | [submodule "libs/rapidobj"] 8 | path = libs/rapidobj 9 | url = https://github.com/guybrush77/rapidobj 10 | [submodule "libs/assimp"] 11 | path = libs/assimp 12 | url = https://github.com/assimp/assimp 13 | [submodule "libs/xxHash"] 14 | path = libs/xxHash 15 | url = https://github.com/Cyan4973/xxHash 16 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.8) 2 | 3 | option(BUILD_SHARED_LIBS "Build shared libs" OFF) 4 | option(ASSIMP_BUILD_ALL_EXPORTERS_BY_DEFAULT "" OFF) 5 | option(ASSIMP_BUILD_ALL_IMPORTERS_BY_DEFAULT "" OFF) 6 | option(ASSIMP_BUILD_ASSIMP_TOOLS "" OFF) 7 | option(ASSIMP_BUILD_TESTS "" OFF) 8 | option(ASSIMP_INSTALL "" OFF) 9 | option(ASSIMP_BUILD_ASSIMP_VIEW "" OFF) 10 | option(ASSIMP_BUILD_OBJ_IMPORTER "" ON) 11 | add_subdirectory(libs/assimp) 12 | 13 | add_subdirectory(libs/fast_obj) 14 | add_subdirectory(libs/rapidobj) 15 | add_subdirectory(libs/tinyobjloader) 16 | 17 | set(XXHASH_BUILD_ENABLE_INLINE_API OFF) 18 | set(XXHASH_BUILD_XXHSUM OFF) 19 | add_subdirectory(libs/xxHash/cmake_unofficial) 20 | 21 | project ("obj_parse_tester") 22 | 23 | add_executable (obj_parse_tester "obj_parse_tester.cpp") 24 | add_definitions(-DNOMINMAX) 25 | target_sources(obj_parse_tester PRIVATE 26 | # embedded Blender OBJ importer parts 27 | libs/blender/importer/obj_import_file_reader.cc 28 | libs/blender/importer/obj_importer.cc 29 | libs/blender/importer/obj_import_string_utils.cc 30 | libs/blender/intern/BLI_assert.c 31 | libs/blender/intern/leak_detector.cc 32 | libs/blender/intern/mallocn.c 33 | libs/blender/intern/mallocn_guarded_impl.c 34 | libs/blender/intern/mallocn_lockfree_impl.c 35 | libs/blender/intern/math_base_inline.c 36 | libs/blender/intern/math_color_inline.c 37 | libs/blender/intern/math_geom_inline.c 38 | libs/blender/intern/math_vector_inline.c 39 | libs/blender/intern/path_util.c 40 | libs/blender/intern/string.c 41 | # minimal amount of OpenSceneGraph to get OBJ parser 42 | libs/OpenSceneGraph-min/obj.cpp 43 | ) 44 | target_compile_features(obj_parse_tester PRIVATE cxx_std_17) 45 | target_include_directories(obj_parse_tester PRIVATE 46 | libs/tinyobjloader/experimental 47 | libs/blender 48 | ) 49 | 50 | set(THREADS_PREFER_PTHREAD_FLAG ON) 51 | find_package(Threads REQUIRED) 52 | 53 | target_link_libraries(obj_parse_tester 54 | tinyobjloader 55 | xxHash::xxhash 56 | fast_obj_lib 57 | rapidobj::rapidobj 58 | assimp::assimp 59 | Threads::Threads 60 | ) 61 | if (MSVC) 62 | target_link_libraries(obj_parse_tester ${CMAKE_SOURCE_DIR}/libs/blender/pthreads/lib/pthreadVC3.lib) 63 | endif() 64 | -------------------------------------------------------------------------------- /CMakePresets.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "configurePresets": [ 4 | { 5 | "name": "windows-base", 6 | "hidden": true, 7 | "generator": "Ninja", 8 | "binaryDir": "${sourceDir}/out/build/${presetName}", 9 | "installDir": "${sourceDir}/out/install/${presetName}", 10 | "cacheVariables": { 11 | "CMAKE_C_COMPILER": "cl.exe", 12 | "CMAKE_CXX_COMPILER": "cl.exe" 13 | }, 14 | "condition": { 15 | "type": "equals", 16 | "lhs": "${hostSystemName}", 17 | "rhs": "Windows" 18 | } 19 | }, 20 | { 21 | "name": "x64-debug", 22 | "displayName": "x64 Debug", 23 | "inherits": "windows-base", 24 | "architecture": { 25 | "value": "x64", 26 | "strategy": "external" 27 | }, 28 | "cacheVariables": { 29 | "CMAKE_BUILD_TYPE": "Debug" 30 | } 31 | }, 32 | { 33 | "name": "x64-release", 34 | "displayName": "x64 Release", 35 | "inherits": "x64-debug", 36 | "cacheVariables": { 37 | "CMAKE_BUILD_TYPE": "RelWithDebInfo" 38 | } 39 | }, 40 | { 41 | "name": "x64-release-clang", 42 | "displayName": "x64 Release Clang", 43 | "inherits": "x64-release", 44 | "cacheVariables": { 45 | "CMAKE_C_COMPILER": "clang-cl", 46 | "CMAKE_CXX_COMPILER": "clang-cl" 47 | } 48 | } 49 | ] 50 | } 51 | -------------------------------------------------------------------------------- /libs/OpenSceneGraph-min/Export: -------------------------------------------------------------------------------- 1 | /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 | * 3 | * This library is open source and may be redistributed and/or modified under 4 | * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 | * (at your option) any later version. The full license is in LICENSE file 6 | * included with this distribution, and on the openscenegraph.org website. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | * OpenSceneGraph Public License for more details. 12 | */ 13 | 14 | #ifndef OSG_EXPORT_ 15 | #define OSG_EXPORT_ 1 16 | 17 | #define OSG_LIBRARY_STATIC 1 18 | 19 | // disable VisualStudio warnings 20 | #if defined(_MSC_VER) && defined(OSG_DISABLE_MSVC_WARNINGS) 21 | #pragma warning( disable : 4244 ) 22 | #pragma warning( disable : 4251 ) 23 | #pragma warning( disable : 4275 ) 24 | #pragma warning( disable : 4512 ) 25 | #pragma warning( disable : 4267 ) 26 | #pragma warning( disable : 4702 ) 27 | #pragma warning( disable : 4511 ) 28 | #endif 29 | 30 | #if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__) || defined( __MWERKS__) 31 | # if defined( OSG_LIBRARY_STATIC ) 32 | # define OSG_EXPORT 33 | # elif defined( OSG_LIBRARY ) 34 | # define OSG_EXPORT __declspec(dllexport) 35 | # else 36 | # define OSG_EXPORT __declspec(dllimport) 37 | # endif 38 | #else 39 | # define OSG_EXPORT 40 | #endif 41 | 42 | // set up define for whether member templates are supported by VisualStudio compilers. 43 | #ifdef _MSC_VER 44 | # if (_MSC_VER >= 1300) 45 | # define __STL_MEMBER_TEMPLATES 46 | # endif 47 | #endif 48 | 49 | /* Define NULL pointer value */ 50 | 51 | #ifndef NULL 52 | #ifdef __cplusplus 53 | #define NULL 0 54 | #else 55 | #define NULL ((void *)0) 56 | #endif 57 | #endif 58 | 59 | // helper macro's for quieten unused variable warnings 60 | #define OSG_UNUSED(VAR) (void)(VAR) 61 | #define OSG_UNUSED2(VAR1, VAR2) (void)(VAR1); (void)(VAR2); 62 | #define OSG_UNUSED3(VAR1, VAR2, VAR3) (void)(VAR1); (void)(VAR2); (void)(VAR2); 63 | #define OSG_UNUSED4(VAR1, VAR2, VAR3, VAR4) (void)(VAR1); (void)(VAR2); (void)(VAR3); (void)(VAR4); 64 | #define OSG_UNUSED5(VAR1, VAR2, VAR3, VAR4, VAR5) (void)(VAR1); (void)(VAR2); (void)(VAR3); (void)(VAR4); (void)(VAR5); 65 | 66 | /** 67 | 68 | \namespace osg 69 | 70 | The core osg library provides the basic scene graph classes such as Nodes, 71 | State and Drawables, and maths and general helper classes. 72 | */ 73 | 74 | #endif 75 | 76 | -------------------------------------------------------------------------------- /libs/OpenSceneGraph-min/Math: -------------------------------------------------------------------------------- 1 | /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2004 Robert Osfield 2 | * 3 | * This library is open source and may be redistributed and/or modified under 4 | * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 | * (at your option) any later version. The full license is in LICENSE file 6 | * included with this distribution, and on the openscenegraph.org website. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | * OpenSceneGraph Public License for more details. 12 | */ 13 | 14 | #ifndef __OSG_MATH 15 | #define __OSG_MATH 16 | 17 | #include 18 | #include 19 | 20 | #include "Export" 21 | 22 | namespace osg { 23 | 24 | // define the standard trig values 25 | #ifdef PI 26 | #undef PI 27 | #undef PI_2 28 | #undef PI_4 29 | #endif 30 | const double PI = 3.14159265358979323846; 31 | const double PI_2 = 1.57079632679489661923; 32 | const double PI_4 = 0.78539816339744830962; 33 | const double LN_2 = 0.69314718055994530942; 34 | const double INVLN_2 = 1.0 / LN_2; 35 | 36 | const float PIf = 3.14159265358979323846f; 37 | const float PI_2f = 1.57079632679489661923f; 38 | const float PI_4f = 0.78539816339744830962f; 39 | const float LN_2f = 0.69314718055994530942f; 40 | const float INVLN_2f = 1.0f / LN_2f; 41 | 42 | 43 | template 44 | inline T default_value() { return T(); } 45 | 46 | template<> inline float default_value() { return 0.0f; } 47 | template<> inline double default_value() { return 0.0; } 48 | template<> inline char default_value() { return 0; } 49 | template<> inline unsigned char default_value() { return 0; } 50 | template<> inline short default_value() { return 0; } 51 | template<> inline unsigned short default_value() { return 0; } 52 | template<> inline int default_value() { return 0; } 53 | template<> inline unsigned int default_value() { return 0; } 54 | 55 | 56 | template 57 | inline T absolute(T v) { return v<(T)0?-v:v; } 58 | 59 | /** return true if float lhs and rhs are equivalent, 60 | * meaning that the difference between them is less than an epsilon value 61 | * which defaults to 1e-6. 62 | */ 63 | inline bool equivalent(float lhs,float rhs,float epsilon=1e-6) 64 | { float delta = rhs-lhs; return delta<0.0f?delta>=-epsilon:delta<=epsilon; } 65 | 66 | /** return true if double lhs and rhs are equivalent, 67 | * meaning that the difference between them is less than an epsilon value 68 | * which defaults to 1e-6. 69 | */ 70 | inline bool equivalent(double lhs,double rhs,double epsilon=1e-6) 71 | { double delta = rhs-lhs; return delta<0.0?delta>=-epsilon:delta<=epsilon; } 72 | 73 | /** return the minimum of two values, equivalent to std::min. 74 | * std::min not used because of STL implementation under IRIX not containing 75 | * std::min. 76 | */ 77 | template 78 | inline T minimum(T lhs,T rhs) { return lhs 85 | inline T maximum(T lhs,T rhs) { return lhs>rhs?lhs:rhs; } 86 | 87 | template 88 | inline T clampTo(T v,T minimum,T maximum) { return vmaximum?maximum:v; } 89 | 90 | template 91 | inline T clampAbove(T v,T minimum) { return v 94 | inline T clampBelow(T v,T maximum) { return v>maximum?maximum:v; } 95 | 96 | template 97 | inline T clampBetween(T v,T minimum, T maximum) 98 | { return clampBelow(clampAbove(v,minimum),maximum); } 99 | 100 | template 101 | inline T sign(T v) { return v<(T)0?(T)-1:(T)1; } 102 | 103 | template 104 | inline T signOrZero(T v) { return v<(T)0 ? (T)-1 : ( v>(T)0 ? (T)1 : 0 ); } 105 | 106 | template 107 | inline T square(T v) { return v*v; } 108 | 109 | template 110 | inline T signedSquare(T v) { return v<(T)0?-v*v:v*v;; } 111 | 112 | inline float inDegrees(float angle) { return angle*(float)PI/180.0f; } 113 | inline double inDegrees(double angle) { return angle*PI/180.0; } 114 | 115 | template 116 | inline T inRadians(T angle) { return angle; } 117 | 118 | inline float DegreesToRadians(float angle) { return angle*(float)PI/180.0f; } 119 | inline double DegreesToRadians(double angle) { return angle*PI/180.0; } 120 | 121 | inline float RadiansToDegrees(float angle) { return angle*180.0f/(float)PI; } 122 | inline double RadiansToDegrees(double angle) { return angle*180.0/PI; } 123 | 124 | inline float round(float v) { return v>=0.0f?floorf(v+0.5f):ceilf(v-0.5f); } 125 | inline double round(double v) { return v>=0.0?floor(v+0.5):ceil(v-0.5); } 126 | 127 | #if defined(_MSC_VER) 128 | inline bool isNaN(double v) { return _isnan(v)!=0; } 129 | #elif defined(__ANDROID__) 130 | inline bool isNaN(float v) { return isnan(v); } 131 | inline bool isNaN(double v) { return isnan(v); } 132 | #else 133 | inline bool isNaN(float v) { return std::isnan(v); } 134 | inline bool isNaN(double v) { return std::isnan(v); } 135 | #endif 136 | 137 | 138 | /** compute the volume of a tetrahedron. */ 139 | template 140 | inline float computeVolume(const T& a,const T& b,const T& c,const T& d) 141 | { 142 | return fabsf(((b-c)^(a-b))*(d-b)); 143 | } 144 | 145 | /** compute the volume of a prism. */ 146 | template 147 | inline float computeVolume(const T& f1,const T& f2,const T& f3, 148 | const T& b1,const T& b2,const T& b3) 149 | { 150 | return computeVolume(f1,f2,f3,b1)+ 151 | computeVolume(b1,b2,b3,f2)+ 152 | computeVolume(b1,b3,f2,f3); 153 | } 154 | 155 | /** Convert a ascii number to a double, ignoring locale settings.*/ 156 | extern OSG_EXPORT double asciiToDouble(const char* str); 157 | 158 | /** Convert a ascii number to a float, ignoring locale settings.*/ 159 | inline float asciiToFloat(const char* str) { return static_cast(asciiToDouble(str)); } 160 | 161 | /** Detect first ascii POSITIVE number in string and convert to double.*/ 162 | extern OSG_EXPORT double findAsciiToDouble(const char* str); 163 | 164 | /** Detect first ascii POSITIVE number in string and convert to double.*/ 165 | inline float findAsciiToFloat(const char* str) { return static_cast(findAsciiToDouble(str)); } 166 | 167 | } 168 | 169 | 170 | #endif // __OSG_MATH 171 | 172 | -------------------------------------------------------------------------------- /libs/OpenSceneGraph-min/Referenced: -------------------------------------------------------------------------------- 1 | /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 | * 3 | * This library is open source and may be redistributed and/or modified under 4 | * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 | * (at your option) any later version. The full license is in LICENSE file 6 | * included with this distribution, and on the openscenegraph.org website. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | * OpenSceneGraph Public License for more details. 12 | */ 13 | 14 | #ifndef OSG_REFERENCED 15 | #define OSG_REFERENCED 1 16 | 17 | #include 18 | #include "Export" 19 | 20 | namespace osg { 21 | 22 | // forward declare, declared after Referenced below. 23 | class DeleteHandler; 24 | class Observer; 25 | class ObserverSet; 26 | class State; 27 | 28 | /** template class to help enforce static initialization order. */ 29 | template 30 | struct depends_on 31 | { 32 | depends_on() { M(); } 33 | }; 34 | 35 | /** Base class for providing reference counted objects.*/ 36 | class OSG_EXPORT Referenced 37 | { 38 | 39 | public: 40 | 41 | 42 | Referenced() :_observerSet(0), _refCount(0) {} 43 | 44 | /** Deprecated, Referenced is now always uses thread safe ref/unref, use default Referenced() constructor instead */ 45 | explicit Referenced(bool threadSafeRefUnref); 46 | 47 | Referenced(const Referenced&); 48 | 49 | inline Referenced& operator = (const Referenced&) { return *this; } 50 | 51 | /** Deprecated, Referenced is always theadsafe so there method now has no effect and does not need to be called.*/ 52 | virtual void setThreadSafeRefUnref(bool /*threadSafe*/) {} 53 | 54 | /** Get whether a mutex is used to ensure ref() and unref() are thread safe.*/ 55 | bool getThreadSafeRefUnref() const { return true; } 56 | 57 | /** Get the mutex used to ensure thread safety of ref()/unref(). */ 58 | //OpenThreads::Mutex* getRefMutex() const { return getGlobalReferencedMutex(); } 59 | 60 | /** Get the optional global Referenced mutex, this can be shared between all osg::Referenced.*/ 61 | //static OpenThreads::Mutex* getGlobalReferencedMutex(); 62 | 63 | /** Increment the reference count by one, indicating that 64 | this object has another pointer which is referencing it.*/ 65 | inline int ref() const; 66 | 67 | /** Decrement the reference count by one, indicating that 68 | a pointer to this object is no longer referencing it. If the 69 | reference count goes to zero, it is assumed that this object 70 | is no longer referenced and is automatically deleted.*/ 71 | inline int unref() const; 72 | 73 | /** Decrement the reference count by one, indicating that 74 | a pointer to this object is no longer referencing it. However, do 75 | not delete it, even if ref count goes to 0. Warning, unref_nodelete() 76 | should only be called if the user knows exactly who will 77 | be responsible for, one should prefer unref() over unref_nodelete() 78 | as the latter can lead to memory leaks.*/ 79 | int unref_nodelete() const; 80 | 81 | /** Return the number of pointers currently referencing this object. */ 82 | inline int referenceCount() const { return _refCount; } 83 | 84 | 85 | /** Get the ObserverSet if one is attached, otherwise return NULL.*/ 86 | ObserverSet* getObserverSet() const 87 | { 88 | return nullptr; 89 | } 90 | 91 | /** Get the ObserverSet if one is attached, otherwise create an ObserverSet, attach it, then return this newly created ObserverSet.*/ 92 | ObserverSet* getOrCreateObserverSet() const; 93 | 94 | /** Add a Observer that is observing this object, notify the Observer when this object gets deleted.*/ 95 | void addObserver(Observer* observer) const; 96 | 97 | /** Remove Observer that is observing this object.*/ 98 | void removeObserver(Observer* observer) const; 99 | #if 0 100 | /** Resize any per context GLObject buffers to specified size. */ 101 | virtual void resizeGLObjectBuffers(unsigned int /*maxSize*/) {} 102 | 103 | /** If State is non-zero, this function releases any associated OpenGL objects for 104 | * the specified graphics context. Otherwise, releases OpenGL objects 105 | * for all graphics contexts. */ 106 | virtual void releaseGLObjects(osg::State* = 0) const {} 107 | #endif 108 | public: 109 | 110 | friend class DeleteHandler; 111 | 112 | /** Set a DeleteHandler to which deletion of all referenced counted objects 113 | * will be delegated.*/ 114 | static void setDeleteHandler(DeleteHandler* handler); 115 | 116 | /** Get a DeleteHandler.*/ 117 | static DeleteHandler* getDeleteHandler(); 118 | 119 | 120 | protected: 121 | 122 | virtual ~Referenced() {} 123 | 124 | void signalObserversAndDelete(bool signalDelete, bool doDelete) const 125 | { 126 | if (doDelete) 127 | { 128 | //if (_refCount!=0) 129 | // OSG_NOTICE<<"Warning Referenced::signalObserversAndDelete(,,) doing delete with _refCount="<<_refCount< _refCount; 141 | }; 142 | 143 | inline int Referenced::ref() const 144 | { 145 | return ++_refCount; 146 | } 147 | 148 | inline int Referenced::unref() const 149 | { 150 | int newRef; 151 | newRef = --_refCount; 152 | bool needDelete = (newRef == 0); 153 | 154 | if (needDelete) 155 | { 156 | signalObserversAndDelete(true,true); 157 | } 158 | return newRef; 159 | } 160 | 161 | // intrusive_ptr_add_ref and intrusive_ptr_release allow 162 | // use of osg Referenced classes with boost::intrusive_ptr 163 | inline void intrusive_ptr_add_ref(Referenced* p) { p->ref(); } 164 | inline void intrusive_ptr_release(Referenced* p) { p->unref(); } 165 | 166 | } 167 | 168 | #endif 169 | -------------------------------------------------------------------------------- /libs/OpenSceneGraph-min/Vec2: -------------------------------------------------------------------------------- 1 | /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 | * 3 | * This library is open source and may be redistributed and/or modified under 4 | * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 | * (at your option) any later version. The full license is in LICENSE file 6 | * included with this distribution, and on the openscenegraph.org website. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | * OpenSceneGraph Public License for more details. 12 | */ 13 | 14 | #ifndef OSG_VEC2 15 | #define OSG_VEC2 1 16 | 17 | #include "Vec2f" 18 | 19 | namespace osg { 20 | 21 | typedef Vec2f Vec2; 22 | 23 | } 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /libs/OpenSceneGraph-min/Vec2f: -------------------------------------------------------------------------------- 1 | /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 | * 3 | * This library is open source and may be redistributed and/or modified under 4 | * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 | * (at your option) any later version. The full license is in LICENSE file 6 | * included with this distribution, and on the openscenegraph.org website. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | * OpenSceneGraph Public License for more details. 12 | */ 13 | 14 | #ifndef OSG_VEC2F 15 | #define OSG_VEC2F 1 16 | 17 | #include "Math" 18 | 19 | namespace osg { 20 | 21 | /** General purpose float pair. Uses include representation of 22 | * texture coordinates. 23 | * No support yet added for float * Vec2f - is it necessary? 24 | * Need to define a non-member non-friend operator* etc. 25 | * BTW: Vec2f * float is okay 26 | */ 27 | 28 | class Vec2f 29 | { 30 | public: 31 | 32 | /** Data type of vector components.*/ 33 | typedef float value_type; 34 | 35 | /** Number of vector components. */ 36 | enum { num_components = 2 }; 37 | 38 | /** Vec member variable. */ 39 | value_type _v[2]; 40 | 41 | 42 | /** Constructor that sets all components of the vector to zero */ 43 | Vec2f() {_v[0]=0.0; _v[1]=0.0;} 44 | Vec2f(value_type x,value_type y) { _v[0]=x; _v[1]=y; } 45 | 46 | 47 | inline bool operator == (const Vec2f& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1]; } 48 | 49 | inline bool operator != (const Vec2f& v) const { return _v[0]!=v._v[0] || _v[1]!=v._v[1]; } 50 | 51 | inline bool operator < (const Vec2f& v) const 52 | { 53 | if (_v[0]v._v[0]) return false; 55 | else return (_v[1]0.0) 167 | { 168 | value_type inv = 1.0f/norm; 169 | _v[0] *= inv; 170 | _v[1] *= inv; 171 | } 172 | return( norm ); 173 | } 174 | 175 | }; // end of class Vec2f 176 | 177 | /** multiply by vector components. */ 178 | inline Vec2f componentMultiply(const Vec2f& lhs, const Vec2f& rhs) 179 | { 180 | return Vec2f(lhs[0]*rhs[0], lhs[1]*rhs[1]); 181 | } 182 | 183 | /** divide rhs components by rhs vector components. */ 184 | inline Vec2f componentDivide(const Vec2f& lhs, const Vec2f& rhs) 185 | { 186 | return Vec2f(lhs[0]/rhs[0], lhs[1]/rhs[1]); 187 | } 188 | 189 | } // end of namespace osg 190 | #endif 191 | 192 | -------------------------------------------------------------------------------- /libs/OpenSceneGraph-min/Vec3: -------------------------------------------------------------------------------- 1 | /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 | * 3 | * This library is open source and may be redistributed and/or modified under 4 | * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 | * (at your option) any later version. The full license is in LICENSE file 6 | * included with this distribution, and on the openscenegraph.org website. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | * OpenSceneGraph Public License for more details. 12 | */ 13 | 14 | #ifndef OSG_VEC3 15 | #define OSG_VEC3 1 16 | 17 | #include "Vec3f" 18 | 19 | namespace osg { 20 | 21 | typedef Vec3f Vec3; 22 | 23 | } 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /libs/OpenSceneGraph-min/Vec4: -------------------------------------------------------------------------------- 1 | /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 | * 3 | * This library is open source and may be redistributed and/or modified under 4 | * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 | * (at your option) any later version. The full license is in LICENSE file 6 | * included with this distribution, and on the openscenegraph.org website. 7 | * 8 | * This library is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | * OpenSceneGraph Public License for more details. 12 | */ 13 | 14 | #ifndef OSG_VEC4 15 | #define OSG_VEC4 1 16 | 17 | #include "Vec4f" 18 | 19 | namespace osg { 20 | 21 | typedef Vec4f Vec4; 22 | 23 | } 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /libs/blender/BLI_alloca.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | */ 16 | 17 | #pragma once 18 | 19 | /** \file 20 | * \ingroup bli 21 | * 22 | * Defines alloca and utility macro BLI_array_alloca 23 | */ 24 | 25 | /* BLI_array_alloca / alloca */ 26 | 27 | #include 28 | 29 | #if defined(__GNUC__) || defined(__clang__) 30 | # if defined(__cplusplus) && (__cplusplus > 199711L) 31 | # define BLI_array_alloca(arr, realsize) (decltype(arr))alloca(sizeof(*arr) * (realsize)) 32 | # else 33 | # define BLI_array_alloca(arr, realsize) (typeof(arr))alloca(sizeof(*arr) * (realsize)) 34 | # endif 35 | #else 36 | # define BLI_array_alloca(arr, realsize) alloca(sizeof(*arr) * (realsize)) 37 | #endif 38 | -------------------------------------------------------------------------------- /libs/blender/BLI_allocator.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | */ 16 | #pragma once 17 | 18 | /** \file 19 | * \ingroup bli 20 | * 21 | * An `Allocator` can allocate and deallocate memory. It is used by containers such as 22 | * blender::Vector. The allocators defined in this file do not work with standard library 23 | * containers such as std::vector. 24 | * 25 | * Every allocator has to implement two methods: 26 | * void *allocate(size_t size, size_t alignment, const char *name); 27 | * void deallocate(void *ptr); 28 | * 29 | * We don't use the std::allocator interface, because it does more than is really necessary for an 30 | * allocator and has some other quirks. It mixes the concepts of allocation and construction. It is 31 | * essentially forced to be a template, even though the allocator should not care about the type. 32 | * Also see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html#std_allocator. Some 33 | * of these aspects have been improved in new versions of C++, so we might have to reevaluate the 34 | * strategy later on. 35 | * 36 | * The allocator interface dictated by this file is very simplistic, but for now that is all we 37 | * need. More complexity can be added when it seems necessary. 38 | */ 39 | 40 | #include 41 | #include 42 | 43 | #include "MEM_guardedalloc.h" 44 | 45 | #include "BLI_math_base.h" 46 | #include "BLI_utildefines.h" 47 | 48 | namespace blender { 49 | 50 | /** 51 | * Use Blender's guarded allocator (aka MEM_*). This should always be used except there is a 52 | * good reason not to use it. 53 | */ 54 | class GuardedAllocator { 55 | public: 56 | void *allocate(size_t size, size_t alignment, const char *name) 57 | { 58 | /* Should we use MEM_mallocN, when alignment is small? If yes, how small must alignment be? */ 59 | return MEM_mallocN_aligned(size, alignment, name); 60 | } 61 | 62 | void deallocate(void *ptr) 63 | { 64 | MEM_freeN(ptr); 65 | } 66 | }; 67 | 68 | /** 69 | * This is a wrapper around malloc/free. Only use this when the GuardedAllocator cannot be 70 | * used. This can be the case when the allocated memory might live longer than Blender's 71 | * allocator. For example, when the memory is owned by a static variable. 72 | */ 73 | class RawAllocator { 74 | private: 75 | struct MemHead { 76 | int offset; 77 | }; 78 | 79 | public: 80 | void *allocate(size_t size, size_t alignment, const char *UNUSED(name)) 81 | { 82 | BLI_assert(is_power_of_2_i(static_cast(alignment))); 83 | void *ptr = malloc(size + alignment + sizeof(MemHead)); 84 | void *used_ptr = reinterpret_cast( 85 | reinterpret_cast(POINTER_OFFSET(ptr, alignment + sizeof(MemHead))) & 86 | ~(static_cast(alignment) - 1)); 87 | int offset = static_cast((intptr_t)used_ptr - (intptr_t)ptr); 88 | BLI_assert(offset >= static_cast(sizeof(MemHead))); 89 | (static_cast(used_ptr) - 1)->offset = offset; 90 | return used_ptr; 91 | } 92 | 93 | void deallocate(void *ptr) 94 | { 95 | MemHead *head = static_cast(ptr) - 1; 96 | int offset = -head->offset; 97 | void *actual_pointer = POINTER_OFFSET(ptr, offset); 98 | free(actual_pointer); 99 | } 100 | }; 101 | 102 | } // namespace blender 103 | -------------------------------------------------------------------------------- /libs/blender/BLI_array.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | * 16 | * The Original Code is Copyright (C) 2008 Blender Foundation. 17 | * All rights reserved. 18 | */ 19 | 20 | #pragma once 21 | 22 | /** \file 23 | * \ingroup bli 24 | * \brief A (mainly) macro array library. 25 | */ 26 | 27 | /* -------------------------------------------------------------------- */ 28 | /** \name Internal defines 29 | * \{ */ 30 | 31 | /** This returns the entire size of the array, including any buffering. */ 32 | #define _bli_array_totalsize_dynamic(arr) \ 33 | (((arr) == NULL) ? 0 : MEM_allocN_len(arr) / sizeof(*(arr))) 34 | 35 | #define _bli_array_totalsize_static(arr) (sizeof(_##arr##_static) / sizeof(*(arr))) 36 | 37 | #define _bli_array_totalsize(arr) \ 38 | ((size_t)(((void *)(arr) == (void *)_##arr##_static && (void *)(arr) != NULL) ? \ 39 | _bli_array_totalsize_static(arr) : \ 40 | _bli_array_totalsize_dynamic(arr))) 41 | 42 | /** \} */ 43 | 44 | /** 45 | * BLI_array.c 46 | * 47 | * Doing the reallocation in a macro isn't so simple, 48 | * so use a function the macros can use. 49 | * 50 | * This function is only to be called via macros. 51 | * 52 | * \note The caller must adjust \a arr_len 53 | */ 54 | void _bli_array_grow_func(void **arr_p, 55 | const void *arr_static, 56 | int sizeof_arr_p, 57 | int arr_len, 58 | int num, 59 | const char *alloc_str); 60 | 61 | /* -------------------------------------------------------------------- */ 62 | /** \name Public defines 63 | * \{ */ 64 | 65 | /** use `sizeof(*(arr))` to ensure the array exists and is an array */ 66 | #define BLI_array_declare(arr) \ 67 | int _##arr##_len = ((void)(sizeof(*(arr))), 0); \ 68 | void *_##arr##_static = NULL 69 | 70 | /** 71 | * This will use stack space, up to `maxstatic` array elements, 72 | * before switching to dynamic heap allocation. 73 | */ 74 | #define BLI_array_staticdeclare(arr, maxstatic) \ 75 | int _##arr##_len = 0; \ 76 | char _##arr##_static[maxstatic * sizeof(*(arr))] 77 | 78 | /** returns the logical size of the array, not including buffering. */ 79 | #define BLI_array_len(arr) ((void)0, _##arr##_len) 80 | 81 | /** 82 | * Grow the array by a fixed number of items. 83 | * 84 | * Allow for a large 'num' value when the new size is more than double 85 | * to allocate the exact sized array. 86 | */ 87 | #define BLI_array_reserve(arr, num) \ 88 | (void)((((void *)(arr) == NULL) && \ 89 | ((void *)(_##arr##_static) != \ 90 | NULL) && /* don't add _##arr##_len below because it must be zero */ \ 91 | (_bli_array_totalsize_static(arr) >= \ 92 | (size_t)(_##arr##_len + \ 93 | (num)))) ? /* we have an empty array and a static var big enough */ \ 94 | (void)(arr = (void *)_##arr##_static) : /* use existing static array or allocate */ \ 95 | (LIKELY(_bli_array_totalsize(arr) >= (size_t)(_##arr##_len + (num))) ? \ 96 | (void)0 /* do nothing */ : \ 97 | _bli_array_grow_func((void **)&(arr), \ 98 | _##arr##_static, \ 99 | sizeof(*(arr)), \ 100 | _##arr##_len, \ 101 | num, \ 102 | "BLI_array." #arr))) 103 | 104 | /** 105 | * Returns length of array. 106 | */ 107 | #define BLI_array_grow_items(arr, num) (BLI_array_reserve(arr, num), (_##arr##_len += num)) 108 | 109 | #define BLI_array_grow_one(arr) BLI_array_grow_items(arr, 1) 110 | 111 | /** 112 | * Appends an item to the array. 113 | */ 114 | #define BLI_array_append(arr, item) \ 115 | ((void)BLI_array_grow_one(arr), (void)(arr[_##arr##_len - 1] = item)) 116 | 117 | /** 118 | * Appends an item to the array and returns a pointer to the item in the array. 119 | * item is not a pointer, but actual data value. 120 | */ 121 | #define BLI_array_append_r(arr, item) \ 122 | ((void)BLI_array_grow_one(arr), (void)(arr[_##arr##_len - 1] = item), (&arr[_##arr##_len - 1])) 123 | 124 | /** 125 | * Appends (grows) & returns a pointer to the uninitialized memory. 126 | */ 127 | #define BLI_array_append_ret(arr) (BLI_array_reserve(arr, 1), &arr[(_##arr##_len++)]) 128 | 129 | #define BLI_array_free(arr) \ 130 | { \ 131 | if (arr && (char *)arr != _##arr##_static) { \ 132 | BLI_array_fake_user(arr); \ 133 | MEM_freeN((void *)arr); \ 134 | } \ 135 | } \ 136 | ((void)0) 137 | 138 | #define BLI_array_pop(arr) ((arr && _##arr##_len) ? arr[--_##arr##_len] : NULL) 139 | 140 | /** 141 | * Resets the logical size of an array to zero, but doesn't 142 | * free the memory. 143 | */ 144 | #define BLI_array_clear(arr) \ 145 | { \ 146 | _##arr##_len = 0; \ 147 | } \ 148 | ((void)0) 149 | 150 | /** 151 | * Set the length of the array, doesn't actually increase the allocated array size. 152 | * Don't use this unless you know what you're doing. 153 | */ 154 | #define BLI_array_len_set(arr, len) \ 155 | { \ 156 | _##arr##_len = (len); \ 157 | } \ 158 | ((void)0) 159 | 160 | /** 161 | * Only to prevent unused warnings. 162 | */ 163 | #define BLI_array_fake_user(arr) ((void)_##arr##_len, (void)_##arr##_static) 164 | 165 | /** \} */ 166 | 167 | /* -------------------------------------------------------------------- */ 168 | /** \name Generic Array Utils 169 | * 170 | * Other useful defines (unrelated to the main array macros). 171 | * \{ */ 172 | 173 | /** 174 | * Not part of the 'API' but handy functions, same purpose as #BLI_array_staticdeclare() 175 | * but use when the max size is known ahead of time. 176 | */ 177 | #define BLI_array_fixedstack_declare(arr, maxstatic, realsize, allocstr) \ 178 | char _##arr##_static[maxstatic * sizeof(*(arr))]; \ 179 | const bool _##arr##_is_static = ((void *)_##arr##_static) != \ 180 | (arr = ((realsize) <= maxstatic) ? \ 181 | (void *)_##arr##_static : \ 182 | MEM_mallocN(sizeof(*(arr)) * (realsize), allocstr)) 183 | 184 | #define BLI_array_fixedstack_free(arr) \ 185 | if (_##arr##_is_static) { \ 186 | MEM_freeN(arr); \ 187 | } \ 188 | ((void)0) 189 | 190 | /** \} */ 191 | -------------------------------------------------------------------------------- /libs/blender/BLI_array_store.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | */ 16 | 17 | #pragma once 18 | 19 | /** \file 20 | * \ingroup bli 21 | * \brief Efficient in-memory storage of multiple similar arrays. 22 | */ 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | typedef struct BArrayState BArrayState; 29 | typedef struct BArrayStore BArrayStore; 30 | 31 | /** 32 | * Create a new array store, which can store any number of arrays 33 | * as long as their stride matches. 34 | * 35 | * \param stride: `sizeof()` each element, 36 | * 37 | * \note while a stride of `1` will always work, 38 | * its less efficient since duplicate chunks of memory will be searched 39 | * at positions unaligned with the array data. 40 | * 41 | * \param chunk_count: Number of elements to split each chunk into. 42 | * - A small value increases the ability to de-duplicate chunks, 43 | * but adds overhead by increasing the number of chunks to look up when searching for duplicates, 44 | * as well as some overhead constructing the original array again, with more calls to `memcpy`. 45 | * - Larger values reduce the *book keeping* overhead, 46 | * but increase the chance a small, 47 | * isolated change will cause a larger amount of data to be duplicated. 48 | * 49 | * \return A new array store, to be freed with #BLI_array_store_destroy. 50 | */ 51 | BArrayStore *BLI_array_store_create(unsigned int stride, unsigned int chunk_count); 52 | /** 53 | * Free the #BArrayStore, including all states and chunks. 54 | */ 55 | void BLI_array_store_destroy(BArrayStore *bs); 56 | /** 57 | * Clear all contents, allowing reuse of \a bs. 58 | */ 59 | void BLI_array_store_clear(BArrayStore *bs); 60 | 61 | /** 62 | * Find the memory used by all states (expanded & real). 63 | * 64 | * \return the total amount of memory that would be used by getting the arrays for all states. 65 | */ 66 | size_t BLI_array_store_calc_size_expanded_get(const BArrayStore *bs); 67 | /** 68 | * \return the amount of memory used by all #BChunk.data 69 | * (duplicate chunks are only counted once). 70 | */ 71 | size_t BLI_array_store_calc_size_compacted_get(const BArrayStore *bs); 72 | 73 | /** 74 | * 75 | * \param data: Data used to create 76 | * \param state_reference: The state to use as a reference when adding the new state, 77 | * typically this is the previous state, 78 | * however it can be any previously created state from this \a bs. 79 | * 80 | * \return The new state, 81 | * which is used by the caller as a handle to get back the contents of \a data. 82 | * This may be removed using #BLI_array_store_state_remove, 83 | * otherwise it will be removed with #BLI_array_store_destroy. 84 | */ 85 | BArrayState *BLI_array_store_state_add(BArrayStore *bs, 86 | const void *data, 87 | size_t data_len, 88 | const BArrayState *state_reference); 89 | /** 90 | * Remove a state and free any unused #BChunk data. 91 | * 92 | * The states can be freed in any order. 93 | */ 94 | void BLI_array_store_state_remove(BArrayStore *bs, BArrayState *state); 95 | 96 | /** 97 | * \return the expanded size of the array, 98 | * use this to know how much memory to allocate #BLI_array_store_state_data_get's argument. 99 | */ 100 | size_t BLI_array_store_state_size_get(BArrayState *state); 101 | /** 102 | * Fill in existing allocated memory with the contents of \a state. 103 | */ 104 | void BLI_array_store_state_data_get(BArrayState *state, void *data); 105 | /** 106 | * Allocate an array for \a state and return it. 107 | */ 108 | void *BLI_array_store_state_data_get_alloc(BArrayState *state, size_t *r_data_len); 109 | 110 | /** 111 | * \note Only for tests. 112 | */ 113 | bool BLI_array_store_is_valid(BArrayStore *bs); 114 | 115 | #ifdef __cplusplus 116 | } 117 | #endif 118 | -------------------------------------------------------------------------------- /libs/blender/BLI_array_store_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | */ 16 | 17 | #pragma once 18 | 19 | /** \file 20 | * \ingroup bli 21 | */ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | struct BArrayStore; 28 | 29 | struct BArrayStore_AtSize { 30 | struct BArrayStore **stride_table; 31 | int stride_table_len; 32 | }; 33 | 34 | BArrayStore *BLI_array_store_at_size_ensure(struct BArrayStore_AtSize *bs_stride, 35 | int stride, 36 | int chunk_size); 37 | 38 | BArrayStore *BLI_array_store_at_size_get(struct BArrayStore_AtSize *bs_stride, int stride); 39 | 40 | void BLI_array_store_at_size_clear(struct BArrayStore_AtSize *bs_stride); 41 | 42 | void BLI_array_store_at_size_calc_memory_usage(struct BArrayStore_AtSize *bs_stride, 43 | size_t *r_size_expanded, 44 | size_t *r_size_compacted); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | -------------------------------------------------------------------------------- /libs/blender/BLI_array_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | */ 16 | 17 | #pragma once 18 | 19 | /** \file 20 | * \ingroup bli 21 | * \brief Generic array manipulation API. 22 | */ 23 | 24 | #include "BLI_compiler_typecheck.h" 25 | #include "BLI_sys_types.h" 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /** 32 | * In-place array reverse. 33 | * 34 | * Access via #BLI_array_reverse 35 | */ 36 | void _bli_array_reverse(void *arr, uint arr_len, size_t arr_stride); 37 | #define BLI_array_reverse(arr, arr_len) _bli_array_reverse(arr, arr_len, sizeof(*(arr))) 38 | 39 | /** 40 | * In-place array wrap. 41 | * (rotate the array one step forward or backwards). 42 | * 43 | * Access via #BLI_array_wrap 44 | */ 45 | void _bli_array_wrap(void *arr, uint arr_len, size_t arr_stride, int dir); 46 | #define BLI_array_wrap(arr, arr_len, dir) _bli_array_wrap(arr, arr_len, sizeof(*(arr)), dir) 47 | 48 | /** 49 | *In-place array permute. 50 | * (re-arrange elements based on an array of indices). 51 | * 52 | * Access via #BLI_array_wrap 53 | */ 54 | void _bli_array_permute( 55 | void *arr, uint arr_len, size_t arr_stride, const uint *order, void *arr_temp); 56 | #define BLI_array_permute(arr, arr_len, order) \ 57 | _bli_array_permute(arr, arr_len, sizeof(*(arr)), order, NULL) 58 | #define BLI_array_permute_ex(arr, arr_len, order, arr_temp) \ 59 | _bli_array_permute(arr, arr_len, sizeof(*(arr)), order, arr_temp) 60 | 61 | /** 62 | * In-place array de-duplication of an ordered array. 63 | * 64 | * \return The new length of the array. 65 | * 66 | * Access via #BLI_array_deduplicate_ordered 67 | */ 68 | uint _bli_array_deduplicate_ordered(void *arr, uint arr_len, size_t arr_stride); 69 | #define BLI_array_deduplicate_ordered(arr, arr_len) \ 70 | _bli_array_deduplicate_ordered(arr, arr_len, sizeof(*(arr))) 71 | 72 | /** 73 | * Find the first index of an item in an array. 74 | * 75 | * Access via #BLI_array_findindex 76 | * 77 | * \note Not efficient, use for error checks/asserts. 78 | */ 79 | int _bli_array_findindex(const void *arr, uint arr_len, size_t arr_stride, const void *p); 80 | #define BLI_array_findindex(arr, arr_len, p) _bli_array_findindex(arr, arr_len, sizeof(*(arr)), p) 81 | 82 | /** 83 | * A version of #BLI_array_findindex that searches from the end of the list. 84 | */ 85 | int _bli_array_rfindindex(const void *arr, uint arr_len, size_t arr_stride, const void *p); 86 | #define BLI_array_rfindindex(arr, arr_len, p) \ 87 | _bli_array_rfindindex(arr, arr_len, sizeof(*(arr)), p) 88 | 89 | void _bli_array_binary_and( 90 | void *arr, const void *arr_a, const void *arr_b, uint arr_len, size_t arr_stride); 91 | #define BLI_array_binary_and(arr, arr_a, arr_b, arr_len) \ 92 | (CHECK_TYPE_PAIR_INLINE(*(arr), *(arr_a)), \ 93 | CHECK_TYPE_PAIR_INLINE(*(arr), *(arr_b)), \ 94 | _bli_array_binary_and(arr, arr_a, arr_b, arr_len, sizeof(*(arr)))) 95 | 96 | void _bli_array_binary_or( 97 | void *arr, const void *arr_a, const void *arr_b, uint arr_len, size_t arr_stride); 98 | #define BLI_array_binary_or(arr, arr_a, arr_b, arr_len) \ 99 | (CHECK_TYPE_PAIR_INLINE(*(arr), *(arr_a)), \ 100 | CHECK_TYPE_PAIR_INLINE(*(arr), *(arr_b)), \ 101 | _bli_array_binary_or(arr, arr_a, arr_b, arr_len, sizeof(*(arr)))) 102 | 103 | /** 104 | * Utility function to iterate over contiguous items in an array. 105 | * 106 | * \param use_wrap: Detect contiguous ranges across the first/last points. 107 | * In this case the second index of \a span_step may be lower than the first, 108 | * which indicates the values are wrapped. 109 | * \param use_delimit_bounds: When false, 110 | * ranges that defined by the start/end indices are excluded. 111 | * This option has no effect when \a use_wrap is enabled. 112 | * \param test_fn: Function to test if the item should be included in the range. 113 | * \param user_data: User data for \a test_fn. 114 | * \param span_step: Indices to iterate over, 115 | * initialize both values to the array length to initialize iteration. 116 | * \param r_span_len: The length of the span, useful when \a use_wrap is enabled, 117 | * where calculating the length isn't a simple subtraction. 118 | */ 119 | bool _bli_array_iter_span(const void *arr, 120 | uint arr_len, 121 | size_t arr_stride, 122 | bool use_wrap, 123 | bool use_delimit_bounds, 124 | bool (*test_fn)(const void *arr_item, void *user_data), 125 | void *user_data, 126 | uint span_step[2], 127 | uint *r_span_len); 128 | #define BLI_array_iter_span( \ 129 | arr, arr_len, use_wrap, use_delimit_bounds, test_fn, user_data, span_step, r_span_len) \ 130 | _bli_array_iter_span(arr, \ 131 | arr_len, \ 132 | sizeof(*(arr)), \ 133 | use_wrap, \ 134 | use_delimit_bounds, \ 135 | test_fn, \ 136 | user_data, \ 137 | span_step, \ 138 | r_span_len) 139 | 140 | /** 141 | * Simple utility to check memory is zeroed. 142 | */ 143 | bool _bli_array_is_zeroed(const void *arr, uint arr_len, size_t arr_stride); 144 | #define BLI_array_is_zeroed(arr, arr_len) _bli_array_is_zeroed(arr, arr_len, sizeof(*(arr))) 145 | 146 | /** 147 | * Smart function to sample a rectangle spiraling outside. 148 | * Nice for selection ID. 149 | * 150 | * \param arr_shape: dimensions [w, h]. 151 | * \param center: coordinates [x, y] indicating where to start traversing. 152 | */ 153 | bool _bli_array_iter_spiral_square(const void *arr_v, 154 | const int arr_shape[2], 155 | size_t elem_size, 156 | const int center[2], 157 | bool (*test_fn)(const void *arr_item, void *user_data), 158 | void *user_data); 159 | #define BLI_array_iter_spiral_square(arr, arr_shape, center, test_fn, user_data) \ 160 | _bli_array_iter_spiral_square(arr, arr_shape, sizeof(*(arr)), center, test_fn, user_data) 161 | #ifdef __cplusplus 162 | } 163 | #endif 164 | -------------------------------------------------------------------------------- /libs/blender/BLI_assert.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | */ 16 | 17 | #pragma once 18 | 19 | /** \file 20 | * \ingroup bli 21 | * 22 | * Defines: 23 | * - #BLI_assert 24 | * - #BLI_STATIC_ASSERT 25 | * - #BLI_STATIC_ASSERT_ALIGN 26 | */ 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | /* Utility functions. */ 33 | 34 | void _BLI_assert_print_pos(const char *file, int line, const char *function, const char *id); 35 | void _BLI_assert_print_extra(const char *str); 36 | void _BLI_assert_print_backtrace(void); 37 | void _BLI_assert_abort(void); 38 | void _BLI_assert_unreachable_print(const char *file, int line, const char *function); 39 | 40 | #ifdef _MSC_VER 41 | # include /* for _STATIC_ASSERT */ 42 | #endif 43 | 44 | #ifndef NDEBUG 45 | /* _BLI_ASSERT_PRINT_POS */ 46 | # if defined(__GNUC__) 47 | # define _BLI_ASSERT_PRINT_POS(a) _BLI_assert_print_pos(__FILE__, __LINE__, __func__, # a) 48 | # elif defined(_MSC_VER) 49 | # define _BLI_ASSERT_PRINT_POS(a) _BLI_assert_print_pos(__FILE__, __LINE__, __func__, # a) 50 | # else 51 | # define _BLI_ASSERT_PRINT_POS(a) _BLI_assert_print_pos(__FILE__, __LINE__, "", # a) 52 | # endif 53 | /* _BLI_ASSERT_ABORT */ 54 | # ifdef WITH_ASSERT_ABORT 55 | # define _BLI_ASSERT_ABORT _BLI_assert_abort 56 | # else 57 | # define _BLI_ASSERT_ABORT() (void)0 58 | # endif 59 | /* BLI_assert */ 60 | # define BLI_assert(a) \ 61 | (void)((!(a)) ? ((_BLI_assert_print_backtrace(), \ 62 | _BLI_ASSERT_PRINT_POS(a), \ 63 | _BLI_ASSERT_ABORT(), \ 64 | NULL)) : \ 65 | NULL) 66 | /** A version of #BLI_assert() to pass an additional message to be printed on failure. */ 67 | # define BLI_assert_msg(a, msg) \ 68 | (void)((!(a)) ? ((_BLI_assert_print_backtrace(), \ 69 | _BLI_ASSERT_PRINT_POS(a), \ 70 | _BLI_assert_print_extra(msg), \ 71 | _BLI_ASSERT_ABORT(), \ 72 | NULL)) : \ 73 | NULL) 74 | #else 75 | # define BLI_assert(a) ((void)0) 76 | # define BLI_assert_msg(a, msg) ((void)0) 77 | #endif 78 | 79 | #if defined(__cplusplus) 80 | /* C++11 */ 81 | # define BLI_STATIC_ASSERT(a, msg) static_assert(a, msg); 82 | #elif defined(_MSC_VER) 83 | /* Visual Studio */ 84 | # if (_MSC_VER > 1910) && !defined(__clang__) 85 | # define BLI_STATIC_ASSERT(a, msg) static_assert(a, msg); 86 | # else 87 | # define BLI_STATIC_ASSERT(a, msg) _STATIC_ASSERT(a); 88 | # endif 89 | #elif defined(__COVERITY__) 90 | /* Workaround error with coverity */ 91 | # define BLI_STATIC_ASSERT(a, msg) 92 | #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) 93 | /* C11 */ 94 | # define BLI_STATIC_ASSERT(a, msg) _Static_assert(a, msg); 95 | #else 96 | /* Old unsupported compiler */ 97 | # define BLI_STATIC_ASSERT(a, msg) 98 | #endif 99 | 100 | #define BLI_STATIC_ASSERT_ALIGN(st, align) \ 101 | BLI_STATIC_ASSERT((sizeof(st) % (align) == 0), "Structure must be strictly aligned") 102 | 103 | /** 104 | * Indicates that this line of code should never be executed. If it is reached, it will abort in 105 | * debug builds and print an error in release builds. 106 | */ 107 | #define BLI_assert_unreachable() \ 108 | { \ 109 | _BLI_assert_unreachable_print(__FILE__, __LINE__, __func__); \ 110 | BLI_assert_msg(0, "This line of code is marked to be unreachable."); \ 111 | } \ 112 | ((void)0) 113 | 114 | #ifdef __cplusplus 115 | } 116 | #endif 117 | -------------------------------------------------------------------------------- /libs/blender/BLI_compiler_attrs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | * 16 | * The Original Code is Copyright (C) 2013 Blender Foundation. 17 | * All rights reserved. 18 | */ 19 | 20 | #pragma once 21 | 22 | /** \file 23 | * \ingroup bli 24 | */ 25 | 26 | /* hint to make sure function result is actually used */ 27 | #ifdef __GNUC__ 28 | # define ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) 29 | #else 30 | # define ATTR_WARN_UNUSED_RESULT 31 | #endif 32 | 33 | /* hint to mark function arguments expected to be non-null 34 | * if no arguments are given to the macro, all of pointer 35 | * arguments would be expected to be non-null 36 | */ 37 | #ifdef __GNUC__ 38 | # define ATTR_NONNULL(args...) __attribute__((nonnull(args))) 39 | #else 40 | # define ATTR_NONNULL(...) 41 | #endif 42 | 43 | /* never returns NULL */ 44 | #if (__GNUC__ * 100 + __GNUC_MINOR__) >= 409 /* gcc4.9+ only */ 45 | # define ATTR_RETURNS_NONNULL __attribute__((returns_nonnull)) 46 | #else 47 | # define ATTR_RETURNS_NONNULL 48 | #endif 49 | 50 | /* hint to mark function as it wouldn't return */ 51 | #if defined(__GNUC__) || defined(__clang__) 52 | # define ATTR_NORETURN __attribute__((noreturn)) 53 | #else 54 | # define ATTR_NORETURN 55 | #endif 56 | 57 | /* hint to treat any non-null function return value cannot alias any other pointer */ 58 | #if (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 403)) 59 | # define ATTR_MALLOC __attribute__((malloc)) 60 | #else 61 | # define ATTR_MALLOC 62 | #endif 63 | 64 | /* the function return value points to memory (2 args for 'size * tot') */ 65 | #if (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 403)) 66 | # define ATTR_ALLOC_SIZE(args...) __attribute__((alloc_size(args))) 67 | #else 68 | # define ATTR_ALLOC_SIZE(...) 69 | #endif 70 | 71 | /* ensures a NULL terminating argument as the n'th last argument of a variadic function */ 72 | #ifdef __GNUC__ 73 | # define ATTR_SENTINEL(arg_pos) __attribute__((sentinel(arg_pos))) 74 | #else 75 | # define ATTR_SENTINEL(arg_pos) 76 | #endif 77 | 78 | /* hint to compiler that function uses printf-style format string */ 79 | #ifdef __GNUC__ 80 | # define ATTR_PRINTF_FORMAT(format_param, dots_param) \ 81 | __attribute__((format(printf, format_param, dots_param))) 82 | #else 83 | # define ATTR_PRINTF_FORMAT(format_param, dots_param) 84 | #endif 85 | 86 | /* Use to suppress '-Wimplicit-fallthrough' (in place of 'break'). */ 87 | #ifndef ATTR_FALLTHROUGH 88 | # if defined(__GNUC__) && (__GNUC__ >= 7) /* gcc7.0+ only */ 89 | # define ATTR_FALLTHROUGH __attribute__((fallthrough)) 90 | # else 91 | # define ATTR_FALLTHROUGH ((void)0) 92 | # endif 93 | #endif 94 | 95 | /* Declare the memory alignment in Bytes. */ 96 | #if defined(_WIN32) && !defined(FREE_WINDOWS) 97 | # define ATTR_ALIGN(x) __declspec(align(x)) 98 | #else 99 | # define ATTR_ALIGN(x) __attribute__((aligned(x))) 100 | #endif 101 | 102 | /* Alignment directive */ 103 | #ifdef _WIN64 104 | # define ALIGN_STRUCT __declspec(align(64)) 105 | #else 106 | # define ALIGN_STRUCT 107 | #endif 108 | -------------------------------------------------------------------------------- /libs/blender/BLI_compiler_compat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | */ 16 | 17 | /* clang-format off */ 18 | 19 | /* #define typeof() triggers a bug in some clang-format versions, disable format 20 | * for entire file to keep results consistent. */ 21 | 22 | #pragma once 23 | 24 | 25 | /** \file 26 | * \ingroup bli 27 | * 28 | * Use to help with cross platform portability. 29 | */ 30 | 31 | #if defined(_MSC_VER) 32 | # define alloca _alloca 33 | #endif 34 | 35 | #if (defined(__GNUC__) || defined(__clang__)) && defined(__cplusplus) 36 | extern "C++" { 37 | /** Some magic to be sure we don't have reference in the type. */ 38 | template static inline T decltype_helper(T x) 39 | { 40 | return x; 41 | } 42 | #define typeof(x) decltype(decltype_helper(x)) 43 | } 44 | #endif 45 | 46 | /* little macro so inline keyword works */ 47 | #if defined(_MSC_VER) 48 | # define BLI_INLINE static __forceinline 49 | #else 50 | # define BLI_INLINE static inline __attribute__((always_inline)) __attribute__((__unused__)) 51 | #endif 52 | 53 | #if defined(__GNUC__) 54 | # define BLI_NOINLINE __attribute__((noinline)) 55 | #else 56 | # define BLI_NOINLINE 57 | #endif 58 | -------------------------------------------------------------------------------- /libs/blender/BLI_hash.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | */ 16 | 17 | #pragma once 18 | 19 | /** \file 20 | * \ingroup bli 21 | */ 22 | 23 | #include "BLI_utildefines.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /** 30 | * Jenkins Lookup3 Hash Functions. 31 | * Source: http://burtleburtle.net/bob/c/lookup3.c 32 | */ 33 | 34 | #define rot(x, k) (((x) << (k)) | ((x) >> (32 - (k)))) 35 | #define final(a, b, c) \ 36 | { \ 37 | c ^= b; \ 38 | c -= rot(b, 14); \ 39 | a ^= c; \ 40 | a -= rot(c, 11); \ 41 | b ^= a; \ 42 | b -= rot(a, 25); \ 43 | c ^= b; \ 44 | c -= rot(b, 16); \ 45 | a ^= c; \ 46 | a -= rot(c, 4); \ 47 | b ^= a; \ 48 | b -= rot(a, 14); \ 49 | c ^= b; \ 50 | c -= rot(b, 24); \ 51 | } \ 52 | ((void)0) 53 | 54 | BLI_INLINE unsigned int BLI_hash_int_3d(unsigned int kx, unsigned int ky, unsigned int kz) 55 | { 56 | unsigned int a, b, c; 57 | a = b = c = 0xdeadbeef + (3 << 2) + 13; 58 | 59 | c += kz; 60 | b += ky; 61 | a += kx; 62 | final(a, b, c); 63 | 64 | return c; 65 | } 66 | 67 | BLI_INLINE unsigned int BLI_hash_int_2d(unsigned int kx, unsigned int ky) 68 | { 69 | unsigned int a, b, c; 70 | 71 | a = b = c = 0xdeadbeef + (2 << 2) + 13; 72 | a += kx; 73 | b += ky; 74 | 75 | final(a, b, c); 76 | 77 | return c; 78 | } 79 | 80 | #undef final 81 | #undef rot 82 | 83 | BLI_INLINE unsigned int BLI_hash_string(const char *str) 84 | { 85 | unsigned int i = 0, c; 86 | 87 | while ((c = *str++)) { 88 | i = i * 37 + c; 89 | } 90 | return i; 91 | } 92 | 93 | BLI_INLINE float BLI_hash_int_2d_to_float(uint32_t kx, uint32_t ky) 94 | { 95 | return (float)BLI_hash_int_2d(kx, ky) / (float)0xFFFFFFFFu; 96 | } 97 | 98 | BLI_INLINE float BLI_hash_int_3d_to_float(uint32_t kx, uint32_t ky, uint32_t kz) 99 | { 100 | return (float)BLI_hash_int_3d(kx, ky, kz) / (float)0xFFFFFFFFu; 101 | } 102 | 103 | BLI_INLINE unsigned int BLI_hash_int(unsigned int k) 104 | { 105 | return BLI_hash_int_2d(k, 0); 106 | } 107 | 108 | BLI_INLINE float BLI_hash_int_01(unsigned int k) 109 | { 110 | return (float)BLI_hash_int(k) * (1.0f / (float)0xFFFFFFFF); 111 | } 112 | 113 | BLI_INLINE void BLI_hash_pointer_to_color(const void *ptr, int *r, int *g, int *b) 114 | { 115 | size_t val = (size_t)ptr; 116 | const size_t hash_a = BLI_hash_int(val & 0x0000ffff); 117 | const size_t hash_b = BLI_hash_int((uint)((val & 0xffff0000) >> 16)); 118 | const size_t hash = hash_a ^ (hash_b + 0x9e3779b9 + (hash_a << 6) + (hash_a >> 2)); 119 | *r = (hash & 0xff0000) >> 16; 120 | *g = (hash & 0x00ff00) >> 8; 121 | *b = hash & 0x0000ff; 122 | } 123 | 124 | #ifdef __cplusplus 125 | } 126 | #endif 127 | -------------------------------------------------------------------------------- /libs/blender/BLI_hash_md5.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | */ 16 | 17 | #pragma once 18 | 19 | /** \file 20 | * \ingroup bli 21 | */ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /** 28 | * Compute MD5 message digest for 'len' bytes beginning at 'buffer'. 29 | * The result is always in little endian byte order, 30 | * so that a byte-wise output yields to the wanted ASCII representation of the message digest. 31 | */ 32 | void *BLI_hash_md5_buffer(const char *buffer, size_t len, void *resblock); 33 | 34 | /** 35 | * Compute MD5 message digest for bytes read from 'stream'. 36 | * The resulting message digest number will be written into the 16 bytes beginning at 'resblock'. 37 | * \return Non-zero if an error occurred. 38 | */ 39 | int BLI_hash_md5_stream(FILE *stream, void *resblock); 40 | 41 | char *BLI_hash_md5_to_hexdigest(void *resblock, char r_hex_digest[33]); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | -------------------------------------------------------------------------------- /libs/blender/BLI_hash_mm2a.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | */ 16 | 17 | #pragma once 18 | 19 | /** \file 20 | * \ingroup bli 21 | */ 22 | 23 | #include "BLI_sys_types.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | typedef struct BLI_HashMurmur2A { 30 | uint32_t hash; 31 | uint32_t tail; 32 | uint32_t count; 33 | uint32_t size; 34 | } BLI_HashMurmur2A; 35 | 36 | void BLI_hash_mm2a_init(BLI_HashMurmur2A *mm2, uint32_t seed); 37 | 38 | void BLI_hash_mm2a_add(BLI_HashMurmur2A *mm2, const unsigned char *data, size_t len); 39 | 40 | void BLI_hash_mm2a_add_int(BLI_HashMurmur2A *mm2, int data); 41 | 42 | uint32_t BLI_hash_mm2a_end(BLI_HashMurmur2A *mm2); 43 | 44 | /** 45 | * Non-incremental version, quicker for small keys. 46 | */ 47 | uint32_t BLI_hash_mm2(const unsigned char *data, size_t len, uint32_t seed); 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | -------------------------------------------------------------------------------- /libs/blender/BLI_hash_mm3.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | */ 16 | 17 | #pragma once 18 | 19 | /** \file 20 | * \ingroup bli 21 | */ 22 | 23 | #include "BLI_sys_types.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | uint32_t BLI_hash_mm3(const unsigned char *data, size_t len, uint32_t seed); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | -------------------------------------------------------------------------------- /libs/blender/BLI_listbase_wrapper.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | */ 16 | 17 | #pragma once 18 | 19 | /** \file 20 | * \ingroup bli 21 | * 22 | * `blender::ListBaseWrapper` is a typed wrapper for the #ListBase struct. That makes it safer and 23 | * more convenient to use in C++ in some cases. However, if you find yourself iterating over a 24 | * linked list a lot, consider to convert it into a vector for further processing. This improves 25 | * performance and debug-ability. 26 | */ 27 | 28 | #include "BLI_listbase.h" 29 | #include "DNA_listBase.h" 30 | 31 | namespace blender { 32 | 33 | template class ListBaseWrapper { 34 | private: 35 | ListBase *listbase_; 36 | 37 | public: 38 | ListBaseWrapper(ListBase *listbase) : listbase_(listbase) 39 | { 40 | BLI_assert(listbase); 41 | } 42 | 43 | ListBaseWrapper(ListBase &listbase) : ListBaseWrapper(&listbase) 44 | { 45 | } 46 | 47 | class Iterator { 48 | private: 49 | ListBase *listbase_; 50 | T *current_; 51 | 52 | public: 53 | Iterator(ListBase *listbase, T *current) : listbase_(listbase), current_(current) 54 | { 55 | } 56 | 57 | Iterator &operator++() 58 | { 59 | /* Some types store next/prev using `void *`, so cast is necessary. */ 60 | current_ = static_cast(current_->next); 61 | return *this; 62 | } 63 | 64 | Iterator operator++(int) 65 | { 66 | Iterator iterator = *this; 67 | ++*this; 68 | return iterator; 69 | } 70 | 71 | bool operator!=(const Iterator &iterator) const 72 | { 73 | return current_ != iterator.current_; 74 | } 75 | 76 | T *operator*() const 77 | { 78 | return current_; 79 | } 80 | }; 81 | 82 | Iterator begin() const 83 | { 84 | return Iterator(listbase_, static_cast(listbase_->first)); 85 | } 86 | 87 | Iterator end() const 88 | { 89 | return Iterator(listbase_, nullptr); 90 | } 91 | 92 | T get(uint index) const 93 | { 94 | void *ptr = BLI_findlink(listbase_, index); 95 | BLI_assert(ptr); 96 | return static_cast(ptr); 97 | } 98 | 99 | int64_t index_of(const T *value) const 100 | { 101 | int64_t index = 0; 102 | for (T *ptr : *this) { 103 | if (ptr == value) { 104 | return index; 105 | } 106 | index++; 107 | } 108 | BLI_assert(false); 109 | return -1; 110 | } 111 | }; 112 | 113 | } /* namespace blender */ 114 | -------------------------------------------------------------------------------- /libs/blender/BLI_math.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | * 16 | * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 17 | * All rights reserved. 18 | * 19 | * The Original Code is: some of this file. 20 | */ 21 | 22 | #pragma once 23 | 24 | /** \file 25 | * \ingroup bli 26 | * 27 | * \section mathabbrev Abbreviations 28 | * 29 | * - `fl` = float 30 | * - `db` = double 31 | * - `v2` = vec2 = vector 2 32 | * - `v3` = vec3 = vector 3 33 | * - `v4` = vec4 = vector 4 34 | * - `vn` = vec4 = vector N dimensions, *passed as an arg, after the vector*. 35 | * - `qt` = quat = quaternion 36 | * - `dq` = dquat = dual quaternion 37 | * - `m2` = mat2 = matrix 2x2 38 | * - `m3` = mat3 = matrix 3x3 39 | * - `m4` = mat4 = matrix 4x4 40 | * - `eul` = euler rotation 41 | * - `eulO` = euler with order 42 | * - `plane` = plane 4, (vec3, distance) 43 | * - `plane3` = plane 3 (same as a `plane` with a zero 4th component) 44 | * 45 | * \subsection mathabbrev_all Function Type Abbreviations 46 | * 47 | * For non float versions of functions (which typically operate on floats), 48 | * use single suffix abbreviations. 49 | * 50 | * - `_d` = double 51 | * - `_i` = int 52 | * - `_u` = unsigned int 53 | * - `_char` = char 54 | * - `_uchar` = unsigned char 55 | * 56 | * \section mathvarnames Variable Names 57 | * 58 | * - f = single value 59 | * - a, b, c = vectors 60 | * - r = result vector 61 | * - A, B, C = matrices 62 | * - R = result matrix 63 | */ 64 | 65 | #include "BLI_math_base.h" 66 | #include "BLI_math_color.h" 67 | #include "BLI_math_geom.h" 68 | #include "BLI_math_interp.h" 69 | #include "BLI_math_matrix.h" 70 | #include "BLI_math_rotation.h" 71 | #include "BLI_math_solvers.h" 72 | #include "BLI_math_statistics.h" 73 | #include "BLI_math_time.h" 74 | #include "BLI_math_vector.h" 75 | -------------------------------------------------------------------------------- /libs/blender/BLI_math_base_safe.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | */ 16 | 17 | #pragma once 18 | 19 | /** \file 20 | * \ingroup bli 21 | * 22 | * This file provides safe alternatives to common math functions like sqrt, powf. 23 | * In this context "safe" means that the output is not NaN if the input is not NaN. 24 | */ 25 | 26 | #include "BLI_math_base.h" 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | MINLINE float safe_divide(float a, float b); 33 | MINLINE float safe_modf(float a, float b); 34 | MINLINE float safe_logf(float a, float base); 35 | MINLINE float safe_sqrtf(float a); 36 | MINLINE float safe_inverse_sqrtf(float a); 37 | MINLINE float safe_asinf(float a); 38 | MINLINE float safe_acosf(float a); 39 | MINLINE float safe_powf(float base, float exponent); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #if BLI_MATH_DO_INLINE 46 | # include "intern/math_base_safe_inline.c" 47 | #endif 48 | -------------------------------------------------------------------------------- /libs/blender/BLI_math_bits.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | */ 16 | 17 | #pragma once 18 | 19 | /** \file 20 | * \ingroup bli 21 | */ 22 | 23 | #include "BLI_math_inline.h" 24 | #include "BLI_utildefines.h" 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Search the value from LSB to MSB for a set bit. Returns index of this bit. */ 31 | 32 | MINLINE int bitscan_forward_i(int a); 33 | MINLINE unsigned int bitscan_forward_uint(unsigned int a); 34 | MINLINE unsigned int bitscan_forward_uint64(unsigned long long a); 35 | 36 | /* Similar to above, but also clears the bit. */ 37 | 38 | MINLINE int bitscan_forward_clear_i(int *a); 39 | MINLINE unsigned int bitscan_forward_clear_uint(unsigned int *a); 40 | 41 | /* Search the value from MSB to LSB for a set bit. Returns index of this bit. */ 42 | 43 | MINLINE int bitscan_reverse_i(int a); 44 | MINLINE unsigned int bitscan_reverse_uint(unsigned int a); 45 | MINLINE unsigned int bitscan_reverse_uint64(unsigned long long a); 46 | 47 | /* Similar to above, but also clears the bit. */ 48 | 49 | MINLINE int bitscan_reverse_clear_i(int *a); 50 | MINLINE unsigned int bitscan_reverse_clear_uint(unsigned int *a); 51 | 52 | /* NOTE: Those functions returns 2 to the power of index of highest order bit. */ 53 | 54 | MINLINE unsigned int highest_order_bit_uint(unsigned int n); 55 | MINLINE unsigned short highest_order_bit_s(unsigned short n); 56 | 57 | #ifdef __GNUC__ 58 | # define count_bits_i(i) __builtin_popcount(i) 59 | #else 60 | MINLINE int count_bits_i(unsigned int n); 61 | #endif 62 | 63 | MINLINE int float_as_int(float f); 64 | MINLINE unsigned int float_as_uint(float f); 65 | MINLINE float int_as_float(int i); 66 | MINLINE float uint_as_float(unsigned int i); 67 | MINLINE float xor_fl(float x, int y); 68 | 69 | #if BLI_MATH_DO_INLINE 70 | # include "intern/math_bits_inline.c" 71 | #endif 72 | 73 | #ifdef __cplusplus 74 | } 75 | #endif 76 | -------------------------------------------------------------------------------- /libs/blender/BLI_math_boolean.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | */ 16 | 17 | #pragma once 18 | 19 | /** \file 20 | * \ingroup bli 21 | * \brief Math vector functions needed specifically for mesh intersect and boolean. 22 | */ 23 | 24 | #include "BLI_math_vec_types.hh" 25 | 26 | #ifdef WITH_GMP 27 | # include "BLI_math_mpq.hh" 28 | # include "BLI_math_vec_mpq_types.hh" 29 | #endif 30 | 31 | namespace blender { 32 | 33 | /** 34 | * #orient2d gives the exact result, using multi-precision arithmetic when result 35 | * is close to zero. orient3d_fast just uses double arithmetic, so may be 36 | * wrong if the answer is very close to zero. 37 | * Similarly, for #incircle and #incircle_fast. 38 | */ 39 | int orient2d(const double2 &a, const double2 &b, const double2 &c); 40 | int orient2d_fast(const double2 &a, const double2 &b, const double2 &c); 41 | 42 | int incircle(const double2 &a, const double2 &b, const double2 &c, const double2 &d); 43 | int incircle_fast(const double2 &a, const double2 &b, const double2 &c, const double2 &d); 44 | 45 | /** 46 | * #orient3d gives the exact result, using multi-precision arithmetic when result 47 | * is close to zero. orient3d_fast just uses double arithmetic, so may be 48 | * wrong if the answer is very close to zero. 49 | * Similarly, for #insphere and #insphere_fast. 50 | */ 51 | int orient3d(const double3 &a, const double3 &b, const double3 &c, const double3 &d); 52 | int orient3d_fast(const double3 &a, const double3 &b, const double3 &c, const double3 &d); 53 | 54 | int insphere( 55 | const double3 &a, const double3 &b, const double3 &c, const double3 &d, const double3 &e); 56 | int insphere_fast( 57 | const double3 &a, const double3 &b, const double3 &c, const double3 &d, const double3 &e); 58 | 59 | #ifdef WITH_GMP 60 | /** 61 | * Return +1 if a, b, c are in CCW order around a circle in the plane. 62 | * Return -1 if they are in CW order, and 0 if they are in line. 63 | */ 64 | int orient2d(const mpq2 &a, const mpq2 &b, const mpq2 &c); 65 | /** 66 | * Return +1 if d is in the oriented circle through a, b, and c. 67 | * The oriented circle goes CCW through a, b, and c. 68 | * Return -1 if d is outside, and 0 if it is on the circle. 69 | */ 70 | int incircle(const mpq2 &a, const mpq2 &b, const mpq2 &c, const mpq2 &d); 71 | /** 72 | * Return +1 if d is below the plane containing a, b, c (which appear 73 | * CCW when viewed from above the plane). 74 | * Return -1 if d is above the plane. 75 | * Return 0 if it is on the plane. 76 | */ 77 | int orient3d(const mpq3 &a, const mpq3 &b, const mpq3 &c, const mpq3 &d); 78 | #endif 79 | } // namespace blender 80 | -------------------------------------------------------------------------------- /libs/blender/BLI_math_inline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | * 16 | * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 17 | * All rights reserved. 18 | * 19 | * The Original Code is: some of this file. 20 | */ 21 | 22 | #pragma once 23 | 24 | /** \file 25 | * \ingroup bli 26 | */ 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | /* add platform/compiler checks here if it is not supported */ 33 | /* all platforms support forcing inline so this is always enabled */ 34 | #define BLI_MATH_DO_INLINE 1 35 | 36 | #if BLI_MATH_DO_INLINE 37 | # ifdef _MSC_VER 38 | # define MINLINE static __forceinline 39 | # define MALWAYS_INLINE MINLINE 40 | # else 41 | # define MINLINE static inline 42 | # define MALWAYS_INLINE static inline __attribute__((always_inline)) __attribute__((unused)) 43 | # endif 44 | #else 45 | # define MINLINE 46 | # define MALWAYS_INLINE 47 | #endif 48 | 49 | /* gcc 4.6 (supports push/pop) */ 50 | #if (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 406)) 51 | # define BLI_MATH_GCC_WARN_PRAGMA 1 52 | #endif 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | -------------------------------------------------------------------------------- /libs/blender/BLI_math_interp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | * 16 | * The Original Code is Copyright (C) 2012 by Blender Foundation. 17 | * All rights reserved. 18 | */ 19 | 20 | #pragma once 21 | 22 | /** \file 23 | * \ingroup bli 24 | */ 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | void BLI_bicubic_interpolation_fl( 31 | const float *buffer, float *output, int width, int height, int components, float u, float v); 32 | 33 | void BLI_bicubic_interpolation_char(const unsigned char *buffer, 34 | unsigned char *output, 35 | int width, 36 | int height, 37 | int components, 38 | float u, 39 | float v); 40 | 41 | void BLI_bilinear_interpolation_fl( 42 | const float *buffer, float *output, int width, int height, int components, float u, float v); 43 | 44 | void BLI_bilinear_interpolation_char(const unsigned char *buffer, 45 | unsigned char *output, 46 | int width, 47 | int height, 48 | int components, 49 | float u, 50 | float v); 51 | 52 | void BLI_bilinear_interpolation_wrap_fl(const float *buffer, 53 | float *output, 54 | int width, 55 | int height, 56 | int components, 57 | float u, 58 | float v, 59 | bool wrap_x, 60 | bool wrap_y); 61 | 62 | void BLI_bilinear_interpolation_wrap_char(const unsigned char *buffer, 63 | unsigned char *output, 64 | int width, 65 | int height, 66 | int components, 67 | float u, 68 | float v, 69 | bool wrap_x, 70 | bool wrap_y); 71 | 72 | #define EWA_MAXIDX 255 73 | extern const float EWA_WTS[EWA_MAXIDX + 1]; 74 | 75 | typedef void (*ewa_filter_read_pixel_cb)(void *userdata, int x, int y, float result[4]); 76 | 77 | void BLI_ewa_imp2radangle( 78 | float A, float B, float C, float F, float *a, float *b, float *th, float *ecc); 79 | 80 | /** 81 | * TODO(sergey): Consider making this function inlined, so the pixel read callback 82 | * could also be inlined in order to avoid per-pixel function calls. 83 | */ 84 | void BLI_ewa_filter(int width, 85 | int height, 86 | bool intpol, 87 | bool use_alpha, 88 | const float uv[2], 89 | const float du[2], 90 | const float dv[2], 91 | ewa_filter_read_pixel_cb read_pixel_cb, 92 | void *userdata, 93 | float result[4]); 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | -------------------------------------------------------------------------------- /libs/blender/BLI_math_mpq.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | */ 16 | 17 | #pragma once 18 | 19 | /** \file 20 | * \ingroup bli 21 | */ 22 | 23 | #ifdef WITH_GMP 24 | 25 | /* This file uses an external file header to define the multi-precision 26 | * rational type, mpq_class. 27 | * This class keeps separate multi-precision integer numerator and 28 | * denominator, reduced to lowest terms after each arithmetic operation. 29 | * It can be used where it is important to have exact arithmetic results. 30 | * 31 | * See gmplib.org for full documentation. In particular: 32 | * https://gmplib.org/manual/C_002b_002b-Interface-Rationals 33 | */ 34 | # include "gmpxx.h" 35 | 36 | #endif /* WITH_GMP */ 37 | -------------------------------------------------------------------------------- /libs/blender/BLI_math_solvers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | * 16 | * The Original Code is Copyright (C) 2015 by Blender Foundation 17 | * All rights reserved. 18 | */ 19 | 20 | #pragma once 21 | 22 | /** \file 23 | * \ingroup bli 24 | */ 25 | 26 | #include "BLI_compiler_attrs.h" 27 | #include "BLI_math_inline.h" 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | #ifdef BLI_MATH_GCC_WARN_PRAGMA 34 | # pragma GCC diagnostic push 35 | # pragma GCC diagnostic ignored "-Wredundant-decls" 36 | #endif 37 | 38 | /* -------------------------------------------------------------------- */ 39 | /** \name Eigen Solvers 40 | * \{ */ 41 | 42 | /** 43 | * \brief Compute the eigen values and/or vectors of given 3D symmetric (aka adjoint) matrix. 44 | * 45 | * \param m3: the 3D symmetric matrix. 46 | * \return r_eigen_values the computed eigen values (NULL if not needed). 47 | * \return r_eigen_vectors the computed eigen vectors (NULL if not needed). 48 | */ 49 | bool BLI_eigen_solve_selfadjoint_m3(const float m3[3][3], 50 | float r_eigen_values[3], 51 | float r_eigen_vectors[3][3]); 52 | 53 | /** 54 | * \brief Compute the SVD (Singular Values Decomposition) of given 3D matrix (m3 = USV*). 55 | * 56 | * \param m3: the matrix to decompose. 57 | * \return r_U the computed left singular vector of \a m3 (NULL if not needed). 58 | * \return r_S the computed singular values of \a m3 (NULL if not needed). 59 | * \return r_V the computed right singular vector of \a m3 (NULL if not needed). 60 | */ 61 | void BLI_svd_m3(const float m3[3][3], float r_U[3][3], float r_S[3], float r_V[3][3]); 62 | 63 | /** \} */ 64 | 65 | /* -------------------------------------------------------------------- */ 66 | /** \name Simple Solvers 67 | * \{ */ 68 | 69 | /** 70 | * \brief Solve a tridiagonal system of equations: 71 | * 72 | * a[i] * r_x[i-1] + b[i] * r_x[i] + c[i] * r_x[i+1] = d[i] 73 | * 74 | * Ignores a[0] and c[count-1]. Uses the Thomas algorithm, e.g. see wiki. 75 | * 76 | * \param r_x: output vector, may be shared with any of the input ones 77 | * \return true if success 78 | */ 79 | bool BLI_tridiagonal_solve( 80 | const float *a, const float *b, const float *c, const float *d, float *r_x, int count); 81 | /** 82 | * \brief Solve a possibly cyclic tridiagonal system using the Sherman-Morrison formula. 83 | * 84 | * \param r_x: output vector, may be shared with any of the input ones 85 | * \return true if success 86 | */ 87 | bool BLI_tridiagonal_solve_cyclic( 88 | const float *a, const float *b, const float *c, const float *d, float *r_x, int count); 89 | 90 | /** 91 | * Generic 3 variable Newton's method solver. 92 | */ 93 | typedef void (*Newton3D_DeltaFunc)(void *userdata, const float x[3], float r_delta[3]); 94 | typedef void (*Newton3D_JacobianFunc)(void *userdata, const float x[3], float r_jacobian[3][3]); 95 | typedef bool (*Newton3D_CorrectionFunc)(void *userdata, 96 | const float x[3], 97 | float step[3], 98 | float x_next[3]); 99 | 100 | /** 101 | * \brief Solve a generic f(x) = 0 equation using Newton's method. 102 | * 103 | * \param func_delta: Callback computing the value of f(x). 104 | * \param func_jacobian: Callback computing the Jacobian matrix of the function at x. 105 | * \param func_correction: Callback for forcing the search into an arbitrary custom domain. 106 | * May be NULL. 107 | * \param userdata: Data for the callbacks. 108 | * \param epsilon: Desired precision. 109 | * \param max_iterations: Limit on the iterations. 110 | * \param trace: Enables logging to console. 111 | * \param x_init: Initial solution vector. 112 | * \param result: Final result. 113 | * \return true if success 114 | */ 115 | bool BLI_newton3d_solve(Newton3D_DeltaFunc func_delta, 116 | Newton3D_JacobianFunc func_jacobian, 117 | Newton3D_CorrectionFunc func_correction, 118 | void *userdata, 119 | float epsilon, 120 | int max_iterations, 121 | bool trace, 122 | const float x_init[3], 123 | float result[3]); 124 | 125 | #ifdef BLI_MATH_GCC_WARN_PRAGMA 126 | # pragma GCC diagnostic pop 127 | #endif 128 | 129 | /** \} */ 130 | 131 | #ifdef __cplusplus 132 | } 133 | #endif 134 | -------------------------------------------------------------------------------- /libs/blender/BLI_math_statistics.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | * 16 | * The Original Code is Copyright (C) 2015 by Blender Foundation 17 | * All rights reserved. 18 | */ 19 | 20 | #pragma once 21 | 22 | /** \file 23 | * \ingroup bli 24 | */ 25 | 26 | #include "BLI_compiler_attrs.h" 27 | #include "BLI_math_inline.h" 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | #ifdef BLI_MATH_GCC_WARN_PRAGMA 34 | # pragma GCC diagnostic push 35 | # pragma GCC diagnostic ignored "-Wredundant-decls" 36 | #endif 37 | 38 | /* -------------------------------------------------------------------- */ 39 | /** \name Covariance Matrices 40 | * \{ */ 41 | 42 | /** 43 | * \brief Compute the covariance matrix of given set of nD coordinates. 44 | * 45 | * \param n: the dimension of the vectors (and hence, of the covariance matrix to compute). 46 | * \param cos_vn: the nD points to compute covariance from. 47 | * \param nbr_cos_vn: the number of nD coordinates in cos_vn. 48 | * \param center: the center (or mean point) of cos_vn. If NULL, 49 | * it is assumed cos_vn is already centered. 50 | * \param use_sample_correction: whether to apply sample correction 51 | * (i.e. get 'sample variance' instead of 'population variance'). 52 | * \return r_covmat the computed covariance matrix. 53 | */ 54 | void BLI_covariance_m_vn_ex(int n, 55 | const float *cos_vn, 56 | int nbr_cos_vn, 57 | const float *center, 58 | bool use_sample_correction, 59 | float *r_covmat); 60 | /** 61 | * \brief Compute the covariance matrix of given set of 3D coordinates. 62 | * 63 | * \param cos_v3: the 3D points to compute covariance from. 64 | * \param nbr_cos_v3: the number of 3D coordinates in cos_v3. 65 | * \return r_covmat the computed covariance matrix. 66 | * \return r_center the computed center (mean) of 3D points (may be NULL). 67 | */ 68 | void BLI_covariance_m3_v3n(const float (*cos_v3)[3], 69 | int nbr_cos_v3, 70 | bool use_sample_correction, 71 | float r_covmat[3][3], 72 | float r_center[3]); 73 | 74 | #ifdef BLI_MATH_GCC_WARN_PRAGMA 75 | # pragma GCC diagnostic pop 76 | #endif 77 | 78 | /** \} */ 79 | 80 | #ifdef __cplusplus 81 | } 82 | #endif 83 | -------------------------------------------------------------------------------- /libs/blender/BLI_math_time.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | * 16 | * The Original Code is Copyright (C) 2021 by Blender Foundation. 17 | * All rights reserved. 18 | */ 19 | 20 | #pragma once 21 | 22 | /** \file 23 | * \ingroup bli 24 | */ 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* -------------------------------------------------------------------- */ 31 | /** \name Time Constants Definitions 32 | * \{ */ 33 | 34 | #define SECONDS_IN_MILLISECONDS 0.001 35 | #define SECONDS_IN_MINUTE 60.0 36 | #define MINUTES_IN_HOUR 60.0 37 | #define HOURS_IN_DAY 24.0 38 | 39 | #define MINUTES_IN_DAY (MINUTES_IN_HOUR * HOURS_IN_DAY) 40 | #define SECONDS_IN_DAY (MINUTES_IN_DAY * SECONDS_IN_MINUTE) 41 | #define SECONDS_IN_HOUR (MINUTES_IN_HOUR * SECONDS_IN_MINUTE) 42 | 43 | /** \} */ 44 | 45 | /* -------------------------------------------------------------------- */ 46 | /** \name Time API 47 | * \{ */ 48 | 49 | /** 50 | * Explode given time value expressed in seconds, into a set of days, hours, minutes, seconds 51 | * and/or milliseconds (depending on which return parameters are not NULL). 52 | * 53 | * \note The smallest given return parameter will get the potential fractional remaining time 54 | * value. E.g. if you give `seconds=90.0` and do not pass `r_seconds` and `r_milliseconds`, 55 | * `r_minutes` will be set to `1.5`. 56 | */ 57 | void BLI_math_time_seconds_decompose(double seconds, 58 | double *r_days, 59 | double *r_hours, 60 | double *r_minutes, 61 | double *r_seconds, 62 | double *r_milliseconds); 63 | 64 | /** \} */ 65 | 66 | /* -------------------------------------------------------------------- */ 67 | /** \name Inline Definitions 68 | * \{ */ 69 | 70 | /* None. */ 71 | 72 | /** \} */ 73 | 74 | #ifdef __cplusplus 75 | } 76 | #endif 77 | -------------------------------------------------------------------------------- /libs/blender/BLI_math_vec_mpq_types.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | */ 16 | 17 | #pragma once 18 | 19 | /** \file 20 | * \ingroup bli 21 | */ 22 | 23 | #include "BLI_math_vec_types.hh" 24 | 25 | #ifdef WITH_GMP 26 | 27 | # include "BLI_math_mpq.hh" 28 | 29 | namespace blender { 30 | 31 | using mpq2 = vec_base; 32 | using mpq3 = vec_base; 33 | 34 | namespace math { 35 | 36 | uint64_t hash_mpq_class(const mpq_class &value); 37 | 38 | template<> inline uint64_t vector_hash(const mpq2 &vec) 39 | { 40 | return hash_mpq_class(vec.x) ^ (hash_mpq_class(vec.y) * 33); 41 | } 42 | 43 | template<> inline uint64_t vector_hash(const mpq3 &vec) 44 | { 45 | return hash_mpq_class(vec.x) ^ (hash_mpq_class(vec.y) * 33) ^ (hash_mpq_class(vec.z) * 33 * 37); 46 | } 47 | 48 | /** 49 | * Cannot do this exactly in rational arithmetic! 50 | * Approximate by going in and out of doubles. 51 | */ 52 | template<> inline mpq_class length(const mpq2 &a) 53 | { 54 | return mpq_class(sqrt(length_squared(a).get_d())); 55 | } 56 | 57 | /** 58 | * Cannot do this exactly in rational arithmetic! 59 | * Approximate by going in and out of doubles. 60 | */ 61 | template<> inline mpq_class length(const mpq3 &a) 62 | { 63 | return mpq_class(sqrt(length_squared(a).get_d())); 64 | } 65 | 66 | /** 67 | * The buffer avoids allocating a temporary variable. 68 | */ 69 | inline mpq_class distance_squared_with_buffer(const mpq3 &a, const mpq3 &b, mpq3 &buffer) 70 | { 71 | buffer = a; 72 | buffer -= b; 73 | return dot(buffer, buffer); 74 | } 75 | 76 | /** 77 | * The buffer avoids allocating a temporary variable. 78 | */ 79 | inline mpq_class dot_with_buffer(const mpq3 &a, const mpq3 &b, mpq3 &buffer) 80 | { 81 | buffer = a; 82 | buffer *= b; 83 | buffer.x += buffer.y; 84 | buffer.x += buffer.z; 85 | return buffer.x; 86 | } 87 | 88 | } // namespace math 89 | 90 | } // namespace blender 91 | 92 | #endif /* WITH_GMP */ 93 | -------------------------------------------------------------------------------- /libs/blender/BLI_memory_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | */ 16 | 17 | /* Use a define instead of `#pragma once` because of `BLI_utildefines.h` */ 18 | #ifndef __BLI_MEMORY_UTILS_H__ 19 | #define __BLI_MEMORY_UTILS_H__ 20 | 21 | /** \file 22 | * \ingroup bli 23 | * \brief Generic memory manipulation API. 24 | */ 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* it may be defined already */ 31 | #ifndef __BLI_UTILDEFINES_H__ 32 | bool BLI_memory_is_zero(const void *arr, size_t size); 33 | #endif 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif /* __BLI_MEMORY_UTILS_H__ */ 40 | -------------------------------------------------------------------------------- /libs/blender/BLI_simd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | */ 16 | 17 | #pragma once 18 | 19 | /** \file 20 | * \ingroup bli 21 | * 22 | * SIMD instruction support. 23 | */ 24 | 25 | #if defined(__ARM_NEON) && defined(WITH_SSE2NEON) 26 | /* SSE/SSE2 emulation on ARM Neon. Match SSE precision. */ 27 | # define SSE2NEON_PRECISE_MINMAX 1 28 | # define SSE2NEON_PRECISE_DIV 1 29 | # define SSE2NEON_PRECISE_SQRT 1 30 | # include 31 | # define BLI_HAVE_SSE2 32 | #elif defined(__SSE2__) 33 | /* Native SSE2 on Intel/AMD. */ 34 | # include 35 | # define BLI_HAVE_SSE2 36 | #endif 37 | -------------------------------------------------------------------------------- /libs/blender/BLI_strict_flags.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | */ 16 | 17 | #pragma once 18 | 19 | /** \file 20 | * \ingroup bli 21 | * \brief Strict compiler flags for areas of code we want 22 | * to ensure don't do conversions without us knowing about it. 23 | */ 24 | 25 | #ifdef __GNUC__ 26 | # if (__GNUC__ * 100 + __GNUC_MINOR__) >= 406 /* gcc4.6+ only */ 27 | # pragma GCC diagnostic error "-Wsign-compare" 28 | # endif 29 | # if __GNUC__ >= 6 /* gcc6+ only */ 30 | # pragma GCC diagnostic error "-Wconversion" 31 | # endif 32 | # if (__GNUC__ * 100 + __GNUC_MINOR__) >= 408 33 | /* gcc4.8+ only (behavior changed to ignore globals). */ 34 | # pragma GCC diagnostic error "-Wshadow" 35 | /* older gcc changed behavior with ternary */ 36 | # pragma GCC diagnostic error "-Wsign-conversion" 37 | # endif 38 | /* pedantic gives too many issues, developers can define this for own use */ 39 | # ifdef WARN_PEDANTIC 40 | # pragma GCC diagnostic error "-Wpedantic" 41 | # ifdef __clang__ /* pedantic causes clang error */ 42 | # pragma GCC diagnostic ignored "-Wlanguage-extension-token" 43 | # endif 44 | # endif 45 | #endif 46 | 47 | #ifdef _MSC_VER 48 | # pragma warning(error : 4018) /* signed/unsigned mismatch */ 49 | # pragma warning(error : 4244) /* conversion from 'type1' to 'type2', possible loss of data */ 50 | # pragma warning(error : 4245) /* conversion from 'int' to 'unsigned int' */ 51 | # pragma warning(error : 4267) /* conversion from 'size_t' to 'type', possible loss of data */ 52 | # pragma warning(error : 4305) /* truncation from 'type1' to 'type2' */ 53 | # pragma warning(error : 4389) /* signed/unsigned mismatch */ 54 | #endif 55 | -------------------------------------------------------------------------------- /libs/blender/BLI_string_cursor_utf8.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | * 16 | * The Original Code is Copyright (C) 2011 Blender Foundation. 17 | * All rights reserved. 18 | */ 19 | 20 | #pragma once 21 | 22 | /** \file 23 | * \ingroup bli 24 | */ 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | typedef enum eStrCursorJumpType { 31 | STRCUR_JUMP_NONE, 32 | STRCUR_JUMP_DELIM, 33 | STRCUR_JUMP_ALL, 34 | } eStrCursorJumpType; 35 | 36 | typedef enum eStrCursorJumpDirection { 37 | STRCUR_DIR_PREV, 38 | STRCUR_DIR_NEXT, 39 | } eStrCursorJumpDirection; 40 | 41 | bool BLI_str_cursor_step_next_utf8(const char *str, size_t maxlen, int *pos); 42 | bool BLI_str_cursor_step_prev_utf8(const char *str, size_t maxlen, int *pos); 43 | 44 | void BLI_str_cursor_step_utf8(const char *str, 45 | size_t maxlen, 46 | int *pos, 47 | eStrCursorJumpDirection direction, 48 | eStrCursorJumpType jump, 49 | bool use_init_step); 50 | 51 | void BLI_str_cursor_step_utf32(const char32_t *str, 52 | size_t maxlen, 53 | int *pos, 54 | eStrCursorJumpDirection direction, 55 | eStrCursorJumpType jump, 56 | bool use_init_step); 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | -------------------------------------------------------------------------------- /libs/blender/BLI_string_search.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | */ 16 | 17 | #pragma once 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | typedef struct StringSearch StringSearch; 24 | 25 | StringSearch *BLI_string_search_new(void); 26 | /** 27 | * Add a new possible result to the search. 28 | * The caller keeps ownership of all parameters. 29 | * 30 | * \param weight: Can be used to customize the order when multiple items have the same match score. 31 | */ 32 | void BLI_string_search_add(StringSearch *search, const char *str, void *user_data, int weight); 33 | 34 | /** 35 | * Filter and sort all previously added search items. 36 | * Returns an array containing the filtered user data. 37 | * The caller has to free the returned array. 38 | */ 39 | int BLI_string_search_query(StringSearch *search, const char *query, void ***r_data); 40 | void BLI_string_search_free(StringSearch *search); 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #ifdef __cplusplus 47 | 48 | # include "BLI_linear_allocator.hh" 49 | # include "BLI_span.hh" 50 | # include "BLI_string_ref.hh" 51 | # include "BLI_vector.hh" 52 | 53 | namespace blender::string_search { 54 | 55 | /** 56 | * Computes the cost of transforming string a into b. The cost/distance is the minimal number of 57 | * operations that need to be executed. Valid operations are deletion, insertion, substitution and 58 | * transposition. 59 | * 60 | * This function is utf8 aware in the sense that it works at the level of individual code points 61 | * (1-4 bytes long) instead of on individual bytes. 62 | */ 63 | int damerau_levenshtein_distance(StringRef a, StringRef b); 64 | /** 65 | * Returns -1 when this is no reasonably good match. 66 | * Otherwise returns the number of errors in the match. 67 | */ 68 | int get_fuzzy_match_errors(StringRef query, StringRef full); 69 | /** 70 | * Splits a string into words and normalizes them (currently that just means converting to lower 71 | * case). The returned strings are allocated in the given allocator. 72 | */ 73 | void extract_normalized_words(StringRef str, 74 | LinearAllocator<> &allocator, 75 | Vector &r_words); 76 | 77 | } // namespace blender::string_search 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /libs/blender/BLI_sys_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | * 16 | * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 17 | * All rights reserved. 18 | */ 19 | 20 | /** \file 21 | * \ingroup bli 22 | * 23 | * A platform-independent definition of [u]intXX_t 24 | * Plus the accompanying header include for htonl/ntohl 25 | * 26 | * This file includes to define [u]intXX_t types, where 27 | * XX can be 8, 16, 32 or 64. Unfortunately, not all systems have this 28 | * file. 29 | * - Windows uses __intXX compiler-builtin types. These are signed, 30 | * so we have to flip the signs. 31 | * For these rogue platforms, we make the typedefs ourselves. 32 | */ 33 | 34 | #pragma once 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | #if defined(__linux__) || defined(__GNU__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ 41 | defined(__FreeBSD_kernel__) || defined(__HAIKU__) 42 | 43 | /* Linux-i386, Linux-Alpha, Linux-PPC */ 44 | # include 45 | 46 | /* XXX */ 47 | # ifndef UINT64_MAX 48 | # define UINT64_MAX 18446744073709551615 49 | typedef uint8_t u_int8_t; 50 | typedef uint16_t u_int16_t; 51 | typedef uint32_t u_int32_t; 52 | typedef uint64_t u_int64_t; 53 | # endif 54 | 55 | #elif defined(__APPLE__) 56 | 57 | # include 58 | 59 | /* MSVC >= 2010 */ 60 | #elif defined(_MSC_VER) 61 | # include 62 | 63 | #else 64 | 65 | /* FreeBSD, Solaris */ 66 | # include 67 | # include 68 | 69 | #endif /* ifdef platform for types */ 70 | 71 | #include 72 | #include /* size_t define */ 73 | 74 | #ifndef __cplusplus 75 | /* The standard header is missing on some systems. */ 76 | # if defined(__APPLE__) || defined(__NetBSD__) 77 | typedef unsigned int char32_t; 78 | # else 79 | # include 80 | # endif 81 | #endif 82 | 83 | typedef unsigned int uint; 84 | typedef unsigned short ushort; 85 | typedef unsigned long ulong; 86 | typedef unsigned char uchar; 87 | 88 | #ifdef __cplusplus 89 | } 90 | #endif 91 | -------------------------------------------------------------------------------- /libs/blender/BLI_system.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | */ 16 | 17 | #pragma once 18 | 19 | #include 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | /** \file 26 | * \ingroup bli 27 | */ 28 | 29 | int BLI_cpu_support_sse2(void); 30 | int BLI_cpu_support_sse41(void); 31 | void BLI_system_backtrace(FILE *fp); 32 | 33 | /** Get CPU brand, result is to be MEM_freeN()-ed. */ 34 | char *BLI_cpu_brand_string(void); 35 | 36 | /** 37 | * Obtain the hostname from the system. 38 | * 39 | * This simply determines the host's name, and doesn't do any DNS lookup of any 40 | * IP address of the machine. As such, it's only usable for identification 41 | * purposes, and not for reachability over a network. 42 | * 43 | * \param buffer: Character buffer to write the hostname into. 44 | * \param bufsize: Size of the character buffer, including trailing '\0'. 45 | */ 46 | void BLI_hostname_get(char *buffer, size_t bufsize); 47 | 48 | /** Get maximum addressable memory in megabytes. */ 49 | size_t BLI_system_memory_max_in_megabytes(void); 50 | /** Get maximum addressable memory in megabytes (clamped to #INT_MAX). */ 51 | int BLI_system_memory_max_in_megabytes_int(void); 52 | 53 | /* For `getpid`. */ 54 | #ifdef WIN32 55 | # define BLI_SYSTEM_PID_H 56 | 57 | /** 58 | * \note Use `void *` for `exception` since we really do not want to drag Windows.h 59 | * in to get the proper `typedef`. 60 | */ 61 | void BLI_windows_handle_exception(void *exception); 62 | 63 | #else 64 | # define BLI_SYSTEM_PID_H 65 | #endif 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | -------------------------------------------------------------------------------- /libs/blender/BLI_utildefines_variadic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | */ 16 | 17 | #pragma once 18 | 19 | /** \file 20 | * \ingroup bli 21 | */ 22 | 23 | /* Over wrapped args. */ 24 | /* clang-format off */ 25 | 26 | /* --- internal helpers --- */ 27 | #define _VA_NARGS_GLUE(x, y) x y 28 | #define _VA_NARGS_RETURN_COUNT(\ 29 | _1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, _9_, _10_, _11_, _12_, _13_, _14_, _15_, _16_, \ 30 | _17_, _18_, _19_, _20_, _21_, _22_, _23_, _24_, _25_, _26_, _27_, _28_, _29_, _30_, _31_, _32_, \ 31 | _33_, _34_, _35_, _36_, _37_, _38_, _39_, _40_, _41_, _42_, _43_, _44_, _45_, _46_, _47_, _48_, \ 32 | _49_, _50_, _51_, _52_, _53_, _54_, _55_, _56_, _57_, _58_, _59_, _60_, _61_, _62_, _63_, _64_, \ 33 | count, ...) count 34 | #define _VA_NARGS_EXPAND(args) _VA_NARGS_RETURN_COUNT args 35 | #define _VA_NARGS_OVERLOAD_MACRO2(name, count) name##count 36 | #define _VA_NARGS_OVERLOAD_MACRO1(name, count) _VA_NARGS_OVERLOAD_MACRO2(name, count) 37 | #define _VA_NARGS_OVERLOAD_MACRO(name, count) _VA_NARGS_OVERLOAD_MACRO1(name, count) 38 | /* --- expose for re-use --- */ 39 | /* 64 args max */ 40 | #define VA_NARGS_COUNT(...) _VA_NARGS_EXPAND((__VA_ARGS__, \ 41 | 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, \ 42 | 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, \ 43 | 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, \ 44 | 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)) 45 | #define VA_NARGS_CALL_OVERLOAD(name, ...) \ 46 | _VA_NARGS_GLUE(_VA_NARGS_OVERLOAD_MACRO(name, VA_NARGS_COUNT(__VA_ARGS__)), (__VA_ARGS__)) 47 | 48 | /* clang-format on */ 49 | -------------------------------------------------------------------------------- /libs/blender/BLI_vector_set_slots.hh: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | */ 16 | 17 | #pragma once 18 | 19 | /** \file 20 | * \ingroup bli 21 | * 22 | * This file contains slot types that are supposed to be used with blender::VectorSet. 23 | * 24 | * Every slot type has to be able to hold an integer index and state information. 25 | * A vector set slot has three possible states: empty, occupied and removed. 26 | * 27 | * A vector slot type has to implement a couple of methods that are explained in 28 | * SimpleVectorSetSlot. 29 | * A vector slot type is assumed to be trivially destructible, when it is in empty or removed 30 | * state. 31 | * 32 | * Possible Improvements: 33 | * - Implement a slot type that stores the hash. 34 | * - Implement a slot type that stores the key. That means that the key would be stored in two 35 | * places: the key vector and the slot itself. Maybe storing the key in the slot as well, can 36 | * result in better performance, due to better cache utilization. 37 | */ 38 | 39 | #include "BLI_sys_types.h" 40 | 41 | namespace blender { 42 | 43 | /** 44 | * The simplest possible vector set slot. It stores the index and state in a signed integer. If the 45 | * value is negative, it represents empty or occupied state. Otherwise it represents the index. 46 | */ 47 | template class SimpleVectorSetSlot { 48 | private: 49 | #define s_is_empty -1 50 | #define s_is_removed -2 51 | 52 | /** 53 | * After the default constructor has run, the slot has to be in the empty state. 54 | */ 55 | int64_t state_ = s_is_empty; 56 | 57 | public: 58 | /** 59 | * Return true if this slot contains an index to a key. 60 | */ 61 | bool is_occupied() const 62 | { 63 | return state_ >= 0; 64 | } 65 | 66 | /** 67 | * Return true if the slot is empty, i.e. it does not contain an index. 68 | */ 69 | bool is_empty() const 70 | { 71 | return state_ == s_is_empty; 72 | } 73 | 74 | /** 75 | * Return the stored index. It is assumed that the slot is occupied. 76 | */ 77 | int64_t index() const 78 | { 79 | BLI_assert(this->is_occupied()); 80 | return state_; 81 | } 82 | 83 | /** 84 | * Return true if the slot contains the given key, i.e. its index points to a key that compares 85 | * equal to it. The hash can be used by other implementations to determine inequality faster. 86 | */ 87 | template 88 | bool contains(const ForwardKey &key, 89 | const IsEqual &is_equal, 90 | uint64_t UNUSED(hash), 91 | const Key *keys) const 92 | { 93 | if (state_ >= 0) { 94 | return is_equal(key, keys[state_]); 95 | } 96 | return false; 97 | } 98 | 99 | /** 100 | * Change the state of this slot from empty/removed to occupied. The hash can be used by other 101 | * slot implementations. 102 | */ 103 | void occupy(int64_t index, uint64_t UNUSED(hash)) 104 | { 105 | BLI_assert(!this->is_occupied()); 106 | state_ = index; 107 | } 108 | 109 | /** 110 | * The key has changed its position in the vector, so the index has to be updated. This method 111 | * can assume that the slot is currently occupied. 112 | */ 113 | void update_index(int64_t index) 114 | { 115 | BLI_assert(this->is_occupied()); 116 | state_ = index; 117 | } 118 | 119 | /** 120 | * Change the state of this slot from occupied to removed. 121 | */ 122 | void remove() 123 | { 124 | BLI_assert(this->is_occupied()); 125 | state_ = s_is_removed; 126 | } 127 | 128 | /** 129 | * Return true if this slot is currently occupied and its corresponding key has the given index. 130 | */ 131 | bool has_index(int64_t index) const 132 | { 133 | return state_ == index; 134 | } 135 | 136 | /** 137 | * Return the hash of the currently stored key. In this simple set slot implementation, we just 138 | * compute the hash here. Other implementations might store the hash in the slot instead. 139 | */ 140 | template uint64_t get_hash(const Key &key, const Hash &hash) const 141 | { 142 | BLI_assert(this->is_occupied()); 143 | return hash(key); 144 | } 145 | 146 | #undef s_is_empty 147 | #undef s_is_removed 148 | }; 149 | 150 | template struct DefaultVectorSetSlot; 151 | 152 | template struct DefaultVectorSetSlot { 153 | using type = SimpleVectorSetSlot; 154 | }; 155 | 156 | } // namespace blender 157 | -------------------------------------------------------------------------------- /libs/blender/DNA_ID_enums.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | */ 16 | 17 | /** \file 18 | * \ingroup DNA 19 | * \brief Enumerations for `DNA_ID.h`. 20 | */ 21 | 22 | #pragma once 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | enum eIconSizes { 29 | ICON_SIZE_ICON = 0, 30 | ICON_SIZE_PREVIEW = 1, 31 | 32 | NUM_ICON_SIZES, 33 | }; 34 | 35 | /** 36 | * Defines for working with IDs. 37 | * 38 | * The tags represent types! This is a dirty way of enabling RTTI. The 39 | * sig_byte end endian defines aren't really used much. 40 | */ 41 | 42 | #ifdef __BIG_ENDIAN__ 43 | /* big endian */ 44 | # define MAKE_ID2(c, d) ((c) << 8 | (d)) 45 | #else 46 | /* little endian */ 47 | # define MAKE_ID2(c, d) ((d) << 8 | (c)) 48 | #endif 49 | 50 | /** 51 | * ID from database. 52 | * 53 | * Written to #BHead.code (for file IO) 54 | * and the first 2 bytes of #ID.name (for runtime checks, see #GS macro). 55 | */ 56 | typedef enum ID_Type { 57 | ID_SCE = MAKE_ID2('S', 'C'), /* Scene */ 58 | ID_LI = MAKE_ID2('L', 'I'), /* Library */ 59 | ID_OB = MAKE_ID2('O', 'B'), /* Object */ 60 | ID_ME = MAKE_ID2('M', 'E'), /* Mesh */ 61 | ID_CU = MAKE_ID2('C', 'U'), /* Curve */ 62 | ID_MB = MAKE_ID2('M', 'B'), /* MetaBall */ 63 | ID_MA = MAKE_ID2('M', 'A'), /* Material */ 64 | ID_TE = MAKE_ID2('T', 'E'), /* Tex (Texture) */ 65 | ID_IM = MAKE_ID2('I', 'M'), /* Image */ 66 | ID_LT = MAKE_ID2('L', 'T'), /* Lattice */ 67 | ID_LA = MAKE_ID2('L', 'A'), /* Light */ 68 | ID_CA = MAKE_ID2('C', 'A'), /* Camera */ 69 | ID_IP = MAKE_ID2('I', 'P'), /* Ipo (depreciated, replaced by FCurves) */ 70 | ID_KE = MAKE_ID2('K', 'E'), /* Key (shape key) */ 71 | ID_WO = MAKE_ID2('W', 'O'), /* World */ 72 | ID_SCR = MAKE_ID2('S', 'R'), /* Screen */ 73 | ID_VF = MAKE_ID2('V', 'F'), /* VFont (Vector Font) */ 74 | ID_TXT = MAKE_ID2('T', 'X'), /* Text */ 75 | ID_SPK = MAKE_ID2('S', 'K'), /* Speaker */ 76 | ID_SO = MAKE_ID2('S', 'O'), /* Sound */ 77 | ID_GR = MAKE_ID2('G', 'R'), /* Collection */ 78 | ID_AR = MAKE_ID2('A', 'R'), /* bArmature */ 79 | ID_AC = MAKE_ID2('A', 'C'), /* bAction */ 80 | ID_NT = MAKE_ID2('N', 'T'), /* bNodeTree */ 81 | ID_BR = MAKE_ID2('B', 'R'), /* Brush */ 82 | ID_PA = MAKE_ID2('P', 'A'), /* ParticleSettings */ 83 | ID_GD = MAKE_ID2('G', 'D'), /* bGPdata, (Grease Pencil) */ 84 | ID_WM = MAKE_ID2('W', 'M'), /* WindowManager */ 85 | ID_MC = MAKE_ID2('M', 'C'), /* MovieClip */ 86 | ID_MSK = MAKE_ID2('M', 'S'), /* Mask */ 87 | ID_LS = MAKE_ID2('L', 'S'), /* FreestyleLineStyle */ 88 | ID_PAL = MAKE_ID2('P', 'L'), /* Palette */ 89 | ID_PC = MAKE_ID2('P', 'C'), /* PaintCurve */ 90 | ID_CF = MAKE_ID2('C', 'F'), /* CacheFile */ 91 | ID_WS = MAKE_ID2('W', 'S'), /* WorkSpace */ 92 | ID_LP = MAKE_ID2('L', 'P'), /* LightProbe */ 93 | ID_HA = MAKE_ID2('H', 'A'), /* Hair */ 94 | ID_PT = MAKE_ID2('P', 'T'), /* PointCloud */ 95 | ID_VO = MAKE_ID2('V', 'O'), /* Volume */ 96 | ID_SIM = MAKE_ID2('S', 'I'), /* Simulation (geometry node groups) */ 97 | } ID_Type; 98 | 99 | /* Only used as 'placeholder' in .blend files for directly linked data-blocks. */ 100 | #define ID_LINK_PLACEHOLDER MAKE_ID2('I', 'D') /* (internal use only) */ 101 | 102 | /* Deprecated. */ 103 | #define ID_SCRN MAKE_ID2('S', 'N') 104 | 105 | /* NOTE: Fake IDs, needed for `g.sipo->blocktype` or outliner. */ 106 | #define ID_SEQ MAKE_ID2('S', 'Q') 107 | /* constraint */ 108 | #define ID_CO MAKE_ID2('C', 'O') 109 | /* pose (action channel, used to be ID_AC in code, so we keep code for backwards compatible). */ 110 | #define ID_PO MAKE_ID2('A', 'C') 111 | /* used in outliner... */ 112 | #define ID_NLA MAKE_ID2('N', 'L') 113 | /* fluidsim Ipo */ 114 | #define ID_FLUIDSIM MAKE_ID2('F', 'S') 115 | 116 | #ifdef __cplusplus 117 | } 118 | #endif 119 | -------------------------------------------------------------------------------- /libs/blender/DNA_color_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | * 16 | * The Original Code is Copyright (C) 2006 Blender Foundation. 17 | * All rights reserved. 18 | */ 19 | 20 | /** \file 21 | * \ingroup DNA 22 | */ 23 | 24 | #pragma once 25 | 26 | #include "DNA_defs.h" 27 | #include "DNA_vec_types.h" 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | /* general defines for kernel functions */ 34 | #define CM_RESOL 32 35 | #define CM_TABLE 256 36 | #define CM_TABLEDIV (1.0f / 256.0f) 37 | 38 | #define CM_TOT 4 39 | 40 | typedef struct CurveMapPoint { 41 | float x, y; 42 | /** Shorty for result lookup. */ 43 | short flag, shorty; 44 | } CurveMapPoint; 45 | 46 | /** #CurveMapPoint.flag */ 47 | enum { 48 | CUMA_SELECT = (1 << 0), 49 | CUMA_HANDLE_VECTOR = (1 << 1), 50 | CUMA_HANDLE_AUTO_ANIM = (1 << 2), 51 | }; 52 | 53 | typedef struct CurveMap { 54 | short totpoint; 55 | short flag DNA_DEPRECATED; 56 | 57 | /** Quick multiply value for reading table. */ 58 | float range; 59 | /** The x-axis range for the table. */ 60 | float mintable, maxtable; 61 | /** For extrapolated curves, the direction vector. */ 62 | float ext_in[2], ext_out[2]; 63 | /** Actual curve. */ 64 | CurveMapPoint *curve; 65 | /** Display and evaluate table. */ 66 | CurveMapPoint *table; 67 | 68 | /** For RGB curves, pre-multiplied table. */ 69 | CurveMapPoint *premultable; 70 | /** For RGB curves, pre-multiplied extrapolation vector. */ 71 | float premul_ext_in[2]; 72 | float premul_ext_out[2]; 73 | } CurveMap; 74 | 75 | typedef struct CurveMapping { 76 | /** Cur; for buttons, to show active curve. */ 77 | int flag, cur; 78 | int preset; 79 | int changed_timestamp; 80 | 81 | /** Current rect, clip rect (is default rect too). */ 82 | rctf curr, clipr; 83 | 84 | /** Max 4 builtin curves per mapping struct now. */ 85 | CurveMap cm[4]; 86 | /** Black/white point (black[0] abused for current frame). */ 87 | float black[3], white[3]; 88 | /** Black/white point multiply value, for speed. */ 89 | float bwmul[3]; 90 | 91 | /** Sample values, if flag set it draws line and intersection. */ 92 | float sample[3]; 93 | 94 | short tone; 95 | char _pad[6]; 96 | } CurveMapping; 97 | 98 | /** #CurveMapping.flag */ 99 | typedef enum eCurveMappingFlags { 100 | CUMA_DO_CLIP = (1 << 0), 101 | CUMA_PREMULLED = (1 << 1), 102 | CUMA_DRAW_CFRA = (1 << 2), 103 | CUMA_DRAW_SAMPLE = (1 << 3), 104 | 105 | /** The curve is extended by extrapolation. When not set the curve is extended horizontally. */ 106 | CUMA_EXTEND_EXTRAPOLATE = (1 << 4), 107 | } eCurveMappingFlags; 108 | 109 | /** #CurveMapping.preset */ 110 | typedef enum eCurveMappingPreset { 111 | CURVE_PRESET_LINE = 0, 112 | CURVE_PRESET_SHARP = 1, 113 | CURVE_PRESET_SMOOTH = 2, 114 | CURVE_PRESET_MAX = 3, 115 | CURVE_PRESET_MID9 = 4, 116 | CURVE_PRESET_ROUND = 5, 117 | CURVE_PRESET_ROOT = 6, 118 | CURVE_PRESET_GAUSS = 7, 119 | CURVE_PRESET_BELL = 8, 120 | } eCurveMappingPreset; 121 | 122 | /** #CurveMapping.tone */ 123 | typedef enum eCurveMappingTone { 124 | CURVE_TONE_STANDARD = 0, 125 | CURVE_TONE_FILMLIKE = 2, 126 | } eCurveMappingTone; 127 | 128 | /** #Histogram.mode */ 129 | enum { 130 | HISTO_MODE_LUMA = 0, 131 | HISTO_MODE_RGB = 1, 132 | HISTO_MODE_R = 2, 133 | HISTO_MODE_G = 3, 134 | HISTO_MODE_B = 4, 135 | HISTO_MODE_ALPHA = 5, 136 | }; 137 | 138 | enum { 139 | HISTO_FLAG_LINE = (1 << 0), 140 | HISTO_FLAG_SAMPLELINE = (1 << 1), 141 | }; 142 | 143 | typedef struct Histogram { 144 | int channels; 145 | int x_resolution; 146 | float data_luma[256]; 147 | float data_r[256]; 148 | float data_g[256]; 149 | float data_b[256]; 150 | float data_a[256]; 151 | float xmax, ymax; 152 | short mode; 153 | short flag; 154 | int height; 155 | 156 | /** Sample line only (image coords: source -> destination). */ 157 | float co[2][2]; 158 | } Histogram; 159 | 160 | typedef struct Scopes { 161 | int ok; 162 | int sample_full; 163 | int sample_lines; 164 | float accuracy; 165 | int wavefrm_mode; 166 | float wavefrm_alpha; 167 | float wavefrm_yfac; 168 | int wavefrm_height; 169 | float vecscope_alpha; 170 | int vecscope_height; 171 | float minmax[3][2]; 172 | struct Histogram hist; 173 | float *waveform_1; 174 | float *waveform_2; 175 | float *waveform_3; 176 | float *vecscope; 177 | int waveform_tot; 178 | char _pad[4]; 179 | } Scopes; 180 | 181 | /** #Scopes.wavefrm_mode */ 182 | enum { 183 | SCOPES_WAVEFRM_LUMA = 0, 184 | SCOPES_WAVEFRM_RGB_PARADE = 1, 185 | SCOPES_WAVEFRM_YCC_601 = 2, 186 | SCOPES_WAVEFRM_YCC_709 = 3, 187 | SCOPES_WAVEFRM_YCC_JPEG = 4, 188 | SCOPES_WAVEFRM_RGB = 5, 189 | }; 190 | 191 | typedef struct ColorManagedViewSettings { 192 | int flag; 193 | char _pad[4]; 194 | /** Look which is being applied when displaying buffer on the screen 195 | * (prior to view transform). */ 196 | char look[64]; 197 | /** View transform which is being applied when displaying buffer on the screen. */ 198 | char view_transform[64]; 199 | /** F-stop exposure. */ 200 | float exposure; 201 | /** Post-display gamma transform. */ 202 | float gamma; 203 | /** Pre-display RGB curves transform. */ 204 | struct CurveMapping *curve_mapping; 205 | void *_pad2; 206 | } ColorManagedViewSettings; 207 | 208 | typedef struct ColorManagedDisplaySettings { 209 | char display_device[64]; 210 | } ColorManagedDisplaySettings; 211 | 212 | typedef struct ColorManagedColorspaceSettings { 213 | /** MAX_COLORSPACE_NAME. */ 214 | char name[64]; 215 | } ColorManagedColorspaceSettings; 216 | 217 | /** #ColorManagedViewSettings.flag */ 218 | enum { 219 | COLORMANAGE_VIEW_USE_CURVES = (1 << 0), 220 | }; 221 | 222 | #ifdef __cplusplus 223 | } 224 | #endif 225 | -------------------------------------------------------------------------------- /libs/blender/DNA_defaults.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * This program is free software; you can redistribute it and/or 4 | * modify it under the terms of the GNU General Public License 5 | * as published by the Free Software Foundation; either version 2 6 | * of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | * GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program; if not, write to the Free Software Foundation, 15 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 16 | * 17 | * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 18 | * All rights reserved. 19 | */ 20 | 21 | /** \file 22 | * \ingroup DNA 23 | * 24 | * \see dna_defaults.c for details on how to use this system. 25 | */ 26 | 27 | #pragma once 28 | 29 | #include "BLI_utildefines.h" 30 | 31 | #include "dna_type_offsets.h" 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | extern const void *DNA_default_table[SDNA_TYPE_MAX]; 38 | 39 | uint8_t *_DNA_struct_default_alloc_impl(const uint8_t *data_src, 40 | size_t size, 41 | const char *alloc_str); 42 | 43 | /** 44 | * Wrap with macro that casts correctly. 45 | */ 46 | #define DNA_struct_default_get(struct_name) \ 47 | (const struct_name *)DNA_default_table[SDNA_TYPE_FROM_STRUCT(struct_name)] 48 | 49 | #define DNA_struct_default_alloc(struct_name) \ 50 | (struct_name *)_DNA_struct_default_alloc_impl( \ 51 | (const uint8_t *)DNA_default_table[SDNA_TYPE_FROM_STRUCT(struct_name)], \ 52 | sizeof(struct_name), \ 53 | __func__) 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | -------------------------------------------------------------------------------- /libs/blender/DNA_defs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | */ 16 | 17 | /** \file 18 | * \ingroup DNA 19 | * 20 | * Group generic defines for all DNA headers may use in this file. 21 | */ 22 | 23 | #pragma once 24 | 25 | /* makesdna ignores */ 26 | #ifdef DNA_DEPRECATED_ALLOW 27 | /* allow use of deprecated items */ 28 | # define DNA_DEPRECATED 29 | #else 30 | # ifndef DNA_DEPRECATED 31 | # ifdef __GNUC__ 32 | # define DNA_DEPRECATED __attribute__((deprecated)) 33 | # else 34 | /* TODO: MSVC & others. */ 35 | # define DNA_DEPRECATED 36 | # endif 37 | # endif 38 | #endif 39 | 40 | #ifdef __GNUC__ 41 | # define DNA_PRIVATE_ATTR __attribute__((deprecated)) 42 | #else 43 | # define DNA_PRIVATE_ATTR 44 | #endif 45 | 46 | /* poison pragma */ 47 | #ifdef DNA_DEPRECATED_ALLOW 48 | # define DNA_DEPRECATED_GCC_POISON 0 49 | #else 50 | /* enable the pragma if we can */ 51 | # ifdef __GNUC__ 52 | # define DNA_DEPRECATED_GCC_POISON 1 53 | # else 54 | # define DNA_DEPRECATED_GCC_POISON 0 55 | # endif 56 | #endif 57 | 58 | /* hrmf, we need a better include then this */ 59 | #include "BLI_sys_types.h" /* needed for int64_t only! */ 60 | 61 | /* non-id name variables should use this length */ 62 | #define MAX_NAME 64 63 | -------------------------------------------------------------------------------- /libs/blender/DNA_lineart_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | * 16 | * The Original Code is Copyright (C) 2010 Blender Foundation. 17 | * All rights reserved. 18 | */ 19 | 20 | #pragma once 21 | 22 | /** \file 23 | * \ingroup DNA 24 | */ 25 | 26 | #include "DNA_ID.h" 27 | #include "DNA_listBase.h" 28 | 29 | /* Notice that we need to have this file although no struct defines. 30 | * Edge flags and usage flags are used by with scene/object/gpencil modifier bits, and those values 31 | * needs to stay consistent throughout. */ 32 | 33 | /* These flags are used for 1 time calculation, not stroke selection afterwards. */ 34 | typedef enum eLineartMainFlags { 35 | LRT_INTERSECTION_AS_CONTOUR = (1 << 0), 36 | LRT_EVERYTHING_AS_CONTOUR = (1 << 1), 37 | LRT_ALLOW_DUPLI_OBJECTS = (1 << 2), 38 | LRT_ALLOW_OVERLAPPING_EDGES = (1 << 3), 39 | LRT_ALLOW_CLIPPING_BOUNDARIES = (1 << 4), 40 | LRT_REMOVE_DOUBLES = (1 << 5), 41 | LRT_LOOSE_AS_CONTOUR = (1 << 6), 42 | LRT_GPENCIL_INVERT_SOURCE_VGROUP = (1 << 7), 43 | LRT_GPENCIL_MATCH_OUTPUT_VGROUP = (1 << 8), 44 | LRT_FILTER_FACE_MARK = (1 << 9), 45 | LRT_FILTER_FACE_MARK_INVERT = (1 << 10), 46 | LRT_FILTER_FACE_MARK_BOUNDARIES = (1 << 11), 47 | LRT_CHAIN_LOOSE_EDGES = (1 << 12), 48 | LRT_CHAIN_GEOMETRY_SPACE = (1 << 13), 49 | LRT_ALLOW_OVERLAP_EDGE_TYPES = (1 << 14), 50 | LRT_USE_CREASE_ON_SMOOTH_SURFACES = (1 << 15), 51 | LRT_USE_CREASE_ON_SHARP_EDGES = (1 << 16), 52 | LRT_USE_CUSTOM_CAMERA = (1 << 17), 53 | LRT_FILTER_FACE_MARK_KEEP_CONTOUR = (1 << 18), 54 | LRT_USE_BACK_FACE_CULLING = (1 << 19), 55 | LRT_USE_IMAGE_BOUNDARY_TRIMMING = (1 << 20), 56 | LRT_CHAIN_PRESERVE_DETAILS = (1 << 22), 57 | } eLineartMainFlags; 58 | 59 | typedef enum eLineartEdgeFlag { 60 | LRT_EDGE_FLAG_EDGE_MARK = (1 << 0), 61 | LRT_EDGE_FLAG_CONTOUR = (1 << 1), 62 | LRT_EDGE_FLAG_CREASE = (1 << 2), 63 | LRT_EDGE_FLAG_MATERIAL = (1 << 3), 64 | LRT_EDGE_FLAG_INTERSECTION = (1 << 4), 65 | LRT_EDGE_FLAG_LOOSE = (1 << 5), 66 | LRT_EDGE_FLAG_CHAIN_PICKED = (1 << 6), 67 | LRT_EDGE_FLAG_CLIPPED = (1 << 7), 68 | /** Limited to 8 bits, DON'T ADD ANYMORE until improvements on the data structure. */ 69 | } eLineartEdgeFlag; 70 | 71 | #define LRT_EDGE_FLAG_ALL_TYPE 0x3f 72 | -------------------------------------------------------------------------------- /libs/blender/DNA_listBase.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | * 16 | * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 17 | * All rights reserved. 18 | */ 19 | 20 | /** \file 21 | * \ingroup DNA 22 | * \brief These structs are the foundation for all linked lists in the library system. 23 | * 24 | * Doubly-linked lists start from a ListBase and contain elements beginning 25 | * with Link. 26 | */ 27 | 28 | #pragma once 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /** Generic - all structs which are put into linked lists begin with this. */ 35 | typedef struct Link { 36 | struct Link *next, *prev; 37 | } Link; 38 | 39 | /** Simple subclass of Link. Use this when it is not worth defining a custom one. */ 40 | typedef struct LinkData { 41 | struct LinkData *next, *prev; 42 | void *data; 43 | } LinkData; 44 | 45 | /** Never change the size of this! dna_genfile.c detects pointer_size with it. */ 46 | typedef struct ListBase { 47 | void *first, *last; 48 | } ListBase; 49 | 50 | /* 8 byte alignment! */ 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | -------------------------------------------------------------------------------- /libs/blender/DNA_object_defaults.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | */ 16 | 17 | /** \file 18 | * \ingroup DNA 19 | */ 20 | 21 | #pragma once 22 | 23 | #include "DNA_vec_defaults.h" 24 | 25 | /* Struct members on own line. */ 26 | /* clang-format off */ 27 | 28 | /* -------------------------------------------------------------------- */ 29 | /** \name Object Struct 30 | * \{ */ 31 | 32 | #define _DNA_DEFAULT_Object \ 33 | { \ 34 | /* Type is not very meaningful as a default, normally changed. */ \ 35 | .type = OB_EMPTY, \ 36 | .color = {1, 1, 1, 1}, \ 37 | \ 38 | .constinv = _DNA_DEFAULT_UNIT_M4, \ 39 | .parentinv = _DNA_DEFAULT_UNIT_M4, \ 40 | .obmat = _DNA_DEFAULT_UNIT_M4, \ 41 | \ 42 | .scale = {1, 1, 1}, \ 43 | .dscale = {1, 1, 1}, \ 44 | /* Objects should default to having Euler XYZ rotations, \ 45 | * but rotations default to quaternions. */ \ 46 | .rotmode = ROT_MODE_EUL, \ 47 | /** See #unit_axis_angle. */ \ 48 | .rotAxis = {0, 1, 0}, \ 49 | .rotAngle = 0, \ 50 | .drotAxis = {0, 1, 0}, \ 51 | .drotAngle = 0, \ 52 | .quat = _DNA_DEFAULT_UNIT_QT, \ 53 | .dquat = _DNA_DEFAULT_UNIT_QT, \ 54 | .protectflag = OB_LOCK_ROT4D, \ 55 | \ 56 | .dt = OB_TEXTURE, \ 57 | \ 58 | .empty_drawtype = OB_PLAINAXES, \ 59 | .empty_drawsize = 1.0, \ 60 | .empty_image_depth = OB_EMPTY_IMAGE_DEPTH_DEFAULT, \ 61 | .ima_ofs = {-0.5, -0.5}, \ 62 | \ 63 | .instance_faces_scale = 1, \ 64 | .col_group = 0x01, \ 65 | .col_mask = 0xffff, \ 66 | .preview = NULL, \ 67 | .duplicator_visibility_flag = OB_DUPLI_FLAG_VIEWPORT | OB_DUPLI_FLAG_RENDER, \ 68 | .pc_ids = {NULL, NULL}, \ 69 | .lineart = { .crease_threshold = DEG2RAD(140.0f) }, \ 70 | } 71 | 72 | /** \} */ 73 | 74 | /* clang-format on */ 75 | -------------------------------------------------------------------------------- /libs/blender/DNA_object_enums.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | */ 16 | 17 | /** \file 18 | * \ingroup DNA 19 | * 20 | * Enums typedef's for use in public headers. 21 | */ 22 | 23 | #pragma once 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /** #Object.mode */ 30 | typedef enum eObjectMode { 31 | OB_MODE_OBJECT = 0, 32 | OB_MODE_EDIT = 1 << 0, 33 | OB_MODE_SCULPT = 1 << 1, 34 | OB_MODE_VERTEX_PAINT = 1 << 2, 35 | OB_MODE_WEIGHT_PAINT = 1 << 3, 36 | OB_MODE_TEXTURE_PAINT = 1 << 4, 37 | OB_MODE_PARTICLE_EDIT = 1 << 5, 38 | OB_MODE_POSE = 1 << 6, 39 | OB_MODE_EDIT_GPENCIL = 1 << 7, 40 | OB_MODE_PAINT_GPENCIL = 1 << 8, 41 | OB_MODE_SCULPT_GPENCIL = 1 << 9, 42 | OB_MODE_WEIGHT_GPENCIL = 1 << 10, 43 | OB_MODE_VERTEX_GPENCIL = 1 << 11, 44 | } eObjectMode; 45 | 46 | /** #Object.dt, #View3DShading.type */ 47 | typedef enum eDrawType { 48 | OB_BOUNDBOX = 1, 49 | OB_WIRE = 2, 50 | OB_SOLID = 3, 51 | OB_MATERIAL = 4, 52 | OB_TEXTURE = 5, 53 | OB_RENDER = 6, 54 | } eDrawType; 55 | 56 | /** Any mode where the brush system is used. */ 57 | #define OB_MODE_ALL_PAINT \ 58 | (OB_MODE_SCULPT | OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT) 59 | 60 | #define OB_MODE_ALL_PAINT_GPENCIL \ 61 | (OB_MODE_PAINT_GPENCIL | OB_MODE_SCULPT_GPENCIL | OB_MODE_WEIGHT_GPENCIL | \ 62 | OB_MODE_VERTEX_GPENCIL) 63 | 64 | /** Any mode that uses Object.sculpt. */ 65 | #define OB_MODE_ALL_SCULPT (OB_MODE_SCULPT | OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT) 66 | 67 | /** Any mode that uses weightpaint. */ 68 | #define OB_MODE_ALL_WEIGHT_PAINT (OB_MODE_WEIGHT_PAINT | OB_MODE_WEIGHT_GPENCIL) 69 | 70 | /** 71 | * Any mode that has data or for Grease Pencil modes, we need to free when switching modes, 72 | * see: #ED_object_mode_generic_exit 73 | */ 74 | #define OB_MODE_ALL_MODE_DATA \ 75 | (OB_MODE_EDIT | OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_SCULPT | OB_MODE_POSE | \ 76 | OB_MODE_PAINT_GPENCIL | OB_MODE_EDIT_GPENCIL | OB_MODE_SCULPT_GPENCIL | \ 77 | OB_MODE_WEIGHT_GPENCIL | OB_MODE_VERTEX_GPENCIL) 78 | 79 | #ifdef __cplusplus 80 | } 81 | #endif 82 | -------------------------------------------------------------------------------- /libs/blender/DNA_object_fluidsim_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | * 16 | * The Original Code is Copyright (C) 2004-2005 by Blender Foundation 17 | * All rights reserved. 18 | */ 19 | 20 | /** \file 21 | * \ingroup DNA 22 | */ 23 | 24 | #pragma once 25 | 26 | #include "DNA_ID.h" 27 | #include "DNA_defs.h" 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | struct Ipo; 34 | 35 | typedef struct FluidVertexVelocity { 36 | float vel[3]; 37 | } FluidVertexVelocity; 38 | 39 | typedef struct FluidsimSettings { 40 | /** For fast RNA access. */ 41 | struct FluidsimModifierData *fmd; 42 | /* threadcont the calculation is done with */ 43 | int threads; 44 | char _pad1[4]; 45 | /* domain, fluid or obstacle */ 46 | short type; 47 | /* Display advanced options in fluid sim tab (on=1, off=0). */ 48 | short show_advancedoptions; 49 | 50 | /* domain object settings */ 51 | /* resolutions */ 52 | short resolutionxyz; 53 | short previewresxyz; 54 | /* size of the domain in real units (meters along largest resolution x, y, z extent) */ 55 | float realsize; 56 | /* show original meshes, preview or final sim */ 57 | short guiDisplayMode; 58 | short renderDisplayMode; 59 | 60 | /* fluid properties */ 61 | float viscosityValue; 62 | short viscosityMode DNA_DEPRECATED; 63 | short viscosityExponent; 64 | /* gravity strength */ 65 | float grav[3]; 66 | /* anim start end time (in seconds) */ 67 | float animStart, animEnd; 68 | /* bake start end time (in blender frames) */ 69 | int bakeStart, bakeEnd; 70 | /* offset for baked frames */ 71 | int frameOffset; 72 | char _pad2[4]; 73 | /* g star param (LBM compressibility) */ 74 | float gstar; 75 | /* activate refinement? */ 76 | int maxRefine; 77 | 78 | /* fluid object type settings */ 79 | /* gravity strength */ 80 | float iniVelx, iniVely, iniVelz; 81 | 82 | /* store output path, and file prefix for baked fluid surface */ 83 | /* strlens; 256= FILE_MAXFILE, 768= FILE_MAXDIR */ 84 | char surfdataPath[1024]; 85 | 86 | /* store start coords of axis aligned bounding box together with size */ 87 | /* values are inited during derived mesh display */ 88 | float bbStart[3], bbSize[3]; 89 | 90 | /* animated params */ 91 | struct Ipo *ipo; 92 | 93 | /* additional flags depending on the type, lower short contains flags 94 | * to check validity, higher short additional flags */ 95 | short typeFlags; 96 | /** 97 | * Switch off velocity generation, 98 | * volume init type for fluid/obstacles (volume=1, shell=2, both=3). 99 | */ 100 | char domainNovecgen, volumeInitType; 101 | 102 | /* boundary "stickiness" for part slip values */ 103 | float partSlipValue; 104 | 105 | /* number of tracers to generate */ 106 | int generateTracers; 107 | /* particle generation - on if >0, then determines amount (experimental...) */ 108 | float generateParticles; 109 | /* smooth fluid surface? */ 110 | float surfaceSmoothing; 111 | /** Number of surface subdivisions. */ 112 | int surfaceSubdivs; 113 | /** GUI flags. */ 114 | int flag; 115 | 116 | /** Particle display - size scaling, and alpha influence. */ 117 | float particleInfSize, particleInfAlpha; 118 | /* testing vars */ 119 | float farFieldSize; 120 | 121 | /** Vertex velocities of simulated fluid mesh. */ 122 | struct FluidVertexVelocity *meshVelocities; 123 | /** Number of vertices in simulated fluid mesh. */ 124 | int totvert; 125 | 126 | /* Fluid control settings */ 127 | float cpsTimeStart; 128 | float cpsTimeEnd; 129 | float cpsQuality; 130 | 131 | float attractforceStrength; 132 | float attractforceRadius; 133 | float velocityforceStrength; 134 | float velocityforceRadius; 135 | 136 | int lastgoodframe; 137 | 138 | /** Simulation/flow rate control (i.e. old "Fac-Time"). */ 139 | float animRate; 140 | } FluidsimSettings; 141 | 142 | /* ob->fluidsimSettings defines */ 143 | #define OB_FLUIDSIM_ENABLE 1 144 | #define OB_FLUIDSIM_DOMAIN 2 145 | #define OB_FLUIDSIM_FLUID 4 146 | #define OB_FLUIDSIM_OBSTACLE 8 147 | #define OB_FLUIDSIM_INFLOW 16 148 | #define OB_FLUIDSIM_OUTFLOW 32 149 | #define OB_FLUIDSIM_PARTICLE 64 150 | #define OB_FLUIDSIM_CONTROL 128 151 | 152 | #define OB_TYPEFLAG_START 7 153 | #define OB_FSGEO_THIN (1 << (OB_TYPEFLAG_START + 1)) 154 | #define OB_FSBND_NOSLIP (1 << (OB_TYPEFLAG_START + 2)) 155 | #define OB_FSBND_PARTSLIP (1 << (OB_TYPEFLAG_START + 3)) 156 | #define OB_FSBND_FREESLIP (1 << (OB_TYPEFLAG_START + 4)) 157 | #define OB_FSINFLOW_LOCALCOORD (1 << (OB_TYPEFLAG_START + 5)) 158 | 159 | /* surface generation flag (part of enabling chapter 6 of 160 | * "Free Surface Flows with Moving and Deforming Objects for LBM") */ 161 | #define OB_FSSG_NOOBS (1 << (OB_TYPEFLAG_START + 6)) 162 | 163 | // guiDisplayMode particle flags 164 | #define OB_FSDOM_GEOM 1 165 | #define OB_FSDOM_PREVIEW 2 166 | #define OB_FSDOM_FINAL 3 167 | #define OB_FSPART_BUBBLE (1 << 1) 168 | #define OB_FSPART_DROP (1 << 2) 169 | #define OB_FSPART_NEWPART (1 << 3) 170 | #define OB_FSPART_FLOAT (1 << 4) 171 | #define OB_FSPART_TRACER (1 << 5) 172 | 173 | // new fluid bit flags for fss->flags 174 | #define OB_FLUIDSIM_REVERSE (1 << 0) 175 | #define OB_FLUIDSIM_ACTIVE (1 << 1) 176 | #define OB_FLUIDSIM_OVERRIDE_TIME (1 << 2) 177 | 178 | #ifdef __cplusplus 179 | } 180 | #endif 181 | -------------------------------------------------------------------------------- /libs/blender/DNA_session_uuid_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | */ 16 | 17 | /** \file 18 | * \ingroup DNA 19 | */ 20 | 21 | #pragma once 22 | 23 | #include "BLI_sys_types.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Is a structure because of the following considerations: 30 | * 31 | * - It is not possible to use custom types in DNA members: makesdna does not recognize them. 32 | * - It allows to add more bits, more than standard fixed-size types can store. For example, if 33 | * we ever need to go 128 bits, it is as simple as adding extra 64bit field. 34 | */ 35 | typedef struct SessionUUID { 36 | /* Never access directly, as it might cause a headache when more bits are needed: if the field 37 | * is used directly it will not be easy to find all places where partial access is used. */ 38 | uint64_t uuid_; 39 | } SessionUUID; 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | -------------------------------------------------------------------------------- /libs/blender/DNA_vec_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | * 16 | * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 17 | * All rights reserved. 18 | */ 19 | 20 | /** \file 21 | * \ingroup DNA 22 | */ 23 | 24 | #pragma once 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* types */ 31 | 32 | /** vector of two shorts. */ 33 | typedef struct vec2s { 34 | short x, y; 35 | } vec2s; 36 | 37 | /** vector of two floats. */ 38 | typedef struct vec2f { 39 | float x, y; 40 | } vec2f; 41 | 42 | /* not used at the moment */ 43 | /* 44 | typedef struct vec2i { 45 | int x, y; 46 | } vec2i; 47 | 48 | typedef struct vec2d { 49 | double x, y; 50 | } vec2d; 51 | 52 | typedef struct vec3i { 53 | int x, y, z; 54 | } vec3i; 55 | */ 56 | typedef struct vec3f { 57 | float x, y, z; 58 | } vec3f; 59 | /* 60 | typedef struct vec3d { 61 | double x, y, z; 62 | } vec3d; 63 | 64 | typedef struct vec4i { 65 | int x, y, z, w; 66 | } vec4i; 67 | 68 | typedef struct vec4f { 69 | float x, y, z, w; 70 | } vec4f; 71 | 72 | typedef struct vec4d { 73 | double x, y, z, w; 74 | } vec4d; 75 | */ 76 | 77 | /** integer rectangle. */ 78 | typedef struct rcti { 79 | int xmin, xmax; 80 | int ymin, ymax; 81 | } rcti; 82 | 83 | /** float rectangle. */ 84 | typedef struct rctf { 85 | float xmin, xmax; 86 | float ymin, ymax; 87 | } rctf; 88 | 89 | /** dual quaternion. */ 90 | typedef struct DualQuat { 91 | float quat[4]; 92 | float trans[4]; 93 | 94 | float scale[4][4]; 95 | float scale_weight; 96 | } DualQuat; 97 | 98 | #ifdef __cplusplus 99 | } 100 | #endif 101 | -------------------------------------------------------------------------------- /libs/blender/DNA_view2d_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | * 16 | * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 17 | * All rights reserved. 18 | */ 19 | 20 | /** \file 21 | * \ingroup DNA 22 | */ 23 | 24 | #pragma once 25 | 26 | #include "DNA_vec_types.h" 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | /* ---------------------------------- */ 33 | 34 | /** View 2D data - stored per region. */ 35 | typedef struct View2D { 36 | /** Tot - area that data can be drawn in; cur - region of tot that is visible in viewport. */ 37 | rctf tot, cur; 38 | /** Vert - vertical scrollbar region; hor - horizontal scrollbar region. */ 39 | rcti vert, hor; 40 | /** Mask - region (in screenspace) within which 'cur' can be viewed. */ 41 | rcti mask; 42 | 43 | /** Min/max sizes of 'cur' rect (only when keepzoom not set). */ 44 | float min[2], max[2]; 45 | /** Allowable zoom factor range (only when (keepzoom & V2D_LIMITZOOM)) is set. */ 46 | float minzoom, maxzoom; 47 | 48 | /** Scroll - scrollbars to display (bitflag). */ 49 | short scroll; 50 | /** Scroll_ui - temp settings used for UI drawing of scrollers. */ 51 | short scroll_ui; 52 | 53 | /** Keeptot - 'cur' rect cannot move outside the 'tot' rect? */ 54 | short keeptot; 55 | /** Keepzoom - axes that zooming cannot occur on, and also clamp within zoom-limits. */ 56 | short keepzoom; 57 | /** Keepofs - axes that translation is not allowed to occur on. */ 58 | short keepofs; 59 | 60 | /** Settings. */ 61 | short flag; 62 | /** Alignment of content in totrect. */ 63 | short align; 64 | 65 | /** Storage of current winx/winy values, set in UI_view2d_size_update. */ 66 | short winx, winy; 67 | /** Storage of previous winx/winy values encountered by UI_view2d_curRect_validate(), 68 | * for keepaspect. */ 69 | short oldwinx, oldwiny; 70 | 71 | /** Pivot point for transforms (rotate and scale). */ 72 | short around; 73 | 74 | /* Usually set externally (as in, not in view2d files). */ 75 | /** Alpha of vertical and horizontal scrollbars (range is [0, 255]). */ 76 | char alpha_vert, alpha_hor; 77 | char _pad[6]; 78 | 79 | /* animated smooth view */ 80 | struct SmoothView2DStore *sms; 81 | struct wmTimer *smooth_timer; 82 | } View2D; 83 | 84 | /* ---------------------------------- */ 85 | 86 | /** View zooming restrictions, per axis (#View2D.keepzoom) */ 87 | enum { 88 | /* zoom is clamped to lie within limits set by minzoom and maxzoom */ 89 | V2D_LIMITZOOM = (1 << 0), 90 | /* aspect ratio is maintained on view resize */ 91 | V2D_KEEPASPECT = (1 << 1), 92 | /* zoom is kept when the window resizes */ 93 | V2D_KEEPZOOM = (1 << 2), 94 | /* zooming on x-axis is not allowed */ 95 | V2D_LOCKZOOM_X = (1 << 8), 96 | /* zooming on y-axis is not allowed */ 97 | V2D_LOCKZOOM_Y = (1 << 9), 98 | }; 99 | 100 | /** View panning restrictions, per axis (#View2D.keepofs). */ 101 | enum { 102 | /* panning on x-axis is not allowed */ 103 | V2D_LOCKOFS_X = (1 << 1), 104 | /* panning on y-axis is not allowed */ 105 | V2D_LOCKOFS_Y = (1 << 2), 106 | /* on resize, keep the x offset */ 107 | V2D_KEEPOFS_X = (1 << 3), 108 | /* on resize, keep the y offset */ 109 | V2D_KEEPOFS_Y = (1 << 4), 110 | }; 111 | 112 | /** View extent restrictions (#View2D.keeptot). */ 113 | enum { 114 | /** 'cur' view can be out of extents of 'tot' */ 115 | V2D_KEEPTOT_FREE = 0, 116 | /** 'cur' rect is adjusted so that it satisfies the extents of 'tot', with some compromises */ 117 | V2D_KEEPTOT_BOUNDS = 1, 118 | /** 'cur' rect is moved so that the 'minimum' bounds of the 'tot' rect are always respected 119 | * (particularly in x-axis) */ 120 | V2D_KEEPTOT_STRICT = 2, 121 | }; 122 | 123 | /** General refresh settings (#View2D.flag). */ 124 | enum { 125 | /* global view2d horizontal locking (for showing same time interval) */ 126 | /* TODO: this flag may be set in old files but is not accessible currently, 127 | * should be exposed from RNA - Campbell */ 128 | V2D_VIEWSYNC_SCREEN_TIME = (1 << 0), 129 | /* within area (i.e. between regions) view2d vertical locking */ 130 | V2D_VIEWSYNC_AREA_VERTICAL = (1 << 1), 131 | /* apply pixel offsets on x-axis when setting view matrices */ 132 | V2D_PIXELOFS_X = (1 << 2), 133 | /* apply pixel offsets on y-axis when setting view matrices */ 134 | V2D_PIXELOFS_Y = (1 << 3), 135 | /* zoom, pan or similar action is in progress */ 136 | V2D_IS_NAVIGATING = (1 << 9), 137 | /* view settings need to be set still... */ 138 | V2D_IS_INIT = (1 << 10), 139 | }; 140 | 141 | /** Scroller flags for View2D (#View2D.scroll). */ 142 | enum { 143 | /* left scrollbar */ 144 | V2D_SCROLL_LEFT = (1 << 0), 145 | V2D_SCROLL_RIGHT = (1 << 1), 146 | V2D_SCROLL_VERTICAL = (V2D_SCROLL_LEFT | V2D_SCROLL_RIGHT), 147 | /* horizontal scrollbar */ 148 | V2D_SCROLL_TOP = (1 << 2), 149 | V2D_SCROLL_BOTTOM = (1 << 3), 150 | /* UNUSED = (1 << 4), */ 151 | V2D_SCROLL_HORIZONTAL = (V2D_SCROLL_TOP | V2D_SCROLL_BOTTOM), 152 | /* display vertical scale handles */ 153 | V2D_SCROLL_VERTICAL_HANDLES = (1 << 5), 154 | /* display horizontal scale handles */ 155 | V2D_SCROLL_HORIZONTAL_HANDLES = (1 << 6), 156 | /* induce hiding of scrollbars - set by region drawing in response to size of region */ 157 | V2D_SCROLL_VERTICAL_HIDE = (1 << 7), 158 | V2D_SCROLL_HORIZONTAL_HIDE = (1 << 8), 159 | /* scrollbar extends beyond its available window - 160 | * set when calculating scrollbars for drawing */ 161 | V2D_SCROLL_VERTICAL_FULLR = (1 << 9), 162 | V2D_SCROLL_HORIZONTAL_FULLR = (1 << 10), 163 | }; 164 | 165 | /** scroll_ui, activate flag for drawing. */ 166 | enum { 167 | V2D_SCROLL_H_ACTIVE = (1 << 0), 168 | V2D_SCROLL_V_ACTIVE = (1 << 1), 169 | }; 170 | 171 | /** 172 | * Alignment flags for `totrect`, flags use 'shading-out' convention (#View2D.align). 173 | */ 174 | enum { 175 | /* all quadrants free */ 176 | V2D_ALIGN_FREE = 0, 177 | /* horizontal restrictions */ 178 | V2D_ALIGN_NO_POS_X = (1 << 0), 179 | V2D_ALIGN_NO_NEG_X = (1 << 1), 180 | /* vertical restrictions */ 181 | V2D_ALIGN_NO_POS_Y = (1 << 2), 182 | V2D_ALIGN_NO_NEG_Y = (1 << 3), 183 | }; 184 | 185 | #ifdef __cplusplus 186 | } 187 | #endif 188 | -------------------------------------------------------------------------------- /libs/blender/importer/IO_wavefront_obj.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 | 3 | /** \file 4 | * \ingroup obj 5 | */ 6 | 7 | #pragma once 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | typedef enum { 14 | OBJ_AXIS_X_UP = 0, 15 | OBJ_AXIS_Y_UP = 1, 16 | OBJ_AXIS_Z_UP = 2, 17 | OBJ_AXIS_NEGATIVE_X_UP = 3, 18 | OBJ_AXIS_NEGATIVE_Y_UP = 4, 19 | OBJ_AXIS_NEGATIVE_Z_UP = 5, 20 | } eTransformAxisUp; 21 | 22 | typedef enum { 23 | OBJ_AXIS_X_FORWARD = 0, 24 | OBJ_AXIS_Y_FORWARD = 1, 25 | OBJ_AXIS_Z_FORWARD = 2, 26 | OBJ_AXIS_NEGATIVE_X_FORWARD = 3, 27 | OBJ_AXIS_NEGATIVE_Y_FORWARD = 4, 28 | OBJ_AXIS_NEGATIVE_Z_FORWARD = 5, 29 | } eTransformAxisForward; 30 | 31 | static const int TOTAL_AXES = 3; 32 | 33 | 34 | struct OBJImportParams { 35 | /** Full path to the source OBJ file to import. */ 36 | char filepath[260]; 37 | /* Value 0 disables clamping. */ 38 | float clamp_size; 39 | eTransformAxisForward forward_axis; 40 | eTransformAxisUp up_axis; 41 | }; 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | -------------------------------------------------------------------------------- /libs/blender/importer/obj_export_io.hh: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 | 3 | /** \file 4 | * \ingroup obj 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "../BLI_compiler_attrs.h" 16 | #include "../BLI_string_ref.hh" 17 | 18 | namespace blender::io::obj { 19 | 20 | enum class eFileType { 21 | OBJ, 22 | MTL, 23 | }; 24 | 25 | enum class eOBJSyntaxElement { 26 | vertex_coords, 27 | vertex_coords_color, 28 | uv_vertex_coords, 29 | normal, 30 | poly_element_begin, 31 | vertex_uv_normal_indices, 32 | vertex_normal_indices, 33 | vertex_uv_indices, 34 | vertex_indices, 35 | poly_element_end, 36 | poly_usemtl, 37 | edge, 38 | cstype, 39 | nurbs_degree, 40 | curve_element_begin, 41 | curve_element_end, 42 | nurbs_parameter_begin, 43 | nurbs_parameters, 44 | nurbs_parameter_end, 45 | nurbs_group_end, 46 | new_line, 47 | mtllib, 48 | smooth_group, 49 | object_group, 50 | object_name, 51 | /* Use rarely. New line is NOT included for string. */ 52 | string, 53 | }; 54 | 55 | enum class eMTLSyntaxElement { 56 | newmtl, 57 | Ni, 58 | d, 59 | Ns, 60 | illum, 61 | Ka, 62 | Kd, 63 | Ks, 64 | Ke, 65 | map_Kd, 66 | map_Ks, 67 | map_Ns, 68 | map_d, 69 | map_refl, 70 | map_Ke, 71 | map_Bump, 72 | /* Use rarely. New line is NOT included for string. */ 73 | string, 74 | }; 75 | 76 | 77 | } // namespace blender::io::obj 78 | -------------------------------------------------------------------------------- /libs/blender/importer/obj_export_mtl.hh: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 | 3 | /** \file 4 | * \ingroup obj 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "../BLI_map.hh" 10 | #include "../BLI_math_vec_types.hh" 11 | #include "../BLI_string_ref.hh" 12 | #include "../BLI_vector.hh" 13 | 14 | #include "obj_export_io.hh" 15 | 16 | namespace blender { 17 | template<> struct DefaultHash { 18 | uint64_t operator()(const io::obj::eMTLSyntaxElement value) const 19 | { 20 | return static_cast(value); 21 | } 22 | }; 23 | 24 | } // namespace blender 25 | 26 | namespace blender::io::obj { 27 | class OBJMesh; 28 | 29 | /** 30 | * Generic container for texture node properties. 31 | */ 32 | struct tex_map_XX { 33 | tex_map_XX(StringRef to_socket_id) : dest_socket_id(to_socket_id){}; 34 | 35 | /** Target socket which this texture node connects to. */ 36 | const std::string dest_socket_id; 37 | float3 translation{0.0f}; 38 | float3 scale{1.0f}; 39 | /* Only Flat and Smooth projections are supported. */ 40 | int projection_type = 1; 41 | std::string image_path; 42 | std::string mtl_dir_path; 43 | }; 44 | 45 | /** 46 | * Container suited for storing Material data for/from a .MTL file. 47 | */ 48 | struct MTLMaterial { 49 | MTLMaterial() 50 | { 51 | texture_maps.add(eMTLSyntaxElement::map_Kd, tex_map_XX("Base Color")); 52 | texture_maps.add(eMTLSyntaxElement::map_Ks, tex_map_XX("Specular")); 53 | texture_maps.add(eMTLSyntaxElement::map_Ns, tex_map_XX("Roughness")); 54 | texture_maps.add(eMTLSyntaxElement::map_d, tex_map_XX("Alpha")); 55 | texture_maps.add(eMTLSyntaxElement::map_refl, tex_map_XX("Metallic")); 56 | texture_maps.add(eMTLSyntaxElement::map_Ke, tex_map_XX("Emission")); 57 | texture_maps.add(eMTLSyntaxElement::map_Bump, tex_map_XX("Normal")); 58 | } 59 | 60 | /** 61 | * Caller must ensure that the given lookup key exists in the Map. 62 | * \return Texture map corresponding to the given ID. 63 | */ 64 | tex_map_XX &tex_map_of_type(const eMTLSyntaxElement key) 65 | { 66 | { 67 | BLI_assert(texture_maps.contains_as(key)); 68 | return texture_maps.lookup_as(key); 69 | } 70 | } 71 | 72 | std::string name; 73 | /* Always check for negative values while importing or exporting. Use defaults if 74 | * any value is negative. */ 75 | float Ns{-1.0f}; 76 | float3 Ka{-1.0f}; 77 | float3 Kd{-1.0f}; 78 | float3 Ks{-1.0f}; 79 | float3 Ke{-1.0f}; 80 | float Ni{-1.0f}; 81 | float d{-1.0f}; 82 | int illum{-1}; 83 | Map texture_maps; 84 | /** Only used for Normal Map node: "map_Bump". */ 85 | float map_Bump_strength{-1.0f}; 86 | }; 87 | 88 | } // namespace blender::io::obj 89 | -------------------------------------------------------------------------------- /libs/blender/importer/obj_import_file_reader.hh: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 | 3 | /** \file 4 | * \ingroup obj 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include "IO_wavefront_obj.h" 11 | #include "obj_import_objects.hh" 12 | #include "obj_export_mtl.hh" 13 | 14 | namespace blender::io::obj { 15 | 16 | /* NOTE: the OBJ parser implementation is planned to get fairly large changes "soon", 17 | * so don't read too much into current implementation... */ 18 | class OBJParser { 19 | private: 20 | const OBJImportParams &import_params_; 21 | FILE *obj_file_; 22 | Vector mtl_libraries_; 23 | size_t read_buffer_size_; 24 | 25 | public: 26 | /** 27 | * Open OBJ file at the path given in import parameters. 28 | */ 29 | OBJParser(const OBJImportParams &import_params, size_t read_buffer_size); 30 | ~OBJParser(); 31 | 32 | /** 33 | * Read the OBJ file line by line and create OBJ Geometry instances. Also store all the vertex 34 | * and UV vertex coordinates in a struct accessible by all objects. 35 | */ 36 | void parse(Vector> &r_all_geometries, 37 | GlobalVertices &r_global_vertices); 38 | /** 39 | * Return a list of all material library filepaths referenced by the OBJ file. 40 | */ 41 | Span mtl_libraries() const; 42 | 43 | private: 44 | void add_mtl_library(StringRef path); 45 | void add_default_mtl_library(); 46 | }; 47 | 48 | class MTLParser { 49 | private: 50 | char mtl_file_path_[260]; 51 | /** 52 | * Directory in which the MTL file is found. 53 | */ 54 | char mtl_dir_path_[260]; 55 | 56 | public: 57 | /** 58 | * Open material library file. 59 | */ 60 | MTLParser(StringRefNull mtl_library_, StringRefNull obj_filepath); 61 | 62 | /** 63 | * Read MTL file(s) and add MTLMaterial instances to the given Map reference. 64 | */ 65 | void parse_and_store(Map> &r_materials); 66 | }; 67 | } // namespace blender::io::obj 68 | -------------------------------------------------------------------------------- /libs/blender/importer/obj_import_objects.hh: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 | 3 | /** \file 4 | * \ingroup obj 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "../BLI_map.hh" 10 | #include "../BLI_math_vec_types.hh" 11 | #include "../BLI_vector.hh" 12 | #include "../BLI_vector_set.hh" 13 | 14 | #include "../DNA_meshdata_types.h" 15 | #include "../DNA_object_types.h" 16 | 17 | namespace blender::io::obj { 18 | 19 | /** 20 | * List of all vertex and UV vertex coordinates in an OBJ file accessible to any 21 | * Geometry instance at any time. 22 | */ 23 | struct GlobalVertices { 24 | Vector vertices; 25 | Vector uv_vertices; 26 | Vector vertex_normals; 27 | Vector vertex_colors; 28 | }; 29 | 30 | /** 31 | * Keeps track of the vertices that belong to other Geometries. 32 | * Needed only for MLoop.v and MEdge.v1 which needs vertex indices ranging from (0 to total 33 | * vertices in the mesh) as opposed to the other OBJ indices ranging from (0 to total vertices 34 | * in the global list). 35 | */ 36 | struct VertexIndexOffset { 37 | private: 38 | int offset_ = 0; 39 | 40 | public: 41 | void set_index_offset(const int64_t total_vertices) 42 | { 43 | offset_ = total_vertices; 44 | } 45 | int64_t get_index_offset() const 46 | { 47 | return offset_; 48 | } 49 | }; 50 | 51 | /** 52 | * A face's corner in an OBJ file. In Blender, it translates to a mloop vertex. 53 | */ 54 | struct PolyCorner { 55 | /* These indices range from zero to total vertices in the OBJ file. */ 56 | int vert_index; 57 | /* -1 is to indicate absence of UV vertices. Only < 0 condition should be checked since 58 | * it can be less than -1 too. */ 59 | int uv_vert_index = -1; 60 | int vertex_normal_index = -1; 61 | }; 62 | 63 | struct PolyElem { 64 | int vertex_group_index = -1; 65 | int material_index = -1; 66 | bool shaded_smooth = false; 67 | int start_index_ = 0; 68 | int corner_count_ = 0; 69 | }; 70 | 71 | /** 72 | * Contains data for one single NURBS curve in the OBJ file. 73 | */ 74 | struct NurbsElement { 75 | /** 76 | * For curves, groups may be used to specify multiple splines in the same curve object. 77 | * It may also serve as the name of the curve if not specified explicitly. 78 | */ 79 | std::string group_; 80 | int degree = 0; 81 | /** 82 | * Indices into the global list of vertex coordinates. Must be non-negative. 83 | */ 84 | Vector curv_indices; 85 | /* Values in the parm u/v line in a curve definition. */ 86 | Vector parm; 87 | }; 88 | 89 | enum eGeometryType { 90 | GEOM_MESH = OB_MESH, 91 | GEOM_CURVE = OB_CURVES_LEGACY, 92 | }; 93 | 94 | struct Geometry { 95 | eGeometryType geom_type_ = GEOM_MESH; 96 | std::string geometry_name_; 97 | Map group_indices_; 98 | Vector group_order_; 99 | Map material_indices_; 100 | Vector material_order_; 101 | 102 | int vertex_start_ = 0; 103 | int vertex_count_ = 0; 104 | int vertex_color_start_ = 0; 105 | int vertex_color_count_ = 0; 106 | /** Edges written in the file in addition to (or even without polygon) elements. */ 107 | Vector edges_; 108 | 109 | Vector face_corners_; 110 | Vector face_elements_; 111 | 112 | bool has_invalid_polys_ = false; 113 | bool has_vertex_normals_ = false; 114 | bool has_vertex_groups_ = false; 115 | NurbsElement nurbs_element_; 116 | int total_loops_ = 0; 117 | }; 118 | 119 | } // namespace blender::io::obj 120 | -------------------------------------------------------------------------------- /libs/blender/importer/obj_import_string_utils.cc: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 | 3 | #include "obj_import_string_utils.hh" 4 | 5 | /* NOTE: we could use C++17 from_chars to parse 6 | * floats, but even if some compilers claim full support, 7 | * their standard libraries are not quite there yet. 8 | * LLVM/libc++ only has a float parser since LLVM 14, 9 | * and gcc/libstdc++ since 11.1. So until at least these are 10 | * the minimum spec, use an external library. */ 11 | #include "../intern/fast_float.h" 12 | #include 13 | 14 | namespace blender::io::obj { 15 | 16 | StringRef read_next_line(StringRef &buffer) 17 | { 18 | const char *start = buffer.begin(); 19 | const char *end = buffer.end(); 20 | size_t len = 0; 21 | char prev = 0; 22 | const char *ptr = start; 23 | while (ptr < end) { 24 | char c = *ptr++; 25 | if (c == '\n' && prev != '\\') { 26 | break; 27 | } 28 | prev = c; 29 | ++len; 30 | } 31 | 32 | buffer = StringRef(ptr, end); 33 | return StringRef(start, len); 34 | } 35 | 36 | static bool is_whitespace(char c) 37 | { 38 | return c <= ' ' || c == '\\'; 39 | } 40 | 41 | const char *drop_whitespace(const char *p, const char *end) 42 | { 43 | while (p < end && is_whitespace(*p)) { 44 | ++p; 45 | } 46 | return p; 47 | } 48 | 49 | const char *drop_non_whitespace(const char *p, const char *end) 50 | { 51 | while (p < end && !is_whitespace(*p)) { 52 | ++p; 53 | } 54 | return p; 55 | } 56 | 57 | static const char *drop_plus(const char *p, const char *end) 58 | { 59 | if (p < end && *p == '+') { 60 | ++p; 61 | } 62 | return p; 63 | } 64 | 65 | const char *parse_float( 66 | const char *p, const char *end, float fallback, float &dst, bool skip_space) 67 | { 68 | if (skip_space) { 69 | p = drop_whitespace(p, end); 70 | } 71 | p = drop_plus(p, end); 72 | fast_float::from_chars_result res = fast_float::from_chars(p, end, dst); 73 | if (res.ec == std::errc::invalid_argument || res.ec == std::errc::result_out_of_range) { 74 | dst = fallback; 75 | } 76 | return res.ptr; 77 | } 78 | 79 | const char *parse_floats(const char *p, const char *end, float fallback, float *dst, int count) 80 | { 81 | for (int i = 0; i < count; ++i) { 82 | p = parse_float(p, end, fallback, dst[i]); 83 | } 84 | return p; 85 | } 86 | 87 | const char *parse_int(const char *p, const char *end, int fallback, int &dst, bool skip_space) 88 | { 89 | if (skip_space) { 90 | p = drop_whitespace(p, end); 91 | } 92 | p = drop_plus(p, end); 93 | std::from_chars_result res = std::from_chars(p, end, dst); 94 | if (res.ec == std::errc::invalid_argument || res.ec == std::errc::result_out_of_range) { 95 | dst = fallback; 96 | } 97 | return res.ptr; 98 | } 99 | 100 | } // namespace blender::io::obj 101 | -------------------------------------------------------------------------------- /libs/blender/importer/obj_import_string_utils.hh: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 | 3 | #pragma once 4 | 5 | #include "BLI_string_ref.hh" 6 | 7 | /* 8 | * Various text parsing utilities used by OBJ importer. 9 | * The utilities are not directly usable by other formats, since 10 | * they treat backslash (\) as a whitespace character (OBJ format 11 | * allows backslashes to function as a line-continuation character). 12 | * 13 | * Many of these functions take two pointers (p, end) indicating 14 | * which part of a string to operate on, and return a possibly 15 | * changed new start of the string. They could be taking a StringRef 16 | * as input and returning a new StringRef, but this is a hot path 17 | * in OBJ parsing, and the StringRef approach does lose performance 18 | * (mostly due to return of StringRef being two register-size values 19 | * instead of just one pointer). 20 | */ 21 | 22 | namespace blender::io::obj { 23 | 24 | /** 25 | * Fetches next line from an input string buffer. 26 | * 27 | * The returned line will not have '\n' characters at the end; 28 | * the `buffer` is modified to contain remaining text without 29 | * the input line. 30 | * 31 | * Note that backslash (\) character is treated as a line 32 | * continuation. 33 | */ 34 | StringRef read_next_line(StringRef &buffer); 35 | 36 | /** 37 | * Drop leading white-space from a string part. 38 | * Note that backslash character is considered white-space. 39 | */ 40 | const char *drop_whitespace(const char *p, const char *end); 41 | 42 | /** 43 | * Drop leading non-white-space from a string part. 44 | * Note that backslash character is considered white-space. 45 | */ 46 | const char *drop_non_whitespace(const char *p, const char *end); 47 | 48 | /** 49 | * Parse an integer from an input string. 50 | * The parsed result is stored in `dst`. The function skips 51 | * leading white-space unless `skip_space=false`. If the 52 | * number can't be parsed (invalid syntax, out of range), 53 | * `fallback` value is stored instead. 54 | * 55 | * Returns the start of remainder of the input string after parsing. 56 | */ 57 | const char *parse_int( 58 | const char *p, const char *end, int fallback, int &dst, bool skip_space = true); 59 | 60 | /** 61 | * Parse a float from an input string. 62 | * The parsed result is stored in `dst`. The function skips 63 | * leading white-space unless `skip_space=false`. If the 64 | * number can't be parsed (invalid syntax, out of range), 65 | * `fallback` value is stored instead. 66 | * 67 | * Returns the start of remainder of the input string after parsing. 68 | */ 69 | const char *parse_float( 70 | const char *p, const char *end, float fallback, float &dst, bool skip_space = true); 71 | 72 | /** 73 | * Parse a number of white-space separated floats from an input string. 74 | * The parsed `count` numbers are stored in `dst`. If a 75 | * number can't be parsed (invalid syntax, out of range), 76 | * `fallback` value is stored instead. 77 | * 78 | * Returns the start of remainder of the input string after parsing. 79 | */ 80 | const char *parse_floats(const char *p, const char *end, float fallback, float *dst, int count); 81 | 82 | } // namespace blender::io::obj 83 | -------------------------------------------------------------------------------- /libs/blender/importer/obj_importer.cc: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 | 3 | /** \file 4 | * \ingroup obj 5 | */ 6 | 7 | #include 8 | 9 | #include "obj_import_file_reader.hh" 10 | #include "obj_importer.hh" 11 | 12 | namespace blender::io::obj { 13 | 14 | void importer_main(const OBJImportParams &import_params, GlobalVertices& global_vertices, Vector>& all_geometries, Map>& materials) 15 | { 16 | OBJParser obj_parser{import_params, 1<<16}; 17 | obj_parser.parse(all_geometries, global_vertices); 18 | 19 | for (StringRefNull mtl_library : obj_parser.mtl_libraries()) { 20 | MTLParser mtl_parser{mtl_library, import_params.filepath}; 21 | mtl_parser.parse_and_store(materials); 22 | } 23 | } 24 | } // namespace blender::io::obj 25 | -------------------------------------------------------------------------------- /libs/blender/importer/obj_importer.hh: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 | 3 | /** \file 4 | * \ingroup obj 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "IO_wavefront_obj.h" 10 | #include "obj_import_objects.hh" 11 | #include "obj_export_mtl.hh" 12 | #include "../BLI_map.hh" 13 | 14 | namespace blender::io::obj { 15 | 16 | void importer_main(const OBJImportParams &import_params, GlobalVertices& global_vertices, Vector>& all_geometries, Map>& materials); 17 | 18 | } // namespace blender::io::obj 19 | -------------------------------------------------------------------------------- /libs/blender/intern/BLI_assert.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | */ 16 | 17 | /** \file 18 | * \ingroup bli 19 | * 20 | * Helper functions for BLI_assert.h header. 21 | */ 22 | 23 | #include "../BLI_assert.h" /* Own include. */ 24 | #include "../BLI_system.h" 25 | 26 | #include 27 | #include 28 | 29 | void _BLI_assert_print_pos(const char *file, const int line, const char *function, const char *id) 30 | { 31 | fprintf(stderr, "BLI_assert failed: %s:%d, %s(), at \'%s\'\n", file, line, function, id); 32 | } 33 | 34 | void _BLI_assert_print_extra(const char *str) 35 | { 36 | fprintf(stderr, " %s\n", str); 37 | } 38 | 39 | void _BLI_assert_unreachable_print(const char *file, const int line, const char *function) 40 | { 41 | fprintf(stderr, "Code marked as unreachable has been executed. Please report this as a bug.\n"); 42 | fprintf(stderr, "Error found at %s:%d in %s.\n", file, line, function); 43 | } 44 | 45 | void _BLI_assert_print_backtrace(void) 46 | { 47 | #ifndef NDEBUG 48 | //BLI_system_backtrace(stderr); 49 | #endif 50 | } 51 | 52 | void _BLI_assert_abort(void) 53 | { 54 | /* Wrap to remove 'noreturn' attribute since this suppresses missing return statements, 55 | * allowing changes to debug builds to accidentally to break release builds. 56 | * 57 | * For example `BLI_assert(0);` at the end of a function that returns a value, 58 | * will hide that it's missing a return. */ 59 | 60 | abort(); 61 | } 62 | -------------------------------------------------------------------------------- /libs/blender/intern/atomic_ops_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Original code from jemalloc with this license: 3 | * 4 | * Copyright (C) 2002-2013 Jason Evans . 5 | * All rights reserved. 6 | * Copyright (C) 2007-2012 Mozilla Foundation. All rights reserved. 7 | * Copyright (C) 2009-2013 Facebook, Inc. All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions are met: 11 | * 1. Redistributions of source code must retain the above copyright notice(s), 12 | * this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright notice(s), 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS 18 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 20 | * EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 25 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | * This program is free software; you can redistribute it and/or 28 | * modify it under the terms of the GNU General Public License 29 | * as published by the Free Software Foundation; either version 2 30 | * of the License, or (at your option) any later version. 31 | * 32 | * This program is distributed in the hope that it will be useful, 33 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 34 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 35 | * GNU General Public License for more details. 36 | * 37 | * You should have received a copy of the GNU General Public License 38 | * along with this program; if not, write to the Free Software Foundation, 39 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 40 | * 41 | * The Original Code is Copyright (C) 2016 Blender Foundation. 42 | * All rights reserved. 43 | * 44 | * The Original Code is: adapted from jemalloc. 45 | */ 46 | 47 | /** \file 48 | * \ingroup intern_atomic 49 | */ 50 | 51 | #ifndef __ATOMIC_OPS_UTILS_H__ 52 | #define __ATOMIC_OPS_UTILS_H__ 53 | 54 | #include 55 | #include 56 | #include 57 | #include 58 | 59 | #include 60 | 61 | /* little macro so inline keyword works */ 62 | #if defined(_MSC_VER) 63 | # define ATOMIC_INLINE static __forceinline 64 | #else 65 | # define ATOMIC_INLINE static inline __attribute__((always_inline)) 66 | #endif 67 | 68 | #ifdef __GNUC__ 69 | # define _ATOMIC_LIKELY(x) __builtin_expect(!!(x), 1) 70 | # define _ATOMIC_UNLIKELY(x) __builtin_expect(!!(x), 0) 71 | # define _ATOMIC_MAYBE_UNUSED __attribute__((unused)) 72 | #else 73 | # define _ATOMIC_LIKELY(x) (x) 74 | # define _ATOMIC_UNLIKELY(x) (x) 75 | # define _ATOMIC_MAYBE_UNUSED 76 | #endif 77 | 78 | #if defined(__SIZEOF_POINTER__) 79 | # define LG_SIZEOF_PTR __SIZEOF_POINTER__ 80 | #elif defined(UINTPTR_MAX) 81 | # if (UINTPTR_MAX == 0xFFFFFFFF) 82 | # define LG_SIZEOF_PTR 4 83 | # elif (UINTPTR_MAX == 0xFFFFFFFFFFFFFFFF) 84 | # define LG_SIZEOF_PTR 8 85 | # endif 86 | #elif defined(__WORDSIZE) /* Fallback for older glibc and cpp */ 87 | # if (__WORDSIZE == 32) 88 | # define LG_SIZEOF_PTR 4 89 | # elif (__WORDSIZE == 64) 90 | # define LG_SIZEOF_PTR 8 91 | # endif 92 | #endif 93 | 94 | #ifndef LG_SIZEOF_PTR 95 | # error "Cannot find pointer size" 96 | #endif 97 | 98 | #if (UINT_MAX == 0xFFFFFFFF) 99 | # define LG_SIZEOF_INT 4 100 | #elif (UINT_MAX == 0xFFFFFFFFFFFFFFFF) 101 | # define LG_SIZEOF_INT 8 102 | #else 103 | # error "Cannot find int size" 104 | #endif 105 | 106 | /* Copied from BLI_utils... */ 107 | /* C++ can't use _Static_assert, expects static_assert() but c++0x only, 108 | * Coverity also errors out. */ 109 | #if (!defined(__cplusplus)) && (!defined(__COVERITY__)) && \ 110 | (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 406)) /* gcc4.6+ only */ 111 | # define ATOMIC_STATIC_ASSERT(a, msg) __extension__ _Static_assert(a, msg); 112 | #else 113 | /* Code adapted from http://www.pixelbeat.org/programming/gcc/static_assert.html */ 114 | /* Note we need the two concats below because arguments to ## are not expanded, so we need to 115 | * expand __LINE__ with one indirection before doing the actual concatenation. */ 116 | # define ATOMIC_ASSERT_CONCAT_(a, b) a##b 117 | # define ATOMIC_ASSERT_CONCAT(a, b) ATOMIC_ASSERT_CONCAT_(a, b) 118 | /* These can't be used after statements in c89. */ 119 | # if defined(__COUNTER__) /* MSVC */ 120 | # define ATOMIC_STATIC_ASSERT(a, msg) \ 121 | ; \ 122 | enum { ATOMIC_ASSERT_CONCAT(static_assert_, __COUNTER__) = 1 / (int)(!!(a)) }; 123 | # else /* older gcc, clang... */ 124 | /* This can't be used twice on the same line so ensure if using in headers 125 | * that the headers are not included twice (by wrapping in #ifndef...#endif) 126 | * Note it doesn't cause an issue when used on same line of separate modules 127 | * compiled with gcc -combine -fwhole-program. */ 128 | # define ATOMIC_STATIC_ASSERT(a, msg) \ 129 | ; \ 130 | enum { ATOMIC_ASSERT_CONCAT(assert_line_, __LINE__) = 1 / (int)(!!(a)) }; 131 | # endif 132 | #endif 133 | 134 | #endif /* __ATOMIC_OPS_UTILS_H__ */ 135 | -------------------------------------------------------------------------------- /libs/blender/intern/leak_detector.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | */ 16 | 17 | /** \file 18 | * \ingroup intern_mem 19 | */ 20 | 21 | #include /* Needed for `printf` on WIN32/APPLE. */ 22 | #include 23 | 24 | #include "../MEM_guardedalloc.h" 25 | #include "mallocn_intern.h" 26 | 27 | bool leak_detector_has_run = false; 28 | char free_after_leak_detection_message[] = 29 | "Freeing memory after the leak detector has run. This can happen when using " 30 | "static variables in C++ that are defined outside of functions. To fix this " 31 | "error, use the 'construct on first use' idiom."; 32 | 33 | namespace { 34 | 35 | bool fail_on_memleak = false; 36 | bool ignore_memleak = false; 37 | 38 | class MemLeakPrinter { 39 | public: 40 | ~MemLeakPrinter() 41 | { 42 | if (ignore_memleak) { 43 | return; 44 | } 45 | leak_detector_has_run = true; 46 | const uint leaked_blocks = MEM_get_memory_blocks_in_use(); 47 | if (leaked_blocks == 0) { 48 | return; 49 | } 50 | const size_t mem_in_use = MEM_get_memory_in_use(); 51 | printf("Error: Not freed memory blocks: %u, total unfreed memory %f MB\n", 52 | leaked_blocks, 53 | (double)mem_in_use / 1024 / 1024); 54 | MEM_printmemlist(); 55 | 56 | if (fail_on_memleak) { 57 | /* There are many other ways to change the exit code to failure here: 58 | * - Make the destructor noexcept(false) and throw an exception. 59 | * - Call exit(EXIT_FAILURE). 60 | * - Call terminate(). 61 | */ 62 | abort(); 63 | } 64 | } 65 | }; 66 | } // namespace 67 | 68 | void MEM_init_memleak_detection() 69 | { 70 | /** 71 | * This variable is constructed when this function is first called. This should happen as soon as 72 | * possible when the program starts. 73 | * 74 | * It is destructed when the program exits. During destruction, it will print information about 75 | * leaked memory blocks. Static variables are destructed in reversed order of their 76 | * construction. Therefore, all static variables that own memory have to be constructed after 77 | * this function has been called. 78 | */ 79 | static MemLeakPrinter printer; 80 | } 81 | 82 | void MEM_use_memleak_detection(bool enabled) 83 | { 84 | ignore_memleak = !enabled; 85 | } 86 | 87 | void MEM_enable_fail_on_memleak() 88 | { 89 | fail_on_memleak = true; 90 | } 91 | -------------------------------------------------------------------------------- /libs/blender/intern/mallocn_inline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Adapted from jemalloc, to protect against buffer overflow vulnerabilities. 3 | * 4 | * Copyright (C) 2002-2017 Jason Evans . 5 | * All rights reserved. 6 | * Copyright (C) 2007-2012 Mozilla Foundation. All rights reserved. 7 | * Copyright (C) 2009-2017 Facebook, Inc. All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions are met: 11 | * 1. Redistributions of source code must retain the above copyright notice(s), 12 | * this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright notice(s), 14 | * this list of conditions and the following disclaimer in the documentation 15 | * and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS 18 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 20 | * EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 25 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /** \file 30 | * \ingroup intern_mem 31 | */ 32 | 33 | #ifndef __MALLOCN_INLINE_H__ 34 | #define __MALLOCN_INLINE_H__ 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | MEM_INLINE bool MEM_size_safe_multiply(size_t a, size_t b, size_t *result) 41 | { 42 | /* A size_t with its high-half bits all set to 1. */ 43 | const size_t high_bits = SIZE_MAX << (sizeof(size_t) * 8 / 2); 44 | *result = a * b; 45 | 46 | if (UNLIKELY(*result == 0)) { 47 | return (a == 0 || b == 0); 48 | } 49 | 50 | /* 51 | * We got a non-zero size, but we don't know if we overflowed to get 52 | * there. To avoid having to do a divide, we'll be clever and note that 53 | * if both A and B can be represented in N/2 bits, then their product 54 | * can be represented in N bits (without the possibility of overflow). 55 | */ 56 | return ((high_bits & (a | b)) == 0 || (*result / b == a)); 57 | } 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | #endif /* __MALLOCN_INLINE_H__ */ 64 | -------------------------------------------------------------------------------- /libs/blender/intern/math_base_safe_inline.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU General Public License 4 | * as published by the Free Software Foundation; either version 2 5 | * of the License, or (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program; if not, write to the Free Software Foundation, 14 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 | */ 16 | 17 | #ifndef __MATH_BASE_SAFE_INLINE_C__ 18 | #define __MATH_BASE_SAFE_INLINE_C__ 19 | 20 | #include "BLI_math_base_safe.h" 21 | #include "BLI_utildefines.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | MINLINE float safe_divide(float a, float b) 28 | { 29 | return (b != 0.0f) ? a / b : 0.0f; 30 | } 31 | 32 | MINLINE float safe_modf(float a, float b) 33 | { 34 | return (b != 0.0f) ? fmodf(a, b) : 0.0f; 35 | } 36 | 37 | MINLINE float safe_logf(float a, float base) 38 | { 39 | if (UNLIKELY(a <= 0.0f || base <= 0.0f)) { 40 | return 0.0f; 41 | } 42 | return safe_divide(logf(a), logf(base)); 43 | } 44 | 45 | MINLINE float safe_sqrtf(float a) 46 | { 47 | return sqrtf(MAX2(a, 0.0f)); 48 | } 49 | 50 | MINLINE float safe_inverse_sqrtf(float a) 51 | { 52 | return (a > 0.0f) ? 1.0f / sqrtf(a) : 0.0f; 53 | } 54 | 55 | MINLINE float safe_asinf(float a) 56 | { 57 | CLAMP(a, -1.0f, 1.0f); 58 | return asinf(a); 59 | } 60 | 61 | MINLINE float safe_acosf(float a) 62 | { 63 | CLAMP(a, -1.0f, 1.0f); 64 | return acosf(a); 65 | } 66 | 67 | MINLINE float safe_powf(float base, float exponent) 68 | { 69 | if (UNLIKELY(base < 0.0f && exponent != (int)exponent)) { 70 | return 0.0f; 71 | } 72 | return powf(base, exponent); 73 | } 74 | 75 | #ifdef __cplusplus 76 | } 77 | #endif 78 | 79 | #endif /* __MATH_BASE_SAFE_INLINE_C__ */ 80 | -------------------------------------------------------------------------------- /libs/blender/pthreads/include/semaphore.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Module: semaphore.h 3 | * 4 | * Purpose: 5 | * Semaphores aren't actually part of the PThreads standard. 6 | * They are defined by the POSIX Standard: 7 | * 8 | * POSIX 1003.1b-1993 (POSIX.1b) 9 | * 10 | * -------------------------------------------------------------------------- 11 | * 12 | * Pthreads4w - POSIX Threads for Windows 13 | * Copyright 1998 John E. Bossom 14 | * Copyright 1999-2018, Pthreads4w contributors 15 | * 16 | * Homepage: https://sourceforge.net/projects/pthreads4w/ 17 | * 18 | * The current list of contributors is contained 19 | * in the file CONTRIBUTORS included with the source 20 | * code distribution. The list can also be seen at the 21 | * following World Wide Web location: 22 | * 23 | * https://sourceforge.net/p/pthreads4w/wiki/Contributors/ 24 | * 25 | * Licensed under the Apache License, Version 2.0 (the "License"); 26 | * you may not use this file except in compliance with the License. 27 | * You may obtain a copy of the License at 28 | * 29 | * http://www.apache.org/licenses/LICENSE-2.0 30 | * 31 | * Unless required by applicable law or agreed to in writing, software 32 | * distributed under the License is distributed on an "AS IS" BASIS, 33 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 34 | * See the License for the specific language governing permissions and 35 | * limitations under the License. 36 | */ 37 | #if !defined( SEMAPHORE_H ) 38 | #define SEMAPHORE_H 39 | 40 | /* FIXME: POSIX.1 says that _POSIX_SEMAPHORES should be defined 41 | * in , not here; for later POSIX.1 versions, its value 42 | * should match the corresponding _POSIX_VERSION number, but in 43 | * the case of POSIX.1b-1993, the value is unspecified. 44 | * 45 | * Notwithstanding the above, since POSIX semaphores, (and indeed 46 | * having any to #include), are not a standard feature 47 | * on MS-Windows, it is convenient to retain this definition here; 48 | * we may consider adding a hook, to make it selectively available 49 | * for inclusion by , in those cases (e.g. MinGW) where 50 | * is provided. 51 | */ 52 | #define _POSIX_SEMAPHORES 53 | 54 | /* Internal macros, common to the public interfaces for various 55 | * pthreads-win32 components, are defined in <_ptw32.h>; we must 56 | * include them here. 57 | */ 58 | #include <_ptw32.h> 59 | 60 | /* The sem_timedwait() function was added in POSIX.1-2001; it 61 | * requires struct timespec to be defined, at least as a partial 62 | * (a.k.a. incomplete) data type. Forward declare it as such, 63 | * then include selectively, to acquire a complete 64 | * definition, (if available). 65 | */ 66 | struct timespec; 67 | #define __need_struct_timespec 68 | #include 69 | 70 | /* The data type used to represent our semaphore implementation, 71 | * as required by POSIX.1; FIXME: consider renaming the underlying 72 | * structure tag, to avoid possible pollution of user namespace. 73 | */ 74 | typedef struct sem_t_ * sem_t; 75 | 76 | /* POSIX.1b (and later) mandates SEM_FAILED as the value to be 77 | * returned on failure of sem_open(); (our implementation is a 78 | * stub, which will always return this). 79 | */ 80 | #define SEM_FAILED (sem_t *)(-1) 81 | 82 | __PTW32_BEGIN_C_DECLS 83 | 84 | /* Function prototypes: some are implemented as stubs, which 85 | * always fail; (FIXME: identify them). 86 | */ 87 | __PTW32_DLLPORT int __PTW32_CDECL sem_init (sem_t * sem, 88 | int pshared, 89 | unsigned int value); 90 | 91 | __PTW32_DLLPORT int __PTW32_CDECL sem_destroy (sem_t * sem); 92 | 93 | __PTW32_DLLPORT int __PTW32_CDECL sem_trywait (sem_t * sem); 94 | 95 | __PTW32_DLLPORT int __PTW32_CDECL sem_wait (sem_t * sem); 96 | 97 | __PTW32_DLLPORT int __PTW32_CDECL sem_timedwait (sem_t * sem, 98 | const struct timespec * abstime); 99 | 100 | __PTW32_DLLPORT int __PTW32_CDECL sem_post (sem_t * sem); 101 | 102 | __PTW32_DLLPORT int __PTW32_CDECL sem_post_multiple (sem_t * sem, 103 | int count); 104 | 105 | __PTW32_DLLPORT sem_t * __PTW32_CDECL sem_open (const char *, int, ...); 106 | 107 | __PTW32_DLLPORT int __PTW32_CDECL sem_close (sem_t * sem); 108 | 109 | __PTW32_DLLPORT int __PTW32_CDECL sem_unlink (const char * name); 110 | 111 | __PTW32_DLLPORT int __PTW32_CDECL sem_getvalue (sem_t * sem, 112 | int * sval); 113 | 114 | __PTW32_END_C_DECLS 115 | 116 | #endif /* !SEMAPHORE_H */ 117 | -------------------------------------------------------------------------------- /libs/blender/pthreads/lib/pthreadVC3.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aras-p/obj_parse_tester/414b36774da3d3eeb1db49ab4f1901457eda3d56/libs/blender/pthreads/lib/pthreadVC3.lib -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Testing various Wafefront .OBJ parsing libraries 2 | 3 | Test code for "[**Comparing .obj parse libraries**](https://aras-p.info/blog/2022/05/14/comparing-obj-parse-libraries/)" blog post. 4 | 5 | ### Libraries: 6 | 7 | * `tinyobjloader`: https://github.com/tinyobjloader/tinyobjloader, 2021 Dec 27 (8322e00a), v1.0.6+. MIT license. 8 | * `tinyobjloader_opt`: using the experimental multi-threaded parser from the above. 9 | * `fast_obj`: https://github.com/thisistherk/fast_obj, 2022 Jan 29 (85778da5), v1.2+. MIT license. 10 | * `rapidobj`: https://github.com/guybrush77/rapidobj, 2022 Jun 18 (0e545f1), v0.9. MIT license. 11 | * `blender`: part of Blender codebase for building just the OBJ parser ([tree](https://github.com/blender/blender/tree/6ad9d8e2/source/blender/io/wavefront_obj/importer)), 2022 Jun 19, version 3.3.0 alpha. GPL v3 license. 12 | * `assimp`: https://github.com/assimp/assimp, 2022 May 10 (ff43768d), version 5.2.3+. BSD 3-clause license. 13 | * `osg`: part of https://github.com/openscenegraph/OpenSceneGraph code, just the OBJ parser ([tree](https://github.com/openscenegraph/OpenSceneGraph/tree/68340324/src/osgPlugins/obj)), 2022 Apr 7, v3.6.5+. LGPL-based license. 14 | 15 | 16 | ### Features 17 | 18 | | Feature |tinyobjloader|fast_obj|rapidobj|blender|assimp|osg| 19 | | :--- |:---:|:---:|:---:|:---:|:---:|:---:| 20 | | Base meshes | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | 21 | | Base materials | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | 22 | | [PBR](http://exocortex.com/blog/extending_wavefront_mtl_to_support_pbr) materials | ✓ | | ✓ | | ✓ | | 23 | | Vertex colors ([xyzrgb](http://paulbourke.net/dataformats/obj/colour.html)) | ✓ | | | ✓ | ✓ | ✓ | 24 | | Vertex colors ([MRGB](http://paulbourke.net/dataformats/obj/colour.html)) | | | | ✓ | | ✓ | 25 | | Lines (`l`) | ✓ | | ✓ | ✓ | ✓ | ✓ | 26 | | Points (`p`) | ✓ | | | | ✓ | ✓ | 27 | | Curves (`curv`) | | | | ✓* | | | 28 | | 2D Curves (`curv2`) | | | | | | | 29 | | Surfaces (`surf`) | | | | | | | 30 | | Skin weights (`vw`) | ✓ | | | | | | 31 | | Subdiv crease tags (`t`) | ✓ | | | | | | 32 | | Line continuations (`\`) | | | | ✓ | ✓ | ✓ | 33 | | Platform: Windows | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | 34 | | Platform: macOS | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | 35 | | Platform: Linux | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | 36 | 37 | \* Blender OBJ parser has limited support for curves: only `bspline` curve type is supported. 38 | 39 | 40 | ### Testing on models: 41 | 42 | * `sponza`: 20MB, 0.15M verts, 381 objects, 25 materials. "Crytek Sponza" from [McGuire Computer Graphics Archive](https://casual-effects.com/data/). 43 | * `Monkey-6`: 330MB, 2.0M verts, 1 object, 1 material. Blender's Monkey mesh, subdivided to level 6. 44 | * `rungholt`: 270MB, 2.5M verts, 1 object, 84 materials. "Rungholt" Minecraft map from [McGuire Computer Graphics Archive](https://casual-effects.com/data/). 45 | * `Blender3Splash`: 2.5GB, 14.4M verts, 24k objects, 113 materials. Blender 3.0 splash scene "[Sprite Fright](https://cloud.blender.org/p/gallery/617933e9b7b35ce1e1c01066)", exported as OBJ. 46 | 47 | 48 | ### Time in seconds it takes to load an .obj file: 49 | 50 | Windows 10, AMD Ryzen 5950X, VS2022 17.1: 51 | 52 | | Library |sponza|Monkey-6|rungholt|Blender3Splash| 53 | | :--- | ---:| ---:| ---:| ---:| 54 | | tinyobjloader | 0.17 | 2.75 | 2.83 | 19.57 | 55 | | tinyobjloader_opt | 0.04 | 0.41 | 0.40 | 3.12 | 56 | | fast_obj | 0.04 | 0.70 | 0.58 | 5.16 | 57 | | rapidobj | 0.02 | 0.19 | 0.19 | 1.25 | 58 | | blender | 0.07 | 0.94 | 0.83 | 6.92 | 59 | | assimp | 0.20 | 2.98 | 3.88 | 21.98 | 60 | | osg | 0.82 |12.88 |12.04 | 96.42 | 61 | 62 | Windows 10, AMD Ryzen 5950X, clang 13: 63 | 64 | | Library |sponza|Monkey-6|rungholt|Blender3Splash| 65 | | :--- | ---:| ---:| ---:| ---:| 66 | | tinyobjloader | | 2.65 | 2.42 | 16.47 | 67 | | tinyobjloader_opt | | 0.38 | 0.38 | 2.69 | 68 | | fast_obj | | 0.71 | 0.58 | 5.25 | 69 | | rapidobj | | 0.19 | 0.17 | 1.62 | 70 | | blender | | 0.80 | 0.74 | 5.98 | 71 | | assimp | | 2.74 | 3.53 | 19.90 | 72 | 73 | macOS 12.3, Apple M1 Max, clang 13: 74 | 75 | | Library |sponza|Monkey-6|rungholt|Blender3Splash| 76 | | :--- | ---:| ---:| ---:| ---:| 77 | | tinyobjloader | 0.14 | 2.09 | 2.12 | 14.72 | 78 | | tinyobjloader_opt | 0.03 | 0.47 | 0.38 | 5.07 | 79 | | fast_obj | 0.02 | 0.33 | 0.30 | 2.40 | 80 | | rapidobj | 0.01 | 0.10 | 0.10 | 0.63 | 81 | | blender | | 0.73 | 0.76 | 5.53 | 82 | | assimp | 0.13 | 1.89 | 2.17 | 14.26 | 83 | | osg | 0.46 | 7.04 | 5.83 | 53.14 | 84 | 85 | ### Memory usage: 86 | 87 | Memory usage in MB (peak/end), Windows/VS2022: 88 | 89 | | Library |rungholt |Blender3Splash| 90 | | :--- | ---:| ---:| 91 | | tinyobjloader | 395 / 248 | 1505 / 1438 | 92 | | tinyobjloader_opt | 1662 / 469 |13850 / 2272 | 93 | | fast_obj | 319 / 214 | 1895 / 1237 | 94 | | rapidobj | 428 / 218 | 2667 / 1265 | 95 | | blender-initial | 680 / 560 | 4058 / 4051 | 96 | | blender | 272 / 253 | 1621 / 1614 | 97 | | assimp | 1341 / 640 | 6097 / 2788 | 98 | | osg | 857 / 850 | 3945 / 3937 | 99 | 100 | -------------------------------------------------------------------------------- /test_files/cube.mtl: -------------------------------------------------------------------------------- 1 | # 2 | 3 | newmtl red 4 | Ka 0.2 0.2 0.2 5 | Kd 1.0 0.0 0.0 6 | -------------------------------------------------------------------------------- /test_files/cube.obj: -------------------------------------------------------------------------------- 1 | ## 2 | ## Three-D Library generated .obj file 3 | ## cube 4 | ## 5 | o TheCube 6 | 7 | mtllib cube.mtl 8 | 9 | # 0 materials 10 | 11 | v -1.000000 -1.000000 1.000000 12 | v -1.000000 1.000000 1.000000 13 | v 1.000000 1.000000 1.000000 14 | v 1.000000 -1.000000 1.000000 15 | v -1.000000 -1.000000 -1.000000 16 | v -1.000000 1.000000 -1.000000 17 | v 1.000000 1.000000 -1.000000 18 | v 1.000000 -1.000000 -1.000000 19 | # 8 vertices 20 | 21 | vn 0.577350 0.577350 -0.577350 22 | vn 0.577350 -0.577350 -0.577350 23 | vn -0.577350 -0.577350 -0.577350 24 | vn -0.577350 0.577350 -0.577350 25 | vn 0.577350 0.577350 0.577350 26 | vn 0.577350 -0.577350 0.577350 27 | vn -0.577350 -0.577350 0.577350 28 | vn -0.577350 0.577350 0.577350 29 | # 8 vertex normals 30 | 31 | # 0 texture vertices 32 | 33 | g default 34 | usemtl red 35 | f 4//4 3//3 2//2 1//1 36 | f 1//1 2//2 6//6 5//5 37 | f 7//7 6//6 2//2 3//3 38 | f 4//4 8//8 7//7 3//3 39 | f 5//5 8//8 4//4 1//1 40 | f 5//5 6//6 7//7 8//8 41 | # 6 faces 42 | 43 | -------------------------------------------------------------------------------- /test_files/monkey-subd6-30.mtl: -------------------------------------------------------------------------------- 1 | # Blender MTL File: 'monkey-subd6.blend' 2 | # Material Count: 1 3 | 4 | newmtl None 5 | Ns 500 6 | Ka 0.8 0.8 0.8 7 | Kd 0.8 0.8 0.8 8 | Ks 0.8 0.8 0.8 9 | d 1 10 | illum 2 11 | -------------------------------------------------------------------------------- /test_files/monkey-subd6-nonormals.mtl: -------------------------------------------------------------------------------- 1 | # Blender 3.3.0 Alpha MTL File: 'None' 2 | # www.blender.org 3 | -------------------------------------------------------------------------------- /test_files/simple.mtl: -------------------------------------------------------------------------------- 1 | # Blender 3.2.0 Alpha MTL File: 'simple.blend' 2 | # www.blender.org 3 | 4 | newmtl Material 5 | Ns 360.000000 6 | Ka 1.000000 1.000000 1.000000 7 | Kd 0.800000 0.800000 0.800000 8 | Ks 0.500000 0.500000 0.500000 9 | Ke 0.000000 0.000000 0.000000 10 | Ni 1.450000 11 | d 1.000000 12 | illum 2 13 | map_Kd ..\..\..\code\projects\ToyPathTracer\Shots\screenshot.jpg 14 | map_d ..\..\..\code\projects\other\blender\blog\obj_import\rungholt\rungholt-Alpha.png 15 | 16 | newmtl Material.001 17 | Ns 250.000000 18 | Ka 1.000000 1.000000 1.000000 19 | Kd 0.155347 0.140603 0.800000 20 | Ks 0.500000 0.500000 0.500000 21 | Ke 0.000000 0.000000 0.000000 22 | Ni 1.450000 23 | d 1.000000 24 | illum 2 25 | --------------------------------------------------------------------------------