2011-02-23 10:52:22 +00:00
|
|
|
/*
|
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.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup bke
|
2011-02-27 20:40:57 +00:00
|
|
|
*/
|
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include <math.h>
|
2020-03-19 09:33:03 +01:00
|
|
|
#include <stdio.h>
|
2002-10-12 11:37:38 +00:00
|
|
|
#include <stdlib.h>
|
2020-03-19 09:33:03 +01:00
|
|
|
#include <string.h>
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2013-12-09 15:32:05 +11:00
|
|
|
#include "BLI_bitmap.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_listbase.h"
|
2013-12-09 15:32:05 +11:00
|
|
|
#include "BLI_math.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_utildefines.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2020-03-06 16:22:49 +01:00
|
|
|
#include "BLT_translation.h"
|
|
|
|
|
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_curve_types.h"
|
|
|
|
|
#include "DNA_defaults.h"
|
|
|
|
|
#include "DNA_key_types.h"
|
|
|
|
|
#include "DNA_lattice_types.h"
|
2004-03-20 22:55:42 +00:00
|
|
|
#include "DNA_meshdata_types.h"
|
2010-08-04 04:01:27 +00:00
|
|
|
#include "DNA_object_types.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_scene_types.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2013-08-19 09:25:24 +00:00
|
|
|
#include "BKE_curve.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "BKE_displist.h"
|
2020-03-06 16:22:49 +01:00
|
|
|
#include "BKE_idtype.h"
|
2004-09-14 19:03:11 +00:00
|
|
|
#include "BKE_lattice.h"
|
2020-02-10 12:58:59 +01:00
|
|
|
#include "BKE_lib_id.h"
|
2020-05-12 18:11:53 +02:00
|
|
|
#include "BKE_lib_query.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
|
|
|
|
2018-05-15 17:16:20 +02:00
|
|
|
#include "DEG_depsgraph_query.h"
|
|
|
|
|
|
2020-03-06 16:22:49 +01:00
|
|
|
static void lattice_init_data(ID *id)
|
|
|
|
|
{
|
|
|
|
|
Lattice *lattice = (Lattice *)id;
|
|
|
|
|
|
|
|
|
|
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(lattice, id));
|
|
|
|
|
|
|
|
|
|
MEMCPY_STRUCT_AFTER(lattice, DNA_struct_default_get(Lattice), id);
|
|
|
|
|
|
|
|
|
|
lattice->def = MEM_callocN(sizeof(BPoint), "lattvert"); /* temporary */
|
|
|
|
|
BKE_lattice_resize(lattice, 2, 2, 2, NULL); /* creates a uniform lattice */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void lattice_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const int flag)
|
|
|
|
|
{
|
|
|
|
|
Lattice *lattice_dst = (Lattice *)id_dst;
|
|
|
|
|
const Lattice *lattice_src = (const Lattice *)id_src;
|
|
|
|
|
|
|
|
|
|
lattice_dst->def = MEM_dupallocN(lattice_src->def);
|
|
|
|
|
|
|
|
|
|
if (lattice_src->key && (flag & LIB_ID_COPY_SHAPEKEY)) {
|
|
|
|
|
BKE_id_copy_ex(bmain, &lattice_src->key->id, (ID **)&lattice_dst->key, flag);
|
|
|
|
|
/* XXX This is not nice, we need to make BKE_id_copy_ex fully re-entrant... */
|
|
|
|
|
lattice_dst->key->from = &lattice_dst->id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (lattice_src->dvert) {
|
|
|
|
|
int tot = lattice_src->pntsu * lattice_src->pntsv * lattice_src->pntsw;
|
|
|
|
|
lattice_dst->dvert = MEM_mallocN(sizeof(MDeformVert) * tot, "Lattice MDeformVert");
|
|
|
|
|
BKE_defvert_array_copy(lattice_dst->dvert, lattice_src->dvert, tot);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lattice_dst->editlatt = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void lattice_free_data(ID *id)
|
|
|
|
|
{
|
|
|
|
|
Lattice *lattice = (Lattice *)id;
|
|
|
|
|
|
|
|
|
|
BKE_lattice_batch_cache_free(lattice);
|
|
|
|
|
|
|
|
|
|
MEM_SAFE_FREE(lattice->def);
|
|
|
|
|
if (lattice->dvert) {
|
|
|
|
|
BKE_defvert_array_free(lattice->dvert, lattice->pntsu * lattice->pntsv * lattice->pntsw);
|
|
|
|
|
lattice->dvert = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (lattice->editlatt) {
|
|
|
|
|
Lattice *editlt = lattice->editlatt->latt;
|
|
|
|
|
|
|
|
|
|
if (editlt->def) {
|
|
|
|
|
MEM_freeN(editlt->def);
|
|
|
|
|
}
|
|
|
|
|
if (editlt->dvert) {
|
|
|
|
|
BKE_defvert_array_free(editlt->dvert, lattice->pntsu * lattice->pntsv * lattice->pntsw);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MEM_freeN(editlt);
|
|
|
|
|
MEM_freeN(lattice->editlatt);
|
|
|
|
|
lattice->editlatt = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-12 18:11:53 +02:00
|
|
|
static void lattice_foreach_id(ID *id, LibraryForeachIDData *data)
|
|
|
|
|
{
|
|
|
|
|
Lattice *lattice = (Lattice *)id;
|
|
|
|
|
BKE_LIB_FOREACHID_PROCESS(data, lattice->key, IDWALK_CB_USER);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-06 16:22:49 +01:00
|
|
|
IDTypeInfo IDType_ID_LT = {
|
|
|
|
|
.id_code = ID_LT,
|
|
|
|
|
.id_filter = FILTER_ID_LT,
|
|
|
|
|
.main_listbase_index = INDEX_ID_LT,
|
|
|
|
|
.struct_size = sizeof(Lattice),
|
|
|
|
|
.name = "Lattice",
|
|
|
|
|
.name_plural = "lattices",
|
|
|
|
|
.translation_context = BLT_I18NCONTEXT_ID_LATTICE,
|
|
|
|
|
.flags = 0,
|
|
|
|
|
|
|
|
|
|
.init_data = lattice_init_data,
|
|
|
|
|
.copy_data = lattice_copy_data,
|
|
|
|
|
.free_data = lattice_free_data,
|
|
|
|
|
.make_local = NULL,
|
2020-05-12 18:11:53 +02:00
|
|
|
.foreach_id = lattice_foreach_id,
|
2020-08-28 13:05:48 +02:00
|
|
|
.foreach_cache = NULL,
|
|
|
|
|
|
|
|
|
|
.blend_write = NULL,
|
|
|
|
|
.blend_read_data = NULL,
|
|
|
|
|
.blend_read_lib = NULL,
|
|
|
|
|
.blend_read_expand = NULL,
|
2020-03-06 16:22:49 +01:00
|
|
|
};
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
int BKE_lattice_index_from_uvw(Lattice *lt, const int u, const int v, const int w)
|
2013-06-24 13:45:35 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
const int totu = lt->pntsu;
|
|
|
|
|
const int totv = lt->pntsv;
|
2013-06-28 21:24:38 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return (w * (totu * totv) + (v * totu) + u);
|
2013-06-24 13:45:35 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void BKE_lattice_index_to_uvw(Lattice *lt, const int index, int *r_u, int *r_v, int *r_w)
|
2013-06-24 13:45:35 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
const int totu = lt->pntsu;
|
|
|
|
|
const int totv = lt->pntsv;
|
2013-06-28 21:24:38 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
*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
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
int BKE_lattice_index_flip(
|
|
|
|
|
Lattice *lt, const int index, const bool flip_u, const bool flip_v, const bool flip_w)
|
2013-12-09 15:32:05 +11:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int u, v, w;
|
2013-12-09 15:32:05 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_lattice_index_to_uvw(lt, index, &u, &v, &w);
|
2013-12-09 15:32:05 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (flip_u) {
|
|
|
|
|
u = (lt->pntsu - 1) - u;
|
|
|
|
|
}
|
2013-12-09 15:32:05 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (flip_v) {
|
|
|
|
|
v = (lt->pntsv - 1) - v;
|
|
|
|
|
}
|
2013-12-09 15:32:05 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (flip_w) {
|
|
|
|
|
w = (lt->pntsw - 1) - w;
|
|
|
|
|
}
|
2013-12-09 15:32:05 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return BKE_lattice_index_from_uvw(lt, u, v, w);
|
2013-12-09 15:32:05 +11:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void BKE_lattice_bitmap_from_flag(
|
|
|
|
|
Lattice *lt, BLI_bitmap *bitmap, const short flag, const bool clear, const bool respecthide)
|
2013-12-09 15:32:05 +11:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
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)) {
|
|
|
|
|
BLI_BITMAP_ENABLE(bitmap, i);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (clear) {
|
|
|
|
|
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
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (res == 1) {
|
|
|
|
|
*r_fu = 0.0;
|
|
|
|
|
*r_du = 0.0;
|
|
|
|
|
}
|
|
|
|
|
else if (flag & LT_GRID) {
|
|
|
|
|
*r_fu = -0.5f * (res - 1);
|
|
|
|
|
*r_du = 1.0f;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
*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
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BPoint *bp;
|
|
|
|
|
int i, u, v, w;
|
|
|
|
|
float fu, fv, fw, uc, vc, wc, du = 0.0, dv = 0.0, dw = 0.0;
|
2019-08-22 06:28:35 +10:00
|
|
|
float *co, (*vert_coords)[3] = NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
/* vertex weight groups are just freed all for now */
|
|
|
|
|
if (lt->dvert) {
|
|
|
|
|
BKE_defvert_array_free(lt->dvert, lt->pntsu * lt->pntsv * lt->pntsw);
|
|
|
|
|
lt->dvert = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (uNew * vNew * wNew > 32000) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (uNew >= vNew && uNew >= wNew) {
|
2019-04-17 06:17:24 +02:00
|
|
|
uNew--;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
else if (vNew >= uNew && vNew >= wNew) {
|
2019-04-17 06:17:24 +02:00
|
|
|
vNew--;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
wNew--;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2019-08-22 06:28:35 +10:00
|
|
|
vert_coords = MEM_mallocN(sizeof(*vert_coords) * uNew * vNew * wNew, "tmp_vcos");
|
2019-04-17 06:17:24 +02: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);
|
|
|
|
|
|
|
|
|
|
/* 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.
|
|
|
|
|
*/
|
|
|
|
|
if (ltOb) {
|
|
|
|
|
if (uNew != 1 && lt->pntsu != 1) {
|
|
|
|
|
fu = lt->fu;
|
|
|
|
|
du = (lt->pntsu - 1) * lt->du / (uNew - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (vNew != 1 && lt->pntsv != 1) {
|
|
|
|
|
fv = lt->fv;
|
|
|
|
|
dv = (lt->pntsv - 1) * lt->dv / (vNew - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (wNew != 1 && lt->pntsw != 1) {
|
|
|
|
|
fw = lt->fw;
|
|
|
|
|
dw = (lt->pntsw - 1) * lt->dw / (wNew - 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-22 06:28:35 +10:00
|
|
|
co = vert_coords[0];
|
2019-04-17 06:17:24 +02: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) {
|
|
|
|
|
co[0] = uc;
|
|
|
|
|
co[1] = vc;
|
|
|
|
|
co[2] = wc;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ltOb) {
|
|
|
|
|
float mat[4][4];
|
|
|
|
|
int typeu = lt->typeu, typev = lt->typev, typew = lt->typew;
|
|
|
|
|
|
|
|
|
|
/* works best if we force to linear type (endpoints match) */
|
|
|
|
|
lt->typeu = lt->typev = lt->typew = KEY_LINEAR;
|
|
|
|
|
|
|
|
|
|
if (ltOb->runtime.curve_cache) {
|
|
|
|
|
/* prevent using deformed locations */
|
|
|
|
|
BKE_displist_free(<Ob->runtime.curve_cache->disp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
copy_m4_m4(mat, ltOb->obmat);
|
|
|
|
|
unit_m4(ltOb->obmat);
|
2020-06-12 13:07:50 +10:00
|
|
|
BKE_lattice_deform_coords(ltOb, NULL, vert_coords, uNew * vNew * wNew, 0, NULL, 1.0f);
|
2019-04-17 06:17:24 +02:00
|
|
|
copy_m4_m4(ltOb->obmat, mat);
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
lt->actbp = LT_ACTBP_NONE;
|
|
|
|
|
MEM_freeN(lt->def);
|
|
|
|
|
lt->def = MEM_callocN(lt->pntsu * lt->pntsv * lt->pntsw * sizeof(BPoint), "lattice bp");
|
|
|
|
|
|
|
|
|
|
bp = lt->def;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < lt->pntsu * lt->pntsv * lt->pntsw; i++, bp++) {
|
2019-08-22 06:28:35 +10:00
|
|
|
copy_v3_v3(bp->vec, vert_coords[i]);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2019-08-22 06:28:35 +10:00
|
|
|
MEM_freeN(vert_coords);
|
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
|
|
|
Lattice *BKE_lattice_add(Main *bmain, const char *name)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Lattice *lt;
|
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
|
|
|
|
2019-04-17 06:17:24 +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
|
|
|
|
2020-03-06 16:22:49 +01:00
|
|
|
lattice_init_data(<->id);
|
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
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return lt;
|
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
|
|
|
Lattice *BKE_lattice_copy(Main *bmain, const Lattice *lt)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Lattice *lt_copy;
|
|
|
|
|
BKE_id_copy(bmain, <->id, (ID **)<_copy);
|
|
|
|
|
return lt_copy;
|
2002-10-12 11:37:38 +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
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ob->parent && ob->parent->type == OB_LATTICE && ob->partype == PARSKEL) {
|
|
|
|
|
DispList *dl;
|
|
|
|
|
|
|
|
|
|
for (dl = dispbase->first; dl; dl = dl->next) {
|
2020-06-12 13:07:50 +10:00
|
|
|
BKE_lattice_deform_coords(ob->parent, ob, (float(*)[3])dl->verts, dl->nr, 0, NULL, 1.0f);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2020-08-07 12:30:43 +02:00
|
|
|
|
|
|
|
|
return false;
|
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
|
|
|
{
|
2019-04-17 06:17:24 +02: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)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BPoint *bp, *bp1, *bp2;
|
|
|
|
|
int u, v, w;
|
|
|
|
|
float fac1, du = 0.0, dv = 0.0, dw = 0.0;
|
|
|
|
|
|
|
|
|
|
if (lt->flag & LT_OUTSIDE) {
|
|
|
|
|
bp = lt->def;
|
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (lt->pntsu > 1) {
|
2019-04-17 06:17:24 +02:00
|
|
|
du = 1.0f / ((float)lt->pntsu - 1);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
if (lt->pntsv > 1) {
|
2019-04-17 06:17:24 +02:00
|
|
|
dv = 1.0f / ((float)lt->pntsv - 1);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
if (lt->pntsw > 1) {
|
2019-04-17 06:17:24 +02:00
|
|
|
dw = 1.0f / ((float)lt->pntsw - 1);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
for (w = 0; w < lt->pntsw; w++) {
|
|
|
|
|
|
|
|
|
|
for (v = 0; v < lt->pntsv; v++) {
|
|
|
|
|
|
|
|
|
|
for (u = 0; u < lt->pntsu; u++, bp++) {
|
|
|
|
|
if (u == 0 || v == 0 || w == 0 || u == lt->pntsu - 1 || v == lt->pntsv - 1 ||
|
|
|
|
|
w == lt->pntsw - 1) {
|
|
|
|
|
/* pass */
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
bp->hide = 1;
|
|
|
|
|
bp->f1 &= ~SELECT;
|
|
|
|
|
|
|
|
|
|
/* u extrema */
|
|
|
|
|
bp1 = latt_bp(lt, 0, v, w);
|
|
|
|
|
bp2 = latt_bp(lt, lt->pntsu - 1, v, w);
|
|
|
|
|
|
|
|
|
|
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];
|
|
|
|
|
|
|
|
|
|
/* v extrema */
|
|
|
|
|
bp1 = latt_bp(lt, u, 0, w);
|
|
|
|
|
bp2 = latt_bp(lt, u, lt->pntsv - 1, w);
|
|
|
|
|
|
|
|
|
|
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];
|
|
|
|
|
|
|
|
|
|
/* w extrema */
|
|
|
|
|
bp1 = latt_bp(lt, u, v, 0);
|
|
|
|
|
bp2 = latt_bp(lt, u, v, lt->pntsw - 1);
|
|
|
|
|
|
|
|
|
|
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];
|
|
|
|
|
|
|
|
|
|
mul_v3_fl(bp->vec, 1.0f / 3.0f);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
bp = lt->def;
|
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
for (w = 0; w < lt->pntsw; w++) {
|
|
|
|
|
for (v = 0; v < lt->pntsv; v++) {
|
|
|
|
|
for (u = 0; u < lt->pntsu; u++, bp++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
bp->hide = 0;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2005-08-15 10:30:53 +00:00
|
|
|
|
2019-08-22 13:20:05 +10:00
|
|
|
void BKE_lattice_vert_coords_get(const Lattice *lt, float (*vert_coords)[3])
|
2005-08-15 10:30:53 +00:00
|
|
|
{
|
2019-08-22 13:20:05 +10:00
|
|
|
const int vert_len = lt->pntsu * lt->pntsv * lt->pntsw;
|
2019-08-22 06:28:35 +10:00
|
|
|
for (int i = 0; i < vert_len; i++) {
|
|
|
|
|
copy_v3_v3(vert_coords[i], lt->def[i].vec);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-08-22 13:20:05 +10:00
|
|
|
}
|
2005-08-15 10:30:53 +00:00
|
|
|
|
2019-08-22 13:20:05 +10:00
|
|
|
float (*BKE_lattice_vert_coords_alloc(const Lattice *lt, int *r_vert_len))[3]
|
|
|
|
|
{
|
|
|
|
|
const int vert_len = *r_vert_len = lt->pntsu * lt->pntsv * lt->pntsw;
|
|
|
|
|
float(*vert_coords)[3] = MEM_mallocN(sizeof(*vert_coords) * vert_len, __func__);
|
|
|
|
|
BKE_lattice_vert_coords_get(lt, vert_coords);
|
2019-08-22 06:28:35 +10:00
|
|
|
return vert_coords;
|
2005-08-15 10:30:53 +00:00
|
|
|
}
|
|
|
|
|
|
2019-08-22 13:45:31 +10:00
|
|
|
void BKE_lattice_vert_coords_apply_with_mat4(struct Lattice *lt,
|
|
|
|
|
const float (*vertexCos)[3],
|
|
|
|
|
const float mat[4][4])
|
|
|
|
|
{
|
|
|
|
|
int i, numVerts = lt->pntsu * lt->pntsv * lt->pntsw;
|
|
|
|
|
for (i = 0; i < numVerts; i++) {
|
|
|
|
|
mul_v3_m4v3(lt->def[i].vec, mat, vertexCos[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-22 06:28:35 +10:00
|
|
|
void BKE_lattice_vert_coords_apply(Lattice *lt, const float (*vert_coords)[3])
|
2005-08-15 10:30:53 +00:00
|
|
|
{
|
2019-08-22 06:28:35 +10:00
|
|
|
const int vert_len = lt->pntsu * lt->pntsv * lt->pntsw;
|
|
|
|
|
for (int i = 0; i < vert_len; i++) {
|
|
|
|
|
copy_v3_v3(lt->def[i].vec, vert_coords[i]);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
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
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Lattice *lt = ob->data;
|
2019-04-27 12:07:07 +10:00
|
|
|
/* Get vertex coordinates from the original copy;
|
|
|
|
|
* otherwise we get already-modified coordinates. */
|
2019-04-17 06:17:24 +02:00
|
|
|
Object *ob_orig = DEG_get_original_object(ob);
|
|
|
|
|
VirtualModifierData virtualModifierData;
|
2020-05-08 10:14:02 +02:00
|
|
|
ModifierData *md = BKE_modifiers_get_virtual_modifierlist(ob, &virtualModifierData);
|
2019-08-22 06:28:35 +10:00
|
|
|
float(*vert_coords)[3] = NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
int numVerts, editmode = (lt->editlatt != NULL);
|
|
|
|
|
const ModifierEvalContext mectx = {depsgraph, ob, 0};
|
|
|
|
|
|
|
|
|
|
if (ob->runtime.curve_cache) {
|
|
|
|
|
BKE_displist_free(&ob->runtime.curve_cache->disp);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
ob->runtime.curve_cache = MEM_callocN(sizeof(CurveCache), "CurveCache for lattice");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (; md; md = md->next) {
|
2020-05-08 10:14:02 +02:00
|
|
|
const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-04-21 13:09:41 +02:00
|
|
|
if (!(mti->flags & eModifierTypeFlag_AcceptsVertexCosOnly)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
continue;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
if (!(md->mode & eModifierMode_Realtime)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
continue;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
if (editmode && !(md->mode & eModifierMode_Editmode)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
continue;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
if (mti->isDisabled && mti->isDisabled(scene, md, 0)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
continue;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
if (mti->type != eModifierTypeType_OnlyDeform) {
|
2019-04-17 06:17:24 +02:00
|
|
|
continue;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-08-22 06:28:35 +10:00
|
|
|
if (!vert_coords) {
|
2019-08-22 13:20:05 +10:00
|
|
|
Lattice *lt_orig = ob_orig->data;
|
|
|
|
|
if (lt_orig->editlatt) {
|
|
|
|
|
lt_orig = lt_orig->editlatt->latt;
|
|
|
|
|
}
|
|
|
|
|
vert_coords = BKE_lattice_vert_coords_alloc(lt_orig, &numVerts);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-08-22 06:28:35 +10:00
|
|
|
mti->deformVerts(md, &mectx, NULL, vert_coords, numVerts);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ob->id.tag & LIB_TAG_COPIED_ON_WRITE) {
|
2019-08-22 06:28:35 +10:00
|
|
|
if (vert_coords) {
|
|
|
|
|
BKE_lattice_vert_coords_apply(ob->data, vert_coords);
|
|
|
|
|
MEM_freeN(vert_coords);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* Displist won't do anything; this is just for posterity's sake until we remove it. */
|
2019-08-22 06:28:35 +10:00
|
|
|
if (!vert_coords) {
|
2019-08-22 13:20:05 +10:00
|
|
|
Lattice *lt_orig = ob_orig->data;
|
|
|
|
|
if (lt_orig->editlatt) {
|
|
|
|
|
lt_orig = lt_orig->editlatt->latt;
|
|
|
|
|
}
|
|
|
|
|
vert_coords = BKE_lattice_vert_coords_alloc(lt_orig, &numVerts);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
DispList *dl = MEM_callocN(sizeof(*dl), "lt_dl");
|
|
|
|
|
dl->type = DL_VERTS;
|
|
|
|
|
dl->parts = 1;
|
|
|
|
|
dl->nr = numVerts;
|
2019-08-22 06:28:35 +10:00
|
|
|
dl->verts = (float *)vert_coords;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
BLI_addtail(&ob->runtime.curve_cache->disp, dl);
|
|
|
|
|
}
|
2005-08-15 10:30:53 +00:00
|
|
|
}
|
2008-11-03 23:17:36 +00:00
|
|
|
|
2020-06-13 16:08:34 +10:00
|
|
|
struct MDeformVert *BKE_lattice_deform_verts_get(const struct Object *oblatt)
|
2008-11-03 23:17:36 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Lattice *lt = (Lattice *)oblatt->data;
|
|
|
|
|
BLI_assert(oblatt->type == OB_LATTICE);
|
2019-04-22 09:39:35 +10:00
|
|
|
if (lt->editlatt) {
|
2019-04-17 06:17:24 +02:00
|
|
|
lt = lt->editlatt->latt;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02: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)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(GS(lt->id.name) == ID_LT);
|
2013-06-09 20:28:08 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (lt->editlatt) {
|
|
|
|
|
lt = lt->editlatt->latt;
|
|
|
|
|
}
|
2013-06-09 20:28:08 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(lt->actbp < lt->pntsu * lt->pntsv * lt->pntsw);
|
2013-06-09 20:28:08 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if ((lt->actbp != LT_ACTBP_NONE) && (lt->actbp < lt->pntsu * lt->pntsv * lt->pntsw)) {
|
|
|
|
|
return <->def[lt->actbp];
|
|
|
|
|
}
|
2020-08-07 12:30:43 +02:00
|
|
|
|
|
|
|
|
return NULL;
|
2013-06-09 20:28:08 +00:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int i, numVerts;
|
2013-02-01 15:17:39 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (lt->editlatt) {
|
2019-04-17 06:17:24 +02:00
|
|
|
lt = lt->editlatt->latt;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
numVerts = lt->pntsu * lt->pntsv * lt->pntsw;
|
2013-02-01 15:17:39 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
zero_v3(cent);
|
2013-02-01 15:17:39 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
for (i = 0; i < numVerts; i++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
add_v3_v3(cent, lt->def[i].vec);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2013-02-01 15:17:39 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
mul_v3_fl(cent, 1.0f / (float)numVerts);
|
2013-02-01 15:17:39 +00:00
|
|
|
}
|
|
|
|
|
|
2015-08-13 18:12:08 +02:00
|
|
|
static void boundbox_lattice(Object *ob)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BoundBox *bb;
|
|
|
|
|
Lattice *lt;
|
|
|
|
|
float min[3], max[3];
|
2015-08-13 18:12:08 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ob->runtime.bb == NULL) {
|
|
|
|
|
ob->runtime.bb = MEM_callocN(sizeof(BoundBox), "Lattice boundbox");
|
|
|
|
|
}
|
2015-08-13 18:12:08 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
bb = ob->runtime.bb;
|
|
|
|
|
lt = ob->data;
|
2015-08-13 18:12:08 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
INIT_MINMAX(min, max);
|
|
|
|
|
BKE_lattice_minmax_dl(ob, lt, min, max);
|
|
|
|
|
BKE_boundbox_init_from_minmax(bb, min, max);
|
2016-03-04 21:50:54 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
bb->flag &= ~BOUNDBOX_DIRTY;
|
2015-08-13 18:12:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BoundBox *BKE_lattice_boundbox_get(Object *ob)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
boundbox_lattice(ob);
|
2015-08-13 18:12:08 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return ob->runtime.bb;
|
2015-08-13 18:12:08 +02:00
|
|
|
}
|
|
|
|
|
|
2015-08-17 16:59:32 +02:00
|
|
|
void BKE_lattice_minmax_dl(Object *ob, Lattice *lt, float min[3], float max[3])
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
DispList *dl = ob->runtime.curve_cache ?
|
|
|
|
|
BKE_displist_find(&ob->runtime.curve_cache->disp, DL_VERTS) :
|
|
|
|
|
NULL;
|
|
|
|
|
|
|
|
|
|
if (!dl) {
|
|
|
|
|
BKE_lattice_minmax(lt, min, max);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
int i, numVerts;
|
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (lt->editlatt) {
|
2019-04-17 06:17:24 +02:00
|
|
|
lt = lt->editlatt->latt;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
numVerts = lt->pntsu * lt->pntsv * lt->pntsw;
|
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
for (i = 0; i < numVerts; i++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
minmax_v3v3_v3(min, max, &dl->verts[i * 3]);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2015-08-17 16:59:32 +02:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int i, numVerts;
|
2013-02-01 15:17:39 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (lt->editlatt) {
|
2019-04-17 06:17:24 +02:00
|
|
|
lt = lt->editlatt->latt;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
numVerts = lt->pntsu * lt->pntsv * lt->pntsw;
|
2013-02-01 15:17:39 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
for (i = 0; i < numVerts; i++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
minmax_v3v3_v3(min, max, lt->def[i].vec);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2013-02-01 15:17:39 +00:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
float min[3], max[3];
|
2013-02-01 15:17:39 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
INIT_MINMAX(min, max);
|
2013-02-01 15:17:39 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_lattice_minmax(lt, min, max);
|
|
|
|
|
mid_v3_v3v3(cent, min, max);
|
2013-02-01 15:17:39 +00:00
|
|
|
}
|
|
|
|
|
|
2020-08-02 17:17:31 +10:00
|
|
|
void BKE_lattice_transform(Lattice *lt, const float mat[4][4], bool do_keys)
|
2014-09-01 20:09:31 +10:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
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-09-01 20:09:31 +10:00
|
|
|
}
|
|
|
|
|
|
2020-08-02 17:17:31 +10:00
|
|
|
void BKE_lattice_translate(Lattice *lt, const float offset[3], bool do_keys)
|
2013-02-01 15:17:39 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int i, numVerts;
|
2013-02-01 15:17:39 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
numVerts = lt->pntsu * lt->pntsv * lt->pntsw;
|
2013-02-01 15:17:39 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (lt->def) {
|
|
|
|
|
for (i = 0; i < numVerts; i++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
add_v3_v3(lt->def[i].vec, offset);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
}
|
2013-02-01 15:17:39 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (lt->editlatt) {
|
|
|
|
|
for (i = 0; i < numVerts; i++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
add_v3_v3(lt->editlatt->latt->def[i].vec, offset);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
}
|
2013-02-01 15:17:39 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (do_keys && lt->key) {
|
|
|
|
|
KeyBlock *kb;
|
2013-02-01 15:17:39 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-01 15:17:39 +00:00
|
|
|
}
|
|
|
|
|
|
2018-05-22 08:11:13 +02:00
|
|
|
bool BKE_lattice_is_any_selected(const Lattice *lt)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Intentionally don't handle 'lt->editlatt' (caller must do this). */
|
|
|
|
|
const BPoint *bp = lt->def;
|
|
|
|
|
int a = lt->pntsu * lt->pntsv * lt->pntsw;
|
|
|
|
|
while (a--) {
|
|
|
|
|
if (bp->hide == 0) {
|
|
|
|
|
if (bp->f1 & SELECT) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
bp++;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2018-05-22 08:11:13 +02:00
|
|
|
}
|
|
|
|
|
|
2015-05-12 13:57:11 +05:00
|
|
|
/* **** Depsgraph evaluation **** */
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void BKE_lattice_eval_geometry(struct Depsgraph *UNUSED(depsgraph), Lattice *UNUSED(latt))
|
2015-05-12 13:57:11 +05:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-21 21:14:11 +10:00
|
|
|
/* Draw Engine */
|
2018-08-23 10:14:29 -03:00
|
|
|
void (*BKE_lattice_batch_cache_dirty_tag_cb)(Lattice *lt, int mode) = NULL;
|
2017-04-21 21:14:11 +10:00
|
|
|
void (*BKE_lattice_batch_cache_free_cb)(Lattice *lt) = NULL;
|
|
|
|
|
|
2018-08-23 10:14:29 -03:00
|
|
|
void BKE_lattice_batch_cache_dirty_tag(Lattice *lt, int mode)
|
2017-04-21 21:14:11 +10:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (lt->batch_cache) {
|
|
|
|
|
BKE_lattice_batch_cache_dirty_tag_cb(lt, mode);
|
|
|
|
|
}
|
2017-04-21 21:14:11 +10:00
|
|
|
}
|
|
|
|
|
void BKE_lattice_batch_cache_free(Lattice *lt)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (lt->batch_cache) {
|
|
|
|
|
BKE_lattice_batch_cache_free_cb(lt);
|
|
|
|
|
}
|
2017-07-21 11:53:13 +02:00
|
|
|
}
|