Commit Graph

440 Commits

Author SHA1 Message Date
Campbell Barton
3af6f7a989 Cleanup: place ID comments before the literal values
This is already done in most places and matches struct-member
comment ordering.
2025-05-21 12:40:10 +10:00
Aras Pranckevicius
389d770bf4 Fix #122256, #123862: OBJ import Clamp Size option issues
- #122256: Clamp Size option did not work at all, due to mesh
  bounding box still not being calculated (and was firing an assert
  in Debug build).
- #123862: Clamp Size option was rounding the resulting scale to
  powers of ten, which is not what anyone would expect.

This fixes both issues, and adds test coverage.

Co-authored-by: dshot92 <dshot92@gmail.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/139145
2025-05-20 11:57:42 +02:00
Lukas Stockner
111b0764c1 Cleanup: Remove unused parameter in OBJ importer 2025-05-18 15:15:39 +02:00
Campbell Barton
b3dfde88f3 Cleanup: spelling in comments (check_spelling_* target)
Also uppercase acronyms: API, UTF & ASCII.
2025-05-17 10:17:37 +10:00
Mattias Fredriksson
bc0913240f Fix: Improve Obj importers parsing and detection of NURBS knot mode
Reworks the implementation for how knots are interpreted when importing
NURBS in .obj format. It refactors each test into a separate function
and simplifies functions using a 'multiplicity sequence' which counts
repeated occurances of knot values (or their 'multiplicity'). Making
comparisons simpler, clearer, and with improved correctness.

With regard to regression tests behavior is almost the same, noticable
difference is consideration of cyclic. Allowing curves with multiplicity
at the endpoints to be cyclic (so Bezier curves can be cyclic given
one repeated point). Untested behavior may also have been 'refined'
(changed), but additional tests would be needed to identify those cases.

Pull Request: https://projects.blender.org/blender/blender/pulls/138778
2025-05-16 15:44:38 +02:00
Mattias Fredriksson
d0cf7dd8b5 Fix: Improve OBJ NURBS IO, support exporting custom knots
Corrects behavior with NURBS knot values in .obj exporter. Knot values
denoting the curve parameter range and values at the boundary region
in the span ends had hardcoded knot values. It also implemented its own
knot calculation, which is not ideal...

Importer is updated to not try to second guess the knot values.
Not entirely sure what it was trying to do but it used wrong indices
and missed writing the end of the knot vector. Combined the changes
should make it possible to import and export a simple NURBS curve with
custom knots and leaving it intact.

This replaces some of the erronous behavior using functions from [new]
Curves implementation. Mixing new and legacy curve implementation is not
ideal but exporter is exporting POLY curves as NURBS while legacy method
does not support computing the knot vector. To avoid introducing
additional branch cases nor update legacy functions, using the new
functions seems to be the correct choice. These functions should be
functionally equivalent but is not identical (e.g. legacy curve returns
knots in [0, 1] range). It should also make it easier to transition to
exporting new Curves.

Pull Request: https://projects.blender.org/blender/blender/pulls/138732
2025-05-12 16:51:21 +02:00
Mattias Fredriksson
f9d3235291 Cleanup: Detect knot mode cyclic
Moving the cyclic mode check into a separate function simplifies the
code. Avoiding an additional local variable to track the result, and
better encapsulates the behavior.

Pull Request: https://projects.blender.org/blender/blender/pulls/138375
2025-05-09 03:44:28 +02:00
Mattias Fredriksson
87d04eadd4 Fix: Prevent NURBS .obj importer from setting invalid degree/order
Default behavior in most edit mode operators is to adjust the order
if there is not enough points/knots to support it. If the degree is
incorrectly encoded in the file, import should update it to avoid
generating an invalid  NURBS curve.

