Commit Graph

72 Commits

Author SHA1 Message Date
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
Damien Picard 7231ac0a52 I18n: extract and disambiguate a few messages
Extract:
- "Attribute", when creating a new attribute with
  `GEOMETRY_OT_attribute_add()`: make the default name in the operator
  a null string, and set it to "Attribute" translated inside an invoke
  method instead.
- Also for new attributes, from `BKE_id_attribute_calc_unique_name()`,
  for instance to create a default vertex color layer when going into
  Vertex Paint mode: use `DATA_()` instead of `IFACE_()`, since it
  represents user data.

Disambiguate:
- "Weight" can be the thickness of font glyphs.
- "Mark as Asset" and "Clear Asset" are operator names already
  extracted using the Operator context. They were recently added to a
  manual translation in the UI, but the existing one can be reused.
- "Second" as a time unit in the context of frame snapping.

Some messages reported by Satoshi Yamasaki in #43295.

Pull Request: https://projects.blender.org/blender/blender/pulls/114159
2023-11-07 18:08:58 +01:00
Campbell Barton 5d3ce7c679 Merge branch 'blender-v4.0-release' 2023-10-25 15:43:18 +11:00
Hans Goudey 692292536f Fix #113665: Sculpt mode does not unshare color attribute data
When retrieving a color attribute to paint it, the layer data needs to
be unshared so that it doesn't modify data from separate meshes.
In the past I think we've unknowingly avoided this problem by porting
code to the new attribute API. I've been refactoring `PBVH` and
`SculptSession` to make that possible (removing the long-lived
layer pointers in the two structs). But that wouldn't fit as a bug fix.
In the meantime, make sure the color attribute data is un-shared
and separate "for read" and "for write" versions of the function.

Pull Request: https://projects.blender.org/blender/blender/pulls/114119
2023-10-24 20:19:14 +02:00
Sergey Sharybin 85c557ffa2 Cleanup: Rename BLI_string_utils.h to BLI_string_utils.hh
All users of it are now C++, which opens doors to add C++ to the
public API.
2023-10-20 10:27:26 +02:00
Sergey Sharybin 687e58bb77 Cleanup: Simplify public API of unique name functions
Their return value was only used in one place.

Change it to comparison with a stored name, and make the functions
to return void instead.

Removing the return boolean makes it possible to change underlying
functions to work with std::string and return unique name by value.

Pull Request: https://projects.blender.org/blender/blender/pulls/113934
2023-10-19 15:07:57 +02:00
Falk David f43426f0de GPv3: Rename layer domain to just "Layer"
We had a short discussion on this change. "Grease Pencil Layer" is
just a bit too long, especially in the UI. Even though "Layer" might be
ambiguous, it shouldn't be in the context of geometry nodes. There are
currently no other "Layers" and if there were, using the same domain
name could be fine (just like we reuse the point domain for e.g. vertices
in meshes and control points in curves).

This also renames the internal enum to `ATTR_DOMAIN_LAYER`

Pull Request: https://projects.blender.org/blender/blender/pulls/113589
2023-10-12 13:54:32 +02:00
Falk David 3931a54e08 GPv3: Initial Geometry Nodes support
This implements the core changes for this design: https://devtalk.blender.org/t/grease-pencil-integration-into-geometry-nodes/31220

The changes include:
* Add `CustomData` for layer attributes
* Add attribute support for the `GreasePencilComponent` to read/write layer attributes. Also introduces a `Layer` domain.
* Implement a `GreasePencilLayerFieldContext` and make `GeometryFieldContext` work with grease pencil layers.
* Implement `Set Position` node for `Grease Pencil`.

Note: These changes are only accessible/visible with the `Grease Pencil 3.0` experimental flag enabled.
Co-authored-by: Jacques Lucke <jacques@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/112535
2023-10-10 16:49:30 +02:00
Jacques Lucke 5c5a041edd Fix #112022: allow vertex groups and attributes with same names again
This was discussed in #112022 and on devtalk:
https://devtalk.blender.org/t/vertex-groups-generic-attributes-and-name-clashing/31073

While vertex groups with the same name as attributes should be avoided, since
it can cause ambiguities when using attributes, it's something we can handle
gracefully for now. Enforcing unique names for vertex groups resulted in breaking
other functionality under some circumstances.

This effectively reverts 12ef20990b, except for
the bug fix in `BKE_id_attribute_new`.

#112891 adds a warning to avoid make users aware of duplicate names so that they
can be avoided in practice.

