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_cast.c
|
|
|
|
* \ingroup modifiers
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2010-04-12 22:33:43 +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 00:36:50 +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
|
|
|
|
2011-01-07 19:18:31 +00:00
|
|
|
|
2010-04-12 22:33:43 +00:00
|
|
|
#include "BKE_deform.h"
|
2010-04-12 00:36:50 +00:00
|
|
|
#include "BKE_DerivedMesh.h"
|
2015-10-08 14:21:11 +02:00
|
|
|
#include "BKE_library_query.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
#include "BKE_modifier.h"
|
2011-01-07 19:18:31 +00:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
#include "depsgraph_private.h"
|
|
|
|
|
|
|
|
#include "MOD_util.h"
|
|
|
|
|
|
|
|
static void initData(ModifierData *md)
|
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
CastModifierData *cmd = (CastModifierData *) md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
cmd->fac = 0.5f;
|
|
|
|
cmd->radius = 0.0f;
|
|
|
|
cmd->size = 0.0f;
|
2012-05-06 13:38:33 +00:00
|
|
|
cmd->flag = MOD_CAST_X | MOD_CAST_Y | MOD_CAST_Z | MOD_CAST_SIZE_FROM_RADIUS;
|
2010-04-11 22:12:30 +00:00
|
|
|
cmd->type = MOD_CAST_TYPE_SPHERE;
|
|
|
|
cmd->defgrp_name[0] = '\0';
|
|
|
|
cmd->object = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void copyData(ModifierData *md, ModifierData *target)
|
|
|
|
{
|
2013-12-22 04:35:52 +11:00
|
|
|
#if 0
|
2012-05-06 13:38:33 +00:00
|
|
|
CastModifierData *cmd = (CastModifierData *) md;
|
|
|
|
CastModifierData *tcmd = (CastModifierData *) target;
|
2013-12-22 04:35:52 +11:00
|
|
|
#endif
|
|
|
|
modifier_copyData_generic(md, target);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2013-06-02 03:59:19 +00:00
|
|
|
static bool isDisabled(ModifierData *md, int UNUSED(useRenderParams))
|
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;
|
|
|
|
|
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
|
|
|
|
2013-06-02 03:59:19 +00:00
|
|
|
if ((cmd->fac == 0.0f) || flag == 0) return true;
|
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
|
|
|
}
|
|
|
|
|
2010-10-14 06:29:17 +00:00
|
|
|
static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
|
|
|
CastModifierData *cmd = (CastModifierData *)md;
|
|
|
|
CustomDataMask dataMask = 0;
|
|
|
|
|
|
|
|
/* ask for vertexgroups if we need them */
|
2012-03-24 06:24:53 +00:00
|
|
|
if (cmd->defgrp_name[0]) dataMask |= CD_MASK_MDEFORMVERT;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
return dataMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
CastModifierData *cmd = (CastModifierData *) md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2017-01-31 09:47:59 +01:00
|
|
|
walk(userData, ob, &cmd->object, IDWALK_CB_NOP);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2010-10-14 06:29:17 +00:00
|
|
|
static void updateDepgraph(ModifierData *md, DagForest *forest,
|
2015-03-13 11:48:04 +05:00
|
|
|
struct Main *UNUSED(bmain),
|
2012-05-06 13:38:33 +00:00
|
|
|
struct Scene *UNUSED(scene),
|
|
|
|
Object *UNUSED(ob),
|
|
|
|
DagNode *obNode)
|
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
|
|
|
|
|
|
|
if (cmd->object) {
|
|
|
|
DagNode *curNode = dag_get_node(forest, cmd->object);
|
|
|
|
|
|
|
|
dag_add_relation(forest, curNode, obNode, DAG_RL_OB_DATA,
|
2012-05-06 13:38:33 +00:00
|
|
|
"Cast Modifier");
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
static void updateDepsgraph(ModifierData *md,
|
|
|
|
struct Main *UNUSED(bmain),
|
|
|
|
struct Scene *UNUSED(scene),
|
2016-12-09 13:40:12 +01:00
|
|
|
Object *object,
|
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
|
|
|
struct DepsNodeHandle *node)
|
|
|
|
{
|
|
|
|
CastModifierData *cmd = (CastModifierData *)md;
|
|
|
|
if (cmd->object != NULL) {
|
|
|
|
DEG_add_object_relation(node, cmd->object, DEG_OB_COMP_TRANSFORM, "Cast Modifier");
|
2016-12-09 13:40:12 +01:00
|
|
|
DEG_add_object_relation(node, object, DEG_OB_COMP_TRANSFORM, "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(
|
2012-08-23 16:17:47 +00:00
|
|
|
CastModifierData *cmd, Object *ob, DerivedMesh *dm,
|
|
|
|
float (*vertexCos)[3], int numVerts)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
|
|
|
MDeformVert *dvert = NULL;
|
|
|
|
|
|
|
|
Object *ctrl_ob = NULL;
|
|
|
|
|
|
|
|
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];
|
|
|
|
|
|
|
|
flag = cmd->flag;
|
|
|
|
type = cmd->type; /* projection type: sphere or cylinder */
|
|
|
|
|
|
|
|
if (type == MOD_CAST_TYPE_CYLINDER)
|
|
|
|
flag &= ~MOD_CAST_Z;
|
|
|
|
|
|
|
|
ctrl_ob = cmd->object;
|
|
|
|
|
|
|
|
/* spherify's center is {0, 0, 0} (the ob's own center in its local
|
2012-03-09 18:28:30 +00:00
|
|
|
* 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) {
|
2014-08-25 20:58:36 +02:00
|
|
|
invert_m4_m4(imat, ctrl_ob->obmat);
|
|
|
|
mul_m4_m4m4(mat, imat, ob->obmat);
|
2010-04-11 22:12:30 +00:00
|
|
|
invert_m4_m4(imat, mat);
|
|
|
|
}
|
|
|
|
|
|
|
|
invert_m4_m4(ob->imat, ob->obmat);
|
2010-04-12 00:36:50 +00:00
|
|
|
mul_v3_m4v3(center, ob->imat, ctrl_ob->obmat[3]);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* now we check which options the user wants */
|
|
|
|
|
|
|
|
/* 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 */
|
2010-04-11 22:12:30 +00:00
|
|
|
if (cmd->radius > FLT_EPSILON) has_radius = 1;
|
|
|
|
|
|
|
|
/* 3) if we were given a vertex group name,
|
2012-03-09 18:28:30 +00:00
|
|
|
* only those vertices should be affected */
|
2011-07-11 09:15:20 +00:00
|
|
|
modifier_get_vgroup(ob, dm, cmd->defgrp_name, &dvert, &defgrp_index);
|
2010-04-11 22:12:30 +00: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;
|
|
|
|
}
|
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (len <= 0) {
|
2010-04-11 22:12:30 +00:00
|
|
|
for (i = 0; i < numVerts; i++) {
|
|
|
|
len += len_v3v3(center, vertexCos[i]);
|
|
|
|
}
|
|
|
|
len /= numVerts;
|
|
|
|
|
|
|
|
if (len == 0.0f) len = 10.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < numVerts; i++) {
|
|
|
|
float tmp_co[3];
|
|
|
|
|
2010-04-12 00:36:50 +00:00
|
|
|
copy_v3_v3(tmp_co, vertexCos[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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-12 00:36:50 +00:00
|
|
|
copy_v3_v3(vec, tmp_co);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
if (type == MOD_CAST_TYPE_CYLINDER)
|
|
|
|
vec[2] = 0.0f;
|
|
|
|
|
|
|
|
if (has_radius) {
|
|
|
|
if (len_v3(vec) > cmd->radius) continue;
|
|
|
|
}
|
|
|
|
|
2013-03-03 05:43:47 +00:00
|
|
|
if (dvert) {
|
|
|
|
const float weight = defvert_find_weight(&dvert[i], defgrp_index);
|
|
|
|
if (weight == 0.0f) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
fac = fac_orig * weight;
|
|
|
|
facm = 1.0f - fac;
|
|
|
|
}
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
normalize_v3(vec);
|
|
|
|
|
|
|
|
if (flag & MOD_CAST_X)
|
2012-05-06 13:38:33 +00:00
|
|
|
tmp_co[0] = fac * vec[0] * len + facm * tmp_co[0];
|
2010-04-11 22:12:30 +00: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];
|
2010-04-11 22:12:30 +00: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];
|
2010-04-11 22:12:30 +00: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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-12 00:36:50 +00:00
|
|
|
copy_v3_v3(vertexCos[i], tmp_co);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cuboid_do(
|
2012-08-23 16:17:47 +00:00
|
|
|
CastModifierData *cmd, Object *ob, DerivedMesh *dm,
|
|
|
|
float (*vertexCos)[3], int numVerts)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
|
|
|
MDeformVert *dvert = NULL;
|
|
|
|
Object *ctrl_ob = NULL;
|
|
|
|
|
|
|
|
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;
|
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];
|
|
|
|
|
|
|
|
flag = cmd->flag;
|
|
|
|
|
|
|
|
ctrl_ob = cmd->object;
|
|
|
|
|
|
|
|
/* now we check which options the user wants */
|
|
|
|
|
|
|
|
/* 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 */
|
2010-04-11 22:12:30 +00:00
|
|
|
if (cmd->radius > FLT_EPSILON) has_radius = 1;
|
|
|
|
|
|
|
|
/* 3) if we were given a vertex group name,
|
2012-03-09 18:28:30 +00:00
|
|
|
* only those vertices should be affected */
|
2011-07-11 09:15:20 +00:00
|
|
|
modifier_get_vgroup(ob, dm, cmd->defgrp_name, &dvert, &defgrp_index);
|
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) {
|
2014-08-25 20:58:36 +02:00
|
|
|
invert_m4_m4(imat, ctrl_ob->obmat);
|
|
|
|
mul_m4_m4m4(mat, imat, ob->obmat);
|
2010-04-11 22:12:30 +00:00
|
|
|
invert_m4_m4(imat, mat);
|
|
|
|
}
|
|
|
|
|
|
|
|
invert_m4_m4(ob->imat, ob->obmat);
|
2010-04-12 00:36:50 +00:00
|
|
|
mul_v3_m4v3(center, ob->imat, ctrl_ob->obmat[3]);
|
2010-04-11 22:12:30 +00: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);
|
|
|
|
|
|
|
|
/* 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];
|
|
|
|
|
|
|
|
/* 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);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
for (i = 0; i < numVerts; i++) {
|
|
|
|
sub_v3_v3v3(vec, vertexCos[i], center);
|
2012-05-13 11:05:52 +00:00
|
|
|
minmax_v3v3_v3(min, max, vec);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (i = 0; i < numVerts; i++) {
|
2012-05-13 11:05:52 +00:00
|
|
|
minmax_v3v3_v3(min, max, vertexCos[i]);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we want a symmetric bound box around the origin */
|
2012-07-21 15:27:40 +00:00
|
|
|
if (fabsf(min[0]) > fabsf(max[0])) max[0] = fabsf(min[0]);
|
|
|
|
if (fabsf(min[1]) > fabsf(max[1])) max[1] = fabsf(min[1]);
|
|
|
|
if (fabsf(min[2]) > fabsf(max[2])) max[2] = fabsf(min[2]);
|
2010-04-11 22:12:30 +00:00
|
|
|
min[0] = -max[0];
|
|
|
|
min[1] = -max[1];
|
|
|
|
min[2] = -max[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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];
|
|
|
|
|
2013-03-03 05:43:47 +00:00
|
|
|
/* ready to apply the effect, one vertex at a time */
|
2010-04-11 22:12:30 +00:00
|
|
|
for (i = 0; i < numVerts; i++) {
|
|
|
|
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];
|
|
|
|
|
2010-04-12 00:36:50 +00:00
|
|
|
copy_v3_v3(tmp_co, vertexCos[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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (has_radius) {
|
2011-03-27 13:49:53 +00:00
|
|
|
if (fabsf(tmp_co[0]) > cmd->radius ||
|
2012-04-28 06:31:57 +00:00
|
|
|
fabsf(tmp_co[1]) > cmd->radius ||
|
|
|
|
fabsf(tmp_co[2]) > cmd->radius)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2013-03-03 05:43:47 +00:00
|
|
|
if (dvert) {
|
|
|
|
const float weight = defvert_find_weight(&dvert[i], defgrp_index);
|
|
|
|
if (weight == 0.0f) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
fac = fac_orig * weight;
|
|
|
|
facm = 1.0f - fac;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The algo used to project the vertices to their
|
|
|
|
* 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. */
|
|
|
|
|
|
|
|
/* find in which octant this vertex is in */
|
2010-04-11 22:12:30 +00:00
|
|
|
octant = 0;
|
|
|
|
if (tmp_co[0] > 0.0f) octant += 1;
|
|
|
|
if (tmp_co[1] > 0.0f) octant += 2;
|
|
|
|
if (tmp_co[2] > 0.0f) octant += 4;
|
|
|
|
|
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]);
|
|
|
|
|
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];
|
|
|
|
|
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) {
|
|
|
|
/* dmax = d[2]; */ /* commented, we don't need it */
|
|
|
|
coord = 2;
|
|
|
|
}
|
|
|
|
|
2013-03-03 05:43:47 +00:00
|
|
|
/* ok, now we know which coordinate of the vertex to use */
|
|
|
|
|
|
|
|
if (fabsf(tmp_co[coord]) < FLT_EPSILON) /* avoid division by zero */
|
2010-04-11 22:12:30 +00:00
|
|
|
continue;
|
|
|
|
|
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];
|
|
|
|
|
2013-03-03 05:43:47 +00:00
|
|
|
/* calculate the new vertex position */
|
2010-04-11 22:12:30 +00:00
|
|
|
if (flag & MOD_CAST_X)
|
|
|
|
tmp_co[0] = facm * tmp_co[0] + fac * tmp_co[0] * fbb;
|
|
|
|
if (flag & MOD_CAST_Y)
|
|
|
|
tmp_co[1] = facm * tmp_co[1] + fac * tmp_co[1] * fbb;
|
|
|
|
if (flag & MOD_CAST_Z)
|
|
|
|
tmp_co[2] = facm * tmp_co[2] + fac * tmp_co[2] * fbb;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-12 00:36:50 +00:00
|
|
|
copy_v3_v3(vertexCos[i], tmp_co);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-14 06:29:17 +00:00
|
|
|
static void deformVerts(ModifierData *md, Object *ob,
|
2012-05-06 13:38:33 +00:00
|
|
|
DerivedMesh *derivedData,
|
|
|
|
float (*vertexCos)[3],
|
|
|
|
int numVerts,
|
2012-05-09 15:00:26 +00:00
|
|
|
ModifierApplyFlag UNUSED(flag))
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
|
|
|
DerivedMesh *dm = NULL;
|
|
|
|
CastModifierData *cmd = (CastModifierData *)md;
|
|
|
|
|
2013-07-16 08:24:53 +00:00
|
|
|
dm = get_dm(ob, NULL, derivedData, NULL, false, false);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
if (cmd->type == MOD_CAST_TYPE_CUBOID) {
|
|
|
|
cuboid_do(cmd, ob, dm, vertexCos, numVerts);
|
2012-03-24 06:24:53 +00:00
|
|
|
}
|
|
|
|
else { /* MOD_CAST_TYPE_SPHERE or MOD_CAST_TYPE_CYLINDER */
|
2010-04-11 22:12:30 +00:00
|
|
|
sphere_do(cmd, ob, dm, vertexCos, numVerts);
|
|
|
|
}
|
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (dm != derivedData)
|
2010-04-11 22:12:30 +00:00
|
|
|
dm->release(dm);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void deformVertsEM(
|
2012-08-23 16:17:47 +00:00
|
|
|
ModifierData *md, Object *ob, struct BMEditMesh *editData,
|
|
|
|
DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2013-07-16 08:24:53 +00:00
|
|
|
DerivedMesh *dm = get_dm(ob, editData, derivedData, NULL, false, false);
|
2010-04-11 22:12:30 +00:00
|
|
|
CastModifierData *cmd = (CastModifierData *)md;
|
|
|
|
|
|
|
|
if (cmd->type == MOD_CAST_TYPE_CUBOID) {
|
|
|
|
cuboid_do(cmd, ob, dm, vertexCos, numVerts);
|
2012-03-24 06:24:53 +00:00
|
|
|
}
|
|
|
|
else { /* MOD_CAST_TYPE_SPHERE or MOD_CAST_TYPE_CYLINDER */
|
2010-04-11 22:12:30 +00:00
|
|
|
sphere_do(cmd, ob, dm, vertexCos, numVerts);
|
|
|
|
}
|
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (dm != derivedData)
|
2010-04-11 22:12:30 +00:00
|
|
|
dm->release(dm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ModifierTypeInfo modifierType_Cast = {
|
|
|
|
/* name */ "Cast",
|
|
|
|
/* structName */ "CastModifierData",
|
|
|
|
/* structSize */ sizeof(CastModifierData),
|
|
|
|
/* 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,
|
|
|
|
/* deformVerts */ deformVerts,
|
2011-03-05 10:29:10 +00:00
|
|
|
/* deformMatrices */ NULL,
|
2010-04-11 22:12:30 +00:00
|
|
|
/* deformVertsEM */ deformVertsEM,
|
2011-03-05 10:29:10 +00:00
|
|
|
/* deformMatricesEM */ NULL,
|
|
|
|
/* applyModifier */ NULL,
|
|
|
|
/* applyModifierEM */ NULL,
|
2010-04-11 22:12:30 +00:00
|
|
|
/* initData */ initData,
|
|
|
|
/* requiredDataMask */ requiredDataMask,
|
2011-03-05 10:29:10 +00:00
|
|
|
/* freeData */ NULL,
|
2010-04-11 22:12:30 +00:00
|
|
|
/* isDisabled */ isDisabled,
|
|
|
|
/* updateDepgraph */ updateDepgraph,
|
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
|
|
|
};
|