Pull Request: https://projects.blender.org/blender/blender/pulls/138374
2025-05-07 17:41:39 +02:00
Jacques Lucke
e09ccc9b35 Core: add templated version of BKE_id_new_nomain to reduce explicit casting
This adds a version of `BKE_id_new_nomain` that takes the ID type parameter as
template argument. This allows the function the return the newly created ID with
the correct type, removing the need to use `static_cast` on the call-site.

To make this work, I added a static `id_type` member to every ID struct. This
can also be used to create a similar API for other id management functions in
future patches.

```cpp
// Old
Mesh *mesh = static_cast<Mesh *>(BKE_id_new_nomain(ID_ME, "Mesh"));

// New
Mesh *mesh = BKE_id_new_nomain<Mesh>("Mesh");
```

Pull Request: https://projects.blender.org/blender/blender/pulls/138383
2025-05-05 18:41:03 +02:00
Jacques Lucke
e8d1491e62 Refactor: Depsgraph: simplify query API further
* Remove `DEG_get_evaluated_object` in favor of `DEG_get_evaluated`.
* Remove `DEG_is_original_object` in favor of `DEG_is_original`.
* Remove `DEG_is_evaluated_object` in favor of `DEG_is_evaluated`.

Pull Request: https://projects.blender.org/blender/blender/pulls/138317
2025-05-02 15:08:29 +02:00
Campbell Barton
64f5dee6d7 Cleanup: spelling in comments (make check_spelling_*) 2025-04-17 12:06:12 +10:00
Laurynas Duburas
8f6af72a3f Curves: Custom NURBS knots
Adds new NURBS knot mode NURBS_KNOT_MODE_FREE. Knots are stored in
`CurvesGeometry::custom_knots`. Knot offsets binding them to their
curves are calculated at runtime and held in a cache. This commit adds
custom knots support to OBJ import. It is the only way create such
curves for now. Legacy curve's tools don't support this knot mode,
thus on any modification knots get regenerated and whole shape changes.
If to convert imported legacy curve to new curves, point deletion,
duplicate and extrude preserve custom knots.

Rel #99891

Pull Request: https://projects.blender.org/blender/blender/pulls/130132
2025-04-01 20:22:47 +02:00
Brecht Van Lommel
9526fe9993 Refactor: Add BKE_mesh_new_from_object argument to ignore subdivision
Pull Request: https://projects.blender.org/blender/blender/pulls/135895
2025-03-19 14:08:37 +01:00
Bastien Montagne
b87b58b07e OBJ Export: Update 'bitflag smoothgroup' to also consider boundary vertices.
Previous code would consider two different face groups sharing no common
edges as fully isolated from each other, and could assign them the same
bitflag facegroup value.

Following FBX recent option to export these bitflags smoothgroups (!135646),
also consider that two different face groups are connected if they only share
common vertices, and assign them different bitflags values.

NOTE: This seems to be the expected behavior in major DCCs actually
using smoothgroups, only considering boundary edges create groups that
generate broken shading when imported by these tools.

NOTE: The 'unique integer identifers' option is kept for OBJ exporter,
as such OBJ files are also found on internet, depending on which app
generated them.

Pull Request: https://projects.blender.org/blender/blender/pulls/135998
2025-03-18 10:04:38 +01:00
Bastien Montagne
1e976ec37b Cleanup: io: Replace 'void' MEM_[cm]allocN with templated, type-safe MEM_[cm]allocN<T>.
The main issue of 'type-less' standard C allocations is that there is no check on
allocated type possible.

This is a serious source of annoyance (and crashes) when making some
low-level structs non-trivial, as tracking down all usages of these
structs in higher-level other structs and their allocation is... really
painful.

MEM_[cm]allocN<T> templates on the other hand do check that the
given type is trivial, at build time (static assert), which makes such issue...
trivial to catch.

NOTE: New code should strive to use MEM_new (i.e. allocation and
construction) as much as possible, even for trivial PoD types.