Pull Request: https://projects.blender.org/blender/blender/pulls/112889
2023-09-26 15:36:12 +02:00
Campbell Barton e955c94ed3 License Headers: Set copyright to "Blender Authors", add AUTHORS
Listing the "Blender Foundation" as copyright holder implied the Blender
Foundation holds copyright to files which may include work from many
developers.

While keeping copyright on headers makes sense for isolated libraries,
Blender's own code may be refactored or moved between files in a way
that makes the per file copyright holders less meaningful.

Copyright references to the "Blender Foundation" have been replaced with
"Blender Authors", with the exception of `./extern/` since these this
contains libraries which are more isolated, any changed to license
headers there can be handled on a case-by-case basis.

Some directories in `./intern/` have also been excluded:

- `./intern/cycles/` it's own `AUTHORS` file is planned.
- `./intern/opensubdiv/`.

An "AUTHORS" file has been added, using the chromium projects authors
file as a template.

Design task: #110784

Ref !110783.
2023-08-16 00:20:26 +10:00
Pratik Borhade d87db8d569 Fix #111024: Crash when adding attribute to curve object
After 12ef20990b, attributes and vertex group names were checked
simultaneously to fix the name collision. But this results in crash when
new attribute is added to curve object (it searches for vertex group
list). To avoid the crash, check for supported id types in new function
`BKE_id_supports_vertex_groups`.

Pull Request: https://projects.blender.org/blender/blender/pulls/111036
2023-08-12 07:37:37 +02:00
Jacques Lucke cc4d5c432c RNA: move headers to C++
Also see #103343.

Pull Request: https://projects.blender.org/blender/blender/pulls/111022
2023-08-10 22:40:27 +02:00
Philipp Oeser 12ef20990b Fix #103410: name collisions between vertex groups and attributes
These name collisions should be avoided with attributes, all sorts of
issues can arise from those. We already warned in the attributes
(but not the vertex groups) list if those were found.

Previously, creating a vertex group with the same name as an already
existing attribute would allow this (and give said warning), and creating
an attribute with the same name as an already existing vertex group
would silently fail (as in: not return a layer) -- and then due to an oversight
in 101d04f41f (which assumed a valid layer would always be returned
by `BKE_id_attribute_new`) would even crash.

Now name collisions between vertex groups and attributes are avoided,
unique names will be found across attributes and vertex groups if either
`BKE_id_attribute_calc_unique_name` or `BKE_object_defgroup_unique_name`
is called.

This is done by unifying the checks and callbacks for both into a single.

Pull Request: https://projects.blender.org/blender/blender/pulls/109910
2023-08-08 10:11:10 +02:00
Hans Goudey 95edff7495 Cleanup: Rename mesh custom data fields
Implements the rest of #101689, after 5e9ea9243b.

- `vdata` -> `vert_data`
- `edata` -> `edge_data`
- `pdata` -> `face_data`
- `ldata` -> `loop_data`

A deeper rename of `loop` to `corner` will be proposed as a next
step, and renaming `totvert` and `totedge` can be done separately.

Pull Request: https://projects.blender.org/blender/blender/pulls/110432
2023-07-25 21:15:52 +02:00
Hans Goudey 5e9ea9243b Mesh: Rename "polys" to "faces"
Implements part of #101689.

The "poly" name was chosen to distinguish the `MLoop` + `MPoly`
combination from the `MFace` struct it replaced. Those two structures
persisted together for a long time, but nowadays `MPoly` is gone, and
`MFace` is only used in some legacy code like the particle system.

To avoid unnecessarily using a different term, increase consistency
with the UI and with BMesh, and generally make code a bit easier to
read, this commit replaces the `poly` term with `poly`. Most variables
that use the term are renamed too. `Mesh.totface` and `Mesh.fdata` now
have a `_legacy` suffix to reduce confusion. In a next step, `pdata`
can be renamed to `face_data` as well.

Pull Request: https://projects.blender.org/blender/blender/pulls/109819
2023-07-24 22:06:55 +02:00
Hans Goudey c728fa0663 Cleanup: Simplify retrieving color attribute, improve const correctness
Make it harder to retrieve a mutable attribute from const a const mesh,
and use the attribute search function to check multiple domains and
colors at once.
2023-07-11 16:50:34 -04:00
Campbell Barton a2865b701d Cleanup: rename max-length to maxncpy as this includes the null byte 2023-06-10 17:21:24 +10:00
Sergey Sharybin c1bc70b711 Cleanup: Add a copyright notice to files and use SPDX format
A lot of files were missing copyright field in the header and
the Blender Foundation contributed to them in a sense of bug
fixing and general maintenance.

