Blender  V3.3
key.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 <stddef.h>
10 #include <string.h>
11 
12 #include "MEM_guardedalloc.h"
13 
14 #include "BLI_blenlib.h"
15 #include "BLI_endian_switch.h"
16 #include "BLI_math_vector.h"
17 #include "BLI_string_utils.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_ID.h"
26 #include "DNA_anim_types.h"
27 #include "DNA_key_types.h"
28 #include "DNA_lattice_types.h"
29 #include "DNA_mesh_types.h"
30 #include "DNA_meshdata_types.h"
31 #include "DNA_object_types.h"
32 #include "DNA_scene_types.h"
33 
34 #include "BKE_anim_data.h"
35 #include "BKE_curve.h"
36 #include "BKE_customdata.h"
37 #include "BKE_deform.h"
38 #include "BKE_editmesh.h"
39 #include "BKE_idtype.h"
40 #include "BKE_key.h"
41 #include "BKE_lattice.h"
42 #include "BKE_lib_id.h"
43 #include "BKE_lib_query.h"
44 #include "BKE_main.h"
45 #include "BKE_mesh.h"
46 #include "BKE_scene.h"
47 
48 #include "RNA_access.h"
49 #include "RNA_path.h"
50 #include "RNA_prototypes.h"
51 
52 #include "BLO_read_write.h"
53 
54 static void shapekey_copy_data(Main *UNUSED(bmain),
55  ID *id_dst,
56  const ID *id_src,
57  const int UNUSED(flag))
58 {
59  Key *key_dst = (Key *)id_dst;
60  const Key *key_src = (const Key *)id_src;
61  BLI_duplicatelist(&key_dst->block, &key_src->block);
62 
63  KeyBlock *kb_dst, *kb_src;
64  for (kb_src = key_src->block.first, kb_dst = key_dst->block.first; kb_dst;
65  kb_src = kb_src->next, kb_dst = kb_dst->next) {
66  if (kb_dst->data) {
67  kb_dst->data = MEM_dupallocN(kb_dst->data);
68  }
69  if (kb_src == key_src->refkey) {
70  key_dst->refkey = kb_dst;
71  }
72  }
73 }
74 
75 static void shapekey_free_data(ID *id)
76 {
77  Key *key = (Key *)id;
78  KeyBlock *kb;
79 
80  while ((kb = BLI_pophead(&key->block))) {
81  if (kb->data) {
82  MEM_freeN(kb->data);
83  }
84  MEM_freeN(kb);
85  }
86 }
87 
89 {
90  Key *key = (Key *)id;
92 }
93 
94 static ID *shapekey_owner_get(Main *UNUSED(bmain), ID *id, ID *UNUSED(owner_id_hint))
95 {
96  return ((Key *)id)->from;
97 }
98 
99 static void shapekey_blend_write(BlendWriter *writer, ID *id, const void *id_address)
100 {
101  Key *key = (Key *)id;
102  const bool is_undo = BLO_write_is_undo(writer);
103 
104  /* write LibData */
105  BLO_write_id_struct(writer, Key, id_address, &key->id);
106  BKE_id_blend_write(writer, &key->id);
107 
108  if (key->adt) {
109  BKE_animdata_blend_write(writer, key->adt);
110  }
111 
112  /* direct data */
113  LISTBASE_FOREACH (KeyBlock *, kb, &key->block) {
114  KeyBlock tmp_kb = *kb;
115  /* Do not store actual geometry data in case this is a library override ID. */
116  if (ID_IS_OVERRIDE_LIBRARY(key) && !is_undo) {
117  tmp_kb.totelem = 0;
118  tmp_kb.data = NULL;
119  }
120  BLO_write_struct_at_address(writer, KeyBlock, kb, &tmp_kb);
121  if (tmp_kb.data != NULL) {
122  BLO_write_raw(writer, tmp_kb.totelem * key->elemsize, tmp_kb.data);
123  }
124  }
125 }
126 
127 /* old defines from DNA_ipo_types.h for data-type, stored in DNA - don't modify! */
128 #define IPO_FLOAT 4
129 #define IPO_BEZTRIPLE 100
130 #define IPO_BPOINT 101
131 
132 static void switch_endian_keyblock(Key *key, KeyBlock *kb)
133 {
134  int elemsize = key->elemsize;
135  char *data = kb->data;
136 
137  for (int a = 0; a < kb->totelem; a++) {
138  const char *cp = key->elemstr;
139  char *poin = data;
140 
141  while (cp[0]) { /* cp[0] == amount */
142  switch (cp[1]) { /* cp[1] = type */
143  case IPO_FLOAT:
144  case IPO_BPOINT:
145  case IPO_BEZTRIPLE: {
146  int b = cp[0];
147  BLI_endian_switch_float_array((float *)poin, b);
148  poin += sizeof(float) * b;
149  break;
150  }
151  }
152 
153  cp += 2;
154  }
155  data += elemsize;
156  }
157 }
158 
159 static void shapekey_blend_read_data(BlendDataReader *reader, ID *id)
160 {
161  Key *key = (Key *)id;
162  BLO_read_list(reader, &(key->block));
163 
164  BLO_read_data_address(reader, &key->adt);
165  BKE_animdata_blend_read_data(reader, key->adt);
166 
167  BLO_read_data_address(reader, &key->refkey);
168 
169  LISTBASE_FOREACH (KeyBlock *, kb, &key->block) {
170  BLO_read_data_address(reader, &kb->data);
171 
172  if (BLO_read_requires_endian_switch(reader)) {
173  switch_endian_keyblock(key, kb);
174  }
175  }
176 }
177 
178 static void shapekey_blend_read_lib(BlendLibReader *reader, ID *id)
179 {
180  Key *key = (Key *)id;
181  BLI_assert((key->id.tag & LIB_TAG_EXTERN) == 0);
182 
183  BLO_read_id_address(reader, key->id.lib, &key->ipo); /* XXX deprecated - old animation system */
184  BLO_read_id_address(reader, key->id.lib, &key->from);
185 }
186 
187 static void shapekey_blend_read_expand(BlendExpander *expander, ID *id)
188 {
189  Key *key = (Key *)id;
190  BLO_expand(expander, key->ipo); /* XXX deprecated - old animation system */
191 }
192 
194  .id_code = ID_KE,
195  .id_filter = FILTER_ID_KE,
196  .main_listbase_index = INDEX_ID_KE,
197  .struct_size = sizeof(Key),
198  .name = "Key",
199  .name_plural = "shape_keys",
200  .translation_context = BLT_I18NCONTEXT_ID_SHAPEKEY,
202  .asset_type_info = NULL,
203 
204  .init_data = NULL,
205  .copy_data = shapekey_copy_data,
206  .free_data = shapekey_free_data,
207  .make_local = NULL,
208  .foreach_id = shapekey_foreach_id,
209  .foreach_cache = NULL,
210  .foreach_path = NULL,
211  /* A bit weird, due to shape-keys not being strictly speaking embedded data... But they also
212  * share a lot with those (non linkable, only ever used by one owner ID, etc.). */
213  .owner_get = shapekey_owner_get,
214 
215  .blend_write = shapekey_blend_write,
216  .blend_read_data = shapekey_blend_read_data,
217  .blend_read_lib = shapekey_blend_read_lib,
218  .blend_read_expand = shapekey_blend_read_expand,
219 
220  .blend_read_undo_preserve = NULL,
221 
222  .lib_override_apply_post = NULL,
223 };
224 
225 #define KEY_MODE_DUMMY 0 /* use where mode isn't checked for */
226 #define KEY_MODE_BPOINT 1
227 #define KEY_MODE_BEZTRIPLE 2
228 
229 /* Internal use only. */
230 typedef struct WeightsArrayCache {
234 
236 {
237  shapekey_free_data(&key->id);
238 }
239 
241 {
242  KeyBlock *kb;
243 
244  while ((kb = BLI_pophead(&key->block))) {
245  if (kb->data) {
246  MEM_freeN(kb->data);
247  }
248  MEM_freeN(kb);
249  }
250 }
251 
252 Key *BKE_key_add(Main *bmain, ID *id) /* common function */
253 {
254  Key *key;
255  char *el;
256 
257  key = BKE_id_new(bmain, ID_KE, "Key");
258 
259  key->type = KEY_NORMAL;
260  key->from = id;
261 
262  key->uidgen = 1;
263 
264  /* XXX the code here uses some defines which will soon be deprecated... */
265  switch (GS(id->name)) {
266  case ID_ME:
267  el = key->elemstr;
268 
269  el[0] = KEYELEM_FLOAT_LEN_COORD;
270  el[1] = IPO_FLOAT;
271  el[2] = 0;
272 
273  key->elemsize = sizeof(float[KEYELEM_FLOAT_LEN_COORD]);
274 
275  break;
276  case ID_LT:
277  el = key->elemstr;
278 
279  el[0] = KEYELEM_FLOAT_LEN_COORD;
280  el[1] = IPO_FLOAT;
281  el[2] = 0;
282 
283  key->elemsize = sizeof(float[KEYELEM_FLOAT_LEN_COORD]);
284 
285  break;
286  case ID_CU_LEGACY:
287  el = key->elemstr;
288 
289  el[0] = KEYELEM_ELEM_SIZE_CURVE;
290  el[1] = IPO_BPOINT;
291  el[2] = 0;
292 
293  key->elemsize = sizeof(float[KEYELEM_ELEM_SIZE_CURVE]);
294 
295  break;
296 
297  default:
298  break;
299  }
300 
301  return key;
302 }
303 
304 void BKE_key_sort(Key *key)
305 {
306  KeyBlock *kb;
307  KeyBlock *kb2;
308 
309  /* locate the key which is out of position */
310  for (kb = key->block.first; kb; kb = kb->next) {
311  if ((kb->next) && (kb->pos > kb->next->pos)) {
312  break;
313  }
314  }
315 
316  /* if we find a key, move it */
317  if (kb) {
318  kb = kb->next; /* next key is the out-of-order one */
319  BLI_remlink(&key->block, kb);
320 
321  /* find the right location and insert before */
322  for (kb2 = key->block.first; kb2; kb2 = kb2->next) {
323  if (kb2->pos > kb->pos) {
324  BLI_insertlinkafter(&key->block, kb2->prev, kb);
325  break;
326  }
327  }
328  }
329 
330  /* new rule; first key is refkey, this to match drawing channels... */
331  key->refkey = key->block.first;
332 }
333 
334 /**************** do the key ****************/
335 
336 void key_curve_position_weights(float t, float data[4], int type)
337 {
338  float t2, t3, fc;
339 
340  if (type == KEY_LINEAR) {
341  data[0] = 0.0f;
342  data[1] = -t + 1.0f;
343  data[2] = t;
344  data[3] = 0.0f;
345  }
346  else if (type == KEY_CARDINAL) {
347  t2 = t * t;
348  t3 = t2 * t;
349  fc = 0.71f;
350 
351  data[0] = -fc * t3 + 2.0f * fc * t2 - fc * t;
352  data[1] = (2.0f - fc) * t3 + (fc - 3.0f) * t2 + 1.0f;
353  data[2] = (fc - 2.0f) * t3 + (3.0f - 2.0f * fc) * t2 + fc * t;
354  data[3] = fc * t3 - fc * t2;
355  }
356  else if (type == KEY_BSPLINE) {
357  t2 = t * t;
358  t3 = t2 * t;
359 
360  data[0] = -0.16666666f * t3 + 0.5f * t2 - 0.5f * t + 0.16666666f;
361  data[1] = 0.5f * t3 - t2 + 0.66666666f;
362  data[2] = -0.5f * t3 + 0.5f * t2 + 0.5f * t + 0.16666666f;
363  data[3] = 0.16666666f * t3;
364  }
365  else if (type == KEY_CATMULL_ROM) {
366  t2 = t * t;
367  t3 = t2 * t;
368  fc = 0.5f;
369 
370  data[0] = -fc * t3 + 2.0f * fc * t2 - fc * t;
371  data[1] = (2.0f - fc) * t3 + (fc - 3.0f) * t2 + 1.0f;
372  data[2] = (fc - 2.0f) * t3 + (3.0f - 2.0f * fc) * t2 + fc * t;
373  data[3] = fc * t3 - fc * t2;
374  }
375 }
376 
377 void key_curve_tangent_weights(float t, float data[4], int type)
378 {
379  float t2, fc;
380 
381  if (type == KEY_LINEAR) {
382  data[0] = 0.0f;
383  data[1] = -1.0f;
384  data[2] = 1.0f;
385  data[3] = 0.0f;
386  }
387  else if (type == KEY_CARDINAL) {
388  t2 = t * t;
389  fc = 0.71f;
390 
391  data[0] = -3.0f * fc * t2 + 4.0f * fc * t - fc;
392  data[1] = 3.0f * (2.0f - fc) * t2 + 2.0f * (fc - 3.0f) * t;
393  data[2] = 3.0f * (fc - 2.0f) * t2 + 2.0f * (3.0f - 2.0f * fc) * t + fc;
394  data[3] = 3.0f * fc * t2 - 2.0f * fc * t;
395  }
396  else if (type == KEY_BSPLINE) {
397  t2 = t * t;
398 
399  data[0] = -0.5f * t2 + t - 0.5f;
400  data[1] = 1.5f * t2 - t * 2.0f;
401  data[2] = -1.5f * t2 + t + 0.5f;
402  data[3] = 0.5f * t2;
403  }
404  else if (type == KEY_CATMULL_ROM) {
405  t2 = t * t;
406  fc = 0.5f;
407 
408  data[0] = -3.0f * fc * t2 + 4.0f * fc * t - fc;
409  data[1] = 3.0f * (2.0f - fc) * t2 + 2.0f * (fc - 3.0f) * t;
410  data[2] = 3.0f * (fc - 2.0f) * t2 + 2.0f * (3.0f - 2.0f * fc) * t + fc;
411  data[3] = 3.0f * fc * t2 - 2.0f * fc * t;
412  }
413 }
414 
415 void key_curve_normal_weights(float t, float data[4], int type)
416 {
417  float fc;
418 
419  if (type == KEY_LINEAR) {
420  data[0] = 0.0f;
421  data[1] = 0.0f;
422  data[2] = 0.0f;
423  data[3] = 0.0f;
424  }
425  else if (type == KEY_CARDINAL) {
426  fc = 0.71f;
427 
428  data[0] = -6.0f * fc * t + 4.0f * fc;
429  data[1] = 6.0f * (2.0f - fc) * t + 2.0f * (fc - 3.0f);
430  data[2] = 6.0f * (fc - 2.0f) * t + 2.0f * (3.0f - 2.0f * fc);
431  data[3] = 6.0f * fc * t - 2.0f * fc;
432  }
433  else if (type == KEY_BSPLINE) {
434  data[0] = -1.0f * t + 1.0f;
435  data[1] = 3.0f * t - 2.0f;
436  data[2] = -3.0f * t + 1.0f;
437  data[3] = 1.0f * t;
438  }
439  else if (type == KEY_CATMULL_ROM) {
440  fc = 0.5f;
441 
442  data[0] = -6.0f * fc * t + 4.0f * fc;
443  data[1] = 6.0f * (2.0f - fc) * t + 2.0f * (fc - 3.0f);
444  data[2] = 6.0f * (fc - 2.0f) * t + 2.0f * (3.0f - 2.0f * fc);
445  data[3] = 6.0f * fc * t - 2.0f * fc;
446  }
447 }
448 
449 static int setkeys(float fac, ListBase *lb, KeyBlock *k[], float t[4], int cycl)
450 {
451  /* return 1 means k[2] is the position, return 0 means interpolate */
452  KeyBlock *k1, *firstkey;
453  float d, dpos, ofs = 0, lastpos;
454  short bsplinetype;
455 
456  firstkey = lb->first;
457  k1 = lb->last;
458  lastpos = k1->pos;
459  dpos = lastpos - firstkey->pos;
460 
461  if (fac < firstkey->pos) {
462  fac = firstkey->pos;
463  }
464  else if (fac > k1->pos) {
465  fac = k1->pos;
466  }
467 
468  k1 = k[0] = k[1] = k[2] = k[3] = firstkey;
469  t[0] = t[1] = t[2] = t[3] = k1->pos;
470 
471  /* if (fac < 0.0 || fac > 1.0) return 1; */
472 
473  if (k1->next == NULL) {
474  return 1;
475  }
476 
477  if (cycl) { /* pre-sort */
478  k[2] = k1->next;
479  k[3] = k[2]->next;
480  if (k[3] == NULL) {
481  k[3] = k1;
482  }
483  while (k1) {
484  if (k1->next == NULL) {
485  k[0] = k1;
486  }
487  k1 = k1->next;
488  }
489  /* k1 = k[1]; */ /* UNUSED */
490  t[0] = k[0]->pos;
491  t[1] += dpos;
492  t[2] = k[2]->pos + dpos;
493  t[3] = k[3]->pos + dpos;
494  fac += dpos;
495  ofs = dpos;
496  if (k[3] == k[1]) {
497  t[3] += dpos;
498  ofs = 2.0f * dpos;
499  }
500  if (fac < t[1]) {
501  fac += dpos;
502  }
503  k1 = k[3];
504  }
505  else { /* pre-sort */
506  k[2] = k1->next;
507  t[2] = k[2]->pos;
508  k[3] = k[2]->next;
509  if (k[3] == NULL) {
510  k[3] = k[2];
511  }
512  t[3] = k[3]->pos;
513  k1 = k[3];
514  }
515 
516  while (t[2] < fac) { /* find correct location */
517  if (k1->next == NULL) {
518  if (cycl) {
519  k1 = firstkey;
520  ofs += dpos;
521  }
522  else if (t[2] == t[3]) {
523  break;
524  }
525  }
526  else {
527  k1 = k1->next;
528  }
529 
530  t[0] = t[1];
531  k[0] = k[1];
532  t[1] = t[2];
533  k[1] = k[2];
534  t[2] = t[3];
535  k[2] = k[3];
536  t[3] = k1->pos + ofs;
537  k[3] = k1;
538 
539  if (ofs > 2.1f + lastpos) {
540  break;
541  }
542  }
543 
544  bsplinetype = 0;
545  if (k[1]->type == KEY_BSPLINE || k[2]->type == KEY_BSPLINE) {
546  bsplinetype = 1;
547  }
548 
549  if (cycl == 0) {
550  if (bsplinetype == 0) { /* B spline doesn't go through the control points */
551  if (fac <= t[1]) { /* fac for 1st key */
552  t[2] = t[1];
553  k[2] = k[1];
554  return 1;
555  }
556  if (fac >= t[2]) { /* fac after 2nd key */
557  return 1;
558  }
559  }
560  else if (fac > t[2]) { /* last key */
561  fac = t[2];
562  k[3] = k[2];
563  t[3] = t[2];
564  }
565  }
566 
567  d = t[2] - t[1];
568  if (d == 0.0f) {
569  if (bsplinetype == 0) {
570  return 1; /* both keys equal */
571  }
572  }
573  else {
574  d = (fac - t[1]) / d;
575  }
576 
577  /* interpolation */
578  key_curve_position_weights(d, t, k[1]->type);
579 
580  if (k[1]->type != k[2]->type) {
581  float t_other[4];
582  key_curve_position_weights(d, t_other, k[2]->type);
583  interp_v4_v4v4(t, t, t_other, d);
584  }
585 
586  return 0;
587 }
588 
589 static void flerp(int tot,
590  float *in,
591  const float *f0,
592  const float *f1,
593  const float *f2,
594  const float *f3,
595  const float *t)
596 {
597  int a;
598 
599  for (a = 0; a < tot; a++) {
600  in[a] = t[0] * f0[a] + t[1] * f1[a] + t[2] * f2[a] + t[3] * f3[a];
601  }
602 }
603 
604 static void rel_flerp(int tot, float *in, const float *ref, const float *out, float fac)
605 {
606  int a;
607 
608  for (a = 0; a < tot; a++) {
609  in[a] -= fac * (ref[a] - out[a]);
610  }
611 }
612 
613 static char *key_block_get_data(Key *key, KeyBlock *actkb, KeyBlock *kb, char **freedata)
614 {
615  if (kb == actkb) {
616  /* this hack makes it possible to edit shape keys in
617  * edit mode with shape keys blending applied */
618  if (GS(key->from->name) == ID_ME) {
619  Mesh *me;
620  BMVert *eve;
621  BMIter iter;
622  float(*co)[3];
623  int a;
624 
625  me = (Mesh *)key->from;
626 
627  if (me->edit_mesh && me->edit_mesh->bm->totvert == kb->totelem) {
628  a = 0;
629  co = MEM_mallocN(sizeof(float[3]) * me->edit_mesh->bm->totvert, "key_block_get_data");
630 
631  BM_ITER_MESH (eve, &iter, me->edit_mesh->bm, BM_VERTS_OF_MESH) {
632  copy_v3_v3(co[a], eve->co);
633  a++;
634  }
635 
636  *freedata = (char *)co;
637  return (char *)co;
638  }
639  }
640  }
641 
642  *freedata = NULL;
643  return kb->data;
644 }
645 
646 /* currently only the first value of 'ofs' may be set. */
647 static bool key_pointer_size(const Key *key, const int mode, int *poinsize, int *ofs, int *step)
648 {
649  if (key->from == NULL) {
650  return false;
651  }
652 
653  *step = 1;
654 
655  switch (GS(key->from->name)) {
656  case ID_ME:
657  *ofs = sizeof(float[KEYELEM_FLOAT_LEN_COORD]);
658  *poinsize = *ofs;
659  break;
660  case ID_LT:
661  *ofs = sizeof(float[KEYELEM_FLOAT_LEN_COORD]);
662  *poinsize = *ofs;
663  break;
664  case ID_CU_LEGACY:
665  if (mode == KEY_MODE_BPOINT) {
666  *ofs = sizeof(float[KEYELEM_FLOAT_LEN_BPOINT]);
667  *step = KEYELEM_ELEM_LEN_BPOINT;
668  }
669  else {
670  *ofs = sizeof(float[KEYELEM_FLOAT_LEN_BEZTRIPLE]);
672  }
673  *poinsize = sizeof(float[KEYELEM_ELEM_SIZE_CURVE]);
674  break;
675  default:
676  BLI_assert_msg(0, "invalid 'key->from' ID type");
677  return false;
678  }
679 
680  return true;
681 }
682 
683 static void cp_key(const int start,
684  int end,
685  const int tot,
686  char *poin,
687  Key *key,
688  KeyBlock *actkb,
689  KeyBlock *kb,
690  float *weights,
691  const int mode)
692 {
693  float ktot = 0.0, kd = 0.0;
694  int elemsize, poinsize = 0, a, step, *ofsp, ofs[32], flagflo = 0;
695  char *k1, *kref, *freek1, *freekref;
696  char *cp, elemstr[8];
697 
698  /* currently always 0, in future key_pointer_size may assign */
699  ofs[1] = 0;
700 
701  if (!key_pointer_size(key, mode, &poinsize, &ofs[0], &step)) {
702  return;
703  }
704 
705  if (end > tot) {
706  end = tot;
707  }
708 
709  if (tot != kb->totelem) {
710  ktot = 0.0;
711  flagflo = 1;
712  if (kb->totelem) {
713  kd = kb->totelem / (float)tot;
714  }
715  else {
716  return;
717  }
718  }
719 
720  k1 = key_block_get_data(key, actkb, kb, &freek1);
721  kref = key_block_get_data(key, actkb, key->refkey, &freekref);
722 
723  /* this exception is needed curves with multiple splines */
724  if (start != 0) {
725 
726  poin += poinsize * start;
727 
728  if (flagflo) {
729  ktot += start * kd;
730  a = (int)floor(ktot);
731  if (a) {
732  ktot -= a;
733  k1 += a * key->elemsize;
734  }
735  }
736  else {
737  k1 += start * key->elemsize;
738  }
739  }
740 
741  if (mode == KEY_MODE_BEZTRIPLE) {
742  elemstr[0] = 1;
743  elemstr[1] = IPO_BEZTRIPLE;
744  elemstr[2] = 0;
745  }
746 
747  /* just do it here, not above! */
748  elemsize = key->elemsize * step;
749 
750  for (a = start; a < end; a += step) {
751  cp = key->elemstr;
752  if (mode == KEY_MODE_BEZTRIPLE) {
753  cp = elemstr;
754  }
755 
756  ofsp = ofs;
757 
758  while (cp[0]) {
759 
760  switch (cp[1]) {
761  case IPO_FLOAT:
762  if (weights) {
763  memcpy(poin, kref, sizeof(float[KEYELEM_FLOAT_LEN_COORD]));
764  if (*weights != 0.0f) {
765  rel_flerp(
766  KEYELEM_FLOAT_LEN_COORD, (float *)poin, (float *)kref, (float *)k1, *weights);
767  }
768  weights++;
769  }
770  else {
771  memcpy(poin, k1, sizeof(float[KEYELEM_FLOAT_LEN_COORD]));
772  }
773  break;
774  case IPO_BPOINT:
775  memcpy(poin, k1, sizeof(float[KEYELEM_FLOAT_LEN_BPOINT]));
776  break;
777  case IPO_BEZTRIPLE:
778  memcpy(poin, k1, sizeof(float[KEYELEM_FLOAT_LEN_BEZTRIPLE]));
779  break;
780  default:
781  /* should never happen */
782  if (freek1) {
783  MEM_freeN(freek1);
784  }
785  if (freekref) {
786  MEM_freeN(freekref);
787  }
788  BLI_assert_msg(0, "invalid 'cp[1]'");
789  return;
790  }
791 
792  poin += *ofsp;
793  cp += 2;
794  ofsp++;
795  }
796 
797  /* are we going to be nasty? */
798  if (flagflo) {
799  ktot += kd;
800  while (ktot >= 1.0f) {
801  ktot -= 1.0f;
802  k1 += elemsize;
803  kref += elemsize;
804  }
805  }
806  else {
807  k1 += elemsize;
808  kref += elemsize;
809  }
810  }
811 
812  if (freek1) {
813  MEM_freeN(freek1);
814  }
815  if (freekref) {
816  MEM_freeN(freekref);
817  }
818 }
819 
820 static void cp_cu_key(Curve *cu,
821  Key *key,
822  KeyBlock *actkb,
823  KeyBlock *kb,
824  const int start,
825  int end,
826  char *out,
827  const int tot)
828 {
829  Nurb *nu;
830  int a, step, a1, a2;
831 
832  for (a = 0, nu = cu->nurb.first; nu; nu = nu->next, a += step) {
833  if (nu->bp) {
834  step = KEYELEM_ELEM_LEN_BPOINT * nu->pntsu * nu->pntsv;
835 
836  a1 = max_ii(a, start);
837  a2 = min_ii(a + step, end);
838 
839  if (a1 < a2) {
840  cp_key(a1, a2, tot, out, key, actkb, kb, NULL, KEY_MODE_BPOINT);
841  }
842  }
843  else if (nu->bezt) {
844  step = KEYELEM_ELEM_LEN_BEZTRIPLE * nu->pntsu;
845 
846  /* exception because keys prefer to work with complete blocks */
847  a1 = max_ii(a, start);
848  a2 = min_ii(a + step, end);
849 
850  if (a1 < a2) {
851  cp_key(a1, a2, tot, out, key, actkb, kb, NULL, KEY_MODE_BEZTRIPLE);
852  }
853  }
854  else {
855  step = 0;
856  }
857  }
858 }
859 
860 static void key_evaluate_relative(const int start,
861  int end,
862  const int tot,
863  char *basispoin,
864  Key *key,
865  KeyBlock *actkb,
866  float **per_keyblock_weights,
867  const int mode)
868 {
869  KeyBlock *kb;
870  int *ofsp, ofs[3], elemsize, b, step;
871  char *cp, *poin, *reffrom, *from, elemstr[8];
872  int poinsize, keyblock_index;
873 
874  /* currently always 0, in future key_pointer_size may assign */
875  ofs[1] = 0;
876 
877  if (!key_pointer_size(key, mode, &poinsize, &ofs[0], &step)) {
878  return;
879  }
880 
881  if (end > tot) {
882  end = tot;
883  }
884 
885  /* in case of beztriple */
886  elemstr[0] = 1; /* nr of ipofloats */
887  elemstr[1] = IPO_BEZTRIPLE;
888  elemstr[2] = 0;
889 
890  /* just here, not above! */
891  elemsize = key->elemsize * step;
892 
893  /* step 1 init */
894  cp_key(start, end, tot, basispoin, key, actkb, key->refkey, NULL, mode);
895 
896  /* step 2: do it */
897 
898  for (kb = key->block.first, keyblock_index = 0; kb; kb = kb->next, keyblock_index++) {
899  if (kb != key->refkey) {
900  float icuval = kb->curval;
901 
902  /* only with value, and no difference allowed */
903  if (!(kb->flag & KEYBLOCK_MUTE) && icuval != 0.0f && kb->totelem == tot) {
904  KeyBlock *refb;
905  float weight,
906  *weights = per_keyblock_weights ? per_keyblock_weights[keyblock_index] : NULL;
907  char *freefrom = NULL;
908 
909  /* reference now can be any block */
910  refb = BLI_findlink(&key->block, kb->relative);
911  if (refb == NULL) {
912  continue;
913  }
914 
915  poin = basispoin;
916  from = key_block_get_data(key, actkb, kb, &freefrom);
917 
918  /* For meshes, use the original values instead of the bmesh values to
919  * maintain a constant offset. */
920  reffrom = refb->data;
921 
922  poin += start * poinsize;
923  reffrom += key->elemsize * start; /* key elemsize yes! */
924  from += key->elemsize * start;
925 
926  for (b = start; b < end; b += step) {
927 
928  weight = weights ? (*weights * icuval) : icuval;
929 
930  cp = key->elemstr;
931  if (mode == KEY_MODE_BEZTRIPLE) {
932  cp = elemstr;
933  }
934 
935  ofsp = ofs;
936 
937  while (cp[0]) { /* (cp[0] == amount) */
938 
939  switch (cp[1]) {
940  case IPO_FLOAT:
942  (float *)poin,
943  (float *)reffrom,
944  (float *)from,
945  weight);
946  break;
947  case IPO_BPOINT:
949  (float *)poin,
950  (float *)reffrom,
951  (float *)from,
952  weight);
953  break;
954  case IPO_BEZTRIPLE:
956  (float *)poin,
957  (float *)reffrom,
958  (float *)from,
959  weight);
960  break;
961  default:
962  /* should never happen */
963  if (freefrom) {
964  MEM_freeN(freefrom);
965  }
966  BLI_assert_msg(0, "invalid 'cp[1]'");
967  return;
968  }
969 
970  poin += *ofsp;
971 
972  cp += 2;
973  ofsp++;
974  }
975 
976  reffrom += elemsize;
977  from += elemsize;
978 
979  if (weights) {
980  weights++;
981  }
982  }
983 
984  if (freefrom) {
985  MEM_freeN(freefrom);
986  }
987  }
988  }
989  }
990 }
991 
992 static void do_key(const int start,
993  int end,
994  const int tot,
995  char *poin,
996  Key *key,
997  KeyBlock *actkb,
998  KeyBlock **k,
999  float *t,
1000  const int mode)
1001 {
1002  float k1tot = 0.0, k2tot = 0.0, k3tot = 0.0, k4tot = 0.0;
1003  float k1d = 0.0, k2d = 0.0, k3d = 0.0, k4d = 0.0;
1004  int a, step, ofs[32], *ofsp;
1005  int flagdo = 15, flagflo = 0, elemsize, poinsize = 0;
1006  char *k1, *k2, *k3, *k4, *freek1, *freek2, *freek3, *freek4;
1007  char *cp, elemstr[8];
1008 
1009  /* currently always 0, in future key_pointer_size may assign */
1010  ofs[1] = 0;
1011 
1012  if (!key_pointer_size(key, mode, &poinsize, &ofs[0], &step)) {
1013  return;
1014  }
1015 
1016  if (end > tot) {
1017  end = tot;
1018  }
1019 
1020  k1 = key_block_get_data(key, actkb, k[0], &freek1);
1021  k2 = key_block_get_data(key, actkb, k[1], &freek2);
1022  k3 = key_block_get_data(key, actkb, k[2], &freek3);
1023  k4 = key_block_get_data(key, actkb, k[3], &freek4);
1024 
1025  /* Test for more or less points (per key!) */
1026  if (tot != k[0]->totelem) {
1027  k1tot = 0.0;
1028  flagflo |= 1;
1029  if (k[0]->totelem) {
1030  k1d = k[0]->totelem / (float)tot;
1031  }
1032  else {
1033  flagdo -= 1;
1034  }
1035  }
1036  if (tot != k[1]->totelem) {
1037  k2tot = 0.0;
1038  flagflo |= 2;
1039  if (k[0]->totelem) {
1040  k2d = k[1]->totelem / (float)tot;
1041  }
1042  else {
1043  flagdo -= 2;
1044  }
1045  }
1046  if (tot != k[2]->totelem) {
1047  k3tot = 0.0;
1048  flagflo |= 4;
1049  if (k[0]->totelem) {
1050  k3d = k[2]->totelem / (float)tot;
1051  }
1052  else {
1053  flagdo -= 4;
1054  }
1055  }
1056  if (tot != k[3]->totelem) {
1057  k4tot = 0.0;
1058  flagflo |= 8;
1059  if (k[0]->totelem) {
1060  k4d = k[3]->totelem / (float)tot;
1061  }
1062  else {
1063  flagdo -= 8;
1064  }
1065  }
1066 
1067  /* this exception is needed for curves with multiple splines */
1068  if (start != 0) {
1069 
1070  poin += poinsize * start;
1071 
1072  if (flagdo & 1) {
1073  if (flagflo & 1) {
1074  k1tot += start * k1d;
1075  a = (int)floor(k1tot);
1076  if (a) {
1077  k1tot -= a;
1078  k1 += a * key->elemsize;
1079  }
1080  }
1081  else {
1082  k1 += start * key->elemsize;
1083  }
1084  }
1085  if (flagdo & 2) {
1086  if (flagflo & 2) {
1087  k2tot += start * k2d;
1088  a = (int)floor(k2tot);
1089  if (a) {
1090  k2tot -= a;
1091  k2 += a * key->elemsize;
1092  }
1093  }
1094  else {
1095  k2 += start * key->elemsize;
1096  }
1097  }
1098  if (flagdo & 4) {
1099  if (flagflo & 4) {
1100  k3tot += start * k3d;
1101  a = (int)floor(k3tot);
1102  if (a) {
1103  k3tot -= a;
1104  k3 += a * key->elemsize;
1105  }
1106  }
1107  else {
1108  k3 += start * key->elemsize;
1109  }
1110  }
1111  if (flagdo & 8) {
1112  if (flagflo & 8) {
1113  k4tot += start * k4d;
1114  a = (int)floor(k4tot);
1115  if (a) {
1116  k4tot -= a;
1117  k4 += a * key->elemsize;
1118  }
1119  }
1120  else {
1121  k4 += start * key->elemsize;
1122  }
1123  }
1124  }
1125 
1126  /* in case of beztriple */
1127  elemstr[0] = 1; /* nr of ipofloats */
1128  elemstr[1] = IPO_BEZTRIPLE;
1129  elemstr[2] = 0;
1130 
1131  /* only here, not above! */
1132  elemsize = key->elemsize * step;
1133 
1134  for (a = start; a < end; a += step) {
1135  cp = key->elemstr;
1136  if (mode == KEY_MODE_BEZTRIPLE) {
1137  cp = elemstr;
1138  }
1139 
1140  ofsp = ofs;
1141 
1142  while (cp[0]) { /* (cp[0] == amount) */
1143 
1144  switch (cp[1]) {
1145  case IPO_FLOAT:
1147  (float *)poin,
1148  (float *)k1,
1149  (float *)k2,
1150  (float *)k3,
1151  (float *)k4,
1152  t);
1153  break;
1154  case IPO_BPOINT:
1156  (float *)poin,
1157  (float *)k1,
1158  (float *)k2,
1159  (float *)k3,
1160  (float *)k4,
1161  t);
1162  break;
1163  case IPO_BEZTRIPLE:
1165  (void *)poin,
1166  (void *)k1,
1167  (void *)k2,
1168  (void *)k3,
1169  (void *)k4,
1170  t);
1171  break;
1172  default:
1173  /* should never happen */
1174  if (freek1) {
1175  MEM_freeN(freek1);
1176  }
1177  if (freek2) {
1178  MEM_freeN(freek2);
1179  }
1180  if (freek3) {
1181  MEM_freeN(freek3);
1182  }
1183  if (freek4) {
1184  MEM_freeN(freek4);
1185  }
1186  BLI_assert_msg(0, "invalid 'cp[1]'");
1187  return;
1188  }
1189 
1190  poin += *ofsp;
1191  cp += 2;
1192  ofsp++;
1193  }
1194  /* lets do it the difficult way: when keys have a different size */
1195  if (flagdo & 1) {
1196  if (flagflo & 1) {
1197  k1tot += k1d;
1198  while (k1tot >= 1.0f) {
1199  k1tot -= 1.0f;
1200  k1 += elemsize;
1201  }
1202  }
1203  else {
1204  k1 += elemsize;
1205  }
1206  }
1207  if (flagdo & 2) {
1208  if (flagflo & 2) {
1209  k2tot += k2d;
1210  while (k2tot >= 1.0f) {
1211  k2tot -= 1.0f;
1212  k2 += elemsize;
1213  }
1214  }
1215  else {
1216  k2 += elemsize;
1217  }
1218  }
1219  if (flagdo & 4) {
1220  if (flagflo & 4) {
1221  k3tot += k3d;
1222  while (k3tot >= 1.0f) {
1223  k3tot -= 1.0f;
1224  k3 += elemsize;
1225  }
1226  }
1227  else {
1228  k3 += elemsize;
1229  }
1230  }
1231  if (flagdo & 8) {
1232  if (flagflo & 8) {
1233  k4tot += k4d;
1234  while (k4tot >= 1.0f) {
1235  k4tot -= 1.0f;
1236  k4 += elemsize;
1237  }
1238  }
1239  else {
1240  k4 += elemsize;
1241  }
1242  }
1243  }
1244 
1245  if (freek1) {
1246  MEM_freeN(freek1);
1247  }
1248  if (freek2) {
1249  MEM_freeN(freek2);
1250  }
1251  if (freek3) {
1252  MEM_freeN(freek3);
1253  }
1254  if (freek4) {
1255  MEM_freeN(freek4);
1256  }
1257 }
1258 
1259 static float *get_weights_array(Object *ob, char *vgroup, WeightsArrayCache *cache)
1260 {
1261  MDeformVert *dvert = NULL;
1262  BMEditMesh *em = NULL;
1263  BMIter iter;
1264  BMVert *eve;
1265  int totvert = 0, defgrp_index = 0;
1266 
1267  /* no vgroup string set? */
1268  if (vgroup[0] == 0) {
1269  return NULL;
1270  }
1271 
1272  /* gather dvert and totvert */
1273  if (ob->type == OB_MESH) {
1274  Mesh *me = ob->data;
1275  dvert = me->dvert;
1276  totvert = me->totvert;
1277 
1278  if (me->edit_mesh && me->edit_mesh->bm->totvert == totvert) {
1279  em = me->edit_mesh;
1280  }
1281  }
1282  else if (ob->type == OB_LATTICE) {
1283  Lattice *lt = ob->data;
1284  dvert = lt->dvert;
1285  totvert = lt->pntsu * lt->pntsv * lt->pntsw;
1286  }
1287 
1288  if (dvert == NULL) {
1289  return NULL;
1290  }
1291 
1292  /* find the group (weak loop-in-loop) */
1293  defgrp_index = BKE_object_defgroup_name_index(ob, vgroup);
1294  if (defgrp_index != -1) {
1295  float *weights;
1296 
1297  if (cache) {
1298  if (cache->defgroup_weights == NULL) {
1299  int num_defgroup = BKE_object_defgroup_count(ob);
1300  cache->defgroup_weights = MEM_callocN(sizeof(*cache->defgroup_weights) * num_defgroup,
1301  "cached defgroup weights");
1302  cache->num_defgroup_weights = num_defgroup;
1303  }
1304 
1305  if (cache->defgroup_weights[defgrp_index]) {
1306  return cache->defgroup_weights[defgrp_index];
1307  }
1308  }
1309 
1310  weights = MEM_mallocN(totvert * sizeof(float), "weights");
1311 
1312  if (em) {
1313  int i;
1314  const int cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT);
1315  BM_ITER_MESH_INDEX (eve, &iter, em->bm, BM_VERTS_OF_MESH, i) {
1316  dvert = BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset);
1317  weights[i] = BKE_defvert_find_weight(dvert, defgrp_index);
1318  }
1319  }
1320  else {
1321  for (int i = 0; i < totvert; i++, dvert++) {
1322  weights[i] = BKE_defvert_find_weight(dvert, defgrp_index);
1323  }
1324  }
1325 
1326  if (cache) {
1327  cache->defgroup_weights[defgrp_index] = weights;
1328  }
1329 
1330  return weights;
1331  }
1332  return NULL;
1333 }
1334 
1336 {
1337  KeyBlock *keyblock;
1338  float **per_keyblock_weights;
1339  int keyblock_index;
1340 
1341  per_keyblock_weights = MEM_mallocN(sizeof(*per_keyblock_weights) * key->totkey,
1342  "per keyblock weights");
1343 
1344  for (keyblock = key->block.first, keyblock_index = 0; keyblock;
1345  keyblock = keyblock->next, keyblock_index++) {
1346  per_keyblock_weights[keyblock_index] = get_weights_array(ob, keyblock->vgroup, cache);
1347  }
1348 
1349  return per_keyblock_weights;
1350 }
1351 
1353  float **per_keyblock_weights,
1354  WeightsArrayCache *cache)
1355 {
1356  int a;
1357 
1358  if (cache) {
1359  if (cache->num_defgroup_weights) {
1360  for (a = 0; a < cache->num_defgroup_weights; a++) {
1361  if (cache->defgroup_weights[a]) {
1362  MEM_freeN(cache->defgroup_weights[a]);
1363  }
1364  }
1365  MEM_freeN(cache->defgroup_weights);
1366  }
1367  cache->defgroup_weights = NULL;
1368  }
1369  else {
1370  for (a = 0; a < key->totkey; a++) {
1371  if (per_keyblock_weights[a]) {
1372  MEM_freeN(per_keyblock_weights[a]);
1373  }
1374  }
1375  }
1376 
1377  MEM_freeN(per_keyblock_weights);
1378 }
1379 
1380 static void do_mesh_key(Object *ob, Key *key, char *out, const int tot)
1381 {
1382  KeyBlock *k[4], *actkb = BKE_keyblock_from_object(ob);
1383  float t[4];
1384  int flag = 0;
1385 
1386  if (key->type == KEY_RELATIVE) {
1387  WeightsArrayCache cache = {0, NULL};
1388  float **per_keyblock_weights;
1389  per_keyblock_weights = keyblock_get_per_block_weights(ob, key, &cache);
1391  0, tot, tot, (char *)out, key, actkb, per_keyblock_weights, KEY_MODE_DUMMY);
1392  keyblock_free_per_block_weights(key, per_keyblock_weights, &cache);
1393  }
1394  else {
1395  const float ctime_scaled = key->ctime / 100.0f;
1396 
1397  flag = setkeys(ctime_scaled, &key->block, k, t, 0);
1398 
1399  if (flag == 0) {
1400  do_key(0, tot, tot, (char *)out, key, actkb, k, t, KEY_MODE_DUMMY);
1401  }
1402  else {
1403  cp_key(0, tot, tot, (char *)out, key, actkb, k[2], NULL, KEY_MODE_DUMMY);
1404  }
1405  }
1406 }
1407 
1408 static void do_cu_key(
1409  Curve *cu, Key *key, KeyBlock *actkb, KeyBlock **k, float *t, char *out, const int tot)
1410 {
1411  Nurb *nu;
1412  int a, step;
1413 
1414  for (a = 0, nu = cu->nurb.first; nu; nu = nu->next, a += step) {
1415  if (nu->bp) {
1416  step = KEYELEM_ELEM_LEN_BPOINT * nu->pntsu * nu->pntsv;
1417  do_key(a, a + step, tot, out, key, actkb, k, t, KEY_MODE_BPOINT);
1418  }
1419  else if (nu->bezt) {
1420  step = KEYELEM_ELEM_LEN_BEZTRIPLE * nu->pntsu;
1421  do_key(a, a + step, tot, out, key, actkb, k, t, KEY_MODE_BEZTRIPLE);
1422  }
1423  else {
1424  step = 0;
1425  }
1426  }
1427 }
1428 
1429 static void do_rel_cu_key(Curve *cu, Key *key, KeyBlock *actkb, char *out, const int tot)
1430 {
1431  Nurb *nu;
1432  int a, step;
1433 
1434  for (a = 0, nu = cu->nurb.first; nu; nu = nu->next, a += step) {
1435  if (nu->bp) {
1436  step = KEYELEM_ELEM_LEN_BPOINT * nu->pntsu * nu->pntsv;
1437  key_evaluate_relative(a, a + step, tot, out, key, actkb, NULL, KEY_MODE_BPOINT);
1438  }
1439  else if (nu->bezt) {
1440  step = KEYELEM_ELEM_LEN_BEZTRIPLE * nu->pntsu;
1441  key_evaluate_relative(a, a + step, tot, out, key, actkb, NULL, KEY_MODE_BEZTRIPLE);
1442  }
1443  else {
1444  step = 0;
1445  }
1446  }
1447 }
1448 
1449 static void do_curve_key(Object *ob, Key *key, char *out, const int tot)
1450 {
1451  Curve *cu = ob->data;
1452  KeyBlock *k[4], *actkb = BKE_keyblock_from_object(ob);
1453  float t[4];
1454  int flag = 0;
1455 
1456  if (key->type == KEY_RELATIVE) {
1457  do_rel_cu_key(cu, cu->key, actkb, out, tot);
1458  }
1459  else {
1460  const float ctime_scaled = key->ctime / 100.0f;
1461 
1462  flag = setkeys(ctime_scaled, &key->block, k, t, 0);
1463 
1464  if (flag == 0) {
1465  do_cu_key(cu, key, actkb, k, t, out, tot);
1466  }
1467  else {
1468  cp_cu_key(cu, key, actkb, k[2], 0, tot, out, tot);
1469  }
1470  }
1471 }
1472 
1473 static void do_latt_key(Object *ob, Key *key, char *out, const int tot)
1474 {
1475  Lattice *lt = ob->data;
1476  KeyBlock *k[4], *actkb = BKE_keyblock_from_object(ob);
1477  float t[4];
1478  int flag;
1479 
1480  if (key->type == KEY_RELATIVE) {
1481  float **per_keyblock_weights;
1482  per_keyblock_weights = keyblock_get_per_block_weights(ob, key, NULL);
1484  0, tot, tot, (char *)out, key, actkb, per_keyblock_weights, KEY_MODE_DUMMY);
1485  keyblock_free_per_block_weights(key, per_keyblock_weights, NULL);
1486  }
1487  else {
1488  const float ctime_scaled = key->ctime / 100.0f;
1489 
1490  flag = setkeys(ctime_scaled, &key->block, k, t, 0);
1491 
1492  if (flag == 0) {
1493  do_key(0, tot, tot, (char *)out, key, actkb, k, t, KEY_MODE_DUMMY);
1494  }
1495  else {
1496  cp_key(0, tot, tot, (char *)out, key, actkb, k[2], NULL, KEY_MODE_DUMMY);
1497  }
1498  }
1499 
1500  if (lt->flag & LT_OUTSIDE) {
1501  outside_lattice(lt);
1502  }
1503 }
1504 
1505 static void keyblock_data_convert_to_mesh(const float (*fp)[3], MVert *mvert, const int totvert);
1506 static void keyblock_data_convert_to_lattice(const float (*fp)[3],
1507  BPoint *bpoint,
1508  const int totpoint);
1509 static void keyblock_data_convert_to_curve(const float *fp, ListBase *nurb, const int totpoint);
1510 
1512  Object *ob, int *r_totelem, float *arr, size_t arr_size, ID *obdata)
1513 {
1514  Key *key = BKE_key_from_object(ob);
1515  KeyBlock *actkb = BKE_keyblock_from_object(ob);
1516  char *out;
1517  int tot = 0, size = 0;
1518 
1519  if (key == NULL || BLI_listbase_is_empty(&key->block)) {
1520  return NULL;
1521  }
1522 
1523  /* compute size of output array */
1524  if (ob->type == OB_MESH) {
1525  Mesh *me = ob->data;
1526 
1527  tot = me->totvert;
1528  size = tot * sizeof(float[KEYELEM_FLOAT_LEN_COORD]);
1529  }
1530  else if (ob->type == OB_LATTICE) {
1531  Lattice *lt = ob->data;
1532 
1533  tot = lt->pntsu * lt->pntsv * lt->pntsw;
1534  size = tot * sizeof(float[KEYELEM_FLOAT_LEN_COORD]);
1535  }
1536  else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) {
1537  Curve *cu = ob->data;
1538 
1540  size = tot * sizeof(float[KEYELEM_ELEM_SIZE_CURVE]);
1541  }
1542 
1543  /* if nothing to interpolate, cancel */
1544  if (tot == 0 || size == 0) {
1545  return NULL;
1546  }
1547 
1548  /* allocate array */
1549  if (arr == NULL) {
1550  out = MEM_callocN(size, "BKE_key_evaluate_object out");
1551  }
1552  else {
1553  if (arr_size != size) {
1554  return NULL;
1555  }
1556 
1557  out = (char *)arr;
1558  }
1559 
1560  if (ob->shapeflag & OB_SHAPE_LOCK) {
1561  /* shape locked, copy the locked shape instead of blending */
1562  KeyBlock *kb = BLI_findlink(&key->block, ob->shapenr - 1);
1563 
1564  if (kb && (kb->flag & KEYBLOCK_MUTE)) {
1565  kb = key->refkey;
1566  }
1567 
1568  if (kb == NULL) {
1569  kb = key->block.first;
1570  ob->shapenr = 1;
1571  }
1572 
1573  if (OB_TYPE_SUPPORT_VGROUP(ob->type)) {
1574  float *weights = get_weights_array(ob, kb->vgroup, NULL);
1575 
1576  cp_key(0, tot, tot, out, key, actkb, kb, weights, 0);
1577 
1578  if (weights) {
1579  MEM_freeN(weights);
1580  }
1581  }
1582  else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) {
1583  cp_cu_key(ob->data, key, actkb, kb, 0, tot, out, tot);
1584  }
1585  }
1586  else {
1587  if (ob->type == OB_MESH) {
1588  do_mesh_key(ob, key, out, tot);
1589  }
1590  else if (ob->type == OB_LATTICE) {
1591  do_latt_key(ob, key, out, tot);
1592  }
1593  else if (ob->type == OB_CURVES_LEGACY) {
1594  do_curve_key(ob, key, out, tot);
1595  }
1596  else if (ob->type == OB_SURF) {
1597  do_curve_key(ob, key, out, tot);
1598  }
1599  }
1600 
1601  if (obdata != NULL) {
1602  switch (GS(obdata->name)) {
1603  case ID_ME: {
1604  Mesh *mesh = (Mesh *)obdata;
1605  const int totvert = min_ii(tot, mesh->totvert);
1606  keyblock_data_convert_to_mesh((const float(*)[3])out, mesh->mvert, totvert);
1607  break;
1608  }
1609  case ID_LT: {
1610  Lattice *lattice = (Lattice *)obdata;
1611  const int totpoint = min_ii(tot, lattice->pntsu * lattice->pntsv * lattice->pntsw);
1612  keyblock_data_convert_to_lattice((const float(*)[3])out, lattice->def, totpoint);
1613  break;
1614  }
1615  case ID_CU_LEGACY: {
1616  Curve *curve = (Curve *)obdata;
1617  const int totpoint = min_ii(tot, BKE_keyblock_curve_element_count(&curve->nurb));
1618  keyblock_data_convert_to_curve((const float *)out, &curve->nurb, totpoint);
1619  break;
1620  }
1621  default:
1623  }
1624  }
1625 
1626  if (r_totelem) {
1627  *r_totelem = tot;
1628  }
1629  return (float *)out;
1630 }
1631 
1632 float *BKE_key_evaluate_object(Object *ob, int *r_totelem)
1633 {
1634  return BKE_key_evaluate_object_ex(ob, r_totelem, NULL, 0, NULL);
1635 }
1636 
1637 int BKE_keyblock_element_count_from_shape(const Key *key, const int shape_index)
1638 {
1639  int result = 0;
1640  int index = 0;
1641  for (const KeyBlock *kb = key->block.first; kb; kb = kb->next, index++) {
1642  if (ELEM(shape_index, -1, index)) {
1643  result += kb->totelem;
1644  }
1645  }
1646  return result;
1647 }
1648 
1650 {
1651  return BKE_keyblock_element_count_from_shape(key, -1);
1652 }
1653 
1654 size_t BKE_keyblock_element_calc_size_from_shape(const Key *key, const int shape_index)
1655 {
1656  return (size_t)BKE_keyblock_element_count_from_shape(key, shape_index) * key->elemsize;
1657 }
1658 
1660 {
1662 }
1663 
1664 /* -------------------------------------------------------------------- */
1671 void BKE_keyblock_data_get_from_shape(const Key *key, float (*arr)[3], const int shape_index)
1672 {
1673  uint8_t *elements = (uint8_t *)arr;
1674  int index = 0;
1675  for (const KeyBlock *kb = key->block.first; kb; kb = kb->next, index++) {
1676  if (ELEM(shape_index, -1, index)) {
1677  const int block_elem_len = kb->totelem * key->elemsize;
1678  memcpy(elements, kb->data, block_elem_len);
1679  elements += block_elem_len;
1680  }
1681  }
1682 }
1683 
1684 void BKE_keyblock_data_get(const Key *key, float (*arr)[3])
1685 {
1686  BKE_keyblock_data_get_from_shape(key, arr, -1);
1687 }
1688 
1690  const int shape_index,
1691  const float (*coords)[3],
1692  const float mat[4][4])
1693 {
1694  if (key->elemsize != sizeof(float[3])) {
1695  BLI_assert_msg(0, "Invalid elemsize");
1696  return;
1697  }
1698 
1699  const float(*elements)[3] = coords;
1700 
1701  int index = 0;
1702  for (KeyBlock *kb = key->block.first; kb; kb = kb->next, index++) {
1703  if (ELEM(shape_index, -1, index)) {
1704  const int block_elem_len = kb->totelem;
1705  float(*block_data)[3] = (float(*)[3])kb->data;
1706  for (int data_offset = 0; data_offset < block_elem_len; ++data_offset) {
1707  const float *src_data = (const float *)(elements + data_offset);
1708  float *dst_data = (float *)(block_data + data_offset);
1709  mul_v3_m4v3(dst_data, mat, src_data);
1710  }
1711  elements += block_elem_len;
1712  }
1713  }
1714 }
1715 
1717  Key *key, const ListBase *nurb, const int shape_index, const void *data, const float mat[4][4])
1718 {
1719  const uint8_t *elements = data;
1720 
1721  int index = 0;
1722  for (KeyBlock *kb = key->block.first; kb; kb = kb->next, index++) {
1723  if (ELEM(shape_index, -1, index)) {
1724  const int block_elem_size = kb->totelem * key->elemsize;
1725  BKE_keyblock_curve_data_transform(nurb, mat, elements, kb->data);
1726  elements += block_elem_size;
1727  }
1728  }
1729 }
1730 
1731 void BKE_keyblock_data_set(Key *key, const int shape_index, const void *data)
1732 {
1733  const uint8_t *elements = data;
1734  int index = 0;
1735  for (KeyBlock *kb = key->block.first; kb; kb = kb->next, index++) {
1736  if (ELEM(shape_index, -1, index)) {
1737  const int block_elem_size = kb->totelem * key->elemsize;
1738  memcpy(kb->data, elements, block_elem_size);
1739  elements += block_elem_size;
1740  }
1741  }
1742 }
1743 
1746 bool BKE_key_idtype_support(const short id_type)
1747 {
1748  switch (id_type) {
1749  case ID_ME:
1750  case ID_CU_LEGACY:
1751  case ID_LT:
1752  return true;
1753  default:
1754  return false;
1755  }
1756 }
1757 
1759 {
1760  switch (GS(id->name)) {
1761  case ID_ME: {
1762  Mesh *me = (Mesh *)id;
1763  return &me->key;
1764  }
1765  case ID_CU_LEGACY: {
1766  Curve *cu = (Curve *)id;
1767  if (cu->vfont == NULL) {
1768  return &cu->key;
1769  }
1770  break;
1771  }
1772  case ID_LT: {
1773  Lattice *lt = (Lattice *)id;
1774  return &lt->key;
1775  }
1776  default:
1777  break;
1778  }
1779 
1780  return NULL;
1781 }
1782 
1784 {
1785  Key **key_p;
1786  key_p = BKE_key_from_id_p(id);
1787  if (key_p) {
1788  return *key_p;
1789  }
1790 
1791  return NULL;
1792 }
1793 
1795 {
1796  if (ob == NULL || ob->data == NULL) {
1797  return NULL;
1798  }
1799 
1800  return BKE_key_from_id_p(ob->data);
1801 }
1802 
1804 {
1805  Key **key_p;
1806  key_p = BKE_key_from_object_p(ob);
1807  if (key_p) {
1808  return *key_p;
1809  }
1810 
1811  return NULL;
1812 }
1813 
1814 KeyBlock *BKE_keyblock_add(Key *key, const char *name)
1815 {
1816  KeyBlock *kb;
1817  float curpos = -0.1;
1818  int tot;
1819 
1820  kb = key->block.last;
1821  if (kb) {
1822  curpos = kb->pos;
1823  }
1824 
1825  kb = MEM_callocN(sizeof(KeyBlock), "Keyblock");
1826  BLI_addtail(&key->block, kb);
1827  kb->type = KEY_LINEAR;
1828 
1829  tot = BLI_listbase_count(&key->block);
1830  if (name) {
1831  BLI_strncpy(kb->name, name, sizeof(kb->name));
1832  }
1833  else {
1834  if (tot == 1) {
1835  BLI_strncpy(kb->name, DATA_("Basis"), sizeof(kb->name));
1836  }
1837  else {
1838  BLI_snprintf(kb->name, sizeof(kb->name), DATA_("Key %d"), tot - 1);
1839  }
1840  }
1841 
1842  BLI_uniquename(&key->block, kb, DATA_("Key"), '.', offsetof(KeyBlock, name), sizeof(kb->name));
1843 
1844  kb->uid = key->uidgen++;
1845 
1846  key->totkey++;
1847  if (key->totkey == 1) {
1848  key->refkey = kb;
1849  }
1850 
1851  kb->slidermin = 0.0f;
1852  kb->slidermax = 1.0f;
1853 
1857  kb->pos = curpos + 0.1f; /* only used for absolute shape keys */
1858 
1859  return kb;
1860 }
1861 
1862 KeyBlock *BKE_keyblock_add_ctime(Key *key, const char *name, const bool do_force)
1863 {
1864  KeyBlock *kb = BKE_keyblock_add(key, name);
1865  const float cpos = key->ctime / 100.0f;
1866 
1867  /* In case of absolute keys, there is no point in adding more than one key with the same pos.
1868  * Hence only set new keybloc pos to current time if none previous one already use it.
1869  * Now at least people just adding absolute keys without touching to ctime
1870  * won't have to systematically use retiming func (and have ordering issues, too). See T39897.
1871  */
1872  if (!do_force && (key->type != KEY_RELATIVE)) {
1873  KeyBlock *it_kb;
1874  for (it_kb = key->block.first; it_kb; it_kb = it_kb->next) {
1875  /* Use epsilon to avoid floating point precision issues.
1876  * 1e-3 because the position is stored as frame * 1e-2. */
1877  if (compare_ff(it_kb->pos, cpos, 1e-3f)) {
1878  return kb;
1879  }
1880  }
1881  }
1882  if (do_force || (key->type != KEY_RELATIVE)) {
1883  kb->pos = cpos;
1884  BKE_key_sort(key);
1885  }
1886 
1887  return kb;
1888 }
1889 
1891 {
1892  Key *key = BKE_key_from_object(ob);
1893 
1894  if (key) {
1895  KeyBlock *kb = BLI_findlink(&key->block, ob->shapenr - 1);
1896  return kb;
1897  }
1898 
1899  return NULL;
1900 }
1901 
1903 {
1904  Key *key = BKE_key_from_object(ob);
1905 
1906  if (key) {
1907  return key->refkey;
1908  }
1909 
1910  return NULL;
1911 }
1912 
1914 {
1915  if (key) {
1916  KeyBlock *kb = key->block.first;
1917 
1918  for (int i = 1; i < key->totkey; i++) {
1919  kb = kb->next;
1920 
1921  if (index == i) {
1922  return kb;
1923  }
1924  }
1925  }
1926 
1927  return NULL;
1928 }
1929 
1930 KeyBlock *BKE_keyblock_find_name(Key *key, const char name[])
1931 {
1932  return BLI_findstring(&key->block, name, offsetof(KeyBlock, name));
1933 }
1934 
1935 void BKE_keyblock_copy_settings(KeyBlock *kb_dst, const KeyBlock *kb_src)
1936 {
1937  kb_dst->pos = kb_src->pos;
1938  kb_dst->curval = kb_src->curval;
1939  kb_dst->type = kb_src->type;
1940  kb_dst->relative = kb_src->relative;
1941  BLI_strncpy(kb_dst->vgroup, kb_src->vgroup, sizeof(kb_dst->vgroup));
1942  kb_dst->slidermin = kb_src->slidermin;
1943  kb_dst->slidermax = kb_src->slidermax;
1944 }
1945 
1946 char *BKE_keyblock_curval_rnapath_get(const Key *key, const KeyBlock *kb)
1947 {
1948  PointerRNA ptr;
1949  PropertyRNA *prop;
1950 
1951  /* sanity checks */
1952  if (ELEM(NULL, key, kb)) {
1953  return NULL;
1954  }
1955 
1956  /* create the RNA pointer */
1957  RNA_pointer_create((ID *)&key->id, &RNA_ShapeKey, (KeyBlock *)kb, &ptr);
1958  /* get pointer to the property too */
1959  prop = RNA_struct_find_property(&ptr, "value");
1960 
1961  /* return the path */
1962  return RNA_path_from_ID_to_property(&ptr, prop);
1963 }
1964 
1965 /* conversion functions */
1966 
1967 /************************* Lattice ************************/
1968 
1970 {
1971  BPoint *bp;
1972  float(*fp)[3];
1973  int a, tot;
1974 
1975  BLI_assert(kb->totelem == lt->pntsu * lt->pntsv * lt->pntsw);
1976 
1977  tot = kb->totelem;
1978  if (tot == 0) {
1979  return;
1980  }
1981 
1982  bp = lt->def;
1983  fp = kb->data;
1984  for (a = 0; a < kb->totelem; a++, fp++, bp++) {
1985  copy_v3_v3(*fp, bp->vec);
1986  }
1987 }
1988 
1990 {
1991  int tot;
1992 
1993  tot = lt->pntsu * lt->pntsv * lt->pntsw;
1994  if (tot == 0) {
1995  return;
1996  }
1997 
1998  MEM_SAFE_FREE(kb->data);
1999 
2000  kb->data = MEM_mallocN(lt->key->elemsize * tot, __func__);
2001  kb->totelem = tot;
2002 
2004 }
2005 
2006 static void keyblock_data_convert_to_lattice(const float (*fp)[3],
2007  BPoint *bpoint,
2008  const int totpoint)
2009 {
2010  for (int i = 0; i < totpoint; i++, fp++, bpoint++) {
2011  copy_v3_v3(bpoint->vec, *fp);
2012  }
2013 }
2014 
2016 {
2017  BPoint *bp = lt->def;
2018  const float(*fp)[3] = kb->data;
2019  const int tot = min_ii(kb->totelem, lt->pntsu * lt->pntsv * lt->pntsw);
2020 
2021  keyblock_data_convert_to_lattice(fp, bp, tot);
2022 }
2023 
2024 /************************* Curve ************************/
2025 
2027 {
2028  const Nurb *nu;
2029  int tot = 0;
2030 
2031  nu = nurb->first;
2032  while (nu) {
2033  if (nu->bezt) {
2034  tot += KEYELEM_ELEM_LEN_BEZTRIPLE * nu->pntsu;
2035  }
2036  else if (nu->bp) {
2037  tot += KEYELEM_ELEM_LEN_BPOINT * nu->pntsu * nu->pntsv;
2038  }
2039 
2040  nu = nu->next;
2041  }
2042  return tot;
2043 }
2044 
2046 {
2047  Nurb *nu;
2048  BezTriple *bezt;
2049  BPoint *bp;
2050  float *fp;
2051  int a, tot;
2052 
2053  /* count */
2055 
2056  tot = kb->totelem;
2057  if (tot == 0) {
2058  return;
2059  }
2060 
2061  fp = kb->data;
2062  for (nu = nurb->first; nu; nu = nu->next) {
2063  if (nu->bezt) {
2064  for (a = nu->pntsu, bezt = nu->bezt; a; a--, bezt++) {
2065  for (int i = 0; i < 3; i++) {
2066  copy_v3_v3(&fp[i * 3], bezt->vec[i]);
2067  }
2068  fp[9] = bezt->tilt;
2069  fp[10] = bezt->radius;
2071  }
2072  }
2073  else {
2074  for (a = nu->pntsu * nu->pntsv, bp = nu->bp; a; a--, bp++) {
2075  copy_v3_v3(fp, bp->vec);
2076  fp[3] = bp->tilt;
2077  fp[4] = bp->radius;
2079  }
2080  }
2081  }
2082 }
2083 
2085  const float mat[4][4],
2086  const void *src_data,
2087  void *dst_data)
2088 {
2089  const float *src = src_data;
2090  float *dst = dst_data;
2091  for (Nurb *nu = nurb->first; nu; nu = nu->next) {
2092  if (nu->bezt) {
2093  for (int a = nu->pntsu; a; a--) {
2094  for (int i = 0; i < 3; i++) {
2095  mul_v3_m4v3(&dst[i * 3], mat, &src[i * 3]);
2096  }
2097  dst[9] = src[9];
2098  dst[10] = src[10];
2101  }
2102  }
2103  else {
2104  for (int a = nu->pntsu * nu->pntsv; a; a--) {
2105  mul_v3_m4v3(dst, mat, src);
2106  dst[3] = src[3];
2107  dst[4] = src[4];
2109  dst += KEYELEM_FLOAT_LEN_BPOINT;
2110  }
2111  }
2112  }
2113 }
2114 
2115 void BKE_keyblock_convert_from_curve(const Curve *cu, KeyBlock *kb, const ListBase *nurb)
2116 {
2117  int tot;
2118 
2119  /* count */
2121  if (tot == 0) {
2122  return;
2123  }
2124 
2125  MEM_SAFE_FREE(kb->data);
2126 
2127  kb->data = MEM_mallocN(cu->key->elemsize * tot, __func__);
2128  kb->totelem = tot;
2129 
2130  BKE_keyblock_update_from_curve(cu, kb, nurb);
2131 }
2132 
2133 static void keyblock_data_convert_to_curve(const float *fp, ListBase *nurb, int totpoint)
2134 {
2135  for (Nurb *nu = nurb->first; nu && totpoint > 0; nu = nu->next) {
2136  if (nu->bezt != NULL) {
2137  BezTriple *bezt = nu->bezt;
2138  for (int i = nu->pntsu; i && (totpoint -= KEYELEM_ELEM_LEN_BEZTRIPLE) >= 0;
2139  i--, bezt++, fp += KEYELEM_FLOAT_LEN_BEZTRIPLE) {
2140  for (int j = 0; j < 3; j++) {
2141  copy_v3_v3(bezt->vec[j], &fp[j * 3]);
2142  }
2143  bezt->tilt = fp[9];
2144  bezt->radius = fp[10];
2145  }
2146  }
2147  else {
2148  BPoint *bp = nu->bp;
2149  for (int i = nu->pntsu * nu->pntsv; i && (totpoint -= KEYELEM_ELEM_LEN_BPOINT) >= 0;
2150  i--, bp++, fp += KEYELEM_FLOAT_LEN_BPOINT) {
2151  copy_v3_v3(bp->vec, fp);
2152  bp->tilt = fp[3];
2153  bp->radius = fp[4];
2154  }
2155  }
2156  }
2157 }
2158 
2160 {
2161  const float *fp = kb->data;
2162  const int tot = min_ii(kb->totelem, BKE_keyblock_curve_element_count(nurb));
2163 
2164  keyblock_data_convert_to_curve(fp, nurb, tot);
2165 }
2166 
2167 /************************* Mesh ************************/
2168 
2170 {
2171  MVert *mvert;
2172  float(*fp)[3];
2173  int a, tot;
2174 
2175  BLI_assert(me->totvert == kb->totelem);
2176 
2177  tot = me->totvert;
2178  if (tot == 0) {
2179  return;
2180  }
2181 
2182  mvert = me->mvert;
2183  fp = kb->data;
2184  for (a = 0; a < tot; a++, fp++, mvert++) {
2185  copy_v3_v3(*fp, mvert->co);
2186  }
2187 }
2188 
2189 void BKE_keyblock_convert_from_mesh(const Mesh *me, const Key *key, KeyBlock *kb)
2190 {
2191  const int len = me->totvert;
2192 
2193  if (me->totvert == 0) {
2194  return;
2195  }
2196 
2197  MEM_SAFE_FREE(kb->data);
2198 
2199  kb->data = MEM_malloc_arrayN((size_t)len, (size_t)key->elemsize, __func__);
2200  kb->totelem = len;
2201 
2203 }
2204 
2205 static void keyblock_data_convert_to_mesh(const float (*fp)[3], MVert *mvert, const int totvert)
2206 {
2207  for (int i = 0; i < totvert; i++, fp++, mvert++) {
2208  copy_v3_v3(mvert->co, *fp);
2209  }
2210 }
2211 
2212 void BKE_keyblock_convert_to_mesh(const KeyBlock *kb, MVert *mvert, const int totvert)
2213 {
2214  const float(*fp)[3] = kb->data;
2215  const int tot = min_ii(kb->totelem, totvert);
2216 
2217  keyblock_data_convert_to_mesh(fp, mvert, tot);
2218 }
2219 
2221  const Mesh *mesh,
2222  float (*r_vertnors)[3],
2223  float (*r_polynors)[3],
2224  float (*r_loopnors)[3])
2225 {
2226  if (r_vertnors == NULL && r_polynors == NULL && r_loopnors == NULL) {
2227  return;
2228  }
2229 
2230  MVert *mvert = MEM_dupallocN(mesh->mvert);
2232 
2233  const bool loop_normals_needed = r_loopnors != NULL;
2234  const bool vert_normals_needed = r_vertnors != NULL || loop_normals_needed;
2235  const bool poly_normals_needed = r_polynors != NULL || vert_normals_needed ||
2236  loop_normals_needed;
2237 
2238  float(*vert_normals)[3] = r_vertnors;
2239  float(*poly_normals)[3] = r_polynors;
2240  bool free_vert_normals = false;
2241  bool free_poly_normals = false;
2242  if (vert_normals_needed && r_vertnors == NULL) {
2243  vert_normals = MEM_malloc_arrayN(mesh->totvert, sizeof(float[3]), __func__);
2244  free_vert_normals = true;
2245  }
2246  if (poly_normals_needed && r_polynors == NULL) {
2247  poly_normals = MEM_malloc_arrayN(mesh->totpoly, sizeof(float[3]), __func__);
2248  free_poly_normals = true;
2249  }
2250 
2251  if (poly_normals_needed) {
2253  mesh->totvert,
2254  mesh->mloop,
2255  mesh->totloop,
2256  mesh->mpoly,
2257  mesh->totpoly,
2258  poly_normals);
2259  }
2260  if (vert_normals_needed) {
2262  mesh->totvert,
2263  mesh->mloop,
2264  mesh->totloop,
2265  mesh->mpoly,
2266  mesh->totpoly,
2267  poly_normals,
2268  vert_normals);
2269  }
2270  if (loop_normals_needed) {
2271  short(*clnors)[2] = CustomData_get_layer(&mesh->ldata, CD_CUSTOMLOOPNORMAL); /* May be NULL. */
2273  vert_normals,
2274  mesh->totvert,
2275  mesh->medge,
2276  mesh->totedge,
2277  mesh->mloop,
2278  r_loopnors,
2279  mesh->totloop,
2280  mesh->mpoly,
2281  poly_normals,
2282  mesh->totpoly,
2283  (mesh->flag & ME_AUTOSMOOTH) != 0,
2284  mesh->smoothresh,
2285  NULL,
2286  clnors,
2287  NULL);
2288  }
2289 
2290  if (free_vert_normals) {
2291  MEM_freeN(vert_normals);
2292  }
2293  if (free_poly_normals) {
2294  MEM_freeN(poly_normals);
2295  }
2296  MEM_freeN(mvert);
2297 }
2298 
2299 /************************* raw coords ************************/
2300 
2301 void BKE_keyblock_update_from_vertcos(const Object *ob, KeyBlock *kb, const float (*vertCos)[3])
2302 {
2303  const float(*co)[3] = vertCos;
2304  float *fp = kb->data;
2305  int tot, a;
2306 
2307 #ifndef NDEBUG
2308  if (ob->type == OB_LATTICE) {
2309  Lattice *lt = ob->data;
2310  BLI_assert((lt->pntsu * lt->pntsv * lt->pntsw) == kb->totelem);
2311  }
2312  else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) {
2313  Curve *cu = ob->data;
2315  }
2316  else if (ob->type == OB_MESH) {
2317  Mesh *me = ob->data;
2318  BLI_assert(me->totvert == kb->totelem);
2319  }
2320  else {
2321  BLI_assert(0 == kb->totelem);
2322  }
2323 #endif
2324 
2325  tot = kb->totelem;
2326  if (tot == 0) {
2327  return;
2328  }
2329 
2330  /* Copy coords to key-block. */
2331  if (ELEM(ob->type, OB_MESH, OB_LATTICE)) {
2332  for (a = 0; a < tot; a++, fp += 3, co++) {
2333  copy_v3_v3(fp, *co);
2334  }
2335  }
2336  else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) {
2337  const Curve *cu = (const Curve *)ob->data;
2338  const Nurb *nu;
2339  const BezTriple *bezt;
2340  const BPoint *bp;
2341 
2342  for (nu = cu->nurb.first; nu; nu = nu->next) {
2343  if (nu->bezt) {
2344  for (a = nu->pntsu, bezt = nu->bezt; a; a--, bezt++) {
2345  for (int i = 0; i < 3; i++, co++) {
2346  copy_v3_v3(&fp[i * 3], *co);
2347  }
2349  }
2350  }
2351  else {
2352  for (a = nu->pntsu * nu->pntsv, bp = nu->bp; a; a--, bp++, co++) {
2353  copy_v3_v3(fp, *co);
2355  }
2356  }
2357  }
2358  }
2359 }
2360 
2361 void BKE_keyblock_convert_from_vertcos(const Object *ob, KeyBlock *kb, const float (*vertCos)[3])
2362 {
2363  int tot = 0, elemsize;
2364 
2365  MEM_SAFE_FREE(kb->data);
2366 
2367  /* Count of vertex coords in array */
2368  if (ob->type == OB_MESH) {
2369  const Mesh *me = (const Mesh *)ob->data;
2370  tot = me->totvert;
2371  elemsize = me->key->elemsize;
2372  }
2373  else if (ob->type == OB_LATTICE) {
2374  const Lattice *lt = (const Lattice *)ob->data;
2375  tot = lt->pntsu * lt->pntsv * lt->pntsw;
2376  elemsize = lt->key->elemsize;
2377  }
2378  else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) {
2379  const Curve *cu = (const Curve *)ob->data;
2380  elemsize = cu->key->elemsize;
2382  }
2383 
2384  if (tot == 0) {
2385  return;
2386  }
2387 
2388  kb->data = MEM_mallocN(tot * elemsize, __func__);
2389 
2390  /* Copy coords to key-block. */
2391  BKE_keyblock_update_from_vertcos(ob, kb, vertCos);
2392 }
2393 
2395 {
2396  float(*vertCos)[3], (*co)[3];
2397  const float *fp = kb->data;
2398  int tot = 0, a;
2399 
2400  /* Count of vertex coords in array */
2401  if (ob->type == OB_MESH) {
2402  const Mesh *me = (const Mesh *)ob->data;
2403  tot = me->totvert;
2404  }
2405  else if (ob->type == OB_LATTICE) {
2406  const Lattice *lt = (const Lattice *)ob->data;
2407  tot = lt->pntsu * lt->pntsv * lt->pntsw;
2408  }
2409  else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) {
2410  const Curve *cu = (const Curve *)ob->data;
2411  tot = BKE_nurbList_verts_count(&cu->nurb);
2412  }
2413 
2414  if (tot == 0) {
2415  return NULL;
2416  }
2417 
2418  co = vertCos = MEM_mallocN(tot * sizeof(*vertCos), __func__);
2419 
2420  /* Copy coords to array */
2421  if (ELEM(ob->type, OB_MESH, OB_LATTICE)) {
2422  for (a = 0; a < tot; a++, fp += 3, co++) {
2423  copy_v3_v3(*co, fp);
2424  }
2425  }
2426  else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) {
2427  const Curve *cu = (const Curve *)ob->data;
2428  const Nurb *nu;
2429  const BezTriple *bezt;
2430  const BPoint *bp;
2431 
2432  for (nu = cu->nurb.first; nu; nu = nu->next) {
2433  if (nu->bezt) {
2434  for (a = nu->pntsu, bezt = nu->bezt; a; a--, bezt++) {
2435  for (int i = 0; i < 3; i++, co++) {
2436  copy_v3_v3(*co, &fp[i * 3]);
2437  }
2439  }
2440  }
2441  else {
2442  for (a = nu->pntsu * nu->pntsv, bp = nu->bp; a; a--, bp++, co++) {
2443  copy_v3_v3(*co, fp);
2445  }
2446  }
2447  }
2448  }
2449 
2450  return vertCos;
2451 }
2452 
2453 /************************* raw coord offsets ************************/
2454 
2455 void BKE_keyblock_update_from_offset(const Object *ob, KeyBlock *kb, const float (*ofs)[3])
2456 {
2457  int a;
2458  float *fp = kb->data;
2459 
2460  if (ELEM(ob->type, OB_MESH, OB_LATTICE)) {
2461  for (a = 0; a < kb->totelem; a++, fp += 3, ofs++) {
2462  add_v3_v3(fp, *ofs);
2463  }
2464  }
2465  else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) {
2466  const Curve *cu = (const Curve *)ob->data;
2467  const Nurb *nu;
2468  const BezTriple *bezt;
2469  const BPoint *bp;
2470 
2471  for (nu = cu->nurb.first; nu; nu = nu->next) {
2472  if (nu->bezt) {
2473  for (a = nu->pntsu, bezt = nu->bezt; a; a--, bezt++) {
2474  for (int i = 0; i < 3; i++, ofs++) {
2475  add_v3_v3(&fp[i * 3], *ofs);
2476  }
2478  }
2479  }
2480  else {
2481  for (a = nu->pntsu * nu->pntsv, bp = nu->bp; a; a--, bp++, ofs++) {
2482  add_v3_v3(fp, *ofs);
2484  }
2485  }
2486  }
2487  }
2488 }
2489 
2490 /* ==========================================================*/
2491 
2492 bool BKE_keyblock_move(Object *ob, int org_index, int new_index)
2493 {
2494  Key *key = BKE_key_from_object(ob);
2495  KeyBlock *kb;
2496  const int act_index = ob->shapenr - 1;
2497  const int totkey = key->totkey;
2498  int i;
2499  bool rev, in_range = false;
2500 
2501  if (org_index < 0) {
2502  org_index = act_index;
2503  }
2504 
2505  CLAMP(new_index, 0, key->totkey - 1);
2506  CLAMP(org_index, 0, key->totkey - 1);
2507 
2508  if (new_index == org_index) {
2509  return false;
2510  }
2511 
2512  rev = ((new_index - org_index) < 0) ? true : false;
2513 
2514  /* We swap 'org' element with its previous/next neighbor (depending on direction of the move)
2515  * repeatedly, until we reach final position.
2516  * This allows us to only loop on the list once! */
2517  for (kb = (rev ? key->block.last : key->block.first), i = (rev ? totkey - 1 : 0); kb;
2518  kb = (rev ? kb->prev : kb->next), rev ? i-- : i++) {
2519  if (i == org_index) {
2520  in_range = true; /* Start list items swapping... */
2521  }
2522  else if (i == new_index) {
2523  in_range = false; /* End list items swapping. */
2524  }
2525 
2526  if (in_range) {
2527  KeyBlock *other_kb = rev ? kb->prev : kb->next;
2528 
2529  /* Swap with previous/next list item. */
2530  BLI_listbase_swaplinks(&key->block, kb, other_kb);
2531 
2532  /* Swap absolute positions. */
2533  SWAP(float, kb->pos, other_kb->pos);
2534 
2535  kb = other_kb;
2536  }
2537 
2538  /* Adjust relative indices, this has to be done on the whole list! */
2539  if (kb->relative == org_index) {
2540  kb->relative = new_index;
2541  }
2542  else if (kb->relative < org_index && kb->relative >= new_index) {
2543  /* remove after, insert before this index */
2544  kb->relative++;
2545  }
2546  else if (kb->relative > org_index && kb->relative <= new_index) {
2547  /* remove before, insert after this index */
2548  kb->relative--;
2549  }
2550  }
2551 
2552  /* Need to update active shape number if it's affected,
2553  * same principle as for relative indices above. */
2554  if (org_index == act_index) {
2555  ob->shapenr = new_index + 1;
2556  }
2557  else if (act_index < org_index && act_index >= new_index) {
2558  ob->shapenr++;
2559  }
2560  else if (act_index > org_index && act_index <= new_index) {
2561  ob->shapenr--;
2562  }
2563 
2564  /* First key is always refkey, matches interface and BKE_key_sort */
2565  key->refkey = key->block.first;
2566 
2567  return true;
2568 }
2569 
2570 bool BKE_keyblock_is_basis(const Key *key, const int index)
2571 {
2572  const KeyBlock *kb;
2573  int i;
2574 
2575  if (key->type == KEY_RELATIVE) {
2576  for (i = 0, kb = key->block.first; kb; i++, kb = kb->next) {
2577  if ((i != index) && (kb->relative == index)) {
2578  return true;
2579  }
2580  }
2581  }
2582 
2583  return false;
2584 }
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
int BKE_nurbList_verts_count(const struct ListBase *nurb)
CustomData interface, see also DNA_customdata_types.h.
void * CustomData_get_layer(const struct CustomData *data, int type)
int CustomData_get_offset(const struct CustomData *data, int type)
support for deformation groups and hooks.
int BKE_object_defgroup_name_index(const struct Object *ob, const char *name)
float BKE_defvert_find_weight(const struct MDeformVert *dvert, int defgroup)
Definition: deform.c:704
int BKE_object_defgroup_count(const struct Object *ob)
@ IDTYPE_FLAGS_NO_LIBLINKING
Definition: BKE_idtype.h:32
void outside_lattice(struct Lattice *lt)
Definition: lattice.c:421
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
@ IDWALK_CB_LOOPBACK
Definition: BKE_lib_query.h:54
#define BKE_LIB_FOREACHID_PROCESS_ID(_data, _id, _cb_flag)
void BKE_mesh_calc_normals_poly_and_vertex(const struct MVert *mvert, int mvert_len, const struct MLoop *mloop, int mloop_len, const struct MPoly *mpoly, int mpoly_len, float(*r_poly_normals)[3], float(*r_vert_normals)[3])
void BKE_mesh_calc_normals_poly(const struct MVert *mvert, int mvert_len, const struct MLoop *mloop, int mloop_len, const struct MPoly *mpoly, int mpoly_len, float(*r_poly_normals)[3])
void BKE_mesh_normals_loop_split(const struct MVert *mverts, const float(*vert_normals)[3], int numVerts, struct MEdge *medges, int numEdges, struct MLoop *mloops, float(*r_loopnors)[3], int numLoops, struct MPoly *mpolys, const float(*polynors)[3], int numPolys, bool use_split_normals, float split_angle, MLoopNorSpaceArray *r_lnors_spacearr, short(*clnors_data)[2], int *r_loop_to_poly)
#define BLI_assert_unreachable()
Definition: BLI_assert.h:93
#define BLI_assert(a)
Definition: BLI_assert.h:46
#define BLI_assert_msg(a, msg)
Definition: BLI_assert.h:53
void BLI_endian_switch_float_array(float *val, int size) ATTR_NONNULL(1)
Definition: endian_switch.c:51
BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb)
Definition: BLI_listbase.h:269
void * BLI_pophead(ListBase *listbase) ATTR_NONNULL(1)
Definition: listbase.c:221
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:336
void void void void void BLI_duplicatelist(struct ListBase *dst, const struct ListBase *src) ATTR_NONNULL(1
void BLI_insertlinkafter(struct ListBase *listbase, void *vprevlink, void *vnewlink) ATTR_NONNULL(1)
Definition: listbase.c:301
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:80
void BLI_remlink(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:100
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void * BLI_findstring(const struct ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
int BLI_listbase_count(const struct ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void BLI_listbase_swaplinks(struct ListBase *listbase, void *vlinka, void *vlinkb) ATTR_NONNULL(1
MINLINE int min_ii(int a, int b)
MINLINE int max_ii(int a, int b)
MINLINE int compare_ff(float a, float b, float max_diff)
void mul_v3_m4v3(float r[3], const float M[4][4], const float v[3])
Definition: math_matrix.c:739
MINLINE void copy_v3_v3(float r[3], const float a[3])
void interp_v4_v4v4(float r[4], const float a[4], const float b[4], float t)
Definition: math_vector.c:38
MINLINE void add_v3_v3(float r[3], const float a[3])
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
Definition: string.c:64
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
bool BLI_uniquename(struct ListBase *list, void *vlink, const char *defname, char delim, int name_offset, size_t name_len)
Definition: string_utils.c:309
#define SWAP(type, a, b)
#define UNUSED(x)
#define ELEM(...)
#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_expand(expander, id)
bool BLO_read_requires_endian_switch(BlendDataReader *reader)
Definition: readfile.c:5143
void BLO_write_raw(BlendWriter *writer, size_t size_in_bytes, const void *data_ptr)
Definition: writefile.c:1489
bool BLO_write_is_undo(BlendWriter *writer)
Definition: writefile.c:1608
#define BLO_write_struct_at_address(writer, struct_name, address, data_ptr)
#define BLT_I18NCONTEXT_ID_SHAPEKEY
#define DATA_(msgid)
ID and Library types, which are fundamental for sdna.
@ INDEX_ID_KE
Definition: DNA_ID.h:1022
@ LIB_TAG_EXTERN
Definition: DNA_ID.h:674
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition: DNA_ID.h:588
#define FILTER_ID_KE
Definition: DNA_ID.h:934
@ ID_KE
Definition: DNA_ID_enums.h:58
@ ID_CU_LEGACY
Definition: DNA_ID_enums.h:49
@ ID_ME
Definition: DNA_ID_enums.h:48
@ ID_LT
Definition: DNA_ID_enums.h:54
@ CD_CUSTOMLOOPNORMAL
@ CD_MDEFORMVERT
@ KEYBLOCK_MUTE
@ KEY_LINEAR
@ KEY_CARDINAL
@ KEY_BSPLINE
@ KEY_CATMULL_ROM
#define KEYELEM_FLOAT_LEN_COORD
#define KEYELEM_ELEM_LEN_BPOINT
#define KEYELEM_FLOAT_LEN_BEZTRIPLE
#define KEYELEM_ELEM_SIZE_CURVE
struct Key Key
#define KEYELEM_FLOAT_LEN_BPOINT
@ KEY_RELATIVE
@ KEY_NORMAL
#define KEYELEM_ELEM_LEN_BEZTRIPLE
#define LT_OUTSIDE
@ ME_AUTOSMOOTH
Object is a sort of wrapper for general info.
@ OB_SHAPE_LOCK
@ OB_LATTICE
@ OB_SURF
@ OB_MESH
@ OB_CURVES_LEGACY
#define OB_TYPE_SUPPORT_VGROUP(_type)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
Read Guarded memory(de)allocation.
#define MEM_SAFE_FREE(v)
static void init_data(ModifierData *md)
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position CLAMP
#define BM_ELEM_CD_GET_VOID_P(ele, offset)
Definition: bmesh_class.h:541
#define BM_ITER_MESH(ele, iter, bm, itype)
#define BM_ITER_MESH_INDEX(ele, iter, bm, itype, indexvar)
@ BM_VERTS_OF_MESH
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
StackEntry * from
Curve curve
Lattice lattice
SyclQueue void void * src
int len
Definition: draw_manager.c:108
uint pos
#define GS(x)
Definition: iris.c:225
static void shapekey_blend_read_data(BlendDataReader *reader, ID *id)
Definition: key.c:159
void BKE_keyblock_data_set_with_mat4(Key *key, const int shape_index, const float(*coords)[3], const float mat[4][4])
Definition: key.c:1689
void key_curve_normal_weights(float t, float data[4], int type)
Definition: key.c:415
KeyBlock * BKE_keyblock_from_object(Object *ob)
Definition: key.c:1890
#define IPO_FLOAT
Definition: key.c:128
static void key_evaluate_relative(const int start, int end, const int tot, char *basispoin, Key *key, KeyBlock *actkb, float **per_keyblock_weights, const int mode)
Definition: key.c:860
void BKE_keyblock_convert_to_curve(KeyBlock *kb, Curve *UNUSED(cu), ListBase *nurb)
Definition: key.c:2159
void BKE_keyblock_curve_data_transform(const ListBase *nurb, const float mat[4][4], const void *src_data, void *dst_data)
Definition: key.c:2084
Key * BKE_key_from_object(Object *ob)
Definition: key.c:1803
static void flerp(int tot, float *in, const float *f0, const float *f1, const float *f2, const float *f3, const float *t)
Definition: key.c:589
void BKE_keyblock_convert_to_lattice(const KeyBlock *kb, Lattice *lt)
Definition: key.c:2015
static float ** keyblock_get_per_block_weights(Object *ob, Key *key, WeightsArrayCache *cache)
Definition: key.c:1335
KeyBlock * BKE_keyblock_find_name(Key *key, const char name[])
Definition: key.c:1930
float * BKE_key_evaluate_object_ex(Object *ob, int *r_totelem, float *arr, size_t arr_size, ID *obdata)
Definition: key.c:1511
void BKE_keyblock_curve_data_set_with_mat4(Key *key, const ListBase *nurb, const int shape_index, const void *data, const float mat[4][4])
Definition: key.c:1716
size_t BKE_keyblock_element_calc_size_from_shape(const Key *key, const int shape_index)
Definition: key.c:1654
void BKE_key_free_nolib(Key *key)
Definition: key.c:240
void BKE_keyblock_convert_from_mesh(const Mesh *me, const Key *key, KeyBlock *kb)
Definition: key.c:2189
static float * get_weights_array(Object *ob, char *vgroup, WeightsArrayCache *cache)
Definition: key.c:1259
KeyBlock * BKE_keyblock_from_object_reference(Object *ob)
Definition: key.c:1902
KeyBlock * BKE_keyblock_add(Key *key, const char *name)
Definition: key.c:1814
int BKE_keyblock_element_count_from_shape(const Key *key, const int shape_index)
Definition: key.c:1637
void BKE_keyblock_convert_to_mesh(const KeyBlock *kb, MVert *mvert, const int totvert)
Definition: key.c:2212
#define IPO_BEZTRIPLE
Definition: key.c:129
KeyBlock * BKE_keyblock_from_key(Key *key, int index)
Definition: key.c:1913
bool BKE_key_idtype_support(const short id_type)
Definition: key.c:1746
static void keyblock_free_per_block_weights(Key *key, float **per_keyblock_weights, WeightsArrayCache *cache)
Definition: key.c:1352
#define KEY_MODE_BPOINT
Definition: key.c:226
char * BKE_keyblock_curval_rnapath_get(const Key *key, const KeyBlock *kb)
Definition: key.c:1946
bool BKE_keyblock_move(Object *ob, int org_index, int new_index)
Definition: key.c:2492
static void shapekey_foreach_id(ID *id, LibraryForeachIDData *data)
Definition: key.c:88
Key * BKE_key_add(Main *bmain, ID *id)
Definition: key.c:252
void BKE_keyblock_update_from_curve(const Curve *UNUSED(cu), KeyBlock *kb, const ListBase *nurb)
Definition: key.c:2045
void BKE_keyblock_data_set(Key *key, const int shape_index, const void *data)
Definition: key.c:1731
static void do_rel_cu_key(Curve *cu, Key *key, KeyBlock *actkb, char *out, const int tot)
Definition: key.c:1429
void BKE_key_free_data(Key *key)
Definition: key.c:235
void BKE_keyblock_update_from_offset(const Object *ob, KeyBlock *kb, const float(*ofs)[3])
Definition: key.c:2455
static void do_key(const int start, int end, const int tot, char *poin, Key *key, KeyBlock *actkb, KeyBlock **k, float *t, const int mode)
Definition: key.c:992
struct WeightsArrayCache WeightsArrayCache
int BKE_keyblock_curve_element_count(const ListBase *nurb)
Definition: key.c:2026
static void shapekey_blend_read_expand(BlendExpander *expander, ID *id)
Definition: key.c:187
float * BKE_key_evaluate_object(Object *ob, int *r_totelem)
Definition: key.c:1632
void BKE_keyblock_data_get(const Key *key, float(*arr)[3])
Definition: key.c:1684
static void switch_endian_keyblock(Key *key, KeyBlock *kb)
Definition: key.c:132
size_t BKE_keyblock_element_calc_size(const Key *key)
Definition: key.c:1659
static ID * shapekey_owner_get(Main *UNUSED(bmain), ID *id, ID *UNUSED(owner_id_hint))
Definition: key.c:94
static void do_curve_key(Object *ob, Key *key, char *out, const int tot)
Definition: key.c:1449
void BKE_keyblock_copy_settings(KeyBlock *kb_dst, const KeyBlock *kb_src)
Definition: key.c:1935
void BKE_keyblock_convert_from_curve(const Curve *cu, KeyBlock *kb, const ListBase *nurb)
Definition: key.c:2115
#define KEY_MODE_BEZTRIPLE
Definition: key.c:227
void key_curve_tangent_weights(float t, float data[4], int type)
Definition: key.c:377
void BKE_keyblock_convert_from_lattice(const Lattice *lt, KeyBlock *kb)
Definition: key.c:1989
static void keyblock_data_convert_to_curve(const float *fp, ListBase *nurb, const int totpoint)
Definition: key.c:2133
static void do_mesh_key(Object *ob, Key *key, char *out, const int tot)
Definition: key.c:1380
static void keyblock_data_convert_to_lattice(const float(*fp)[3], BPoint *bpoint, const int totpoint)
Definition: key.c:2006
static void do_latt_key(Object *ob, Key *key, char *out, const int tot)
Definition: key.c:1473
KeyBlock * BKE_keyblock_add_ctime(Key *key, const char *name, const bool do_force)
Definition: key.c:1862
static char * key_block_get_data(Key *key, KeyBlock *actkb, KeyBlock *kb, char **freedata)
Definition: key.c:613
static void cp_key(const int start, int end, const int tot, char *poin, Key *key, KeyBlock *actkb, KeyBlock *kb, float *weights, const int mode)
Definition: key.c:683
static void shapekey_blend_write(BlendWriter *writer, ID *id, const void *id_address)
Definition: key.c:99
void BKE_keyblock_update_from_lattice(const Lattice *lt, KeyBlock *kb)
Definition: key.c:1969
int BKE_keyblock_element_count(const Key *key)
Definition: key.c:1649
#define KEY_MODE_DUMMY
Definition: key.c:225
static void rel_flerp(int tot, float *in, const float *ref, const float *out, float fac)
Definition: key.c:604
static void shapekey_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, const int UNUSED(flag))
Definition: key.c:54
IDTypeInfo IDType_ID_KE
Definition: key.c:193
void BKE_keyblock_convert_from_vertcos(const Object *ob, KeyBlock *kb, const float(*vertCos)[3])
Definition: key.c:2361
static void do_cu_key(Curve *cu, Key *key, KeyBlock *actkb, KeyBlock **k, float *t, char *out, const int tot)
Definition: key.c:1408
Key ** BKE_key_from_id_p(ID *id)
Definition: key.c:1758
void BKE_keyblock_mesh_calc_normals(const KeyBlock *kb, const Mesh *mesh, float(*r_vertnors)[3], float(*r_polynors)[3], float(*r_loopnors)[3])
Definition: key.c:2220
void BKE_keyblock_update_from_mesh(const Mesh *me, KeyBlock *kb)
Definition: key.c:2169
static void keyblock_data_convert_to_mesh(const float(*fp)[3], MVert *mvert, const int totvert)
Definition: key.c:2205
static bool key_pointer_size(const Key *key, const int mode, int *poinsize, int *ofs, int *step)
Definition: key.c:647
static int setkeys(float fac, ListBase *lb, KeyBlock *k[], float t[4], int cycl)
Definition: key.c:449
void BKE_key_sort(Key *key)
Definition: key.c:304
bool BKE_keyblock_is_basis(const Key *key, const int index)
Definition: key.c:2570
void BKE_keyblock_update_from_vertcos(const Object *ob, KeyBlock *kb, const float(*vertCos)[3])
Definition: key.c:2301
static void cp_cu_key(Curve *cu, Key *key, KeyBlock *actkb, KeyBlock *kb, const int start, int end, char *out, const int tot)
Definition: key.c:820
float(* BKE_keyblock_convert_to_vertcos(const Object *ob, const KeyBlock *kb))[3]
Definition: key.c:2394
static void shapekey_free_data(ID *id)
Definition: key.c:75
void key_curve_position_weights(float t, float data[4], int type)
Definition: key.c:336
Key ** BKE_key_from_object_p(Object *ob)
Definition: key.c:1794
Key * BKE_key_from_id(ID *id)
Definition: key.c:1783
void BKE_keyblock_data_get_from_shape(const Key *key, float(*arr)[3], const int shape_index)
Definition: key.c:1671
static void shapekey_blend_read_lib(BlendLibReader *reader, ID *id)
Definition: key.c:178
#define IPO_BPOINT
Definition: key.c:130
void *(* MEM_malloc_arrayN)(size_t len, size_t size, const char *str)
Definition: mallocn.c:34
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 unsigned a[3]
Definition: RandGen.cpp:78
T floor(const T &a)
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
void RNA_pointer_create(ID *id, StructRNA *type, void *data, PointerRNA *r_ptr)
Definition: rna_access.c:136
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:717
char * RNA_path_from_ID_to_property(const PointerRNA *ptr, PropertyRNA *prop)
Definition: rna_path.cc:1127
unsigned char uint8_t
Definition: stdint.h:78
struct BMesh * bm
Definition: BKE_editmesh.h:40
float co[3]
Definition: bmesh_class.h:87
int totvert
Definition: bmesh_class.h:297
CustomData vdata
Definition: bmesh_class.h:337
float vec[4]
float radius
float tilt
float vec[3][3]
struct VFont * vfont
struct Key * key
ListBase nurb
short id_code
Definition: BKE_idtype.h:114
Definition: DNA_ID.h:368
int tag
Definition: DNA_ID.h:387
struct Library * lib
Definition: DNA_ID.h:372
char name[66]
Definition: DNA_ID.h:378
struct KeyBlock * prev
Definition: DNA_key_types.h:25
short flag
Definition: DNA_key_types.h:42
char name[64]
Definition: DNA_key_types.h:52
float pos
Definition: DNA_key_types.h:32
float slidermax
Definition: DNA_key_types.h:58
float slidermin
Definition: DNA_key_types.h:57
float curval
Definition: DNA_key_types.h:34
struct KeyBlock * next
Definition: DNA_key_types.h:25
char vgroup[64]
Definition: DNA_key_types.h:54
short relative
Definition: DNA_key_types.h:41
short type
Definition: DNA_key_types.h:37
void * data
Definition: DNA_key_types.h:50
ID * from
Definition: DNA_key_types.h:88
int totkey
Definition: DNA_key_types.h:91
float ctime
Definition: DNA_key_types.h:99
char elemstr[32]
Definition: DNA_key_types.h:78
ID id
Definition: DNA_key_types.h:63
int uidgen
int elemsize
Definition: DNA_key_types.h:80
struct AnimData * adt
Definition: DNA_key_types.h:65
char type
Definition: DNA_key_types.h:94
ListBase block
Definition: DNA_key_types.h:84
KeyBlock * refkey
Definition: DNA_key_types.h:72
struct Key * key
struct MDeformVert * dvert
struct BPoint * def
void * last
Definition: DNA_listBase.h:31
void * first
Definition: DNA_listBase.h:31
float co[3]
Definition: BKE_main.h:121
struct MEdge * medge
struct BMEditMesh * edit_mesh
float smoothresh
struct MVert * mvert
uint16_t flag
struct MDeformVert * dvert
int totedge
int totvert
struct MLoop * mloop
int totpoly
int totloop
struct Key * key
struct MPoly * mpoly
CustomData ldata
struct Nurb * next
BezTriple * bezt
BPoint * bp
short shapenr
void * data
char shapeflag
int num_defgroup_weights
Definition: key.c:231
float ** defgroup_weights
Definition: key.c:232
PointerRNA * ptr
Definition: wm_files.c:3480