externals.c

Go to the documentation of this file.
00001 /* --
00002 OpenFX - Modelling, Animation and Rendering Package
00003 -- */
00004 
00005 
00006 /* file loader.c  - loads/saves the models from their files on disk  */
00007 
00008 #define MODULE_EXTERNAL 1
00009 
00010 #include "design.h"
00011 
00012 static void LoadRenderer(int anim);
00013 
00014 void LoadMDIviewer(void){
00015  BOOL n=FALSE;
00016  int result;
00017  char modulename[255];
00018  HWND hWnd;
00019  if((hWnd=FindWindow("OFX:Viewer",NULL)) == NULL){
00020    strcpy(modulename,gszHomeDir);strcat(modulename,"mdiview.exe");
00021    n=TRUE;
00022    result=WinExec(modulename,SW_SHOW);
00023    if(result < 32){
00024      if(result == ERROR_FILE_NOT_FOUND ||
00025         result == ERROR_PATH_NOT_FOUND)SendPrgmQuery(IDQ_NOSTART,3);
00026      return;
00027    }
00028    hWnd=FindWindow("OFX:Viewer",NULL);
00029  }
00030  if(IsWindow(hWnd)){
00031    SetForegroundWindow(hWnd);
00032    BringWindowToTop(hWnd);
00033    ShowWindow(hWnd,SW_SHOW);
00034    if(n)PostMessage(hWnd,WM_COMMAND,1004,0);
00035  }
00036  return;
00037 }
00038 
00039 
00040 BOOL LoadHeightField(HWND hwnd){
00041  BOOL status=FALSE;
00042  HMODULE hLib;
00043  FARPROC fpFun;
00044  char lname[256];
00045  X__STRUCTURE *Evs;
00046  BOOL (*fpFun1)(HWND, char *, X__STRUCTURE *);
00047  if(SelectSfxFileName(0,gszGIFfile,gszGIFdir,IDX_MISC_HEIGHTFIELD,
00048    "(*.GIF)|*.gif|",ghwnd_main) == FALSE)return FALSE;
00049  EDIT_ACTION=YES;
00050  Evs=&EviStructure;
00051  strcpy(lname,gszHomeDir); strcat(lname,"height.dll");
00052  if((hLib=LoadLibrary(lname)) != NULL){
00053    if((fpFun=GetProcAddress(hLib,"_HeightField")) != NULL){
00054      fpFun1 = (void *)fpFun;
00055      status=(*fpFun1)(hwnd,gszGIFfile,Evs);
00056    }
00057    else SendPrgmQuery(IDQ_FAILEDFUNCTION,3);
00058    FreeLibrary(hLib);
00059  }
00060  else SendPrgmQuery(IDQ_FAILEDLIBRARY,3);
00061  return status;
00062 }
00063 
00064 BOOL TraceImageOutline(HWND hwnd){
00065  BOOL status=FALSE;
00066  static HMODULE hLibTrace=NULL;
00067  FARPROC fpFun;
00068  char lname[256];
00069  X__STRUCTURE *Evs;
00070  BOOL (*fpFun1)(HWND, HWND, char *, X__STRUCTURE *);
00071  if(hLibTrace != NULL){
00072    return FALSE;
00073  }
00074  if(SelectSfxFileName(0,gszIMGfile,gszIMGdir,IDX_MISC_TRACE,
00075    "All Image Formats|*.bmp;*.gif;*.tga|"
00076    "(*.GIF)|*.gif|(*.TGA)|*.tga|(*.BMP)|*.bmp|",
00077    hwnd) == FALSE)return FALSE;
00078  EDIT_ACTION=YES;
00079  Evs=&EviStructure;
00080  strcpy(lname,gszHomeDir); strcat(lname,"trace.dll");
00081  if((hLibTrace=LoadLibrary(lname)) != NULL){
00082    if((fpFun=GetProcAddress(hLibTrace,"_TraceOutline")) != NULL){
00083      fpFun1 = (void *)fpFun;
00084      status=(*fpFun1)(hwnd,ghwnd_info,gszIMGfile,Evs);
00085    }
00086    else SendPrgmQuery(IDQ_FAILEDFUNCTION,3);
00087    FreeLibrary(hLibTrace);
00088  }
00089  else SendPrgmQuery(IDQ_FAILEDLIBRARY,3);
00090  hLibTrace=NULL;
00091  return status;
00092 }
00093 
00094 BOOL PaintMapOutline(HWND hwnd){ 
00095  BOOL status=FALSE;
00096  static HMODULE hLibTrace=NULL;
00097  FARPROC fpFun;
00098  char lname[256];
00099  unsigned char *pixels;
00100  long w,h,id;
00101  IMAGEMAP *map;
00102  RAMIMAGE *image;
00103  X__STRUCTURE *Evs;
00104  BOOL (*fpFun1)(HWND, HWND, unsigned char *, long, long, long, X__STRUCTURE *);
00105  if(hLibTrace != NULL){
00106    return FALSE;
00107  }
00108  if(nImaps < 1){ SendPrgmQuery(IDQ_NOBRUSH,0); return status; }
00109  else if(nImaps > 1){
00110   if((id=RequestMapID(ghwnd_main,"Select by Map",0)) < 0)return status;
00111  }
00112  else  id=0;
00113  map = &(iMap[id]);
00114  image = NULL;
00115  if(map->s == 1 && map->S != NULL && map->Type != ANIMBRUSH)image  = &(map->si);
00116  if(image == NULL)return status;
00117  if( !image->in_use && image->filename == NULL && 
00118          image->data == NULL && image->size == 0)return status;
00119  // Make a full pixel copy of the image map
00120  pixels=MakeFullMemoryImage(image,&w,&h);
00121 
00122  if(pixels == NULL){MessageBox(NULL,"Bad Image Make",NULL,MB_OK); return status; }
00123 
00124  EDIT_ACTION=YES;
00125  Evs=&EviStructure;
00126  strcpy(lname,gszHomeDir); strcat(lname,"paintmap.dll");
00127  if((hLibTrace=LoadLibrary(lname)) != NULL){
00128    if((fpFun=GetProcAddress(hLibTrace,"_PaintMap")) != NULL){
00129      fpFun1 = (void *)fpFun;
00130      status=(*fpFun1)(hwnd,ghwnd_info,pixels,w,h,id,Evs);
00131    }
00132    else SendPrgmQuery(IDQ_FAILEDFUNCTION,3);
00133    FreeLibrary(hLibTrace);
00134  }
00135  else SendPrgmQuery(IDQ_FAILEDLIBRARY,3);
00136  hLibTrace=NULL;
00137  X__Free(pixels);
00138  return status;
00139 }
00140 
00141 
00142 BOOL ExecuteExternalAction(int id,HWND hwnd){
00143  static BOOL inuse=FALSE;
00144  BOOL status=FALSE;
00145  HMODULE hLib;
00146  FARPROC fpFun;
00147  X__STRUCTURE *Evs;
00148  BOOL (*fpFun1)(HWND, HWND, X__STRUCTURE *);
00149  int l;
00150  char fname[255];
00151  if(tool > INZOOM)DisengageDesignerTool();
00152  if(sktool || SelectedBrush >= 0 || SelectedShader >= 0){
00153    SendPrgmQuery(IDQ_TOOLNOTFINISHED,0);
00154    return FALSE;
00155  }
00156  if(id >= nActionsList)return FALSE;
00157  Empty_Undo();
00158  EDIT_ACTION=YES;
00159  Save_Undo(2);
00160  strcpy(fname,ActionsList[id]);
00161  l=strlen(fname);
00162  fname[l-1]='l';
00163  fname[l-2]='l';
00164  fname[l-3]='d';
00165  if(inuse)return FALSE;
00166  inuse=TRUE;
00167  Evs=&EviStructure;
00168  if((hLib=LoadLibrary(fname)) != NULL){
00169    if((fpFun=GetProcAddress(hLib,"_Xmodeler")) != NULL){
00170      fpFun1 = (void *)fpFun;
00171      status=(*fpFun1)(hwnd,ghwnd_info,Evs);
00172    }
00173    else SendPrgmQuery(IDQ_FAILEDFUNCTION,3);
00174    FreeLibrary(hLib);
00175  }
00176  else SendPrgmQuery(IDQ_FAILEDLIBRARY,3);
00177  inuse=FALSE;
00178  return status;
00179  return TRUE;
00180 }
00181 
00182 BOOL ExecuteExternalModeler(HWND hwnd){
00183  long l;
00184  static BOOL inuse=FALSE;
00185  BOOL status=FALSE;
00186  HMODULE hLib;
00187  FARPROC fpFun;
00188  X__STRUCTURE *Evs;
00189  BOOL (*fpFun1)(HWND, HWND, X__STRUCTURE *);
00190  if(inuse)return FALSE;
00191  l=strlen(gszDLMfile);
00192  strcpy((gszDLMfile+l-3),"dfx");
00193  if(SelectSfxFileName(0,gszDLMfile,gszDLMdir,IDX_MISC_EXTMODELER,
00194    "(*.dfx)|*.dfx|",ghwnd_main) == FALSE)return FALSE;
00195  l=strlen(gszDLMfile);
00196  strcpy((gszDLMfile+l-3),"dll");
00197  inuse=TRUE;
00198  EDIT_ACTION=YES;
00199  Evs=&EviStructure;
00200  if((hLib=LoadLibrary(gszDLMfile)) != NULL){
00201    if((fpFun=GetProcAddress(hLib,"_Xmodeler")) != NULL){
00202      fpFun1 = (void *)fpFun;
00203      status=(*fpFun1)(hwnd,ghwnd_info,Evs);
00204    }
00205    else SendPrgmQuery(IDQ_FAILEDFUNCTION,3);
00206    FreeLibrary(hLib);
00207  }
00208  else SendPrgmQuery(IDQ_FAILEDLIBRARY,3);
00209  inuse=FALSE;
00210  return status;
00211 }
00212 
00213 BOOL ExecuteBezierModeler(HWND hwnd){
00214  char lname[256];
00215  static BOOL inuse=FALSE;
00216  BOOL status=FALSE;
00217  HMODULE hLib;
00218  FARPROC fpFun;
00219  X__STRUCTURE *Evs;
00220  BOOL (*fpFun1)(HWND, HWND, X__STRUCTURE *);
00221  if(inuse)return FALSE;
00222  inuse=TRUE;
00223  EDIT_ACTION=YES;
00224  Evs=&EviStructure;
00225  strcpy(lname,gszHomeDir); strcat(lname,"bezier.dll");
00226  if((hLib=LoadLibrary(lname)) != NULL){
00227    if((fpFun=GetProcAddress(hLib,"_BezierModeler")) != NULL){
00228      fpFun1 = (void *)fpFun;
00229      status=(*fpFun1)(hwnd,ghwnd_info,Evs);
00230    }
00231    else SendPrgmQuery(IDQ_FAILEDFUNCTION,3);
00232    FreeLibrary(hLib);
00233  }
00234  else SendPrgmQuery(IDQ_FAILEDLIBRARY,3);
00235  inuse=FALSE;
00236  return status;
00237 }
00238 
00239 long LoadXmodel(char *name, char *library){
00240  char lname[255],text[128];
00241  long rv=0;
00242  HMODULE hLib=NULL;
00243  FARPROC fpFun;
00244  X__STRUCTURE *Evs;
00245  long (*fpFun1)(HWND, char *, char *, X__STRUCTURE *);
00246  Evs=&EviStructure;
00247  strcpy(lname,gszHomeDir); strcat(lname,library);
00248  if((hLib=LoadLibrary(lname)) != NULL){
00249    if((fpFun=GetProcAddress(hLib,"_Convert")) != NULL){
00250      fpFun1 = (void *)fpFun;
00251      sprintf(lname,"%sW_$.mfx",TempPath);
00252      rv=(*fpFun1)(ghwnd_main,name,lname,Evs);
00253    }
00254    else{
00255      SendPrgmQuery(IDQ_FAILEDFUNCTION,3);
00256    }
00257    FreeLibrary(hLib); hLib=NULL;
00258  }
00259  else SendPrgmQuery(IDQ_FAILEDLIBRARY,3);
00260  if(rv > 0)LoadObject(lname,0);
00261  Save_Undo(2);
00262  remove(lname);
00263  return rv;
00264 }
00265 
00266 void Export3DSmodel(HWND hwnd){
00267  if(SelectSfxFileName(1,gsz3DSfile,gsz3DSdir,IDX_MISC_EXPORT3DS,
00268    "(*.3DS)|*.3ds|",ghwnd_main) == FALSE)return;
00269  AppendFileExtension(gsz3DSfile,".3ds");
00270  ExportModel(gsz3DSfile,"3dsout.dll");
00271  return;
00272 }
00273 
00274 void ExportDXFmodel(HWND hwnd){
00275  if(SelectSfxFileName(1,gszDXFfile,gszDXFdir,IDX_MISC_EXPORTDXF,
00276    "(*.DXF)|*.dxf|",ghwnd_main) == FALSE)return;
00277  AppendFileExtension(gszDXFfile,".dxf");
00278  ExportModel(gszDXFfile,"dxfout.dll");
00279  return;
00280 }
00281 
00282 long ExportModel(char *name, char *library){
00283  char lname[255];
00284  long rv=0;
00285  HMODULE hLib=NULL;
00286  FARPROC fpFun;
00287  X__STRUCTURE *Evs;
00288  long (*fpFun1)(HWND, char *, X__STRUCTURE *);
00289  Evs=&EviStructure;
00290  strcpy(lname,gszHomeDir); strcat(lname,library);
00291  if((hLib=LoadLibrary(lname)) != NULL){
00292    if((fpFun=GetProcAddress(hLib,"_Export")) != NULL){
00293      fpFun1 = (void *)fpFun;
00294      rv=(*fpFun1)(ghwnd_main,name,Evs);
00295    }
00296    else{
00297      SendPrgmQuery(IDQ_FAILEDFUNCTION,3);
00298    }
00299    FreeLibrary(hLib); hLib=NULL;
00300  }
00301  else SendPrgmQuery(IDQ_FAILEDLIBRARY,3);
00302  return rv;
00303 }
00304 
00305 BOOL LoadInternalAction(char *library){
00306  char lname[128];
00307  static BOOL inuse=FALSE;
00308  BOOL status=FALSE;
00309  HMODULE hLib;
00310  FARPROC fpFun;
00311  X__STRUCTURE *Evs;
00312  BOOL (*fpFun1)(HWND, HWND, X__STRUCTURE *);
00313  if(tool > INZOOM)DisengageDesignerTool();
00314  if(sktool || SelectedBrush >= 0 || SelectedShader >= 0){
00315    SendPrgmQuery(IDQ_TOOLNOTFINISHED,0);
00316    return FALSE;
00317  }
00318  if(inuse)return FALSE;
00319  inuse=TRUE;
00320  Empty_Undo();
00321  EDIT_ACTION=YES;
00322  Save_Undo(2);
00323  Evs=&EviStructure;
00324  strcpy(lname,gszHomeDir); strcat(lname,library);
00325  if((hLib=LoadLibrary(lname)) != NULL){
00326    if((fpFun=GetProcAddress(hLib,"_Xmodeler")) != NULL){
00327      fpFun1 = (void *)fpFun;
00328      status=(*fpFun1)(ghwnd_main,ghwnd_info,Evs);
00329      DrawModel();
00330      UpdateCounters();
00331      UpdateSkTreeView();
00332    }
00333    else SendPrgmQuery(IDQ_FAILEDFUNCTION,3);
00334    FreeLibrary(hLib);
00335  }
00336  else SendPrgmQuery(IDQ_FAILEDLIBRARY,3);
00337  inuse=FALSE;
00338  return TRUE;
00339 }
00340 
00341 // include the loadviewer code - this is used by the animator and so
00342 // is in a separate file
00343 
00344 #include "loadview.c"
00345 
00346 // invoke the external plugins through their dialog boxes
00347 
00348 #include "..\animate\callall.h"
00349 
00350 static void LoadRenderer(int anim){
00351  char modulename[256];
00352  HWND hWnd,hWndCall;
00353  int result;
00354  if((hWnd=FindWindow("OFX:RenderClass",NULL)) != NULL){
00355    if     (anim == 1)
00356      PostMessage(hWnd,WM_COMMAND,IDM_CALLBACK_SETUP_PREVIEW,0);
00357    else if(anim == 2)
00358      PostMessage(hWnd,WM_COMMAND,IDM_CALLBACK_RUN,(WORD)1);
00359    else if(anim == 3){
00360      if(ghwndOpenGLview == NULL)hWndCall=ghwnd_view;
00361      else                       hWndCall=ghwndOpenGLview;
00362      PostMessage(hWnd,WM_CALLBACK_MATERIAL,0,(LPARAM)hWndCall);
00363    }
00364    else
00365      SendMessage(hWnd,IDM_CALLBACK_SETUP_MODELLER,0,0);
00366    if(anim != 3){
00367      SetForegroundWindow(hWnd);
00368      BringWindowToTop(hWnd);
00369      ShowWindow(hWnd,SW_SHOW);
00370    }
00371    return;
00372  }
00373  else{
00374    strcpy(modulename,gszHomeDir);strcat(modulename,"render.exe $SAL$");
00375    result=WinExec(modulename,SW_SHOW);
00376    if(result < 32){
00377      if(result == ERROR_FILE_NOT_FOUND ||
00378         result == ERROR_PATH_NOT_FOUND)SendPrgmQuery(IDQ_NOSTART,3);
00379    }
00380    if((hWnd=FindWindow("OFX:RenderClass",NULL)) != NULL){
00381      if     (anim == 1)
00382        PostMessage(hWnd,WM_COMMAND,IDM_CALLBACK_SETUP_PREVIEW,0);
00383      else if(anim == 2)
00384        PostMessage(hWnd,WM_COMMAND,IDM_CALLBACK_RUN,(WORD)1);
00385      else if(anim == 3){
00386        if(ghwndOpenGLview == NULL)hWndCall=ghwnd_view;
00387        else                       hWndCall=ghwndOpenGLview;
00388        PostMessage(hWnd,WM_CALLBACK_MATERIAL,0,(LPARAM)hWndCall);
00389      }
00390      else
00391        PostMessage(hWnd,IDM_CALLBACK_SETUP_MODELLER,0,0);
00392      if(anim != 3){
00393        SetForegroundWindow(hWnd);
00394        BringWindowToTop(hWnd);
00395        ShowWindow(hWnd,SW_SHOW);
00396      }
00397    }
00398    else SendPrgmQuery(IDQ_NOSTART,3);
00399  }
00400  return;
00401 }
00402 
00403 void Render_View(int light_pos, long how){
00404  char config_file[64],SCRIPTfilename[256],OBJECTfilename[256];
00405  long i,narg;
00406  FILE *fs,*fc;
00407  HCURSOR lhcurSave;
00408  double lpx,lpy,lpz,rad,dr,llpx,llpy,llpz,Fi,Theta;
00409  if(type_of_view){
00410    Fi = PerspFi; Theta = -PerspTheta;
00411  }
00412  else{
00413    Fi = -PerspFi; Theta = PerspTheta;
00414  }
00415  dr=PI/180.0;
00416  sprintf(OBJECTfilename,"%sW_$.mfx",TempPath);
00417  remove(OBJECTfilename);
00418  lhcurSave=SetCursor(ghcurWait);
00419  SaveObject(OBJECTfilename,2);    // 2 for saving only in window-box
00420  SetCursor(lhcurSave);
00421  sprintf(SCRIPTfilename,"%sW_$.scr",TempPath);
00422  if((fs=fopen(SCRIPTfilename,"w")) == NULL){
00423    remove(OBJECTfilename);
00424    return;
00425  }
00426  fprintf(fs,"Renderer-Script\n");
00427  fprintf(fs,"1 1\n");
00428  lpx=(double)(TVpointX+TVsizeX/2);
00429  lpy=(double)(TVpointY+TVsizeY/2);
00430  lpz=(double)(TVpointZ+TVsizeZ/2);
00431  rad=TVsizeX*5;
00432  llpx = lpx-rad*10.0*cos(-(Theta+30)*dr)*sin(-(Fi+45)*dr);
00433  llpy = lpy-rad*10.0*cos(-(Theta+30)*dr)*cos(-(Fi+45)*dr);
00434  llpz = lpz-rad*10.0*sin(-(Theta+30)*dr);
00435  lpx -= rad*cos(-Theta*dr)*sin(-Fi*dr);
00436  lpy -= rad*cos(-Theta*dr)*cos(-Fi*dr);
00437  lpz -= rad*sin(-Theta*dr);
00438  fprintf(fs,"e %.1f %.1f %.1f\n",lpx,lpy,lpz);
00439  fprintf(fs,"  %.1f %.1f %.1f\n",Fi,0.0,-Theta);
00440  fprintf(fs,"  %.3f %.3f %.3f\n",3.5,3.5,3.5); /* 3.5 3.0 3.0 */
00441  fprintf(fs,"  %d %d %.1f\n",0,0,0.0);
00442 #if 0
00443  if(light_pos == 0){ /* light over shoulder */
00444    fprintf(fs,"l 0\n  255 255 255 1.0\n");
00445    fprintf(fs,"  %.1f %.1f %.1f\n",llpx,llpy,llpz);
00446    fprintf(fs,"  0.0 0.0 0.0\n 0 0 0.0\n");
00447    fprintf(fs,"  0 1.0 0.0 0.0\n");
00448  }
00449 #endif
00450  fprintf(fs,"s %ld %ld %ld\n",
00451          (long)Preferences.Vcolour[0],
00452          (long)Preferences.Vcolour[1],
00453          (long)Preferences.Vcolour[2]);
00454  fprintf(fs,"  %ld %ld %ld\n",
00455          (long)Preferences.Vcolour[0],
00456          (long)Preferences.Vcolour[1],
00457          (long)Preferences.Vcolour[2]);
00458  fprintf(fs," 0.0 0.1 0.08\n");
00459  fprintf(fs," 0 0 0\n");
00460  fprintf(fs," 0 0 0\n");
00461  fprintf(fs," 0\n");
00462  fprintf(fs,"o 1\n");
00463  fprintf(fs,"%s\n",OBJECTfilename);
00464  fprintf(fs,"0\n");
00465  fprintf(fs,"  %.1f %.1f %.1f\n",0.0,0.0,0.0);
00466  fprintf(fs,"  %.1f %.1f %.1f\n",0.0,0.0,0.0);
00467  fprintf(fs,"  %.3f %.3f %.3f\n",1.0,1.0,1.0);
00468  fprintf(fs,"  %d %d %.1f %d %.3f\n",0,0,0.0,0,1.0);
00469  fprintf(fs,"  1 1 1\n");
00470  fprintf(fs,"f\n");
00471  fprintf(fs,"q\n");
00472  fclose(fs);
00473  sprintf(SCRIPTfilename,"%sW_$",TempPath);
00474  if     (how == 1)LoadRenderer(2);   // Quick render with prev params
00475  else if(how == 0){                  // Setup renderer
00476    LoadRenderer(0);
00477    EnableMenuItem(GetMenu(ghwnd_main),IDM_VIEW_RENDERNOW,MF_ENABLED);
00478  }
00479  else if(how == 2)LoadRenderer(3);   // render into window
00480  return;
00481 }
00482 
00483 void ShaderPreview(void){ // NOT used now
00484   LoadRenderer(1);
00485 }
00486 
00487 

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