Commit Graph

121 Commits

Author SHA1 Message Date
Jesse Yurkovich 5ad9f9dc90 Cleanup: unused includes in source/blender/io
Reduce dependence on Blender headers as much as possible and move closer
to an include-what-you-use setup.

- Removes unnecessary includes
- Replaces some includes with more appropriate, narrower, substitutes

Pull Request: https://projects.blender.org/blender/blender/pulls/119234
2024-03-10 04:28:00 +01:00
Campbell Barton 1b514659ca Cleanup: minor changes to temp directory API
- Pass null instead of an empty string to BKE_tempdir_init
  because the string isn't meant to be used.
- Never pass null to BLI_temp_directory_path_copy_if_valid
  (the caller must check).
- Additional comments for which checks are performed & why
  from discussion about #95411.
2024-03-04 11:42:02 +11:00
Campbell Barton 12386e6809 Fix PLY import error caused by recent cleanup
Regression caused by [0]. Passing "Span" by value caused io_ply test to
fail. References were used so changes would be applied to arguments
passed in.

Revert these changes for "ply_import.cc".

[0]: d338261c55
2024-02-28 17:01:30 +11:00
Hans Goudey d338261c55 Cleanup: Pass Span by value
Also pass Span instead of `const Array &`
and use parantheses for BLI includes.
2024-02-27 23:09:54 -05:00
Hans Goudey 19c6f7bfac Fix: Build error after recent commit with incorrect header names
5d9e127234
2024-02-26 15:14:25 -05:00
Jesse Yurkovich e3122d270d Merge branch 'blender-v4.1-release' 2024-02-26 11:48:43 -08:00
Jesse Yurkovich 5d9e127234 Fix: Proper error handling for STL, PLY, and OBJ IO
Properly handle exceptions from STL and PLY code to prevent crashes on
invalid file paths.

This will now also Report errors/warnings to the callers of these
formats as well. For the UI this means a Report banner and Info editor
entry. For Python scripts this means an exception instead of silently
continuing.

Related to #117881
Pull Request: https://projects.blender.org/blender/blender/pulls/118731
2024-02-26 20:45:46 +01:00
Brecht Van Lommel 0f2064bc3b Revert changes from main commits that were merged into blender-v4.1-release
The last good commit was 4bf6a2e564.
2024-02-19 15:59:59 +01:00
Hans Goudey 81a63153d0 Despgraph: Rename "copy-on-write" to "copy-on-evaluation"
The depsgraph CoW mechanism is a bit of a misnomer. It creates an
evaluated copy for data-blocks regardless of whether the copy will
actually be written to. The point is to have physical separation between
original and evaluated data. This is in contrast to the commonly used
performance improvement of keeping a user count and copying data
implicitly when it needs to be changed. In Blender code we call this
"implicit sharing" instead. Importantly, the dependency graph has no
idea about the _actual_ CoW behavior in Blender.

Renaming this functionality in the despgraph removes some of the
confusion that comes up when talking about this, and will hopefully
make the depsgraph less confusing to understand initially too. Wording
like "the evaluated copy" (as opposed to the original data-block) has
also become common anyway.

Pull Request: https://projects.blender.org/blender/blender/pulls/118338
2024-02-19 15:54:08 +01:00
Hans Goudey 61e61ce0e1 Cleanup: Use Span instead of Vector const reference
Span is preferrable since it's agnostic of the source container,
makes it clearer that there is no ownership, is 8 bytes smaller,
and can be passed by value.
2024-02-14 17:23:01 -05:00
Hans Goudey 1c0f374ec3 Object: Move transform matrices to runtime struct
The `object_to_world` and `world_to_object` matrices are set during
depsgraph evaluation, calculated from the object's animated location,
rotation, scale, parenting, and constraints. It's confusing and
unnecessary to store them with the original data in DNA.

This commit moves them to `ObjectRuntime` and moves the matrices to
use the C++ `float4x4` type, giving the potential for simplified code
using the C++ abstractions. The matrices are accessible with functions
on `Object` directly since they are used so commonly. Though for write
access, directly using the runtime struct is necessary.