This change makes it explicit that those files are at least
partially copyrighted by the Blender Foundation.

Note that this does not make it so the Blender Foundation is
the only holder of the copyright in those files, and developers
who do not have a signed contract with the foundation still
hold the copyright as well.

Another aspect of this change is using SPDX format for the
header. We already used it for the license specification,
and now we state it for the copyright as well, following the
FAQ:

    https://reuse.software/faq/
2023-05-31 16:19:06 +02:00
Campbell Barton 823685db76 Cleanup: consistent doxygen comment blocks
Also remove doxygen block for comments in a functions body.
2023-05-27 15:10:58 +10:00
Campbell Barton 169dd2a2b4 Use UTF8 copy function to ensure valid UTF8 output 2023-05-13 17:38:48 +10:00
Campbell Barton e89939ca26 Cleanup: reserve the term 'len' for string length 2023-05-13 17:34:23 +10:00
Campbell Barton 3958ae7241 Cleanup: use STRNCPY, SNPRINTF macros 2023-05-09 14:08:19 +10:00
Campbell Barton f30434ac99 BLI_string_utils: BLI_uniquename no longer accepts NULL defname
A NULL defname would early exit (doing nothing) this isn't good behavior
as this function should always make the name unique and a NULL defname
is likely an error in the code which would allow duplicate names.
This is also inconsistent with BLI_uniquename_cb which always
wrote the defname into the name if it was empty.

Mark this argument as never-NULL.
2023-05-03 11:25:30 +10:00
Campbell Barton 6859bb6e67 Cleanup: format (with BraceWrapping::AfterControlStatement "MultiLine") 2023-05-02 09:37:49 +10:00
Sergey Sharybin a12a8a71bb Remove "All Rights Reserved" from Blender Foundation copyright code
The goal is to solve confusion of the "All rights reserved" for licensing
code under an open-source license.

The phrase "All rights reserved" comes from a historical convention that
required this phrase for the copyright protection to apply. This convention
is no longer relevant.

However, even though the phrase has no meaning in establishing the copyright
it has not lost meaning in terms of licensing.

This change makes it so code under the Blender Foundation copyright does
not use "all rights reserved". This is also how the GPL license itself
states how to apply it to the source code:

    <one line to give the program's name and a brief idea of what it does.>
    Copyright (C) <year>  <name of author>

    This program is free software ...

This change does not change copyright notice in cases when the copyright
is dual (BF and an author), or just an author of the code. It also does
mot change copyright which is inherited from NaN Holding BV as it needs
some further investigation about what is the proper way to handle it.
2023-03-30 10:51:59 +02:00
Jacques Lucke 84c93f3a06 Cleanup: use eCustomDataType instead of int
This makes the APIs more correct and simplifies debugging, because
some debuggers can now show the enum name instead of the integer.

Pull Request: https://projects.blender.org/blender/blender/pulls/106268
2023-03-29 17:10:49 +02:00
Hans Goudey f149d7625d Cleanup: Use more specific variable names for color attributes
The "active_index" and "default_index" could easily apply to different
attribute subsets, better to make the naming specific here.
2023-03-19 10:31:14 -04:00
Hans Goudey 35bb942ae3 Cleanup: Use better check for UV map attribute
Also check the domain in addition to the type, to avoid processing
any associated layers unnecessarily. And remove an unnecessary
comment too.
2023-03-19 10:10:04 -04:00
Hans Goudey 37889015f3 Cleanup: Use C++ attribute API
When deleting UV UI attributes it isn't necessary to use the higher
level C attribute API, since we already know we aren't working with
the edit mesh here.
2023-03-19 10:07:54 -04:00
Hans Goudey fbdeb0434c Merge branch 'blender-v3.5-release' 2023-03-19 10:03:11 -04:00
Hans Goudey f23e3c7f04 Fix: Various issues with attribute removal
There were logic errors and use-after-free errors with the attribute
removal function. Because the custom data layers are reallocated,
we can't reuse the name pointer after removing an attribute. And
we can't return early on the first domain to fail for the edit mode
implementation, because another domain might have the attribute.

