2010-04-11 22:12:30 +00:00
|
|
|
/*
|
2011-10-23 17:52:20 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2005 by the Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s): Daniel Dunbar
|
|
|
|
* Ton Roosendaal,
|
|
|
|
* Ben Batt,
|
|
|
|
* Brecht Van Lommel,
|
|
|
|
* Campbell Barton
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
*/
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2011-02-25 13:57:17 +00:00
|
|
|
/** \file blender/modifiers/intern/MOD_hook.c
|
|
|
|
* \ingroup modifiers
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2018-05-09 12:38:52 +02:00
|
|
|
#include "DNA_mesh_types.h"
|
2010-04-12 00:36:50 +00:00
|
|
|
#include "DNA_meshdata_types.h"
|
2010-08-04 04:01:27 +00:00
|
|
|
#include "DNA_object_types.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2010-04-12 22:33:43 +00:00
|
|
|
#include "BLI_math.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
#include "BKE_action.h"
|
2018-05-09 12:38:52 +02:00
|
|
|
#include "BKE_editmesh.h"
|
|
|
|
#include "BKE_library.h"
|
2015-10-08 14:21:11 +02:00
|
|
|
#include "BKE_library_query.h"
|
2018-05-09 12:38:52 +02:00
|
|
|
#include "BKE_mesh.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
#include "BKE_modifier.h"
|
|
|
|
#include "BKE_deform.h"
|
2015-02-04 07:04:21 +11:00
|
|
|
#include "BKE_colortools.h"
|
2011-01-07 19:18:31 +00:00
|
|
|
|
2018-12-07 15:45:53 +01:00
|
|
|
#include "DEG_depsgraph_query.h"
|
|
|
|
|
2010-04-12 22:33:43 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2011-02-13 14:16:36 +00:00
|
|
|
#include "MOD_util.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2018-06-17 17:04:27 +02:00
|
|
|
static void initData(ModifierData *md)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
HookModifierData *hmd = (HookModifierData *) md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
hmd->force = 1.0;
|
2015-02-04 07:04:21 +11:00
|
|
|
hmd->curfalloff = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
|
|
|
|
hmd->falloff_type = eHook_Falloff_Smooth;
|
|
|
|
hmd->flag = 0;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2018-07-04 12:45:30 +02:00
|
|
|
static void copyData(const ModifierData *md, ModifierData *target, const int flag)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2018-05-08 15:04:10 +02:00
|
|
|
const HookModifierData *hmd = (const HookModifierData *) md;
|
2012-05-06 13:38:33 +00:00
|
|
|
HookModifierData *thmd = (HookModifierData *) target;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2018-07-04 12:45:30 +02:00
|
|
|
modifier_copyData_generic(md, target, flag);
|
2013-12-22 04:35:52 +11:00
|
|
|
|
2015-02-04 07:04:21 +11:00
|
|
|
thmd->curfalloff = curvemapping_copy(hmd->curfalloff);
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
thmd->indexar = MEM_dupallocN(hmd->indexar);
|
|
|
|
}
|
|
|
|
|
2010-10-14 06:29:17 +00:00
|
|
|
static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
|
|
|
HookModifierData *hmd = (HookModifierData *)md;
|
|
|
|
CustomDataMask dataMask = 0;
|
|
|
|
|
|
|
|
/* ask for vertexgroups if we need them */
|
2012-03-24 06:24:53 +00:00
|
|
|
if (hmd->name[0]) dataMask |= CD_MASK_MDEFORMVERT;
|
|
|
|
if (hmd->indexar) dataMask |= CD_MASK_ORIGINDEX;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
return dataMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void freeData(ModifierData *md)
|
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
HookModifierData *hmd = (HookModifierData *) md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2015-02-04 07:04:21 +11:00
|
|
|
curvemapping_free(hmd->curfalloff);
|
|
|
|
|
2018-05-08 14:21:02 +02:00
|
|
|
MEM_SAFE_FREE(hmd->indexar);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2018-07-10 12:14:08 +02:00
|
|
|
static bool isDisabled(const struct Scene *UNUSED(scene), ModifierData *md, bool UNUSED(useRenderParams))
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
HookModifierData *hmd = (HookModifierData *) md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
return !hmd->object;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void foreachObjectLink(
|
2012-05-06 13:38:33 +00:00
|
|
|
ModifierData *md, Object *ob,
|
2015-10-05 15:57:10 +02:00
|
|
|
ObjectWalkFunc walk, void *userData)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
HookModifierData *hmd = (HookModifierData *) md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2017-01-31 09:47:59 +01:00
|
|
|
walk(userData, ob, &hmd->object, IDWALK_CB_NOP);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 12:54:06 +01:00
|
|
|
static void updateDepsgraph(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
|
|
|
{
|
|
|
|
HookModifierData *hmd = (HookModifierData *)md;
|
|
|
|
if (hmd->object != NULL) {
|
|
|
|
if (hmd->subtarget[0]) {
|
2018-02-22 12:54:06 +01:00
|
|
|
DEG_add_bone_relation(ctx->node, hmd->object, hmd->subtarget, DEG_OB_COMP_BONE, "Hook 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
|
|
|
}
|
2018-02-22 12:54:06 +01:00
|
|
|
DEG_add_object_relation(ctx->node, hmd->object, DEG_OB_COMP_TRANSFORM, "Hook 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
|
|
|
}
|
2016-05-11 09:23:11 +02:00
|
|
|
/* We need own transformation as well. */
|
2018-02-22 12:54:06 +01:00
|
|
|
DEG_add_object_relation(ctx->node, ctx->object, DEG_OB_COMP_TRANSFORM, "Hook 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
|
|
|
}
|
|
|
|
|
2015-02-04 07:04:21 +11:00
|
|
|
struct HookData_cb {
|
|
|
|
float (*vertexCos)[3];
|
|
|
|
|
|
|
|
MDeformVert *dvert;
|
|
|
|
int defgrp_index;
|
|
|
|
|
|
|
|
struct CurveMapping *curfalloff;
|
|
|
|
|
|
|
|
char falloff_type;
|
|
|
|
float falloff;
|
|
|
|
float falloff_sq;
|
|
|
|
float fac_orig;
|
|
|
|
|
|
|
|
unsigned int use_falloff : 1;
|
|
|
|
unsigned int use_uniform : 1;
|
|
|
|
|
|
|
|
float cent[3];
|
|
|
|
|
|
|
|
float mat_uniform[3][3];
|
|
|
|
float mat[4][4];
|
|
|
|
};
|
|
|
|
|
|
|
|
static float hook_falloff(
|
|
|
|
const struct HookData_cb *hd,
|
|
|
|
const float len_sq)
|
2010-10-15 08:32:27 +00:00
|
|
|
{
|
2015-02-04 07:04:21 +11:00
|
|
|
BLI_assert(hd->falloff_sq);
|
|
|
|
if (len_sq > hd->falloff_sq) {
|
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
else if (len_sq > 0.0f) {
|
|
|
|
float fac;
|
|
|
|
|
|
|
|
if (hd->falloff_type == eHook_Falloff_Const) {
|
|
|
|
fac = 1.0f;
|
|
|
|
goto finally;
|
|
|
|
}
|
|
|
|
else if (hd->falloff_type == eHook_Falloff_InvSquare) {
|
|
|
|
/* avoid sqrt below */
|
|
|
|
fac = 1.0f - (len_sq / hd->falloff_sq);
|
|
|
|
goto finally;
|
2010-10-15 08:32:27 +00:00
|
|
|
}
|
2015-02-04 07:04:21 +11:00
|
|
|
|
|
|
|
fac = 1.0f - (sqrtf(len_sq) / hd->falloff);
|
|
|
|
|
|
|
|
/* closely match PROP_SMOOTH and similar */
|
|
|
|
switch (hd->falloff_type) {
|
|
|
|
#if 0
|
|
|
|
case eHook_Falloff_None:
|
|
|
|
fac = 1.0f;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case eHook_Falloff_Curve:
|
|
|
|
fac = curvemapping_evaluateF(hd->curfalloff, 0, fac);
|
|
|
|
break;
|
|
|
|
case eHook_Falloff_Sharp:
|
|
|
|
fac = fac * fac;
|
|
|
|
break;
|
|
|
|
case eHook_Falloff_Smooth:
|
|
|
|
fac = 3.0f * fac * fac - 2.0f * fac * fac * fac;
|
|
|
|
break;
|
|
|
|
case eHook_Falloff_Root:
|
|
|
|
fac = sqrtf(fac);
|
|
|
|
break;
|
|
|
|
case eHook_Falloff_Linear:
|
|
|
|
/* pass */
|
|
|
|
break;
|
|
|
|
#if 0
|
|
|
|
case eHook_Falloff_Const:
|
|
|
|
fac = 1.0f;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case eHook_Falloff_Sphere:
|
|
|
|
fac = sqrtf(2 * fac - fac * fac);
|
|
|
|
break;
|
|
|
|
#if 0
|
|
|
|
case eHook_Falloff_InvSquare:
|
|
|
|
fac = fac * (2.0f - fac);
|
|
|
|
break;
|
|
|
|
#endif
|
2010-10-15 08:32:27 +00:00
|
|
|
}
|
2015-02-04 07:04:21 +11:00
|
|
|
|
|
|
|
finally:
|
|
|
|
return fac * hd->fac_orig;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return hd->fac_orig;
|
2010-10-15 08:32:27 +00:00
|
|
|
}
|
2015-02-04 07:04:21 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
static void hook_co_apply(struct HookData_cb *hd, const int j)
|
|
|
|
{
|
|
|
|
float *co = hd->vertexCos[j];
|
|
|
|
float fac;
|
2010-10-15 08:32:27 +00:00
|
|
|
|
2015-02-04 07:04:21 +11:00
|
|
|
if (hd->use_falloff) {
|
|
|
|
float len_sq;
|
|
|
|
|
|
|
|
if (hd->use_uniform) {
|
|
|
|
float co_uniform[3];
|
|
|
|
mul_v3_m3v3(co_uniform, hd->mat_uniform, co);
|
|
|
|
len_sq = len_squared_v3v3(hd->cent, co_uniform);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
len_sq = len_squared_v3v3(hd->cent, co);
|
|
|
|
}
|
|
|
|
|
|
|
|
fac = hook_falloff(hd, len_sq);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fac = hd->fac_orig;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fac) {
|
|
|
|
if (hd->dvert) {
|
|
|
|
fac *= defvert_find_weight(&hd->dvert[j], hd->defgrp_index);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fac) {
|
|
|
|
float co_tmp[3];
|
|
|
|
mul_v3_m4v3(co_tmp, hd->mat, co);
|
|
|
|
interp_v3_v3v3(co, co, co_tmp, fac);
|
|
|
|
}
|
|
|
|
}
|
2010-10-15 08:32:27 +00:00
|
|
|
}
|
|
|
|
|
2018-05-12 08:04:56 +02:00
|
|
|
static void deformVerts_do(
|
2018-12-07 15:45:53 +01:00
|
|
|
HookModifierData *hmd, const ModifierEvalContext *ctx,
|
|
|
|
Object *ob, Mesh *mesh,
|
2018-05-12 08:04:56 +02:00
|
|
|
float (*vertexCos)[3], int numVerts)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2018-12-07 15:45:53 +01:00
|
|
|
Object *ob_target = DEG_get_evaluated_object(ctx->depsgraph, hmd->object);
|
|
|
|
bPoseChannel *pchan = BKE_pose_channel_find_name(ob_target->pose, hmd->subtarget);
|
2015-02-04 07:04:21 +11:00
|
|
|
float dmat[4][4];
|
2010-10-15 08:32:27 +00:00
|
|
|
int i, *index_pt;
|
2015-02-04 07:04:21 +11:00
|
|
|
struct HookData_cb hd;
|
2018-06-17 17:04:27 +02:00
|
|
|
|
2015-02-04 07:04:21 +11:00
|
|
|
if (hmd->curfalloff == NULL) {
|
|
|
|
/* should never happen, but bad lib linking could cause it */
|
|
|
|
hmd->curfalloff = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hmd->curfalloff) {
|
|
|
|
curvemapping_initialize(hmd->curfalloff);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Generic data needed for applying per-vertex calculations (initialize all members) */
|
|
|
|
hd.vertexCos = vertexCos;
|
2018-06-29 19:02:19 +02:00
|
|
|
MOD_get_vgroup(ob, mesh, hmd->name, &hd.dvert, &hd.defgrp_index);
|
2015-02-04 07:04:21 +11:00
|
|
|
|
|
|
|
hd.curfalloff = hmd->curfalloff;
|
|
|
|
|
|
|
|
hd.falloff_type = hmd->falloff_type;
|
|
|
|
hd.falloff = (hmd->falloff_type == eHook_Falloff_None) ? 0.0f : hmd->falloff;
|
|
|
|
hd.falloff_sq = SQUARE(hd.falloff);
|
|
|
|
hd.fac_orig = hmd->force;
|
|
|
|
|
|
|
|
hd.use_falloff = (hd.falloff_sq != 0.0f);
|
|
|
|
hd.use_uniform = (hmd->flag & MOD_HOOK_UNIFORM_SPACE) != 0;
|
|
|
|
|
|
|
|
if (hd.use_uniform) {
|
|
|
|
copy_m3_m4(hd.mat_uniform, hmd->parentinv);
|
|
|
|
mul_v3_m3v3(hd.cent, hd.mat_uniform, hmd->cent);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
unit_m3(hd.mat_uniform); /* unused */
|
|
|
|
copy_v3_v3(hd.cent, hmd->cent);
|
|
|
|
}
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* get world-space matrix of target, corrected for the space the verts are in */
|
|
|
|
if (hmd->subtarget[0] && pchan) {
|
|
|
|
/* bone target if there's a matching pose-channel */
|
2018-12-07 15:45:53 +01:00
|
|
|
mul_m4_m4m4(dmat, ob_target->obmat, pchan->pose_mat);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* just object target */
|
2018-12-07 15:45:53 +01:00
|
|
|
copy_m4_m4(dmat, ob_target->obmat);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
invert_m4_m4(ob->imat, ob->obmat);
|
2015-02-04 07:04:21 +11:00
|
|
|
mul_m4_series(hd.mat, ob->imat, dmat, hmd->parentinv);
|
|
|
|
/* --- done with 'hd' init --- */
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2010-10-15 08:32:27 +00:00
|
|
|
|
|
|
|
/* Regarding index range checking below.
|
|
|
|
*
|
2018-05-09 12:38:52 +02:00
|
|
|
* This should always be true and I don't generally like
|
2010-10-15 08:32:27 +00:00
|
|
|
* "paranoid" style code like this, but old files can have
|
|
|
|
* indices that are out of range because old blender did
|
|
|
|
* not correct them on exit editmode. - zr
|
|
|
|
*/
|
2015-02-04 07:04:21 +11:00
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (hmd->force == 0.0f) {
|
2010-10-15 08:32:27 +00:00
|
|
|
/* do nothing, avoid annoying checks in the loop */
|
|
|
|
}
|
2012-03-24 06:24:53 +00:00
|
|
|
else if (hmd->indexar) { /* vertex indices? */
|
2010-10-15 08:32:27 +00:00
|
|
|
const int *origindex_ar;
|
2018-05-09 12:38:52 +02:00
|
|
|
|
|
|
|
/* if mesh is present and has original index data, use it */
|
|
|
|
if (mesh && (origindex_ar = CustomData_get_layer(&mesh->vdata, CD_ORIGINDEX))) {
|
2012-05-06 13:38:33 +00:00
|
|
|
for (i = 0, index_pt = hmd->indexar; i < hmd->totindex; i++, index_pt++) {
|
2012-03-24 06:24:53 +00:00
|
|
|
if (*index_pt < numVerts) {
|
2010-04-11 22:12:30 +00:00
|
|
|
int j;
|
2018-05-09 12:38:52 +02:00
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
for (j = 0; j < numVerts; j++) {
|
|
|
|
if (origindex_ar[j] == *index_pt) {
|
2015-02-04 07:04:21 +11:00
|
|
|
hook_co_apply(&hd, j);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-05-09 12:38:52 +02:00
|
|
|
else { /* missing mesh or ORIGINDEX */
|
2012-05-03 21:35:04 +00:00
|
|
|
for (i = 0, index_pt = hmd->indexar; i < hmd->totindex; i++, index_pt++) {
|
2012-03-24 06:24:53 +00:00
|
|
|
if (*index_pt < numVerts) {
|
2015-02-04 07:04:21 +11:00
|
|
|
hook_co_apply(&hd, *index_pt);
|
2010-10-15 08:32:27 +00:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
2010-10-15 08:32:27 +00:00
|
|
|
}
|
2015-02-04 07:04:21 +11:00
|
|
|
else if (hd.dvert) { /* vertex group hook */
|
|
|
|
for (i = 0; i < numVerts; i++) {
|
|
|
|
hook_co_apply(&hd, i);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-12 08:04:56 +02:00
|
|
|
static void deformVerts(
|
2018-05-12 08:21:07 +02:00
|
|
|
struct ModifierData *md, const struct ModifierEvalContext *ctx, struct Mesh *mesh,
|
|
|
|
float (*vertexCos)[3], int numVerts)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2018-05-09 12:38:52 +02:00
|
|
|
HookModifierData *hmd = (HookModifierData *)md;
|
2018-11-27 17:21:16 +01:00
|
|
|
Mesh *mesh_src = MOD_deform_mesh_eval_get(ctx->object, NULL, mesh, NULL, numVerts, false, false);
|
2011-12-15 08:57:48 +00:00
|
|
|
|
2018-12-07 15:45:53 +01:00
|
|
|
deformVerts_do(hmd, ctx, ctx->object, mesh_src, vertexCos, numVerts);
|
2018-05-09 17:37:54 +02:00
|
|
|
|
2018-11-27 20:10:41 +01:00
|
|
|
if (!ELEM(mesh_src, NULL, mesh)) {
|
2018-05-09 17:37:54 +02:00
|
|
|
BKE_id_free(NULL, mesh_src);
|
|
|
|
}
|
2011-12-08 15:50:28 +00:00
|
|
|
}
|
|
|
|
|
2018-05-12 08:04:56 +02:00
|
|
|
static void deformVertsEM(
|
2018-05-12 08:21:07 +02:00
|
|
|
struct ModifierData *md, const struct ModifierEvalContext *ctx,
|
|
|
|
struct BMEditMesh *editData,
|
|
|
|
struct Mesh *mesh, float (*vertexCos)[3], int numVerts)
|
2011-12-08 15:50:28 +00:00
|
|
|
{
|
2018-05-09 12:38:52 +02:00
|
|
|
HookModifierData *hmd = (HookModifierData *)md;
|
2018-11-27 17:21:16 +01:00
|
|
|
Mesh *mesh_src = MOD_deform_mesh_eval_get(ctx->object, editData, mesh, NULL, numVerts, false, false);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2018-12-07 15:45:53 +01:00
|
|
|
deformVerts_do(hmd, ctx, ctx->object, mesh_src, vertexCos, numVerts);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2018-11-27 20:10:41 +01:00
|
|
|
if (!ELEM(mesh_src, NULL, mesh)) {
|
2018-05-09 12:38:52 +02:00
|
|
|
BKE_id_free(NULL, mesh_src);
|
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ModifierTypeInfo modifierType_Hook = {
|
|
|
|
/* name */ "Hook",
|
|
|
|
/* structName */ "HookModifierData",
|
|
|
|
/* structSize */ sizeof(HookModifierData),
|
|
|
|
/* type */ eModifierTypeType_OnlyDeform,
|
2012-05-06 13:38:33 +00:00
|
|
|
/* flags */ eModifierTypeFlag_AcceptsCVs |
|
2016-05-18 22:21:46 +10:00
|
|
|
eModifierTypeFlag_AcceptsLattice |
|
2012-05-06 13:38:33 +00:00
|
|
|
eModifierTypeFlag_SupportsEditmode,
|
2010-04-11 22:12:30 +00:00
|
|
|
/* copyData */ copyData,
|
2018-04-18 15:45:54 +02:00
|
|
|
|
2018-05-09 12:38:52 +02:00
|
|
|
/* deformVerts_DM */ NULL,
|
2018-04-18 15:45:54 +02:00
|
|
|
/* deformMatrices_DM */ NULL,
|
2018-05-09 12:38:52 +02:00
|
|
|
/* deformVertsEM_DM */ NULL,
|
2018-04-18 15:45:54 +02:00
|
|
|
/* deformMatricesEM_DM*/NULL,
|
|
|
|
/* applyModifier_DM */ NULL,
|
|
|
|
|
2018-05-09 12:38:52 +02:00
|
|
|
/* deformVerts */ deformVerts,
|
2011-03-05 10:29:10 +00:00
|
|
|
/* deformMatrices */ NULL,
|
2018-05-09 12:38:52 +02:00
|
|
|
/* deformVertsEM */ deformVertsEM,
|
2011-03-05 10:29:10 +00:00
|
|
|
/* deformMatricesEM */ NULL,
|
|
|
|
/* applyModifier */ NULL,
|
2018-04-18 15:45:54 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* initData */ initData,
|
|
|
|
/* requiredDataMask */ requiredDataMask,
|
|
|
|
/* freeData */ freeData,
|
|
|
|
/* isDisabled */ isDisabled,
|
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
|
|
|
/* updateDepsgraph */ updateDepsgraph,
|
2011-03-05 10:29:10 +00:00
|
|
|
/* dependsOnTime */ NULL,
|
|
|
|
/* dependsOnNormals */ NULL,
|
2010-04-11 22:12:30 +00:00
|
|
|
/* foreachObjectLink */ foreachObjectLink,
|
2011-03-05 10:29:10 +00:00
|
|
|
/* foreachIDLink */ NULL,
|
2011-08-12 18:11:22 +00:00
|
|
|
/* foreachTexLink */ NULL,
|
2010-04-11 22:12:30 +00:00
|
|
|
};
|