The inverse `world_to_object` matrix is often calculated before it's
used, even though it's calculated as part of depsgraph evaluation.
Long term we might not want to store this in `ObjectRuntime` at all,
and just calculate it on demand. Or at least we should remove the
redundant calculations. That should be done separately though.

Pull Request: https://projects.blender.org/blender/blender/pulls/118210
2024-02-14 16:14:49 +01:00
Bastien Montagne 29fe777445 Cleanup: Make `BKE_report.h` a full Cpp header. 2024-02-10 18:34:29 +01:00
Jacques Lucke 442429a97c BLI: support formatting StringRef with the fmt library
People were manually converting it to `std::string_view` in many places already.
It's easy enough to allow using `StringRef` directly by providing a `format_as` function.

Also see https://fmt.dev/latest/api.html#udt.

Pull Request: https://projects.blender.org/blender/blender/pulls/117788
2024-02-03 19:14:51 +01:00
Ray Molenkamp fc409e4388 Cleanup: CMake: Modernize extern_fmtlib dependencies
Pretty straightforward

- Remove any fmtlib paths from INC
- Add a dependency though LIB when missing

context: https://devtalk.blender.org/t/cmake-cleanup/30260

Pull Request: https://projects.blender.org/blender/blender/pulls/117787
2024-02-03 18:55:09 +01:00
Jacques Lucke 319b911784 Cleanup: move hash and ghash utils to C++
Also see #103343.

Pull Request: https://projects.blender.org/blender/blender/pulls/117761
2024-02-02 19:55:06 +01:00
Hans Goudey c87e51790d Cleanup: Make format 2024-01-31 22:01:30 -05:00
Hans Goudey fac27b1b6b Cleanup: Replace most used of SWAP macro with std::swap
Also remove / replace use of the math vector double swapping functions.
2024-01-31 21:12:16 -05:00
Hans Goudey ebcdf19537 Cleanup: Use consistent camel case for test class names 2024-01-26 10:25:48 -05:00
Jacques Lucke 932b2d1727 Cleanup: simplify naming of get_default_hash 2024-01-26 11:45:56 +01:00
Hans Goudey 02582213de Cleanup: Move BKE_layer.hh to C++ 2024-01-24 10:55:16 -05:00
Bastien Montagne d8d44a62f7 Cleanup: Move `BKE_appdir.h` to full Cpp header `BKE_appdir.hh`. 2024-01-21 19:42:13 +01:00
Hans Goudey 3e76a1a6c2 Cleanup: Move BKE_lib_id.h to C++ 2024-01-15 12:44:14 -05:00
Campbell Barton 617f7b76df Cleanup: comment block formatting 2024-01-08 11:31:43 +11:00
Brecht Van Lommel 364beee159 Tests: add option to build one binary per GTest file
Bundling many tests in a single binary reduces build time and disk space
usage, but is less convenient for running individual tests command line
as filter flags need to be used.

This adds WITH_TESTS_SINGLE_BINARY to generate one executable file per
source file. Note that enabling this option requires a significant amount
of disk space.

Due to refactoring, the resulting ctest names are a bit different than
before. The number of tests is also a bit different depending if this
option is used, as one uses gtests discovery and the other is organized
purely by filename, which isn't always 1:1.

Co-authored-by: Sergey Sharybin <sergey@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/114604
2024-01-03 18:35:50 +01:00
Brecht Van Lommel f63accd3b6 Cleanup: move CMake test utility functions into testing.cmake
Combining functions from macros.cmake and Modules/GTestTesting.cmake.
It was unusual to have Blender specific code in the Modules folder.

Pull Request: https://projects.blender.org/blender/blender/pulls/116719
2024-01-03 14:49:11 +01:00
Brecht Van Lommel d377ef2543 Clang Format: bump to version 17
Along with the 4.1 libraries upgrade, we are bumping the clang-format
version from 8-12 to 17. This affects quite a few files.

