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