VRMLOUT.C

Go to the documentation of this file.
00001 /* --
00002 OpenFX version 2.0 - Modelling, Animation and Rendering Package
00003 Copyright (C) 2000 - 2007 OpenFX Development Team
00004 -- */
00005 
00006 /* File VRMLOUT.C DLL  */
00007 
00008 #include <stdlib.h>
00009 #include <stdio.h>
00010 #include <math.h>
00011 #include <setjmp.h>
00012 #include <windows.h>
00013 #if __HELP_WS__
00014 #include "..\help_ws\include\htmlhelp.h"
00015 #endif
00016 
00017 #include "struct.h"
00018 #include "dstruct.h"
00019 
00020 #include "vrmlout.h"
00021 
00022 #if __X__MIPS__
00023 BOOL WINAPI _CRT_INIT(HINSTANCE ,DWORD , LPVOID );
00024 #endif
00025 
00026 static HWND      hParent;
00027 static HINSTANCE hThisInstance;
00028 
00029 #define DOS386
00030 #define _X__FAR
00031 #define PI  3.1415926
00032 
00033 #ifndef min
00034 #define min(a,b)  ( ((a) < (b)) ? (a) : (b) )
00035 #endif
00036 #ifndef max
00037 #define max(a,b)  ( ((a) > (b)) ? (a) : (b) )
00038 #endif
00039 
00040 #define UNIT         32768L
00041 #define UNIT2        65536L
00042 #define MINUNIT       2048L     // was 1024 trying larger to prevent error
00043 #define MAXUNIT    4194304L     //1073741824L
00044 #define PI2            PI/2
00045 /* definition of flags and identifiers*/
00046 #define DESELECTED       0
00047 #define SELECTED         1
00048 #define HIDDEN           2
00049 #define INEDITOR         6
00050 #define FAIL            -1
00051 
00052 #define VECSUB(a,b,c)   { c[0]=a[0]-b[0]; c[1]=a[1]-b[1]; c[2]=a[2]-b[2];}
00053 #define VECSUM(a,b,c)   { c[0]=a[0]+b[0]; c[1]=a[1]+b[1]; c[2]=a[2]+b[2];}
00054 #define VECSCALE(a,b,c) { c[0]=(a)*b[0]; c[1]=(a)*b[1]; c[2]=(a)*b[2];}
00055 #define DOT(a,b)        ( (a[0]*b[0]) + (a[1]*b[1]) + (a[2]*b[2]) )
00056 #define CROSS(v1,v2,r)  { \
00057                           r[0] = (v1[1]*v2[2]) - (v2[1]*v1[2]);  \
00058                           r[1] = (v1[2]*v2[0]) - (v1[0]*v2[2]);  \
00059                           r[2] = (v1[0]*v2[1]) - (v2[0]*v1[1]);  \
00060                          }
00061 
00062 
00063 typedef unsigned char COLOUR[3];
00064 
00065 typedef struct tagMapVRML {
00066  char name[15];
00067  unsigned char dr,dg,db;
00068 } MapVRML;
00069 
00070 static MapVRML *mapVRMLlist=NULL;
00071 static long   mapVRMLcount;
00072 static face   **faces=NULL;
00073 static long *faceid=NULL;
00074 static long *facemarker=NULL;
00075 static long lrulerx,lrulery,lrulerz;
00076 static double ruler;
00077 static long indent=0;
00078 static long digits=3;
00079 static BOOL bIndent=TRUE,bPrefix=TRUE,bNormals=FALSE;
00080 static char map_path[256]="../maps/";
00081 static char globalfile[256]="";
00082 
00083 static BOOL WriteDataToRegistry(char *keyname){
00084  HKEY hkey;
00085  DWORD result;
00086  DWORD dw;
00087  if(RegCreateKeyEx(HKEY_LOCAL_MACHINE,keyname,0,NULL,
00088                    REG_OPTION_NON_VOLATILE,
00089                    KEY_ALL_ACCESS,NULL,&hkey,&result) != ERROR_SUCCESS)
00090    return FALSE;
00091  RegSetValueEx(hkey,"map_prefix",0,REG_SZ,map_path,strlen(map_path)+1);
00092  RegSetValueEx(hkey,"model_file",0,REG_SZ,globalfile,strlen(globalfile)+1);
00093  dw=(DWORD)bPrefix;
00094  RegSetValueEx(hkey,"use_map_prefix",0,REG_DWORD,(LPBYTE)(&dw),sizeof(DWORD));
00095  dw=(DWORD)digits;
00096  RegSetValueEx(hkey,"digits",0,REG_DWORD,(LPBYTE)(&dw),sizeof(DWORD));
00097  dw=(DWORD)bIndent;
00098  RegSetValueEx(hkey,"indent",0,REG_DWORD,(LPBYTE)(&dw),sizeof(DWORD));
00099  dw=(DWORD)bNormals;
00100  RegSetValueEx(hkey,"normals",0,REG_DWORD,(LPBYTE)(&dw),sizeof(DWORD));
00101  RegCloseKey(hkey);
00102  return TRUE;
00103 }
00104 
00105 static BOOL ReadDataFromRegistry(char *keyname){
00106  HKEY hkey;
00107  DWORD result;
00108  DWORD len,type,dw;
00109  char  str[256];
00110  if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,keyname,0,KEY_ALL_ACCESS,&hkey)
00111    != ERROR_SUCCESS)return FALSE;
00112  len=256;
00113  if(RegQueryValueEx(hkey,"map_prefix",NULL,&type,str,&len)
00114     == ERROR_SUCCESS)strcpy(map_path,str);
00115  len=256;
00116  if(RegQueryValueEx(hkey,"model_file",NULL,&type,str,&len)
00117     == ERROR_SUCCESS)strcpy(globalfile,str);
00118  len=sizeof(DWORD);
00119  if(RegQueryValueEx(hkey,"use_map_prefix",NULL,&type,(LPBYTE)(&dw),&len)
00120     == ERROR_SUCCESS)bPrefix=(BOOL)dw;
00121  len=sizeof(DWORD);
00122  if(RegQueryValueEx(hkey,"indent",NULL,&type,(LPBYTE)(&dw),&len)
00123     == ERROR_SUCCESS)bIndent=(BOOL)dw;
00124  len=sizeof(DWORD);
00125  if(RegQueryValueEx(hkey,"digits",NULL,&type,(LPBYTE)(&dw),&len)
00126     == ERROR_SUCCESS)digits=(long)dw;
00127  if(RegQueryValueEx(hkey,"normals",NULL,&type,(LPBYTE)(&dw),&len)
00128     == ERROR_SUCCESS)bNormals=(BOOL)dw;
00129  len=sizeof(DWORD);
00130  RegCloseKey(hkey);
00131  return TRUE;
00132 }
00133 
00134 static char *FileOnly(char *file){
00135  char *t;
00136  t=strrchr(file,'\\');
00137  if(t == NULL)return file;
00138  return (t+1);
00139 }
00140 
00141 static void Id(FILE *f){
00142  int i;
00143  if(!bIndent)return;
00144  if(indent > 0)for(i=0;i<indent;i++)fprintf(f,"  ");
00145 }
00146 
00147 static void AddToColourList(COLOUR **L, long *n, face *Fp,
00148                             unsigned R, unsigned G, unsigned B,long ic){
00149  COLOUR *N,*O;
00150  long i,k;
00151  k = *n;
00152  O = *L;
00153  for(i=0;i<k;i++){
00154    if(O[i][0] == R && O[i][1] == G && O[i][2] == B){
00155 //     Fp->pad=(unsigned char)i;
00156      facemarker[ic]=(long)i;
00157      return; // found
00158    }
00159  }
00160  N=(COLOUR *)X__Realloc(O,(k+1)*sizeof(COLOUR));
00161  if(N == NULL)return;  // fail
00162  N[k][0]=R; N[k][1]=G; N[k][2]=B;
00163  //Fp->pad=(unsigned char)k;
00164  facemarker[ic]=(unsigned char)k;
00165  k++;
00166  *n = k;
00167  *L = N;
00168  return;
00169 }
00170 static void GetFaceVector(face *fp, vector n){
00171  vector v20,v10;
00172  VECSUB((double)(MainVp+(fp->V[2]))->xyz,(double)(MainVp+(fp->V[0]))->xyz,v20)
00173  VECSUB((double)(MainVp+(fp->V[1]))->xyz,(double)(MainVp+(fp->V[0]))->xyz,v10)
00174  CROSS(v10,v20,n)
00175  oNormalize(n);
00176  return;
00177 }
00178 
00179 void CreateVRMLfile(FILE *dxfp){
00180  char layer[]={"MODEL"},cl[128],format[64],format1[64];
00181  long fp,vp;
00182  vertex *Vp;
00183  face   *Fp;
00184  skel   *sp;
00185  long i,id1,id2,id3,nColourList=0,ic;
00186  unsigned short nv,nf,j;
00187  unsigned char cR,cG,cB;
00188  float x,y,z;
00189  BOOL bColour=FALSE,bMapped=FALSE;
00190  COLOUR *ColourList=NULL;
00191  vector n,*NormalList=NULL;
00192  long mapid;
00193  mapVRMLlist=NULL;
00194  mapVRMLcount=0;
00195  sprintf(format,"%%.%ldf %%.%ldf %%.%ldf",digits,digits,digits);
00196  sprintf(format1,"%%.%ldf %%.%ldf",digits,digits);
00197 
00198  sp=MainSp; for(;;){ /* sp will be null for vertices not on any node */
00199    if(sp != NULL)strcpy(cl,sp->name);
00200    else          strcpy(cl,layer);
00201    vp=0; nv=0; while(vp < Nvert){
00202      Vp=(MainVp+vp);
00203      if(Vp->status == SELECTED && Vp->sp == sp){
00204        Vp->status=INEDITOR;
00205        nv++;
00206      }
00207      vp++;
00208    }
00209    bColour=FALSE; bMapped=FALSE; nColourList=0; ColourList=NULL; mapid=0;
00210    nf=0; fp=0; ic=0; while(fp < Nface){
00211      Fp=(MainFp+fp);
00212      if((MainVp+Fp->V[0])->status == INEDITOR &&
00213         (MainVp+Fp->V[1])->status == INEDITOR &&
00214         (MainVp+Fp->V[2])->status == INEDITOR){
00215        if(Fp->imagemap >= 0){ // mapped
00216          if(!bMapped)mapid=(long)Fp->imagemap;
00217          bMapped=TRUE;
00218        }
00219        // make color and material list
00220        if(nf == 0){
00221          cR=Fp->color[0]; cG=Fp->color[1]; cB=Fp->color[2];
00222          ColourList=(COLOUR *)X__Malloc(sizeof(COLOUR));
00223          if(ColourList != NULL){
00224            ColourList[0][0]=cR;
00225            ColourList[0][1]=cG;
00226            ColourList[0][2]=cB;
00227            nColourList++;
00228            facemarker[ic]=0;
00229            //Fp->pad=0;
00230          }
00231        }
00232        else{
00233          cR=Fp->color[0]; cG=Fp->color[1]; cB=Fp->color[2];
00234          AddToColourList(&ColourList,&nColourList,Fp,cR,cG,cB,ic);
00235        }
00236        nf++;
00237      }
00238      ic++; fp++;
00239    }
00240 
00241    if(!bMapped)bColour=TRUE;
00242 
00243    if(nf > 0){ /* only write if there are any faces */
00244      if(bNormals &&
00245         (NormalList=(vector *)X__Malloc(nv*sizeof(vector))) != NULL)
00246        bNormals=TRUE;
00247      // write-ROOT header  - Shape
00248      Id(dxfp); fprintf(dxfp,"DEF SFX-%s-ROOT Transform {\n",cl);  indent++;
00249      Id(dxfp); fprintf(dxfp,"translation 0 0 0\n");
00250      Id(dxfp); fprintf(dxfp,"children [\n"); indent++;
00251      Id(dxfp); fprintf(dxfp,"Shape {\n"); indent++;
00252      // write appearance
00253      Id(dxfp); fprintf(dxfp,"appearance Appearance {\n"); indent++;
00254      Id(dxfp); fprintf(dxfp,"material Material {\n"); indent++;
00255      // if all one color then set
00256      if(nColourList == 1){
00257        Id(dxfp); fprintf(dxfp,"diffuseColor %.2lf %.2lf %.2lf\n",
00258          (double)ColourList[0][0]/255.0,
00259          (double)ColourList[0][1]/255.0,
00260          (double)ColourList[0][2]/255.0);
00261      }
00262      else{
00263        Id(dxfp); fprintf(dxfp,"diffuseColor 1 1 1\n");
00264      }
00265      Id(dxfp); fprintf(dxfp,"shininess 0.5\n");
00266      Id(dxfp); fprintf(dxfp,"transparency 0\n");
00267      indent--;
00268      Id(dxfp); fprintf(dxfp,"}\n");  // material
00269 
00270      // mapping if present
00271      if(bMapped){
00272       Id(dxfp); fprintf(dxfp,"texture ImageTexture {\n"); indent++;
00273       Id(dxfp);
00274       if(bPrefix)fprintf(dxfp,"url \"%s",map_path);
00275       else       fprintf(dxfp,"url \"");
00276       if(nImaps > 0 && mapid < nImaps && iMap[mapid].S != NULL){
00277        fprintf(dxfp,"%s\"\n",FileOnly(iMap[mapid].S));
00278       }
00279       else{
00280        fprintf(dxfp,"unnamed.jpg\"\n");
00281       }
00282       indent--; Id(dxfp); fprintf(dxfp,"}\n");
00283      }
00284 
00285      indent--;
00286      Id(dxfp); fprintf(dxfp,"}\n");      // end appearance
00287 
00288      // write geometry header
00289      Id(dxfp); fprintf(dxfp,"geometry DEF SFX-%s-FACES IndexedFaceSet {\n",cl);  indent++;
00290      Id(dxfp); fprintf(dxfp,"ccw TRUE\n");
00291      Id(dxfp); fprintf(dxfp,"solid FALSE\n");
00292      // if there is a colour list
00293      if(nColourList > 1 && bColour){
00294        Id(dxfp); fprintf(dxfp,"colorPerVertex FALSE\n");
00295        Id(dxfp); fprintf(dxfp,"color Color { color [\n"); indent++;
00296        Id(dxfp);
00297        for(i=0;i<nColourList;i++){
00298          fprintf(dxfp,"%.2lf %.2lf %.2lf",
00299            (double)ColourList[i][0]/255.0,
00300            (double)ColourList[i][1]/255.0,
00301            (double)ColourList[i][2]/255.0);
00302          if(i == nColourList-1)fprintf(dxfp,"]\n");
00303          else{
00304            if((i+1)%3 == 0){
00305              fprintf(dxfp,",\n");
00306              Id(dxfp);
00307            }
00308            else fprintf(dxfp,", ");
00309          }
00310        }
00311        indent--;
00312        Id(dxfp); fprintf(dxfp,"}\n");
00313      }
00314 
00315      Id(dxfp); fprintf(dxfp,"coord DEF SFX-%s-COORD Coordinate { point [\n",cl);  indent++;
00316      Id(dxfp);
00317      i=0; vp=0; while(vp < Nvert){
00318        Vp=(MainVp+vp);
00319        if(Vp->status == INEDITOR){  // write vertices
00320          x=(float)(Vp->xyz[0]-lrulerx)/(float)ruler;
00321          y=(float)(Vp->xyz[1]-lrulery)/(float)ruler;
00322          z=(float)(Vp->xyz[2]-lrulerz)/(float)ruler;
00323 //         x=((double)(Vp->xyz[0]))/((double)UNIT);
00324 //         y=((double)(Vp->xyz[1]))/((double)UNIT);
00325 //         z=((double)(Vp->xyz[2]))/((double)UNIT);
00326          if(bNormals){
00327            NormalList[i][0]=0.0;
00328            NormalList[i][1]=0.0;
00329            NormalList[i][2]=0.0;
00330          }
00331          fprintf(dxfp,format,x,z,-y);
00332          Vp->id = i++;
00333          if(i == nv)fprintf(dxfp,"]\n");
00334          else{
00335            if(i%3 == 0){
00336              fprintf(dxfp,",\n");
00337              Id(dxfp);
00338            }
00339            else fprintf(dxfp,", ");
00340          }
00341        }
00342        else Vp->id = 65535;
00343        vp++;
00344      }
00345      indent--;
00346      Id(dxfp); fprintf(dxfp,"}\n");       // coordinates
00347 
00348      // write facet index information
00349      Id(dxfp); fprintf(dxfp,"coordIndex [\n");  indent++;
00350      Id(dxfp);
00351      fp=0; j=0; while(fp < Nface){  // write faces
00352        Fp=(MainFp+fp);
00353        if((MainVp+Fp->V[0])->status == INEDITOR &&
00354           (MainVp+Fp->V[1])->status == INEDITOR &&
00355           (MainVp+Fp->V[2])->status == INEDITOR){
00356          id1=(unsigned short)((MainVp+Fp->V[0])->id);
00357          id2=(unsigned short)((MainVp+Fp->V[1])->id);
00358          id3=(unsigned short)((MainVp+Fp->V[2])->id);
00359          fprintf(dxfp,"%ld, %ld, %ld, -1",id1,id2,id3);
00360          faceid[fp] = (long)(j++);
00361          if(j == nf)fprintf(dxfp,"]\n");
00362          else{
00363            if(j%3 == 0){
00364              fprintf(dxfp,",\n");
00365              Id(dxfp);
00366            }
00367            else fprintf(dxfp,", ");
00368          }
00369          if(bNormals){
00370            if(1){ //(Fp->attrib & 0x80) == 0x80){
00371              GetFaceVector(Fp,n);
00372              VECSUM(n,NormalList[id1],NormalList[id1])
00373              VECSUM(n,NormalList[id2],NormalList[id2])
00374              VECSUM(n,NormalList[id3],NormalList[id3])
00375            }
00376          }
00377        }
00378        fp++;
00379      }
00380      indent--;    // coordIndex
00381 
00382      if(bNormals){
00383        Id(dxfp); fprintf(dxfp,"normal Normal { vector [\n",cl);  indent++;
00384        Id(dxfp);
00385        i=0; vp=0; while(vp < Nvert){
00386          Vp=(MainVp+vp);
00387          if(Vp->status == INEDITOR){  // write vertices
00388            if(oNormalize(NormalList[i]) == FAIL){
00389              x=y=0.0; z=1.0;
00390            }
00391            else{
00392              x=NormalList[i][0];
00393              y=NormalList[i][1];
00394              z=NormalList[i][2];
00395            }
00396            fprintf(dxfp,format,x,z,-y);
00397            i++;
00398            if(i == nv)fprintf(dxfp,"]\n");
00399            else{
00400              if(i%3 == 0){
00401                fprintf(dxfp,",\n");
00402                Id(dxfp);
00403              }
00404              else fprintf(dxfp,", ");
00405            }
00406          }
00407          vp++;
00408        }
00409        indent--;
00410        Id(dxfp); fprintf(dxfp,"}\n");
00411 
00412        Id(dxfp); fprintf(dxfp,"normalPerVertex TRUE\n");
00413        Id(dxfp); fprintf(dxfp,"normalIndex [\n");  indent++;
00414        Id(dxfp);
00415        fp=0; j=0; while(fp < Nface){  // write faces
00416          Fp=(MainFp+fp);
00417          if((MainVp+Fp->V[0])->status == INEDITOR &&
00418             (MainVp+Fp->V[1])->status == INEDITOR &&
00419             (MainVp+Fp->V[2])->status == INEDITOR){
00420            if(! Fp->bSmooth){
00421              id1=id2=id3=(unsigned short)((MainVp+Fp->V[0])->id);
00422            }
00423            else{
00424              id1=(unsigned short)((MainVp+Fp->V[0])->id);
00425              id2=(unsigned short)((MainVp+Fp->V[1])->id);
00426              id3=(unsigned short)((MainVp+Fp->V[2])->id);
00427            }
00428            fprintf(dxfp,"%ld, %ld, %ld, -1",id1,id2,id3);
00429            j++;
00430            if(j == nf)fprintf(dxfp,"]\n");
00431            else{
00432              if(j%3 == 0){
00433                fprintf(dxfp,",\n");
00434                Id(dxfp);
00435              }
00436              else fprintf(dxfp,", ");
00437            }
00438          }
00439          fp++;
00440        }
00441        indent--;    // normalIndex
00442      }
00443 
00444      // write any color index information
00445      if(nColourList > 1 && bColour){
00446        Id(dxfp); fprintf(dxfp,"colorIndex[\n");  indent++;
00447        Id(dxfp);
00448        fp=0; j=0; while(fp < Nface){  // write faces
00449          Fp=(MainFp+fp);
00450          if((MainVp+Fp->V[0])->status == INEDITOR &&
00451             (MainVp+Fp->V[1])->status == INEDITOR &&
00452             (MainVp+Fp->V[2])->status == INEDITOR){
00453            //id1=(long)(Fp->pad);
00454            id1=(long)facemarker[fp];
00455            fprintf(dxfp,"%ld",id1);
00456            j++;
00457            if(j == nf)fprintf(dxfp,"]\n");
00458            else{
00459              if(j%9 == 0){
00460                fprintf(dxfp,",\n");
00461                Id(dxfp);
00462              }
00463              else fprintf(dxfp,", ");
00464            }
00465          }
00466          fp++;
00467        }
00468        indent--;
00469      }  // colour index
00470 
00471      if(bMapped){  // write any texture coordinates and indices
00472        Id(dxfp); fprintf(dxfp,"texCoord DEF SFX-%s-TEXCOORD TextureCoordinate { point [\n",cl);  indent++;
00473        Id(dxfp);
00474        i=0; vp=0; while(vp < Nvert){
00475          Vp=(MainVp+vp);
00476          if(Vp->status == INEDITOR){  // write vertices
00477            fprintf(dxfp,format1,(float)Vp->x,(float)Vp->y);
00478            Vp->id = i++;
00479            if(i == nv)fprintf(dxfp,"]\n");
00480            else{
00481              if(i%4 == 0){
00482                fprintf(dxfp,",\n");
00483                Id(dxfp);
00484              }
00485              else fprintf(dxfp,", ");
00486            }
00487          }
00488          else Vp->id = 65535;
00489          vp++;
00490        }
00491        indent--;
00492        Id(dxfp); fprintf(dxfp,"}\n");      // tex coord
00493        Id(dxfp); fprintf(dxfp,"texCoordIndex [\n");  indent++;
00494        Id(dxfp);
00495        fp=0; j=0; while(fp < Nface){  // write faces tex coordinate index
00496          Fp=(MainFp+fp);
00497          if((MainVp+Fp->V[0])->status == INEDITOR &&
00498             (MainVp+Fp->V[1])->status == INEDITOR &&
00499             (MainVp+Fp->V[2])->status == INEDITOR){
00500            id1=(unsigned short)((MainVp+Fp->V[0])->id);
00501            id2=(unsigned short)((MainVp+Fp->V[1])->id);
00502            id3=(unsigned short)((MainVp+Fp->V[2])->id);
00503            fprintf(dxfp,"%ld, %ld, %ld, -1",id1,id2,id3);
00504            faceid[fp] = (long)(j++);
00505            if(j == nf)fprintf(dxfp,"]\n");
00506            else{
00507              if(j%3 == 0){
00508                fprintf(dxfp,",\n");
00509                Id(dxfp);
00510              }
00511              else fprintf(dxfp,", ");
00512            }
00513          }
00514          fp++;
00515        }
00516        indent--;    // texcoordIndex
00517      }
00518 
00519      indent--;
00520      Id(dxfp); fprintf(dxfp,"}\n"); indent--;    // geometry
00521      // write root tailer
00522      Id(dxfp); fprintf(dxfp,"}\n"); indent--;    // shape
00523      Id(dxfp); fprintf(dxfp,"]\n"); indent--;    // children
00524      Id(dxfp); fprintf(dxfp,"}\n");              // transform
00525      if(bNormals && NormalList != NULL)X__Free(NormalList);
00526    }
00527    vp=0; while(vp < Nvert){ /* reset status */
00528      Vp=(MainVp+vp);
00529      if(Vp->status == INEDITOR)Vp->status=SELECTED;
00530      vp++;
00531    }
00532    if(ColourList != NULL)X__Free(ColourList);
00533    ColourList=NULL; nColourList=0;
00534    if(sp == NULL)break;
00535    sp=sp->last;
00536  }  /* end of for(;;) */
00537 
00538 }
00539 
00540 #if __WATCOMC__
00541 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00542 #else
00543 BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00544 #endif
00545   switch (dwReason) {
00546     case DLL_PROCESS_ATTACH: {
00547 #if __X__MIPS__
00548       if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00549 #endif
00550       hThisInstance=hDLL;
00551       break;
00552     }
00553     case DLL_PROCESS_DETACH:
00554 #if __X__MIPS__
00555       if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00556 #endif
00557       break;
00558   }
00559   return TRUE;
00560 }
00561 
00562 static PSTR FileInPath(PSTR pstrPath){
00563  PSTR pstr;
00564  pstr = pstrPath + strlen(pstrPath);
00565  while (pstr > pstrPath) {
00566      pstr = (AnsiPrev(pstrPath, pstr));
00567      if (*pstr == '\\' || *pstr == ':' || *pstr == '/') {
00568          pstr = (AnsiNext(pstr));
00569          break;
00570      }
00571  }
00572  return pstr;
00573 }
00574 
00575 static unsigned CALLBACK NameHookProc(HWND hwnd,UINT msg,
00576                               WPARAM wparam,LPARAM lparam){
00577  BOOL err;
00578  switch( msg ) {
00579    case WM_INITDIALOG:
00580      if(bPrefix)SendDlgItemMessage(hwnd,DLG_VRML_USEPREFIX,BM_SETCHECK,1,0);
00581      if(bIndent)SendDlgItemMessage(hwnd,DLG_VRML_INDENTATION,BM_SETCHECK,1,0);
00582      if(bNormals)SendDlgItemMessage(hwnd,DLG_VRML_NORMALS,BM_SETCHECK,1,0);
00583      SetDlgItemInt(hwnd,DLG_VRML_DIGITS,digits,FALSE);
00584      SetDlgItemText(hwnd,DLG_VRML_PREFIX,map_path);
00585 //     CentreDlgOnS(GetParent(hwnd));
00586      return FALSE;
00587    case WM_COMMAND:
00588      switch(LOWORD(wparam)){
00589        case IDOK:{
00590           goto JUMPHERE;
00591          }
00592          break;
00593        case  DLG_VRML_HELP:{
00594             char lname[256],res_str1[256],res_str2[256];
00595             GetModuleFileName(hThisInstance,lname,225);
00596             *FileInPath(lname) = '\0';
00597             strcat(lname,"help\\");
00598             strcpy(res_str1,lname);
00599 #if !__HELP_WS__
00600             strcat(res_str1,"ani_help.chm");
00601             ShellExecute(hwnd,NULL,res_str1,
00602                          NULL,lname,SW_SHOW);
00603 #else
00604             {
00605              HH_WINTYPE hhwin;
00606              memset(&hhwin,0,sizeof(HH_WINTYPE));
00607              hhwin.cbStruct=sizeof(HH_WINTYPE);
00608              hhwin.nShowState=SW_SHOW;
00609              hhwin.pszType="MyHelp";
00610              LoadString(hThisInstance,IDX_VRML_STRING2,lname,255);
00611              hhwin.pszCaption=lname;
00612              hhwin.fsValidMembers = HHWIN_PARAM_SHOWSTATE |
00613                                     HHWIN_PARAM_PROPERTIES|
00614                                     HHWIN_PARAM_CUR_TAB|
00615                                     HHWIN_PARAM_EXPANSION|
00616                                     HHWIN_PARAM_RECT;
00617              hhwin.rcWindowPos.top=0;
00618              hhwin.rcWindowPos.left=0;
00619              hhwin.rcWindowPos.right=500;
00620              hhwin.rcWindowPos.bottom=500;
00621              hhwin.nShowState=SW_SHOW;
00622              strcat(res_str1,"ani_help.chm");
00623              hhwin.fNotExpanded = TRUE;
00624              hhwin.fsWinProperties = HHWIN_PROP_TRI_PANE|HHWIN_PROP_TAB_SEARCH;
00625              hhwin.curNavType=HHWIN_NAVTYPE_TOC;
00626              strcpy(res_str2,res_str1);
00627              strcat(res_str2,"::toc.hhc");
00628              hhwin.pszToc=res_str2;
00629              strcat(res_str1,"::/vrml_exporter.htm");
00630              HtmlHelp(hwnd,NULL,HH_SET_WIN_TYPE,(DWORD)&hhwin);
00631              HtmlHelp(hwnd,">MyHelp",HH_DISPLAY_TOPIC,(DWORD)res_str1);
00632            }
00633 #endif
00634          }
00635          break;
00636        default: break;
00637      }
00638      break;
00639    case WM_NOTIFY:{
00640        LPOFNOTIFY lp=(LPOFNOTIFY)lparam;
00641        if(lp->hdr.code == CDN_FILEOK){
00642          JUMPHERE:
00643          if(SendDlgItemMessage(hwnd,DLG_VRML_USEPREFIX,BM_GETCHECK,0,0))
00644               bPrefix=TRUE;
00645          else bPrefix=FALSE;
00646          if(SendDlgItemMessage(hwnd,DLG_VRML_INDENTATION,BM_GETCHECK,0,0))
00647               bIndent=TRUE;
00648          else bIndent=FALSE;
00649          if(SendDlgItemMessage(hwnd,DLG_VRML_NORMALS,BM_GETCHECK,0,0))
00650               bNormals=TRUE;
00651          else bNormals=FALSE;
00652          digits=GetDlgItemInt(hwnd,DLG_VRML_DIGITS,&err,FALSE);
00653          if(digits < 0)digits=0;
00654          GetDlgItemText(hwnd,DLG_VRML_PREFIX,map_path,255);
00655        }
00656      }
00657      break;
00658    default: break;
00659  }
00660  return FALSE;
00661 }
00662 
00663 static BOOL LocalSelectFileName(char *szfile, char *szfilter,
00664                            HWND parent, HINSTANCE hInst){
00665  int i;
00666  OPENFILENAME ofn;
00667  char szFilter[80],title[256];
00668  DWORD version;
00669  strcpy(szFilter,szfilter);
00670  i=0; while(szFilter[i] != '\0'){
00671    if(szFilter[i] == '|')szFilter[i]='\0'; i++;
00672  }
00673  memset(&ofn,0,sizeof(OPENFILENAME));
00674  ofn.lStructSize=sizeof(OPENFILENAME);
00675  ofn.hwndOwner=parent;
00676  ofn.lpstrFilter=szFilter;
00677  ofn.nFilterIndex=0;
00678  ofn.lpstrFile=szfile;
00679  ofn.nMaxFile=255;
00680  ofn.lpstrFileTitle=NULL;
00681  ofn.nMaxFileTitle=0;
00682  ofn.lpstrInitialDir=NULL;
00683  LoadString(hThisInstance,IDX_VRML_STRING1,title,255);
00684  ofn.lpstrTitle=title;
00685  ofn.hInstance=hInst;
00686  ofn.lpfnHook=NameHookProc;
00687  version=GetVersion();
00688  ofn.Flags=OFN_HIDEREADONLY|OFN_PATHMUSTEXIST|
00689            OFN_ENABLEHOOK|OFN_ENABLETEMPLATE|OFN_NONETWORKBUTTON;
00690  if(LOBYTE(LOWORD(version)) >= 4){
00691    ofn.lpTemplateName=MAKEINTRESOURCE(DLG_VRML);
00692    ofn.Flags |= OFN_EXPLORER;
00693  }
00694  else{
00695    ofn.lpTemplateName=MAKEINTRESOURCE(DLG_OLDVRML);
00696  }
00697  return GetOpenFileName(&ofn);
00698 }
00699 
00700 long _Export
00701  (HWND parent_window, char *filename,X__STRUCTURE *lpevi){
00702  char localfile[256];
00703  FILE *dxfp;
00704  lpEVI=lpevi;
00705  ReadDataFromRegistry("SOFTWARE\\OPENFX\\VRML");
00706  strcpy(localfile,globalfile);
00707  if(filename == NULL){
00708    if(!LocalSelectFileName(localfile,
00709                            "VRML files (*.WRL)|*.wrl",
00710                            parent_window,hThisInstance))return 0;
00711 
00712  }
00713  else strcpy(localfile,filename);
00714  strcpy(globalfile,localfile);
00715  WriteDataToRegistry("SOFTWARE\\OPENFX\\VRML");
00716  AppendFileExtension(localfile,".wrl");
00717  if(NvertSelect == 0 || Nface == 0){
00718    MessageBox(parent_window,"Too few vertices or faces selected",NULL,MB_OK);
00719    return 0;
00720  }
00721  lrulerx= (*(lpEVI->orulerx));
00722  lrulery= (*(lpEVI->orulery));
00723  lrulerz= (*(lpEVI->orulerz));
00724  ruler  = (*(lpEVI->ruler));
00725  if((dxfp=fopen(localfile,"w")) != NULL){
00726    if((faceid=(long *)X__Malloc(Nface*sizeof(long))) != NULL){
00727      if((facemarker=(long *)X__Malloc(Nface*sizeof(long))) != NULL){
00728        fprintf(dxfp,"#VRML V2.0 utf8\n\n# Produced by OpenFX 2000\n\n");
00729        CreateVRMLfile(dxfp);
00730        X__Free(facemarker);
00731      }
00732      else MessageBox(NULL,"No memory",NULL,MB_OK);
00733      X__Free(faceid);
00734    }
00735    else MessageBox(NULL,"No memory",NULL,MB_OK);
00736    fclose(dxfp);
00737  }
00738  else{
00739    MessageBox(parent_window,"File open Error",NULL,MB_OK);
00740  }
00741  if(mapVRMLlist != NULL)X__Free(mapVRMLlist);
00742  return 1;
00743 }
00744 
00745 BOOL _Xmodeler
00746  (HWND parent_window,HWND info_window,X__STRUCTURE *lpevi){
00747  return _Export(parent_window,NULL,lpevi);
00748 }
00749 

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