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
|
|
|
*/
|
|
|
|
|
|
Cleanup: reduce amount of math-related includes
Using ClangBuildAnalyzer on the whole Blender build, it was pointing
out that BLI_math.h is the heaviest "header hub" (i.e. non tiny file
that is included a lot).
However, there's very little (actually zero) source files in Blender
that need "all the math" (base, colors, vectors, matrices,
quaternions, intersection, interpolation, statistics, solvers and
time). A common use case is source files needing just vectors, or
just vectors & matrices, or just colors etc. Actually, 181 files
were including the whole math thing without needing it at all.
This change removes BLI_math.h completely, and instead in all the
places that need it, includes BLI_math_vector.h or BLI_math_color.h
and so on.
Change from that:
- BLI_math_color.h was included 1399 times -> now 408 (took 114.0sec
to parse -> now 36.3sec)
- BLI_simd.h 1403 -> 418 (109.7sec -> 34.9sec).
Full rebuild of Blender (Apple M1, Xcode, RelWithDebInfo) is not
affected much (342sec -> 334sec). Most of benefit would be when
someone's changing BLI_simd.h or BLI_math_color.h or similar files,
that now there's 3x fewer files result in a recompile.
Pull Request #110944
2023-08-09 11:39:20 +03:00
|
|
|
#include "BLI_math_matrix.h"
|
2019-02-25 11:39:14 +01:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
2022-07-15 14:12:34 +02:00
|
|
|
#include "BLT_translation.h"
|
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
#include "DNA_key_types.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_mesh_types.h"
|
2020-12-15 10:47:58 +11:00
|
|
|
#include "DNA_object_types.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2024-01-30 14:42:07 -05:00
|
|
|
#include "BKE_key.hh"
|
2016-12-28 17:30:58 +01:00
|
|
|
#include "BKE_particle.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2023-08-10 22:40:27 +02:00
|
|
|
#include "RNA_access.hh"
|
2022-03-14 16:54:46 +01:00
|
|
|
#include "RNA_prototypes.h"
|
2020-09-25 12:49:18 +02:00
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
#include "MOD_modifiertypes.hh"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "UI_resources.hh"
|
2020-09-25 12:45:30 +02:00
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void deform_verts(ModifierData * /*md*/,
|
|
|
|
|
const ModifierEvalContext *ctx,
|
|
|
|
|
Mesh * /*mesh*/,
|
2023-11-14 10:54:57 +01:00
|
|
|
blender::MutableSpan<blender::float3> positions)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2018-05-01 17:33:04 +02:00
|
|
|
Key *key = BKE_key_from_object(ctx->object);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2013-01-03 06:47:44 +00:00
|
|
|
if (key && key->block.first) {
|
|
|
|
|
int deformedVerts_tot;
|
2023-05-04 18:35:37 +02:00
|
|
|
BKE_key_evaluate_object_ex(ctx->object,
|
|
|
|
|
&deformedVerts_tot,
|
2023-11-14 10:54:57 +01:00
|
|
|
reinterpret_cast<float *>(positions.data()),
|
|
|
|
|
sizeof(blender::float3) * positions.size(),
|
2023-05-04 18:35:37 +02:00
|
|
|
nullptr);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void deform_matrices(ModifierData *md,
|
|
|
|
|
const ModifierEvalContext *ctx,
|
|
|
|
|
Mesh *mesh,
|
2023-11-14 10:54:57 +01:00
|
|
|
blender::MutableSpan<blender::float3> positions,
|
|
|
|
|
blender::MutableSpan<blender::float3x3> matrices)
|
2011-01-31 20:02:51 +00:00
|
|
|
{
|
2018-05-01 17:33:04 +02:00
|
|
|
Key *key = BKE_key_from_object(ctx->object);
|
|
|
|
|
KeyBlock *kb = BKE_keyblock_from_object(ctx->object);
|
2011-01-31 20:02:51 +00:00
|
|
|
|
2023-11-14 10:54:57 +01:00
|
|
|
if (kb && kb->totelem == positions.size() && kb != key->refkey) {
|
2022-08-26 12:51:46 +10:00
|
|
|
float scale[3][3];
|
2011-02-13 03:21:27 +00:00
|
|
|
int a;
|
|
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
if (ctx->object->shapeflag & OB_SHAPE_LOCK) {
|
2018-05-01 17:33:04 +02:00
|
|
|
scale_m3_fl(scale, 1);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2011-01-31 20:02:51 +00:00
|
|
|
scale_m3_fl(scale, kb->curval);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2011-01-31 20:02:51 +00:00
|
|
|
|
2023-11-14 10:54:57 +01:00
|
|
|
for (a = 0; a < positions.size(); a++) {
|
|
|
|
|
copy_m3_m3(matrices[a].ptr(), scale);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2011-01-31 20:02:51 +00:00
|
|
|
}
|
|
|
|
|
|
2023-11-14 10:54:57 +01:00
|
|
|
deform_verts(md, ctx, mesh, positions);
|
2011-01-31 20:02:51 +00:00
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void deform_verts_EM(ModifierData *md,
|
|
|
|
|
const ModifierEvalContext *ctx,
|
2023-07-31 10:20:26 +10:00
|
|
|
BMEditMesh * /*em*/,
|
2023-07-27 12:04:18 +10:00
|
|
|
Mesh *mesh,
|
2023-11-14 10:54:57 +01:00
|
|
|
blender::MutableSpan<blender::float3> positions)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2018-05-01 17:33:04 +02:00
|
|
|
Key *key = BKE_key_from_object(ctx->object);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
if (key && key->type == KEY_RELATIVE) {
|
2023-11-14 10:54:57 +01:00
|
|
|
deform_verts(md, ctx, mesh, positions);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void deform_matrices_EM(ModifierData * /*md*/,
|
|
|
|
|
const ModifierEvalContext *ctx,
|
2023-07-31 10:20:26 +10:00
|
|
|
BMEditMesh * /*em*/,
|
2023-07-27 12:04:18 +10:00
|
|
|
Mesh * /*mesh*/,
|
2023-11-14 10:54:57 +01:00
|
|
|
blender::MutableSpan<blender::float3> /*positions*/,
|
|
|
|
|
blender::MutableSpan<blender::float3x3> matrices)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2018-05-01 17:33:04 +02:00
|
|
|
Key *key = BKE_key_from_object(ctx->object);
|
|
|
|
|
KeyBlock *kb = BKE_keyblock_from_object(ctx->object);
|
2011-01-31 20:02:51 +00:00
|
|
|
|
2023-11-14 10:54:57 +01:00
|
|
|
if (kb && kb->totelem == matrices.size() && kb != key->refkey) {
|
2022-08-26 12:51:46 +10:00
|
|
|
float scale[3][3];
|
2010-04-11 22:12:30 +00:00
|
|
|
scale_m3_fl(scale, kb->curval);
|
|
|
|
|
|
2023-11-14 10:54:57 +01:00
|
|
|
for (int a = 0; a < matrices.size(); a++) {
|
|
|
|
|
copy_m3_m3(matrices[a].ptr(), scale);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ModifierTypeInfo modifierType_ShapeKey = {
|
2023-07-26 17:08:14 +02:00
|
|
|
/*idname*/ "ShapeKey",
|
2023-01-16 12:41:11 +11:00
|
|
|
/*name*/ N_("ShapeKey"),
|
2023-07-27 12:04:18 +10:00
|
|
|
/*struct_name*/ "ShapeKeyModifierData",
|
|
|
|
|
/*struct_size*/ sizeof(ShapeKeyModifierData),
|
2023-01-16 12:41:11 +11:00
|
|
|
/*srna*/ &RNA_Modifier,
|
2023-11-14 10:03:56 +01:00
|
|
|
/*type*/ ModifierTypeType::OnlyDeform,
|
2023-01-16 12:41:11 +11:00
|
|
|
/*flags*/ eModifierTypeFlag_AcceptsCVs | eModifierTypeFlag_AcceptsVertexCosOnly |
|
2012-05-06 13:38:33 +00:00
|
|
|
eModifierTypeFlag_SupportsEditmode,
|
2023-01-16 12:41:11 +11:00
|
|
|
/*icon*/ ICON_DOT,
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
/*copy_data*/ nullptr,
|
|
|
|
|
|
|
|
|
|
/*deform_verts*/ deform_verts,
|
|
|
|
|
/*deform_matrices*/ deform_matrices,
|
|
|
|
|
/*deform_verts_EM*/ deform_verts_EM,
|
|
|
|
|
/*deform_matrices_EM*/ deform_matrices_EM,
|
|
|
|
|
/*modify_mesh*/ nullptr,
|
|
|
|
|
/*modify_geometry_set*/ nullptr,
|
|
|
|
|
|
|
|
|
|
/*init_data*/ nullptr,
|
|
|
|
|
/*required_data_mask*/ nullptr,
|
|
|
|
|
/*free_data*/ nullptr,
|
|
|
|
|
/*is_disabled*/ nullptr,
|
|
|
|
|
/*update_depsgraph*/ nullptr,
|
|
|
|
|
/*depends_on_time*/ nullptr,
|
|
|
|
|
/*depends_on_normals*/ nullptr,
|
|
|
|
|
/*foreach_ID_link*/ nullptr,
|
|
|
|
|
/*foreach_tex_link*/ nullptr,
|
|
|
|
|
/*free_runtime_data*/ nullptr,
|
|
|
|
|
/*panel_register*/ nullptr,
|
|
|
|
|
/*blend_write*/ nullptr,
|
|
|
|
|
/*blend_read*/ nullptr,
|
2024-01-18 22:51:30 +01:00
|
|
|
/*foreach_cache*/ nullptr,
|
2010-04-11 22:12:30 +00:00
|
|
|
};
|