Blender  V2.93
lattice.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
24 #include <math.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 
29 #include "MEM_guardedalloc.h"
30 
31 #include "BLI_bitmap.h"
32 #include "BLI_listbase.h"
33 #include "BLI_math.h"
34 #include "BLI_utildefines.h"
35 
36 #include "BLT_translation.h"
37 
38 /* Allow using deprecated functionality for .blend file I/O. */
39 #define DNA_DEPRECATED_ALLOW
40 
41 #include "DNA_curve_types.h"
42 #include "DNA_defaults.h"
43 #include "DNA_key_types.h"
44 #include "DNA_lattice_types.h"
45 #include "DNA_meshdata_types.h"
46 #include "DNA_object_types.h"
47 #include "DNA_scene_types.h"
48 
49 #include "BKE_anim_data.h"
50 #include "BKE_curve.h"
51 #include "BKE_deform.h"
52 #include "BKE_displist.h"
53 #include "BKE_idtype.h"
54 #include "BKE_lattice.h"
55 #include "BKE_lib_id.h"
56 #include "BKE_lib_query.h"
57 #include "BKE_main.h"
58 #include "BKE_modifier.h"
59 #include "BKE_object.h"
60 
61 #include "DEG_depsgraph_query.h"
62 
63 #include "BLO_read_write.h"
64 
65 static void lattice_init_data(ID *id)
66 {
67  Lattice *lattice = (Lattice *)id;
68 
70 
72 
73  lattice->def = MEM_callocN(sizeof(BPoint), "lattvert"); /* temporary */
74  BKE_lattice_resize(lattice, 2, 2, 2, NULL); /* creates a uniform lattice */
75 }
76 
77 static void lattice_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const int flag)
78 {
79  Lattice *lattice_dst = (Lattice *)id_dst;
80  const Lattice *lattice_src = (const Lattice *)id_src;
81 
82  lattice_dst->def = MEM_dupallocN(lattice_src->def);
83 
84  if (lattice_src->key && (flag & LIB_ID_COPY_SHAPEKEY)) {
85  BKE_id_copy_ex(bmain, &lattice_src->key->id, (ID **)&lattice_dst->key, flag);
86  /* XXX This is not nice, we need to make BKE_id_copy_ex fully re-entrant... */
87  lattice_dst->key->from = &lattice_dst->id;
88  }
89 
90  if (lattice_src->dvert) {
91  int tot = lattice_src->pntsu * lattice_src->pntsv * lattice_src->pntsw;
92  lattice_dst->dvert = MEM_mallocN(sizeof(MDeformVert) * tot, "Lattice MDeformVert");
93  BKE_defvert_array_copy(lattice_dst->dvert, lattice_src->dvert, tot);
94  }
95 
96  lattice_dst->editlatt = NULL;
97  lattice_dst->batch_cache = NULL;
98 }
99 
100 static void lattice_free_data(ID *id)
101 {
102  Lattice *lattice = (Lattice *)id;
103 
105 
107  if (lattice->dvert) {
109  lattice->dvert = NULL;
110  }
111  if (lattice->editlatt) {
112  Lattice *editlt = lattice->editlatt->latt;
113 
114  if (editlt->def) {
115  MEM_freeN(editlt->def);
116  }
117  if (editlt->dvert) {
119  }
120 
121  MEM_freeN(editlt);
123  lattice->editlatt = NULL;
124  }
125 }
126 
128 {
129  Lattice *lattice = (Lattice *)id;
131 }
132 
133 static void lattice_blend_write(BlendWriter *writer, ID *id, const void *id_address)
134 {
135  Lattice *lt = (Lattice *)id;
136  if (lt->id.us > 0 || BLO_write_is_undo(writer)) {
137  /* Clean up, important in undo case to reduce false detection of changed datablocks. */
138  lt->editlatt = NULL;
139  lt->batch_cache = NULL;
140 
141  /* write LibData */
142  BLO_write_id_struct(writer, Lattice, id_address, &lt->id);
143  BKE_id_blend_write(writer, &lt->id);
144 
145  /* write animdata */
146  if (lt->adt) {
147  BKE_animdata_blend_write(writer, lt->adt);
148  }
149 
150  /* direct data */
151  BLO_write_struct_array(writer, BPoint, lt->pntsu * lt->pntsv * lt->pntsw, lt->def);
152 
153  BKE_defvert_blend_write(writer, lt->pntsu * lt->pntsv * lt->pntsw, lt->dvert);
154  }
155 }
156 
157 static void lattice_blend_read_data(BlendDataReader *reader, ID *id)
158 {
159  Lattice *lt = (Lattice *)id;
160  BLO_read_data_address(reader, &lt->def);
161 
162  BLO_read_data_address(reader, &lt->dvert);
163  BKE_defvert_blend_read(reader, lt->pntsu * lt->pntsv * lt->pntsw, lt->dvert);
164 
165  lt->editlatt = NULL;
166  lt->batch_cache = NULL;
167 
168  BLO_read_data_address(reader, &lt->adt);
169  BKE_animdata_blend_read_data(reader, lt->adt);
170 }
171 
172 static void lattice_blend_read_lib(BlendLibReader *reader, ID *id)
173 {
174  Lattice *lt = (Lattice *)id;
175  BLO_read_id_address(reader, lt->id.lib, &lt->ipo); // XXX deprecated - old animation system
176  BLO_read_id_address(reader, lt->id.lib, &lt->key);
177 }
178 
179 static void lattice_blend_read_expand(BlendExpander *expander, ID *id)
180 {
181  Lattice *lt = (Lattice *)id;
182  BLO_expand(expander, lt->ipo); // XXX deprecated - old animation system
183  BLO_expand(expander, lt->key);
184 }
185 
187  .id_code = ID_LT,
188  .id_filter = FILTER_ID_LT,
189  .main_listbase_index = INDEX_ID_LT,
190  .struct_size = sizeof(Lattice),
191  .name = "Lattice",
192  .name_plural = "lattices",
193  .translation_context = BLT_I18NCONTEXT_ID_LATTICE,
194  .flags = 0,
195 
197  .copy_data = lattice_copy_data,
198  .free_data = lattice_free_data,
199  .make_local = NULL,
200  .foreach_id = lattice_foreach_id,
201  .foreach_cache = NULL,
202  .owner_get = NULL,
203 
204  .blend_write = lattice_blend_write,
205  .blend_read_data = lattice_blend_read_data,
206  .blend_read_lib = lattice_blend_read_lib,
207  .blend_read_expand = lattice_blend_read_expand,
208 
209  .blend_read_undo_preserve = NULL,
210 
211  .lib_override_apply_post = NULL,
212 };
213 
214 int BKE_lattice_index_from_uvw(Lattice *lt, const int u, const int v, const int w)
215 {
216  const int totu = lt->pntsu;
217  const int totv = lt->pntsv;
218 
219  return (w * (totu * totv) + (v * totu) + u);
220 }
221 
222 void BKE_lattice_index_to_uvw(Lattice *lt, const int index, int *r_u, int *r_v, int *r_w)
223 {
224  const int totu = lt->pntsu;
225  const int totv = lt->pntsv;
226 
227  *r_u = (index % totu);
228  *r_v = (index / totu) % totv;
229  *r_w = (index / (totu * totv));
230 }
231 
233  Lattice *lt, const int index, const bool flip_u, const bool flip_v, const bool flip_w)
234 {
235  int u, v, w;
236 
237  BKE_lattice_index_to_uvw(lt, index, &u, &v, &w);
238 
239  if (flip_u) {
240  u = (lt->pntsu - 1) - u;
241  }
242 
243  if (flip_v) {
244  v = (lt->pntsv - 1) - v;
245  }
246 
247  if (flip_w) {
248  w = (lt->pntsw - 1) - w;
249  }
250 
251  return BKE_lattice_index_from_uvw(lt, u, v, w);
252 }
253 
255  Lattice *lt, BLI_bitmap *bitmap, const uint8_t flag, const bool clear, const bool respecthide)
256 {
257  const unsigned int tot = lt->pntsu * lt->pntsv * lt->pntsw;
258  BPoint *bp;
259 
260  bp = lt->def;
261  for (int i = 0; i < tot; i++, bp++) {
262  if ((bp->f1 & flag) && (!respecthide || !bp->hide)) {
263  BLI_BITMAP_ENABLE(bitmap, i);
264  }
265  else {
266  if (clear) {
267  BLI_BITMAP_DISABLE(bitmap, i);
268  }
269  }
270  }
271 }
272 
273 void calc_lat_fudu(int flag, int res, float *r_fu, float *r_du)
274 {
275  if (res == 1) {
276  *r_fu = 0.0;
277  *r_du = 0.0;
278  }
279  else if (flag & LT_GRID) {
280  *r_fu = -0.5f * (res - 1);
281  *r_du = 1.0f;
282  }
283  else {
284  *r_fu = -1.0f;
285  *r_du = 2.0f / (res - 1);
286  }
287 }
288 
289 void BKE_lattice_resize(Lattice *lt, int uNew, int vNew, int wNew, Object *ltOb)
290 {
291  BPoint *bp;
292  int i, u, v, w;
293  float fu, fv, fw, uc, vc, wc, du = 0.0, dv = 0.0, dw = 0.0;
294  float *co, (*vert_coords)[3] = NULL;
295 
296  /* vertex weight groups are just freed all for now */
297  if (lt->dvert) {
298  BKE_defvert_array_free(lt->dvert, lt->pntsu * lt->pntsv * lt->pntsw);
299  lt->dvert = NULL;
300  }
301 
302  while (uNew * vNew * wNew > 32000) {
303  if (uNew >= vNew && uNew >= wNew) {
304  uNew--;
305  }
306  else if (vNew >= uNew && vNew >= wNew) {
307  vNew--;
308  }
309  else {
310  wNew--;
311  }
312  }
313 
314  vert_coords = MEM_mallocN(sizeof(*vert_coords) * uNew * vNew * wNew, "tmp_vcos");
315 
316  calc_lat_fudu(lt->flag, uNew, &fu, &du);
317  calc_lat_fudu(lt->flag, vNew, &fv, &dv);
318  calc_lat_fudu(lt->flag, wNew, &fw, &dw);
319 
320  /* If old size is different than resolution changed in interface,
321  * try to do clever reinit of points. Pretty simply idea, we just
322  * deform new verts by old lattice, but scaling them to match old
323  * size first.
324  */
325  if (ltOb) {
326  const float default_size = 1.0;
327 
328  if (uNew != 1) {
329  fu = -default_size / 2.0;
330  du = default_size / (uNew - 1);
331  }
332 
333  if (vNew != 1) {
334  fv = -default_size / 2.0;
335  dv = default_size / (vNew - 1);
336  }
337 
338  if (wNew != 1) {
339  fw = -default_size / 2.0;
340  dw = default_size / (wNew - 1);
341  }
342  }
343 
344  co = vert_coords[0];
345  for (w = 0, wc = fw; w < wNew; w++, wc += dw) {
346  for (v = 0, vc = fv; v < vNew; v++, vc += dv) {
347  for (u = 0, uc = fu; u < uNew; u++, co += 3, uc += du) {
348  co[0] = uc;
349  co[1] = vc;
350  co[2] = wc;
351  }
352  }
353  }
354 
355  if (ltOb) {
356  float mat[4][4];
357  int typeu = lt->typeu, typev = lt->typev, typew = lt->typew;
358 
359  /* works best if we force to linear type (endpoints match) */
360  lt->typeu = lt->typev = lt->typew = KEY_LINEAR;
361 
362  if (ltOb->runtime.curve_cache) {
363  /* prevent using deformed locations */
365  }
366 
367  copy_m4_m4(mat, ltOb->obmat);
368  unit_m4(ltOb->obmat);
369  BKE_lattice_deform_coords(ltOb, NULL, vert_coords, uNew * vNew * wNew, 0, NULL, 1.0f);
370  copy_m4_m4(ltOb->obmat, mat);
371 
372  lt->typeu = typeu;
373  lt->typev = typev;
374  lt->typew = typew;
375  }
376 
377  lt->fu = fu;
378  lt->fv = fv;
379  lt->fw = fw;
380  lt->du = du;
381  lt->dv = dv;
382  lt->dw = dw;
383 
384  lt->pntsu = uNew;
385  lt->pntsv = vNew;
386  lt->pntsw = wNew;
387 
388  lt->actbp = LT_ACTBP_NONE;
389  MEM_freeN(lt->def);
390  lt->def = MEM_callocN(lt->pntsu * lt->pntsv * lt->pntsw * sizeof(BPoint), "lattice bp");
391 
392  bp = lt->def;
393 
394  for (i = 0; i < lt->pntsu * lt->pntsv * lt->pntsw; i++, bp++) {
395  copy_v3_v3(bp->vec, vert_coords[i]);
396  }
397 
398  MEM_freeN(vert_coords);
399 }
400 
401 Lattice *BKE_lattice_add(Main *bmain, const char *name)
402 {
403  Lattice *lt;
404 
405  lt = BKE_id_new(bmain, ID_LT, name);
406 
407  return lt;
408 }
409 
410 bool object_deform_mball(Object *ob, ListBase *dispbase)
411 {
412  if (ob->parent && ob->parent->type == OB_LATTICE && ob->partype == PARSKEL) {
413  DispList *dl;
414 
415  for (dl = dispbase->first; dl; dl = dl->next) {
416  BKE_lattice_deform_coords(ob->parent, ob, (float(*)[3])dl->verts, dl->nr, 0, NULL, 1.0f);
417  }
418 
419  return true;
420  }
421 
422  return false;
423 }
424 
425 static BPoint *latt_bp(Lattice *lt, int u, int v, int w)
426 {
427  return &lt->def[BKE_lattice_index_from_uvw(lt, u, v, w)];
428 }
429 
431 {
432  BPoint *bp, *bp1, *bp2;
433  int u, v, w;
434  float fac1, du = 0.0, dv = 0.0, dw = 0.0;
435 
436  if (lt->flag & LT_OUTSIDE) {
437  bp = lt->def;
438 
439  if (lt->pntsu > 1) {
440  du = 1.0f / ((float)lt->pntsu - 1);
441  }
442  if (lt->pntsv > 1) {
443  dv = 1.0f / ((float)lt->pntsv - 1);
444  }
445  if (lt->pntsw > 1) {
446  dw = 1.0f / ((float)lt->pntsw - 1);
447  }
448 
449  for (w = 0; w < lt->pntsw; w++) {
450 
451  for (v = 0; v < lt->pntsv; v++) {
452 
453  for (u = 0; u < lt->pntsu; u++, bp++) {
454  if (u == 0 || v == 0 || w == 0 || u == lt->pntsu - 1 || v == lt->pntsv - 1 ||
455  w == lt->pntsw - 1) {
456  /* pass */
457  }
458  else {
459  bp->hide = 1;
460  bp->f1 &= ~SELECT;
461 
462  /* u extrema */
463  bp1 = latt_bp(lt, 0, v, w);
464  bp2 = latt_bp(lt, lt->pntsu - 1, v, w);
465 
466  fac1 = du * u;
467  bp->vec[0] = (1.0f - fac1) * bp1->vec[0] + fac1 * bp2->vec[0];
468  bp->vec[1] = (1.0f - fac1) * bp1->vec[1] + fac1 * bp2->vec[1];
469  bp->vec[2] = (1.0f - fac1) * bp1->vec[2] + fac1 * bp2->vec[2];
470 
471  /* v extrema */
472  bp1 = latt_bp(lt, u, 0, w);
473  bp2 = latt_bp(lt, u, lt->pntsv - 1, w);
474 
475  fac1 = dv * v;
476  bp->vec[0] += (1.0f - fac1) * bp1->vec[0] + fac1 * bp2->vec[0];
477  bp->vec[1] += (1.0f - fac1) * bp1->vec[1] + fac1 * bp2->vec[1];
478  bp->vec[2] += (1.0f - fac1) * bp1->vec[2] + fac1 * bp2->vec[2];
479 
480  /* w extrema */
481  bp1 = latt_bp(lt, u, v, 0);
482  bp2 = latt_bp(lt, u, v, lt->pntsw - 1);
483 
484  fac1 = dw * w;
485  bp->vec[0] += (1.0f - fac1) * bp1->vec[0] + fac1 * bp2->vec[0];
486  bp->vec[1] += (1.0f - fac1) * bp1->vec[1] + fac1 * bp2->vec[1];
487  bp->vec[2] += (1.0f - fac1) * bp1->vec[2] + fac1 * bp2->vec[2];
488 
489  mul_v3_fl(bp->vec, 1.0f / 3.0f);
490  }
491  }
492  }
493  }
494  }
495  else {
496  bp = lt->def;
497 
498  for (w = 0; w < lt->pntsw; w++) {
499  for (v = 0; v < lt->pntsv; v++) {
500  for (u = 0; u < lt->pntsu; u++, bp++) {
501  bp->hide = 0;
502  }
503  }
504  }
505  }
506 }
507 
508 void BKE_lattice_vert_coords_get(const Lattice *lt, float (*vert_coords)[3])
509 {
510  const int vert_len = lt->pntsu * lt->pntsv * lt->pntsw;
511  for (int i = 0; i < vert_len; i++) {
512  copy_v3_v3(vert_coords[i], lt->def[i].vec);
513  }
514 }
515 
516 float (*BKE_lattice_vert_coords_alloc(const Lattice *lt, int *r_vert_len))[3]
517 {
518  const int vert_len = *r_vert_len = lt->pntsu * lt->pntsv * lt->pntsw;
519  float(*vert_coords)[3] = MEM_mallocN(sizeof(*vert_coords) * vert_len, __func__);
520  BKE_lattice_vert_coords_get(lt, vert_coords);
521  return vert_coords;
522 }
523 
525  const float (*vert_coords)[3],
526  const float mat[4][4])
527 {
528  int i, numVerts = lt->pntsu * lt->pntsv * lt->pntsw;
529  for (i = 0; i < numVerts; i++) {
530  mul_v3_m4v3(lt->def[i].vec, mat, vert_coords[i]);
531  }
532 }
533 
534 void BKE_lattice_vert_coords_apply(Lattice *lt, const float (*vert_coords)[3])
535 {
536  const int vert_len = lt->pntsu * lt->pntsv * lt->pntsw;
537  for (int i = 0; i < vert_len; i++) {
538  copy_v3_v3(lt->def[i].vec, vert_coords[i]);
539  }
540 }
541 
543 {
545  if (ob->runtime.curve_cache == NULL) {
546  ob->runtime.curve_cache = MEM_callocN(sizeof(CurveCache), "CurveCache for lattice");
547  }
548 
549  Lattice *lt = ob->data;
550  VirtualModifierData virtualModifierData;
551  ModifierData *md = BKE_modifiers_get_virtual_modifierlist(ob, &virtualModifierData);
552  float(*vert_coords)[3] = NULL;
553  int numVerts;
554  const bool is_editmode = (lt->editlatt != NULL);
555  const ModifierEvalContext mectx = {depsgraph, ob, 0};
556 
557  for (; md; md = md->next) {
558  const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
559 
561  continue;
562  }
563  if (!(md->mode & eModifierMode_Realtime)) {
564  continue;
565  }
566  if (is_editmode && !(md->mode & eModifierMode_Editmode)) {
567  continue;
568  }
569  if (mti->isDisabled && mti->isDisabled(scene, md, 0)) {
570  continue;
571  }
572  if (mti->type != eModifierTypeType_OnlyDeform) {
573  continue;
574  }
575 
576  if (vert_coords == NULL) {
577  /* Get either the edit-mode or regular lattice, whichever is in use now. */
578  const Lattice *effective_lattice = BKE_object_get_lattice(ob);
579  vert_coords = BKE_lattice_vert_coords_alloc(effective_lattice, &numVerts);
580  }
581 
582  mti->deformVerts(md, &mectx, NULL, vert_coords, numVerts);
583  }
584 
585  if (vert_coords == NULL) {
586  return;
587  }
588 
590  if (lt_eval == NULL) {
591  BKE_id_copy_ex(NULL, &lt->id, (ID **)&lt_eval, LIB_ID_COPY_LOCALIZE);
592  BKE_object_eval_assign_data(ob, &lt_eval->id, true);
593  }
594 
595  BKE_lattice_vert_coords_apply(lt_eval, vert_coords);
596  MEM_freeN(vert_coords);
597 }
598 
599 struct MDeformVert *BKE_lattice_deform_verts_get(const struct Object *oblatt)
600 {
601  BLI_assert(oblatt->type == OB_LATTICE);
602  Lattice *lt = BKE_object_get_lattice(oblatt);
603  return lt->dvert;
604 }
605 
607 {
608  BLI_assert(GS(lt->id.name) == ID_LT);
609 
610  if (lt->editlatt) {
611  lt = lt->editlatt->latt;
612  }
613 
614  BLI_assert(lt->actbp < lt->pntsu * lt->pntsv * lt->pntsw);
615 
616  if ((lt->actbp != LT_ACTBP_NONE) && (lt->actbp < lt->pntsu * lt->pntsv * lt->pntsw)) {
617  return &lt->def[lt->actbp];
618  }
619 
620  return NULL;
621 }
622 
623 void BKE_lattice_center_median(Lattice *lt, float cent[3])
624 {
625  int i, numVerts;
626 
627  if (lt->editlatt) {
628  lt = lt->editlatt->latt;
629  }
630  numVerts = lt->pntsu * lt->pntsv * lt->pntsw;
631 
632  zero_v3(cent);
633 
634  for (i = 0; i < numVerts; i++) {
635  add_v3_v3(cent, lt->def[i].vec);
636  }
637 
638  mul_v3_fl(cent, 1.0f / (float)numVerts);
639 }
640 
641 static void boundbox_lattice(Object *ob)
642 {
643  BoundBox *bb;
644  Lattice *lt;
645  float min[3], max[3];
646 
647  if (ob->runtime.bb == NULL) {
648  ob->runtime.bb = MEM_callocN(sizeof(BoundBox), "Lattice boundbox");
649  }
650 
651  bb = ob->runtime.bb;
652  lt = ob->data;
653 
654  INIT_MINMAX(min, max);
655  BKE_lattice_minmax_dl(ob, lt, min, max);
657 
658  bb->flag &= ~BOUNDBOX_DIRTY;
659 }
660 
662 {
663  boundbox_lattice(ob);
664 
665  return ob->runtime.bb;
666 }
667 
668 void BKE_lattice_minmax_dl(Object *ob, Lattice *lt, float min[3], float max[3])
669 {
670  DispList *dl = ob->runtime.curve_cache ?
672  NULL;
673 
674  if (!dl) {
675  BKE_lattice_minmax(lt, min, max);
676  }
677  else {
678  int i, numVerts;
679 
680  if (lt->editlatt) {
681  lt = lt->editlatt->latt;
682  }
683  numVerts = lt->pntsu * lt->pntsv * lt->pntsw;
684 
685  for (i = 0; i < numVerts; i++) {
686  minmax_v3v3_v3(min, max, &dl->verts[i * 3]);
687  }
688  }
689 }
690 
691 void BKE_lattice_minmax(Lattice *lt, float min[3], float max[3])
692 {
693  int i, numVerts;
694 
695  if (lt->editlatt) {
696  lt = lt->editlatt->latt;
697  }
698  numVerts = lt->pntsu * lt->pntsv * lt->pntsw;
699 
700  for (i = 0; i < numVerts; i++) {
701  minmax_v3v3_v3(min, max, lt->def[i].vec);
702  }
703 }
704 
705 void BKE_lattice_center_bounds(Lattice *lt, float cent[3])
706 {
707  float min[3], max[3];
708 
709  INIT_MINMAX(min, max);
710 
711  BKE_lattice_minmax(lt, min, max);
712  mid_v3_v3v3(cent, min, max);
713 }
714 
715 void BKE_lattice_transform(Lattice *lt, const float mat[4][4], bool do_keys)
716 {
717  BPoint *bp = lt->def;
718  int i = lt->pntsu * lt->pntsv * lt->pntsw;
719 
720  while (i--) {
721  mul_m4_v3(mat, bp->vec);
722  bp++;
723  }
724 
725  if (do_keys && lt->key) {
726  KeyBlock *kb;
727 
728  for (kb = lt->key->block.first; kb; kb = kb->next) {
729  float *fp = kb->data;
730  for (i = kb->totelem; i--; fp += 3) {
731  mul_m4_v3(mat, fp);
732  }
733  }
734  }
735 }
736 
737 void BKE_lattice_translate(Lattice *lt, const float offset[3], bool do_keys)
738 {
739  int i, numVerts;
740 
741  numVerts = lt->pntsu * lt->pntsv * lt->pntsw;
742 
743  if (lt->def) {
744  for (i = 0; i < numVerts; i++) {
745  add_v3_v3(lt->def[i].vec, offset);
746  }
747  }
748 
749  if (lt->editlatt) {
750  for (i = 0; i < numVerts; i++) {
751  add_v3_v3(lt->editlatt->latt->def[i].vec, offset);
752  }
753  }
754 
755  if (do_keys && lt->key) {
756  KeyBlock *kb;
757 
758  for (kb = lt->key->block.first; kb; kb = kb->next) {
759  float *fp = kb->data;
760  for (i = kb->totelem; i--; fp += 3) {
761  add_v3_v3(fp, offset);
762  }
763  }
764  }
765 }
766 
768 {
769  /* Intentionally don't handle 'lt->editlatt' (caller must do this). */
770  const BPoint *bp = lt->def;
771  int a = lt->pntsu * lt->pntsv * lt->pntsw;
772  while (a--) {
773  if (bp->hide == 0) {
774  if (bp->f1 & SELECT) {
775  return true;
776  }
777  }
778  bp++;
779  }
780  return false;
781 }
782 
783 /* **** Depsgraph evaluation **** */
784 
786 {
787 }
788 
789 /* Draw Engine */
792 
794 {
795  if (lt->batch_cache) {
797  }
798 }
800 {
801  if (lt->batch_cache) {
803  }
804 }
typedef float(TangentPoint)[2]
void BKE_animdata_blend_read_data(struct BlendDataReader *reader, struct AnimData *adt)
Definition: anim_data.c:1574
void BKE_animdata_blend_write(struct BlendWriter *writer, struct AnimData *adt)
Definition: anim_data.c:1552
support for deformation groups and hooks.
void BKE_defvert_blend_write(struct BlendWriter *writer, int count, struct MDeformVert *dvlist)
Definition: deform.c:1525
void BKE_defvert_array_free(struct MDeformVert *dvert, int totvert)
Definition: deform.c:977
void BKE_defvert_array_copy(struct MDeformVert *dst, const struct MDeformVert *src, int totvert)
void BKE_defvert_blend_read(struct BlendDataReader *reader, int count, struct MDeformVert *mdverts)
Definition: deform.c:1542
display list (or rather multi purpose list) stuff.
void BKE_displist_free(struct ListBase *lb)
Definition: displist.c:81
DispList * BKE_displist_find(struct ListBase *lb, int type)
Definition: displist.c:105
@ DL_VERTS
Definition: BKE_displist.h:47
void BKE_lattice_deform_coords(const struct Object *ob_lattice, const struct Object *ob_target, float(*vert_coords)[3], const int vert_coords_len, const short flag, const char *defgrp_name, float fac)
@ LIB_ID_COPY_LOCALIZE
Definition: BKE_lib_id.h:145
@ LIB_ID_COPY_SHAPEKEY
Definition: BKE_lib_id.h:133
struct ID * BKE_id_copy_ex(struct Main *bmain, const struct ID *id, struct ID **r_newid, const int flag)
void BKE_id_blend_write(struct BlendWriter *writer, struct ID *id)
Definition: lib_id.c:2395
void * BKE_id_new(struct Main *bmain, const short type, const char *name)
Definition: lib_id.c:1177
#define BKE_LIB_FOREACHID_PROCESS(_data, _id_super, _cb_flag)
@ IDWALK_CB_USER
Definition: BKE_lib_query.h:87
const ModifierTypeInfo * BKE_modifier_get_info(ModifierType type)
@ eModifierTypeFlag_AcceptsVertexCosOnly
Definition: BKE_modifier.h:114
struct ModifierData * BKE_modifiers_get_virtual_modifierlist(const struct Object *ob, struct VirtualModifierData *data)
@ eModifierTypeType_OnlyDeform
Definition: BKE_modifier.h:58
General operations, lookup, etc. for blender objects.
void BKE_boundbox_init_from_minmax(struct BoundBox *bb, const float min[3], const float max[3])
Definition: object.c:3778
struct Lattice * BKE_object_get_lattice(const struct Object *object)
void BKE_object_free_derived_caches(struct Object *ob)
Definition: object.c:1719
struct Lattice * BKE_object_get_evaluated_lattice(const struct Object *object)
void BKE_object_eval_assign_data(struct Object *object, struct ID *data, bool is_owned)
Definition: object.c:1687
#define BLI_assert(a)
Definition: BLI_assert.h:58
#define BLI_BITMAP_ENABLE(_bitmap, _index)
Definition: BLI_bitmap.h:78
#define BLI_BITMAP_DISABLE(_bitmap, _index)
Definition: BLI_bitmap.h:83
unsigned int BLI_bitmap
Definition: BLI_bitmap.h:32
void unit_m4(float m[4][4])
Definition: rct.c:1140
void mul_m4_v3(const float M[4][4], float r[3])
Definition: math_matrix.c:732
void copy_m4_m4(float m1[4][4], const float m2[4][4])
Definition: math_matrix.c:95
void mul_v3_m4v3(float r[3], const float M[4][4], const float v[3])
Definition: math_matrix.c:742
void minmax_v3v3_v3(float min[3], float max[3], const float vec[3])
Definition: math_vector.c:1020
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
void mid_v3_v3v3(float r[3], const float a[3], const float b[3])
Definition: math_vector.c:270
MINLINE void zero_v3(float r[3])
MINLINE void add_v3_v3(float r[3], const float a[3])
#define INIT_MINMAX(min, max)
#define UNUSED(x)
#define MEMCMP_STRUCT_AFTER_IS_ZERO(struct_var, member)
#define MEMCPY_STRUCT_AFTER(struct_dst, struct_src, member)
#define BLO_read_data_address(reader, ptr_p)
#define BLO_write_id_struct(writer, struct_name, id_address, id)
#define BLO_read_id_address(reader, lib, id_ptr_p)
#define BLO_write_struct_array(writer, struct_name, array_size, data_ptr)
#define BLO_expand(expander, id)
bool BLO_write_is_undo(BlendWriter *writer)
Definition: writefile.c:1412
#define BLT_I18NCONTEXT_ID_LATTICE
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
#define FILTER_ID_LT
Definition: DNA_ID.h:715
@ INDEX_ID_LT
Definition: DNA_ID.h:833
@ ID_LT
Definition: DNA_ID_enums.h:66
#define DNA_struct_default_get(struct_name)
Definition: DNA_defaults.h:44
@ KEY_LINEAR
#define LT_ACTBP_NONE
#define LT_OUTSIDE
#define LT_GRID
struct Lattice Lattice
@ eModifierMode_Editmode
@ eModifierMode_Realtime
Object is a sort of wrapper for general info.
@ BOUNDBOX_DIRTY
@ PARSKEL
@ OB_LATTICE
Read Guarded memory(de)allocation.
#define MEM_SAFE_FREE(v)
static void init_data(ModifierData *md)
ATTR_WARN_UNUSED_RESULT const BMVert * v
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition: btQuadWord.h:119
#define SELECT
Scene scene
const Depsgraph * depsgraph
Lattice lattice
#define GS(x)
Definition: iris.c:241
void outside_lattice(Lattice *lt)
Definition: lattice.c:430
static void lattice_blend_read_lib(BlendLibReader *reader, ID *id)
Definition: lattice.c:172
static BPoint * latt_bp(Lattice *lt, int u, int v, int w)
Definition: lattice.c:425
void BKE_lattice_bitmap_from_flag(Lattice *lt, BLI_bitmap *bitmap, const uint8_t flag, const bool clear, const bool respecthide)
Definition: lattice.c:254
void BKE_lattice_transform(Lattice *lt, const float mat[4][4], bool do_keys)
Definition: lattice.c:715
static void lattice_blend_read_expand(BlendExpander *expander, ID *id)
Definition: lattice.c:179
void BKE_lattice_center_bounds(Lattice *lt, float cent[3])
Definition: lattice.c:705
void BKE_lattice_resize(Lattice *lt, int uNew, int vNew, int wNew, Object *ltOb)
Definition: lattice.c:289
void BKE_lattice_batch_cache_dirty_tag(Lattice *lt, int mode)
Definition: lattice.c:793
static void lattice_blend_write(BlendWriter *writer, ID *id, const void *id_address)
Definition: lattice.c:133
void BKE_lattice_vert_coords_apply(Lattice *lt, const float(*vert_coords)[3])
Definition: lattice.c:534
void(* BKE_lattice_batch_cache_dirty_tag_cb)(Lattice *lt, int mode)
Definition: lattice.c:790
float(* BKE_lattice_vert_coords_alloc(const Lattice *lt, int *r_vert_len))[3]
Definition: lattice.c:516
void calc_lat_fudu(int flag, int res, float *r_fu, float *r_du)
Definition: lattice.c:273
void BKE_lattice_minmax_dl(Object *ob, Lattice *lt, float min[3], float max[3])
Definition: lattice.c:668
void BKE_lattice_center_median(Lattice *lt, float cent[3])
Definition: lattice.c:623
static void boundbox_lattice(Object *ob)
Definition: lattice.c:641
static void lattice_free_data(ID *id)
Definition: lattice.c:100
void(* BKE_lattice_batch_cache_free_cb)(Lattice *lt)
Definition: lattice.c:791
static void lattice_blend_read_data(BlendDataReader *reader, ID *id)
Definition: lattice.c:157
static void lattice_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const int flag)
Definition: lattice.c:77
void BKE_lattice_index_to_uvw(Lattice *lt, const int index, int *r_u, int *r_v, int *r_w)
Definition: lattice.c:222
Lattice * BKE_lattice_add(Main *bmain, const char *name)
Definition: lattice.c:401
static void lattice_init_data(ID *id)
Definition: lattice.c:65
struct BPoint * BKE_lattice_active_point_get(Lattice *lt)
Definition: lattice.c:606
void BKE_lattice_translate(Lattice *lt, const float offset[3], bool do_keys)
Definition: lattice.c:737
bool BKE_lattice_is_any_selected(const Lattice *lt)
Definition: lattice.c:767
void BKE_lattice_eval_geometry(struct Depsgraph *UNUSED(depsgraph), Lattice *UNUSED(latt))
Definition: lattice.c:785
void BKE_lattice_vert_coords_apply_with_mat4(struct Lattice *lt, const float(*vert_coords)[3], const float mat[4][4])
Definition: lattice.c:524
bool object_deform_mball(Object *ob, ListBase *dispbase)
Definition: lattice.c:410
int BKE_lattice_index_flip(Lattice *lt, const int index, const bool flip_u, const bool flip_v, const bool flip_w)
Definition: lattice.c:232
void BKE_lattice_minmax(Lattice *lt, float min[3], float max[3])
Definition: lattice.c:691
int BKE_lattice_index_from_uvw(Lattice *lt, const int u, const int v, const int w)
Definition: lattice.c:214
void BKE_lattice_batch_cache_free(Lattice *lt)
Definition: lattice.c:799
void BKE_lattice_vert_coords_get(const Lattice *lt, float(*vert_coords)[3])
Definition: lattice.c:508
IDTypeInfo IDType_ID_LT
Definition: lattice.c:186
BoundBox * BKE_lattice_boundbox_get(Object *ob)
Definition: lattice.c:661
void BKE_lattice_modifiers_calc(struct Depsgraph *depsgraph, Scene *scene, Object *ob)
Definition: lattice.c:542
struct MDeformVert * BKE_lattice_deform_verts_get(const struct Object *oblatt)
Definition: lattice.c:599
static void lattice_foreach_id(ID *id, LibraryForeachIDData *data)
Definition: lattice.c:127
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_dupallocN)(const void *vmemh)
Definition: mallocn.c:42
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:47
static void clear(Message *msg)
Definition: msgfmt.c:294
static unsigned a[3]
Definition: RandGen.cpp:92
#define min(a, b)
Definition: sort.c:51
unsigned char uint8_t
Definition: stdint.h:81
short hide
uint8_t f1
float vec[4]
ListBase disp
Definition: BKE_curve.h:49
float * verts
Definition: BKE_displist.h:74
struct DispList * next
Definition: BKE_displist.h:70
struct Lattice * latt
short id_code
Definition: BKE_idtype.h:120
Definition: DNA_ID.h:273
struct Library * lib
Definition: DNA_ID.h:277
int us
Definition: DNA_ID.h:293
char name[66]
Definition: DNA_ID.h:283
struct KeyBlock * next
Definition: DNA_key_types.h:41
void * data
Definition: DNA_key_types.h:66
ID * from
ID id
Definition: DNA_key_types.h:79
ListBase block
struct Key * key
void * batch_cache
struct MDeformVert * dvert
struct EditLatt * editlatt
struct BPoint * def
struct AnimData * adt
void * first
Definition: DNA_listBase.h:47
Definition: BKE_main.h:116
struct ModifierData * next
bool(* isDisabled)(const struct Scene *scene, struct ModifierData *md, bool userRenderParams)
Definition: BKE_modifier.h:312
ModifierTypeFlag flags
Definition: BKE_modifier.h:174
ModifierTypeType type
Definition: BKE_modifier.h:173
void(* deformVerts)(struct ModifierData *md, const struct ModifierEvalContext *ctx, struct Mesh *mesh, float(*vertexCos)[3], int numVerts)
Definition: BKE_modifier.h:197
struct CurveCache * curve_cache
struct BoundBox * bb
short partype
Object_Runtime runtime
float obmat[4][4]
struct Object * parent
void * data
float max