If not already the case, you may consider pointing your IDE to the
clang-format binary bundled with the Blender precompiled libraries.
2024-01-03 13:38:14 +01:00
Brecht Van Lommel 4ce14a639f Revert "Cleanup: move CMake test utility functions into testing.cmake"
This breaks execution of some Windows tests.

This reverts commit 4190a61020.
2024-01-02 19:06:39 +01:00
Brecht Van Lommel 4190a61020 Cleanup: move CMake test utility functions into testing.cmake
Combining functions from macros.cmake and Modules/GTestTesting.cmake.
It was unusual to have Blender specific code in the Modules folder.
2024-01-02 15:34:52 +01:00
Hans Goudey 2c43a9eed9 Cleanup: Move BKE_mesh_calc_edges to bke namespace
Also use reference for mesh argument, and move edges calculation
from legacy faces to "legacy" file.
2023-12-20 20:47:10 -05:00
Hans Goudey 19b46e0816 Cleanup: Make format 2023-12-20 14:54:50 -05:00
Hans Goudey edf8a776ac Cleanup: Use forward declarations to replace includes of BKE_attribute.hh
Remove most includes of this header inside other headers, to remove unnecessary
indirect includes which can have a impact on compile times. In the future we may
want more dedicated "_fwd.hh" headers, but until then, this sticks with the
solution in existing code.

Unfortunately it isn't yet possible to remove the include from `BKE_geometry_set.hh`.
2023-12-20 13:25:28 -05:00
Hans Goudey 19001c9e6c Cleanup: Move attribute domain enum to C++ header, use enum class
Each value is now out of the global namespace, so they can be shorter
and easier to read. Most of this commit just adds the necessary casting
and namespace specification. `enum class` can be forward declared since
it has a specified size. We will make use of that in the next commit.
2023-12-20 13:25:28 -05:00
Hans Goudey 8dd8f932e2 Cleanup: Rename Mesh loop_data to corner_data
Related to #110434, efbee2d606, 7c69c8827b
2023-12-19 20:39:05 -05:00
Hans Goudey efbee2d606 Mesh: Rename totvert, totedge, and totloop fields
Use the standard "elements_num" naming, and use the "corner" name rather
than the old "loop" name: `verts_num`, `edges_num`, and `corners_num`.
This matches the existing `faces_num` field which was already renamed.

Pull Request: https://projects.blender.org/blender/blender/pulls/116350
2023-12-20 02:21:48 +01:00
Hans Goudey e657aa2360 Cleanup: Move two mesh functions to C++ header 2023-12-13 09:50:47 -05:00
Aras Pranckevicius a0640ce8d5 PLY: extend test coverage for #116022 2023-12-12 19:09:43 +02:00
Aras Pranckevicius 460439acba Fix #116022: Binary PLY import fails if first data byte is 0x0A or 0x0D
Now instead of trying to potentially handle unlimited amount of
newlines (which might be actual data in a binary file), only
explicitly handle either LF or CRLF line endings. Fixes #116022.

Will add test coverage in a followup commit, for easier backporting
of just the fix if needed.
2023-12-12 19:09:43 +02:00
Hans Goudey 7a96c4672c Cleanup: Move BMesh headers to C++
Pull Request: https://projects.blender.org/blender/blender/pulls/115817
2023-12-05 23:01:12 +01:00
Ray Molenkamp 6b70c04724 Cleanup: CMake: Modernize bf_depsgraph dependencies
Pretty straightforward

- Remove any bf_depsgraph paths from INC
- Add a dependency though LIB when missing

context: https://devtalk.blender.org/t/cmake-cleanup/30260

Pull Request: https://projects.blender.org/blender/blender/pulls/115422
2023-11-25 22:51:59 +01:00
Hans Goudey 3d57bc4397 Cleanup: Move several blenkernel headers to C++
Mostly focus on areas where we're already using C++ features,
where combining C and C++ APIs is getting in the way.

