Commit Graph

379 Commits

Author SHA1 Message Date
Iliya Katueshenock
75d17b1db5 Cleanup: Move BKE_node to namespace
Move all header file into namespace.
Unnecessary namespaces was removed from implementations file.
Part of forward declarations in header was moved in the top part
of file just to do not have a lot of separate namespaces.

Pull Request: https://projects.blender.org/blender/blender/pulls/121637
2024-05-13 16:07:12 +02:00
Aras Pranckevicius
39150096d8 Fix #121720: OBJ does not import some curves properly
If a curve was not using U parameter range of 0..1, the importer
did not properly detect whether the "U endpoint" flag should
be set on it. Fixed that, along with test coverage for the case.
2024-05-13 11:45:20 +03:00
Campbell Barton
d3c6eeb03e Docs: merge doc-strings, move move into header 2024-05-04 15:36:28 +10:00
Campbell Barton
4f5f0040c0 Cleanup: back-tick quote file extensions in code-comments 2024-05-04 15:06:46 +10:00
Campbell Barton
761dd6c923 IO: enable mesh validation by default for STL, PLY & OBJ importers
When moving importers from Python to C++ validation was removed
(from PLY) & disabled by default (STL & OBJ) which re-introduces
crashes reported by users such as #31835.

Enable validation by default because crashes caused by imported data
should be avoided, especially since the crashes may happen later when
users enter edit-mode or run certain editing operations.

This does slow down importing, from testing a 236MB .OBJ it takes around
twice as long to import (~1.5 to ~3 seconds). Although validation can
be optimized to reduce the overhead ad well as run in parallel for
importers that load multiple objects.

The defaults for USD and Alembic remain unchanged since this was never
enabled by default, although we could consider enabling these as well.
2024-05-04 14:40:06 +10:00
Bastien Montagne
9e94ff0d2d Fix (unreported) broken wavefront IO test in debug builds.
`face_verts` parameter of `fixup_invalid_face()` was shadowed by a local
variable, leading to asserting on the wrong data.
2024-04-29 16:54:14 +02:00
Campbell Barton
29dd91815f Cleanup: remove redundant calls to strlen 2024-04-25 12:02:12 +10:00
Aras Pranckevicius
dc9d2d41f5 Fix #120499: OBJ MTL with Ni=0 are displayed as gray
Some files out there have index of refraction 0.0, which is
not quite valid. Ignore these and keep default IOR in the imported
material.
2024-04-12 14:16:46 +03:00
Jesse Yurkovich
88526ab5f4 Collection Export: Don't draw ignored properties for OBJ and USD
When using Collection export skip drawing certain operator properties
which shouldn't apply for this style of export.

These suppressed properties were mentioned a few times while gathering
feedback for the feature and they are ignored internally when using
collection export anyhow.
2024-04-11 07:01:45 +02:00
Jesse Yurkovich
509a7870c3 Collection Exporters: Enable file exporters to be specified on Collections
This implements the ability to have file exporters added and configured on Collections.

Exporting is reachable from several locations:
- Individually on each exporter configuration: The `Export` button in each panel header
- For all exporters on the collection: The `Export All` button in the main panel interface
- For all exporters on all collections in the scene: The `File`->`Export All Collections` button

Visibility of which collections currently have exporters configured is done by ways of an icon added to the Collection row in the Outliner.

Adding multiple exporters for the same file type is permitted. The user is free to setup several exports of the same format but with different file locations or settings etc.

Notes:
Only USD and Wavefront OBJ are enabled for the initial commit. Additional formats, including those implemented in Python will be added as separate commits after this.

Ref #115690
Pull Request: https://projects.blender.org/blender/blender/pulls/116646
2024-04-08 22:10:39 +02:00
Jesse Yurkovich
14e0547da9 Fix: OBJ failing to create a proper .mtl filepath
The MTLWriter was using a BLI_assert to check user-provided data, which
is incorrect and would only work in Debug builds. Release builds would
end up using too small of a buffer and would needlessly fail to append
the `.mtl` extension in some cases.

Instead, we now allow the path manipulation code to just use the full
max size available to it.

Pull Request: https://projects.blender.org/blender/blender/pulls/120275
2024-04-05 04:43:28 +02:00
Campbell Barton
eb04e1a753 Cleanup: quiet set-but-unused warnings 2024-04-04 10:55:18 +11:00
Campbell Barton
b03332a055 Cleanup: use BLI_assert_msg instead of checking string literals 2024-04-03 14:27:54 +11:00
Campbell Barton
0ef033750f Cleanup: pass arguments by const reference 2024-03-28 17:16:33 +11:00
Hans Goudey
c28db1f0a0 Cleanup: Use C++ namespace for object editors module
Move the public functions from the editors/object (`ED_object.hh`)
header to the `blender::ed::object` namespace, and move all of the
implementation files to the namespace too. This provides better code
completion, makes it easier to use other C++ code, removes unnecessary
redundancy and verbosity from local uses of public functions, and more
cleanly separates different modules.

See the diff in `ED_object.hh` for the main renaming changes.

