2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2005 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup modifiers
|
2011-02-25 13:57:17 +00:00
|
|
|
*/
|
|
|
|
|
|
2022-10-06 16:05:56 -05:00
|
|
|
#include <cstring>
|
2010-04-12 22:33:43 +00:00
|
|
|
|
2019-02-25 11:39:14 +01:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_bitmap.h"
|
|
|
|
|
#include "BLI_math_matrix.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_math_vector.h"
|
2019-02-25 11:39:14 +01:00
|
|
|
|
2012-04-10 14:11:45 +00:00
|
|
|
#include "DNA_image_types.h"
|
2018-04-19 11:03:58 +02:00
|
|
|
#include "DNA_mesh_types.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_meshdata_types.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
#include "DNA_modifier_types.h"
|
|
|
|
|
#include "DNA_object_types.h"
|
2012-04-10 14:11:45 +00:00
|
|
|
#include "DNA_scene_types.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2020-04-10 14:03:36 +02:00
|
|
|
#include "BKE_action.h" /* BKE_pose_channel_find_name */
|
2011-07-11 09:15:20 +00:00
|
|
|
#include "BKE_deform.h"
|
2018-05-08 11:33:31 +02:00
|
|
|
#include "BKE_editmesh.h"
|
2012-04-10 14:11:45 +00:00
|
|
|
#include "BKE_image.h"
|
2011-07-11 09:15:20 +00:00
|
|
|
#include "BKE_lattice.h"
|
2020-02-10 12:58:59 +01:00
|
|
|
#include "BKE_lib_id.h"
|
2023-03-12 22:29:15 +01:00
|
|
|
#include "BKE_mesh.hh"
|
2023-08-02 22:14:18 +02:00
|
|
|
#include "BKE_mesh_wrapper.hh"
|
2018-12-14 16:07:29 +01:00
|
|
|
#include "BKE_object.h"
|
2011-01-07 19:18:31 +00:00
|
|
|
|
2010-04-25 01:10:03 +00:00
|
|
|
#include "BKE_modifier.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2023-09-22 03:18:17 +02:00
|
|
|
#include "DEG_depsgraph.hh"
|
|
|
|
|
#include "DEG_depsgraph_query.hh"
|
2018-05-23 15:52:35 +02:00
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
#include "MOD_modifiertypes.hh"
|
|
|
|
|
#include "MOD_util.hh"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2010-04-12 22:33:43 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2018-12-07 15:45:53 +01:00
|
|
|
void MOD_init_texture(MappingInfoModifierData *dmd, const ModifierEvalContext *ctx)
|
2012-04-10 14:11:45 +00:00
|
|
|
{
|
2019-03-26 11:25:07 +01:00
|
|
|
Tex *tex = dmd->texture;
|
2018-12-07 15:45:53 +01:00
|
|
|
|
2022-10-06 16:05:56 -05:00
|
|
|
if (tex == nullptr) {
|
2012-04-10 14:11:45 +00:00
|
|
|
return;
|
2018-12-07 15:45:53 +01:00
|
|
|
}
|
2012-04-10 14:11:45 +00:00
|
|
|
|
2014-01-14 04:59:58 +11:00
|
|
|
if (tex->ima && BKE_image_is_animated(tex->ima)) {
|
2019-06-17 11:39:52 +02:00
|
|
|
BKE_image_user_frame_calc(tex->ima, &tex->iuser, DEG_get_ctime(ctx->depsgraph));
|
2014-01-14 04:59:58 +11:00
|
|
|
}
|
2012-04-10 14:11:45 +00:00
|
|
|
}
|
|
|
|
|
|
2018-05-07 18:14:15 +02:00
|
|
|
void MOD_get_texture_coords(MappingInfoModifierData *dmd,
|
2022-10-12 10:27:27 +11:00
|
|
|
const ModifierEvalContext * /*ctx*/,
|
2018-05-07 18:14:15 +02:00
|
|
|
Object *ob,
|
|
|
|
|
Mesh *mesh,
|
2018-05-08 11:57:34 +02:00
|
|
|
float (*cos)[3],
|
2018-05-07 18:14:15 +02:00
|
|
|
float (*r_texco)[3])
|
|
|
|
|
{
|
2023-03-29 14:16:31 +11:00
|
|
|
/* TODO: to be renamed to `get_texture_coords` once we are done with moving modifiers to Mesh. */
|
|
|
|
|
|
Mesh: Replace MLoop struct with generic attributes
Implements #102359.
Split the `MLoop` struct into two separate integer arrays called
`corner_verts` and `corner_edges`, referring to the vertex each corner
is attached to and the next edge around the face at each corner. These
arrays can be sliced to give access to the edges or vertices in a face.
Then they are often referred to as "poly_verts" or "poly_edges".
The main benefits are halving the necessary memory bandwidth when only
one array is used and simplifications from using regular integer indices
instead of a special-purpose struct.
The commit also starts a renaming from "loop" to "corner" in mesh code.
Like the other mesh struct of array refactors, forward compatibility is
kept by writing files with the older format. This will be done until 4.0
to ease the transition process.
Looking at a small portion of the patch should give a good impression
for the rest of the changes. I tried to make the changes as small as
possible so it's easy to tell the correctness from the diff. Though I
found Blender developers have been very inventive over the last decade
when finding different ways to loop over the corners in a face.
For performance, nearly every piece of code that deals with `Mesh` is
slightly impacted. Any algorithm that is memory bottle-necked should
see an improvement. For example, here is a comparison of interpolating
a vertex float attribute to face corners (Ryzen 3700x):
**Before** (Average: 3.7 ms, Min: 3.4 ms)
```
threading::parallel_for(loops.index_range(), 4096, [&](IndexRange range) {
for (const int64_t i : range) {
dst[i] = src[loops[i].v];
}
});
```
**After** (Average: 2.9 ms, Min: 2.6 ms)
```
array_utils::gather(src, corner_verts, dst);
```
That's an improvement of 28% to the average timings, and it's also a
simplification, since an index-based routine can be used instead.
For more examples using the new arrays, see the design task.
Pull Request: https://projects.blender.org/blender/blender/pulls/104424
2023-03-20 15:55:13 +01:00
|
|
|
using namespace blender;
|
2022-03-28 12:29:47 +11:00
|
|
|
const int verts_num = mesh->totvert;
|
2018-05-07 18:14:15 +02:00
|
|
|
int i;
|
|
|
|
|
int texmapping = dmd->texmapping;
|
2020-04-10 14:03:36 +02:00
|
|
|
float mapref_imat[4][4];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-07 18:14:15 +02:00
|
|
|
if (texmapping == MOD_DISP_MAP_OBJECT) {
|
2022-10-06 16:05:56 -05:00
|
|
|
if (dmd->map_object != nullptr) {
|
2019-03-26 11:25:07 +01:00
|
|
|
Object *map_object = dmd->map_object;
|
2020-04-10 14:03:36 +02:00
|
|
|
if (dmd->map_bone[0] != '\0') {
|
|
|
|
|
bPoseChannel *pchan = BKE_pose_channel_find_name(map_object->pose, dmd->map_bone);
|
|
|
|
|
if (pchan) {
|
|
|
|
|
float mat_bone_world[4][4];
|
2022-10-24 14:16:37 +02:00
|
|
|
mul_m4_m4m4(mat_bone_world, map_object->object_to_world, pchan->pose_mat);
|
2020-04-10 14:03:36 +02:00
|
|
|
invert_m4_m4(mapref_imat, mat_bone_world);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2022-10-24 14:16:37 +02:00
|
|
|
invert_m4_m4(mapref_imat, map_object->object_to_world);
|
2020-04-10 14:03:36 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2022-10-24 14:16:37 +02:00
|
|
|
invert_m4_m4(mapref_imat, map_object->object_to_world);
|
2020-04-10 14:03:36 +02:00
|
|
|
}
|
2018-12-07 15:45:53 +01:00
|
|
|
}
|
|
|
|
|
else { /* if there is no map object, default to local */
|
2018-05-07 18:14:15 +02:00
|
|
|
texmapping = MOD_DISP_MAP_LOCAL;
|
2018-12-07 15:45:53 +01:00
|
|
|
}
|
2018-05-07 18:14:15 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-07 18:14:15 +02:00
|
|
|
/* UVs need special handling, since they come from faces */
|
|
|
|
|
if (texmapping == MOD_DISP_MAP_UV) {
|
2023-07-25 21:15:52 +02:00
|
|
|
if (CustomData_has_layer(&mesh->loop_data, CD_PROP_FLOAT2)) {
|
2023-07-24 22:06:55 +02:00
|
|
|
const OffsetIndices faces = mesh->faces();
|
Mesh: Replace MLoop struct with generic attributes
Implements #102359.
Split the `MLoop` struct into two separate integer arrays called
`corner_verts` and `corner_edges`, referring to the vertex each corner
is attached to and the next edge around the face at each corner. These
arrays can be sliced to give access to the edges or vertices in a face.
Then they are often referred to as "poly_verts" or "poly_edges".
The main benefits are halving the necessary memory bandwidth when only
one array is used and simplifications from using regular integer indices
instead of a special-purpose struct.
The commit also starts a renaming from "loop" to "corner" in mesh code.
Like the other mesh struct of array refactors, forward compatibility is
kept by writing files with the older format. This will be done until 4.0
to ease the transition process.
Looking at a small portion of the patch should give a good impression
for the rest of the changes. I tried to make the changes as small as
possible so it's easy to tell the correctness from the diff. Though I
found Blender developers have been very inventive over the last decade
when finding different ways to loop over the corners in a face.
For performance, nearly every piece of code that deals with `Mesh` is
slightly impacted. Any algorithm that is memory bottle-necked should
see an improvement. For example, here is a comparison of interpolating
a vertex float attribute to face corners (Ryzen 3700x):
**Before** (Average: 3.7 ms, Min: 3.4 ms)
```
threading::parallel_for(loops.index_range(), 4096, [&](IndexRange range) {
for (const int64_t i : range) {
dst[i] = src[loops[i].v];
}
});
```
**After** (Average: 2.9 ms, Min: 2.6 ms)
```
array_utils::gather(src, corner_verts, dst);
```
That's an improvement of 28% to the average timings, and it's also a
simplification, since an index-based routine can be used instead.
For more examples using the new arrays, see the design task.
Pull Request: https://projects.blender.org/blender/blender/pulls/104424
2023-03-20 15:55:13 +01:00
|
|
|
const Span<int> corner_verts = mesh->corner_verts();
|
2022-03-28 12:29:47 +11:00
|
|
|
BLI_bitmap *done = BLI_BITMAP_NEW(verts_num, __func__);
|
2018-05-07 18:14:15 +02:00
|
|
|
char uvname[MAX_CUSTOMDATA_LAYER_NAME];
|
2023-07-25 21:15:52 +02:00
|
|
|
CustomData_validate_layer_name(&mesh->loop_data, CD_PROP_FLOAT2, dmd->uvlayer_name, uvname);
|
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 00:47:04 -05:00
|
|
|
const float(*mloop_uv)[2] = static_cast<const float(*)[2]>(
|
2023-07-25 21:15:52 +02:00
|
|
|
CustomData_get_layer_named(&mesh->loop_data, CD_PROP_FLOAT2, uvname));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-07 18:14:15 +02:00
|
|
|
/* verts are given the UV from the first face that uses them */
|
2023-07-24 22:06:55 +02:00
|
|
|
for (const int i : faces.index_range()) {
|
|
|
|
|
const IndexRange face = faces[i];
|
2023-07-25 10:24:46 -04:00
|
|
|
for (const int corner : face) {
|
|
|
|
|
const int vert = corner_verts[corner];
|
|
|
|
|
if (!BLI_BITMAP_TEST(done, vert)) {
|
2018-05-07 18:14:15 +02:00
|
|
|
/* remap UVs from [0, 1] to [-1, 1] */
|
2023-07-25 10:24:46 -04:00
|
|
|
r_texco[vert][0] = (mloop_uv[corner][0] * 2.0f) - 1.0f;
|
|
|
|
|
r_texco[vert][1] = (mloop_uv[corner][1] * 2.0f) - 1.0f;
|
|
|
|
|
BLI_BITMAP_ENABLE(done, vert);
|
2018-05-07 18:14:15 +02:00
|
|
|
}
|
2023-07-25 10:24:46 -04:00
|
|
|
}
|
2018-05-07 18:14:15 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-07 18:14:15 +02:00
|
|
|
MEM_freeN(done);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-08-07 12:40:29 +02:00
|
|
|
|
|
|
|
|
/* if there are no UVs, default to local */
|
|
|
|
|
texmapping = MOD_DISP_MAP_LOCAL;
|
2018-05-07 18:14:15 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-06-14 11:59:32 -04:00
|
|
|
const Span<float3> positions = mesh->vert_positions();
|
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
|
|
|
for (i = 0; i < verts_num; i++, r_texco++) {
|
2018-05-07 18:14:15 +02:00
|
|
|
switch (texmapping) {
|
|
|
|
|
case MOD_DISP_MAP_LOCAL:
|
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
|
|
|
copy_v3_v3(*r_texco, cos != nullptr ? *cos : positions[i]);
|
2018-05-07 18:14:15 +02:00
|
|
|
break;
|
|
|
|
|
case MOD_DISP_MAP_GLOBAL:
|
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
|
|
|
mul_v3_m4v3(*r_texco, ob->object_to_world, cos != nullptr ? *cos : positions[i]);
|
2018-05-07 18:14:15 +02:00
|
|
|
break;
|
|
|
|
|
case MOD_DISP_MAP_OBJECT:
|
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
|
|
|
mul_v3_m4v3(*r_texco, ob->object_to_world, cos != nullptr ? *cos : positions[i]);
|
2020-04-10 14:03:36 +02:00
|
|
|
mul_m4_v3(mapref_imat, *r_texco);
|
2018-05-07 18:14:15 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2022-10-06 16:05:56 -05:00
|
|
|
if (cos != nullptr) {
|
2018-05-08 11:57:34 +02:00
|
|
|
cos++;
|
|
|
|
|
}
|
2018-05-07 18:14:15 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-12 14:29:59 +10:00
|
|
|
void MOD_previous_vcos_store(ModifierData *md, const float (*vert_coords)[3])
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
while ((md = md->next) && md->type == eModifierType_Armature) {
|
|
|
|
|
ArmatureModifierData *amd = (ArmatureModifierData *)md;
|
2022-10-06 16:05:56 -05:00
|
|
|
if (amd->multi && amd->vert_coords_prev == nullptr) {
|
|
|
|
|
amd->vert_coords_prev = static_cast<float(*)[3]>(MEM_dupallocN(vert_coords));
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2010-04-11 22:12:30 +00:00
|
|
|
break;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
/* lattice/mesh modifier too */
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-05 16:02:05 -04:00
|
|
|
void MOD_get_vgroup(const Object *ob,
|
|
|
|
|
const Mesh *mesh,
|
|
|
|
|
const char *name,
|
|
|
|
|
const MDeformVert **dvert,
|
|
|
|
|
int *defgrp_index)
|
2018-04-19 11:03:58 +02:00
|
|
|
{
|
2021-07-13 12:10:34 -04:00
|
|
|
if (mesh) {
|
|
|
|
|
*defgrp_index = BKE_id_defgroup_name_index(&mesh->id, name);
|
|
|
|
|
if (*defgrp_index != -1) {
|
Mesh: Remove redundant custom data pointers
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
2022-09-05 11:56:34 -05:00
|
|
|
*dvert = BKE_mesh_deform_verts(mesh);
|
2021-07-13 12:10:34 -04:00
|
|
|
}
|
|
|
|
|
else {
|
2022-10-06 16:05:56 -05:00
|
|
|
*dvert = nullptr;
|
2021-07-13 12:10:34 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
*defgrp_index = BKE_object_defgroup_name_index(ob, name);
|
|
|
|
|
if (*defgrp_index != -1 && ob->type == OB_LATTICE) {
|
2018-04-19 11:03:58 +02:00
|
|
|
*dvert = BKE_lattice_deform_verts_get(ob);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2021-07-13 12:10:34 -04:00
|
|
|
else {
|
2022-10-06 16:05:56 -05:00
|
|
|
*dvert = nullptr;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2018-04-19 11:03:58 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-03 08:36:28 +10:00
|
|
|
void MOD_depsgraph_update_object_bone_relation(DepsNodeHandle *node,
|
2020-04-10 22:00:21 +02:00
|
|
|
Object *object,
|
|
|
|
|
const char *bonename,
|
|
|
|
|
const char *description)
|
|
|
|
|
{
|
2022-10-06 16:05:56 -05:00
|
|
|
if (object == nullptr) {
|
2020-04-10 22:00:21 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (bonename[0] != '\0' && object->type == OB_ARMATURE) {
|
|
|
|
|
DEG_add_object_relation(node, object, DEG_OB_COMP_EVAL_POSE, description);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
DEG_add_object_relation(node, object, DEG_OB_COMP_TRANSFORM, description);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-14 06:29:17 +00:00
|
|
|
void modifier_type_init(ModifierTypeInfo *types[])
|
2010-04-25 01:10:03 +00:00
|
|
|
{
|
|
|
|
|
#define INIT_TYPE(typeName) (types[eModifierType_##typeName] = &modifierType_##typeName)
|
|
|
|
|
INIT_TYPE(None);
|
|
|
|
|
INIT_TYPE(Curve);
|
|
|
|
|
INIT_TYPE(Lattice);
|
|
|
|
|
INIT_TYPE(Subsurf);
|
|
|
|
|
INIT_TYPE(Build);
|
|
|
|
|
INIT_TYPE(Array);
|
|
|
|
|
INIT_TYPE(Mirror);
|
|
|
|
|
INIT_TYPE(EdgeSplit);
|
|
|
|
|
INIT_TYPE(Bevel);
|
|
|
|
|
INIT_TYPE(Displace);
|
|
|
|
|
INIT_TYPE(UVProject);
|
|
|
|
|
INIT_TYPE(Decimate);
|
|
|
|
|
INIT_TYPE(Smooth);
|
|
|
|
|
INIT_TYPE(Cast);
|
|
|
|
|
INIT_TYPE(Wave);
|
|
|
|
|
INIT_TYPE(Armature);
|
|
|
|
|
INIT_TYPE(Hook);
|
|
|
|
|
INIT_TYPE(Softbody);
|
|
|
|
|
INIT_TYPE(Cloth);
|
|
|
|
|
INIT_TYPE(Collision);
|
|
|
|
|
INIT_TYPE(Boolean);
|
|
|
|
|
INIT_TYPE(MeshDeform);
|
2011-11-13 12:17:27 +00:00
|
|
|
INIT_TYPE(Ocean);
|
2010-04-25 01:10:03 +00:00
|
|
|
INIT_TYPE(ParticleSystem);
|
|
|
|
|
INIT_TYPE(ParticleInstance);
|
|
|
|
|
INIT_TYPE(Explode);
|
|
|
|
|
INIT_TYPE(Shrinkwrap);
|
|
|
|
|
INIT_TYPE(Mask);
|
|
|
|
|
INIT_TYPE(SimpleDeform);
|
|
|
|
|
INIT_TYPE(Multires);
|
|
|
|
|
INIT_TYPE(Surface);
|
2019-12-16 15:50:14 +01:00
|
|
|
INIT_TYPE(Fluid);
|
2010-04-25 01:10:03 +00:00
|
|
|
INIT_TYPE(ShapeKey);
|
|
|
|
|
INIT_TYPE(Solidify);
|
|
|
|
|
INIT_TYPE(Screw);
|
2011-05-01 15:16:59 +00:00
|
|
|
INIT_TYPE(Warp);
|
2011-07-25 15:27:01 +00:00
|
|
|
INIT_TYPE(WeightVGEdit);
|
|
|
|
|
INIT_TYPE(WeightVGMix);
|
|
|
|
|
INIT_TYPE(WeightVGProximity);
|
2011-05-24 07:08:58 +00:00
|
|
|
INIT_TYPE(DynamicPaint);
|
2011-12-30 21:11:40 +00:00
|
|
|
INIT_TYPE(Remesh);
|
2012-05-22 15:29:01 +00:00
|
|
|
INIT_TYPE(Skin);
|
2012-10-24 10:39:11 +00:00
|
|
|
INIT_TYPE(LaplacianSmooth);
|
2012-11-19 20:40:08 +00:00
|
|
|
INIT_TYPE(Triangulate);
|
2012-12-14 04:07:30 +00:00
|
|
|
INIT_TYPE(UVWarp);
|
2013-01-21 15:41:00 +00:00
|
|
|
INIT_TYPE(MeshCache);
|
2013-11-24 07:00:49 +11:00
|
|
|
INIT_TYPE(LaplacianDeform);
|
2013-12-22 07:08:35 +11:00
|
|
|
INIT_TYPE(Wireframe);
|
2019-12-11 22:31:20 -03:00
|
|
|
INIT_TYPE(Weld);
|
2015-01-09 21:19:12 +01:00
|
|
|
INIT_TYPE(DataTransfer);
|
2015-02-05 14:49:44 +01:00
|
|
|
INIT_TYPE(NormalEdit);
|
2015-03-29 04:44:05 +11:00
|
|
|
INIT_TYPE(CorrectiveSmooth);
|
Basic Alembic support
All in all, this patch adds an Alembic importer, an Alembic exporter,
and a new CacheFile data block which, for now, wraps around an Alembic
archive. This data block is made available through a new modifier ("Mesh
Sequence Cache") as well as a new constraint ("Transform Cache") to
somewhat properly support respectively geometric and transformation data
streaming from alembic caches.
A more in-depth documentation is to be found on the wiki, as well as a
guide to compile alembic: https://wiki.blender.org/index.php/
User:Kevindietrich/AlembicBasicIo.
Many thanks to everyone involved in this little project, and huge shout
out to "cgstrive" for the thorough testings with Maya, 3ds Max, Houdini
and Realflow as well as @fjuhec, @jensverwiebe and @jasperge for the
custom builds and compile fixes.
Reviewers: sergey, campbellbarton, mont29
Reviewed By: sergey, campbellbarton, mont29
Differential Revision: https://developer.blender.org/D2060
2016-08-06 06:20:37 +02:00
|
|
|
INIT_TYPE(MeshSequenceCache);
|
2017-02-27 12:39:14 -03:00
|
|
|
INIT_TYPE(SurfaceDeform);
|
2018-05-25 22:24:24 +05:30
|
|
|
INIT_TYPE(WeightedNormal);
|
2020-09-29 16:02:40 +02:00
|
|
|
INIT_TYPE(MeshToVolume);
|
2020-10-07 18:03:07 +02:00
|
|
|
INIT_TYPE(VolumeDisplace);
|
2020-10-19 12:11:38 +02:00
|
|
|
INIT_TYPE(VolumeToMesh);
|
2020-12-02 13:25:25 +01:00
|
|
|
INIT_TYPE(Nodes);
|
2010-04-25 01:10:03 +00:00
|
|
|
#undef INIT_TYPE
|
|
|
|
|
}
|