2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-01-07 19:13:47 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
|
* 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
|
2008-01-07 19:13:47 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
|
* 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,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
|
*
|
2008-01-07 19:13:47 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
|
|
|
|
|
2011-02-27 20:40:57 +00:00
|
|
|
/** \file blender/blenkernel/intern/lattice.c
|
|
|
|
|
* \ingroup bke
|
|
|
|
|
*/
|
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <math.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2013-12-09 15:32:05 +11:00
|
|
|
#include "BLI_listbase.h"
|
|
|
|
|
#include "BLI_bitmap.h"
|
|
|
|
|
#include "BLI_math.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
#include "DNA_mesh_types.h"
|
2004-03-20 22:55:42 +00:00
|
|
|
#include "DNA_meshdata_types.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "DNA_scene_types.h"
|
2010-08-04 04:01:27 +00:00
|
|
|
#include "DNA_object_types.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "DNA_lattice_types.h"
|
|
|
|
|
#include "DNA_curve_types.h"
|
|
|
|
|
#include "DNA_key_types.h"
|
|
|
|
|
|
2010-12-13 06:31:49 +00:00
|
|
|
#include "BKE_animsys.h"
|
2004-09-14 19:03:11 +00:00
|
|
|
#include "BKE_anim.h"
|
2006-08-28 01:12:36 +00:00
|
|
|
#include "BKE_cdderivedmesh.h"
|
2013-08-19 09:25:24 +00:00
|
|
|
#include "BKE_curve.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "BKE_displist.h"
|
|
|
|
|
#include "BKE_key.h"
|
2004-09-14 19:03:11 +00:00
|
|
|
#include "BKE_lattice.h"
|
|
|
|
|
#include "BKE_library.h"
|
2016-07-09 15:38:02 +02:00
|
|
|
#include "BKE_library_query.h"
|
|
|
|
|
#include "BKE_library_remap.h"
|
2004-09-14 19:03:11 +00:00
|
|
|
#include "BKE_main.h"
|
2005-08-15 10:30:53 +00:00
|
|
|
#include "BKE_modifier.h"
|
2015-08-13 18:12:08 +02:00
|
|
|
#include "BKE_object.h"
|
2011-01-07 19:18:31 +00:00
|
|
|
|
2010-04-20 21:38:55 +00:00
|
|
|
#include "BKE_deform.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2013-12-09 15:32:05 +11:00
|
|
|
int BKE_lattice_index_from_uvw(Lattice *lt,
|
2013-06-24 13:45:35 +00:00
|
|
|
const int u, const int v, const int w)
|
|
|
|
|
{
|
2013-06-28 21:24:38 +00:00
|
|
|
const int totu = lt->pntsu;
|
|
|
|
|
const int totv = lt->pntsv;
|
|
|
|
|
|
|
|
|
|
return (w * (totu * totv) + (v * totu) + u);
|
2013-06-24 13:45:35 +00:00
|
|
|
}
|
|
|
|
|
|
2013-12-09 15:32:05 +11:00
|
|
|
void BKE_lattice_index_to_uvw(Lattice *lt, const int index,
|
2013-06-24 13:45:35 +00:00
|
|
|
int *r_u, int *r_v, int *r_w)
|
|
|
|
|
{
|
2013-06-28 21:24:38 +00:00
|
|
|
const int totu = lt->pntsu;
|
|
|
|
|
const int totv = lt->pntsv;
|
|
|
|
|
|
|
|
|
|
*r_u = (index % totu);
|
|
|
|
|
*r_v = (index / totu) % totv;
|
|
|
|
|
*r_w = (index / (totu * totv));
|
2013-06-24 13:45:35 +00:00
|
|
|
}
|
2005-07-21 21:19:38 +00:00
|
|
|
|
2013-12-09 15:32:05 +11:00
|
|
|
int BKE_lattice_index_flip(Lattice *lt, const int index,
|
|
|
|
|
const bool flip_u, const bool flip_v, const bool flip_w)
|
|
|
|
|
{
|
|
|
|
|
int u, v, w;
|
|
|
|
|
|
|
|
|
|
BKE_lattice_index_to_uvw(lt, index, &u, &v, &w);
|
|
|
|
|
|
|
|
|
|
if (flip_u) {
|
|
|
|
|
u = (lt->pntsu - 1) - u;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (flip_v) {
|
|
|
|
|
v = (lt->pntsv - 1) - v;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (flip_w) {
|
|
|
|
|
w = (lt->pntsw - 1) - w;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return BKE_lattice_index_from_uvw(lt, u, v, w);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_lattice_bitmap_from_flag(Lattice *lt, BLI_bitmap *bitmap, const short flag,
|
|
|
|
|
const bool clear, const bool respecthide)
|
|
|
|
|
{
|
|
|
|
|
const unsigned int tot = lt->pntsu * lt->pntsv * lt->pntsw;
|
|
|
|
|
unsigned int i;
|
|
|
|
|
BPoint *bp;
|
|
|
|
|
|
|
|
|
|
bp = lt->def;
|
|
|
|
|
for (i = 0; i < tot; i++, bp++) {
|
|
|
|
|
if ((bp->f1 & flag) && (!respecthide || !bp->hide)) {
|
2014-06-06 16:05:15 +10:00
|
|
|
BLI_BITMAP_ENABLE(bitmap, i);
|
2013-12-09 15:32:05 +11:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (clear) {
|
2014-06-06 16:05:15 +10:00
|
|
|
BLI_BITMAP_DISABLE(bitmap, i);
|
2013-12-09 15:32:05 +11:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-15 09:11:17 +00:00
|
|
|
void calc_lat_fudu(int flag, int res, float *r_fu, float *r_du)
|
2005-08-15 10:30:53 +00:00
|
|
|
{
|
2012-05-06 15:15:33 +00:00
|
|
|
if (res == 1) {
|
2012-10-15 09:11:17 +00:00
|
|
|
*r_fu = 0.0;
|
|
|
|
|
*r_du = 0.0;
|
2005-08-15 10:30:53 +00:00
|
|
|
}
|
2012-02-23 02:17:50 +00:00
|
|
|
else if (flag & LT_GRID) {
|
2012-10-15 09:11:17 +00:00
|
|
|
*r_fu = -0.5f * (res - 1);
|
|
|
|
|
*r_du = 1.0f;
|
2005-08-15 10:30:53 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-10-15 09:11:17 +00:00
|
|
|
*r_fu = -1.0f;
|
|
|
|
|
*r_du = 2.0f / (res - 1);
|
2005-08-15 10:30:53 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-05 16:03:57 +00:00
|
|
|
void BKE_lattice_resize(Lattice *lt, int uNew, int vNew, int wNew, Object *ltOb)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
|
BPoint *bp;
|
2005-08-15 10:30:53 +00:00
|
|
|
int i, u, v, w;
|
2012-05-06 15:15:33 +00:00
|
|
|
float fu, fv, fw, uc, vc, wc, du = 0.0, dv = 0.0, dw = 0.0;
|
2005-08-15 10:30:53 +00:00
|
|
|
float *co, (*vertexCos)[3] = NULL;
|
|
|
|
|
|
2006-09-03 12:16:14 +00:00
|
|
|
/* vertex weight groups are just freed all for now */
|
2012-02-23 02:17:50 +00:00
|
|
|
if (lt->dvert) {
|
2012-12-28 09:06:48 +00:00
|
|
|
BKE_defvert_array_free(lt->dvert, lt->pntsu * lt->pntsv * lt->pntsw);
|
2012-05-06 15:15:33 +00:00
|
|
|
lt->dvert = NULL;
|
2006-09-03 12:16:14 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
while (uNew * vNew * wNew > 32000) {
|
|
|
|
|
if (uNew >= vNew && uNew >= wNew) uNew--;
|
|
|
|
|
else if (vNew >= uNew && vNew >= wNew) vNew--;
|
2005-08-15 10:30:53 +00:00
|
|
|
else wNew--;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
vertexCos = MEM_mallocN(sizeof(*vertexCos) * uNew * vNew * wNew, "tmp_vcos");
|
2005-08-15 10:30:53 +00:00
|
|
|
|
|
|
|
|
calc_lat_fudu(lt->flag, uNew, &fu, &du);
|
|
|
|
|
calc_lat_fudu(lt->flag, vNew, &fv, &dv);
|
|
|
|
|
calc_lat_fudu(lt->flag, wNew, &fw, &dw);
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
/* If old size is different then resolution changed in interface,
|
|
|
|
|
* try to do clever reinit of points. Pretty simply idea, we just
|
|
|
|
|
* deform new verts by old lattice, but scaling them to match old
|
|
|
|
|
* size first.
|
|
|
|
|
*/
|
2005-08-15 10:30:53 +00:00
|
|
|
if (ltOb) {
|
2012-05-06 15:15:33 +00:00
|
|
|
if (uNew != 1 && lt->pntsu != 1) {
|
2005-08-15 10:30:53 +00:00
|
|
|
fu = lt->fu;
|
2012-05-06 15:15:33 +00:00
|
|
|
du = (lt->pntsu - 1) * lt->du / (uNew - 1);
|
2005-08-15 10:30:53 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (vNew != 1 && lt->pntsv != 1) {
|
2005-08-15 10:30:53 +00:00
|
|
|
fv = lt->fv;
|
2012-05-06 15:15:33 +00:00
|
|
|
dv = (lt->pntsv - 1) * lt->dv / (vNew - 1);
|
2005-08-15 10:30:53 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (wNew != 1 && lt->pntsw != 1) {
|
2005-08-15 10:30:53 +00:00
|
|
|
fw = lt->fw;
|
2012-05-06 15:15:33 +00:00
|
|
|
dw = (lt->pntsw - 1) * lt->dw / (wNew - 1);
|
2005-08-15 10:30:53 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
co = vertexCos[0];
|
2012-05-06 15:15:33 +00:00
|
|
|
for (w = 0, wc = fw; w < wNew; w++, wc += dw) {
|
|
|
|
|
for (v = 0, vc = fv; v < vNew; v++, vc += dv) {
|
|
|
|
|
for (u = 0, uc = fu; u < uNew; u++, co += 3, uc += du) {
|
2005-08-15 10:30:53 +00:00
|
|
|
co[0] = uc;
|
|
|
|
|
co[1] = vc;
|
|
|
|
|
co[2] = wc;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2005-08-15 10:30:53 +00:00
|
|
|
if (ltOb) {
|
|
|
|
|
float mat[4][4];
|
|
|
|
|
int typeu = lt->typeu, typev = lt->typev, typew = lt->typew;
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
/* works best if we force to linear type (endpoints match) */
|
2005-08-15 10:30:53 +00:00
|
|
|
lt->typeu = lt->typev = lt->typew = KEY_LINEAR;
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
/* prevent using deformed locations */
|
2013-08-19 09:25:24 +00:00
|
|
|
BKE_displist_free(<Ob->curve_cache->disp);
|
2005-08-15 10:30:53 +00:00
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
copy_m4_m4(mat, ltOb->obmat);
|
|
|
|
|
unit_m4(ltOb->obmat);
|
2012-05-06 15:15:33 +00:00
|
|
|
lattice_deform_verts(ltOb, NULL, NULL, vertexCos, uNew * vNew * wNew, NULL, 1.0f);
|
2009-11-10 20:43:45 +00:00
|
|
|
copy_m4_m4(ltOb->obmat, mat);
|
2005-08-15 10:30:53 +00:00
|
|
|
|
|
|
|
|
lt->typeu = typeu;
|
|
|
|
|
lt->typev = typev;
|
|
|
|
|
lt->typew = typew;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lt->fu = fu;
|
|
|
|
|
lt->fv = fv;
|
|
|
|
|
lt->fw = fw;
|
|
|
|
|
lt->du = du;
|
|
|
|
|
lt->dv = dv;
|
|
|
|
|
lt->dw = dw;
|
|
|
|
|
|
|
|
|
|
lt->pntsu = uNew;
|
|
|
|
|
lt->pntsv = vNew;
|
|
|
|
|
lt->pntsw = wNew;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2013-06-09 20:28:08 +00:00
|
|
|
lt->actbp = LT_ACTBP_NONE;
|
2002-10-12 11:37:38 +00:00
|
|
|
MEM_freeN(lt->def);
|
2012-05-06 15:15:33 +00:00
|
|
|
lt->def = MEM_callocN(lt->pntsu * lt->pntsv * lt->pntsw * sizeof(BPoint), "lattice bp");
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
bp = lt->def;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (i = 0; i < lt->pntsu * lt->pntsv * lt->pntsw; i++, bp++) {
|
2010-08-06 05:19:00 +00:00
|
|
|
copy_v3_v3(bp->vec, vertexCos[i]);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2005-08-15 10:30:53 +00:00
|
|
|
|
|
|
|
|
MEM_freeN(vertexCos);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
First step to handle missing libs/datablocks when reading a file.
Idea is, instead of ignoring completely missing linked datablocks, to
create void placeholders for them.
That way, you can work on your file, save it, and find again your missing data once
lib becomes available again. Or you can edit missing lib's path (in Outliner),
save and reload the file, and you are done.
Also, Outliner now shows broken libraries (and placeholders) with a 'broken lib' icon.
Future plans are also to be able to relocate missing libs and reload them at runtime.
Code notes:
- Placeholder ID is just a regular datablock of same type as expected linked one,
with 'default' data, and a LIB_MISSING bitflag set.
- To allow creation of such datablocks, creation of datablocks in BKE was split in two step:
+ Allocation of memory itself.
+ Setting of all internal data to default values.
See also the design task (T43351).
Reviewed by @campbellbarton, thanks a bunch!
Differential Revision: https://developer.blender.org/D1394
2015-10-20 14:44:57 +02:00
|
|
|
void BKE_lattice_init(Lattice *lt)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
First step to handle missing libs/datablocks when reading a file.
Idea is, instead of ignoring completely missing linked datablocks, to
create void placeholders for them.
That way, you can work on your file, save it, and find again your missing data once
lib becomes available again. Or you can edit missing lib's path (in Outliner),
save and reload the file, and you are done.
Also, Outliner now shows broken libraries (and placeholders) with a 'broken lib' icon.
Future plans are also to be able to relocate missing libs and reload them at runtime.
Code notes:
- Placeholder ID is just a regular datablock of same type as expected linked one,
with 'default' data, and a LIB_MISSING bitflag set.
- To allow creation of such datablocks, creation of datablocks in BKE was split in two step:
+ Allocation of memory itself.
+ Setting of all internal data to default values.
See also the design task (T43351).
Reviewed by @campbellbarton, thanks a bunch!
Differential Revision: https://developer.blender.org/D1394
2015-10-20 14:44:57 +02:00
|
|
|
BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(lt, id));
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
lt->flag = LT_GRID;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
lt->typeu = lt->typev = lt->typew = KEY_BSPLINE;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
lt->def = MEM_callocN(sizeof(BPoint), "lattvert"); /* temporary */
|
|
|
|
|
BKE_lattice_resize(lt, 2, 2, 2, NULL); /* creates a uniform lattice */
|
2013-06-09 20:28:08 +00:00
|
|
|
lt->actbp = LT_ACTBP_NONE;
|
First step to handle missing libs/datablocks when reading a file.
Idea is, instead of ignoring completely missing linked datablocks, to
create void placeholders for them.
That way, you can work on your file, save it, and find again your missing data once
lib becomes available again. Or you can edit missing lib's path (in Outliner),
save and reload the file, and you are done.
Also, Outliner now shows broken libraries (and placeholders) with a 'broken lib' icon.
Future plans are also to be able to relocate missing libs and reload them at runtime.
Code notes:
- Placeholder ID is just a regular datablock of same type as expected linked one,
with 'default' data, and a LIB_MISSING bitflag set.
- To allow creation of such datablocks, creation of datablocks in BKE was split in two step:
+ Allocation of memory itself.
+ Setting of all internal data to default values.
See also the design task (T43351).
Reviewed by @campbellbarton, thanks a bunch!
Differential Revision: https://developer.blender.org/D1394
2015-10-20 14:44:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Lattice *BKE_lattice_add(Main *bmain, const char *name)
|
|
|
|
|
{
|
|
|
|
|
Lattice *lt;
|
|
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
lt = BKE_libblock_alloc(bmain, ID_LT, name, 0);
|
First step to handle missing libs/datablocks when reading a file.
Idea is, instead of ignoring completely missing linked datablocks, to
create void placeholders for them.
That way, you can work on your file, save it, and find again your missing data once
lib becomes available again. Or you can edit missing lib's path (in Outliner),
save and reload the file, and you are done.
Also, Outliner now shows broken libraries (and placeholders) with a 'broken lib' icon.
Future plans are also to be able to relocate missing libs and reload them at runtime.
Code notes:
- Placeholder ID is just a regular datablock of same type as expected linked one,
with 'default' data, and a LIB_MISSING bitflag set.
- To allow creation of such datablocks, creation of datablocks in BKE was split in two step:
+ Allocation of memory itself.
+ Setting of all internal data to default values.
See also the design task (T43351).
Reviewed by @campbellbarton, thanks a bunch!
Differential Revision: https://developer.blender.org/D1394
2015-10-20 14:44:57 +02:00
|
|
|
|
|
|
|
|
BKE_lattice_init(lt);
|
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
return lt;
|
|
|
|
|
}
|
|
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
/**
|
|
|
|
|
* Only copy internal data of Lattice ID from source to already allocated/initialized destination.
|
|
|
|
|
* You probably nerver want to use that directly, use id_copy or BKE_id_copy_ex for typical needs.
|
|
|
|
|
*
|
|
|
|
|
* WARNING! This function will not handle ID user count!
|
|
|
|
|
*
|
|
|
|
|
* \param flag Copying options (see BKE_library.h's LIB_ID_COPY_... flags for more).
|
|
|
|
|
*/
|
|
|
|
|
void BKE_lattice_copy_data(Main *bmain, Lattice *lt_dst, const Lattice *lt_src, const int flag)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
lt_dst->def = MEM_dupallocN(lt_src->def);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
if (lt_src->key) {
|
|
|
|
|
BKE_id_copy_ex(bmain, <_src->key->id, (ID **)<_dst->key, flag, false);
|
2006-09-03 12:16:14 +00:00
|
|
|
}
|
2011-04-21 09:38:09 +00:00
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
if (lt_src->dvert) {
|
|
|
|
|
int tot = lt_src->pntsu * lt_src->pntsv * lt_src->pntsw;
|
|
|
|
|
lt_dst->dvert = MEM_mallocN(sizeof(MDeformVert) * tot, "Lattice MDeformVert");
|
|
|
|
|
BKE_defvert_array_copy(lt_dst->dvert, lt_src->dvert, tot);
|
|
|
|
|
}
|
2011-04-21 09:38:09 +00:00
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
lt_dst->editlatt = NULL;
|
|
|
|
|
}
|
2015-01-09 09:52:51 +01:00
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
Lattice *BKE_lattice_copy(Main *bmain, const Lattice *lt)
|
|
|
|
|
{
|
|
|
|
|
Lattice *lt_copy;
|
|
|
|
|
BKE_id_copy_ex(bmain, <->id, (ID **)<_copy, 0, false);
|
|
|
|
|
return lt_copy;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
/** Free (or release) any data used by this lattice (does not free the lattice itself). */
|
2012-05-05 14:03:12 +00:00
|
|
|
void BKE_lattice_free(Lattice *lt)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
ID-Remap - Step one: core work (cleanup and rework of generic ID datablock handling).
This commit changes a lot of how IDs are handled internally, especially the unlinking/freeing
processes. So far, this was very fuzy, to summarize cleanly deleting or replacing a datablock
was pretty much impossible, except for a few special cases.
Also, unlinking was handled by each datatype, in a rather messy and prone-to-errors way (quite
a few ID usages were missed or wrongly handled that way).
One of the main goal of id-remap branch was to cleanup this, and fatorize ID links handling
by using library_query utils to allow generic handling of those, which is now the case
(now, generic ID links handling is only "knwon" from readfile.c and library_query.c).
This commit also adds backends to allow live replacement and deletion of datablocks in Blender
(so-called 'remapping' process, where we replace all usages of a given ID pointer by a new one,
or NULL one in case of unlinking).
This will allow nice new features, like ability to easily reload or relocate libraries, real immediate
deletion of datablocks in blender, replacement of one datablock by another, etc.
Some of those are for next commits.
A word of warning: this commit is highly risky, because it affects potentially a lot in Blender core.
Though it was tested rather deeply, being totally impossible to check all possible ID usage cases,
it's likely there are some remaining issues and bugs in new code... Please report them! ;)
Review task: D2027 (https://developer.blender.org/D2027).
Reviewed by campbellbarton, thanks a bunch.
2016-06-22 17:29:38 +02:00
|
|
|
BKE_animdata_free(<->id, false);
|
|
|
|
|
|
2017-04-13 22:09:59 +10:00
|
|
|
BKE_lattice_batch_cache_free(lt);
|
|
|
|
|
|
ID-Remap - Step one: core work (cleanup and rework of generic ID datablock handling).
This commit changes a lot of how IDs are handled internally, especially the unlinking/freeing
processes. So far, this was very fuzy, to summarize cleanly deleting or replacing a datablock
was pretty much impossible, except for a few special cases.
Also, unlinking was handled by each datatype, in a rather messy and prone-to-errors way (quite
a few ID usages were missed or wrongly handled that way).
One of the main goal of id-remap branch was to cleanup this, and fatorize ID links handling
by using library_query utils to allow generic handling of those, which is now the case
(now, generic ID links handling is only "knwon" from readfile.c and library_query.c).
This commit also adds backends to allow live replacement and deletion of datablocks in Blender
(so-called 'remapping' process, where we replace all usages of a given ID pointer by a new one,
or NULL one in case of unlinking).
This will allow nice new features, like ability to easily reload or relocate libraries, real immediate
deletion of datablocks in blender, replacement of one datablock by another, etc.
Some of those are for next commits.
A word of warning: this commit is highly risky, because it affects potentially a lot in Blender core.
Though it was tested rather deeply, being totally impossible to check all possible ID usage cases,
it's likely there are some remaining issues and bugs in new code... Please report them! ;)
Review task: D2027 (https://developer.blender.org/D2027).
Reviewed by campbellbarton, thanks a bunch.
2016-06-22 17:29:38 +02:00
|
|
|
MEM_SAFE_FREE(lt->def);
|
|
|
|
|
if (lt->dvert) {
|
|
|
|
|
BKE_defvert_array_free(lt->dvert, lt->pntsu * lt->pntsv * lt->pntsw);
|
|
|
|
|
lt->dvert = NULL;
|
|
|
|
|
}
|
2012-02-23 02:17:50 +00:00
|
|
|
if (lt->editlatt) {
|
2012-05-06 15:15:33 +00:00
|
|
|
Lattice *editlt = lt->editlatt->latt;
|
2010-08-10 06:36:42 +00:00
|
|
|
|
ID-Remap - Step one: core work (cleanup and rework of generic ID datablock handling).
This commit changes a lot of how IDs are handled internally, especially the unlinking/freeing
processes. So far, this was very fuzy, to summarize cleanly deleting or replacing a datablock
was pretty much impossible, except for a few special cases.
Also, unlinking was handled by each datatype, in a rather messy and prone-to-errors way (quite
a few ID usages were missed or wrongly handled that way).
One of the main goal of id-remap branch was to cleanup this, and fatorize ID links handling
by using library_query utils to allow generic handling of those, which is now the case
(now, generic ID links handling is only "knwon" from readfile.c and library_query.c).
This commit also adds backends to allow live replacement and deletion of datablocks in Blender
(so-called 'remapping' process, where we replace all usages of a given ID pointer by a new one,
or NULL one in case of unlinking).
This will allow nice new features, like ability to easily reload or relocate libraries, real immediate
deletion of datablocks in blender, replacement of one datablock by another, etc.
Some of those are for next commits.
A word of warning: this commit is highly risky, because it affects potentially a lot in Blender core.
Though it was tested rather deeply, being totally impossible to check all possible ID usage cases,
it's likely there are some remaining issues and bugs in new code... Please report them! ;)
Review task: D2027 (https://developer.blender.org/D2027).
Reviewed by campbellbarton, thanks a bunch.
2016-06-22 17:29:38 +02:00
|
|
|
if (editlt->def)
|
|
|
|
|
MEM_freeN(editlt->def);
|
|
|
|
|
if (editlt->dvert)
|
|
|
|
|
BKE_defvert_array_free(editlt->dvert, lt->pntsu * lt->pntsv * lt->pntsw);
|
2010-08-10 06:36:42 +00:00
|
|
|
|
|
|
|
|
MEM_freeN(editlt);
|
2009-01-13 15:18:41 +00:00
|
|
|
MEM_freeN(lt->editlatt);
|
ID-Remap - Step one: core work (cleanup and rework of generic ID datablock handling).
This commit changes a lot of how IDs are handled internally, especially the unlinking/freeing
processes. So far, this was very fuzy, to summarize cleanly deleting or replacing a datablock
was pretty much impossible, except for a few special cases.
Also, unlinking was handled by each datatype, in a rather messy and prone-to-errors way (quite
a few ID usages were missed or wrongly handled that way).
One of the main goal of id-remap branch was to cleanup this, and fatorize ID links handling
by using library_query utils to allow generic handling of those, which is now the case
(now, generic ID links handling is only "knwon" from readfile.c and library_query.c).
This commit also adds backends to allow live replacement and deletion of datablocks in Blender
(so-called 'remapping' process, where we replace all usages of a given ID pointer by a new one,
or NULL one in case of unlinking).
This will allow nice new features, like ability to easily reload or relocate libraries, real immediate
deletion of datablocks in blender, replacement of one datablock by another, etc.
Some of those are for next commits.
A word of warning: this commit is highly risky, because it affects potentially a lot in Blender core.
Though it was tested rather deeply, being totally impossible to check all possible ID usage cases,
it's likely there are some remaining issues and bugs in new code... Please report them! ;)
Review task: D2027 (https://developer.blender.org/D2027).
Reviewed by campbellbarton, thanks a bunch.
2016-06-22 17:29:38 +02:00
|
|
|
lt->editlatt = NULL;
|
2010-12-13 06:31:49 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-07-20 19:49:45 +02:00
|
|
|
void BKE_lattice_make_local(Main *bmain, Lattice *lt, const bool lib_local)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2016-07-20 19:49:45 +02:00
|
|
|
BKE_id_make_local_generic(bmain, <->id, true, lib_local);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-19 10:11:48 +00:00
|
|
|
typedef struct LatticeDeformData {
|
|
|
|
|
Object *object;
|
|
|
|
|
float *latticedata;
|
|
|
|
|
float latmat[4][4];
|
|
|
|
|
} LatticeDeformData;
|
|
|
|
|
|
|
|
|
|
LatticeDeformData *init_latt_deform(Object *oblatt, Object *ob)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2012-05-06 15:15:33 +00:00
|
|
|
/* we make an array with all differences */
|
|
|
|
|
Lattice *lt = oblatt->data;
|
2009-01-02 19:10:35 +00:00
|
|
|
BPoint *bp;
|
2013-08-19 09:25:24 +00:00
|
|
|
DispList *dl = oblatt->curve_cache ? BKE_displist_find(&oblatt->curve_cache->disp, DL_VERTS) : NULL;
|
2014-04-27 00:20:13 +10:00
|
|
|
const float *co = dl ? dl->verts : NULL;
|
2002-10-12 11:37:38 +00:00
|
|
|
float *fp, imat[4][4];
|
2005-08-15 10:30:53 +00:00
|
|
|
float fu, fv, fw;
|
2002-10-12 11:37:38 +00:00
|
|
|
int u, v, w;
|
2013-08-19 10:11:48 +00:00
|
|
|
float *latticedata;
|
|
|
|
|
float latmat[4][4];
|
|
|
|
|
LatticeDeformData *lattice_deform_data;
|
2005-08-15 10:30:53 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (lt->editlatt) lt = lt->editlatt->latt;
|
2009-01-02 19:10:35 +00:00
|
|
|
bp = lt->def;
|
|
|
|
|
|
2013-08-19 10:11:48 +00:00
|
|
|
fp = latticedata = MEM_mallocN(sizeof(float) * 3 * lt->pntsu * lt->pntsv * lt->pntsw, "latticedata");
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-27 19:40:36 +00:00
|
|
|
/* for example with a particle system: (ob == NULL) */
|
2012-05-06 15:15:33 +00:00
|
|
|
if (ob == NULL) {
|
2003-04-26 11:56:44 +00:00
|
|
|
/* in deformspace, calc matrix */
|
2013-08-19 10:11:48 +00:00
|
|
|
invert_m4_m4(latmat, oblatt->obmat);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2003-04-26 11:56:44 +00:00
|
|
|
/* back: put in deform array */
|
2013-08-19 10:11:48 +00:00
|
|
|
invert_m4_m4(imat, latmat);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2003-04-26 11:56:44 +00:00
|
|
|
/* in deformspace, calc matrix */
|
2009-11-10 20:43:45 +00:00
|
|
|
invert_m4_m4(imat, oblatt->obmat);
|
2013-08-19 10:11:48 +00:00
|
|
|
mul_m4_m4m4(latmat, imat, ob->obmat);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2003-04-26 11:56:44 +00:00
|
|
|
/* back: put in deform array */
|
2013-08-19 10:11:48 +00:00
|
|
|
invert_m4_m4(imat, latmat);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (w = 0, fw = lt->fw; w < lt->pntsw; w++, fw += lt->dw) {
|
|
|
|
|
for (v = 0, fv = lt->fv; v < lt->pntsv; v++, fv += lt->dv) {
|
|
|
|
|
for (u = 0, fu = lt->fu; u < lt->pntsu; u++, bp++, co += 3, fp += 3, fu += lt->du) {
|
2005-08-15 10:30:53 +00:00
|
|
|
if (dl) {
|
|
|
|
|
fp[0] = co[0] - fu;
|
|
|
|
|
fp[1] = co[1] - fv;
|
|
|
|
|
fp[2] = co[2] - fw;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2005-08-15 10:30:53 +00:00
|
|
|
fp[0] = bp->vec[0] - fu;
|
|
|
|
|
fp[1] = bp->vec[1] - fv;
|
|
|
|
|
fp[2] = bp->vec[2] - fw;
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
mul_mat3_m4_v3(imat, fp);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-08-19 10:11:48 +00:00
|
|
|
|
|
|
|
|
lattice_deform_data = MEM_mallocN(sizeof(LatticeDeformData), "Lattice Deform Data");
|
|
|
|
|
lattice_deform_data->latticedata = latticedata;
|
|
|
|
|
lattice_deform_data->object = oblatt;
|
|
|
|
|
copy_m4_m4(lattice_deform_data->latmat, latmat);
|
|
|
|
|
|
|
|
|
|
return lattice_deform_data;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-19 10:11:48 +00:00
|
|
|
void calc_latt_deform(LatticeDeformData *lattice_deform_data, float co[3], float weight)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2013-08-19 10:11:48 +00:00
|
|
|
Object *ob = lattice_deform_data->object;
|
2012-05-06 15:15:33 +00:00
|
|
|
Lattice *lt = ob->data;
|
2005-08-15 10:30:53 +00:00
|
|
|
float u, v, w, tu[4], tv[4], tw[4];
|
2010-04-20 21:38:55 +00:00
|
|
|
float vec[3];
|
|
|
|
|
int idx_w, idx_v, idx_u;
|
2003-02-13 16:56:42 +00:00
|
|
|
int ui, vi, wi, uu, vv, ww;
|
2010-04-20 21:38:55 +00:00
|
|
|
|
|
|
|
|
/* vgroup influence */
|
2012-10-22 17:19:05 +00:00
|
|
|
int defgrp_index = -1;
|
2012-05-06 15:15:33 +00:00
|
|
|
float co_prev[3], weight_blend = 0.0f;
|
|
|
|
|
MDeformVert *dvert = BKE_lattice_deform_verts_get(ob);
|
2010-04-20 21:38:55 +00:00
|
|
|
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (lt->editlatt) lt = lt->editlatt->latt;
|
2013-08-19 10:11:48 +00:00
|
|
|
if (lattice_deform_data->latticedata == NULL) return;
|
2010-04-20 21:38:55 +00:00
|
|
|
|
2012-02-23 02:17:50 +00:00
|
|
|
if (lt->vgroup[0] && dvert) {
|
2012-10-22 17:19:05 +00:00
|
|
|
defgrp_index = defgroup_name_index(ob, lt->vgroup);
|
2010-04-20 21:38:55 +00:00
|
|
|
copy_v3_v3(co_prev, co);
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-26 11:56:44 +00:00
|
|
|
/* co is in local coords, treat with latmat */
|
2013-08-19 10:11:48 +00:00
|
|
|
mul_v3_m4v3(vec, lattice_deform_data->latmat, co);
|
2010-04-20 21:38:55 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/* u v w coords */
|
2010-04-20 21:38:55 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (lt->pntsu > 1) {
|
|
|
|
|
u = (vec[0] - lt->fu) / lt->du;
|
|
|
|
|
ui = (int)floor(u);
|
2002-10-12 11:37:38 +00:00
|
|
|
u -= ui;
|
2009-09-09 18:09:03 +00:00
|
|
|
key_curve_position_weights(u, tu, lt->typeu);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-05-06 15:15:33 +00:00
|
|
|
tu[0] = tu[2] = tu[3] = 0.0; tu[1] = 1.0;
|
|
|
|
|
ui = 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2010-04-20 21:38:55 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (lt->pntsv > 1) {
|
|
|
|
|
v = (vec[1] - lt->fv) / lt->dv;
|
|
|
|
|
vi = (int)floor(v);
|
2002-10-12 11:37:38 +00:00
|
|
|
v -= vi;
|
2009-09-09 18:09:03 +00:00
|
|
|
key_curve_position_weights(v, tv, lt->typev);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-05-06 15:15:33 +00:00
|
|
|
tv[0] = tv[2] = tv[3] = 0.0; tv[1] = 1.0;
|
|
|
|
|
vi = 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2010-04-20 21:38:55 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (lt->pntsw > 1) {
|
|
|
|
|
w = (vec[2] - lt->fw) / lt->dw;
|
|
|
|
|
wi = (int)floor(w);
|
2002-10-12 11:37:38 +00:00
|
|
|
w -= wi;
|
2009-09-09 18:09:03 +00:00
|
|
|
key_curve_position_weights(w, tw, lt->typew);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-05-06 15:15:33 +00:00
|
|
|
tw[0] = tw[2] = tw[3] = 0.0; tw[1] = 1.0;
|
|
|
|
|
wi = 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2010-04-20 21:38:55 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (ww = wi - 1; ww <= wi + 2; ww++) {
|
|
|
|
|
w = tw[ww - wi + 1];
|
2010-04-20 21:38:55 +00:00
|
|
|
|
2012-02-23 02:17:50 +00:00
|
|
|
if (w != 0.0f) {
|
2012-05-06 15:15:33 +00:00
|
|
|
if (ww > 0) {
|
|
|
|
|
if (ww < lt->pntsw) idx_w = ww * lt->pntsu * lt->pntsv;
|
2013-03-09 03:46:30 +00:00
|
|
|
else idx_w = (lt->pntsw - 1) * lt->pntsu * lt->pntsv;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
idx_w = 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2010-04-20 21:38:55 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (vv = vi - 1; vv <= vi + 2; vv++) {
|
|
|
|
|
v = w * tv[vv - vi + 1];
|
2010-04-20 21:38:55 +00:00
|
|
|
|
2012-02-23 02:17:50 +00:00
|
|
|
if (v != 0.0f) {
|
2012-05-06 15:15:33 +00:00
|
|
|
if (vv > 0) {
|
|
|
|
|
if (vv < lt->pntsv) idx_v = idx_w + vv * lt->pntsu;
|
2013-03-09 03:46:30 +00:00
|
|
|
else idx_v = idx_w + (lt->pntsv - 1) * lt->pntsu;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
idx_v = idx_w;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2010-04-20 21:38:55 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (uu = ui - 1; uu <= ui + 2; uu++) {
|
|
|
|
|
u = weight * v * tu[uu - ui + 1];
|
2010-04-20 21:38:55 +00:00
|
|
|
|
2012-02-23 02:17:50 +00:00
|
|
|
if (u != 0.0f) {
|
2012-05-06 15:15:33 +00:00
|
|
|
if (uu > 0) {
|
|
|
|
|
if (uu < lt->pntsu) idx_u = idx_v + uu;
|
2013-03-09 03:46:30 +00:00
|
|
|
else idx_u = idx_v + (lt->pntsu - 1);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
idx_u = idx_v;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2010-04-20 21:38:55 +00:00
|
|
|
|
2013-08-19 10:11:48 +00:00
|
|
|
madd_v3_v3fl(co, &lattice_deform_data->latticedata[idx_u * 3], u);
|
2010-04-20 21:38:55 +00:00
|
|
|
|
2012-10-22 17:19:05 +00:00
|
|
|
if (defgrp_index != -1)
|
|
|
|
|
weight_blend += (u * defvert_find_weight(dvert + idx_u, defgrp_index));
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-04-20 21:38:55 +00:00
|
|
|
|
2012-10-22 17:19:05 +00:00
|
|
|
if (defgrp_index != -1)
|
2010-04-20 21:38:55 +00:00
|
|
|
interp_v3_v3v3(co, co_prev, co, weight_blend);
|
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-19 10:11:48 +00:00
|
|
|
void end_latt_deform(LatticeDeformData *lattice_deform_data)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2013-08-19 10:11:48 +00:00
|
|
|
if (lattice_deform_data->latticedata)
|
|
|
|
|
MEM_freeN(lattice_deform_data->latticedata);
|
|
|
|
|
|
|
|
|
|
MEM_freeN(lattice_deform_data);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
/* calculations is in local space of deformed object
|
|
|
|
|
* so we store in latmat transform from path coord inside object
|
|
|
|
|
*/
|
2004-09-14 19:03:11 +00:00
|
|
|
typedef struct {
|
2012-01-31 21:06:52 +00:00
|
|
|
float dmin[3], dmax[3];
|
Two wonderful new NLA & Armature editing features!
- FORWARD CYCLING & MATCHING
Up to no now, adding multiple actions in NLA with walkcycles required to
animate them standing still, as if walking on a conveyor belt. The stride
option then makes the object itself move forward, trying to keep the foot
stuck on the floor (with poor results!).
This option now allows to make walk cycles moving forward. By
indicating a reference Offset Bone, the NLA system will use that bone to
detect the correct offset for the Armature Pose to make it seamlessly going
forward.
Best of all, this option works as for cyclic Action Strips as well as for
individual Action Strips. Note that for individual strips, you have to set
the strip on "Hold". (Might become automatic detected later).
Here's an example edit image for NLA:
http://www.blender.org/bf/nla_match-cycle.jpg
And the animation for it:
http://download.blender.org/demo/test/2.43/0001_0150_match.avi
Blender file:
http://download.blender.org/demo/test/2.43/mancandy_matching.blend
Using this kind of cycling works pretty straightforward, and is a lot
easier to setup than Stride Bones.
To be further tested:
- Blending cycles
- matching rotation for the bones as well.
- ACTION MODIFIERS (motion deformors)
The above option was actually required for this feature. Typically walk
cycles are constructed with certain Bones to be the handles, controlling
for example the torso or feet.
An Action Modifier allows you to use a Curve Path to deform the motion of
these controlling bones. This uses the existing Curve Deformation option.
Modifiers can be added per Action Strip, each controlling a channel (bone)
by choice, and even allows to layer multiple modifiers on top of each other
(several paths deforming motion). This option is using the dependency graph,
so editing the Curve will give realtime changes in the Armature.
The previous walkcycle, controlled by two curves:
http://download.blender.org/demo/test/2.43/0001_0150_deform.avi
Blender file:
http://download.blender.org/demo/test/2.43/mancandy_actiondeform.blend
Action Modifiers can be added in the NLA Properties Panel. Per Modifier you
have to indicate the channel and a Curve Object. You can copy modifiers from
one strip to another using CTRL+C (only copies to active Object strips).
Setting up a correct Curve Path has to be carefully done:
- Use SHIFT+A "Curve Path" in top view, or ensure the path is not rotated.
- make sure the center point of the Curve Object is at the center of the
Armature (or above)
- move the first point of the curve to the center point as well.
- check if the path starts from this first point, you can change it using
(in Curve EditMode) the option Wkey -> "Switch Direction"
- Make sure alignment uses the correct axis; if the Armature walks into
the negative Y direction, you have to set in Object Buttons, "Anim settings"
Panel, the correct Track option. (Note; option will probably move to the
Modifier later).
This is a good reason to make such paths automatic (on a command). Is on the
todo list.
Also note this:
- the Curve Path extends in beginning and ending, that's (for now) the default,
and allows to use multiple paths. Make sure paths begin and end horizontal.
- Moving the Curve in Object Mode will change the "mapping" (as if the landscape
a character walks over moves). Moving the Curve in Edit Mode will change the
actual position of the deformation.
- Speed (Ipos) on paths is not supported yet, will be done.
- The Curve "Stretch" deform option doesn't work.
- Modifiers are executed *after* all actions in NLA are evaluated, there's no
support yet for blending multiple strips with Modifiers.
- This doesn't work yet for time-mapping...
This commit is mostly for review by character animators... some details or
working methods might change.
This feature can also be used for other modifiers, such as noise (Perlin) or
the mythical "Oomph" (frequency control) and of course Python.
Special thanks to Bassam & Matt for research & design help. Have fun!
2006-10-31 15:51:57 +00:00
|
|
|
float curvespace[4][4], objectspace[4][4], objectspace3[3][3];
|
|
|
|
|
int no_rot_axis;
|
2004-09-14 19:03:11 +00:00
|
|
|
} CurveDeform;
|
|
|
|
|
|
2012-01-31 21:06:52 +00:00
|
|
|
static void init_curve_deform(Object *par, Object *ob, CurveDeform *cd)
|
2004-09-14 19:03:11 +00:00
|
|
|
{
|
2009-11-10 20:43:45 +00:00
|
|
|
invert_m4_m4(ob->imat, ob->obmat);
|
2013-05-26 18:36:25 +00:00
|
|
|
mul_m4_m4m4(cd->objectspace, ob->imat, par->obmat);
|
2009-11-10 20:43:45 +00:00
|
|
|
invert_m4_m4(cd->curvespace, cd->objectspace);
|
|
|
|
|
copy_m3_m4(cd->objectspace3, cd->objectspace);
|
2012-05-06 15:15:33 +00:00
|
|
|
cd->no_rot_axis = 0;
|
2004-09-14 19:03:11 +00:00
|
|
|
}
|
|
|
|
|
|
2012-01-31 20:38:03 +00:00
|
|
|
/* this makes sure we can extend for non-cyclic.
|
|
|
|
|
*
|
|
|
|
|
* returns OK: 1/0
|
|
|
|
|
*/
|
2014-02-05 22:36:15 +11:00
|
|
|
static bool where_on_path_deform(Object *ob, float ctime, float vec[4], float dir[3], float quat[4], float *radius)
|
2004-09-14 19:03:11 +00:00
|
|
|
{
|
|
|
|
|
BevList *bl;
|
|
|
|
|
float ctime1;
|
2012-05-06 15:15:33 +00:00
|
|
|
int cycl = 0;
|
2004-09-14 19:03:11 +00:00
|
|
|
|
|
|
|
|
/* test for cyclic */
|
2013-08-19 09:25:24 +00:00
|
|
|
bl = ob->curve_cache->bev.first;
|
2014-12-01 17:11:18 +01:00
|
|
|
if (!bl->nr) return false;
|
2012-09-14 06:17:14 +00:00
|
|
|
if (bl->poly > -1) cycl = 1;
|
2004-09-14 19:03:11 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (cycl == 0) {
|
|
|
|
|
ctime1 = CLAMPIS(ctime, 0.0f, 1.0f);
|
2004-09-14 19:03:11 +00:00
|
|
|
}
|
2013-03-09 03:46:30 +00:00
|
|
|
else {
|
|
|
|
|
ctime1 = ctime;
|
|
|
|
|
}
|
2004-11-21 10:42:42 +00:00
|
|
|
|
|
|
|
|
/* vec needs 4 items */
|
2012-02-23 02:17:50 +00:00
|
|
|
if (where_on_path(ob, ctime1, vec, dir, quat, radius, NULL)) {
|
2004-09-14 19:03:11 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (cycl == 0) {
|
2013-08-19 09:25:24 +00:00
|
|
|
Path *path = ob->curve_cache->path;
|
2004-09-14 19:03:11 +00:00
|
|
|
float dvec[3];
|
|
|
|
|
|
2012-02-23 02:17:50 +00:00
|
|
|
if (ctime < 0.0f) {
|
2009-11-10 20:43:45 +00:00
|
|
|
sub_v3_v3v3(dvec, path->data[1].vec, path->data[0].vec);
|
2012-05-06 15:15:33 +00:00
|
|
|
mul_v3_fl(dvec, ctime * (float)path->len);
|
2010-08-06 05:19:00 +00:00
|
|
|
add_v3_v3(vec, dvec);
|
2012-02-23 02:17:50 +00:00
|
|
|
if (quat) copy_qt_qt(quat, path->data[0].quat);
|
2012-05-06 15:15:33 +00:00
|
|
|
if (radius) *radius = path->data[0].radius;
|
2004-09-14 19:03:11 +00:00
|
|
|
}
|
2012-02-23 02:17:50 +00:00
|
|
|
else if (ctime > 1.0f) {
|
2012-05-06 15:15:33 +00:00
|
|
|
sub_v3_v3v3(dvec, path->data[path->len - 1].vec, path->data[path->len - 2].vec);
|
|
|
|
|
mul_v3_fl(dvec, (ctime - 1.0f) * (float)path->len);
|
2010-08-06 05:19:00 +00:00
|
|
|
add_v3_v3(vec, dvec);
|
2012-05-06 15:15:33 +00:00
|
|
|
if (quat) copy_qt_qt(quat, path->data[path->len - 1].quat);
|
|
|
|
|
if (radius) *radius = path->data[path->len - 1].radius;
|
2010-04-21 11:59:47 +00:00
|
|
|
/* weight - not used but could be added */
|
2004-09-14 19:03:11 +00:00
|
|
|
}
|
|
|
|
|
}
|
2014-12-01 17:11:18 +01:00
|
|
|
return true;
|
2004-09-14 19:03:11 +00:00
|
|
|
}
|
2014-12-01 17:11:18 +01:00
|
|
|
return false;
|
2004-09-14 19:03:11 +00:00
|
|
|
}
|
|
|
|
|
|
2012-01-31 20:38:03 +00:00
|
|
|
/* for each point, rotate & translate to curve */
|
|
|
|
|
/* use path, since it has constant distances */
|
|
|
|
|
/* co: local coord, result local too */
|
|
|
|
|
/* returns quaternion for rotation, using cd->no_rot_axis */
|
|
|
|
|
/* axis is using another define!!! */
|
2017-11-20 12:37:11 +01:00
|
|
|
static bool calc_curve_deform(Object *par, float co[3],
|
2014-03-16 03:24:05 +11:00
|
|
|
const short axis, CurveDeform *cd, float r_quat[4])
|
2004-09-14 19:03:11 +00:00
|
|
|
{
|
2012-05-06 15:15:33 +00:00
|
|
|
Curve *cu = par->data;
|
2009-09-30 23:31:10 +00:00
|
|
|
float fac, loc[4], dir[3], new_quat[4], radius;
|
2012-01-31 21:20:30 +00:00
|
|
|
short index;
|
2014-02-03 18:55:59 +11:00
|
|
|
const bool is_neg_axis = (axis > 2);
|
2009-09-30 23:31:10 +00:00
|
|
|
|
2014-06-25 16:25:43 +06:00
|
|
|
if (par->curve_cache == NULL) {
|
2017-11-20 12:37:11 +01:00
|
|
|
/* Happens with a cyclic dependencies. */
|
|
|
|
|
return false;
|
2014-06-25 16:25:43 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (par->curve_cache->path == NULL) {
|
2014-12-01 17:11:18 +01:00
|
|
|
return false; /* happens on append, cyclic dependencies and empty curves */
|
2004-09-27 10:39:18 +00:00
|
|
|
}
|
2014-06-25 16:25:43 +06:00
|
|
|
|
2004-09-14 19:03:11 +00:00
|
|
|
/* options */
|
2012-01-31 21:20:30 +00:00
|
|
|
if (is_neg_axis) {
|
2012-01-31 21:32:06 +00:00
|
|
|
index = axis - 3;
|
2012-02-23 02:17:50 +00:00
|
|
|
if (cu->flag & CU_STRETCH)
|
2012-05-06 15:15:33 +00:00
|
|
|
fac = (-co[index] - cd->dmax[index]) / (cd->dmax[index] - cd->dmin[index]);
|
Two wonderful new NLA & Armature editing features!
- FORWARD CYCLING & MATCHING
Up to no now, adding multiple actions in NLA with walkcycles required to
animate them standing still, as if walking on a conveyor belt. The stride
option then makes the object itself move forward, trying to keep the foot
stuck on the floor (with poor results!).
This option now allows to make walk cycles moving forward. By
indicating a reference Offset Bone, the NLA system will use that bone to
detect the correct offset for the Armature Pose to make it seamlessly going
forward.
Best of all, this option works as for cyclic Action Strips as well as for
individual Action Strips. Note that for individual strips, you have to set
the strip on "Hold". (Might become automatic detected later).
Here's an example edit image for NLA:
http://www.blender.org/bf/nla_match-cycle.jpg
And the animation for it:
http://download.blender.org/demo/test/2.43/0001_0150_match.avi
Blender file:
http://download.blender.org/demo/test/2.43/mancandy_matching.blend
Using this kind of cycling works pretty straightforward, and is a lot
easier to setup than Stride Bones.
To be further tested:
- Blending cycles
- matching rotation for the bones as well.
- ACTION MODIFIERS (motion deformors)
The above option was actually required for this feature. Typically walk
cycles are constructed with certain Bones to be the handles, controlling
for example the torso or feet.
An Action Modifier allows you to use a Curve Path to deform the motion of
these controlling bones. This uses the existing Curve Deformation option.
Modifiers can be added per Action Strip, each controlling a channel (bone)
by choice, and even allows to layer multiple modifiers on top of each other
(several paths deforming motion). This option is using the dependency graph,
so editing the Curve will give realtime changes in the Armature.
The previous walkcycle, controlled by two curves:
http://download.blender.org/demo/test/2.43/0001_0150_deform.avi
Blender file:
http://download.blender.org/demo/test/2.43/mancandy_actiondeform.blend
Action Modifiers can be added in the NLA Properties Panel. Per Modifier you
have to indicate the channel and a Curve Object. You can copy modifiers from
one strip to another using CTRL+C (only copies to active Object strips).
Setting up a correct Curve Path has to be carefully done:
- Use SHIFT+A "Curve Path" in top view, or ensure the path is not rotated.
- make sure the center point of the Curve Object is at the center of the
Armature (or above)
- move the first point of the curve to the center point as well.
- check if the path starts from this first point, you can change it using
(in Curve EditMode) the option Wkey -> "Switch Direction"
- Make sure alignment uses the correct axis; if the Armature walks into
the negative Y direction, you have to set in Object Buttons, "Anim settings"
Panel, the correct Track option. (Note; option will probably move to the
Modifier later).
This is a good reason to make such paths automatic (on a command). Is on the
todo list.
Also note this:
- the Curve Path extends in beginning and ending, that's (for now) the default,
and allows to use multiple paths. Make sure paths begin and end horizontal.
- Moving the Curve in Object Mode will change the "mapping" (as if the landscape
a character walks over moves). Moving the Curve in Edit Mode will change the
actual position of the deformation.
- Speed (Ipos) on paths is not supported yet, will be done.
- The Curve "Stretch" deform option doesn't work.
- Modifiers are executed *after* all actions in NLA are evaluated, there's no
support yet for blending multiple strips with Modifiers.
- This doesn't work yet for time-mapping...
This commit is mostly for review by character animators... some details or
working methods might change.
This feature can also be used for other modifiers, such as noise (Perlin) or
the mythical "Oomph" (frequency control) and of course Python.
Special thanks to Bassam & Matt for research & design help. Have fun!
2006-10-31 15:51:57 +00:00
|
|
|
else
|
2013-08-19 09:25:24 +00:00
|
|
|
fac = -(co[index] - cd->dmax[index]) / (par->curve_cache->path->totdist);
|
Two wonderful new NLA & Armature editing features!
- FORWARD CYCLING & MATCHING
Up to no now, adding multiple actions in NLA with walkcycles required to
animate them standing still, as if walking on a conveyor belt. The stride
option then makes the object itself move forward, trying to keep the foot
stuck on the floor (with poor results!).
This option now allows to make walk cycles moving forward. By
indicating a reference Offset Bone, the NLA system will use that bone to
detect the correct offset for the Armature Pose to make it seamlessly going
forward.
Best of all, this option works as for cyclic Action Strips as well as for
individual Action Strips. Note that for individual strips, you have to set
the strip on "Hold". (Might become automatic detected later).
Here's an example edit image for NLA:
http://www.blender.org/bf/nla_match-cycle.jpg
And the animation for it:
http://download.blender.org/demo/test/2.43/0001_0150_match.avi
Blender file:
http://download.blender.org/demo/test/2.43/mancandy_matching.blend
Using this kind of cycling works pretty straightforward, and is a lot
easier to setup than Stride Bones.
To be further tested:
- Blending cycles
- matching rotation for the bones as well.
- ACTION MODIFIERS (motion deformors)
The above option was actually required for this feature. Typically walk
cycles are constructed with certain Bones to be the handles, controlling
for example the torso or feet.
An Action Modifier allows you to use a Curve Path to deform the motion of
these controlling bones. This uses the existing Curve Deformation option.
Modifiers can be added per Action Strip, each controlling a channel (bone)
by choice, and even allows to layer multiple modifiers on top of each other
(several paths deforming motion). This option is using the dependency graph,
so editing the Curve will give realtime changes in the Armature.
The previous walkcycle, controlled by two curves:
http://download.blender.org/demo/test/2.43/0001_0150_deform.avi
Blender file:
http://download.blender.org/demo/test/2.43/mancandy_actiondeform.blend
Action Modifiers can be added in the NLA Properties Panel. Per Modifier you
have to indicate the channel and a Curve Object. You can copy modifiers from
one strip to another using CTRL+C (only copies to active Object strips).
Setting up a correct Curve Path has to be carefully done:
- Use SHIFT+A "Curve Path" in top view, or ensure the path is not rotated.
- make sure the center point of the Curve Object is at the center of the
Armature (or above)
- move the first point of the curve to the center point as well.
- check if the path starts from this first point, you can change it using
(in Curve EditMode) the option Wkey -> "Switch Direction"
- Make sure alignment uses the correct axis; if the Armature walks into
the negative Y direction, you have to set in Object Buttons, "Anim settings"
Panel, the correct Track option. (Note; option will probably move to the
Modifier later).
This is a good reason to make such paths automatic (on a command). Is on the
todo list.
Also note this:
- the Curve Path extends in beginning and ending, that's (for now) the default,
and allows to use multiple paths. Make sure paths begin and end horizontal.
- Moving the Curve in Object Mode will change the "mapping" (as if the landscape
a character walks over moves). Moving the Curve in Edit Mode will change the
actual position of the deformation.
- Speed (Ipos) on paths is not supported yet, will be done.
- The Curve "Stretch" deform option doesn't work.
- Modifiers are executed *after* all actions in NLA are evaluated, there's no
support yet for blending multiple strips with Modifiers.
- This doesn't work yet for time-mapping...
This commit is mostly for review by character animators... some details or
working methods might change.
This feature can also be used for other modifiers, such as noise (Perlin) or
the mythical "Oomph" (frequency control) and of course Python.
Special thanks to Bassam & Matt for research & design help. Have fun!
2006-10-31 15:51:57 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-01-31 21:32:06 +00:00
|
|
|
index = axis;
|
2014-04-11 17:40:07 +06:00
|
|
|
if (cu->flag & CU_STRETCH) {
|
2012-05-06 15:15:33 +00:00
|
|
|
fac = (co[index] - cd->dmin[index]) / (cd->dmax[index] - cd->dmin[index]);
|
2014-04-11 17:40:07 +06:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (LIKELY(par->curve_cache->path->totdist > FLT_EPSILON)) {
|
|
|
|
|
fac = +(co[index] - cd->dmin[index]) / (par->curve_cache->path->totdist);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
fac = 0.0f;
|
|
|
|
|
}
|
|
|
|
|
}
|
Two wonderful new NLA & Armature editing features!
- FORWARD CYCLING & MATCHING
Up to no now, adding multiple actions in NLA with walkcycles required to
animate them standing still, as if walking on a conveyor belt. The stride
option then makes the object itself move forward, trying to keep the foot
stuck on the floor (with poor results!).
This option now allows to make walk cycles moving forward. By
indicating a reference Offset Bone, the NLA system will use that bone to
detect the correct offset for the Armature Pose to make it seamlessly going
forward.
Best of all, this option works as for cyclic Action Strips as well as for
individual Action Strips. Note that for individual strips, you have to set
the strip on "Hold". (Might become automatic detected later).
Here's an example edit image for NLA:
http://www.blender.org/bf/nla_match-cycle.jpg
And the animation for it:
http://download.blender.org/demo/test/2.43/0001_0150_match.avi
Blender file:
http://download.blender.org/demo/test/2.43/mancandy_matching.blend
Using this kind of cycling works pretty straightforward, and is a lot
easier to setup than Stride Bones.
To be further tested:
- Blending cycles
- matching rotation for the bones as well.
- ACTION MODIFIERS (motion deformors)
The above option was actually required for this feature. Typically walk
cycles are constructed with certain Bones to be the handles, controlling
for example the torso or feet.
An Action Modifier allows you to use a Curve Path to deform the motion of
these controlling bones. This uses the existing Curve Deformation option.
Modifiers can be added per Action Strip, each controlling a channel (bone)
by choice, and even allows to layer multiple modifiers on top of each other
(several paths deforming motion). This option is using the dependency graph,
so editing the Curve will give realtime changes in the Armature.
The previous walkcycle, controlled by two curves:
http://download.blender.org/demo/test/2.43/0001_0150_deform.avi
Blender file:
http://download.blender.org/demo/test/2.43/mancandy_actiondeform.blend
Action Modifiers can be added in the NLA Properties Panel. Per Modifier you
have to indicate the channel and a Curve Object. You can copy modifiers from
one strip to another using CTRL+C (only copies to active Object strips).
Setting up a correct Curve Path has to be carefully done:
- Use SHIFT+A "Curve Path" in top view, or ensure the path is not rotated.
- make sure the center point of the Curve Object is at the center of the
Armature (or above)
- move the first point of the curve to the center point as well.
- check if the path starts from this first point, you can change it using
(in Curve EditMode) the option Wkey -> "Switch Direction"
- Make sure alignment uses the correct axis; if the Armature walks into
the negative Y direction, you have to set in Object Buttons, "Anim settings"
Panel, the correct Track option. (Note; option will probably move to the
Modifier later).
This is a good reason to make such paths automatic (on a command). Is on the
todo list.
Also note this:
- the Curve Path extends in beginning and ending, that's (for now) the default,
and allows to use multiple paths. Make sure paths begin and end horizontal.
- Moving the Curve in Object Mode will change the "mapping" (as if the landscape
a character walks over moves). Moving the Curve in Edit Mode will change the
actual position of the deformation.
- Speed (Ipos) on paths is not supported yet, will be done.
- The Curve "Stretch" deform option doesn't work.
- Modifiers are executed *after* all actions in NLA are evaluated, there's no
support yet for blending multiple strips with Modifiers.
- This doesn't work yet for time-mapping...
This commit is mostly for review by character animators... some details or
working methods might change.
This feature can also be used for other modifiers, such as noise (Perlin) or
the mythical "Oomph" (frequency control) and of course Python.
Special thanks to Bassam & Matt for research & design help. Have fun!
2006-10-31 15:51:57 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (where_on_path_deform(par, fac, loc, dir, new_quat, &radius)) { /* returns OK */
|
2009-09-30 23:31:10 +00:00
|
|
|
float quat[4], cent[3];
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (cd->no_rot_axis) { /* set by caller */
|
2009-09-30 23:31:10 +00:00
|
|
|
|
2011-05-28 13:11:24 +00:00
|
|
|
/* this is not exactly the same as 2.4x, since the axis is having rotation removed rather than
|
2009-09-30 23:31:10 +00:00
|
|
|
* changing the axis before calculating the tilt but serves much the same purpose */
|
2012-05-06 15:15:33 +00:00
|
|
|
float dir_flat[3] = {0, 0, 0}, q[4];
|
2010-08-06 05:19:00 +00:00
|
|
|
copy_v3_v3(dir_flat, dir);
|
2012-05-06 15:15:33 +00:00
|
|
|
dir_flat[cd->no_rot_axis - 1] = 0.0f;
|
2009-09-30 23:31:10 +00:00
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
normalize_v3(dir);
|
|
|
|
|
normalize_v3(dir_flat);
|
2009-09-30 23:31:10 +00:00
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
rotation_between_vecs_to_quat(q, dir, dir_flat); /* Could this be done faster? */
|
2009-09-30 23:31:10 +00:00
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
mul_qt_qtqt(new_quat, q, new_quat);
|
2009-09-30 23:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Logic for 'cent' orientation *
|
|
|
|
|
*
|
|
|
|
|
* The way 'co' is copied to 'cent' may seem to have no meaning, but it does.
|
|
|
|
|
*
|
|
|
|
|
* Use a curve modifier to stretch a cube out, color each side RGB, positive side light, negative dark.
|
|
|
|
|
* view with X up (default), from the angle that you can see 3 faces RGB colors (light), anti-clockwise
|
|
|
|
|
* Notice X,Y,Z Up all have light colors and each ordered CCW.
|
|
|
|
|
*
|
|
|
|
|
* Now for Neg Up XYZ, the colors are all dark, and ordered clockwise - Campbell
|
2010-10-08 02:08:11 +00:00
|
|
|
*
|
|
|
|
|
* note: moved functions into quat_apply_track/vec_apply_track
|
2009-09-30 23:31:10 +00:00
|
|
|
* */
|
2010-10-08 02:08:11 +00:00
|
|
|
copy_qt_qt(quat, new_quat);
|
|
|
|
|
copy_v3_v3(cent, co);
|
|
|
|
|
|
|
|
|
|
/* zero the axis which is not used,
|
|
|
|
|
* the big block of text above now applies to these 3 lines */
|
2012-05-06 15:15:33 +00:00
|
|
|
quat_apply_track(quat, axis, (axis == 0 || axis == 2) ? 1 : 0); /* up flag is a dummy, set so no rotation is done */
|
2012-01-31 21:32:06 +00:00
|
|
|
vec_apply_track(cent, axis);
|
2012-05-06 15:15:33 +00:00
|
|
|
cent[index] = 0.0f;
|
2009-09-30 23:31:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/* scale if enabled */
|
2012-02-23 02:17:50 +00:00
|
|
|
if (cu->flag & CU_PATH_RADIUS)
|
2009-11-10 20:43:45 +00:00
|
|
|
mul_v3_fl(cent, radius);
|
2004-09-14 19:03:11 +00:00
|
|
|
|
2009-09-30 23:31:10 +00:00
|
|
|
/* local rotation */
|
2009-11-10 20:43:45 +00:00
|
|
|
normalize_qt(quat);
|
|
|
|
|
mul_qt_v3(quat, cent);
|
2009-09-30 23:31:10 +00:00
|
|
|
|
2004-09-14 19:03:11 +00:00
|
|
|
/* translation */
|
2010-08-06 05:19:00 +00:00
|
|
|
add_v3_v3v3(co, cent, loc);
|
2009-09-30 23:31:10 +00:00
|
|
|
|
2014-03-16 03:24:05 +11:00
|
|
|
if (r_quat)
|
|
|
|
|
copy_qt_qt(r_quat, quat);
|
2010-08-06 05:19:00 +00:00
|
|
|
|
2014-12-01 17:11:18 +01:00
|
|
|
return true;
|
2004-09-14 19:03:11 +00:00
|
|
|
}
|
2014-12-01 17:11:18 +01:00
|
|
|
return false;
|
2004-09-14 19:03:11 +00:00
|
|
|
}
|
|
|
|
|
|
2015-03-21 22:34:20 +11:00
|
|
|
void curve_deform_verts(
|
2017-08-16 12:45:11 +10:00
|
|
|
Object *cuOb, Object *target, DerivedMesh *dm, float (*vertexCos)[3],
|
2015-03-21 22:34:20 +11:00
|
|
|
int numVerts, const char *vgroup, short defaxis)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2008-04-04 12:33:01 +00:00
|
|
|
Curve *cu;
|
2014-01-10 01:45:53 +06:00
|
|
|
int a;
|
2005-07-19 20:14:17 +00:00
|
|
|
CurveDeform cd;
|
2014-09-04 16:43:52 +02:00
|
|
|
MDeformVert *dvert = NULL;
|
|
|
|
|
int defgrp_index = -1;
|
2014-02-03 18:55:59 +11:00
|
|
|
const bool is_neg_axis = (defaxis > 2);
|
2008-04-04 12:33:01 +00:00
|
|
|
|
2012-02-23 02:17:50 +00:00
|
|
|
if (cuOb->type != OB_CURVE)
|
2008-04-04 12:33:01 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
cu = cuOb->data;
|
2005-07-19 20:14:17 +00:00
|
|
|
|
2012-01-31 21:06:52 +00:00
|
|
|
init_curve_deform(cuOb, target, &cd);
|
2010-08-06 08:27:07 +00:00
|
|
|
|
|
|
|
|
/* dummy bounds, keep if CU_DEFORM_BOUNDS_OFF is set */
|
2014-04-01 11:34:00 +11:00
|
|
|
if (is_neg_axis == false) {
|
2012-05-06 15:15:33 +00:00
|
|
|
cd.dmin[0] = cd.dmin[1] = cd.dmin[2] = 0.0f;
|
|
|
|
|
cd.dmax[0] = cd.dmax[1] = cd.dmax[2] = 1.0f;
|
2010-08-06 08:27:07 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* negative, these bounds give a good rest position */
|
2012-05-06 15:15:33 +00:00
|
|
|
cd.dmin[0] = cd.dmin[1] = cd.dmin[2] = -1.0f;
|
|
|
|
|
cd.dmax[0] = cd.dmax[1] = cd.dmax[2] = 0.0f;
|
2010-08-06 08:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
2014-09-04 16:43:52 +02:00
|
|
|
/* Check whether to use vertex groups (only possible if target is a Mesh or Lattice).
|
|
|
|
|
* We want either a Mesh/Lattice with no derived data, or derived data with deformverts.
|
2006-08-28 01:12:36 +00:00
|
|
|
*/
|
2014-09-04 16:43:52 +02:00
|
|
|
if (vgroup && vgroup[0] && ELEM(target->type, OB_MESH, OB_LATTICE)) {
|
|
|
|
|
defgrp_index = defgroup_name_index(target, vgroup);
|
|
|
|
|
|
|
|
|
|
if (defgrp_index != -1) {
|
|
|
|
|
/* if there's derived data without deformverts, don't use vgroups */
|
|
|
|
|
if (dm) {
|
|
|
|
|
dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT);
|
|
|
|
|
}
|
|
|
|
|
else if (target->type == OB_LATTICE) {
|
|
|
|
|
dvert = ((Lattice *)target->data)->dvert;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
dvert = ((Mesh *)target->data)->dvert;
|
|
|
|
|
}
|
2012-05-19 13:28:19 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
2006-08-28 01:12:36 +00:00
|
|
|
|
2014-09-04 16:43:52 +02:00
|
|
|
if (dvert) {
|
|
|
|
|
MDeformVert *dvert_iter;
|
|
|
|
|
float vec[3];
|
|
|
|
|
|
|
|
|
|
if (cu->flag & CU_DEFORM_BOUNDS_OFF) {
|
|
|
|
|
for (a = 0, dvert_iter = dvert; a < numVerts; a++, dvert_iter++) {
|
|
|
|
|
const float weight = defvert_find_weight(dvert_iter, defgrp_index);
|
|
|
|
|
|
|
|
|
|
if (weight > 0.0f) {
|
|
|
|
|
mul_m4_v3(cd.curvespace, vertexCos[a]);
|
|
|
|
|
copy_v3_v3(vec, vertexCos[a]);
|
2017-11-20 12:37:11 +01:00
|
|
|
calc_curve_deform(cuOb, vec, defaxis, &cd, NULL);
|
2014-09-04 16:43:52 +02:00
|
|
|
interp_v3_v3v3(vertexCos[a], vertexCos[a], vec, weight);
|
|
|
|
|
mul_m4_v3(cd.objectspace, vertexCos[a]);
|
2006-08-28 01:12:36 +00:00
|
|
|
}
|
|
|
|
|
}
|
2014-09-04 16:43:52 +02:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* set mesh min/max bounds */
|
|
|
|
|
INIT_MINMAX(cd.dmin, cd.dmax);
|
|
|
|
|
|
|
|
|
|
for (a = 0, dvert_iter = dvert; a < numVerts; a++, dvert_iter++) {
|
|
|
|
|
if (defvert_find_weight(dvert_iter, defgrp_index) > 0.0f) {
|
|
|
|
|
mul_m4_v3(cd.curvespace, vertexCos[a]);
|
|
|
|
|
minmax_v3v3_v3(cd.dmin, cd.dmax, vertexCos[a]);
|
2010-08-06 08:27:07 +00:00
|
|
|
}
|
2014-09-04 16:43:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (a = 0, dvert_iter = dvert; a < numVerts; a++, dvert_iter++) {
|
|
|
|
|
const float weight = defvert_find_weight(dvert_iter, defgrp_index);
|
|
|
|
|
|
|
|
|
|
if (weight > 0.0f) {
|
|
|
|
|
/* already in 'cd.curvespace', prev for loop */
|
|
|
|
|
copy_v3_v3(vec, vertexCos[a]);
|
2017-11-20 12:37:11 +01:00
|
|
|
calc_curve_deform(cuOb, vec, defaxis, &cd, NULL);
|
2014-09-04 16:43:52 +02:00
|
|
|
interp_v3_v3v3(vertexCos[a], vertexCos[a], vec, weight);
|
|
|
|
|
mul_m4_v3(cd.objectspace, vertexCos[a]);
|
2005-10-20 18:52:29 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-08-06 08:27:07 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-02-23 02:17:50 +00:00
|
|
|
if (cu->flag & CU_DEFORM_BOUNDS_OFF) {
|
|
|
|
|
for (a = 0; a < numVerts; a++) {
|
2010-08-06 08:27:07 +00:00
|
|
|
mul_m4_v3(cd.curvespace, vertexCos[a]);
|
2017-11-20 12:37:11 +01:00
|
|
|
calc_curve_deform(cuOb, vertexCos[a], defaxis, &cd, NULL);
|
2010-08-06 08:27:07 +00:00
|
|
|
mul_m4_v3(cd.objectspace, vertexCos[a]);
|
|
|
|
|
}
|
2006-08-28 01:12:36 +00:00
|
|
|
}
|
2010-08-06 08:27:07 +00:00
|
|
|
else {
|
|
|
|
|
/* set mesh min max bounds */
|
|
|
|
|
INIT_MINMAX(cd.dmin, cd.dmax);
|
|
|
|
|
|
2012-02-23 02:17:50 +00:00
|
|
|
for (a = 0; a < numVerts; a++) {
|
2010-08-06 08:27:07 +00:00
|
|
|
mul_m4_v3(cd.curvespace, vertexCos[a]);
|
2012-05-13 11:05:52 +00:00
|
|
|
minmax_v3v3_v3(cd.dmin, cd.dmax, vertexCos[a]);
|
2010-08-06 08:27:07 +00:00
|
|
|
}
|
|
|
|
|
|
2012-02-23 02:17:50 +00:00
|
|
|
for (a = 0; a < numVerts; a++) {
|
2012-01-31 20:48:48 +00:00
|
|
|
/* already in 'cd.curvespace', prev for loop */
|
2017-11-20 12:37:11 +01:00
|
|
|
calc_curve_deform(cuOb, vertexCos[a], defaxis, &cd, NULL);
|
2010-08-06 08:27:07 +00:00
|
|
|
mul_m4_v3(cd.objectspace, vertexCos[a]);
|
|
|
|
|
}
|
2005-10-20 18:52:29 +00:00
|
|
|
}
|
2005-07-19 20:14:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
2005-07-19 02:36:21 +00:00
|
|
|
|
Two wonderful new NLA & Armature editing features!
- FORWARD CYCLING & MATCHING
Up to no now, adding multiple actions in NLA with walkcycles required to
animate them standing still, as if walking on a conveyor belt. The stride
option then makes the object itself move forward, trying to keep the foot
stuck on the floor (with poor results!).
This option now allows to make walk cycles moving forward. By
indicating a reference Offset Bone, the NLA system will use that bone to
detect the correct offset for the Armature Pose to make it seamlessly going
forward.
Best of all, this option works as for cyclic Action Strips as well as for
individual Action Strips. Note that for individual strips, you have to set
the strip on "Hold". (Might become automatic detected later).
Here's an example edit image for NLA:
http://www.blender.org/bf/nla_match-cycle.jpg
And the animation for it:
http://download.blender.org/demo/test/2.43/0001_0150_match.avi
Blender file:
http://download.blender.org/demo/test/2.43/mancandy_matching.blend
Using this kind of cycling works pretty straightforward, and is a lot
easier to setup than Stride Bones.
To be further tested:
- Blending cycles
- matching rotation for the bones as well.
- ACTION MODIFIERS (motion deformors)
The above option was actually required for this feature. Typically walk
cycles are constructed with certain Bones to be the handles, controlling
for example the torso or feet.
An Action Modifier allows you to use a Curve Path to deform the motion of
these controlling bones. This uses the existing Curve Deformation option.
Modifiers can be added per Action Strip, each controlling a channel (bone)
by choice, and even allows to layer multiple modifiers on top of each other
(several paths deforming motion). This option is using the dependency graph,
so editing the Curve will give realtime changes in the Armature.
The previous walkcycle, controlled by two curves:
http://download.blender.org/demo/test/2.43/0001_0150_deform.avi
Blender file:
http://download.blender.org/demo/test/2.43/mancandy_actiondeform.blend
Action Modifiers can be added in the NLA Properties Panel. Per Modifier you
have to indicate the channel and a Curve Object. You can copy modifiers from
one strip to another using CTRL+C (only copies to active Object strips).
Setting up a correct Curve Path has to be carefully done:
- Use SHIFT+A "Curve Path" in top view, or ensure the path is not rotated.
- make sure the center point of the Curve Object is at the center of the
Armature (or above)
- move the first point of the curve to the center point as well.
- check if the path starts from this first point, you can change it using
(in Curve EditMode) the option Wkey -> "Switch Direction"
- Make sure alignment uses the correct axis; if the Armature walks into
the negative Y direction, you have to set in Object Buttons, "Anim settings"
Panel, the correct Track option. (Note; option will probably move to the
Modifier later).
This is a good reason to make such paths automatic (on a command). Is on the
todo list.
Also note this:
- the Curve Path extends in beginning and ending, that's (for now) the default,
and allows to use multiple paths. Make sure paths begin and end horizontal.
- Moving the Curve in Object Mode will change the "mapping" (as if the landscape
a character walks over moves). Moving the Curve in Edit Mode will change the
actual position of the deformation.
- Speed (Ipos) on paths is not supported yet, will be done.
- The Curve "Stretch" deform option doesn't work.
- Modifiers are executed *after* all actions in NLA are evaluated, there's no
support yet for blending multiple strips with Modifiers.
- This doesn't work yet for time-mapping...
This commit is mostly for review by character animators... some details or
working methods might change.
This feature can also be used for other modifiers, such as noise (Perlin) or
the mythical "Oomph" (frequency control) and of course Python.
Special thanks to Bassam & Matt for research & design help. Have fun!
2006-10-31 15:51:57 +00:00
|
|
|
/* input vec and orco = local coord in armature space */
|
|
|
|
|
/* orco is original not-animated or deformed reference point */
|
|
|
|
|
/* result written in vec and mat */
|
2017-11-20 12:37:11 +01:00
|
|
|
void curve_deform_vector(Object *cuOb, Object *target,
|
2012-12-11 14:29:01 +00:00
|
|
|
float orco[3], float vec[3], float mat[3][3], int no_rot_axis)
|
Two wonderful new NLA & Armature editing features!
- FORWARD CYCLING & MATCHING
Up to no now, adding multiple actions in NLA with walkcycles required to
animate them standing still, as if walking on a conveyor belt. The stride
option then makes the object itself move forward, trying to keep the foot
stuck on the floor (with poor results!).
This option now allows to make walk cycles moving forward. By
indicating a reference Offset Bone, the NLA system will use that bone to
detect the correct offset for the Armature Pose to make it seamlessly going
forward.
Best of all, this option works as for cyclic Action Strips as well as for
individual Action Strips. Note that for individual strips, you have to set
the strip on "Hold". (Might become automatic detected later).
Here's an example edit image for NLA:
http://www.blender.org/bf/nla_match-cycle.jpg
And the animation for it:
http://download.blender.org/demo/test/2.43/0001_0150_match.avi
Blender file:
http://download.blender.org/demo/test/2.43/mancandy_matching.blend
Using this kind of cycling works pretty straightforward, and is a lot
easier to setup than Stride Bones.
To be further tested:
- Blending cycles
- matching rotation for the bones as well.
- ACTION MODIFIERS (motion deformors)
The above option was actually required for this feature. Typically walk
cycles are constructed with certain Bones to be the handles, controlling
for example the torso or feet.
An Action Modifier allows you to use a Curve Path to deform the motion of
these controlling bones. This uses the existing Curve Deformation option.
Modifiers can be added per Action Strip, each controlling a channel (bone)
by choice, and even allows to layer multiple modifiers on top of each other
(several paths deforming motion). This option is using the dependency graph,
so editing the Curve will give realtime changes in the Armature.
The previous walkcycle, controlled by two curves:
http://download.blender.org/demo/test/2.43/0001_0150_deform.avi
Blender file:
http://download.blender.org/demo/test/2.43/mancandy_actiondeform.blend
Action Modifiers can be added in the NLA Properties Panel. Per Modifier you
have to indicate the channel and a Curve Object. You can copy modifiers from
one strip to another using CTRL+C (only copies to active Object strips).
Setting up a correct Curve Path has to be carefully done:
- Use SHIFT+A "Curve Path" in top view, or ensure the path is not rotated.
- make sure the center point of the Curve Object is at the center of the
Armature (or above)
- move the first point of the curve to the center point as well.
- check if the path starts from this first point, you can change it using
(in Curve EditMode) the option Wkey -> "Switch Direction"
- Make sure alignment uses the correct axis; if the Armature walks into
the negative Y direction, you have to set in Object Buttons, "Anim settings"
Panel, the correct Track option. (Note; option will probably move to the
Modifier later).
This is a good reason to make such paths automatic (on a command). Is on the
todo list.
Also note this:
- the Curve Path extends in beginning and ending, that's (for now) the default,
and allows to use multiple paths. Make sure paths begin and end horizontal.
- Moving the Curve in Object Mode will change the "mapping" (as if the landscape
a character walks over moves). Moving the Curve in Edit Mode will change the
actual position of the deformation.
- Speed (Ipos) on paths is not supported yet, will be done.
- The Curve "Stretch" deform option doesn't work.
- Modifiers are executed *after* all actions in NLA are evaluated, there's no
support yet for blending multiple strips with Modifiers.
- This doesn't work yet for time-mapping...
This commit is mostly for review by character animators... some details or
working methods might change.
This feature can also be used for other modifiers, such as noise (Perlin) or
the mythical "Oomph" (frequency control) and of course Python.
Special thanks to Bassam & Matt for research & design help. Have fun!
2006-10-31 15:51:57 +00:00
|
|
|
{
|
|
|
|
|
CurveDeform cd;
|
2008-02-27 17:43:23 +00:00
|
|
|
float quat[4];
|
Two wonderful new NLA & Armature editing features!
- FORWARD CYCLING & MATCHING
Up to no now, adding multiple actions in NLA with walkcycles required to
animate them standing still, as if walking on a conveyor belt. The stride
option then makes the object itself move forward, trying to keep the foot
stuck on the floor (with poor results!).
This option now allows to make walk cycles moving forward. By
indicating a reference Offset Bone, the NLA system will use that bone to
detect the correct offset for the Armature Pose to make it seamlessly going
forward.
Best of all, this option works as for cyclic Action Strips as well as for
individual Action Strips. Note that for individual strips, you have to set
the strip on "Hold". (Might become automatic detected later).
Here's an example edit image for NLA:
http://www.blender.org/bf/nla_match-cycle.jpg
And the animation for it:
http://download.blender.org/demo/test/2.43/0001_0150_match.avi
Blender file:
http://download.blender.org/demo/test/2.43/mancandy_matching.blend
Using this kind of cycling works pretty straightforward, and is a lot
easier to setup than Stride Bones.
To be further tested:
- Blending cycles
- matching rotation for the bones as well.
- ACTION MODIFIERS (motion deformors)
The above option was actually required for this feature. Typically walk
cycles are constructed with certain Bones to be the handles, controlling
for example the torso or feet.
An Action Modifier allows you to use a Curve Path to deform the motion of
these controlling bones. This uses the existing Curve Deformation option.
Modifiers can be added per Action Strip, each controlling a channel (bone)
by choice, and even allows to layer multiple modifiers on top of each other
(several paths deforming motion). This option is using the dependency graph,
so editing the Curve will give realtime changes in the Armature.
The previous walkcycle, controlled by two curves:
http://download.blender.org/demo/test/2.43/0001_0150_deform.avi
Blender file:
http://download.blender.org/demo/test/2.43/mancandy_actiondeform.blend
Action Modifiers can be added in the NLA Properties Panel. Per Modifier you
have to indicate the channel and a Curve Object. You can copy modifiers from
one strip to another using CTRL+C (only copies to active Object strips).
Setting up a correct Curve Path has to be carefully done:
- Use SHIFT+A "Curve Path" in top view, or ensure the path is not rotated.
- make sure the center point of the Curve Object is at the center of the
Armature (or above)
- move the first point of the curve to the center point as well.
- check if the path starts from this first point, you can change it using
(in Curve EditMode) the option Wkey -> "Switch Direction"
- Make sure alignment uses the correct axis; if the Armature walks into
the negative Y direction, you have to set in Object Buttons, "Anim settings"
Panel, the correct Track option. (Note; option will probably move to the
Modifier later).
This is a good reason to make such paths automatic (on a command). Is on the
todo list.
Also note this:
- the Curve Path extends in beginning and ending, that's (for now) the default,
and allows to use multiple paths. Make sure paths begin and end horizontal.
- Moving the Curve in Object Mode will change the "mapping" (as if the landscape
a character walks over moves). Moving the Curve in Edit Mode will change the
actual position of the deformation.
- Speed (Ipos) on paths is not supported yet, will be done.
- The Curve "Stretch" deform option doesn't work.
- Modifiers are executed *after* all actions in NLA are evaluated, there's no
support yet for blending multiple strips with Modifiers.
- This doesn't work yet for time-mapping...
This commit is mostly for review by character animators... some details or
working methods might change.
This feature can also be used for other modifiers, such as noise (Perlin) or
the mythical "Oomph" (frequency control) and of course Python.
Special thanks to Bassam & Matt for research & design help. Have fun!
2006-10-31 15:51:57 +00:00
|
|
|
|
2012-02-23 02:17:50 +00:00
|
|
|
if (cuOb->type != OB_CURVE) {
|
2009-11-10 20:43:45 +00:00
|
|
|
unit_m3(mat);
|
2008-04-04 12:33:01 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-31 21:06:52 +00:00
|
|
|
init_curve_deform(cuOb, target, &cd);
|
2012-05-06 15:15:33 +00:00
|
|
|
cd.no_rot_axis = no_rot_axis; /* option to only rotate for XY, for example */
|
Two wonderful new NLA & Armature editing features!
- FORWARD CYCLING & MATCHING
Up to no now, adding multiple actions in NLA with walkcycles required to
animate them standing still, as if walking on a conveyor belt. The stride
option then makes the object itself move forward, trying to keep the foot
stuck on the floor (with poor results!).
This option now allows to make walk cycles moving forward. By
indicating a reference Offset Bone, the NLA system will use that bone to
detect the correct offset for the Armature Pose to make it seamlessly going
forward.
Best of all, this option works as for cyclic Action Strips as well as for
individual Action Strips. Note that for individual strips, you have to set
the strip on "Hold". (Might become automatic detected later).
Here's an example edit image for NLA:
http://www.blender.org/bf/nla_match-cycle.jpg
And the animation for it:
http://download.blender.org/demo/test/2.43/0001_0150_match.avi
Blender file:
http://download.blender.org/demo/test/2.43/mancandy_matching.blend
Using this kind of cycling works pretty straightforward, and is a lot
easier to setup than Stride Bones.
To be further tested:
- Blending cycles
- matching rotation for the bones as well.
- ACTION MODIFIERS (motion deformors)
The above option was actually required for this feature. Typically walk
cycles are constructed with certain Bones to be the handles, controlling
for example the torso or feet.
An Action Modifier allows you to use a Curve Path to deform the motion of
these controlling bones. This uses the existing Curve Deformation option.
Modifiers can be added per Action Strip, each controlling a channel (bone)
by choice, and even allows to layer multiple modifiers on top of each other
(several paths deforming motion). This option is using the dependency graph,
so editing the Curve will give realtime changes in the Armature.
The previous walkcycle, controlled by two curves:
http://download.blender.org/demo/test/2.43/0001_0150_deform.avi
Blender file:
http://download.blender.org/demo/test/2.43/mancandy_actiondeform.blend
Action Modifiers can be added in the NLA Properties Panel. Per Modifier you
have to indicate the channel and a Curve Object. You can copy modifiers from
one strip to another using CTRL+C (only copies to active Object strips).
Setting up a correct Curve Path has to be carefully done:
- Use SHIFT+A "Curve Path" in top view, or ensure the path is not rotated.
- make sure the center point of the Curve Object is at the center of the
Armature (or above)
- move the first point of the curve to the center point as well.
- check if the path starts from this first point, you can change it using
(in Curve EditMode) the option Wkey -> "Switch Direction"
- Make sure alignment uses the correct axis; if the Armature walks into
the negative Y direction, you have to set in Object Buttons, "Anim settings"
Panel, the correct Track option. (Note; option will probably move to the
Modifier later).
This is a good reason to make such paths automatic (on a command). Is on the
todo list.
Also note this:
- the Curve Path extends in beginning and ending, that's (for now) the default,
and allows to use multiple paths. Make sure paths begin and end horizontal.
- Moving the Curve in Object Mode will change the "mapping" (as if the landscape
a character walks over moves). Moving the Curve in Edit Mode will change the
actual position of the deformation.
- Speed (Ipos) on paths is not supported yet, will be done.
- The Curve "Stretch" deform option doesn't work.
- Modifiers are executed *after* all actions in NLA are evaluated, there's no
support yet for blending multiple strips with Modifiers.
- This doesn't work yet for time-mapping...
This commit is mostly for review by character animators... some details or
working methods might change.
This feature can also be used for other modifiers, such as noise (Perlin) or
the mythical "Oomph" (frequency control) and of course Python.
Special thanks to Bassam & Matt for research & design help. Have fun!
2006-10-31 15:51:57 +00:00
|
|
|
|
2010-08-06 05:19:00 +00:00
|
|
|
copy_v3_v3(cd.dmin, orco);
|
|
|
|
|
copy_v3_v3(cd.dmax, orco);
|
Two wonderful new NLA & Armature editing features!
- FORWARD CYCLING & MATCHING
Up to no now, adding multiple actions in NLA with walkcycles required to
animate them standing still, as if walking on a conveyor belt. The stride
option then makes the object itself move forward, trying to keep the foot
stuck on the floor (with poor results!).
This option now allows to make walk cycles moving forward. By
indicating a reference Offset Bone, the NLA system will use that bone to
detect the correct offset for the Armature Pose to make it seamlessly going
forward.
Best of all, this option works as for cyclic Action Strips as well as for
individual Action Strips. Note that for individual strips, you have to set
the strip on "Hold". (Might become automatic detected later).
Here's an example edit image for NLA:
http://www.blender.org/bf/nla_match-cycle.jpg
And the animation for it:
http://download.blender.org/demo/test/2.43/0001_0150_match.avi
Blender file:
http://download.blender.org/demo/test/2.43/mancandy_matching.blend
Using this kind of cycling works pretty straightforward, and is a lot
easier to setup than Stride Bones.
To be further tested:
- Blending cycles
- matching rotation for the bones as well.
- ACTION MODIFIERS (motion deformors)
The above option was actually required for this feature. Typically walk
cycles are constructed with certain Bones to be the handles, controlling
for example the torso or feet.
An Action Modifier allows you to use a Curve Path to deform the motion of
these controlling bones. This uses the existing Curve Deformation option.
Modifiers can be added per Action Strip, each controlling a channel (bone)
by choice, and even allows to layer multiple modifiers on top of each other
(several paths deforming motion). This option is using the dependency graph,
so editing the Curve will give realtime changes in the Armature.
The previous walkcycle, controlled by two curves:
http://download.blender.org/demo/test/2.43/0001_0150_deform.avi
Blender file:
http://download.blender.org/demo/test/2.43/mancandy_actiondeform.blend
Action Modifiers can be added in the NLA Properties Panel. Per Modifier you
have to indicate the channel and a Curve Object. You can copy modifiers from
one strip to another using CTRL+C (only copies to active Object strips).
Setting up a correct Curve Path has to be carefully done:
- Use SHIFT+A "Curve Path" in top view, or ensure the path is not rotated.
- make sure the center point of the Curve Object is at the center of the
Armature (or above)
- move the first point of the curve to the center point as well.
- check if the path starts from this first point, you can change it using
(in Curve EditMode) the option Wkey -> "Switch Direction"
- Make sure alignment uses the correct axis; if the Armature walks into
the negative Y direction, you have to set in Object Buttons, "Anim settings"
Panel, the correct Track option. (Note; option will probably move to the
Modifier later).
This is a good reason to make such paths automatic (on a command). Is on the
todo list.
Also note this:
- the Curve Path extends in beginning and ending, that's (for now) the default,
and allows to use multiple paths. Make sure paths begin and end horizontal.
- Moving the Curve in Object Mode will change the "mapping" (as if the landscape
a character walks over moves). Moving the Curve in Edit Mode will change the
actual position of the deformation.
- Speed (Ipos) on paths is not supported yet, will be done.
- The Curve "Stretch" deform option doesn't work.
- Modifiers are executed *after* all actions in NLA are evaluated, there's no
support yet for blending multiple strips with Modifiers.
- This doesn't work yet for time-mapping...
This commit is mostly for review by character animators... some details or
working methods might change.
This feature can also be used for other modifiers, such as noise (Perlin) or
the mythical "Oomph" (frequency control) and of course Python.
Special thanks to Bassam & Matt for research & design help. Have fun!
2006-10-31 15:51:57 +00:00
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
mul_m4_v3(cd.curvespace, vec);
|
Two wonderful new NLA & Armature editing features!
- FORWARD CYCLING & MATCHING
Up to no now, adding multiple actions in NLA with walkcycles required to
animate them standing still, as if walking on a conveyor belt. The stride
option then makes the object itself move forward, trying to keep the foot
stuck on the floor (with poor results!).
This option now allows to make walk cycles moving forward. By
indicating a reference Offset Bone, the NLA system will use that bone to
detect the correct offset for the Armature Pose to make it seamlessly going
forward.
Best of all, this option works as for cyclic Action Strips as well as for
individual Action Strips. Note that for individual strips, you have to set
the strip on "Hold". (Might become automatic detected later).
Here's an example edit image for NLA:
http://www.blender.org/bf/nla_match-cycle.jpg
And the animation for it:
http://download.blender.org/demo/test/2.43/0001_0150_match.avi
Blender file:
http://download.blender.org/demo/test/2.43/mancandy_matching.blend
Using this kind of cycling works pretty straightforward, and is a lot
easier to setup than Stride Bones.
To be further tested:
- Blending cycles
- matching rotation for the bones as well.
- ACTION MODIFIERS (motion deformors)
The above option was actually required for this feature. Typically walk
cycles are constructed with certain Bones to be the handles, controlling
for example the torso or feet.
An Action Modifier allows you to use a Curve Path to deform the motion of
these controlling bones. This uses the existing Curve Deformation option.
Modifiers can be added per Action Strip, each controlling a channel (bone)
by choice, and even allows to layer multiple modifiers on top of each other
(several paths deforming motion). This option is using the dependency graph,
so editing the Curve will give realtime changes in the Armature.
The previous walkcycle, controlled by two curves:
http://download.blender.org/demo/test/2.43/0001_0150_deform.avi
Blender file:
http://download.blender.org/demo/test/2.43/mancandy_actiondeform.blend
Action Modifiers can be added in the NLA Properties Panel. Per Modifier you
have to indicate the channel and a Curve Object. You can copy modifiers from
one strip to another using CTRL+C (only copies to active Object strips).
Setting up a correct Curve Path has to be carefully done:
- Use SHIFT+A "Curve Path" in top view, or ensure the path is not rotated.
- make sure the center point of the Curve Object is at the center of the
Armature (or above)
- move the first point of the curve to the center point as well.
- check if the path starts from this first point, you can change it using
(in Curve EditMode) the option Wkey -> "Switch Direction"
- Make sure alignment uses the correct axis; if the Armature walks into
the negative Y direction, you have to set in Object Buttons, "Anim settings"
Panel, the correct Track option. (Note; option will probably move to the
Modifier later).
This is a good reason to make such paths automatic (on a command). Is on the
todo list.
Also note this:
- the Curve Path extends in beginning and ending, that's (for now) the default,
and allows to use multiple paths. Make sure paths begin and end horizontal.
- Moving the Curve in Object Mode will change the "mapping" (as if the landscape
a character walks over moves). Moving the Curve in Edit Mode will change the
actual position of the deformation.
- Speed (Ipos) on paths is not supported yet, will be done.
- The Curve "Stretch" deform option doesn't work.
- Modifiers are executed *after* all actions in NLA are evaluated, there's no
support yet for blending multiple strips with Modifiers.
- This doesn't work yet for time-mapping...
This commit is mostly for review by character animators... some details or
working methods might change.
This feature can also be used for other modifiers, such as noise (Perlin) or
the mythical "Oomph" (frequency control) and of course Python.
Special thanks to Bassam & Matt for research & design help. Have fun!
2006-10-31 15:51:57 +00:00
|
|
|
|
2017-11-20 12:37:11 +01:00
|
|
|
if (calc_curve_deform(cuOb, vec, target->trackflag, &cd, quat)) {
|
Two wonderful new NLA & Armature editing features!
- FORWARD CYCLING & MATCHING
Up to no now, adding multiple actions in NLA with walkcycles required to
animate them standing still, as if walking on a conveyor belt. The stride
option then makes the object itself move forward, trying to keep the foot
stuck on the floor (with poor results!).
This option now allows to make walk cycles moving forward. By
indicating a reference Offset Bone, the NLA system will use that bone to
detect the correct offset for the Armature Pose to make it seamlessly going
forward.
Best of all, this option works as for cyclic Action Strips as well as for
individual Action Strips. Note that for individual strips, you have to set
the strip on "Hold". (Might become automatic detected later).
Here's an example edit image for NLA:
http://www.blender.org/bf/nla_match-cycle.jpg
And the animation for it:
http://download.blender.org/demo/test/2.43/0001_0150_match.avi
Blender file:
http://download.blender.org/demo/test/2.43/mancandy_matching.blend
Using this kind of cycling works pretty straightforward, and is a lot
easier to setup than Stride Bones.
To be further tested:
- Blending cycles
- matching rotation for the bones as well.
- ACTION MODIFIERS (motion deformors)
The above option was actually required for this feature. Typically walk
cycles are constructed with certain Bones to be the handles, controlling
for example the torso or feet.
An Action Modifier allows you to use a Curve Path to deform the motion of
these controlling bones. This uses the existing Curve Deformation option.
Modifiers can be added per Action Strip, each controlling a channel (bone)
by choice, and even allows to layer multiple modifiers on top of each other
(several paths deforming motion). This option is using the dependency graph,
so editing the Curve will give realtime changes in the Armature.
The previous walkcycle, controlled by two curves:
http://download.blender.org/demo/test/2.43/0001_0150_deform.avi
Blender file:
http://download.blender.org/demo/test/2.43/mancandy_actiondeform.blend
Action Modifiers can be added in the NLA Properties Panel. Per Modifier you
have to indicate the channel and a Curve Object. You can copy modifiers from
one strip to another using CTRL+C (only copies to active Object strips).
Setting up a correct Curve Path has to be carefully done:
- Use SHIFT+A "Curve Path" in top view, or ensure the path is not rotated.
- make sure the center point of the Curve Object is at the center of the
Armature (or above)
- move the first point of the curve to the center point as well.
- check if the path starts from this first point, you can change it using
(in Curve EditMode) the option Wkey -> "Switch Direction"
- Make sure alignment uses the correct axis; if the Armature walks into
the negative Y direction, you have to set in Object Buttons, "Anim settings"
Panel, the correct Track option. (Note; option will probably move to the
Modifier later).
This is a good reason to make such paths automatic (on a command). Is on the
todo list.
Also note this:
- the Curve Path extends in beginning and ending, that's (for now) the default,
and allows to use multiple paths. Make sure paths begin and end horizontal.
- Moving the Curve in Object Mode will change the "mapping" (as if the landscape
a character walks over moves). Moving the Curve in Edit Mode will change the
actual position of the deformation.
- Speed (Ipos) on paths is not supported yet, will be done.
- The Curve "Stretch" deform option doesn't work.
- Modifiers are executed *after* all actions in NLA are evaluated, there's no
support yet for blending multiple strips with Modifiers.
- This doesn't work yet for time-mapping...
This commit is mostly for review by character animators... some details or
working methods might change.
This feature can also be used for other modifiers, such as noise (Perlin) or
the mythical "Oomph" (frequency control) and of course Python.
Special thanks to Bassam & Matt for research & design help. Have fun!
2006-10-31 15:51:57 +00:00
|
|
|
float qmat[3][3];
|
|
|
|
|
|
2012-04-29 15:47:02 +00:00
|
|
|
quat_to_mat3(qmat, quat);
|
2009-11-10 20:43:45 +00:00
|
|
|
mul_m3_m3m3(mat, qmat, cd.objectspace3);
|
Two wonderful new NLA & Armature editing features!
- FORWARD CYCLING & MATCHING
Up to no now, adding multiple actions in NLA with walkcycles required to
animate them standing still, as if walking on a conveyor belt. The stride
option then makes the object itself move forward, trying to keep the foot
stuck on the floor (with poor results!).
This option now allows to make walk cycles moving forward. By
indicating a reference Offset Bone, the NLA system will use that bone to
detect the correct offset for the Armature Pose to make it seamlessly going
forward.
Best of all, this option works as for cyclic Action Strips as well as for
individual Action Strips. Note that for individual strips, you have to set
the strip on "Hold". (Might become automatic detected later).
Here's an example edit image for NLA:
http://www.blender.org/bf/nla_match-cycle.jpg
And the animation for it:
http://download.blender.org/demo/test/2.43/0001_0150_match.avi
Blender file:
http://download.blender.org/demo/test/2.43/mancandy_matching.blend
Using this kind of cycling works pretty straightforward, and is a lot
easier to setup than Stride Bones.
To be further tested:
- Blending cycles
- matching rotation for the bones as well.
- ACTION MODIFIERS (motion deformors)
The above option was actually required for this feature. Typically walk
cycles are constructed with certain Bones to be the handles, controlling
for example the torso or feet.
An Action Modifier allows you to use a Curve Path to deform the motion of
these controlling bones. This uses the existing Curve Deformation option.
Modifiers can be added per Action Strip, each controlling a channel (bone)
by choice, and even allows to layer multiple modifiers on top of each other
(several paths deforming motion). This option is using the dependency graph,
so editing the Curve will give realtime changes in the Armature.
The previous walkcycle, controlled by two curves:
http://download.blender.org/demo/test/2.43/0001_0150_deform.avi
Blender file:
http://download.blender.org/demo/test/2.43/mancandy_actiondeform.blend
Action Modifiers can be added in the NLA Properties Panel. Per Modifier you
have to indicate the channel and a Curve Object. You can copy modifiers from
one strip to another using CTRL+C (only copies to active Object strips).
Setting up a correct Curve Path has to be carefully done:
- Use SHIFT+A "Curve Path" in top view, or ensure the path is not rotated.
- make sure the center point of the Curve Object is at the center of the
Armature (or above)
- move the first point of the curve to the center point as well.
- check if the path starts from this first point, you can change it using
(in Curve EditMode) the option Wkey -> "Switch Direction"
- Make sure alignment uses the correct axis; if the Armature walks into
the negative Y direction, you have to set in Object Buttons, "Anim settings"
Panel, the correct Track option. (Note; option will probably move to the
Modifier later).
This is a good reason to make such paths automatic (on a command). Is on the
todo list.
Also note this:
- the Curve Path extends in beginning and ending, that's (for now) the default,
and allows to use multiple paths. Make sure paths begin and end horizontal.
- Moving the Curve in Object Mode will change the "mapping" (as if the landscape
a character walks over moves). Moving the Curve in Edit Mode will change the
actual position of the deformation.
- Speed (Ipos) on paths is not supported yet, will be done.
- The Curve "Stretch" deform option doesn't work.
- Modifiers are executed *after* all actions in NLA are evaluated, there's no
support yet for blending multiple strips with Modifiers.
- This doesn't work yet for time-mapping...
This commit is mostly for review by character animators... some details or
working methods might change.
This feature can also be used for other modifiers, such as noise (Perlin) or
the mythical "Oomph" (frequency control) and of course Python.
Special thanks to Bassam & Matt for research & design help. Have fun!
2006-10-31 15:51:57 +00:00
|
|
|
}
|
|
|
|
|
else
|
2009-11-10 20:43:45 +00:00
|
|
|
unit_m3(mat);
|
Two wonderful new NLA & Armature editing features!
- FORWARD CYCLING & MATCHING
Up to no now, adding multiple actions in NLA with walkcycles required to
animate them standing still, as if walking on a conveyor belt. The stride
option then makes the object itself move forward, trying to keep the foot
stuck on the floor (with poor results!).
This option now allows to make walk cycles moving forward. By
indicating a reference Offset Bone, the NLA system will use that bone to
detect the correct offset for the Armature Pose to make it seamlessly going
forward.
Best of all, this option works as for cyclic Action Strips as well as for
individual Action Strips. Note that for individual strips, you have to set
the strip on "Hold". (Might become automatic detected later).
Here's an example edit image for NLA:
http://www.blender.org/bf/nla_match-cycle.jpg
And the animation for it:
http://download.blender.org/demo/test/2.43/0001_0150_match.avi
Blender file:
http://download.blender.org/demo/test/2.43/mancandy_matching.blend
Using this kind of cycling works pretty straightforward, and is a lot
easier to setup than Stride Bones.
To be further tested:
- Blending cycles
- matching rotation for the bones as well.
- ACTION MODIFIERS (motion deformors)
The above option was actually required for this feature. Typically walk
cycles are constructed with certain Bones to be the handles, controlling
for example the torso or feet.
An Action Modifier allows you to use a Curve Path to deform the motion of
these controlling bones. This uses the existing Curve Deformation option.
Modifiers can be added per Action Strip, each controlling a channel (bone)
by choice, and even allows to layer multiple modifiers on top of each other
(several paths deforming motion). This option is using the dependency graph,
so editing the Curve will give realtime changes in the Armature.
The previous walkcycle, controlled by two curves:
http://download.blender.org/demo/test/2.43/0001_0150_deform.avi
Blender file:
http://download.blender.org/demo/test/2.43/mancandy_actiondeform.blend
Action Modifiers can be added in the NLA Properties Panel. Per Modifier you
have to indicate the channel and a Curve Object. You can copy modifiers from
one strip to another using CTRL+C (only copies to active Object strips).
Setting up a correct Curve Path has to be carefully done:
- Use SHIFT+A "Curve Path" in top view, or ensure the path is not rotated.
- make sure the center point of the Curve Object is at the center of the
Armature (or above)
- move the first point of the curve to the center point as well.
- check if the path starts from this first point, you can change it using
(in Curve EditMode) the option Wkey -> "Switch Direction"
- Make sure alignment uses the correct axis; if the Armature walks into
the negative Y direction, you have to set in Object Buttons, "Anim settings"
Panel, the correct Track option. (Note; option will probably move to the
Modifier later).
This is a good reason to make such paths automatic (on a command). Is on the
todo list.
Also note this:
- the Curve Path extends in beginning and ending, that's (for now) the default,
and allows to use multiple paths. Make sure paths begin and end horizontal.
- Moving the Curve in Object Mode will change the "mapping" (as if the landscape
a character walks over moves). Moving the Curve in Edit Mode will change the
actual position of the deformation.
- Speed (Ipos) on paths is not supported yet, will be done.
- The Curve "Stretch" deform option doesn't work.
- Modifiers are executed *after* all actions in NLA are evaluated, there's no
support yet for blending multiple strips with Modifiers.
- This doesn't work yet for time-mapping...
This commit is mostly for review by character animators... some details or
working methods might change.
This feature can also be used for other modifiers, such as noise (Perlin) or
the mythical "Oomph" (frequency control) and of course Python.
Special thanks to Bassam & Matt for research & design help. Have fun!
2006-10-31 15:51:57 +00:00
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
mul_m4_v3(cd.objectspace, vec);
|
Two wonderful new NLA & Armature editing features!
- FORWARD CYCLING & MATCHING
Up to no now, adding multiple actions in NLA with walkcycles required to
animate them standing still, as if walking on a conveyor belt. The stride
option then makes the object itself move forward, trying to keep the foot
stuck on the floor (with poor results!).
This option now allows to make walk cycles moving forward. By
indicating a reference Offset Bone, the NLA system will use that bone to
detect the correct offset for the Armature Pose to make it seamlessly going
forward.
Best of all, this option works as for cyclic Action Strips as well as for
individual Action Strips. Note that for individual strips, you have to set
the strip on "Hold". (Might become automatic detected later).
Here's an example edit image for NLA:
http://www.blender.org/bf/nla_match-cycle.jpg
And the animation for it:
http://download.blender.org/demo/test/2.43/0001_0150_match.avi
Blender file:
http://download.blender.org/demo/test/2.43/mancandy_matching.blend
Using this kind of cycling works pretty straightforward, and is a lot
easier to setup than Stride Bones.
To be further tested:
- Blending cycles
- matching rotation for the bones as well.
- ACTION MODIFIERS (motion deformors)
The above option was actually required for this feature. Typically walk
cycles are constructed with certain Bones to be the handles, controlling
for example the torso or feet.
An Action Modifier allows you to use a Curve Path to deform the motion of
these controlling bones. This uses the existing Curve Deformation option.
Modifiers can be added per Action Strip, each controlling a channel (bone)
by choice, and even allows to layer multiple modifiers on top of each other
(several paths deforming motion). This option is using the dependency graph,
so editing the Curve will give realtime changes in the Armature.
The previous walkcycle, controlled by two curves:
http://download.blender.org/demo/test/2.43/0001_0150_deform.avi
Blender file:
http://download.blender.org/demo/test/2.43/mancandy_actiondeform.blend
Action Modifiers can be added in the NLA Properties Panel. Per Modifier you
have to indicate the channel and a Curve Object. You can copy modifiers from
one strip to another using CTRL+C (only copies to active Object strips).
Setting up a correct Curve Path has to be carefully done:
- Use SHIFT+A "Curve Path" in top view, or ensure the path is not rotated.
- make sure the center point of the Curve Object is at the center of the
Armature (or above)
- move the first point of the curve to the center point as well.
- check if the path starts from this first point, you can change it using
(in Curve EditMode) the option Wkey -> "Switch Direction"
- Make sure alignment uses the correct axis; if the Armature walks into
the negative Y direction, you have to set in Object Buttons, "Anim settings"
Panel, the correct Track option. (Note; option will probably move to the
Modifier later).
This is a good reason to make such paths automatic (on a command). Is on the
todo list.
Also note this:
- the Curve Path extends in beginning and ending, that's (for now) the default,
and allows to use multiple paths. Make sure paths begin and end horizontal.
- Moving the Curve in Object Mode will change the "mapping" (as if the landscape
a character walks over moves). Moving the Curve in Edit Mode will change the
actual position of the deformation.
- Speed (Ipos) on paths is not supported yet, will be done.
- The Curve "Stretch" deform option doesn't work.
- Modifiers are executed *after* all actions in NLA are evaluated, there's no
support yet for blending multiple strips with Modifiers.
- This doesn't work yet for time-mapping...
This commit is mostly for review by character animators... some details or
working methods might change.
This feature can also be used for other modifiers, such as noise (Perlin) or
the mythical "Oomph" (frequency control) and of course Python.
Special thanks to Bassam & Matt for research & design help. Have fun!
2006-10-31 15:51:57 +00:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-28 01:12:36 +00:00
|
|
|
void lattice_deform_verts(Object *laOb, Object *target, DerivedMesh *dm,
|
2012-03-26 00:42:21 +00:00
|
|
|
float (*vertexCos)[3], int numVerts, const char *vgroup, float fac)
|
2005-07-19 20:14:17 +00:00
|
|
|
{
|
2013-08-19 10:11:48 +00:00
|
|
|
LatticeDeformData *lattice_deform_data;
|
2005-07-19 20:14:17 +00:00
|
|
|
int a;
|
2014-04-01 11:34:00 +11:00
|
|
|
bool use_vgroups;
|
2005-07-19 02:36:21 +00:00
|
|
|
|
2012-02-23 02:17:50 +00:00
|
|
|
if (laOb->type != OB_LATTICE)
|
2008-04-04 12:33:01 +00:00
|
|
|
return;
|
|
|
|
|
|
2013-08-19 10:11:48 +00:00
|
|
|
lattice_deform_data = init_latt_deform(laOb, target);
|
2006-08-28 01:12:36 +00:00
|
|
|
|
|
|
|
|
/* check whether to use vertex groups (only possible if target is a Mesh)
|
|
|
|
|
* we want either a Mesh with no derived data, or derived data with
|
|
|
|
|
* deformverts
|
|
|
|
|
*/
|
2012-05-06 15:15:33 +00:00
|
|
|
if (target && target->type == OB_MESH) {
|
2006-08-28 01:12:36 +00:00
|
|
|
/* if there's derived data without deformverts, don't use vgroups */
|
2012-05-19 13:28:19 +00:00
|
|
|
if (dm) {
|
2014-03-05 15:11:36 +01:00
|
|
|
use_vgroups = (dm->getVertDataArray(dm, CD_MDEFORMVERT) != NULL);
|
2012-05-19 13:28:19 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-05-22 09:00:34 +00:00
|
|
|
Mesh *me = target->data;
|
|
|
|
|
use_vgroups = (me->dvert != NULL);
|
2012-05-19 13:28:19 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2014-04-01 11:34:00 +11:00
|
|
|
use_vgroups = false;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
2006-08-28 01:12:36 +00:00
|
|
|
|
2012-02-23 02:17:50 +00:00
|
|
|
if (vgroup && vgroup[0] && use_vgroups) {
|
2006-08-28 01:12:36 +00:00
|
|
|
Mesh *me = target->data;
|
2012-10-22 17:19:05 +00:00
|
|
|
const int defgrp_index = defgroup_name_index(target, vgroup);
|
2010-06-13 00:11:42 +00:00
|
|
|
float weight;
|
2006-08-28 01:12:36 +00:00
|
|
|
|
2012-10-22 17:19:05 +00:00
|
|
|
if (defgrp_index >= 0 && (me->dvert || dm)) {
|
2006-08-28 01:12:36 +00:00
|
|
|
MDeformVert *dvert = me->dvert;
|
2005-10-20 18:52:29 +00:00
|
|
|
|
2012-02-23 02:17:50 +00:00
|
|
|
for (a = 0; a < numVerts; a++, dvert++) {
|
|
|
|
|
if (dm) dvert = dm->getVertData(dm, a, CD_MDEFORMVERT);
|
2010-06-13 00:11:42 +00:00
|
|
|
|
2012-10-22 17:19:05 +00:00
|
|
|
weight = defvert_find_weight(dvert, defgrp_index);
|
2010-06-13 00:11:42 +00:00
|
|
|
|
2012-02-23 02:17:50 +00:00
|
|
|
if (weight > 0.0f)
|
2013-08-19 10:11:48 +00:00
|
|
|
calc_latt_deform(lattice_deform_data, vertexCos[a], weight * fac);
|
2005-10-20 18:52:29 +00:00
|
|
|
}
|
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-02-23 02:17:50 +00:00
|
|
|
for (a = 0; a < numVerts; a++) {
|
2013-08-19 10:11:48 +00:00
|
|
|
calc_latt_deform(lattice_deform_data, vertexCos[a], fac);
|
2005-10-20 18:52:29 +00:00
|
|
|
}
|
2005-07-19 02:36:21 +00:00
|
|
|
}
|
2013-08-19 10:11:48 +00:00
|
|
|
end_latt_deform(lattice_deform_data);
|
2005-07-19 20:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
2014-02-05 22:36:15 +11:00
|
|
|
bool object_deform_mball(Object *ob, ListBase *dispbase)
|
2005-07-19 02:36:21 +00:00
|
|
|
{
|
2012-05-06 15:15:33 +00:00
|
|
|
if (ob->parent && ob->parent->type == OB_LATTICE && ob->partype == PARSKEL) {
|
2005-08-14 06:08:41 +00:00
|
|
|
DispList *dl;
|
2005-07-19 02:36:21 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (dl = dispbase->first; dl; dl = dl->next) {
|
2006-08-28 01:12:36 +00:00
|
|
|
lattice_deform_verts(ob->parent, ob, NULL,
|
2012-05-06 15:15:33 +00:00
|
|
|
(float(*)[3])dl->verts, dl->nr, NULL, 1.0f);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2005-08-14 06:08:41 +00:00
|
|
|
|
2014-12-01 17:11:18 +01:00
|
|
|
return true;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2014-12-01 17:11:18 +01:00
|
|
|
return false;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2005-08-14 06:08:41 +00:00
|
|
|
}
|
|
|
|
|
|
2005-08-15 10:30:53 +00:00
|
|
|
static BPoint *latt_bp(Lattice *lt, int u, int v, int w)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2013-06-24 13:45:35 +00:00
|
|
|
return <->def[BKE_lattice_index_from_uvw(lt, u, v, w)];
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void outside_lattice(Lattice *lt)
|
|
|
|
|
{
|
|
|
|
|
BPoint *bp, *bp1, *bp2;
|
|
|
|
|
int u, v, w;
|
2012-05-06 15:15:33 +00:00
|
|
|
float fac1, du = 0.0, dv = 0.0, dw = 0.0;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-02-23 02:17:50 +00:00
|
|
|
if (lt->flag & LT_OUTSIDE) {
|
2012-05-06 15:15:33 +00:00
|
|
|
bp = lt->def;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (lt->pntsu > 1) du = 1.0f / ((float)lt->pntsu - 1);
|
|
|
|
|
if (lt->pntsv > 1) dv = 1.0f / ((float)lt->pntsv - 1);
|
|
|
|
|
if (lt->pntsw > 1) dw = 1.0f / ((float)lt->pntsw - 1);
|
2009-07-03 15:23:33 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (w = 0; w < lt->pntsw; w++) {
|
2009-07-03 15:23:33 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (v = 0; v < lt->pntsv; v++) {
|
2009-07-03 15:23:33 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (u = 0; u < lt->pntsu; u++, bp++) {
|
2012-10-07 09:48:59 +00:00
|
|
|
if (u == 0 || v == 0 || w == 0 || u == lt->pntsu - 1 || v == lt->pntsv - 1 || w == lt->pntsw - 1) {
|
|
|
|
|
/* pass */
|
|
|
|
|
}
|
2009-07-03 15:23:33 +00:00
|
|
|
else {
|
2012-05-06 15:15:33 +00:00
|
|
|
bp->hide = 1;
|
2009-07-03 15:23:33 +00:00
|
|
|
bp->f1 &= ~SELECT;
|
|
|
|
|
|
|
|
|
|
/* u extrema */
|
2012-05-06 15:15:33 +00:00
|
|
|
bp1 = latt_bp(lt, 0, v, w);
|
|
|
|
|
bp2 = latt_bp(lt, lt->pntsu - 1, v, w);
|
2009-07-03 15:23:33 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
fac1 = du * u;
|
|
|
|
|
bp->vec[0] = (1.0f - fac1) * bp1->vec[0] + fac1 * bp2->vec[0];
|
|
|
|
|
bp->vec[1] = (1.0f - fac1) * bp1->vec[1] + fac1 * bp2->vec[1];
|
|
|
|
|
bp->vec[2] = (1.0f - fac1) * bp1->vec[2] + fac1 * bp2->vec[2];
|
2009-07-03 15:23:33 +00:00
|
|
|
|
|
|
|
|
/* v extrema */
|
2012-05-06 15:15:33 +00:00
|
|
|
bp1 = latt_bp(lt, u, 0, w);
|
|
|
|
|
bp2 = latt_bp(lt, u, lt->pntsv - 1, w);
|
2009-07-03 15:23:33 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
fac1 = dv * v;
|
|
|
|
|
bp->vec[0] += (1.0f - fac1) * bp1->vec[0] + fac1 * bp2->vec[0];
|
|
|
|
|
bp->vec[1] += (1.0f - fac1) * bp1->vec[1] + fac1 * bp2->vec[1];
|
|
|
|
|
bp->vec[2] += (1.0f - fac1) * bp1->vec[2] + fac1 * bp2->vec[2];
|
2009-07-03 15:23:33 +00:00
|
|
|
|
|
|
|
|
/* w extrema */
|
2012-05-06 15:15:33 +00:00
|
|
|
bp1 = latt_bp(lt, u, v, 0);
|
|
|
|
|
bp2 = latt_bp(lt, u, v, lt->pntsw - 1);
|
2009-07-03 15:23:33 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
fac1 = dw * w;
|
|
|
|
|
bp->vec[0] += (1.0f - fac1) * bp1->vec[0] + fac1 * bp2->vec[0];
|
|
|
|
|
bp->vec[1] += (1.0f - fac1) * bp1->vec[1] + fac1 * bp2->vec[1];
|
|
|
|
|
bp->vec[2] += (1.0f - fac1) * bp1->vec[2] + fac1 * bp2->vec[2];
|
2009-07-03 15:23:33 +00:00
|
|
|
|
2013-02-14 17:35:43 +00:00
|
|
|
mul_v3_fl(bp->vec, 1.0f / 3.0f);
|
2009-07-03 15:23:33 +00:00
|
|
|
|
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2009-07-03 15:23:33 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-07-03 15:23:33 +00:00
|
|
|
else {
|
2012-05-06 15:15:33 +00:00
|
|
|
bp = lt->def;
|
2009-07-03 15:23:33 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (w = 0; w < lt->pntsw; w++)
|
|
|
|
|
for (v = 0; v < lt->pntsv; v++)
|
|
|
|
|
for (u = 0; u < lt->pntsu; u++, bp++)
|
|
|
|
|
bp->hide = 0;
|
2009-07-03 15:23:33 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2005-08-15 10:30:53 +00:00
|
|
|
|
2014-03-16 03:24:05 +11:00
|
|
|
float (*BKE_lattice_vertexcos_get(struct Object *ob, int *r_numVerts))[3]
|
2005-08-15 10:30:53 +00:00
|
|
|
{
|
2009-01-02 19:10:35 +00:00
|
|
|
Lattice *lt = ob->data;
|
|
|
|
|
int i, numVerts;
|
2009-01-06 12:30:44 +00:00
|
|
|
float (*vertexCos)[3];
|
2005-08-15 10:30:53 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (lt->editlatt) lt = lt->editlatt->latt;
|
2014-03-16 03:24:05 +11:00
|
|
|
numVerts = *r_numVerts = lt->pntsu * lt->pntsv * lt->pntsw;
|
2009-01-02 19:10:35 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
vertexCos = MEM_mallocN(sizeof(*vertexCos) * numVerts, "lt_vcos");
|
2009-01-06 12:30:44 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (i = 0; i < numVerts; i++) {
|
2010-08-06 05:19:00 +00:00
|
|
|
copy_v3_v3(vertexCos[i], lt->def[i].vec);
|
2005-08-15 10:30:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return vertexCos;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-05 16:03:57 +00:00
|
|
|
void BKE_lattice_vertexcos_apply(struct Object *ob, float (*vertexCos)[3])
|
2005-08-15 10:30:53 +00:00
|
|
|
{
|
|
|
|
|
Lattice *lt = ob->data;
|
2012-05-06 15:15:33 +00:00
|
|
|
int i, numVerts = lt->pntsu * lt->pntsv * lt->pntsw;
|
2005-08-15 10:30:53 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (i = 0; i < numVerts; i++) {
|
2010-08-06 05:19:00 +00:00
|
|
|
copy_v3_v3(lt->def[i].vec, vertexCos[i]);
|
2005-08-15 10:30:53 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
void BKE_lattice_modifiers_calc(struct Depsgraph *depsgraph, Scene *scene, Object *ob)
|
2005-08-15 10:30:53 +00:00
|
|
|
{
|
2012-05-06 15:15:33 +00:00
|
|
|
Lattice *lt = ob->data;
|
2013-08-19 09:05:34 +00:00
|
|
|
VirtualModifierData virtualModifierData;
|
|
|
|
|
ModifierData *md = modifiers_getVirtualModifierList(ob, &virtualModifierData);
|
2009-01-02 19:10:35 +00:00
|
|
|
float (*vertexCos)[3] = NULL;
|
2012-05-06 15:15:33 +00:00
|
|
|
int numVerts, editmode = (lt->editlatt != NULL);
|
2005-08-15 10:30:53 +00:00
|
|
|
|
2013-08-19 09:25:24 +00:00
|
|
|
if (ob->curve_cache) {
|
|
|
|
|
BKE_displist_free(&ob->curve_cache->disp);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
ob->curve_cache = MEM_callocN(sizeof(CurveCache), "CurveCache for lattice");
|
|
|
|
|
}
|
2005-08-15 10:30:53 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (; md; md = md->next) {
|
2015-03-30 21:17:07 +11:00
|
|
|
const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
|
2005-08-15 10:30:53 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
md->scene = scene;
|
2009-01-04 14:14:06 +00:00
|
|
|
|
2016-05-18 22:21:46 +10:00
|
|
|
if (!(mti->flags & eModifierTypeFlag_AcceptsLattice)) continue;
|
2012-05-06 15:15:33 +00:00
|
|
|
if (!(md->mode & eModifierMode_Realtime)) continue;
|
|
|
|
|
if (editmode && !(md->mode & eModifierMode_Editmode)) continue;
|
2009-11-25 14:07:12 +00:00
|
|
|
if (mti->isDisabled && mti->isDisabled(md, 0)) continue;
|
2012-05-06 15:15:33 +00:00
|
|
|
if (mti->type != eModifierTypeType_OnlyDeform) continue;
|
2005-08-15 10:30:53 +00:00
|
|
|
|
2012-05-05 16:03:57 +00:00
|
|
|
if (!vertexCos) vertexCos = BKE_lattice_vertexcos_get(ob, &numVerts);
|
2018-04-18 15:45:54 +02:00
|
|
|
modifier_deformVerts_DM_deprecated(md, depsgraph, ob, NULL, vertexCos, numVerts, 0);
|
2005-08-15 10:30:53 +00:00
|
|
|
}
|
|
|
|
|
|
2008-07-20 16:06:40 +00:00
|
|
|
/* always displist to make this work like derivedmesh */
|
2012-05-05 16:03:57 +00:00
|
|
|
if (!vertexCos) vertexCos = BKE_lattice_vertexcos_get(ob, &numVerts);
|
2008-07-20 16:06:40 +00:00
|
|
|
|
|
|
|
|
{
|
2005-08-15 10:30:53 +00:00
|
|
|
DispList *dl = MEM_callocN(sizeof(*dl), "lt_dl");
|
|
|
|
|
dl->type = DL_VERTS;
|
|
|
|
|
dl->parts = 1;
|
|
|
|
|
dl->nr = numVerts;
|
2012-05-06 15:15:33 +00:00
|
|
|
dl->verts = (float *) vertexCos;
|
2005-08-15 10:30:53 +00:00
|
|
|
|
2013-08-19 09:25:24 +00:00
|
|
|
BLI_addtail(&ob->curve_cache->disp, dl);
|
2005-08-15 10:30:53 +00:00
|
|
|
}
|
|
|
|
|
}
|
2008-11-03 23:17:36 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
struct MDeformVert *BKE_lattice_deform_verts_get(struct Object *oblatt)
|
2008-11-03 23:17:36 +00:00
|
|
|
{
|
2012-05-06 15:15:33 +00:00
|
|
|
Lattice *lt = (Lattice *)oblatt->data;
|
2011-03-30 02:59:32 +00:00
|
|
|
BLI_assert(oblatt->type == OB_LATTICE);
|
2012-05-06 15:15:33 +00:00
|
|
|
if (lt->editlatt) lt = lt->editlatt->latt;
|
2011-03-30 02:59:32 +00:00
|
|
|
return lt->dvert;
|
2008-11-03 23:17:36 +00:00
|
|
|
}
|
2013-02-01 15:17:39 +00:00
|
|
|
|
2013-06-09 20:28:08 +00:00
|
|
|
struct BPoint *BKE_lattice_active_point_get(Lattice *lt)
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(GS(lt->id.name) == ID_LT);
|
|
|
|
|
|
|
|
|
|
if (lt->editlatt) {
|
|
|
|
|
lt = lt->editlatt->latt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BLI_assert(lt->actbp < lt->pntsu * lt->pntsv * lt->pntsw);
|
|
|
|
|
|
|
|
|
|
if ((lt->actbp != LT_ACTBP_NONE) && (lt->actbp < lt->pntsu * lt->pntsv * lt->pntsw)) {
|
|
|
|
|
return <->def[lt->actbp];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-09 15:32:05 +11:00
|
|
|
void BKE_lattice_center_median(Lattice *lt, float cent[3])
|
2013-02-01 15:17:39 +00:00
|
|
|
{
|
|
|
|
|
int i, numVerts;
|
|
|
|
|
|
|
|
|
|
if (lt->editlatt) lt = lt->editlatt->latt;
|
|
|
|
|
numVerts = lt->pntsu * lt->pntsv * lt->pntsw;
|
|
|
|
|
|
|
|
|
|
zero_v3(cent);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < numVerts; i++)
|
|
|
|
|
add_v3_v3(cent, lt->def[i].vec);
|
|
|
|
|
|
|
|
|
|
mul_v3_fl(cent, 1.0f / (float)numVerts);
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-13 18:12:08 +02:00
|
|
|
static void boundbox_lattice(Object *ob)
|
|
|
|
|
{
|
|
|
|
|
BoundBox *bb;
|
|
|
|
|
Lattice *lt;
|
|
|
|
|
float min[3], max[3];
|
|
|
|
|
|
2016-03-04 21:50:54 +11:00
|
|
|
if (ob->bb == NULL) {
|
|
|
|
|
ob->bb = MEM_callocN(sizeof(BoundBox), "Lattice boundbox");
|
|
|
|
|
}
|
2015-08-13 18:12:08 +02:00
|
|
|
|
|
|
|
|
bb = ob->bb;
|
|
|
|
|
lt = ob->data;
|
|
|
|
|
|
|
|
|
|
INIT_MINMAX(min, max);
|
2015-08-17 16:59:32 +02:00
|
|
|
BKE_lattice_minmax_dl(ob, lt, min, max);
|
2015-08-13 18:12:08 +02:00
|
|
|
BKE_boundbox_init_from_minmax(bb, min, max);
|
2016-03-04 21:50:54 +11:00
|
|
|
|
|
|
|
|
bb->flag &= ~BOUNDBOX_DIRTY;
|
2015-08-13 18:12:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BoundBox *BKE_lattice_boundbox_get(Object *ob)
|
|
|
|
|
{
|
|
|
|
|
boundbox_lattice(ob);
|
|
|
|
|
|
|
|
|
|
return ob->bb;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-17 16:59:32 +02:00
|
|
|
void BKE_lattice_minmax_dl(Object *ob, Lattice *lt, float min[3], float max[3])
|
|
|
|
|
{
|
|
|
|
|
DispList *dl = ob->curve_cache ? BKE_displist_find(&ob->curve_cache->disp, DL_VERTS) : NULL;
|
|
|
|
|
|
|
|
|
|
if (!dl) {
|
|
|
|
|
BKE_lattice_minmax(lt, min, max);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
int i, numVerts;
|
|
|
|
|
|
|
|
|
|
if (lt->editlatt) lt = lt->editlatt->latt;
|
|
|
|
|
numVerts = lt->pntsu * lt->pntsv * lt->pntsw;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < numVerts; i++)
|
|
|
|
|
minmax_v3v3_v3(min, max, &dl->verts[i * 3]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-09 15:32:05 +11:00
|
|
|
void BKE_lattice_minmax(Lattice *lt, float min[3], float max[3])
|
2013-02-01 15:17:39 +00:00
|
|
|
{
|
|
|
|
|
int i, numVerts;
|
|
|
|
|
|
|
|
|
|
if (lt->editlatt) lt = lt->editlatt->latt;
|
|
|
|
|
numVerts = lt->pntsu * lt->pntsv * lt->pntsw;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < numVerts; i++)
|
|
|
|
|
minmax_v3v3_v3(min, max, lt->def[i].vec);
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-09 15:32:05 +11:00
|
|
|
void BKE_lattice_center_bounds(Lattice *lt, float cent[3])
|
2013-02-01 15:17:39 +00:00
|
|
|
{
|
|
|
|
|
float min[3], max[3];
|
|
|
|
|
|
|
|
|
|
INIT_MINMAX(min, max);
|
|
|
|
|
|
|
|
|
|
BKE_lattice_minmax(lt, min, max);
|
|
|
|
|
mid_v3_v3v3(cent, min, max);
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-01 20:09:31 +10:00
|
|
|
void BKE_lattice_transform(Lattice *lt, float mat[4][4], bool do_keys)
|
|
|
|
|
{
|
|
|
|
|
BPoint *bp = lt->def;
|
|
|
|
|
int i = lt->pntsu * lt->pntsv * lt->pntsw;
|
|
|
|
|
|
|
|
|
|
while (i--) {
|
|
|
|
|
mul_m4_v3(mat, bp->vec);
|
|
|
|
|
bp++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (do_keys && lt->key) {
|
|
|
|
|
KeyBlock *kb;
|
|
|
|
|
|
|
|
|
|
for (kb = lt->key->block.first; kb; kb = kb->next) {
|
|
|
|
|
float *fp = kb->data;
|
|
|
|
|
for (i = kb->totelem; i--; fp += 3) {
|
|
|
|
|
mul_m4_v3(mat, fp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-03 18:55:59 +11:00
|
|
|
void BKE_lattice_translate(Lattice *lt, float offset[3], bool do_keys)
|
2013-02-01 15:17:39 +00:00
|
|
|
{
|
|
|
|
|
int i, numVerts;
|
|
|
|
|
|
|
|
|
|
numVerts = lt->pntsu * lt->pntsv * lt->pntsw;
|
|
|
|
|
|
|
|
|
|
if (lt->def)
|
|
|
|
|
for (i = 0; i < numVerts; i++)
|
|
|
|
|
add_v3_v3(lt->def[i].vec, offset);
|
|
|
|
|
|
|
|
|
|
if (lt->editlatt)
|
|
|
|
|
for (i = 0; i < numVerts; i++)
|
|
|
|
|
add_v3_v3(lt->editlatt->latt->def[i].vec, offset);
|
|
|
|
|
|
|
|
|
|
if (do_keys && lt->key) {
|
|
|
|
|
KeyBlock *kb;
|
|
|
|
|
|
|
|
|
|
for (kb = lt->key->block.first; kb; kb = kb->next) {
|
|
|
|
|
float *fp = kb->data;
|
|
|
|
|
for (i = kb->totelem; i--; fp += 3) {
|
|
|
|
|
add_v3_v3(fp, offset);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-12 13:57:11 +05:00
|
|
|
/* **** Depsgraph evaluation **** */
|
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
void BKE_lattice_eval_geometry(struct Depsgraph *UNUSED(depsgraph),
|
2015-05-12 13:57:11 +05:00
|
|
|
Lattice *UNUSED(latt))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-21 21:14:11 +10:00
|
|
|
/* Draw Engine */
|
|
|
|
|
void (*BKE_lattice_batch_cache_dirty_cb)(Lattice *lt, int mode) = NULL;
|
|
|
|
|
void (*BKE_lattice_batch_cache_free_cb)(Lattice *lt) = NULL;
|
|
|
|
|
|
|
|
|
|
void BKE_lattice_batch_cache_dirty(Lattice *lt, int mode)
|
|
|
|
|
{
|
|
|
|
|
if (lt->batch_cache) {
|
|
|
|
|
BKE_lattice_batch_cache_dirty_cb(lt, mode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void BKE_lattice_batch_cache_free(Lattice *lt)
|
|
|
|
|
{
|
|
|
|
|
if (lt->batch_cache) {
|
|
|
|
|
BKE_lattice_batch_cache_free_cb(lt);
|
|
|
|
|
}
|
2017-07-21 11:53:13 +02:00
|
|
|
}
|