Also reorganize some of the code to make the logic clearer: only remove
sub-attribuutes and change attribute names after actually removing the
attribute,and  assert if the attribute isn't removed after it is found.
2023-03-19 10:02:29 -04:00
Hans Goudey 45c4a0b1ef Merge branch 'blender-v3.5-release' 2023-03-18 19:57:58 -04:00
Jorijn de Graaf ea019cf01e Fix #105152: Removing color attribute doesn't update active
It now gets the index before deleting the attribute,
then sets the attribute at that index as active.

Pull Request: https://projects.blender.org/blender/blender/pulls/105871
2023-03-18 19:57:22 -04:00
Chris Blackbourn 254e3e133f Cleanup: format 2023-03-15 18:24:34 +13:00
Hans Goudey ee18b625ca Fix: Edit mesh face corner color operators always use first layer
The operator went through quite a bit of trouble to pass a color
attribute index to the operator, but then it always used the offset
from the first layer of the active color attribute's type.

Also remove the "copy domains temp" API function, which
generalized this more than necessary, and exposed the internals
of the custom data system a bit more than we would like.
2023-03-14 12:03:46 -04:00
Hans Goudey 90076b543b Cleanup: Remove two redundant color attribute functions
The two removed BKE functions were at a mid-level of abstraction
that doesn't make total sense in this API. Removing them is also
helpful in the general effort to have the attribute system rely less
on `CustomData` internally.
2023-03-14 11:33:32 -04:00
Hans Goudey 1dc57a89e9 Mesh: Move functions to C++ header
Refactoring mesh code, it has become clear that local cleanups and
simplifications are limited by the need to keep a C public API for
mesh functions. This change makes code more obvious and makes further
refactoring much easier.

- Add a new `BKE_mesh.hh` header for a C++ only mesh API
- Introduce a new `blender::bke::mesh` namespace, documented here:
  https://wiki.blender.org/wiki/Source/Objects/Mesh#Namespaces
- Move some functions to the new namespace, cleaning up their arguments
- Move code to `Array` and `float3` where necessary to use the new API
- Define existing inline mesh data access functions to the new header
- Keep some C API functions where necessary because of RNA
- Move all C++ files to use the new header, which includes the old one

In the future it may make sense to split up `BKE_mesh.hh` more, but for
now keeping the same name as the existing header keeps things simple.

Pull Request: https://projects.blender.org/blender/blender/pulls/105416
2023-03-12 22:29:15 +01:00
Jacques Lucke 2995165148 Cleanup: simplify wrapping CurvesGeometry in C++ 2023-01-31 18:45:55 +01:00
Martijn Versteegh 6c774feba2 Mesh: Move UV layers to generic attributes
Currently the `MLoopUV` struct stores UV coordinates and flags related
to editing UV maps in the UV editor. This patch changes the coordinates
to use the generic 2D vector type, and moves the flags into three
separate boolean attributes. This follows the design in T95965, with
the ultimate intention of simplifying code and improving performance.

Importantly, the change allows exporters and renderers to use UVs
"touched" by geometry nodes, which only creates generic attributes.
It also allows geometry nodes to create "proper" UV maps from scratch,
though only with the Store Named Attribute node for now.

The new design considers any 2D vector attribute on the corner domain
to be a UV map. In the future, they might be distinguished from regular
2D vectors with attribute metadata, which may be helpful because they
are often interpolated differently.

Most of the code changes deal with passing around UV BMesh custom data
offsets and tracking the boolean "sublayers". The boolean layers are
use the following prefixes for attribute names: vert selection: `.vs.`,
edge selection: `.es.`, pinning: `.pn.`. Currently these are short to
avoid using up the maximum length of attribute names. To accommodate
for these 4 extra characters, the name length limit is enlarged to 68
bytes, while the maximum user settable name length is still 64 bytes.

Unfortunately Python/RNA API access to the UV flag data becomes slower.
Accessing the boolean layers directly is be better for performance in
general.

Like the other mesh SoA refactors, backward and forward compatibility
aren't affected, and won't be changed until 4.0. We pay for that by
making mesh reading and writing more expensive with conversions.

Resolves T85962

Differential Revision: https://developer.blender.org/D14365
2023-01-10 01:01:43 -05:00
Hans Goudey 1af62cb3bf Mesh: Move positions to a generic attribute
**Changes**
As described in T93602, this patch removes all use of the `MVert`
struct, replacing it with a generic named attribute with the name
`"position"`, consistent with other geometry types.

Variable names have been changed from `verts` to `positions`, to align
with the attribute name and the more generic design (positions are not
vertices, they are just an attribute stored on the point domain).

