Age | Commit message (Collapse) | Author |
|
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
|
|
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.
|
|
|
|
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
|
|
|
|
|
|
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
|
|
The virtual arrays may be null if the curves are empty,
it's simple to just skip the domain interpolation completely.
|
|
The "snap to surface" operators now have "disabled" poll messages
when there is no surface object.
The implementation in most curves operators is also unified.
The goal is to avoid having to define and use the poll failure messages
in multiple places, to reduce the boilerplate that tends to be
necessary to add an operator, and to increase the likelihood that
operators are implemented with proper poll messages.
Differential Revision: https://developer.blender.org/D15528
|
|
|
|
Currently, there are two attribute API. The first, defined in `BKE_attribute.h` is
accessible from RNA and C code. The second is implemented with `GeometryComponent`
and is only accessible in C++ code. The second is widely used, but only being
accessible through the `GeometrySet` API makes it awkward to use, and even impossible
for types that don't correspond directly to a geometry component like `CurvesGeometry`.
This patch adds a new attribute API, designed to replace the `GeometryComponent`
attribute API now, and to eventually replace or be the basis of the other one.
The basic idea is that there is an `AttributeAccessor` class that allows code to
interact with a set of attributes owned by some geometry. The accessor itself has
no ownership. `AttributeAccessor` is a simple type that can be passed around by
value. That makes it easy to return it from functions and to store it in containers.
For const-correctness, there is also a `MutableAttributeAccessor` that allows
changing individual and can add or remove attributes.
Currently, `AttributeAccessor` is composed of two pointers. The first is a pointer
to the owner of the attribute data. The second is a pointer to a struct with
function pointers, that is similar to a virtual function table. The functions
know how to access attributes on the owner.
The actual attribute access for geometries is still implemented with the `AttributeProvider`
pattern, which makes it easy to support different sources of attributes on a
geometry and simplifies dealing with built-in attributes.
There are different ways to get an attribute accessor for a geometry:
* `GeometryComponent.attributes()`
* `CurvesGeometry.attributes()`
* `bke::mesh_attributes(const Mesh &)`
* `bke::pointcloud_attributes(const PointCloud &)`
All of these also have a `_for_write` variant that returns a `MutabelAttributeAccessor`.
Differential Revision: https://developer.blender.org/D15280
|
|
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
|
|
This patch adds (selected/active) outline around a curve object in object mode.
{F13270680}
In the past the draw bounds option was enabled for any curve objects. With this
patch it isn't needed and will be disabled.
In the future the curve outline could also be enabled to improve GPU selection.
Reviewed By: dfelinto, HooglyBoogly, fclem
Maniphest Tasks: T95933
Differential Revision: https://developer.blender.org/D15308
|
|
It's helpful to make the separation of legacy data formats explicit,
because it declutters actively changed code and makes it clear which
areas do not follow Blender's current design. In this case I separated
the `MFace`/"tessface" conversion code into a separate blenkernel
.cc file and header. This also makes refactoring to remove these
functions simpler because they're easier to find.
In the future, conversions to the `MLoopUV` type and `MVert`
can be implemented here for the same reasons (see T95965).
Differential Revision: https://developer.blender.org/D15396
|
|
This commit adds visualization to the selection in curves sculpt mode.
Previously it was only possible to see the selection when it was
connected to a material.
In order to obstruct the users vision as little as possible, the
selected areas of the curve are left as is, but a dark overlay
is drawn over unselected areas.
To make it work, the overlay requests the selection attribute and then
ensures that the evaluation is complete for curves. Then it retrieves
the evaluated selection GPU texture and passes that to the shader.
This reuses the existing generic attribute extraction system because
there currently wouldn't be any benefits to dealing with selection
separately, and because it avoids duplication of the logic that
extracts attributes from curves and evaluates them if necessary.
Differential Revision: https://developer.blender.org/D15219
|
|
This makes it possible to use this function without having
to call an operator. This is currently used by D14864.
|
|
|
|
* Make the class names more consistent.
* Implement missing move-constructors and assignment-operators.
|
|
This commit contains various new features for curves sculpt mode
that have been developed in parallel.
* Selection:
* Operator to select points/curves randomly.
* Operator to select endpoints of curves.
* Operator to grow/shrink an existing selection.
* New Brushes:
* Pinch: Moves points towards the brush center.
* Smooth: Makes individual curves straight without changing the root
or tip position.
* Puff: Makes curves stand up, aligning them with the surface normal.
* Density: Add or remove curves to achieve a certain density defined
by a minimum distance value.
* Slide: Move root points on the surface.
Differential Revision: https://developer.blender.org/D15134
|
|
|
|
This implements the new way to attach curves to a mesh surface using
a uv map (based on the recent discussion in T95776).
The curves data block now not only stores a reference to the surface object
but also a name of a uv map on that object. Having a uv map is optional
for most operations, but it will be required later for animation (when the
curves are supposed to be deformed based on deformation of the surface).
The "Empty Hair" operator in the Add menu sets the uv map name automatically
if possible. It's possible to start working without a uv map and to attach the
curves to a uv map later on. It's also possible to reattach the curves to a new
uv map using the "Curves > Snap to Nearest Surface" operator in curves sculpt
mode.
Note, the implementation to do the reverse lookup from uv to a position on the
surface is trivial and inefficient now. A more efficient data structure will be
implemented separately soon.
Differential Revision: https://developer.blender.org/D15125
|
|
This optimization should be restored when there is proper vizualization
for the selection attributes.
|
|
|
|
- CustomDataType -> eCustomDataType
- CustomDataMask -> eCustomDataMask
- AttributeDomain -> eAttrDomain
- NamedAttributeUsage -> eNamedAttrUsage
|
|
This commit adds a float selection to curve control points or curves,
a sculpt tool to paint the selection, and uses the selection influence
in the existing sculpt brushes.
The selection is the inverse of the "mask" from mesh sculpt mode
currently. That change is described in more detail here: T97903
Since some sculpt tools are really "per curve" tools, they use the
average point selection of all of their points. The delete brush
considers a curve selected if any of its points have a non-zero
selection.
There is a new option to choose the selection domain, which affects how
painting the selection works. You can also turn the selection off by
clicking on the active domain.
Sculpt brushes can be faster when the selection is small, because
finding selected curves or points is generally faster than the
existing brush intersection and distance checks.
The main limitation currently is that we can't see the selection in the
viewport by default. For now, to see the selection one has to add a
simple material to the curves object as shown in the differential
revision. And one has to switch to Material Preview in the 3d view.
Differential Revision: https://developer.blender.org/D14934
|
|
Knowing when layers are retrieved for write access will be essential
when adding proper copy-on-write support. This commit makes that
clearer by adding `const` where the retrieved data is not modified.
Ref T95842
|
|
This creates a new curves object with the name of the particle system.
The generated curves match the current evaluated state of the active hair
particle system.
Attachment information is not transferred currently.
Differential Revision: https://developer.blender.org/D14908
|
|
Follow conventions from T85728.
|
|
Ref T97171.
Differential Revision: https://developer.blender.org/D14637
|
|
|
|
This operator snaps the first point of every curve to the corresponding
surface object. The shape of individual curves or their orientation is
not changed.
There are two different attachment modes:
* `Nearest`: Move each curve so that the first point is on the closest
point on the surface. This should be used when the topology of the
surface mesh changed, but the shape generally stayed the same.
* `Deform`: Use the existing attachment information that is stored
for curves to move curves to their new location when the surface
mesh was deformed. This generally does not work when the
topology changed.
The purpose of the operator is to help setup the "ground truth"
for how curves are attached to the surface. When the ground
truth surface changed, the original curves have to be updated
as well. Deforming curves based on an animated surface will be
done with geometry nodes independent of the operator.
In the UI, the operator is currently exposed in curves sculpt mode
in the `Curves > Snap Curves to Surface` menu.
Differential Revision: https://developer.blender.org/D14515
|
|
Add "for_write" on function names that retrieve mutable data arrays.
Though this makes function names longer, it's likely worth it because
it allows more easily using the const functions in a non-const context,
and reduces cases of mistakenly retrieving with edit access.
In the long term, this situation might change more if we implement
attributes storage that is accessible directly on `CurvesGeometry`
without duplicating the attribute API on geometry components,
which is currently the rough plan.
Differential Revision: https://developer.blender.org/D14562
|
|
|
|
|
|
This adds a new operator that converts all selected curves objects
into hair particle systems on their respective surface objects. Existing
particle systems with the correct name are updated, otherwise a new
particle system is added.
The purpose of the operator is the make the new curve sculpting tools
useful even before all functionality is ported over from the old hair system.
The operator can be found in the `Object > Convert` menu in object mode,
when a curves object is active.
Differential Revision: https://developer.blender.org/D14441
|
|
A follow-up to e253f9f66d6f. Follow the policy from T85728
completely (using "num" as a prefix) and rename another function.
|
|
Rename "size" variables and functions to use "num" instead,
based on T85728 (though this doesn't apply to simple C++
containers, it applies here). Rename "range" to "points" in
some functions, so be more specific.
Differential Revision: https://developer.blender.org/D14431
|
|
Currently, any time a Curves data-block is created, the `curves_random`
function runs, filling it with 500 random curves, also adding a radius
attribute. This is just left over from the prototype in the initial
commit that added the type.
This commit moves the code that creates the random data to the curve
editors module, like the other primitives are organized.
Differential Revision: https://developer.blender.org/D14211
|
|
This is necessary, because the operator will have to use functions that
are currently private within this module. E.g. `paint_cursor_start`.
|
|
This adds the boilerplate code that is necessary to use the tool/brush/paint
systems in the new sculpt curves mode.
Two temporary dummy tools are part of this patch. They do nothing and
only serve to test the boilerplate. When the first actual tool is added,
those dummy tools will be removed.
Differential Revision: https://developer.blender.org/D14117
|
|
This adds a new sculpt mode to the experimental new curves object.
Currently, this mode can only be entered and exited, nothing else.
The main initial purpose of this node will be to use it for hair grooming.
The patch also adds the `editors/curves/` directory for the new curves
object, which will be necessary for many other things as well.
I added a completely new mode (`OB_MODE_SCULPT_CURVES`), because
`OB_MODE_SCULPT` seems to be rather specific to meshes, and reusing
it doesn't seem worth the trouble. The tools/brushes used in mesh vs.
curves sculpt mode are quite distinct as well.
I had to add DNA_userdef_enums.h to make the patch compile with C++
(forward declaration of enums isn't allowed). This follows the same
pattern that we use for other enums in dna.
Differential Revision: https://developer.blender.org/D14107
|