Pull Request: https://projects.blender.org/blender/blender/pulls/119947
2024-03-28 01:30:38 +01:00
Hans Goudey
6f4718242e Fix #119304: Assert copying transform data in OBJ and STL export 2024-03-11 14:36:36 -04:00
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
Hans Goudey
31f6d4db89 Fix: Incorrect assert in OBJ mesh edge creation
Typo in 2a4323c2f5
2024-03-04 10:11:38 -05: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
6c78f79740 Cleanup: pass matrices by reference instead of value 2024-02-28 17:16:18 +11:00
Campbell Barton
a9803765dc Cleanup: remove colon after "return" doxy command 2024-02-28 12:13:17 +11:00
Pratik Borhade
c926b65132 Merge branch 'blender-v4.1-release' 2024-02-27 17:43:50 +05:30
Pratik Borhade
05c4b7f588 Fix #118621: Obj Importer does not handle inline comments correctly
Add simple check in `geom_add_polygon` to skip comments that are on same
line as face corner index.

Pull Request: https://projects.blender.org/blender/blender/pulls/118742
2024-02-27 13:09:05 +01: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
Campbell Barton
eb318b7733 Cleanup: use FILE_MAX instead of PATH_MAX for paths based on blend files
The blend file path is limited to FILE_MAX.
2024-02-13 09:53:45 +11:00
Bastien Montagne
5aaadebbe4 Cleanup: Make BKE_scene.h a full Cpp header. 2024-02-10 19:16:25 +01:00
Hans Goudey
91e54fdd83 Cleanup: Move BLO_readfile.h to C++
I added a new BLO_userdef_default.h header to contain declarations of
two global variables that are still defined in C files. Use of designated
initializers for large structs make those files harder to change.
Arguably this is a better header for them anyway.

Pull Request: https://projects.blender.org/blender/blender/pulls/118015
2024-02-09 13:41:30 +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
Hans Goudey
961783c444 Cleanup: Move BKE_deform.h to C++ 2024-01-29 19:04:13 -05:00
Hans Goudey
3b2a99af3e Fix: Build error in debug build 2024-01-26 13:47:50 -05:00
Hans Goudey
2a5531b253 Cleanup: Use StringRef instead of const char * in OBJ export 2024-01-26 13:18:58 -05:00
Hans Goudey
2a0c8593c9 Cleanup: Use C++ Array in OBJ import 2024-01-26 13:17:30 -05:00
Hans Goudey
0d03ae4a4d Cleanup: Update mesh naming in OBJ IO code 2024-01-26 13:16:01 -05:00
Hans Goudey
899546d4e4 Cleanup: Use utility to fill index range in OBJ mesh export 2024-01-26 12:58:45 -05:00
Hans Goudey
94ca3aea83 OBJ: Use mesh normals domain properly for normals storage
- Only calculate the necessary normals based on smooth/flat/mixed shading
- Use cached face normals instead of computing them
- Use a `VectorSet` for deduplication instead of a `Map`
- Deduplicate vertex normals and store indices in separate loops
- Avoid unnecessary duplication of face normal indices
- Inline simple function for slicing index span

Export time (ms) of 1.8m vertex mesh:
| Normals Domain  | Before | After |
| --------------- | ------ | ----- |
| Face (flat)     | 559    | 469   |
| Vertex (smooth) | 659    | 466   |
| Corner (mixed)  | 656    | 640   |

The change of using normals from different domains and using a
VectorSet for de-duplication change the order of normals in the OBJ
files. Other than that, the results should be unchanged.

Fixes #117510

Pull Request: https://projects.blender.org/blender/blender/pulls/117522
2024-01-26 18:54:58 +01:00
Hans Goudey
ebcdf19537 Cleanup: Use consistent camel case for test class names 2024-01-26 10:25:48 -05:00
Hans Goudey
e2e4c95258 OBJ: Combine global scale parameter into transform matrix
Remove the need for the `calc_vertex_coords` function by combining
the scale into the existing transform needed to export vertex positions
in global space. This simplifies code and may slightly improve performance
(I only observed a few percent difference in the positions export, which is
not a slower part of the export).
2024-01-25 13:54:30 -05:00
Hans Goudey
a08e636bbc Cleanup: Use C++ math types in OBJ export 2024-01-25 13:10:22 -05:00
Hans Goudey
9f0c6e0685 Cleanup: Clarify OBJ IO use of Span, Vector, and Array
- Use Span where ownership is unnecessary
- Use Array when dynamic growth is unnecessary
- Use Vector in all other cases

Also remove unnecessary namespace specification.
2024-01-25 13:10:22 -05:00
Hans Goudey
02582213de Cleanup: Move BKE_layer.hh to C++ 2024-01-24 10:55:16 -05:00
Pratik Borhade
d5766dfdce Fix: Obj crash exporting curve without modifier property
`BKE_object_get_pre_modified_mesh` returns curve object data, later
accessing non-existing edge/face data triggered the crash.
`apply_modifiers` seems valid for mesh data only.

Pull Request: https://projects.blender.org/blender/blender/pulls/117471
2024-01-24 12:37:08 +01:00
Campbell Barton
9a7b767226 Cleanup: reserve "r_" prefix for return arguments 2024-01-23 13:30:47 +11:00
Bastien Montagne
d8d44a62f7 Cleanup: Move BKE_appdir.h to full Cpp header BKE_appdir.hh. 2024-01-21 19:42:13 +01:00