This change is made possible by previous commits that moved all other
data out of `MVert` to runtime data or other generic attributes. What
remains is mostly a simple type change. Though, the type still shows up
859 times, so the patch is quite large.

One compromise is that now `CD_MASK_BAREMESH` now contains
`CD_PROP_FLOAT3`. With the general move towards generic attributes
over custom data types, we are removing use of these type masks anyway.

**Benefits**
The most obvious benefit is reduced memory usage and the benefits
that brings in memory-bound situations. `float3` is only 3 bytes, in
comparison to `MVert` which was 4. When there are millions of vertices
this starts to matter more.

The other benefits come from using a more generic type. Instead of
writing algorithms specifically for `MVert`, code can just use arrays
of vectors. This will allow eliminating many temporary arrays or
wrappers used to extract positions.

Many possible improvements aren't implemented in this patch, though
I did switch simplify or remove the process of creating temporary
position arrays in a few places.

The design clarity that "positions are just another attribute" brings
allows removing explicit copying of vertices in some procedural
operations-- they are just processed like most other attributes.

**Performance**
This touches so many areas that it's hard to benchmark exhaustively,
but I observed some areas as examples.
* The mesh line node with 4 million count was 1.5x (8ms to 12ms) faster.
* The Spring splash screen went from ~4.3 to ~4.5 fps.
* The subdivision surface modifier/node was slightly faster
RNA access through Python may be slightly slower, since now we need
a name lookup instead of just a custom data type lookup for each index.

**Future Improvements**
* Remove uses of "vert_coords" functions:
  * `BKE_mesh_vert_coords_alloc`
  * `BKE_mesh_vert_coords_get`
  * `BKE_mesh_vert_coords_apply{_with_mat4}`
* Remove more hidden copying of positions
* General simplification now possible in many areas
* Convert more code to C++ to use `float3` instead of `float[3]`
  * Currently `reinterpret_cast` is used for those C-API functions

Differential Revision: https://developer.blender.org/D15982
2023-01-10 00:10:43 -05:00
Hans Goudey 08b2d04021 Cleanup: Use std::swap instead of macro in C++ code 2023-01-09 11:30:36 -05:00
Hans Goudey 6514bb05ea Mesh: Store active & default color attributes with strings
Attributes are unifying around a name-based API, and we would like to
be able to move away from CustomData in the future. This patch moves
the identification of active and fallback (render) color attributes
to strings on the mesh from flags on CustomDataLayer. This also
removes some ugliness used to retrieve these attributes and maintain
the active status.

The design is described more here: T98366

The patch keeps forward compatibility working until 4.0 with
the same method as the mesh struct of array refactors (T95965).

The strings are allowed to not correspond to an attribute, to allow
setting the active/default attribute independently of actually filling
its data. When applying a modifier, if the strings don't match an
attribute, they will be removed.

The realize instances / join node and join operator take the names from
the first / active input mesh. While other heuristics may be helpful
(and could be a future improvement), just using the first is simple
and predictable.

Differential Revision: https://developer.blender.org/D15169
2022-12-15 14:21:35 -06:00
Hans Goudey ca1642cd0c Cleanup: Use string argument for attribute API function
Instead of CustomDataLayer, which exposes the internal implementation
more than necessary, and requires that the layer is always available,
which isn't always true.
2022-11-10 15:29:21 -06:00
Campbell Barton f68cfd6bb0 Cleanup: replace C-style casts with functional casts for numeric types 2022-09-25 20:17:08 +10:00
Campbell Barton c7b247a118 Cleanup: replace static_casts with functional casts for numeric types 2022-09-25 18:31:10 +10:00
Hans Goudey d5df23d758 Cleanup: Rename attribute required functions
Avoid "customdata" in the name, since that's an implementation detail
in this context.
2022-09-15 13:14:31 -05:00
Hans Goudey d593497421 Cleanup: Use C++ methods to retrieve attribute accessors
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-07 21:41:39 -05:00
Campbell Barton 9c4c9a889d Cleanup: use 'continue' in customdata for loop, reduce right shift 2022-09-07 09:02:59 +10:00
Campbell Barton 6602f30225 Cleanup: early exit when the active layer disallows procedural access
Once the active layer index is reached, there is no need to keep
searching. Return early instead.
2022-09-06 17:16:04 +10:00
Philipp Oeser 4b818b1513 Merge branch 'blender-v3.3-release' 2022-09-03 11:43:15 +02:00