5 * ***** BEGIN GPL LICENSE BLOCK *****
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software Foundation,
19 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
22 * All rights reserved.
24 * The Original Code is: all of this file.
26 * Contributor(s): none yet.
28 * ***** END GPL LICENSE BLOCK *****
39 #include "MEM_guardedalloc.h"
41 #include "DNA_action_types.h"
42 #include "DNA_armature_types.h"
43 #include "DNA_curve_types.h"
44 #include "DNA_camera_types.h"
45 #include "DNA_lamp_types.h"
46 #include "DNA_ipo_types.h"
47 #include "DNA_key_types.h"
48 #include "DNA_material_types.h"
49 #include "DNA_mesh_types.h"
50 #include "DNA_object_types.h"
51 #include "DNA_object_force.h"
52 #include "DNA_particle_types.h"
53 #include "DNA_sequence_types.h"
54 #include "DNA_scene_types.h"
55 #include "DNA_sound_types.h"
56 #include "DNA_texture_types.h"
57 #include "DNA_view3d_types.h"
58 #include "DNA_world_types.h"
60 #include "BLI_blenlib.h"
61 #include "BLI_arithb.h"
63 #include "BKE_bad_level_calls.h"
64 #include "BKE_utildefines.h"
66 #include "BKE_action.h"
67 #include "BKE_blender.h"
68 #include "BKE_curve.h"
69 #include "BKE_constraint.h"
70 #include "BKE_global.h"
72 #include "BKE_library.h"
75 #include "BKE_object.h"
76 #include "BPY_extern.h" /* for BPY_pydriver_eval() */
78 #define SMALL -1.0e-10
80 /* This array concept was meant to make sure that defines such as OB_LOC_X
81 don't have to be enumerated, also for backward compatibility, future changes,
82 and to enable it all can be accessed with a for-next loop.
85 int co_ar[CO_TOTIPO]= {
86 CO_ENFORCE, CO_HEADTAIL
89 int ob_ar[OB_TOTIPO]= {
90 OB_LOC_X, OB_LOC_Y, OB_LOC_Z, OB_DLOC_X, OB_DLOC_Y, OB_DLOC_Z,
91 OB_ROT_X, OB_ROT_Y, OB_ROT_Z, OB_DROT_X, OB_DROT_Y, OB_DROT_Z,
92 OB_SIZE_X, OB_SIZE_Y, OB_SIZE_Z, OB_DSIZE_X, OB_DSIZE_Y, OB_DSIZE_Z,
93 OB_LAY, OB_TIME, OB_COL_R, OB_COL_G, OB_COL_B, OB_COL_A,
94 OB_PD_FSTR, OB_PD_FFALL, OB_PD_SDAMP, OB_PD_RDAMP, OB_PD_PERM, OB_PD_FMAXD
97 int ac_ar[AC_TOTIPO]= {
98 AC_LOC_X, AC_LOC_Y, AC_LOC_Z,
99 AC_QUAT_W, AC_QUAT_X, AC_QUAT_Y, AC_QUAT_Z,
100 AC_SIZE_X, AC_SIZE_Y, AC_SIZE_Z
103 int ma_ar[MA_TOTIPO]= {
104 MA_COL_R, MA_COL_G, MA_COL_B,
105 MA_SPEC_R, MA_SPEC_G, MA_SPEC_B,
106 MA_MIR_R, MA_MIR_G, MA_MIR_B,
107 MA_REF, MA_ALPHA, MA_EMIT, MA_AMB,
108 MA_SPEC, MA_HARD, MA_SPTR, MA_IOR,
109 MA_MODE, MA_HASIZE, MA_TRANSLU, MA_RAYM,
110 MA_FRESMIR, MA_FRESMIRI, MA_FRESTRA, MA_FRESTRAI, MA_ADD,
112 MA_MAP1+MAP_OFS_X, MA_MAP1+MAP_OFS_Y, MA_MAP1+MAP_OFS_Z,
113 MA_MAP1+MAP_SIZE_X, MA_MAP1+MAP_SIZE_Y, MA_MAP1+MAP_SIZE_Z,
114 MA_MAP1+MAP_R, MA_MAP1+MAP_G, MA_MAP1+MAP_B,
115 MA_MAP1+MAP_DVAR, MA_MAP1+MAP_COLF, MA_MAP1+MAP_NORF, MA_MAP1+MAP_VARF, MA_MAP1+MAP_DISP
118 int te_ar[TE_TOTIPO] ={
120 TE_NSIZE, TE_NDEPTH, TE_NTYPE, TE_TURB,
122 TE_VNW1, TE_VNW2, TE_VNW3, TE_VNW4,
123 TE_VNMEXP, TE_VN_COLT, TE_VN_DISTM,
127 TE_MG_TYP, TE_MGH, TE_MG_LAC, TE_MG_OCT, TE_MG_OFF, TE_MG_GAIN,
129 TE_N_BAS1, TE_N_BAS2,
131 TE_COL_R, TE_COL_G, TE_COL_B, TE_BRIGHT, TE_CONTRA
134 int seq_ar[SEQ_TOTIPO]= {
138 int cu_ar[CU_TOTIPO]= {
142 int wo_ar[WO_TOTIPO]= {
143 WO_HOR_R, WO_HOR_G, WO_HOR_B, WO_ZEN_R, WO_ZEN_G, WO_ZEN_B,
144 WO_EXPOS, WO_MISI, WO_MISTDI, WO_MISTSTA, WO_MISTHI,
145 WO_STAR_R, WO_STAR_G, WO_STAR_B, WO_STARDIST, WO_STARSIZE,
147 MA_MAP1+MAP_OFS_X, MA_MAP1+MAP_OFS_Y, MA_MAP1+MAP_OFS_Z,
148 MA_MAP1+MAP_SIZE_X, MA_MAP1+MAP_SIZE_Y, MA_MAP1+MAP_SIZE_Z,
149 MA_MAP1+MAP_R, MA_MAP1+MAP_G, MA_MAP1+MAP_B,
150 MA_MAP1+MAP_DVAR, MA_MAP1+MAP_COLF, MA_MAP1+MAP_NORF, MA_MAP1+MAP_VARF
153 int la_ar[LA_TOTIPO]= {
154 LA_ENERGY, LA_COL_R, LA_COL_G, LA_COL_B,
155 LA_DIST, LA_SPOTSI, LA_SPOTBL,
156 LA_QUAD1, LA_QUAD2, LA_HALOINT,
158 MA_MAP1+MAP_OFS_X, MA_MAP1+MAP_OFS_Y, MA_MAP1+MAP_OFS_Z,
159 MA_MAP1+MAP_SIZE_X, MA_MAP1+MAP_SIZE_Y, MA_MAP1+MAP_SIZE_Z,
160 MA_MAP1+MAP_R, MA_MAP1+MAP_G, MA_MAP1+MAP_B,
161 MA_MAP1+MAP_DVAR, MA_MAP1+MAP_COLF
164 /* yafray: aperture & focal distance curves added */
165 /* qdn: FDIST now available to Blender as well for defocus node */
166 int cam_ar[CAM_TOTIPO]= {
167 CAM_LENS, CAM_STA, CAM_END, CAM_YF_APERT, CAM_YF_FDIST, CAM_SHIFT_X, CAM_SHIFT_Y
170 int snd_ar[SND_TOTIPO]= {
171 SND_VOLUME, SND_PITCH, SND_PANNING, SND_ATTEN
174 int fluidsim_ar[FLUIDSIM_TOTIPO]= {
175 FLUIDSIM_VISC, FLUIDSIM_TIME,
176 FLUIDSIM_GRAV_X , FLUIDSIM_GRAV_Y , FLUIDSIM_GRAV_Z ,
177 FLUIDSIM_VEL_X , FLUIDSIM_VEL_Y , FLUIDSIM_VEL_Z ,
181 int part_ar[PART_TOTIPO]= {
182 PART_EMIT_FREQ, PART_EMIT_LIFE, PART_EMIT_VEL, PART_EMIT_AVE, PART_EMIT_SIZE,
183 PART_AVE, PART_SIZE, PART_DRAG, PART_BROWN, PART_DAMP, PART_LENGTH, PART_CLUMP,
184 PART_GRAV_X, PART_GRAV_Y, PART_GRAV_Z, PART_KINK_AMP, PART_KINK_FREQ, PART_KINK_SHAPE,
189 float frame_to_float(int cfra) /* see also bsystem_time in object.c */
191 extern float bluroffs; /* bad stuff borrowed from object.c */
192 extern float fieldoffs;
196 ctime+= bluroffs+fieldoffs;
197 ctime*= G.scene->r.framelen;
202 /* includes ipo curve itself */
203 void free_ipo_curve(IpoCurve *icu)
205 if(icu->bezt) MEM_freeN(icu->bezt);
206 if(icu->bp) MEM_freeN(icu->bp);
207 if(icu->driver) MEM_freeN(icu->driver);
211 /* do not free ipo itself */
212 void free_ipo(Ipo *ipo)
216 while( (icu= ipo->curve.first) ) {
217 BLI_remlink(&ipo->curve, icu);
222 /* on adding new ipos, or for empty views */
223 void ipo_default_v2d_cur(int blocktype, rctf *cur)
225 if(blocktype==ID_CA) {
226 cur->xmin= G.scene->r.sfra;
227 cur->xmax= G.scene->r.efra;
231 else if ELEM5(blocktype, ID_MA, ID_CU, ID_WO, ID_LA, ID_CO) {
232 cur->xmin= (float)G.scene->r.sfra-0.1;
233 cur->xmax= G.scene->r.efra;
234 cur->ymin= (float)-0.1;
235 cur->ymax= (float)+1.1;
237 else if(blocktype==ID_TE) {
238 cur->xmin= (float)G.scene->r.sfra-0.1;
239 cur->xmax= G.scene->r.efra;
240 cur->ymin= (float)-0.1;
241 cur->ymax= (float)+1.1;
243 else if(blocktype==ID_SEQ) {
246 cur->ymin= (float)-0.1;
247 cur->ymax= (float)+1.1;
249 else if(blocktype==ID_KE) {
250 cur->xmin= (float)G.scene->r.sfra-0.1;
251 cur->xmax= G.scene->r.efra;
252 cur->ymin= (float)-0.1;
253 cur->ymax= (float)+2.1;
255 else { /* ID_OB and everything else */
256 cur->xmin= G.scene->r.sfra;
257 cur->xmax= G.scene->r.efra;
264 Ipo *add_ipo(char *name, int idcode)
268 ipo= alloc_libblock(&G.main->ipo, ID_IP, name);
269 ipo->blocktype= idcode;
270 ipo_default_v2d_cur(idcode, &ipo->cur);
275 Ipo *copy_ipo(Ipo *ipo)
280 if(ipo==NULL) return 0;
282 ipon= copy_libblock(ipo);
284 duplicatelist(&(ipon->curve), &(ipo->curve));
286 for(icu= ipo->curve.first; icu; icu= icu->next) {
287 icu->bezt= MEM_dupallocN(icu->bezt);
288 if(icu->driver) icu->driver= MEM_dupallocN(icu->driver);
294 /* uses id->newid to match pointers with other copied data */
295 void ipo_idnew(Ipo *ipo)
300 for(icu= ipo->curve.first; icu; icu= icu->next) {
302 ID_NEW(icu->driver->ob);
308 void make_local_obipo(Ipo *ipo)
314 /* - only lib users: do nothing
315 * - only local users: set flag
319 ob= G.main->object.first;
322 if(ob->id.lib) lib= 1;
328 if(local && lib==0) {
330 ipo->id.flag= LIB_LOCAL;
331 new_id(0, (ID *)ipo, 0);
333 else if(local && lib) {
337 ob= G.main->object.first;
341 if(ob->id.lib==NULL) {
352 void make_local_matipo(Ipo *ipo)
358 /* - only lib users: do nothing
359 * - only local users: set flag
363 ma= G.main->mat.first;
366 if(ma->id.lib) lib= 1;
372 if(local && lib==0) {
374 ipo->id.flag= LIB_LOCAL;
375 new_id(0, (ID *)ipo, 0);
377 else if(local && lib) {
381 ma= G.main->mat.first;
385 if(ma->id.lib==NULL) {
396 void make_local_keyipo(Ipo *ipo)
402 /* - only lib users: do nothing
403 * - only local users: set flag
407 key= G.main->key.first;
410 if(key->id.lib) lib= 1;
416 if(local && lib==0) {
418 ipo->id.flag= LIB_LOCAL;
419 new_id(0, (ID *)ipo, 0);
421 else if(local && lib) {
425 key= G.main->key.first;
429 if(key->id.lib==NULL) {
441 void make_local_ipo(Ipo *ipo)
444 if(ipo->id.lib==NULL) return;
447 ipo->id.flag= LIB_LOCAL;
448 new_id(0, (ID *)ipo, 0);
452 if(ipo->blocktype==ID_OB) make_local_obipo(ipo);
453 else if(ipo->blocktype==ID_MA) make_local_matipo(ipo);
454 else if(ipo->blocktype==ID_KE) make_local_keyipo(ipo);
458 IpoCurve *find_ipocurve(Ipo *ipo, int adrcode)
462 for(icu= ipo->curve.first; icu; icu= icu->next) {
463 if(icu->adrcode==adrcode) return icu;
469 void calchandles_ipocurve(IpoCurve *icu)
471 BezTriple *bezt, *prev, *next;
476 /* IPO_CONST doesn't have handles */
477 if(a<2 || icu->ipo==IPO_CONST) return;
485 if(bezt->vec[0][0]>bezt->vec[1][0]) bezt->vec[0][0]= bezt->vec[1][0];
486 if(bezt->vec[2][0]<bezt->vec[1][0]) bezt->vec[2][0]= bezt->vec[1][0];
488 if(icu->flag & IPO_AUTO_HORIZ)
489 calchandleNurb(bezt, prev, next, 2); /* 2==special autohandle && keep extrema horizontal */
491 calchandleNurb(bezt, prev, next, 1); /* 1==special autohandle */
499 /* for automatic ease in and out */
500 if(bezt->h1==HD_AUTO && bezt->h2==HD_AUTO) {
501 if(a==0 || a==icu->totvert-1) {
502 if(icu->extrap==IPO_HORIZ) {
503 bezt->vec[0][1]= bezt->vec[2][1]= bezt->vec[1][1];
512 void testhandles_ipocurve(IpoCurve *icu)
514 /* use when something has changed with handles.
515 it treats all BezTriples with the following rules:
516 PHASE 1: do types have to be altered?
517 Auto handles: become aligned when selection status is NOT(000 || 111)
518 Vector handles: become 'nothing' when (one half selected AND other not)
519 PHASE 2: recalculate handles
525 if(bezt==NULL) return;
530 if(bezt->f1 & SELECT) flag++;
531 if(bezt->f2 & SELECT) flag += 2;
532 if(bezt->f3 & SELECT) flag += 4;
534 if( !(flag==0 || flag==7) ) {
535 if(bezt->h1==HD_AUTO) { /* auto */
538 if(bezt->h2==HD_AUTO) { /* auto */
542 if(bezt->h1==HD_VECT) { /* vector */
543 if(flag < 4) bezt->h1= 0;
545 if(bezt->h2==HD_VECT) { /* vector */
546 if( flag > 3) bezt->h2= 0;
552 calchandles_ipocurve(icu);
556 void sort_time_ipocurve(IpoCurve *icu)
569 if( bezt->vec[1][0] > (bezt+1)->vec[1][0]) {
570 SWAP(BezTriple, *bezt, *(bezt+1));
574 if(bezt->vec[0][0]>bezt->vec[1][0] && bezt->vec[2][0]<bezt->vec[1][0]) {
575 SWAP(float, bezt->vec[0][0], bezt->vec[2][0]);
576 SWAP(float, bezt->vec[0][1], bezt->vec[2][1]);
579 if(bezt->vec[0][0]>bezt->vec[1][0]) bezt->vec[0][0]= bezt->vec[1][0];
580 if(bezt->vec[2][0]<bezt->vec[1][0]) bezt->vec[2][0]= bezt->vec[1][0];
591 int test_time_ipocurve(IpoCurve *icu)
600 if( bezt->vec[1][0] > (bezt+1)->vec[1][0]) {
613 void correct_bezpart(float *v1, float *v2, float *v3, float *v4)
615 /* the total length of the handles is not allowed to be more
616 * than the horizontal distance between (v1-v4)
617 * this to prevent curve loops
619 float h1[2], h2[2], len1, len2, len, fac;
627 len1= (float)fabs(h1[0]);
628 len2= (float)fabs(h2[0]);
630 if(len1+len2==0.0) return;
631 if(len1+len2 > len) {
632 fac= len/(len1+len2);
634 v2[0]= (v1[0]-fac*h1[0]);
635 v2[1]= (v1[1]-fac*h1[1]);
637 v3[0]= (v4[0]-fac*h2[0]);
638 v3[1]= (v4[1]-fac*h2[1]);
643 /* *********************** ARITH *********************** */
645 int findzero(float x, float q0, float q1, float q2, float q3, float *o)
647 double c0, c1, c2, c3, a, b, c, p, q, d, t, phi;
662 q= (2*a*a*a-a*b+c)/2;
667 o[0]= (float)(Sqrt3d(-q+t)+Sqrt3d(-q-t)-a);
668 if(o[0]>= SMALL && o[0]<=1.000001) return 1;
673 o[0]= (float)(2*t-a);
674 if(o[0]>=SMALL && o[0]<=1.000001) nr++;
675 o[nr]= (float)(-t-a);
676 if(o[nr]>=SMALL && o[nr]<=1.000001) return nr+1;
680 phi= acos(-q/sqrt(-(p*p*p)));
684 o[0]= (float)(2*t*p-a);
685 if(o[0]>=SMALL && o[0]<=1.000001) nr++;
686 o[nr]= (float)(-t*(p+q)-a);
687 if(o[nr]>=SMALL && o[nr]<=1.000001) nr++;
688 o[nr]= (float)(-t*(p-q)-a);
689 if(o[nr]>=SMALL && o[nr]<=1.000001) return nr+1;
702 o[0]= (float)((-b-p)/(2*a));
703 if(o[0]>=SMALL && o[0]<=1.000001) nr++;
704 o[nr]= (float)((-b+p)/(2*a));
705 if(o[nr]>=SMALL && o[nr]<=1.000001) return nr+1;
709 o[0]= (float)(-b/(2*a));
710 if(o[0]>=SMALL && o[0]<=1.000001) return 1;
716 if(o[0]>=SMALL && o[0]<=1.000001) return 1;
727 void berekeny(float f1, float f2, float f3, float f4, float *o, int b)
729 float t, c0, c1, c2, c3;
734 c2= 3.0f*(f1 - 2.0f*f2 + f3);
735 c3= f4 - f1 + 3.0f*(f2-f3);
739 o[a]= c0+t*c1+t*t*c2+t*t*t*c3;
743 void berekenx(float *f, float *o, int b)
745 float t, c0, c1, c2, c3;
750 c2= 3*(f[0]-2*f[3]+f[6]);
751 c3= f[9]-f[0]+3*(f[3]-f[6]);
754 o[a]= c0+t*c1+t*t*c2+t*t*t*c3;
758 /* we need the local transform = current transform - (parent transform + bone transform) */
759 /* (local transform is on action channel level) */
760 static void posechannel_get_local_transform(bPoseChannel *pchan, float *loc, float *eul, float *size)
762 float diff_mat[4][4];
763 float parmat[4][4], offs_bone[4][4], imat[4][4];
766 /* get first the parent + bone transform in parmat */
768 /* bone transform itself */
769 Mat4CpyMat3(offs_bone, pchan->bone->bone_mat);
770 /* The bone's root offset (is in the parent's coordinate system) */
771 VECCOPY(offs_bone[3], pchan->bone->head);
772 /* Get the length translation of parent (length along y axis) */
773 offs_bone[3][1]+= pchan->parent->bone->length;
775 Mat4MulSerie(parmat, pchan->parent->pose_mat, offs_bone, NULL, NULL, NULL, NULL, NULL, NULL);
778 Mat4Invert(imat, parmat);
781 Mat4CpyMat3(offs_bone, pchan->bone->bone_mat);
782 VECCOPY(offs_bone[3], pchan->bone->head);
785 Mat4Invert(imat, offs_bone);
789 /* difference: current transform - (parent transform + bone transform) */
790 Mat4MulMat4(diff_mat, pchan->pose_mat, imat);
793 VECCOPY(loc, diff_mat[3]);
795 Mat4ToEul(diff_mat, eul);
797 Mat4ToSize(diff_mat, size);
801 /* has to return a float value */
802 static float eval_driver(IpoDriver *driver, float ipotime)
805 if(driver->type == IPO_DRIVER_TYPE_PYTHON) {
806 /* check for empty or invalid expression */
807 if ((driver->name[0] == '\0') ||
808 (driver->flag & IPO_DRIVER_FLAG_INVALID))
810 /* this evals the expression and returns its result:
811 * (on errors it reports, then returns 0.0f) */
812 return BPY_pydriver_eval(driver);
815 Object *ob= driver->ob;
817 if(ob==NULL) return 0.0f;
821 if(driver->blocktype==ID_OB) {
822 /* depsgraph failure; ob ipos are calculated in where_is_object, this might get called too late */
823 if(ob->ipo && ob->ctime!=ipotime) {
824 calc_ipo_spec(ob->ipo, driver->adrcode, &ipotime);
828 switch(driver->adrcode) {
836 return ob->rot[0]/(M_PI_2/9.0);
838 return ob->rot[1]/(M_PI_2/9.0);
840 return ob->rot[2]/(M_PI_2/9.0);
850 bPoseChannel *pchan= get_pose_channel(ob->pose, driver->name);
851 if(pchan && pchan->bone) {
853 /* rotation difference is not a simple driver (i.e. value drives value), but the angle between 2 bones is driving stuff... which is useful */
854 if(driver->adrcode==OB_ROT_DIFF) {
855 bPoseChannel *pchan2= get_pose_channel(ob->pose, driver->name+DRIVER_NAME_OFFS);
856 if(pchan2 && pchan2->bone) {
857 float q1[4], q2[4], quat[4], angle;
859 Mat4ToQuat(pchan->pose_mat, q1);
860 Mat4ToQuat(pchan2->pose_mat, q2);
863 QuatMul(quat, q1, q2);
864 angle = 2.0f * (saacos(quat[0]));
867 return angle>M_PI?2.0f*M_PI-angle:angle;
871 float loc[3], eul[3], size[3];
873 posechannel_get_local_transform(pchan, loc, eul, size);
875 switch(driver->adrcode) {
883 return eul[0]/(M_PI_2/9.0);
885 return eul[1]/(M_PI_2/9.0);
887 return eul[2]/(M_PI_2/9.0);
902 float eval_icu(IpoCurve *icu, float ipotime)
904 BezTriple *bezt, *prevbezt;
905 float v1[2], v2[2], v3[2], v4[2], opl[32], dx, fac;
906 float cycdx, cycdy, ofs, cycyofs, cvalue = 0.0;
912 /* ipotime now serves as input for the curve */
913 ipotime= cvalue= eval_driver(icu->driver, ipotime);
921 if(icu->extrap & IPO_CYCL) {
922 ofs= icu->bezt->vec[1][0];
923 cycdx= (icu->bezt+icu->totvert-1)->vec[1][0] - ofs;
924 cycdy= (icu->bezt+icu->totvert-1)->vec[1][1] - icu->bezt->vec[1][1];
927 if(icu->extrap & IPO_DIR) {
928 cycyofs= (float)floor((ipotime-ofs)/cycdx);
932 ipotime= (float)(fmod(ipotime-ofs, cycdx)+ofs);
933 if(ipotime<ofs) ipotime+= cycdx;
939 if(prevbezt->vec[1][0]>=ipotime) {
940 if( (icu->extrap & IPO_DIR) && icu->ipo!=IPO_CONST) {
941 dx= prevbezt->vec[1][0]-ipotime;
942 fac= prevbezt->vec[1][0]-prevbezt->vec[0][0];
944 fac= (prevbezt->vec[1][1]-prevbezt->vec[0][1])/fac;
945 cvalue= prevbezt->vec[1][1]-fac*dx;
947 else cvalue= prevbezt->vec[1][1];
949 else cvalue= prevbezt->vec[1][1];
953 else if( (prevbezt+a)->vec[1][0]<=ipotime) {
954 if( (icu->extrap & IPO_DIR) && icu->ipo!=IPO_CONST) {
956 dx= ipotime-prevbezt->vec[1][0];
957 fac= prevbezt->vec[2][0]-prevbezt->vec[1][0];
960 fac= (prevbezt->vec[2][1]-prevbezt->vec[1][1])/fac;
961 cvalue= prevbezt->vec[1][1]+fac*dx;
963 else cvalue= prevbezt->vec[1][1];
965 else cvalue= (prevbezt+a)->vec[1][1];
971 if(prevbezt->vec[1][0]<=ipotime && bezt->vec[1][0]>=ipotime) {
972 if(icu->ipo==IPO_CONST) {
973 cvalue= prevbezt->vec[1][1]+cycyofs;
975 else if(icu->ipo==IPO_LIN) {
976 fac= bezt->vec[1][0]-prevbezt->vec[1][0];
977 if(fac==0) cvalue= cycyofs+prevbezt->vec[1][1];
979 fac= (ipotime-prevbezt->vec[1][0])/fac;
980 cvalue= cycyofs+prevbezt->vec[1][1]+ fac*(bezt->vec[1][1]-prevbezt->vec[1][1]);
984 v1[0]= prevbezt->vec[1][0];
985 v1[1]= prevbezt->vec[1][1];
986 v2[0]= prevbezt->vec[2][0];
987 v2[1]= prevbezt->vec[2][1];
989 v3[0]= bezt->vec[0][0];
990 v3[1]= bezt->vec[0][1];
991 v4[0]= bezt->vec[1][0];
992 v4[1]= bezt->vec[1][1];
994 correct_bezpart(v1, v2, v3, v4);
996 b= findzero(ipotime, v1[0], v2[0], v3[0], v4[0], opl);
998 berekeny(v1[1], v2[1], v3[1], v4[1], opl, 1);
999 cvalue= opl[0]+cycyofs;
1010 if(icu->ymin < icu->ymax) {
1011 if(cvalue < icu->ymin) cvalue= icu->ymin;
1012 else if(cvalue > icu->ymax) cvalue= icu->ymax;
1018 void calc_icu(IpoCurve *icu, float ctime)
1020 icu->curval= eval_icu(icu, ctime);
1023 float calc_ipo_time(Ipo *ipo, float ctime)
1026 if(ipo && ipo->blocktype==ID_OB) {
1027 IpoCurve *icu= ipo->curve.first;
1030 if (icu->adrcode==OB_TIME) {
1031 calc_icu(icu, ctime);
1032 return 10.0f*icu->curval;
1041 void calc_ipo(Ipo *ipo, float ctime)
1045 if(ipo==NULL) return;
1046 if(ipo->muteipo) return;
1048 for(icu= ipo->curve.first; icu; icu= icu->next) {
1049 if(icu->driver || (icu->flag & IPO_LOCK)==0) {
1050 if((icu->flag & IPO_MUTE)==0)
1051 calc_icu(icu, ctime);
1056 /* ************************************** */
1058 /* ************************************** */
1060 void write_ipo_poin(void *poin, int type, float val)
1065 *( (float *)poin)= val;
1067 case IPO_FLOAT_DEGR:
1068 *( (float *)poin)= (float)(val*M_PI_2/9.0);
1073 *( (int *)poin)= (int)val;
1077 *( (short *)poin)= (short)val;
1081 *( (char *)poin)= (char)val;
1086 float read_ipo_poin(void *poin, int type)
1092 val= *( (float *)poin);
1094 case IPO_FLOAT_DEGR:
1095 val= *( (float *)poin);
1096 val = (float)(val/(M_PI_2/9.0));
1101 val= (float)(*( (int *)poin));
1105 val= *( (short *)poin);
1109 val= *( (char *)poin);
1115 static void *give_tex_poin(Tex *tex, int adrcode, int *type )
1121 poin= &(tex->noisesize); break;
1123 poin= &(tex->turbul); break;
1125 poin= &(tex->noisedepth); *type= IPO_SHORT; break;
1127 poin= &(tex->noisetype); *type= IPO_SHORT; break;
1129 poin= &(tex->vn_w1); break;
1131 poin= &(tex->vn_w2); break;
1133 poin= &(tex->vn_w3); break;
1135 poin= &(tex->vn_w4); break;
1137 poin= &(tex->vn_mexp); break;
1139 poin= &(tex->ns_outscale); break;
1141 poin= &(tex->dist_amount); break;
1143 poin= &(tex->vn_coltype); *type= IPO_SHORT; break;
1145 poin= &(tex->vn_distm); *type= IPO_SHORT; break;
1147 poin= &(tex->stype); *type= IPO_SHORT; break;
1149 poin= &(tex->mg_H); break;
1151 poin= &(tex->mg_lacunarity); break;
1153 poin= &(tex->mg_octaves); break;
1155 poin= &(tex->mg_offset); break;
1157 poin= &(tex->mg_gain); break;
1159 poin= &(tex->noisebasis); *type= IPO_SHORT; break;
1161 poin= &(tex->noisebasis2); *type= IPO_SHORT; break;
1163 poin= &(tex->rfac); break;
1165 poin= &(tex->gfac); break;
1167 poin= &(tex->bfac); break;
1169 poin= &(tex->bright); break;
1171 poin= &(tex->contrast); break;
1178 void *give_mtex_poin(MTex *mtex, int adrcode )
1184 poin= &(mtex->ofs[0]); break;
1186 poin= &(mtex->ofs[1]); break;
1188 poin= &(mtex->ofs[2]); break;
1190 poin= &(mtex->size[0]); break;
1192 poin= &(mtex->size[1]); break;
1194 poin= &(mtex->size[2]); break;
1196 poin= &(mtex->r); break;
1198 poin= &(mtex->g); break;
1200 poin= &(mtex->b); break;
1202 poin= &(mtex->def_var); break;
1204 poin= &(mtex->colfac); break;
1206 poin= &(mtex->norfac); break;
1208 poin= &(mtex->varfac); break;
1210 poin= &(mtex->dispfac); break;
1216 /* GS reads the memory pointed at in a specific ordering. There are,
1217 * however two definitions for it. I have jotted them down here, both,
1218 * but I think the first one is actually used. The thing is that
1219 * big-endian systems might read this the wrong way round. OTOH, we
1220 * constructed the IDs that are read out with this macro explicitly as
1221 * well. I expect we'll sort it out soon... */
1224 #define GS(a) (*((short *)(a)))
1226 /* from misc_util: flip the bytes from x */
1227 /* #define GS(x) (((unsigned char *)(x))[0] << 8 | ((unsigned char *)(x))[1]) */
1229 void *get_ipo_poin(ID *id, IpoCurve *icu, int *type)
1239 ParticleSettings *part;
1243 if( GS(id->name)==ID_OB) {
1247 switch(icu->adrcode) {
1249 poin= &(ob->loc[0]); break;
1251 poin= &(ob->loc[1]); break;
1253 poin= &(ob->loc[2]); break;
1255 poin= &(ob->dloc[0]); break;
1257 poin= &(ob->dloc[1]); break;
1259 poin= &(ob->dloc[2]); break;
1262 poin= &(ob->rot[0]); *type= IPO_FLOAT_DEGR; break;
1264 poin= &(ob->rot[1]); *type= IPO_FLOAT_DEGR; break;
1266 poin= &(ob->rot[2]); *type= IPO_FLOAT_DEGR; break;
1268 poin= &(ob->drot[0]); *type= IPO_FLOAT_DEGR; break;
1270 poin= &(ob->drot[1]); *type= IPO_FLOAT_DEGR; break;
1272 poin= &(ob->drot[2]); *type= IPO_FLOAT_DEGR; break;
1275 poin= &(ob->size[0]); break;
1277 poin= &(ob->size[1]); break;
1279 poin= &(ob->size[2]); break;
1281 poin= &(ob->dsize[0]); break;
1283 poin= &(ob->dsize[1]); break;
1285 poin= &(ob->dsize[2]); break;
1288 poin= &(ob->lay); *type= IPO_INT_BIT; break;
1291 poin= &(ob->col[0]);
1294 poin= &(ob->col[1]);
1297 poin= &(ob->col[2]);
1300 poin= &(ob->col[3]);
1303 if(ob->pd) poin= &(ob->pd->f_strength);
1306 if(ob->pd) poin= &(ob->pd->f_power);
1309 if(ob->pd) poin= &(ob->pd->pdef_damp);
1312 if(ob->pd) poin= &(ob->pd->pdef_rdamp);
1315 if(ob->pd) poin= &(ob->pd->pdef_perm);
1318 if(ob->pd) poin= &(ob->pd->maxdist);
1322 else if( GS(id->name)==ID_MA) {
1326 switch(icu->adrcode) {
1328 poin= &(ma->r); break;
1330 poin= &(ma->g); break;
1332 poin= &(ma->b); break;
1334 poin= &(ma->specr); break;
1336 poin= &(ma->specg); break;
1338 poin= &(ma->specb); break;
1340 poin= &(ma->mirr); break;
1342 poin= &(ma->mirg); break;
1344 poin= &(ma->mirb); break;
1346 poin= &(ma->ref); break;
1348 poin= &(ma->alpha); break;
1350 poin= &(ma->emit); break;
1352 poin= &(ma->amb); break;
1354 poin= &(ma->spec); break;
1356 poin= &(ma->har); *type= IPO_SHORT; break;
1358 poin= &(ma->spectra); break;
1360 poin= &(ma->ang); break;
1362 poin= &(ma->mode); *type= IPO_INT_BIT; break;
1364 poin= &(ma->hasize); break;
1366 poin= &(ma->translucency); break;
1368 poin= &(ma->ray_mirror); break;
1370 poin= &(ma->fresnel_mir); break;
1372 poin= &(ma->fresnel_mir_i); break;
1374 poin= &(ma->fresnel_tra); break;
1376 poin= &(ma->fresnel_tra_i); break;
1378 poin= &(ma->add); break;
1383 if(icu->adrcode & MA_MAP1) mtex= ma->mtex[0];
1384 else if(icu->adrcode & MA_MAP2) mtex= ma->mtex[1];
1385 else if(icu->adrcode & MA_MAP3) mtex= ma->mtex[2];
1386 else if(icu->adrcode & MA_MAP4) mtex= ma->mtex[3];
1387 else if(icu->adrcode & MA_MAP5) mtex= ma->mtex[4];
1388 else if(icu->adrcode & MA_MAP6) mtex= ma->mtex[5];
1389 else if(icu->adrcode & MA_MAP7) mtex= ma->mtex[6];
1390 else if(icu->adrcode & MA_MAP8) mtex= ma->mtex[7];
1391 else if(icu->adrcode & MA_MAP9) mtex= ma->mtex[8];
1392 else if(icu->adrcode & MA_MAP10) mtex= ma->mtex[9];
1395 poin= give_mtex_poin(mtex, icu->adrcode & (MA_MAP1-1) );
1399 else if( GS(id->name)==ID_TE) {
1402 if(tex) poin= give_tex_poin(tex, icu->adrcode, type);
1404 else if( GS(id->name)==ID_SEQ) {
1405 seq= (Sequence *)id;
1407 switch(icu->adrcode) {
1409 poin= &(seq->facf0); break;
1412 else if( GS(id->name)==ID_CU) {
1414 poin= &(icu->curval);
1417 else if( GS(id->name)==ID_KE) {
1418 KeyBlock *kb= ((Key *)id)->block.first;
1420 for(; kb; kb= kb->next)
1421 if(kb->adrcode==icu->adrcode)
1424 poin= &(kb->curval);
1427 else if(GS(id->name)==ID_WO) {
1431 switch(icu->adrcode) {
1433 poin= &(wo->horr); break;
1435 poin= &(wo->horg); break;
1437 poin= &(wo->horb); break;
1439 poin= &(wo->zenr); break;
1441 poin= &(wo->zeng); break;
1443 poin= &(wo->zenb); break;
1446 poin= &(wo->exposure); break;
1449 poin= &(wo->misi); break;
1451 poin= &(wo->mistdist); break;
1453 poin= &(wo->miststa); break;
1455 poin= &(wo->misthi); break;
1458 poin= &(wo->starr); break;
1460 poin= &(wo->starg); break;
1462 poin= &(wo->starb); break;
1465 poin= &(wo->stardist); break;
1467 poin= &(wo->starsize); break;
1472 if(icu->adrcode & MA_MAP1) mtex= wo->mtex[0];
1473 else if(icu->adrcode & MA_MAP2) mtex= wo->mtex[1];
1474 else if(icu->adrcode & MA_MAP3) mtex= wo->mtex[2];
1475 else if(icu->adrcode & MA_MAP4) mtex= wo->mtex[3];
1476 else if(icu->adrcode & MA_MAP5) mtex= wo->mtex[4];
1477 else if(icu->adrcode & MA_MAP6) mtex= wo->mtex[5];
1478 else if(icu->adrcode & MA_MAP7) mtex= wo->mtex[6];
1479 else if(icu->adrcode & MA_MAP8) mtex= wo->mtex[7];
1480 else if(icu->adrcode & MA_MAP9) mtex= wo->mtex[8];
1481 else if(icu->adrcode & MA_MAP10) mtex= wo->mtex[9];
1484 poin= give_mtex_poin(mtex, icu->adrcode & (MA_MAP1-1) );
1488 else if( GS(id->name)==ID_LA) {
1492 switch(icu->adrcode) {
1494 poin= &(la->energy); break;
1496 poin= &(la->r); break;
1498 poin= &(la->g); break;
1500 poin= &(la->b); break;
1502 poin= &(la->dist); break;
1504 poin= &(la->spotsize); break;
1506 poin= &(la->spotblend); break;
1508 poin= &(la->att1); break;
1510 poin= &(la->att2); break;
1512 poin= &(la->haint); break;
1517 if(icu->adrcode & MA_MAP1) mtex= la->mtex[0];
1518 else if(icu->adrcode & MA_MAP2) mtex= la->mtex[1];
1519 else if(icu->adrcode & MA_MAP3) mtex= la->mtex[2];
1520 else if(icu->adrcode & MA_MAP4) mtex= la->mtex[3];
1521 else if(icu->adrcode & MA_MAP5) mtex= la->mtex[4];
1522 else if(icu->adrcode & MA_MAP6) mtex= la->mtex[5];
1523 else if(icu->adrcode & MA_MAP7) mtex= la->mtex[6];
1524 else if(icu->adrcode & MA_MAP8) mtex= la->mtex[7];
1525 else if(icu->adrcode & MA_MAP9) mtex= la->mtex[8];
1526 else if(icu->adrcode & MA_MAP10) mtex= la->mtex[9];
1529 poin= give_mtex_poin(mtex, icu->adrcode & (MA_MAP1-1) );
1533 else if(GS(id->name)==ID_CA) {
1534 Camera *ca= (Camera *)id;
1536 /* yafray: aperture & focal distance params */
1537 switch(icu->adrcode) {
1539 if(ca->type==CAM_ORTHO)
1540 poin= &(ca->ortho_scale);
1545 poin= &(ca->clipsta); break;
1547 poin= &(ca->clipend); break;
1549 poin= &(ca->YF_aperture); break;
1551 poin= &(ca->YF_dofdist); break;
1553 poin= &(ca->shiftx); break;
1555 poin= &(ca->shifty); break;
1558 else if(GS(id->name)==ID_SO) {
1559 bSound *snd= (bSound *)id;
1561 switch(icu->adrcode) {
1563 poin= &(snd->volume); break;
1565 poin= &(snd->pitch); break;
1567 poin= &(snd->panning); break;
1569 poin= &(snd->attenuation); break;
1572 else if( GS(id->name)==ID_PA) {
1574 part= (ParticleSettings *)id;
1576 switch(icu->adrcode) {
1577 case PART_EMIT_FREQ:
1578 case PART_EMIT_LIFE:
1581 case PART_EMIT_SIZE:
1584 poin= &(part->clumpfac); break;
1586 poin= &(part->avefac); break;
1588 poin= &(part->size); break;
1590 poin= &(part->dragfac); break;
1592 poin= &(part->brownfac); break;
1594 poin= &(part->dampfac); break;
1596 poin= &(part->length); break;
1598 poin= &(part->acc[0]); break;
1600 poin= &(part->acc[1]); break;
1602 poin= &(part->acc[2]); break;
1604 poin= &(part->kink_amp); break;
1605 case PART_KINK_FREQ:
1606 poin= &(part->kink_freq); break;
1607 case PART_KINK_SHAPE:
1608 poin= &(part->kink_shape); break;
1610 poin= &(part->bb_tilt); break;
1617 void set_icu_vars(IpoCurve *icu)
1619 /* defaults. 0.0 for y-extents makes these ignored */
1620 icu->ymin= icu->ymax= 0.0;
1623 if(icu->blocktype==ID_OB) {
1625 if(icu->adrcode==OB_LAY) {
1626 icu->ipo= IPO_CONST;
1627 icu->vartype= IPO_BITS;
1631 else if(icu->blocktype==ID_MA) {
1633 if(icu->adrcode < MA_MAP1) {
1634 switch(icu->adrcode) {
1636 icu->ymax= 10000.0; break;
1638 icu->ymax= 511.0; break;
1640 icu->ymax= 2.0; break;
1642 icu->ipo= IPO_CONST;
1643 icu->vartype= IPO_BITS; break;
1645 icu->ymax= 1.0; break;
1647 icu->ymax= 1.0; break;
1650 icu->ymax= 3.0; break;
1652 icu->ymax= 5.0; break;
1655 icu->ymax= 5.0; break;
1657 icu->ymax= 5.0; break;
1660 icu->ymax= 5.0; break;
1662 icu->ymax= 1.0; break;
1664 icu->ymax= 1.0; break;
1668 switch(icu->adrcode & (MA_MAP1-1)) {
1694 else if(icu->blocktype==ID_TE) {
1695 switch(icu->adrcode & (MA_MAP1-1)) {
1698 icu->ymax= 2.0; break;
1700 icu->vartype= IPO_SHORT;
1701 icu->ipo= IPO_CONST;
1702 icu->ymax= 6.0; break;
1704 icu->vartype= IPO_SHORT;
1705 icu->ipo= IPO_CONST;
1706 icu->ymax= 1.0; break;
1708 icu->ymax= 200.0; break;
1714 icu->ymin= -2.0; break;
1717 icu->ymin= 0.01; break;
1719 icu->vartype= IPO_SHORT;
1720 icu->ipo= IPO_CONST;
1721 icu->ymax= 6.0; break;
1723 icu->vartype= IPO_SHORT;
1724 icu->ipo= IPO_CONST;
1725 icu->ymax= 3.0; break;
1728 icu->ymin= 0.01; break;
1730 icu->ymax= 10.0; break;
1732 icu->vartype= IPO_SHORT;
1733 icu->ipo= IPO_CONST;
1734 icu->ymax= 6.0; break;
1737 icu->ymax= 2.0; break;
1741 icu->ymax= 6.0; break;
1743 icu->ymax= 8.0; break;
1746 icu->vartype= IPO_SHORT;
1747 icu->ipo= IPO_CONST;
1748 icu->ymax= 8.0; break;
1750 icu->ymax= 0.0; break;
1752 icu->ymax= 2.0; break;
1754 icu->ymax= 2.0; break;
1756 icu->ymax= 2.0; break;
1758 icu->ymax= 5.0; break;
1762 else if(icu->blocktype==ID_SEQ) {
1767 else if(icu->blocktype==ID_CU) {
1772 else if(icu->blocktype==ID_WO) {
1774 if(icu->adrcode < MA_MAP1) {
1775 switch(icu->adrcode) {
1777 icu->ymax= 5.0; break;
1791 switch(icu->adrcode & (MA_MAP1-1)) {
1814 else if(icu->blocktype==ID_LA) {
1815 if(icu->adrcode < MA_MAP1) {
1816 switch(icu->adrcode) {
1827 icu->ymax= 1.0; break;
1829 icu->ymax= 180.0; break;
1831 icu->ymax= 5.0; break;
1835 switch(icu->adrcode & (MA_MAP1-1)) {
1857 else if(icu->blocktype==ID_CA) {
1859 /* yafray: aperture & focal distance params */
1860 switch(icu->adrcode) {
1887 else if(icu->blocktype==ID_SO) {
1889 switch(icu->adrcode) {
1908 else if(icu->blocktype==ID_PA){
1910 switch(icu->adrcode) {
1911 case PART_EMIT_LIFE:
1913 case PART_KINK_FREQ:
1916 case PART_EMIT_SIZE:
1929 case PART_KINK_SHAPE:
1935 else if(icu->blocktype==ID_CO) {
1940 /* by default, slider limits will be icu->ymin and icu->ymax */
1941 icu->slide_min= icu->ymin;
1942 icu->slide_max= icu->ymax;
1945 /* not for actions or constraints! */
1946 void execute_ipo(ID *id, Ipo *ipo)
1952 if(ipo==NULL) return;
1954 for(icu= ipo->curve.first; icu; icu= icu->next) {
1955 poin= get_ipo_poin(id, icu, &type);
1956 if(poin) write_ipo_poin(poin, type, icu->curval);
1960 void *get_pchan_ipo_poin(bPoseChannel *pchan, int adrcode)
1966 poin= &(pchan->quat[0]);
1967 pchan->flag |= POSE_ROT;
1970 poin= &(pchan->quat[1]);
1971 pchan->flag |= POSE_ROT;
1974 poin= &(pchan->quat[2]);
1975 pchan->flag |= POSE_ROT;
1978 poin= &(pchan->quat[3]);
1979 pchan->flag |= POSE_ROT;
1982 poin= &(pchan->loc[0]);
1983 pchan->flag |= POSE_LOC;
1986 poin= &(pchan->loc[1]);
1987 pchan->flag |= POSE_LOC;
1990 poin= &(pchan->loc[2]);
1991 pchan->flag |= POSE_LOC;
1994 poin= &(pchan->size[0]);
1995 pchan->flag |= POSE_SIZE;
1998 poin= &(pchan->size[1]);
1999 pchan->flag |= POSE_SIZE;
2002 poin= &(pchan->size[2]);
2003 pchan->flag |= POSE_SIZE;
2009 void execute_action_ipo(bActionChannel *achan, bPoseChannel *pchan)
2012 if(achan && achan->ipo) {
2014 for(icu= achan->ipo->curve.first; icu; icu= icu->next) {
2015 void *poin= get_pchan_ipo_poin(pchan, icu->adrcode);
2017 write_ipo_poin(poin, IPO_FLOAT, icu->curval);
2018 //printf("execute_action_ipo wrote_ipo_poin: %f\n", icu->curval);
2019 //printf("%s has poin %p value %f\n", achan->name, poin, icu->curval);
2025 /* exception: it does calc for objects...
2026 * now find out why this routine was used anyway!
2028 void do_ipo_nocalc(Ipo *ipo)
2038 if(ipo==NULL) return;
2040 switch(ipo->blocktype) {
2042 ob= G.main->object.first;
2046 /* execute_ipo((ID *)ob, ipo); */
2052 ma= G.main->mat.first;
2054 if(ma->ipo==ipo) execute_ipo((ID *)ma, ipo);
2059 tex= G.main->tex.first;
2061 if(tex->ipo==ipo) execute_ipo((ID *)tex, ipo);
2066 wo= G.main->world.first;
2068 if(wo->ipo==ipo) execute_ipo((ID *)wo, ipo);
2073 la= G.main->lamp.first;
2075 if(la->ipo==ipo) execute_ipo((ID *)la, ipo);
2080 ca= G.main->camera.first;
2082 if(ca->ipo==ipo) execute_ipo((ID *)ca, ipo);
2087 snd= G.main->sound.first;
2089 if(snd->ipo==ipo) execute_ipo((ID *)snd, ipo);
2096 void do_ipo(Ipo *ipo)
2099 float ctime= frame_to_float(G.scene->r.cfra);
2100 calc_ipo(ipo, ctime);
2108 void do_mat_ipo(Material *ma)
2112 if(ma==NULL || ma->ipo==NULL) return;
2114 ctime= frame_to_float(G.scene->r.cfra);
2115 /* if(ob->ipoflag & OB_OFFS_OB) ctime-= ob->sf; */
2117 calc_ipo(ma->ipo, ctime);
2119 execute_ipo((ID *)ma, ma->ipo);
2122 void do_ob_ipo(Object *ob)
2127 if(ob->ipo==NULL) return;
2129 /* do not set ob->ctime here: for example when parent in invisible layer */
2131 ctime= bsystem_time(ob, (float) G.scene->r.cfra, 0.0);
2133 calc_ipo(ob->ipo, ctime);
2135 /* Patch: remember localview */
2136 lay= ob->lay & 0xFF000000;
2138 execute_ipo((ID *)ob, ob->ipo);
2141 if(ob->id.name[2]=='S' && ob->id.name[3]=='C' && ob->id.name[4]=='E') {
2142 if(strcmp(G.scene->id.name+2, ob->id.name+6)==0) {
2143 G.scene->lay= ob->lay;
2144 copy_view3d_lock(0);
2145 /* no redraw here! creates too many calls */
2150 void do_ob_ipodrivers(Object *ob, Ipo *ipo, float ctime)
2156 for(icu= ipo->curve.first; icu; icu= icu->next) {
2158 icu->curval= eval_icu(icu, ctime);
2159 poin= get_ipo_poin((ID *)ob, icu, &type);
2160 if(poin) write_ipo_poin(poin, type, icu->curval);
2165 void do_seq_ipo(Sequence *seq, int cfra)
2169 /* seq_ipo has an exception: calc both fields immediately */
2172 if((seq->flag & SEQ_IPO_FRAME_LOCKED) != 0) {
2173 ctime = frame_to_float(cfra);
2176 ctime= frame_to_float(cfra - seq->startdisp);
2177 div= (seq->enddisp - seq->startdisp)/100.0f;
2178 if(div==0.0) return;
2182 calc_ipo(seq->ipo, (ctime+0.5f)/div);
2183 execute_ipo((ID *)seq, seq->ipo);
2184 seq->facf1= seq->facf0;
2187 calc_ipo(seq->ipo, ctime/div);
2188 execute_ipo((ID *)seq, seq->ipo);
2191 else seq->facf1= seq->facf0= 1.0f;
2194 int has_ipo_code(Ipo *ipo, int code)
2198 if(ipo==NULL) return 0;
2200 for(icu= ipo->curve.first; icu; icu= icu->next) {
2201 if(icu->adrcode==code) return 1;
2206 void do_all_data_ipos()
2221 ctime= frame_to_float(G.scene->r.cfra);
2223 /* this exception cannot be depgraphed yet... what todo with objects in other layers?... */
2224 for(base= G.scene->base.first; base; base= base->next) {
2225 /* only update layer when an ipo */
2226 if( has_ipo_code(base->object->ipo, OB_LAY) ) {
2227 do_ob_ipo(base->object);
2228 base->lay= base->object->lay;
2232 /* layers for the set...*/
2234 for(base= G.scene->set->base.first; base; base= base->next) {
2235 if( has_ipo_code(base->object->ipo, OB_LAY) ) {
2236 do_ob_ipo(base->object);
2237 base->lay= base->object->lay;
2243 ipo= G.main->ipo.first;
2245 if(ipo->id.us && ipo->blocktype!=ID_OB) {
2246 calc_ipo(ipo, ctime);
2251 for(tex= G.main->tex.first; tex; tex= tex->id.next) {
2252 if(tex->ipo) execute_ipo((ID *)tex, tex->ipo);
2255 for(ma= G.main->mat.first; ma; ma= ma->id.next) {
2256 if(ma->ipo) execute_ipo((ID *)ma, ma->ipo);
2259 for(wo= G.main->world.first; wo; wo= wo->id.next) {
2260 if(wo->ipo) execute_ipo((ID *)wo, wo->ipo);
2263 for(key= G.main->key.first; key; key= key->id.next) {
2264 if(key->ipo) execute_ipo((ID *)key, key->ipo);
2267 la= G.main->lamp.first;
2269 if(la->ipo) execute_ipo((ID *)la, la->ipo);
2273 ca= G.main->camera.first;
2275 if(ca->ipo) execute_ipo((ID *)ca, ca->ipo);
2279 snd= G.main->sound.first;
2281 if(snd->ipo) execute_ipo((ID *)snd, snd->ipo);
2285 /* process FAC Ipos used as volume envelopes */
2288 seq= ed->seqbasep->first;
2290 if ((seq->type == SEQ_RAM_SOUND
2291 || seq->type == SEQ_HD_SOUND) && (seq->ipo) &&
2292 (seq->startdisp<=G.scene->r.cfra+2) &&
2293 (seq->enddisp>G.scene->r.cfra))
2294 do_seq_ipo(seq, G.scene->r.cfra);
2302 int calc_ipo_spec(Ipo *ipo, int adrcode, float *ctime)
2306 if(ipo==NULL) return 0;
2308 for(icu= ipo->curve.first; icu; icu= icu->next) {
2309 if(icu->adrcode == adrcode) {
2310 if(icu->flag & IPO_LOCK);
2311 else calc_icu(icu, *ctime);
2313 *ctime= icu->curval;
2322 /* ************************** */
2324 void clear_delta_obipo(Ipo *ipo)
2328 if(ipo==NULL) return;
2330 ob= G.main->object.first;
2332 if(ob->id.lib==NULL) {
2334 memset(&ob->dloc, 0, 12);
2335 memset(&ob->drot, 0, 12);
2336 memset(&ob->dsize, 0, 12);
2343 void add_to_cfra_elem(ListBase *lb, BezTriple *bezt)
2350 if( ce->cfra==bezt->vec[1][0] ) {
2351 /* do because of double keys */
2352 if(bezt->f2 & SELECT) ce->sel= bezt->f2;
2355 else if(ce->cfra > bezt->vec[1][0]) break;
2360 cen= MEM_callocN(sizeof(CfraElem), "add_to_cfra_elem");
2361 if(ce) BLI_insertlinkbefore(lb, ce, cen);
2362 else BLI_addtail(lb, cen);
2364 cen->cfra= bezt->vec[1][0];
2370 void make_cfra_list(Ipo *ipo, ListBase *elems)
2376 if(ipo->blocktype==ID_OB) {
2377 for(icu= ipo->curve.first; icu; icu= icu->next) {
2378 if(icu->flag & IPO_VISIBLE) {
2379 switch(icu->adrcode) {
2409 add_to_cfra_elem(elems, bezt);
2418 else if(ipo->blocktype==ID_AC) {
2419 for(icu= ipo->curve.first; icu; icu= icu->next) {
2420 if(icu->flag & IPO_VISIBLE) {
2421 switch(icu->adrcode) {
2436 add_to_cfra_elem(elems, bezt);
2446 for(icu= ipo->curve.first; icu; icu= icu->next) {
2447 if(icu->flag & IPO_VISIBLE) {
2452 add_to_cfra_elem(elems, bezt);
2460 /* what's the point of this little block of code? */
2462 if(ipo->showkey==0) {
2463 /* deselect all keys */
2473 /* *********************** INTERFACE FOR KETSJI ********** */
2476 int IPO_GetChannels(Ipo *ipo, IPO_Channel *channels)
2478 /* channels is max 32 items, allocated by calling function */
2483 if(ipo==NULL) return 0;
2485 for(icu= ipo->curve.first; icu; icu= icu->next) {
2486 channels[total]= icu->adrcode;
2496 /* Get the float value for channel 'channel' at time 'ctime' */
2498 float IPO_GetFloatValue(Ipo *ipo, IPO_Channel channel, float ctime)
2500 if(ipo==NULL) return 0;
2502 calc_ipo_spec(ipo, channel, &ctime);
2504 if (OB_ROT_X <= channel && channel <= OB_DROT_Z) {
2505 ctime *= (float)(M_PI_2/9.0);