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