Pull Request: https://projects.blender.org/blender/blender/pulls/135976
2025-03-14 14:52:16 +01:00
Bastien Montagne
00de07f752 I/O: Smoothgroups: Add option to also consider 'sharp vertices'.
According to reports and testing in blender/blender-addons#104434, DCCs
tend to behave badly when rebuilding normals from 'bitflags'
smoothgroups, if different smoothgroups using the same bitflag value share
(are connected by) some common vertices, even if there are no common
edges between them.

This commit adds a new option to the RNA API generating smooth groups,
to also consider smooth groups only sharing vertices as neighbors.

It also makes related required change to implementation, and some
refactor of the API, splitting public functions between 'normal' and
'bitflags' versions.

This should make changes proposed in blender/blender-addons#105516
much simpler, and allow for a matching behavior in smoothgroups
generated by the OBJ exporter as well.

Pull Request: https://projects.blender.org/blender/blender/pulls/135248
2025-03-07 11:24:37 +01:00
Aras Pranckevicius
b02f2e8c59 Merge branch 'blender-v4.4-release' 2025-02-25 14:16:13 +02:00
Nikita Lisitsa
e1bcd08f61 Fix #135073: OBJ import of emissive colors
The emissions strength was only set when using an emissive texture.
Additionally, for colors brighter than 1.0, normalize the color
into 0..1 range and set the strength accordingly.

Pull-Request: https://projects.blender.org/blender/blender/pulls/135094
2025-02-25 14:15:18 +02:00
Jacques Lucke
3eaccd6c2c Fix: Geometry Nodes: use object names in Import OBJ node 2025-02-24 18:57:41 +01:00
Jörg Müller
9301a0e159 Compile fix: include limits.h for INT_MIN/MAX.
Pull Request: https://projects.blender.org/blender/blender/pulls/134697
2025-02-19 22:51:07 +01:00
илья _
119fc054f8 Cleanup: BKE: Nodes: Pass-by-reference
Restriction of the nodes api to clearly define never-null function arguments.
Side effects: some assertions and null-check (with early return) were removed.
On the caller side is ensured to never derefer null to pass argument (mainly in RNA).
In addition, one pointer argument now actually a return type.

By-reference return types instead of pointers going to be separate kind of
change since also imply of cleaning up variables created from reference.

Also good future improvement would be to mark a copy-constructor as
explicit for DNA node types.

Pull Request: https://projects.blender.org/blender/blender/pulls/134627
2025-02-19 13:44:11 +01:00
Hans Goudey
4727dfd627 Cleanup: Remove unnecessary const qualifiers in function declarations 2025-02-14 14:32:57 -05:00
Brecht Van Lommel
c7a33a62a2 Cleanup: Directly include DNA_userdef_types.h and BLI_listbase.h
Instead of relying on them being included indirectly.

Pull Request: https://projects.blender.org/blender/blender/pulls/134406
2025-02-12 23:01:08 +01:00
Devashish Lal
1a62fdc82a Geometry Nodes: CSV import node
This commit implements a node to import CSV files as a point cloud.
The interface is minimal, with just a file path input. The type of each
column is chosen by whether the first value is an integer or a float
(those are currently the only supported types).

The goal of the node is to make it easier to get arbitrary data into
geometry nodes for visualization purposes, for example.

https://devtalk.blender.org/t/gsoc-2024-geometry-nodes-file-import-nodes/34482

Pull Request: https://projects.blender.org/blender/blender/pulls/126308
2025-02-10 16:56:52 +01:00
Brecht Van Lommel
941f186e88 Cleanup: Various clang-tidy warnings in io
Pull Request: https://projects.blender.org/blender/blender/pulls/133734
2025-01-31 17:03:18 +01:00
Aras Pranckevicius
f5c2aecd8b Tests: emit more information in import tests templates
- Bone matrices,
- Material viewport settings (colors, backfaces etc.)
- Improved handling of relative paths of material images

