Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2022-02-24Fix T95985: crash when assigning a name for an output attributeJacques Lucke
This was a double free error which happened because `BM_mesh_bm_from_me` was taking ownership of arrays that were still owned by the Mesh. Note that this only happens when the mesh is empty but some custom data layers still have a non-null data pointer. While usually the data pointer should be null in this case for performance reasons, other functions should still be able to handle this situation. Differential Revision: https://developer.blender.org/D14181
2022-02-22Merge branch 'blender-v3.1-release'Hans Goudey
2022-02-22Fix T95839: Data race when lazily creating mesh normal layersHans Goudey
Currently, when normals are calculated for a const mesh, a custom data layer might be added if it doesn't already exist. Adding a custom data layer to a mesh is not thread-safe, so this can be a problem in some situations. This commit moves derived mesh normals for polygons and vertices out of `CustomData` to `Mesh_Runtime`. Most of the hard work for this was already done by rBcfa53e0fbeed7178. Some changes to logic elsewhere are necessary/helpful: - No need to call both `BKE_mesh_runtime_clear_cache` and `BKE_mesh_normals_tag_dirty`, since the former also does the latter. - Cleanup/simplify mesh conversion and copying since normals are handled with other runtime data. Storing these normals like other runtime data clarifies their status as derived data, meaning custom data moves more towards storing original/editable data. This means normals won't automatically benefit from the planned copy-on-write refactor (T95845), so it will have to be added manually like for the other runtime data. Differential Revision: https://developer.blender.org/D14154
2022-02-22Merge branch 'blender-v3.1-release'Campbell Barton
2022-02-22Fix T44415: Shape keys get out of sync when using undo in edit-modeCampbell Barton
This is an alternate fix for T35170 since it caused T44415. Having the undo system manipulate the key-block coordinates is error prone as (in the case of T44415) there are situations when it's important to apply the difference with the original shape key. This reverts dab0bd9de65a9be5e8ababba0e2799f994d5d12f, and instead avoids the problem by not using the data in `Mesh.key` as a reference for updating shape-keys when exiting edit-mode. The assumption that the `Mesh.key` in edit-mode won't be modified until leaving edit-mode isn't always true. Leading to synchronization errors. (details noted in code-comments). Resolve this by using shape-key data stored in the BMesh. Resolving both T35170 & T44415. Details: - Remove use of the original vertices when exiting edit mode. - Remove use of the original shape-key coordinates when exiting edit-mode (except as a last resort). - Move shape-key synchronization into a separate function: `bm_to_mesh_key`. - Split the synchronization loop into two branches, depending on the existence of BMesh shape-key coordinates. - Always write shape-key values back to the BMesh CD_SHAPEKEY layers. This was only done in some cases but is now necessary for all shape-keys as these are used to calculate offsets where the `Mesh.key` was previously used. - Report a warning when the shape-key layer isn't found as this uses an imperfect method of restoring coordinates which should only be used as a last resort. Reviewed By: mont29 Ref D14127
2022-02-21Cleanup: avoid reallocating arrays at the same sizeCampbell Barton
2022-02-18Mesh: Avoid creating incorrect original index layersHans Goudey
Currently, whenever any BMesh is converted to a Mesh (except for edit mode switching), original index (`CD_ORIGINDEX`) layers are added. This is incorrect, because many operations just convert some Mesh into a BMesh and then back, but they shouldn't make any assumption about where their input mesh came from. It might even come from a primitive in geometry nodes, where there are no original indices at all. Conceptually, mesh original indices should be filled by the modifier stack when first creating the evaluated mesh. So that's where they're moved in this patch. A separate function now fills the indices with their default (0,1,2,3...) values. The way the mesh wrapper system defers the BMesh to Mesh conversion makes this a bit less obvious though. The old behavior is incorrect, but it's also slower, because three arrays the size of the mesh's vertices, edges, and faces had to be allocated and filled during the BMesh to Mesh conversion, which just ends up putting more pressure on the cache. In the many cases where original indices aren't used, I measured an **8% speedup** for the conversion (from 76.5ms to 70.7ms). Generally there is an assumption that BMesh is "original" and Mesh is "evaluated". After this patch, that assumption isn't quite as strong, but it still exists for two reasons. First, original indices are added whenever converting a BMesh "wrapper" to a Mesh. Second, original indices are not added to the BMesh at the beginning of evaluation, which assumes that every BMesh in the viewport is original and doesn't need the mapping. Differential Revision: https://developer.blender.org/D14018
2022-02-11File headers: SPDX License migrationCampbell Barton
Use a shorter/simpler license convention, stops the header taking so much space. Follow the SPDX license specification: https://spdx.org/licenses - C/C++/objc/objc++ - Python - Shell Scripts - CMake, GNUmakefile While most of the source tree has been included - `./extern/` was left out. - `./intern/cycles` & `./intern/atomic` are also excluded because they use different header conventions. doc/license/SPDX-license-identifiers.txt has been added to list SPDX all used identifiers. See P2788 for the script that automated these edits. Reviewed By: brecht, mont29, sergey Ref D14069
2022-02-08Mesh: add option to select vertices by similar vertex creaseKévin Dietrich
This adds an option to the "Select Similar" operator in edit mode to select vertices based on vertex crease similarity. The implementation follows that of the edge crease, with a 1-dimensional KD-tree used to store and retrieve vertex indices base on crease values. To maintain compatibility with old files (scripts), the `SIMEDGE_CREASE` enumeration identifier remains `CREASE`, while the one for the new `SIMVERT_CREASE` is `VCREASE` to follow the naming convention of other enum values. Reviewed By: campbellbarton Differential Revision: https://developer.blender.org/D14037
2022-01-24Cleanup: Grammar: its self vs. itselfHans Goudey
2022-01-24Cleanup: spelling in commentsCampbell Barton
2022-01-23Cleanup: Improvements to mesh to bmesh conversionHans Goudey
- Use `Array` and `Span` instead of raw pointers. - Declare variables in smaller scope. - Use references instead of pointers.
2022-01-22Fix T94760: Crash building BMesh when opening fileHans Goudey
A large polygon in the file from the report caused `alloca` to exceed the maximum stack size, causing a crash. Instead of using `alloca`, use `blender::Array` with an inline buffer. Based on a patch by Germano Cavalcante (@mano-wii). Differential Revision: https://developer.blender.org/D13898
2022-01-22Fix linking in debug modeCampbell Barton
b7878a4d457a59d4a42f8ac0f428ea336562d75a seems to have caused linking issues building debug mode on Linux. Using extern "C" resolves.
2022-01-22Cleanup: Move bmesh_mesh_convert.c to C++Hans Goudey
Useful for a simpler bug fix, code clarity, and easier possible optimizations in the future.
2022-01-20Subdivision: add support for vertex creasingKévin Dietrich
This adds vertex creasing support for OpenSubDiv for modeling, rendering, Alembic and USD I/O. For modeling, vertex creasing follows the edge creasing implementation with an operator accessible through the Vertex menu in Edit Mode, and some parameter in the properties panel. The option in the Subsurf and Multires to use edge creasing also affects vertex creasing. The vertex crease data is stored as a CustomData layer, unlike edge creases which for now are stored in `MEdge`, but will in the future also be moved to a `CustomData` layer. See comments for details on the difference in behavior for the `CD_CREASE` layer between egdes and vertices. For Cycles this adds sockets on the Mesh node to hold data about which vertices are creased (one socket for the indices, one for the weigths). Viewport rendering of vertex creasing reuses the same color scheme as for edges and creased vertices are drawn bigger than uncreased vertices. For Alembic and USD, vertex crease support follows the edge crease implementation, they are always read, but only exported if a `Subsurf` modifier is present on the Mesh. Reviewed By: brecht, fclem, sergey, sybren, campbellbarton Differential Revision: https://developer.blender.org/D10145
2022-01-20Cleanup: spelling in commentsCampbell Barton
2022-01-19BMesh: add mesh debug information printingCampbell Barton
- Add BM_mesh_debug_print & BM_mesh_debug_info. - Report flags in Mesh.cd_flag in BKE_mesh_debug_print - Move custom data printing into customdata.cc (noted as a TODO). Note that the term "runtime" has been removed from `BKE_mesh_runtime_debug_print` since these are useful for debugging any kind of mesh data.
2022-01-19BMesh: improve handling of custom-data flag (Mesh.cd_flag)Campbell Barton
Code that handled merging & initializing custom-data from other meshes sometimes missed checks for this flag, causing bevel weights to lost when the mesh was converted to a BMesh. The following changes are a more general fix for T94197. - Add BM_mesh_copy_init_customdata_from_mesh_array which initializes custom-data from multiple meshes at once. As well as initializing custom-data layers from Mesh.cd_flag. This isn't essential for boolean, however it avoids the overhead of resizing custom-data layers. - Loading mesh data into a BMesh now respects Mesh.cd_flag instead of only checking if the BMesh custom-data-layer exists. Without this, the order of meshes passed to BM_mesh_bm_from_me could give different (incorrect) results. - Copying mesh data now copies `cd_flag` too. This is a precaution as in my tests evaluating modifiers these values always matched. Nevertheless it's correct to copy this value as custom-data it's self is being copied.
2022-01-13Refactor: Move normals out of MVert, lazy calculationHans Goudey
As described in T91186, this commit moves mesh vertex normals into a contiguous array of float vectors in a custom data layer, how face normals are currently stored. The main interface is documented in `BKE_mesh.h`. Vertex and face normals are now calculated on-demand and cached, retrieved with an "ensure" function. Since the logical state of a mesh is now "has normals when necessary", they can be retrieved from a `const` mesh. The goal is to use on-demand calculation for all derived data, but leave room for eager calculation for performance purposes (modifier evaluation is threaded, but viewport data generation is not). **Benefits** This moves us closer to a SoA approach rather than the current AoS paradigm. Accessing a contiguous `float3` is much more efficient than retrieving data from a larger struct. The memory requirements for accessing only normals or vertex locations are smaller, and at the cost of more memory usage for just normals, they now don't have to be converted between float and short, which also simplifies code In the future, the remaining items can be removed from `MVert`, leaving only `float3`, which has similar benefits (see T93602). Removing the combination of derived and original data makes it conceptually simpler to only calculate normals when necessary. This is especially important now that we have more opportunities for temporary meshes in geometry nodes. **Performance** In addition to the theoretical future performance improvements by making `MVert == float3`, I've done some basic performance testing on this patch directly. The data is fairly rough, but it gives an idea about where things stand generally. - Mesh line primitive 4m Verts: 1.16x faster (36 -> 31 ms), showing that accessing just `MVert` is now more efficient. - Spring Splash Screen: 1.03-1.06 -> 1.06-1.11 FPS, a very slight change that at least shows there is no regression. - Sprite Fright Snail Smoosh: 3.30-3.40 -> 3.42-3.50 FPS, a small but observable speedup. - Set Position Node with Scaled Normal: 1.36x faster (53 -> 39 ms), shows that using normals in geometry nodes is faster. - Normal Calculation 1.6m Vert Cube: 1.19x faster (25 -> 21 ms), shows that calculating normals is slightly faster now. - File Size of 1.6m Vert Cube: 1.03x smaller (214.7 -> 208.4 MB), Normals are not saved in files, which can help with large meshes. As for memory usage, it may be slightly more in some cases, but I didn't observe any difference in the production files I tested. **Tests** Some modifiers and cycles test results need to be updated with this commit, for two reasons: - The subdivision surface modifier is not responsible for calculating normals anymore. In master, the modifier creates different normals than the result of the `Mesh` normal calculation, so this is a bug fix. - There are small differences in the results of some modifiers that use normals because they are not converted to and from `short` anymore. **Future improvements** - Remove `ModifierTypeInfo::dependsOnNormals`. Code in each modifier already retrieves normals if they are needed anyway. - Copy normals as part of a better CoW system for attributes. - Make more areas use lazy instead of eager normal calculation. - Remove `BKE_mesh_normals_tag_dirty` in more places since that is now the default state of a new mesh. - Possibly apply a similar change to derived face corner normals. Differential Revision: https://developer.blender.org/D12770
2022-01-12Revert "BLI: Refactor vector types & functions to use templates"Clément Foucault
Includes unwanted changes This reverts commit 46e049d0ce2bce2f53ddc41a0dbbea2969d00a5d.
2022-01-12BLI: Refactor vector types & functions to use templatesClment Foucault
This patch implements the vector types (i.e:`float2`) by making heavy usage of templating. All vector functions are now outside of the vector classes (inside the `blender::math` namespace) and are not vector size dependent for the most part. In the ongoing effort to make shaders less GL centric, we are aiming to share more code between GLSL and C++ to avoid code duplication. ####Motivations: - We are aiming to share UBO and SSBO structures between GLSL and C++. This means we will use many of the existing vector types and others we currently don't have (uintX, intX). All these variations were asking for many more code duplication. - Deduplicate existing code which is duplicated for each vector size. - We also want to share small functions. Which means that vector functions should be static and not in the class namespace. - Reduce friction to use these types in new projects due to their incompleteness. - The current state of the `BLI_(float|double|mpq)(2|3|4).hh` is a bit of a let down. Most clases are incomplete, out of sync with each others with different codestyles, and some functions that should be static are not (i.e: `float3::reflect()`). ####Upsides: - Still support `.x, .y, .z, .w` for readability. - Compact, readable and easilly extendable. - All of the vector functions are available for all the vectors types and can be restricted to certain types. Also template specialization let us define exception for special class (like mpq). - With optimization ON, the compiler unroll the loops and performance is the same. ####Downsides: - Might impact debugability. Though I would arge that the bugs are rarelly caused by the vector class itself (since the operations are quite trivial) but by the type conversions. - Might impact compile time. I did not saw a significant impact since the usage is not really widespread. - Functions needs to be rewritten to support arbitrary vector length. For instance, one can't call `len_squared_v3v3` in `math::length_squared()` and call it a day. - Type cast does not work with the template version of the `math::` vector functions. Meaning you need to manually cast `float *` and `(float *)[3]` to `float3` for the function calls. i.e: `math::distance_squared(float3(nearest.co), positions[i]);` - Some parts might loose in readability: `float3::dot(v1.normalized(), v2.normalized())` becoming `math::dot(math::normalize(v1), math::normalize(v2))` But I propose, when appropriate, to use `using namespace blender::math;` on function local or file scope to increase readability. `dot(normalize(v1), normalize(v2))` ####Consideration: - Include back `.length()` method. It is quite handy and is more C++ oriented. - I considered the GLM library as a candidate for replacement. It felt like too much for what we need and would be difficult to extend / modify to our needs. - I used Macros to reduce code in operators declaration and potential copy paste bugs. This could reduce debugability and could be reverted. - This touches `delaunay_2d.cc` and the intersection code. I would like to know @howardt opinion on the matter. - The `noexcept` on the copy constructor of `mpq(2|3)` is being removed. But according to @JacquesLucke it is not a real problem for now. I would like to give a huge thanks to @JacquesLucke who helped during this and pushed me to reduce the duplication further. Reviewed By: brecht, sergey, JacquesLucke Differential Revision: https://developer.blender.org/D13791
2022-01-12Revert "BLI: Refactor vector types & functions to use templates"Clément Foucault
Reverted because the commit removes a lot of commits. This reverts commit a2c1c368af48644fa8995ecbe7138cc0d7900c30.
2022-01-12BLI: Refactor vector types & functions to use templatesClément Foucault
This patch implements the vector types (i.e:float2) by making heavy usage of templating. All vector functions are now outside of the vector classes (inside the blender::math namespace) and are not vector size dependent for the most part. In the ongoing effort to make shaders less GL centric, we are aiming to share more code between GLSL and C++ to avoid code duplication. Motivations: - We are aiming to share UBO and SSBO structures between GLSL and C++. This means we will use many of the existing vector types and others we currently don't have (uintX, intX). All these variations were asking for many more code duplication. - Deduplicate existing code which is duplicated for each vector size. - We also want to share small functions. Which means that vector functions should be static and not in the class namespace. - Reduce friction to use these types in new projects due to their incompleteness. - The current state of the BLI_(float|double|mpq)(2|3|4).hh is a bit of a let down. Most clases are incomplete, out of sync with each others with different codestyles, and some functions that should be static are not (i.e: float3::reflect()). Upsides: - Still support .x, .y, .z, .w for readability. - Compact, readable and easilly extendable. - All of the vector functions are available for all the vectors types and can be restricted to certain types. Also template specialization let us define exception for special class (like mpq). - With optimization ON, the compiler unroll the loops and performance is the same. Downsides: - Might impact debugability. Though I would arge that the bugs are rarelly caused by the vector class itself (since the operations are quite trivial) but by the type conversions. - Might impact compile time. I did not saw a significant impact since the usage is not really widespread. - Functions needs to be rewritten to support arbitrary vector length. For instance, one can't call len_squared_v3v3 in math::length_squared() and call it a day. - Type cast does not work with the template version of the math:: vector functions. Meaning you need to manually cast float * and (float *)[3] to float3 for the function calls. i.e: math::distance_squared(float3(nearest.co), positions[i]); - Some parts might loose in readability: float3::dot(v1.normalized(), v2.normalized()) becoming math::dot(math::normalize(v1), math::normalize(v2)) But I propose, when appropriate, to use using namespace blender::math; on function local or file scope to increase readability. dot(normalize(v1), normalize(v2)) Consideration: - Include back .length() method. It is quite handy and is more C++ oriented. - I considered the GLM library as a candidate for replacement. It felt like too much for what we need and would be difficult to extend / modify to our needs. - I used Macros to reduce code in operators declaration and potential copy paste bugs. This could reduce debugability and could be reverted. - This touches delaunay_2d.cc and the intersection code. I would like to know @Howard Trickey (howardt) opinion on the matter. - The noexcept on the copy constructor of mpq(2|3) is being removed. But according to @Jacques Lucke (JacquesLucke) it is not a real problem for now. I would like to give a huge thanks to @Jacques Lucke (JacquesLucke) who helped during this and pushed me to reduce the duplication further. Reviewed By: brecht, sergey, JacquesLucke Differential Revision: http://developer.blender.org/D13791
2022-01-11Add support for a longest diagonal quad triangulation modeHenrik Dick
The new triangulation mode for quads is the opposite of the current default shortest diagonal mode. It is optimal for cloth simulations using quad meshes. Differential Revision: http://developer.blender.org/D13777
2022-01-07Cleanup: remove redundant const qualifiers for POD typesCampbell Barton
MSVC used to warn about const mismatch for arguments passed by value. Remove these as newer versions of MSVC no longer show this warning.
2022-01-06Cleanup: spelling in commentsCampbell Barton
2021-12-14Cleanup: resolve parameter mis-matches in doc-stringsCampbell Barton
Renamed or removed parameters which no longer exist.
2021-12-14Cleanup: correct unbalanced doxygen groupsCampbell Barton
Also add groups in some files.
2021-12-10Cleanup: move public doc-strings into headers for various API'sCampbell Barton
Some doc-strings were skipped because of blank-lines between the doc-string and the symbol and needed to be moved manually. - Added space below non doc-string comments to make it clear these aren't comments for the symbols directly below them. - Use doxy sections for some headers. Ref T92709
2021-12-10Cleanup: spelling in commentsCampbell Barton
2021-12-03Cleanup: move public doc-strings into headers for 'bmesh'Campbell Barton
Some minor improvements to doc-strings too. Ref T92709
2021-12-03Fix T93574: Asset triangulating a meshCampbell Barton
Correct assert for edit-mesh normal calculation.
2021-11-12Cleanup: remove redundant loop-index accessCampbell Barton
Use a counter for loop indices as they're being iterated in order.
2021-11-10Fix T92874: Custom normals reset when vertex is deletedCampbell Barton
Storing and restoring custom normals was broken by 39b2a7bb7e815e051348bf5c5ec777d091324164 This also caused "Sharp Edge" option for Weld by Distance to fail, reported as T92875.
2021-11-09Fix T92384: Wrong UV layers used with Boolean Modifier (Fast Solver)Campbell Barton
Ensure the layers from the source mesh are used instead of the object referenced by the boolean modifier.
2021-10-24Cleanup: spelling in commentsCampbell Barton
2021-10-03Cleanup: spelling in commentsCampbell Barton
2021-09-28Fix error in previous commitGermano Cavalcante
`v_other` -> `v_step`
2021-09-28Fix flag wrongly set in 'BM_face_split_edgenet_connect_islands'Germano Cavalcante
Sometimes the `use_partial_connect` option could trigger the assert: ``` BLI_assert(!BM_elem_flag_test(l_iter->v, VERT_NOT_IN_STACK)); ``` This can happen when `v_delimit->e` is not part of edgenet, so `v_other` will not have the flag.
2021-09-13Fix T84638: Wrong scale for primitives with radiusFalk David
Creating some primitives allows for a scale value (via python) that will scale the object accordingly. For objects with a radius parameter (like cylinders, spheres, etc.) passing a scale different to (1,1,1) would result in unexpected behavior. For example: `>>> bpy.ops.mesh.primitive_uv_sphere_add(radius=2, scale=(1,1,2))` We would expect this to create a sphere with a radius of 2 (dimensions 4,4,4) and then be scaled *2 along the z-axis (dimensions 4,4,8). But this would previously create a scaled sphere with dimensions (2,2,4). The scale was simply divided by two. Maybe because the "radius" parameter for creating the primitives was confusingly named "diameter" (but used as the radius). The fix adds a scale parameter to `ED_object_new_primitive_matrix` and also renames the wrongly named "diameter" parameters to "radius". Reviewed By: campbellbarton Maniphest Tasks: T84638 Ref D10093
2021-09-04BMesh: optimize edge & face group calculationMikkel Gjoel
This changes the search for unprocessed faces to only search from the previously found face. Local testing on 1.5 million triangle meshes gives a 75x speedup (of the code affected, which is the first half of the work). The former code would traverse all faces of a mesh until a face was found that had not been processed. This ended up being slow mainly because it had to load face-data to determine the state of the flag. Secondarily, the way it iterated and marked the mesh, it would end up traversing all previously processed faces to find and unprocessed one. The same optimization has been made for edge-group calculation. Reviewed By: campbellbarton Ref D12379
2021-08-17Cleanup: replace degenerate check with assertCampbell Barton
Use an assert since this should never happen.
2021-08-13Revert "Mesh: replace saacos with acosf for normal calculation"Campbell Barton
This reverts commit 41e650981861c2f18ab0548e18851d1d761066ff. This broke "CubeMaskFirst" test. Any value even slightly outside the [-1.0..1.0] range caused the result to be nan, which can happen when calculating the dot-product between two unit length vectors.
2021-08-13Mesh: replace saacos with acosf for normal calculationCampbell Barton
The clamped version of acos isn't needed as degenerate (nan) coordinates result in zeroed vectors which don't need clamping.
2021-08-09Fix T90532: Crash editing meshes with auto-smoothCampbell Barton
Caused by fix for T90256 and a misunderstanding in D11928. Don't skip tagging edges when the auto-smooth angle is 180 degrees since this skips topology checks which are needed for properly calculating edge loop normals.
2021-08-05Fix T90256: faces are flat shaded in edit mode with auto smoothCampbell Barton
Regression in 39b2a7bb7e815e051348bf5c5ec777d091324164.
2021-08-04Cleanup: rename restrict to hide/visibility in Object, Collection, MaskLayerBrecht Van Lommel
This makes the internal naming consistent with the public API. And also gives us a visibility_flag rather than restrictflag that can be extended with more flags.
2021-08-04Fix T90421: edit-mode auto-smooth crash when angle set to 180degreesCampbell Barton
Error in 39b2a7bb7e815e051348bf5c5ec777d091324164 which failed to set edge flags with single threaded calculation, used for low poly models.
2021-08-03Cleanup: use C++ comments or 'if 0' for commented codeCampbell Barton