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"
|
|
|
|
|
#include "BLI_math_vector.h"
|
2019-02-25 11:56:24 +01:00
|
|
|
#include "BLI_utildefines.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2024-02-09 18:59:42 +01:00
|
|
|
#include "BLT_translation.hh"
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2020-10-01 09:38:00 -05:00
|
|
|
#include "DNA_defaults.h"
|
2019-02-25 11:56:24 +01:00
|
|
|
#include "DNA_meshdata_types.h"
|
|
|
|
|
#include "DNA_object_types.h"
|
2020-06-05 10:41:03 -04:00
|
|
|
#include "DNA_screen_types.h"
|
2011-01-07 19:18:31 +00:00
|
|
|
|
2024-01-29 18:57:16 -05:00
|
|
|
#include "BKE_deform.hh"
|
2024-01-18 12:20:42 +01:00
|
|
|
#include "BKE_lib_query.hh"
|
2023-11-14 09:30:40 +01:00
|
|
|
#include "BKE_modifier.hh"
|
2024-02-14 16:14:49 +01:00
|
|
|
#include "BKE_object_types.hh"
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "UI_interface.hh"
|
|
|
|
|
#include "UI_resources.hh"
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2023-08-10 22:40:27 +02:00
|
|
|
#include "RNA_access.hh"
|
2024-07-10 18:30:02 +02:00
|
|
|
#include "RNA_prototypes.hh"
|
2011-01-07 19:18:31 +00:00
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
#include "MOD_ui_common.hh"
|
|
|
|
|
#include "MOD_util.hh"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void init_data(ModifierData *md)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
CastModifierData *cmd = (CastModifierData *)md;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-10-01 09:38:00 -05:00
|
|
|
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(cmd, modifier));
|
|
|
|
|
|
|
|
|
|
MEMCPY_STRUCT_AFTER(cmd, DNA_struct_default_get(CastModifierData), modifier);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static bool is_disabled(const Scene * /*scene*/, ModifierData *md, bool /*use_render_params*/)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
CastModifierData *cmd = (CastModifierData *)md;
|
2010-04-11 22:12:30 +00:00
|
|
|
short flag;
|
2018-06-17 17:04:27 +02:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
flag = cmd->flag & (MOD_CAST_X | MOD_CAST_Y | MOD_CAST_Z);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
if ((cmd->fac == 0.0f) || flag == 0) {
|
2013-06-02 03:59:19 +00:00
|
|
|
return true;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2013-06-02 03:59:19 +00:00
|
|
|
return false;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void required_data_mask(ModifierData *md, CustomData_MeshMasks *r_cddata_masks)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
|
|
|
|
CastModifierData *cmd = (CastModifierData *)md;
|
|
|
|
|
|
2023-05-05 09:25:45 +10:00
|
|
|
/* Ask for vertex-groups if we need them. */
|
Refactor CDData masks, to have one mask per mesh elem type.
We already have different storages for cddata of verts, edges etc.,
'simply' do the same for the mask flags we use all around Blender code
to request some data, or limit some operation to some layers, etc.
Reason we need this is that some cddata types (like Normals) are
actually shared between verts/polys/loops, and we don’t want to generate
clnors everytime we request vnors!
As a side note, this also does final fix to T59338, which was the
trigger for this patch (need to request computed loop normals for
another mesh than evaluated one).
Reviewers: brecht, campbellbarton, sergey
Differential Revision: https://developer.blender.org/D4407
2019-03-07 11:13:40 +01:00
|
|
|
if (cmd->defgrp_name[0] != '\0') {
|
|
|
|
|
r_cddata_masks->vmask |= CD_MASK_MDEFORMVERT;
|
|
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void foreach_ID_link(ModifierData *md, Object *ob, IDWalkFunc walk, void *user_data)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
CastModifierData *cmd = (CastModifierData *)md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
walk(user_data, ob, (ID **)&cmd->object, IDWALK_CB_NOP);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void update_depsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
|
Depsgraph: New dependency graph integration commit
This commit integrates the work done so far on the new dependency graph system,
where goal was to replace legacy depsgraph with the new one, supporting loads of
neat features like:
- More granular dependency relation nature, which solves issues with fake cycles
in the dependencies.
- Move towards all-animatable, by better integration of drivers into the system.
- Lay down some basis for upcoming copy-on-write, overrides and so on.
The new system is living side-by-side with the previous one and disabled by
default, so nothing will become suddenly broken. The way to enable new depsgraph
is to pass `--new-depsgraph` command line argument.
It's a bit early to consider the system production-ready, there are some TODOs
and issues were discovered during the merge period, they'll be addressed ASAP.
But it's important to merge, because it's the only way to attract artists to
really start testing this system.
There are number of assorted documents related on the design of the new system:
* http://wiki.blender.org/index.php/User:Aligorith/GSoC2013_Depsgraph#Design_Documents
* http://wiki.blender.org/index.php/User:Nazg-gul/DependencyGraph
There are also some user-related information online:
* http://code.blender.org/2015/02/blender-dependency-graph-branch-for-users/
* http://code.blender.org/2015/03/more-dependency-graph-tricks/
Kudos to everyone who was involved into the project:
- Joshua "Aligorith" Leung -- design specification, initial code
- Lukas "lukas_t" Toenne -- integrating code into blender, with further fixes
- Sergey "Sergey" "Sharybin" -- some mocking around, trying to wrap up the
project and so
- Bassam "slikdigit" Kurdali -- stressing the new system, reporting all the
issues and recording/writing documentation.
- Everyone else who i forgot to mention here :)
2015-05-12 15:05:57 +05:00
|
|
|
{
|
|
|
|
|
CastModifierData *cmd = (CastModifierData *)md;
|
2023-05-04 18:35:37 +02:00
|
|
|
if (cmd->object != nullptr) {
|
2018-02-22 12:54:06 +01:00
|
|
|
DEG_add_object_relation(ctx->node, cmd->object, DEG_OB_COMP_TRANSFORM, "Cast Modifier");
|
2022-08-04 12:11:31 +02:00
|
|
|
DEG_add_depends_on_transform_relation(ctx->node, "Cast Modifier");
|
Depsgraph: New dependency graph integration commit
This commit integrates the work done so far on the new dependency graph system,
where goal was to replace legacy depsgraph with the new one, supporting loads of
neat features like:
- More granular dependency relation nature, which solves issues with fake cycles
in the dependencies.
- Move towards all-animatable, by better integration of drivers into the system.
- Lay down some basis for upcoming copy-on-write, overrides and so on.
The new system is living side-by-side with the previous one and disabled by
default, so nothing will become suddenly broken. The way to enable new depsgraph
is to pass `--new-depsgraph` command line argument.
It's a bit early to consider the system production-ready, there are some TODOs
and issues were discovered during the merge period, they'll be addressed ASAP.
But it's important to merge, because it's the only way to attract artists to
really start testing this system.
There are number of assorted documents related on the design of the new system:
* http://wiki.blender.org/index.php/User:Aligorith/GSoC2013_Depsgraph#Design_Documents
* http://wiki.blender.org/index.php/User:Nazg-gul/DependencyGraph
There are also some user-related information online:
* http://code.blender.org/2015/02/blender-dependency-graph-branch-for-users/
* http://code.blender.org/2015/03/more-dependency-graph-tricks/
Kudos to everyone who was involved into the project:
- Joshua "Aligorith" Leung -- design specification, initial code
- Lukas "lukas_t" Toenne -- integrating code into blender, with further fixes
- Sergey "Sergey" "Sharybin" -- some mocking around, trying to wrap up the
project and so
- Bassam "slikdigit" Kurdali -- stressing the new system, reporting all the
issues and recording/writing documentation.
- Everyone else who i forgot to mention here :)
2015-05-12 15:05:57 +05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
static void sphere_do(CastModifierData *cmd,
|
2023-05-04 18:35:37 +02:00
|
|
|
const ModifierEvalContext * /*ctx*/,
|
2018-12-07 15:45:53 +01:00
|
|
|
Object *ob,
|
|
|
|
|
Mesh *mesh,
|
2023-11-14 10:54:57 +01:00
|
|
|
blender::MutableSpan<blender::float3> positions)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2023-05-04 18:35:37 +02:00
|
|
|
const MDeformVert *dvert = nullptr;
|
2020-01-27 14:03:24 +01:00
|
|
|
const bool invert_vgroup = (cmd->flag & MOD_CAST_INVERT_VGROUP) != 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
Object *ctrl_ob = nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
int i, defgrp_index;
|
2014-01-28 03:52:21 +11:00
|
|
|
bool has_radius = false;
|
2010-04-11 22:12:30 +00:00
|
|
|
short flag, type;
|
2013-03-03 05:43:47 +00:00
|
|
|
float len = 0.0f;
|
|
|
|
|
float fac = cmd->fac;
|
|
|
|
|
float facm = 1.0f - fac;
|
|
|
|
|
const float fac_orig = fac;
|
2010-04-11 22:12:30 +00:00
|
|
|
float vec[3], center[3] = {0.0f, 0.0f, 0.0f};
|
|
|
|
|
float mat[4][4], imat[4][4];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
flag = cmd->flag;
|
|
|
|
|
type = cmd->type; /* projection type: sphere or cylinder */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
if (type == MOD_CAST_TYPE_CYLINDER) {
|
2010-04-11 22:12:30 +00:00
|
|
|
flag &= ~MOD_CAST_Z;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-26 11:25:07 +01:00
|
|
|
ctrl_ob = cmd->object;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-05-05 09:25:45 +10:00
|
|
|
/* The spheres center is {0, 0, 0} (the ob's own center in its local space),
|
|
|
|
|
* by default, but if the user defined a control object,
|
|
|
|
|
* we use its location, transformed to ob's local space. */
|
2010-04-11 22:12:30 +00:00
|
|
|
if (ctrl_ob) {
|
2012-03-24 06:24:53 +00:00
|
|
|
if (flag & MOD_CAST_USE_OB_TRANSFORM) {
|
2024-02-14 16:14:49 +01:00
|
|
|
invert_m4_m4(imat, ctrl_ob->object_to_world().ptr());
|
|
|
|
|
mul_m4_m4m4(mat, imat, ob->object_to_world().ptr());
|
2010-04-11 22:12:30 +00:00
|
|
|
invert_m4_m4(imat, mat);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-02-14 16:14:49 +01:00
|
|
|
invert_m4_m4(ob->runtime->world_to_object.ptr(), ob->object_to_world().ptr());
|
|
|
|
|
mul_v3_m4v3(center, ob->world_to_object().ptr(), ctrl_ob->object_to_world().location());
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* now we check which options the user wants */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* 1) (flag was checked in the "if (ctrl_ob)" block above) */
|
|
|
|
|
/* 2) cmd->radius > 0.0f: only the vertices within this radius from
|
2012-03-09 18:28:30 +00:00
|
|
|
* the center of the effect should be deformed */
|
2019-04-22 09:15:10 +10:00
|
|
|
if (cmd->radius > FLT_EPSILON) {
|
2023-07-22 11:36:59 +10:00
|
|
|
has_radius = true;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* 3) if we were given a vertex group name,
|
2012-03-09 18:28:30 +00:00
|
|
|
* only those vertices should be affected */
|
2020-03-18 14:14:24 +11:00
|
|
|
if (cmd->defgrp_name[0] != '\0') {
|
|
|
|
|
MOD_get_vgroup(ob, mesh, cmd->defgrp_name, &dvert, &defgrp_index);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (flag & MOD_CAST_SIZE_FROM_RADIUS) {
|
2010-04-11 22:12:30 +00:00
|
|
|
len = cmd->radius;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
len = cmd->size;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (len <= 0) {
|
2023-11-14 10:54:57 +01:00
|
|
|
for (i = 0; i < positions.size(); i++) {
|
|
|
|
|
len += len_v3v3(center, positions[i]);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2023-11-14 10:54:57 +01:00
|
|
|
len /= positions.size();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
if (len == 0.0f) {
|
2010-04-11 22:12:30 +00:00
|
|
|
len = 10.0f;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-11-14 10:54:57 +01:00
|
|
|
for (i = 0; i < positions.size(); i++) {
|
2010-04-11 22:12:30 +00:00
|
|
|
float tmp_co[3];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-11-14 10:54:57 +01:00
|
|
|
copy_v3_v3(tmp_co, positions[i]);
|
2012-03-24 06:24:53 +00:00
|
|
|
if (ctrl_ob) {
|
|
|
|
|
if (flag & MOD_CAST_USE_OB_TRANSFORM) {
|
2010-04-11 22:12:30 +00:00
|
|
|
mul_m4_v3(mat, tmp_co);
|
2012-03-24 06:24:53 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2010-04-23 23:57:00 +00:00
|
|
|
sub_v3_v3(tmp_co, center);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-12 00:36:50 +00:00
|
|
|
copy_v3_v3(vec, tmp_co);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
if (type == MOD_CAST_TYPE_CYLINDER) {
|
2010-04-11 22:12:30 +00:00
|
|
|
vec[2] = 0.0f;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
if (has_radius) {
|
2019-04-22 09:15:10 +10:00
|
|
|
if (len_v3(vec) > cmd->radius) {
|
2010-04-11 22:12:30 +00:00
|
|
|
continue;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-03 05:43:47 +00:00
|
|
|
if (dvert) {
|
2020-03-06 12:50:56 +11:00
|
|
|
const float weight = invert_vgroup ?
|
|
|
|
|
1.0f - BKE_defvert_find_weight(&dvert[i], defgrp_index) :
|
|
|
|
|
BKE_defvert_find_weight(&dvert[i], defgrp_index);
|
2020-01-27 14:03:24 +01:00
|
|
|
|
2013-03-03 05:43:47 +00:00
|
|
|
if (weight == 0.0f) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-03 05:43:47 +00:00
|
|
|
fac = fac_orig * weight;
|
|
|
|
|
facm = 1.0f - fac;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
normalize_v3(vec);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
if (flag & MOD_CAST_X) {
|
2012-05-06 13:38:33 +00:00
|
|
|
tmp_co[0] = fac * vec[0] * len + facm * tmp_co[0];
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (flag & MOD_CAST_Y) {
|
2012-05-06 13:38:33 +00:00
|
|
|
tmp_co[1] = fac * vec[1] * len + facm * tmp_co[1];
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (flag & MOD_CAST_Z) {
|
2012-05-06 13:38:33 +00:00
|
|
|
tmp_co[2] = fac * vec[2] * len + facm * tmp_co[2];
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (ctrl_ob) {
|
|
|
|
|
if (flag & MOD_CAST_USE_OB_TRANSFORM) {
|
2010-04-11 22:12:30 +00:00
|
|
|
mul_m4_v3(imat, tmp_co);
|
2012-03-24 06:24:53 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2010-04-21 12:27:48 +00:00
|
|
|
add_v3_v3(tmp_co, center);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-11-14 10:54:57 +01:00
|
|
|
copy_v3_v3(positions[i], tmp_co);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-26 11:25:07 +01:00
|
|
|
static void cuboid_do(CastModifierData *cmd,
|
2023-05-04 18:35:37 +02:00
|
|
|
const ModifierEvalContext * /*ctx*/,
|
2018-12-07 15:45:53 +01:00
|
|
|
Object *ob,
|
|
|
|
|
Mesh *mesh,
|
2023-11-14 10:54:57 +01:00
|
|
|
blender::MutableSpan<blender::float3> positions)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2023-05-04 18:35:37 +02:00
|
|
|
const MDeformVert *dvert = nullptr;
|
2020-03-18 14:14:24 +11:00
|
|
|
int defgrp_index;
|
2020-01-27 14:03:24 +01:00
|
|
|
const bool invert_vgroup = (cmd->flag & MOD_CAST_INVERT_VGROUP) != 0;
|
|
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
Object *ctrl_ob = nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-18 14:14:24 +11:00
|
|
|
int i;
|
2014-01-28 03:52:21 +11:00
|
|
|
bool has_radius = false;
|
2010-04-11 22:12:30 +00:00
|
|
|
short flag;
|
2013-03-03 05:43:47 +00:00
|
|
|
float fac = cmd->fac;
|
|
|
|
|
float facm = 1.0f - fac;
|
|
|
|
|
const float fac_orig = fac;
|
2010-04-11 22:12:30 +00:00
|
|
|
float min[3], max[3], bb[8][3];
|
|
|
|
|
float center[3] = {0.0f, 0.0f, 0.0f};
|
|
|
|
|
float mat[4][4], imat[4][4];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
flag = cmd->flag;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-26 11:25:07 +01:00
|
|
|
ctrl_ob = cmd->object;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* now we check which options the user wants */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* 1) (flag was checked in the "if (ctrl_ob)" block above) */
|
|
|
|
|
/* 2) cmd->radius > 0.0f: only the vertices within this radius from
|
2012-03-09 18:28:30 +00:00
|
|
|
* the center of the effect should be deformed */
|
2019-04-22 09:15:10 +10:00
|
|
|
if (cmd->radius > FLT_EPSILON) {
|
2023-07-22 11:36:59 +10:00
|
|
|
has_radius = true;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* 3) if we were given a vertex group name,
|
2012-03-09 18:28:30 +00:00
|
|
|
* only those vertices should be affected */
|
2020-03-18 14:14:24 +11:00
|
|
|
if (cmd->defgrp_name[0] != '\0') {
|
|
|
|
|
MOD_get_vgroup(ob, mesh, cmd->defgrp_name, &dvert, &defgrp_index);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
if (ctrl_ob) {
|
2012-03-24 06:24:53 +00:00
|
|
|
if (flag & MOD_CAST_USE_OB_TRANSFORM) {
|
2024-02-14 16:14:49 +01:00
|
|
|
invert_m4_m4(imat, ctrl_ob->object_to_world().ptr());
|
|
|
|
|
mul_m4_m4m4(mat, imat, ob->object_to_world().ptr());
|
2010-04-11 22:12:30 +00:00
|
|
|
invert_m4_m4(imat, mat);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-02-14 16:14:49 +01:00
|
|
|
invert_m4_m4(ob->runtime->world_to_object.ptr(), ob->object_to_world().ptr());
|
|
|
|
|
mul_v3_m4v3(center, ob->world_to_object().ptr(), ctrl_ob->object_to_world().location());
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if ((flag & MOD_CAST_SIZE_FROM_RADIUS) && has_radius) {
|
|
|
|
|
for (i = 0; i < 3; i++) {
|
2010-04-11 22:12:30 +00:00
|
|
|
min[i] = -cmd->radius;
|
|
|
|
|
max[i] = cmd->radius;
|
|
|
|
|
}
|
2012-03-24 06:24:53 +00:00
|
|
|
}
|
|
|
|
|
else if (!(flag & MOD_CAST_SIZE_FROM_RADIUS) && cmd->size > 0) {
|
|
|
|
|
for (i = 0; i < 3; i++) {
|
2010-04-11 22:12:30 +00:00
|
|
|
min[i] = -cmd->size;
|
|
|
|
|
max[i] = cmd->size;
|
|
|
|
|
}
|
2012-03-24 06:24:53 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2010-04-11 22:12:30 +00:00
|
|
|
/* get bound box */
|
|
|
|
|
/* We can't use the object's bound box because other modifiers
|
2012-03-09 18:28:30 +00:00
|
|
|
* may have changed the vertex data. */
|
2010-04-11 22:12:30 +00:00
|
|
|
INIT_MINMAX(min, max);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* Cast's center is the ob's own center in its local space,
|
2012-03-09 18:28:30 +00:00
|
|
|
* by default, but if the user defined a control object, we use
|
|
|
|
|
* its location, transformed to ob's local space. */
|
2010-04-11 22:12:30 +00:00
|
|
|
if (ctrl_ob) {
|
|
|
|
|
float vec[3];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* let the center of the ctrl_ob be part of the bound box: */
|
2012-05-13 11:05:52 +00:00
|
|
|
minmax_v3v3_v3(min, max, center);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-11-14 10:54:57 +01:00
|
|
|
for (i = 0; i < positions.size(); i++) {
|
|
|
|
|
sub_v3_v3v3(vec, positions[i], center);
|
2012-05-13 11:05:52 +00:00
|
|
|
minmax_v3v3_v3(min, max, vec);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2023-11-14 10:54:57 +01:00
|
|
|
for (i = 0; i < positions.size(); i++) {
|
|
|
|
|
minmax_v3v3_v3(min, max, positions[i]);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* we want a symmetric bound box around the origin */
|
2019-04-22 09:15:10 +10:00
|
|
|
if (fabsf(min[0]) > fabsf(max[0])) {
|
2012-07-21 15:27:40 +00:00
|
|
|
max[0] = fabsf(min[0]);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (fabsf(min[1]) > fabsf(max[1])) {
|
2012-07-21 15:27:40 +00:00
|
|
|
max[1] = fabsf(min[1]);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (fabsf(min[2]) > fabsf(max[2])) {
|
2012-07-21 15:27:40 +00:00
|
|
|
max[2] = fabsf(min[2]);
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
min[0] = -max[0];
|
|
|
|
|
min[1] = -max[1];
|
|
|
|
|
min[2] = -max[2];
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* building our custom bounding box */
|
|
|
|
|
bb[0][0] = bb[2][0] = bb[4][0] = bb[6][0] = min[0];
|
|
|
|
|
bb[1][0] = bb[3][0] = bb[5][0] = bb[7][0] = max[0];
|
|
|
|
|
bb[0][1] = bb[1][1] = bb[4][1] = bb[5][1] = min[1];
|
|
|
|
|
bb[2][1] = bb[3][1] = bb[6][1] = bb[7][1] = max[1];
|
|
|
|
|
bb[0][2] = bb[1][2] = bb[2][2] = bb[3][2] = min[2];
|
|
|
|
|
bb[4][2] = bb[5][2] = bb[6][2] = bb[7][2] = max[2];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-03 05:43:47 +00:00
|
|
|
/* ready to apply the effect, one vertex at a time */
|
2023-11-14 10:54:57 +01:00
|
|
|
for (i = 0; i < positions.size(); i++) {
|
2010-04-11 22:12:30 +00:00
|
|
|
int octant, coord;
|
2013-03-03 05:43:47 +00:00
|
|
|
float d[3], dmax, apex[3], fbb;
|
2010-04-11 22:12:30 +00:00
|
|
|
float tmp_co[3];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-11-14 10:54:57 +01:00
|
|
|
copy_v3_v3(tmp_co, positions[i]);
|
2012-03-24 06:24:53 +00:00
|
|
|
if (ctrl_ob) {
|
|
|
|
|
if (flag & MOD_CAST_USE_OB_TRANSFORM) {
|
2010-04-11 22:12:30 +00:00
|
|
|
mul_m4_v3(mat, tmp_co);
|
2012-03-24 06:24:53 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2010-04-12 00:36:50 +00:00
|
|
|
sub_v3_v3(tmp_co, center);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
if (has_radius) {
|
2011-03-27 13:49:53 +00:00
|
|
|
if (fabsf(tmp_co[0]) > cmd->radius || fabsf(tmp_co[1]) > cmd->radius ||
|
2012-04-28 06:31:57 +00:00
|
|
|
fabsf(tmp_co[2]) > cmd->radius)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2012-04-28 06:31:57 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-03 05:43:47 +00:00
|
|
|
if (dvert) {
|
2020-03-06 12:50:56 +11:00
|
|
|
const float weight = invert_vgroup ?
|
|
|
|
|
1.0f - BKE_defvert_find_weight(&dvert[i], defgrp_index) :
|
|
|
|
|
BKE_defvert_find_weight(&dvert[i], defgrp_index);
|
2020-01-27 14:03:24 +01:00
|
|
|
|
2013-03-03 05:43:47 +00:00
|
|
|
if (weight == 0.0f) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-03 05:43:47 +00:00
|
|
|
fac = fac_orig * weight;
|
|
|
|
|
facm = 1.0f - fac;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-11-20 11:39:03 +11:00
|
|
|
/* The algorithm used to project the vertices to their
|
2013-03-03 05:43:47 +00:00
|
|
|
* bounding box (bb) is pretty simple:
|
|
|
|
|
* for each vertex v:
|
|
|
|
|
* 1) find in which octant v is in;
|
|
|
|
|
* 2) find which outer "wall" of that octant is closer to v;
|
|
|
|
|
* 3) calculate factor (var fbb) to project v to that wall;
|
|
|
|
|
* 4) project. */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-03 05:43:47 +00:00
|
|
|
/* find in which octant this vertex is in */
|
2010-04-11 22:12:30 +00:00
|
|
|
octant = 0;
|
2019-04-22 09:15:10 +10:00
|
|
|
if (tmp_co[0] > 0.0f) {
|
2010-04-11 22:12:30 +00:00
|
|
|
octant += 1;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (tmp_co[1] > 0.0f) {
|
2010-04-11 22:12:30 +00:00
|
|
|
octant += 2;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (tmp_co[2] > 0.0f) {
|
2010-04-11 22:12:30 +00:00
|
|
|
octant += 4;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-03 05:43:47 +00:00
|
|
|
/* apex is the bb's vertex at the chosen octant */
|
2010-04-11 22:12:30 +00:00
|
|
|
copy_v3_v3(apex, bb[octant]);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-03 05:43:47 +00:00
|
|
|
/* find which bb plane is closest to this vertex ... */
|
2010-04-11 22:12:30 +00:00
|
|
|
d[0] = tmp_co[0] / apex[0];
|
|
|
|
|
d[1] = tmp_co[1] / apex[1];
|
|
|
|
|
d[2] = tmp_co[2] / apex[2];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-03 05:43:47 +00:00
|
|
|
/* ... (the closest has the higher (closer to 1) d value) */
|
2010-04-11 22:12:30 +00:00
|
|
|
dmax = d[0];
|
|
|
|
|
coord = 0;
|
|
|
|
|
if (d[1] > dmax) {
|
|
|
|
|
dmax = d[1];
|
|
|
|
|
coord = 1;
|
|
|
|
|
}
|
|
|
|
|
if (d[2] > dmax) {
|
2023-07-05 13:58:04 +10:00
|
|
|
// dmax = d[2]; /* commented, we don't need it */
|
2010-04-11 22:12:30 +00:00
|
|
|
coord = 2;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-03 05:43:47 +00:00
|
|
|
/* ok, now we know which coordinate of the vertex to use */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:15:10 +10:00
|
|
|
if (fabsf(tmp_co[coord]) < FLT_EPSILON) { /* avoid division by zero */
|
2010-04-11 22:12:30 +00:00
|
|
|
continue;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-03 05:43:47 +00:00
|
|
|
/* finally, this is the factor we wanted, to project the vertex
|
|
|
|
|
* to its bounding box (bb) */
|
2010-04-11 22:12:30 +00:00
|
|
|
fbb = apex[coord] / tmp_co[coord];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-03 05:43:47 +00:00
|
|
|
/* calculate the new vertex position */
|
2019-04-22 09:15:10 +10:00
|
|
|
if (flag & MOD_CAST_X) {
|
2010-04-11 22:12:30 +00:00
|
|
|
tmp_co[0] = facm * tmp_co[0] + fac * tmp_co[0] * fbb;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (flag & MOD_CAST_Y) {
|
2010-04-11 22:12:30 +00:00
|
|
|
tmp_co[1] = facm * tmp_co[1] + fac * tmp_co[1] * fbb;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
|
|
|
|
if (flag & MOD_CAST_Z) {
|
2010-04-11 22:12:30 +00:00
|
|
|
tmp_co[2] = facm * tmp_co[2] + fac * tmp_co[2] * fbb;
|
2019-04-22 09:15:10 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (ctrl_ob) {
|
|
|
|
|
if (flag & MOD_CAST_USE_OB_TRANSFORM) {
|
2010-04-11 22:12:30 +00:00
|
|
|
mul_m4_v3(imat, tmp_co);
|
2012-03-24 06:24:53 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2010-04-21 12:27:48 +00:00
|
|
|
add_v3_v3(tmp_co, center);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-11-14 10:54:57 +01:00
|
|
|
copy_v3_v3(positions[i], tmp_co);
|
2010-04-11 22:12:30 +00: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
|
|
|
{
|
|
|
|
|
CastModifierData *cmd = (CastModifierData *)md;
|
2020-05-25 20:16:42 +10:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
if (cmd->type == MOD_CAST_TYPE_CUBOID) {
|
2023-11-14 10:54:57 +01:00
|
|
|
cuboid_do(cmd, ctx, ctx->object, mesh, positions);
|
2012-03-24 06:24:53 +00:00
|
|
|
}
|
|
|
|
|
else { /* MOD_CAST_TYPE_SPHERE or MOD_CAST_TYPE_CYLINDER */
|
2023-11-14 10:54:57 +01:00
|
|
|
sphere_do(cmd, ctx, ctx->object, mesh, positions);
|
2018-05-08 17:52:24 +02:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
static void panel_draw(const bContext * /*C*/, Panel *panel)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
|
|
|
|
uiLayout *row;
|
|
|
|
|
uiLayout *layout = panel->layout;
|
2023-07-29 15:06:33 +10:00
|
|
|
const eUI_Item_Flag toggles_flag = UI_ITEM_R_TOGGLE | UI_ITEM_R_FORCE_BLANK_DECORATE;
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
PointerRNA ob_ptr;
|
2020-09-02 14:13:26 -05:00
|
|
|
PointerRNA *ptr = modifier_panel_get_property_pointers(panel, &ob_ptr);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2020-09-02 14:13:26 -05:00
|
|
|
PointerRNA cast_object_ptr = RNA_pointer_get(ptr, "object");
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
uiLayoutSetPropSep(layout, true);
|
|
|
|
|
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(layout, ptr, "cast_type", UI_ITEM_NONE, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
row = uiLayoutRowWithHeading(layout, true, IFACE_("Axis"));
|
2023-05-04 18:35:37 +02:00
|
|
|
uiItemR(row, ptr, "use_x", toggles_flag, nullptr, ICON_NONE);
|
|
|
|
|
uiItemR(row, ptr, "use_y", toggles_flag, nullptr, ICON_NONE);
|
|
|
|
|
uiItemR(row, ptr, "use_z", toggles_flag, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(layout, ptr, "factor", UI_ITEM_NONE, nullptr, ICON_NONE);
|
|
|
|
|
uiItemR(layout, ptr, "radius", UI_ITEM_NONE, nullptr, ICON_NONE);
|
|
|
|
|
uiItemR(layout, ptr, "size", UI_ITEM_NONE, nullptr, ICON_NONE);
|
|
|
|
|
uiItemR(layout, ptr, "use_radius_as_size", UI_ITEM_NONE, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
modifier_vgroup_ui(layout, ptr, &ob_ptr, "vertex_group", "invert_vertex_group", nullptr);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(layout, ptr, "object", UI_ITEM_NONE, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
if (!RNA_pointer_is_null(&cast_object_ptr)) {
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(layout, ptr, "use_transform", UI_ITEM_NONE, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
2020-09-02 14:13:26 -05:00
|
|
|
modifier_panel_end(layout, ptr);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void panel_register(ARegionType *region_type)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
|
|
|
|
modifier_panel_register(region_type, eModifierType_Cast, panel_draw);
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
ModifierTypeInfo modifierType_Cast = {
|
2023-07-26 17:08:14 +02:00
|
|
|
/*idname*/ "Cast",
|
2023-01-16 12:41:11 +11:00
|
|
|
/*name*/ N_("Cast"),
|
2023-07-27 12:04:18 +10:00
|
|
|
/*struct_name*/ "CastModifierData",
|
|
|
|
|
/*struct_size*/ sizeof(CastModifierData),
|
2023-01-16 12:41:11 +11:00
|
|
|
/*srna*/ &RNA_CastModifier,
|
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_MOD_CAST,
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
/*copy_data*/ BKE_modifier_copydata_generic,
|
|
|
|
|
|
|
|
|
|
/*deform_verts*/ deform_verts,
|
|
|
|
|
/*deform_matrices*/ nullptr,
|
|
|
|
|
/*deform_verts_EM*/ nullptr,
|
|
|
|
|
/*deform_matrices_EM*/ nullptr,
|
|
|
|
|
/*modify_mesh*/ nullptr,
|
|
|
|
|
/*modify_geometry_set*/ nullptr,
|
|
|
|
|
|
|
|
|
|
/*init_data*/ init_data,
|
|
|
|
|
/*required_data_mask*/ required_data_mask,
|
|
|
|
|
/*free_data*/ nullptr,
|
|
|
|
|
/*is_disabled*/ is_disabled,
|
|
|
|
|
/*update_depsgraph*/ update_depsgraph,
|
|
|
|
|
/*depends_on_time*/ nullptr,
|
|
|
|
|
/*depends_on_normals*/ nullptr,
|
|
|
|
|
/*foreach_ID_link*/ foreach_ID_link,
|
|
|
|
|
/*foreach_tex_link*/ nullptr,
|
|
|
|
|
/*free_runtime_data*/ nullptr,
|
|
|
|
|
/*panel_register*/ panel_register,
|
|
|
|
|
/*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
|
|
|
};
|