writescript.C

Go to the documentation of this file.
00001 /* file writescript.c    */
00002 
00003 #define MODULE_WRITESCRIPT 1
00004 
00005 #include "animate.h"
00006 #include "callall.h"
00007 
00008 
00009 static void PrepareSequenceFilename(char *tname, long id, char *filename){
00010  int ln;
00011  char *cp,*cp1,*cp2,extn[16],fmat[16],fsurf[256];
00012  strcpy(tname,filename); // just use first if anything goes wrong
00013  strcpy(fsurf,filename);
00014  cp1=strchr(fsurf,'0');
00015  cp2=strchr(fsurf,'.');
00016  if(cp1 == NULL || cp2 == NULL)return;
00017  strcpy(extn,cp2);
00018  ln=0; cp=cp1; while(cp != cp2){ln++; cp++; if(ln > 8)break;}
00019  *cp1='\0';
00020  sprintf(fmat,"%%s%%0%ldld%%s",ln);
00021  sprintf(tname,fmat,fsurf,id,extn);
00022 }
00023 
00024 BOOL MakeScript(long type, long nstep){
00025  FILE   *fs;
00026  node   *Np,*selected_camera;
00027  object *Op;
00028  sky    *Sp;
00029  XIP    *Ip;
00030  BOOL retval=TRUE;
00031  double dframe;
00032  long i,j,ccf,MakeFirst,MakeLast,ncount,Ropen=1,version=0,SkyImageFileID,GroundImageFileID;
00033  point p,tp;
00034  point TVP,TVC,TVclipMin,TVclipMax;
00035  short im,refl;
00036  double phi,theta,alpha,mratio,sx,sy,sz,ima,gamb,oamb,m2ratio;
00037  unsigned char sr,sg,sb,zr,zg,zb;
00038  char *spc,*sps,robot_name[255],filename[255];
00039  int ready=0;
00040  if     (type == 1){MakeFirst = MakeLast = CurrentFrame;}
00041  else if(type == 0){MakeFirst = 1; MakeLast=Nframes;}
00042  if     (type == 3){ /* script this frame to work file */
00043    MakeFirst = MakeLast = CurrentFrame;
00044    sprintf(filename,"%sw_$.scr",TempPath);
00045    ready=1;
00046  }
00047  else if(type == 4){ /* script whole animation to work file */
00048    MakeFirst = 1; MakeLast = Nframes;
00049    sprintf(filename,"%sw_$.scr",TempPath);
00050    ready=1;
00051  }
00052  else if(type == 5){ /* script this frame to work file */
00053    MakeFirst = MakeLast = CurrentFrame;
00054    sprintf(filename,"%sx_$.scr",TempPath);
00055    ready=1;
00056  }
00057  else if(type == 6){ /* script whole animation to work file */
00058    MakeFirst = 1; MakeLast = Nframes;
00059    sprintf(filename,"%sy_$.scr",TempPath);
00060    ready=1;
00061  }
00062  else{
00063   if(SelectSfxFileName(1,gszSCRfile,gszSCRdir,IDX_MISC_SCRIPTFILE,
00064                    "(*.SCR)|*.scr|",ghwnd_main) == TRUE){
00065     AppendFileExtension(gszSCRfile,".scr");
00066     strcpy(filename,gszSCRfile);
00067     ready=1;
00068   }
00069   else ready=0;
00070  }
00071  if(ready){
00072   ghcurSave=SetCursor(ghcurWait);
00073   if(Nrobots > 0)Ropen=OpenRobotDirectory(filename);
00074   if(Ropen && (fs=fopen(filename,"w")) != NULL){
00075    ccf=CurrentFrame;
00076    get_centre_stage(TVC,TVP,TVclipMin,TVclipMax);
00077    fprintf(fs,"RS2\n");
00078    if(type == 1 || type == 3 || type == 5)fprintf(fs,"1 %ld\n",MakeFirst);
00079    else                                   fprintf(fs,"%ld 1\n",Nframes);
00080    for(i=0;i<3;i++)fprintf(fs,"%ld %ld\n",TVclipMin[i],TVclipMax[i]);  // print out scene bounds
00081    SkyImageFileID=0; GroundImageFileID=0;
00082    for(CurrentFrame=MakeFirst; CurrentFrame<=MakeLast; CurrentFrame++){
00083     for(i=0;i<nstep;i++){                     // put sub (dframe loop here)
00084     dframe=1.0/(double)nstep*((double)i+1.0); //
00085     ncount=0;
00086     selected_camera=GetSelectedCamera(CurrentFrame,SelectedCamera);
00087     Np=FirstNp; while(Np!=NULL){
00088       if     (Np->type == CAMERA && Np == selected_camera){
00089         GetTransform(0,CurrentFrame,dframe,
00090                      Np,Np->fobj,p,tp,&phi,&theta,&alpha,
00091                      &sx,&sy,&sz,&im,&ima);
00092         //fprintf(fs,"e %.1f %.1f %.1f\n",(double)p[0],(double)p[1],(double)p[2]);  old script
00093         fprintf(fs,"E %.1f %.1f %.1f\n",(double)p[0],(double)p[1],(double)p[2]);
00094         fprintf(fs,"  %.1f %.1f %.1f\n",phi,theta,alpha);
00095         fprintf(fs,"  %.3f %.3f %.3f\n",sx,sy,sz);
00096         fprintf(fs,"  %d %d %.1f\n",0,im,ima);
00097         {
00098           cameraparam* cpa; 
00099           double focus_distance_ruler_units; 
00100           cpa=CalculateCameraProperties(Np,CurrentFrame,dframe); // get these from the Size Keyframer
00101           // focus distance should be in absolute (global (integer)) units to match the position units
00102           if(cpa == NULL){
00103             fprintf(fs," %.3lf %.3lf %.1lf\n",50.0,5.0,1.0);   
00104             fprintf(fs," %.3lf %.3lf %.1lf\n",1.0,1.0,0.0);
00105             fprintf(fs," %.3lf %.3lf %.3lf\n",1.0,100.0,0.0);
00106           }
00107           else{
00108             fprintf(fs," %.3lf %.3lf %.1lf\n",cpa->focal_length,cpa->f_number,cpa->focus_distance);   
00109             focus_distance_ruler_units=cpa->focus_distance/ruler;
00110             fprintf(fs," %.3lf %.3lf %.1lf\n",focus_distance_ruler_units,ruler,cpa->polar_type);
00111             fprintf(fs," %.3lf %.3lf %.3lf\n",cpa->stereo_separation,cpa->parallax_distance,0.0); //las parameter not used
00112           }
00113           // write extra camera params 
00114           for(j=0;j<7;j++)fprintf(fs,"  0.0 0.0 0.0\n");
00115         }   
00116       }
00117       else if(Np->type == SKY){
00118         if((Sp=Np->fsky) != NULL)while(Sp != NULL){
00119           if(CurrentFrame >= Sp->firstframe && CurrentFrame <= Sp->lastframe){
00120             if(Sp->last != NULL){
00121               mratio=(double)(Sp->lastframe - Sp->firstframe+1);
00122               mratio=((double)CurrentFrame - (double)Sp->firstframe+dframe)/mratio;
00123               sr=Sp->last->colour[0] +
00124                 (Sp->colour[0] - Sp->last->colour[0])*mratio;
00125               sg=Sp->last->colour[1] +
00126                 (Sp->colour[1] - Sp->last->colour[1])*mratio;
00127               sb=Sp->last->colour[2] +
00128                 (Sp->colour[2] - Sp->last->colour[2])*mratio;
00129               zr=Sp->last->zcolour[0] +
00130                 (Sp->zcolour[0] - Sp->last->zcolour[0])*mratio;
00131               zg=Sp->last->zcolour[1] +
00132                 (Sp->zcolour[1] - Sp->last->zcolour[1])*mratio;
00133               zb=Sp->last->zcolour[2] +
00134                 (Sp->zcolour[2] - Sp->last->zcolour[2])*mratio;
00135               oamb=Sp->last->oamb + (Sp->oamb - Sp->last->oamb)*mratio;
00136               gamb=Sp->last->gamb + (Sp->gamb - Sp->last->gamb)*mratio;
00137             }
00138             else{
00139               sr=Sp->colour[0];
00140               sg=Sp->colour[1];
00141               sb=Sp->colour[2];
00142               zr=Sp->zcolour[0];
00143               zg=Sp->zcolour[1];
00144               zb=Sp->zcolour[2];
00145               oamb=Sp->oamb;
00146               gamb=Sp->gamb;
00147             }
00148             // augmented Sky
00149             fprintf(fs,"S"); for(j=0;j<32;j++)fprintf(fs,"  %6.2lf",Sp->sky_params[j]); fprintf(fs,"\n");
00150             // basic sky
00151             fprintf(fs,"s %d %d %d\n",sr,sg,sb);
00152             fprintf(fs,"  %d %d %d\n",zr,zg,zb);
00153             mratio=0.0;  /* NB not needed now leave for compatibility */
00154             sr=0;sg=0;sb=0;zr=0;zg=0;zb=0;
00155             fprintf(fs,"  %.1f %.2lf %.2lf\n",mratio,oamb,gamb); /* sky blend, ambients */
00156             fprintf(fs,"  %d %d %d\n",sr,sg,sb);
00157             fprintf(fs,"  %d %d %d\n",zr,zg,zb);
00158             if(Sp->type == SKYANIMATED)fprintf(fs,"  %d\n",BACKDROP); // animated is backdrop
00159             else                       fprintf(fs,"  %d\n",Sp->type);
00160             if     (Sp->type == SKYANIMATED){
00161               long fid;
00162               char tname[256];
00163               fid=Sp->aff+(CurrentFrame-Sp->firstframe)*Sp->ast;
00164               while(fid > Sp->alf)fid -= Sp->alf;
00165               PrepareSequenceFilename(tname,fid,Sp->name);
00166               fprintf(fs,"  %s\n",tname);
00167             }
00168             else if(Sp->type >= 2){
00169               char temp_name[256];
00170               if(Sp->image.size > 0 && Sp->image.filename != NULL){
00171                 WriteTemporaryFileForScript(TRUE,&(Sp->image),temp_name,
00172                                             &SkyImageFileID);
00173                 fprintf(fs,"  %s\n",temp_name);
00174               }
00175               else fprintf(fs,"  %s\n",Sp->name);
00176             }
00177             break;
00178           }
00179         Sp=Sp->next;}
00180       }
00181       else{
00182         if((Op=Np->fobj) != NULL)while(Op != NULL){
00183           if(CurrentFrame >= Op->firstframe && CurrentFrame <= Op->lastframe){
00184             if     (Op->type == LIGHT){
00185               fprintf(fs,"l %d\n",Op->lighttype);
00186               if(Op->last != NULL){
00187                 mratio=(double)(Op->lastframe - Op->firstframe+1);
00188                 mratio=((double)CurrentFrame - (double)Op->firstframe+dframe)/mratio;
00189                 sr=Op->last->colour[0] +
00190                   (Op->colour[0] - Op->last->colour[0])*mratio;
00191                 sg=Op->last->colour[1] +
00192                   (Op->colour[1] - Op->last->colour[1])*mratio;
00193                 sb=Op->last->colour[2] +
00194                   (Op->colour[2] - Op->last->colour[2])*mratio;
00195               }
00196               else{
00197                 sr=Op->colour[0]; sg=Op->colour[1]; sb=Op->colour[2];
00198               }
00199               fprintf(fs,"  %d %d %d %.2lf\n",sr,sg,sb,Op->light_intensity);
00200               GetTransform(0,CurrentFrame,dframe,
00201                            Np,Op,p,tp,&phi,&theta,&alpha,
00202                            &sx,&sy,&sz,&im,&ima);
00203               fprintf(fs,"  %.1f %.1f %.1f\n",(double)p[0],(double)p[1]
00204                                        ,(double)p[2]);
00205               fprintf(fs,"  %.1f %.1f %.1f\n",phi,theta,alpha);
00206               fprintf(fs,"  %ld %d %.1f\n",(long)(Np->ID),im,ima);
00207               if(Op->depth_cue){
00208                 fprintf(fs,"  %ld %.2f %.3le %.3le\n",
00209                   Op->depth_cue, Op->depth_cue_c,
00210                   ((Op->depth_cue_l)/((double)UNIT*sz)),
00211                   ((Op->depth_cue_q)/((double)UNIT*sz*(double)UNIT*sz)));
00212               }
00213               else fprintf(fs,"  0 1.0 0.0 0.0\n");
00214               if(Op->lighttype >= SPOTLIGHT)fprintf(fs,"  %.3f %.3f\n",
00215                  sx,sy); /* sz is cone angle sy is fall off angle */
00216             }
00217             else if(Op->type == PARTICLE){ 
00218               fprintf(fs,"p %d %d %d\n",Op->particles.id,Op->particles.iid,Op->particles.bSingle);
00219               fprintf(fs,"  %s\n",Op->particles.ImageName);  
00220               fprintf(fs,"  %d %d %d %d\n",Op->particles.particle_size_scale,Op->particles.particle_speed_scale,
00221                                           (long)Op->particles.bSteadyState,(long)Op->particles.bSpinOff);
00222               fprintf(fs,"  %d %d %d %d\n",Op->particles.NumP,Op->particles.burst,Op->particles.ground,Op->particles.blend_model );  
00223               fprintf(fs,"  %d %d %d\n",Op->particles.colour_start[0],Op->particles.colour_start[1]
00224                                        ,Op->particles.colour_start[2]);
00225               fprintf(fs,"  %d %d %d\n",Op->particles.colour_end[0],Op->particles.colour_end[1]
00226                                        ,Op->particles.colour_end[2]);
00227               fprintf(fs,"  %d %d %d %d\n",Op->particles.alpha_start,Op->particles.size_start,
00228                                            Op->particles.alpha_end,Op->particles.size_end);
00229               fprintf(fs,"  %d %d %d\n",Op->particles.life,Op->particles.speed,Op->particles.theta);
00230               fprintf(fs,"  %d %d %d %d %d\n",Op->particles.vcolour,Op->particles.valpha,
00231                                               Op->particles.vsize,Op->particles.vlife,Op->particles.vspeed);
00232               fprintf(fs,"  %d %d %d \n",Op->particles.ew_start,Op->particles.ud_start,Op->particles.ns_start);  
00233               fprintf(fs,"  %d %d %d \n",Op->particles.ew_end,Op->particles.ud_end,Op->particles.ns_end);  
00234               GetTransform(0,CurrentFrame,dframe,
00235                            Np,Op,p,tp,&phi,&theta,&alpha,
00236                            &sx,&sy,&sz,&im,&ima);
00237               fprintf(fs,"  %.1f %.1f %.1f\n",(double)p[0],(double)p[1]
00238                                        ,(double)p[2]);
00239               fprintf(fs,"  %.1f %.1f %.1f\n",phi,theta,alpha);
00240               fprintf(fs,"  %.3f %.3f %.3f\n",sx,sy,sz);
00241               fprintf(fs,"  %d %.1f\n",im,ima);
00242               mratio=(double)(Op->lastframe - Op->firstframe + 1);
00243               mratio=((double)CurrentFrame - (double)Op->firstframe + dframe)/mratio;
00244               fprintf(fs,"%d %.3f\n",(CurrentFrame-Op->firstframe),mratio);  // Dframe
00245               { point p1; // velocity
00246                 long ffid;
00247                 if(CurrentFrame == Op->firstframe)ffid=Op->firstframe+1; else ffid=CurrentFrame-1;
00248                 GetTransform(0,ffid,dframe,
00249                              Np,Op,p1,tp,&phi,&theta,&alpha,
00250                              &sx,&sy,&sz,&im,&ima);
00251                 if(CurrentFrame == Op->firstframe){point pt; VECCOPY(p,pt) VECCOPY(p1,p) VECCOPY(pt,p1)}
00252                 fprintf(fs,"  %.1f %.1f %.1f\n",(double)(p[0]-p1[0]),(double)(p[1]-p1[1]),(double)(p[2]-p1[2]));
00253               }
00254               GetTransform(0,Op->firstframe,dframe,  // position at start of particle actor
00255                            Np,Op,p,tp,&phi,&theta,&alpha,
00256                            &sx,&sy,&sz,&im,&ima);
00257               fprintf(fs,"  %.1f %.1f %.1f\n",(double)p[0],(double)p[1]
00258                                        ,(double)p[2]);
00259               fprintf(fs,"  %.1f %.1f %.1f\n",phi,theta,alpha);
00260               fprintf(fs,"  %.3f %.3f %.3f\n",sx,sy,sz);
00261               fprintf(fs,"  %d %.1f\n",im,ima);
00262             }
00263             else if(Op->type == GROUND){
00264               fprintf(fs,"G %d\n",Op->groundtype);
00265               if(Op->last != NULL){
00266                 mratio=(double)(Op->lastframe - Op->firstframe + 1);
00267                 mratio=((double)CurrentFrame - (double)Op->firstframe + dframe)/mratio;
00268                 sr=Op->last->colour[0] +
00269                   (Op->colour[0] - Op->last->colour[0])*mratio;
00270                 sg=Op->last->colour[1] +
00271                   (Op->colour[1] - Op->last->colour[1])*mratio;
00272                 sb=Op->last->colour[2] +
00273                   (Op->colour[2] - Op->last->colour[2])*mratio;
00274                 zr=Op->last->acolour[0] +
00275                   (Op->acolour[0] - Op->last->acolour[0])*mratio;
00276                 zg=Op->last->acolour[1] +
00277                   (Op->acolour[1] - Op->last->acolour[1])*mratio;
00278                 zb=Op->last->acolour[2] +
00279                   (Op->acolour[2] - Op->last->acolour[2])*mratio;
00280                 refl = Op->last->grefl +
00281                   (Op->grefl - Op->last->grefl)*mratio;
00282               }
00283               else{
00284                  sr=Op->colour[0];  sg=Op->colour[1];  sb=Op->colour[2];
00285                  zr=Op->acolour[0]; zg=Op->acolour[1]; zb=Op->acolour[2];
00286                  refl = Op->grefl;
00287               }
00288               fprintf(fs,"  %d %d %d\n",sr,sg,sb);
00289               if(Op->groundtype > 127){
00290                 fprintf(fs,"  %d %d %d\n",zr,zg,zb);
00291               }
00292               if(Op->groundtype == BRUM || Op->groundtype == TBRUM ||
00293                  Op->groundtype == MBRUM){
00294                 if(Op->image.size > 0 && Op->image.filename != NULL){
00295                   char temp_name[256];
00296                   WriteTemporaryFileForScript(FALSE,&(Op->image),temp_name,
00297                                             &GroundImageFileID);
00298                   fprintf(fs,"  %s\n",temp_name);
00299                 }
00300                 else fprintf(fs,"  %s\n",Op->name);
00301               }
00302               GetTransform(0,CurrentFrame,dframe,
00303                            Np,Op,p,tp,&phi,&theta,&alpha,
00304                            &sx,&sy,&sz,&im,&ima);
00305               fprintf(fs,"  %.1f %.1f %.1f\n",(double)p[0],(double)p[1]
00306                                        ,(double)p[2]);
00307               fprintf(fs,"  %.1f %.1f %.1f\n",phi,theta,alpha);
00308               fprintf(fs,"  %.3f %.3f %.3f\n",sx,sy,sz);
00309               fprintf(fs,"  %d %d %.1f %d\n",0,im,ima,refl);
00310               fprintf(fs,"  %.3f\n",Op->groundTemperature);
00311             }
00312             else if(Op->type == NORMAL || Op->type == ANIMOBJ ||
00313                     Op->type == ROBOT){
00314               if     (Op->bWireframe == 1)fprintf(fs,"w");
00315               else if(Op->bWireframe == 2)fprintf(fs,"h");
00316               else                        fprintf(fs,"o");
00317               fprintf(fs," %ld\n%s\n",(long)(Np->ID),Op->name);
00318               if(Op->type == ROBOT){
00319                 fprintf(fs,"4");
00320                 GetRobotScriptName(filename,ncount,
00321                                   Op->lastframe,
00322                                   robot_name);
00323                 if(!RobotFileExists(robot_name))WriteRobot(Op,robot_name);
00324                 fprintf(fs," %s\n",robot_name);
00325                 if(Op->last != NULL){
00326                   GetRobotScriptName(filename,ncount,
00327                                     Op->last->lastframe,
00328                                     robot_name);
00329                   if(!RobotFileExists(robot_name))
00330                                            WriteRobot(Op->last,robot_name);
00331                 }
00332                 fprintf(fs,"  %s\n",robot_name);
00333                 mratio=(double)(Op->lastframe - Op->firstframe + 1);
00334                 mratio=((double)CurrentFrame - (double)Op->firstframe + dframe)/mratio;
00335                 fprintf(fs,"%.3f\n",mratio);
00336               }
00337               else if(Op->morph == NO || Op->last == NULL){
00338                 fprintf(fs,"0\n");
00339               }
00340               else{
00341                 mratio=(double)(Op->lastframe - Op->firstframe + 1);
00342                 if(Op->lastframe == Nframes)mratio += 1.0; /* for loop */
00343                 mratio=((double)CurrentFrame - (double)Op->firstframe + dframe)/mratio;
00344                 if((Op->morph == QMORPH) &&
00345                    (Op->last->last != NULL || Op->next != NULL)){
00346                    if(Op->last->last != NULL){
00347                      m2ratio=(double)(Op->lastframe - Op->firstframe);
00348                      if(m2ratio < 1.0){
00349                        fprintf(fs,"0\n");
00350                      }
00351                      else{
00352                        fprintf(fs,"2 ");
00353                        fprintf(fs,"%.3f\n",mratio);
00354                        fprintf(fs,"  %s\n",Op->last->name);
00355                        m2ratio=(double)(Op->last->lastframe -
00356                                         Op->last->firstframe)/m2ratio;
00357                        fprintf(fs,"%.3f\n",m2ratio);
00358                        fprintf(fs,"  %s\n",Op->last->last->name);
00359                      }
00360                    }
00361                    else if(Op->next != NULL){
00362                      m2ratio=(double)(Op->lastframe - Op->firstframe);
00363                      if(m2ratio < 1.0){
00364                        fprintf(fs,"0\n");
00365                      }
00366                      else{
00367                        fprintf(fs,"3 ");
00368                        fprintf(fs,"%.3f\n",mratio);
00369                        fprintf(fs,"  %s\n",Op->last->name);
00370                        m2ratio=(double)(Op->next->lastframe -
00371                                         Op->next->firstframe)/m2ratio;
00372                        fprintf(fs,"%.3f\n",m2ratio);
00373                        fprintf(fs,"  %s\n",Op->next->name);
00374                      }
00375                    }
00376                    else{ /* an error has occurred */
00377                      SendPrgmQuery(IDQ_SCRIPTFAIL,0);
00378                    }
00379                 }
00380                 else{
00381                   fprintf(fs,"1 ");
00382                   fprintf(fs,"%.3f\n",mratio);
00383                   fprintf(fs,"  %s\n",Op->last->name);
00384                 }
00385               }
00386               GetTransform(0,CurrentFrame,dframe,
00387                            Np,Op,p,tp,&phi,&theta,&alpha,
00388                            &sx,&sy,&sz,&im,&ima);
00389               fprintf(fs,"  %.1f %.1f %.1f\n",(double)p[0],(double)p[1]
00390                                        ,(double)p[2]);
00391               fprintf(fs,"  %.1f %.1f %.1f\n",phi,theta,alpha);
00392               fprintf(fs,"  %.3f %.3f %.3f\n",sx,sy,sz);
00393               mratio=(double)(Op->lastframe - Op->firstframe + 1);/*effects*/
00394               mratio=((double)CurrentFrame - (double)Op->firstframe + dframe)/mratio;
00395               if(Op->effect == NULL)refl=0;
00396               else refl=21;
00397               fprintf(fs,"  %ld %d %.1f %d %.3f\n",version,im,ima,refl,mratio);
00398               fprintf(fs,"  %ld %ld %ld\n",Op->self_shadow,Op->cast_shadow,
00399                                            Op->show_shadow);
00400               if(Op->effect != NULL){
00401                 fprintf(fs,"  %s ~\n",Op->effect);
00402               }
00403             }
00404             else if(Op->type == IMAGEP){
00405               if(Op->last != NULL && Op->last->xip != NULL && Op->morph == YES){
00406                 mratio=(double)(Op->lastframe - Op->firstframe + 1);
00407                 mratio=((double)CurrentFrame - (double)Op->firstframe + dframe)/mratio;
00408                 im=1;
00409               }
00410               else {im=0; mratio=1.0;}
00411               if(Op->xip != NULL){
00412                 fprintf(fs,"i %d %ld %ld %ld %.3f\n",
00413                         im,Op->firstframe,CurrentFrame,Op->lastframe,mratio);
00414                 fprintf(fs," %s\n",Op->xip);
00415                 if(im == 1)fprintf(fs," %s\n",Op->last->xip);
00416               }
00417             }
00418             break;
00419           }
00420           Op=Op->next;
00421         }
00422       }
00423       Np=Np->next; ncount++;
00424     }
00425     if(NimageProcesses > 0){
00426       Ip=FirstIp; while (Ip != NULL){
00427         if(Ip->p != NULL){
00428           fprintf(fs,"i 0 1 %ld %ld 0.0\n",CurrentFrame,Nframes);
00429           fprintf(fs,"  %s\n",Ip->p);
00430         }
00431         Ip=Ip->next;
00432       }
00433     }
00434     if(i < nstep-1)fprintf(fs,"b\n"); //
00435     }                                 // end sub loop
00436     fprintf(fs,"f\n");
00437    }
00438    CurrentFrame=ccf;
00439    fprintf(fs,"q\n");
00440    fclose(fs);
00441   }
00442   else{
00443     retval=FALSE;
00444   }
00445   SetCursor(ghcurSave);
00446  }
00447  return retval;
00448 }
00449 
00450 BOOL ExportRobotKeyframes(void){  // Must all be same Robot model - each instance is a different sequence
00451  FILE     *fs;
00452  object   *Op;
00453  node     *Np;
00454  position *Pp;
00455  point    PtStart,PtEnd,dP;
00456  BOOL retval=TRUE;
00457  long i,ccf,ncount,lff,fr;
00458  char *spc,*sps,robot_name[255],filename[255],anim_name[255];
00459  int ready=0,Ropen=1,seq;
00460 
00461  if(Nrobots == 0)return FALSE;
00462  if(SelectSfxFileName(1,gszSCRfile,gszSCRdir,IDX_MISC_SCRIPTFILE,
00463                    "(*.SCR)|*.scr|",ghwnd_main) == TRUE){
00464     AppendFileExtension(gszSCRfile,".scr");
00465     strcpy(filename,gszSCRfile);
00466     ready=1;
00467  }
00468  else ready=0;
00469  if(ready){
00470    ghcurSave=SetCursor(ghcurWait);
00471    Ropen=OpenRobotDirectory(filename);
00472    if(Ropen && (fs=fopen(filename,"w")) != NULL){
00473      ccf=CurrentFrame;
00474      ncount=0; Np=FirstNp; while(Np!=NULL){ Op=Np->fobj; if(Op->type == ROBOT)ncount++; Np=Np->next;}
00475      fprintf(fs,"%ld 20\n",ncount); // number of animations 
00476      strcpy(anim_name,FileInPath(filename)); *strchr(anim_name,'.') ='\0';
00477      fprintf(fs,"%s\n",anim_name);   // name of animation
00478      ncount=0; Np=FirstNp; while(Np!=NULL){
00479        Op=Np->fobj;
00480        if(Op->type == ROBOT){
00481          if((Pp=Np->fpos) != NULL){
00482            VECCOPY(Pp->finish,PtStart);
00483            while(Pp != NULL){VECCOPY(Pp->finish,PtEnd)   Pp=Pp->next;}
00484            VECSUB(PtEnd,PtStart,dP)
00485          }
00486          else {dP[0]=dP[1]=dP[2]=0;}
00487          seq=0; while(Op != NULL){seq++; lff=Op->lastframe; Op=Op->next;}
00488 //         fprintf(fs,"%s\n%f %f\n",Np->actorname,(float)(lff)/30.0f,0.01);  
00489          fprintf(fs,"%s\n%f %f %f %f\n",Np->actorname,(float)(lff)/30.0f, //nameof animation and total time  
00490                  (double)dP[1]/(double)ruler*0.016666,   // in order for importer
00491                  (double)dP[0]/(double)ruler*0.016666,
00492                  (double)dP[2]/(double)ruler*0.016666);  
00493          fprintf(fs,"%ld\n",seq);  // number of robots 
00494          Op=Np->fobj;  while(Op != NULL){
00495            GetRobotScriptName(filename,ncount,Op->lastframe, robot_name);
00496            if(!RobotFileExists(robot_name))WriteRobot(Op,robot_name);
00497            if(Op->lastframe == 1)fr=0; else fr=Op->lastframe;
00498            fprintf(fs,"%f %s\n",(float)fr/30.0,robot_name);  // anim time
00499            Op=Op->next;
00500          }
00501          ncount++;
00502        }
00503        Np=Np->next;
00504      }
00505      if(ncount != Nrobots)MessageBox(NULL,"Not all animated sequences written",NULL,MB_OK);
00506      CurrentFrame=ccf;
00507      fclose(fs);
00508    }
00509    else retval=FALSE;
00510    SetCursor(ghcurSave);
00511  }
00512  return retval;
00513 }

Generated on Sun Apr 27 14:20:10 2014 for OpenFX by  doxygen 1.5.6