Pull Request: https://projects.blender.org/blender/blender/pulls/133658
2025-01-27 18:19:04 +01:00
Aras Pranckevicius
1ad083dabf Tests: Add FBX import tests, switch OBJ/PLY/STL import tests to the same machinery
"Expected textual data output" comparison based tests for FBX,
OBJ, PLY, STL import.

- There's a tests/python/modules/io_report.py that can produce
  a "fairly short text description of the scene" (meshes, objects,
  curves, cameras, lights, materials, armatures, actions, images).
  About each object, it lists some basic information (e.g. number
  of vertices in the mesh), plus a small slice of "data" (e.g.
  first few values of each mesh attribute).
    - Custom import parameters, if needed, can be provided by
      having a sidecar .json file next to imported file (same
      basename, json extension), that would have a single json
      object with custom arguments.
- Add FBX test coverage, with 46 fairly small files (total size 3.8MB)
  covering various possible cases (meshes, animations, materials,
  hierarchies, cameras, etc. etc.).
- Switch OBJ/PLY/STL import tests to the above machinery, remove C++
  testing code.

Pull Request: https://projects.blender.org/blender/blender/pulls/132624
2025-01-15 05:52:15 +01:00
Hans Goudey
f2c9fccee0 Cleanup: Move legacy node integer types defines to separate header
Moving these defines to a separate header makes their "legacy" status
more obvious. This commit just adds the include wherever necessary.

Followup to 971c96a92c.

Pull Request: https://projects.blender.org/blender/blender/pulls/132875
2025-01-09 20:03:08 +01:00
Falk David
d413b0064f Cleanup: Move BKE_material.h to C++
The `BKE_material.h` is only renamed to `.hh` to preserve
the history of the file. Changes to the file are done in
the following commit.
2025-01-09 18:11:46 +01:00
Jacques Lucke
038159e96b Refactor: Nodes: improve node tree update API
Main goals of this refactor:
* Make it more obvious which update function should be used.
* Make it more obvious which parameters are required by using references instead
  of pointers.
* Support passing in multiple modified trees instead of just a single one.

No functional changes are expected.

Pull Request: https://projects.blender.org/blender/blender/pulls/132862
2025-01-09 17:00:05 +01:00
Jacques Lucke
971c96a92c Nodes: rename integer type of nodes to type_legacy
The new description for `bNode.type_legacy`:
```
  /**
   * Legacy integer type for nodes. It does not uniquely identify a node type, only the `idname`
   * does that. For example, all custom nodes use #NODE_CUSTOM but do have different idnames.
   * This is mainly kept for compatibility reasons.
   *
   * Currently, this type is also used in many parts of Blender, but that should slowly be phased
   * out by either relying on idnames, accessor methods like `node.is_reroute()`.
   *
   * A main benefit of this integer type over using idnames currently is that integer comparison is
   * much cheaper than string comparison, especially if many idnames have the same prefix (e.g.
   * "GeometryNode"). Eventually, we could introduce cheap-to-compare runtime identifier for node
   * types. That could mean e.g. using `ustring` for idnames (where string comparison is just
   * pointer comparison), or using a run-time generated integer that is automatically assigned when
   * node types are registered.
   */
```

Pull Request: https://projects.blender.org/blender/blender/pulls/132858
2025-01-09 15:28:57 +01:00
Brecht Van Lommel
920e709069 Refactor: Make header files more clangd and clang-tidy friendly
When using clangd or running clang-tidy on headers there are
currently many errors. These are noisy in IDEs, make auto fixes
impossible, and break features like code completion, refactoring
and navigation.

This makes source/blender headers work by themselves, which is
generally the goal anyway. But #includes and forward declarations
were often incomplete.

* Add #includes and forward declarations
* Add IWYU pragma: export in a few places
* Remove some unused #includes (but there are many more)
* Tweak ShaderCreateInfo macros to work better with clangd

