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-10-13Cleanup: Use std::mutex for mesh runtime mutexesHans Goudey
Instead of allocating three separate ThreadMutex pointers, just embed std::mutex into the struct directly.
2022-10-13Mesh: Move runtime data out of DNAHans Goudey
This commit replaces the `Mesh_Runtime` struct embedded in `Mesh` with `blender::bke::MeshRuntime`. This has quite a few benefits: - It's possible to use C++ types like `std::mutex`, `Array`, `BitVector`, etc. more easily - Meshes saved in files are slightly smaller - Copying and writing meshes is a bit more obvious without clearing of runtime data, etc. The first is by far the most important. It will allows us to avoid a bunch of manual memory management boilerplate that is error-prone and annoying. It should also simplify future CoW improvements for runtime data. This patch doesn't change anything besides changing `mesh.runtime.data` to `mesh.runtime->data`. The cleanups above will happen separately. Differential Revision: https://developer.blender.org/D16180
2022-10-12Cleanup: use commented arguments for unused args in C++Campbell Barton
2022-09-25Cleanup: use 'u' prefixed integer types for brevity & cast styleCampbell Barton
To use function style cast '(unsigned char)x' can't be replaced by 'unsigned char(x)'.
2022-09-23Mesh: Move edge crease out of MEdgeHans Goudey
This is very similar to D14077. There are two differences though. First is that vertex creases are already stored in a separate layer, and second is that we can now completely remove use of `Mesh.cd_flag`, since that information is now inherent to whether the layers exist. There are two functional differences here: * Operators are used to add and remove layers instead of a property. * The "crease" attribute can be created and removed by geometry nodes. The second change should make various geometry nodes slightly faster, since the "crease" attribute was always processed before. Creases are now interpolated generically in the CustomData API too, which should help maintain the values across edits better. Meshes get an `edge_creases` RNA property like the existing vertex property, to provide more efficient access to the data in Cycles. One test failure is expected, where different rounding between float the old char storage means that 5 additional points are scattered in a geometry nodes test. Differential Revision: https://developer.blender.org/D15927
2022-09-16Cleanup: spelling in commentsCampbell Barton
2022-09-14Cleanup: Remove unused argument from modifier data mask callbackHans Goudey
This isn't likely to be helpful in the future with the move to generic attributes
2022-09-14ViewLayer: Lazy sync of scene data.Monique Dewanchand
When a change happens which invalidates view layers the syncing will be postponed until the first usage. This will improve importing or adding many objects in a single operation/script. `BKE_view_layer_need_resync_tag` is used to tag the view layer to be out of sync. Before accessing `BKE_view_layer_active_base_get`, `BKE_view_layer_active_object_get`, `BKE_view_layer_active_collection` or `BKE_view_layer_object_bases` the caller should call `BKE_view_layer_synced_ensure`. Having two functions ensures that partial syncing could be added as smaller patches in the future. Tagging a view layer out of sync could be replaced with a partial sync. Eventually the number of full resyncs could be reduced. After all tagging has been replaced with partial syncs the ensure_sync could be phased out. This patch has been added to discuss the details and consequences of the current approach. For clarity the call to BKE_view_layer_ensure_sync is placed close to the getters. In the future this could be placed in more strategical places to reduce the number of calls or improve performance. Finding those strategical places isn't that clear. When multiple operations are grouped in a single script you might want to always check for resync. Some areas found that can be improved. This list isn't complete. These areas aren't addressed by this patch as these changes would be hard to detect to the reviewer. The idea is to add changes to these areas as a separate patch. It might be that the initial commit would reduce performance compared to master, but will be fixed by the additional patches. **Object duplication** During object duplication the syncing is temporarily disabled. With this patch this isn't useful as when disabled the view_layer is accessed to locate bases. This can be improved by first locating the source bases, then duplicate and sync and locate the new bases. Will be solved in a separate patch for clarity reasons ({D15886}). **Object add** `BKE_object_add` not only adds a new object, but also selects and activates the new base. This requires the view_layer to be resynced. Some callers reverse the selection and activation (See `get_new_constraint_target`). We should make the selection and activation optional. This would make it possible to add multiple objects without having to resync per object. **Postpone Activate Base** Setting the basact is done in many locations. They follow a rule as after an action find the base and set the basact. Finding the base could require a resync. The idea is to store in the view_layer the object which base will be set in the basact during the next sync, reducing the times resyncing needs to happen. Reviewed By: mont29 Maniphest Tasks: T73411 Differential Revision: https://developer.blender.org/D15885
2022-09-12When these features aren't used, there is no sense in storing theHans Goudey
corresponding data layers and using their values for computations. Avoiding that should increase performance in many operations that would otherwise have to read, write, or propagate these values. It also means decreased memory usage-- not just for sculpt mode but for any mesh that was in sculpt mode. Previously the mask, face set, and hide status layers were *always* allocated by sculpt mode. Here are a few basic tests when masking and face sets are not used: | Test | Before | After | | Subsurf Modifier | 148 ms | 126 ms | | Sculpt Overlay Extraction | 24 ms every redraw | 0 ms | | Memory usage | 252 MB | 236 MB | I wouldn't expect any difference when they are used though. The code changes are mostly just making sculpt features safe for when the layers aren't stored, and some changes to the conversion to and from the hide layers. Use of the ".hide_poly" attribute replaces testing whether face sets are negative in many places. Differential Revision: https://developer.blender.org/D15937
2022-09-12Cleanup: Remove unused DerivedMesh functionsHans Goudey
2022-09-08Cleanup: Use C++ methods to retrieve attribute accessorsHans Goudey
Replace `mesh_attributes`, `mesh_attributes_for_write` and the point cloud versions with methods on the `Mesh` and `PointCloud` types. This makes them friendlier to use and improves readability. Differential Revision: https://developer.blender.org/D15907
2022-09-07Cleanup: Tweak naming for recently added mesh accessorsHans Goudey
Use `verts` instead of `vertices` and `polys` instead of `polygons` in the API added in 05952aa94d33eeb50. This aligns better with existing naming where the shorter names are much more common.
2022-09-05Mesh: Remove redundant custom data pointersHans Goudey
For copy-on-write, we want to share attribute arrays between meshes where possible. Mutable pointers like `Mesh.mvert` make that difficult by making ownership vague. They also make code more complex by adding redundancy. The simplest solution is just removing them and retrieving layers from `CustomData` as needed. Similar changes have already been applied to curves and point clouds (e9f82d3dc7ee, 410a6efb747f). Removing use of the pointers generally makes code more obvious and more reusable. Mesh data is now accessed with a C++ API (`Mesh::edges()` or `Mesh::edges_for_write()`), and a C API (`BKE_mesh_edges(mesh)`). The CoW changes this commit makes possible are described in T95845 and T95842, and started in D14139 and D14140. The change also simplifies the ongoing mesh struct-of-array refactors from T95965. **RNA/Python Access Performance** Theoretically, accessing mesh elements with the RNA API may become slower, since the layer needs to be found on every random access. However, overhead is already high enough that this doesn't make a noticible differenc, and performance is actually improved in some cases. Random access can be up to 10% faster, but other situations might be a bit slower. Generally using `foreach_get/set` are the best way to improve performance. See the differential revision for more discussion about Python performance. Cycles has been updated to use raw pointers and the internal Blender mesh types, mostly because there is no sense in having this overhead when it's already compiled with Blender. In my tests this roughly halves the Cycles mesh creation time (0.19s to 0.10s for a 1 million face grid). Differential Revision: https://developer.blender.org/D15488
2022-08-31Mesh: Remove unnecessary copy in modifier stackHans Goudey
These few lines making a copy of the final mesh were confusing. The goal (I'm fairly certain) is to make sure the cage mesh and final mesh aren't shared when applying the vertex coordinates to the final mesh. This can be done more simply though, in a way that avoids duplicating the final mesh if it already isn't shared. This works well in some basic tests with different modifiers. Though I doubt it was really a bottleneck anywhere, simplifying the modifier stack internals is always nice. Differential Revision: https://developer.blender.org/D15814
2022-08-31Mesh: Avoid redundant custom data layer initializationHans Goudey
In all these cases, it was clear that the layer values were set right after the layer was created anyway. So there's no point in using calloc or setting the values to zero first. See 25237d2625078c6d for more info.
2022-08-30Merge branch 'blender-v3.3-release'Hans Goudey
2022-08-30Fix: Potential name clash when adding rest position attributeHans Goudey
If a "rest_position" attribute already existed, potentiall with another type, the next name "rest_position.001" would be used, which might even conflict with a name on another domain. Use the C++ attribute API instead, which has more standard/predictable behavior.
2022-08-30Attributes: Improve custom data initialization optionsHans Goudey
When allocating new `CustomData` layers, often we do redundant initialization of arrays. For example, it's common that values are allocated, set to their default value, and then set to some other value. This is wasteful, and it negates the benefits of optimizations to the allocator like D15082. There are two reasons for this. The first is array-of-structs storage that makes it annoying to initialize values manually, and the second is confusing options in the Custom Data API. This patch addresses the latter. The `CustomData` "alloc type" options are rearranged. Now, besides the options that use existing layers, there are two remaining: * `CD_SET_DEFAULT` sets the default value. * Usually zeroes, but for colors this is white (how it was before). * Should be used when you add the layer but don't set all values. * `CD_CONSTRUCT` refers to the "default construct" C++ term. * Only necessary or defined for non-trivial types like vertex groups. * Doesn't do anything for trivial types like `int` or `float3`. * Should be used every other time, when all values will be set. The attribute API's `AttributeInit` types are updated as well. To update code, replace `CD_CALLOC` with `CD_SET_DEFAULT` and `CD_DEFAULT` with `CD_CONSTRUCT`. This doesn't cause any functional changes yet. Follow-up commits will change to avoid initializing new layers where the correctness is clear. Differential Revision: https://developer.blender.org/D15617
2022-08-09Cleanup: use own username in code-comment tagsCampbell Barton
2022-07-12Fix threading crash due to conflict in mesh wrapper typeSergey Sharybin
A mesh wrapper might be being accessed for read-only from one thread while another thread converts the wrapper type to something else. The proposes solution is to defer assignment of the mesh wrapper type until the wrapper is fully converted. The good thing about this approach is that it does not introduce extra synchronization (and, potentially, evaluation pipeline stalls). The downside is that it might not work with all possible wrapper types in the future. If a wrapper type which does not clear data separation is ever added in the future we will re-consider the threading safety then. Unfortunately, some changes outside of the mesh wrapper file are to be made to allow "incremental" construction of the mesh prior changing its wrapper type. Unfortunately, there is no simplified file which demonstrates the issue. It was investigated using Heist production file checked at the revision 1228: `pro/lib/char/einar/einar.shading.blend`. The repro case is simple: tab into edit mode, possibly few times. The gist is that there several surface deform and shrinkwrap modifiers which uses the same target. While one of them is building BVH tree (which changes wrapper type) the other one accesses it for read-only via `BKE_mesh_wrapper_vert_coords_copy_with_mat4()`. Differential Revision: https://developer.blender.org/D15424
2022-07-08Curves: support deforming curves on surfaceJacques Lucke
Curves that are attached to a surface can now follow the surface when it is modified using shape keys or modifiers (but not when the original surface is deformed in edit or sculpt mode). The surface is allowed to be changed in any way that keeps uv maps intact. So deformation is allowed, but also some topology changes like subdivision. The following features are added: * A new `Deform Curves on Surface` node, which deforms curves with attachment information based on the surface object and uv map set in the properties panel. * A new `Add Rest Position` checkbox in the shape keys panel. When checked, a new `rest_position` vector attribute is added to the mesh before shape keys and modifiers are applied. This is necessary to support proper deformation of the curves, but can also be used for other purposes. * The `Add > Curve > Empty Hair` operator now sets up a simple geometry nodes setup that deforms the hair. It also makes sure that the rest position attribute is added to the surface. * A new `Object (Attach Curves to Surface)` operator in the `Set Parent To` (ctrl+P) menu, which attaches existing curves to the surface and sets the surface object as parent. Limitations: * Sculpting the procedurally deformed curves will be implemented separately. * The `Deform Curves on Surface` node is not generic and can only be used for one specific purpose currently. We plan to generalize this more in the future by adding support by exposing more inputs and/or by turning it into a node group. Differential Revision: https://developer.blender.org/D14864
2022-06-29Sculpt: Fix backwards normals in PBVH_GRIDS raycastingJoseph Eagar
Winding order of grid quads was backwards.
2022-06-14Fix T98813: crash with GPU subdiv in edit mode and instanced geometryBrecht Van Lommel
Instancing with geometry nodes uses just the evaluated Mesh, and ignores the Object that it came from. That meant that it would try to look up the subsurf modifier on the instancer object which does not have the subsurf modifier. Instead of storing a session UUID and looking up the modifier data, store a point to the subsurf modifier runtime data. Unlike the modifier data, this runtime data is preserved across depsgraph CoW. It must be for the subdiv descriptor contained in it to stay valid along with the draw cache. As a bonus, this moves various Mesh_Runtime variables into the subsurf runtime data, reducing memory usage for meshes not using subdivision surfaces. Also fixes T98693, issues with subdivision level >= 8 due to integer overflow. Differential Revision: https://developer.blender.org/D15184
2022-06-07Cleanup: spelling in comments, additional white spaceCampbell Barton
2022-05-18Merge branch 'blender-v3.2-release'Sergey Sharybin
2022-05-18Subdiv: support interpolating orco coordinates in subdivision surfacesBrecht Van Lommel
This makes changes to the opensubdiv module to support additional vertex data besides the vertex position, that is smootly interpolated the same way. This is different than varying data which is interpolated linearly. Fixes T96596: wrong generated texture coordinates with GPU subdivision. In that bug lazy subdivision would not interpolate orcos. Later on, this implementation can also be used to remove the modifier stack mechanism where modifiers are evaluated a second time for orcos, which is messy and inefficient. But that's a more risky change, this is just the part to fix the bug in 3.2. Differential Revision: https://developer.blender.org/D14973
2022-05-15Cleanup: Remove includes from DerivedMesh headerHans Goudey
Headers should only include other headers when absolutely necessary, to avoid unnecessary dependencies and increasing compile times. To make this change simpler, three DerivedMesh functions with a single use were removed.
2022-04-27Fix broken obj tests from earlier commitKévin Dietrich
rB08731d70bf66 was not properly checking if subdivision needs to be evaluated on the CPU. Thanks Ray Molenkamp for noticing.
2022-04-27Fix T96327: data transfer crash with GPU subdivisionKévin Dietrich
The crash is caused as the subdivision wrapper does not have loop normals, which are generally computed at the end of the modifier stack evaluation via `mesh_calc_modifier_final_normals`. (Note that they are initially computed, but deleted by the subdivision wrapper creation.) This records in the mesh runtime whether loop normals should have been computed and computes them alongside the subdivision wrapper. Differential Revision: https://developer.blender.org/D14489
2022-04-21Cleanup: Remove unused argument to mesh modifier evaluationHans Goudey
2022-04-20Cleanup: Rename CD_MLOOPCOL to CD_PROP_BYTE_COLORHans Goudey
The "PROP" in the name reflects its generic status, and removing "LOOP" makes sense because it is no longer associated with just mesh face corners. In general the goal is to remove extra semantic meaning from the custom data types.
2022-04-07Cleanup: remove unused mface tesselation code from modifier stackBrecht Van Lommel
This seems to serve no purpose anymore, I don't see anywhere that CD_MFACE is requested for modifier evaluation, and it's confusing to have this in this final normals computation function. Found while looking into D14579. Differential Revision: https://developer.blender.org/D14580
2022-04-07Fix T97035: crash transferring face corner dataBrecht Van Lommel
The mechanism to instance meshes when there are no modifiers did not take into account that modifiers might get re-evaluated from an operator that requests loop normals. Now check for that case and no longer use the instance then. In the future, a better solution may be to compute loop normals on demand as is already done for poly and vertex normals, but that would be a big change. Differential Revision: https://developer.blender.org/D14579
2022-03-07Cleanup: fix various typosBrecht Van Lommel
Contributed by luzpaz. Differential Revision: https://developer.blender.org/D14203
2022-03-01Merge branch 'blender-v3.1-release'Sergey Sharybin
2022-03-01Fix T95997: Crash when entering edit modeSergey Sharybin
The issue was uncovered by the 0f89bcdbebf5, but the root cause goes into a much earlier design violation happened in the code: the modifier evaluation function is modifying input mesh, which is not something what is ever expected. Bring code closer to the older state where such modification is only done for the object in edit mode. --- From own tests works seems to work fine, but extra eyes and testing is needed. Differential Revision: https://developer.blender.org/D14191
2022-02-28Merge branch 'blender-v3.1-release'Brecht Van Lommel
2022-02-28Fix T92288, T96041: instancing of shared mesh objects without modifiers brokenBrecht Van Lommel
New code from the vertex normal refactor cfa53e0fbeed combined with older code from 592759e3d62a that disabled instancing for custom normals and autosmooth meant that instancing was always disabled. However we do not need to disable instancing for custom normals and autosmooth at all, this can be shared between instances just fine.
2022-02-19Merge branch 'blender-v3.1-release'Hans Goudey
2022-02-18Cleanup: Use functions for accessing mesh normal dirty stateHans Goudey
It's better not to expose the details of where the dirty flags are stored to every place that wants to know if the normals are dirty. Some of these places are relics from before vertex normals were computed lazily anyway, so this is more of an incrememtal cleanup. This will make part of the fix for T95839 simpler.
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-14Cleanup: Pass const Scene to mesh evaluationHans Goudey
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-10Fix T95334: Crash with no vertex normals in multires bakeHans Goudey
This is partially caused by a stupid mistake in cfa53e0fbeed7178c78 where I missed initializing the `vert_normals` pointer in `MResolvePixelData`. It's also caused by questionable assumptions from DerivedMesh code that vertex normals would be valid. The fix used here is to create a temporary mesh with the data necessary to compute vertex normals, and ensure them here. This is used because normal calculation is only implemented for `Mesh` and edit mesh, not `DerivedMesh`. While this might not be great for performance, it's potentially aligned with future refactoring of this code to remove `DerivedMesh` completely. Since this is one of the last places the data structure is used, that would be a great improvement. Differential Revision: https://developer.blender.org/D13960
2022-02-04Fix: Remove incorrect assert in mesh modifier evaluationHans Goudey
Since we have a node that sets a mesh's auto smooth angle (unfortunately, in retrospect), we generally can't assume at all that value is the same as whatever input mesh. Similar asserts were removed previously in 8216b759e9557c786. While the attempt at assertions to clarify assumptions is noble, this one doesn't make sense anymore. I found this while investigating T95479. Differential Revision: https://developer.blender.org/D14009
2022-02-04Fix: Remove incorrect assert in mesh modifier evaluationHans Goudey
Since we have a node that sets a mesh's auto smooth angle (unfortunately, in retrospect), we generally can't assume at all that value is the same as whatever input mesh. Similar asserts were removed previously in 8216b759e9557c786. While the attempt at assertions to clarify assumptions is noble, this one doesn't make sense anymore. I found this while investigating T95479. Differential Revision: https://developer.blender.org/D14009
2022-02-03Fix T95334: Crash with no vertex normals in multires bakeHans Goudey
This is partially caused by a stupid mistake in cfa53e0fbeed7178c78 where I missed initializing the `vert_normals` pointer in `MResolvePixelData`. It's also caused by questionable assumptions from DerivedMesh code that vertex normals would be valid. The fix used here is to create a temporary mesh with the data necessary to compute vertex normals, and ensure them here. This is used because normal calculation is only implemented for `Mesh` and edit mesh, not `DerivedMesh`. While this might not be great for performance, it's potentially aligned with future refactoring of this code to remove `DerivedMesh` completely. Since this is one of the last places the data structure is used, that would be a great improvement. Differential Revision: https://developer.blender.org/D13960
2022-01-31Cleanup: Remove unused "_ex" version of functionHans Goudey
2022-01-31Cleanup: Remove unused DerivedMesh flagHans Goudey
The value of this flag was never used.
2022-01-31Cleanup: Remove unused DerivedMesh functionsHans Goudey
Remove functions and function pointers that were never set or never used at all. The "tessface" original index handling in `subsurf_ccg.c` can be removed because the data was never used.