Pull Request: https://projects.blender.org/blender/blender/pulls/114972
2023-11-16 11:41:55 +01:00
Jesse Yurkovich 3a312babe6 Fix #114847: Skip past more newlines when parsing PLY files
When parsing PLY files it was possible that the buffer would contain
leading newline characters which were not being accounted for.

Ensure we skip past them each time we refill the buffer. Also properly
return an error string when handling such lines in the future.

Pull Request: https://projects.blender.org/blender/blender/pulls/114878
2023-11-15 08:31:55 +01:00
Sergey Sharybin 2020f35981 Cleanup: Avoid shallow copy in PLY exporter
It is not clear why shallow copy needs to be created to access
some fields which are copied from the input object. Just use that
object directly.

Shallow copying is a weird and legacy concept, it should not be
used without huge disclaimer why it is unavoidable in the new
code.

Pull Request: https://projects.blender.org/blender/blender/pulls/114791
2023-11-14 10:59:22 +01:00
Iliya Katueshenock 4f03d502e6 Cleanup: Remove iostreams include from timeit header
Continuation of #110986

Pull Request: https://projects.blender.org/blender/blender/pulls/111010
2023-11-13 10:42:29 +01:00
Campbell Barton 134393e846 Cleanup: spelling in comments 2023-11-04 14:08:13 +11:00
Aras Pranckevicius 6833202ab3 PLY: improve import of custom vertex normals
Several improvements how PLY files containing vertex normals are imported:
- When they are present on a regular mesh, the code no longer sets
  all faces as "flat" (since that makes custom normals be ignored).
- When they are present on a pure point cloud (i.e. no faces),
  custom vertex normals are added as a float3 point domain attribute
  (ref #114371).
2023-11-03 17:41:27 +02:00
Aras Pranckevicius d59c6d3e5c PLY: fix unreported crash when exporting multiple objects with different presence of vertex colors
Similar to e98cc412e, exporting PLY essentially merges all meshes into
one. And if any of them has vertex colors to export, they all
should get a fake/dummy vertex color entry.
2023-11-03 08:52:36 +02:00
Aras Pranckevicius e98cc412ef Fix #114346: PLY export crash with multiple objects that have different custom attributes
Custom attribute export (#114320) code did not realize that
PLY exports everything as one single "mesh" with the same vertex
data for everything. So if exporting several input meshes and they
have different vertex attributes, the result needs to have a union
of all present attributes, with fake/zero data for the ones
that were not actually present. Fixes #114346.
2023-11-02 22:58:26 +02:00
Aras Pranckevicius 0eb6aef3b0 PLY: import/export custom vertex attributes (#108948)
Implements #108948 - support for custom point domain attributes for PLY
import and export. Notes:

- Custom attributes are always represented as scalar floats. PLY itself
  has some data types that blender can't fully represent, e.g. double or
  uint32, or some that fit into a float just fine but blender does not have
  them as separate types (e.g. int16).
- When importing, any PLY vertex attribute that is not one of "standard"
  names (position, normal, etc.) gets turned into a custom attribute.
- For exporting, more complex custom attributes (e.g. 2D/3D floats,
  quaternions, colors) get turned into several PLY attributes, with "_x"
  like suffix.

Custom attribute import/export is on by default in the UI.

Pull Request: https://projects.blender.org/blender/blender/pulls/114320
Reviewed By: Hans Goudey
2023-10-31 14:07:51 +01:00
Hans Goudey 976eaae02f Cleanup: Move BKE_object.hh to C++
Simplifies the fix to #111120, where the object bounds functions
may return a C++ type instead of `BoundBox`.

Pull Request: https://projects.blender.org/blender/blender/pulls/113462
2023-10-09 23:41:53 +02:00
Aras Pranckevicius bf23d0e53c Fix #112011: PLY export broken when mesh contains faces with >255 vertices
MPoly -> offset indices refactor (7966cd16d6) did not realize
that due to forced triangulation the mesh changes, so we need
to re-fetch the faces array after triangulating. Fixes #112011
2023-09-28 14:21:23 +03:00