Some types of headers still have errors, these could be fixed or
worked around with more investigation. Mostly preprocessor
template headers like NOD_static_types.h.

Note that that disabling WITH_UNITY_BUILD is required for clangd to
work properly, otherwise compile_commands.json does not contain
the information for the relevant source files.

For more details see the developer docs:
https://developer.blender.org/docs/handbook/tooling/clangd/

Pull Request: https://projects.blender.org/blender/blender/pulls/132608
2025-01-07 12:39:13 +01:00
Hans Goudey
64087c70d5 Cleanup: Move some mesh normals functions to C++ API
Use C++ namespace, reference instead of pointer, and span instead
of raw pointers, mainly to make these functions easier to use in a
few more places.

Pull Request: https://projects.blender.org/blender/blender/pulls/132561
2025-01-02 20:32:47 +01:00
Ray Molenkamp
5783950ac5 Revert: 0dc484f9cc bf_rna modernisation
This caused build errors on the docs builder, I can't seem to reproduce
locally, so revert for now and have another look at some point in the
future.

Sadly as these changes usually go, this took 5c515e26bb and
2f0fc7fc9f with it as well.

Pull Request: https://projects.blender.org/blender/blender/pulls/132559
2025-01-02 19:56:24 +01:00
Ray Molenkamp
0dc484f9cc Cleanup: CMake: Modernize bf_rna dependencies
Pretty straightforward

- Remove any bf_rna 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/132413
2024-12-31 18:23:25 +01:00
Ray Molenkamp
167c15e0c0 Cleanup: CMake: Modernize bf_nodes dependencies
Pretty straightforward

- Remove any bf_nodes 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/132356
2024-12-26 19:52:49 +01:00
Aras Pranckevicius
55083363b8 Cleanup: OBJ export struct defaults
This makes OBJExportParamsDefault in tests code not needed anumore
2024-12-26 18:16:57 +02:00
Ray Molenkamp
54604efdfd Cleanup: CMake: Modernize bf_windowmanager dependencies
Pretty straightforward

- Remove any bf_windowmanager 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/132310
2024-12-24 22:40:38 +01:00
Ray Molenkamp
a7c39896c6 Cleanup: CMake: Modernize bf_blenkernel dependencies
Pretty straightforward

- Remove any bf_blenkernel 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/132282
2024-12-23 20:08:37 +01:00
Ray Molenkamp
2992c63bc3 Cleanup: CMake: Modernize bf_bmesh dependencies
Pretty straightforward

- Remove any bf_bmesh 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/132203
2024-12-23 17:47:25 +01:00
Hans Goudey
4bf34d9591 Nodes: Simplify location storage, remove hidden offfsets
Currently each node's position is stored in the coordinate space of
its parent. To find the location of a node on the canvas, we have to
apply the translation of each of its parents. Also, nodes have hidden
"offset" values used while transforming frame nodes. Together,
those made the system much more complicated than necessary,
and they made the Python API ineffective.

This commit removes usage of the offset values and moves nodes
to be stored in the "global" space of the node canvas. It also resolves
some weird behavior when resizing frame nodes, and fixes a few bugs.

The change is forward compatible, so we still write files with nodes in
the old parent-space format. In 5.0 the conversion when writing can be
removed. The existing Python API also stays the same. A new
"location_absolute" property gives node locations in global space,
and changing the old property also moves the child nodes of frames.

Resolves #92458, #72904.

Pull Request: https://projects.blender.org/blender/blender/pulls/131335
2024-12-11 21:06:41 +01:00
Laurynas Duburas
b13e085109 OBJ Import: Improved NURBS curve support
Adds support of NURBS weights or "rat bspline" in OBJ terms.
Tries to guess Blender knot mode better:

- Detects and closes loops. This decision is based on geometry only. No metadata is provided in OBJ for this, so importer has checkbox to disable this feature.
- Bezier knot mode allows to import circles and circular arcs.

Pull Request: https://projects.blender.org/blender/blender/pulls/131169
2024-12-03 13:16:16 +01:00
Aras Pranckevicius
3d7359a38f Fix #130969: OBJ import shading artifacts when file contains zero-area faces
When OBJ file contains vertex normals, this can in some cases confuse
the custom loop normals code inside Blender. Since it does not simply
just use custom normals, but rather projects them into "lnor space".
But that "lnor space" calculation can go haywire sometimes, when
degenerate faces are present in the input.

Mark zero-area faces as "sharp" before doing custom normals. This will
make them not try to share the "smooth fan" lnor space with other faces,
and things will look correct.

Previously, OBJ importer was (wrongly) always setting all faces
as "sharp", which avoided this problem, but caused other issues.

Pull Request: https://projects.blender.org/blender/blender/pulls/131041
2024-11-27 22:03:15 +01:00
Jesse Yurkovich
c9c2fbc52d Cleanup: IO: Use CLOG and fmtlib for tracing OBJ/PLY/STL messages
OBJ, PLY, and STL used a mix of fprintf, std::cout, and std::cerr to
trace warnings, errors, and general messages to the console.

Now, we instead use CLOG which provides real facilities for warnings and
errors and generally removes the need to pull in and use the heavy
`<iostream>` machinery.

For traces that should always be printed, `fmt::print` is used since
CLOG currently doesn't provide that particular level of trace.

Tests were only minimally changed to drop usage of streams while keeping
their prior usage of older stdio APIs. We can change to using fmtlib
there too if desired.

Pull Request: https://projects.blender.org/blender/blender/pulls/130107
2024-11-12 20:48:57 +01:00
Bastien Montagne
b325142d17 Merge branch 'blender-v4.3-release' 2024-11-12 16:55:40 +01:00
Bastien Montagne
0b3a7cbe69 Cleanup: Move BKE_image.h and related headers to C++.
NOTE: This also required some changes to Cycles code itself, who is now
directly including `BKE_image.hh` instead of declaring a few prototypes
of these functions in its `blender/utils.h` header (due to C++ functions
names mangling, this was not working anymore).

Pull Request: https://projects.blender.org/blender/blender/pulls/130174
2024-11-12 16:53:54 +01:00
Jesse Yurkovich
79d468fe6b Cleanup: Use compile-time format string type for OBJ and PLY writing
The `fmtlib` text formatting library, when compiled in C++20 onwards,
requires that the incoming format string is a compile-time constant so
it's able to perform type checks against it[1]. The change here ensures
it can do so.

While we're not set to go to C++20 any time soon, this is a backwards
compatible change that can be done today and allows us to focus on the
harder fmt-related issues later.

No change in performance or functionality was observed.

[1] https://godbolt.org/z/qG5dsf7YG

Pull Request: https://projects.blender.org/blender/blender/pulls/129272
2024-10-21 21:20:43 +02:00
Campbell Barton
381898b6dc Refactor: move BLI_path_util header to C++, rename to BLI_path_utils
Move to a C++ header to allow C++ features to be used there,
use the "utils" suffix as it's preferred for new files.

Ref !128147
2024-09-26 21:13:39 +10:00
Aras Pranckevicius
5a1cf200aa Fix #127542: OBJ material groups are not written unless .mtl file is also written
These two settings are not coupled together, one should be able to
export face material groups without exporting the .mtl file.
2024-09-23 10:16:25 +03:00
notrudyyy
1939eb03a7 Refactor: Mesh: Normalize input normals in set custom normals
To reduce code duplication in importers, modifies the C++
set_custom_normals API functions to normalize the input normals.

Reverts !124336, !124267, and !124261 as the normalization now
occurs in the API call.

Resolves #124358.

Pull Request: https://projects.blender.org/blender/blender/pulls/127814
2024-09-19 20:12:40 +02:00