Main Page Class Hierarchy Compound List File List Compound Members File Members

SceneConvert.cc

Go to the documentation of this file.
00001 /*
00002 File: SceneConvert.cc
00003 
00004 Function: command-line program to convert scene files
00005 
00006 Author: Andrew Willmott
00007 
00008 Notes: 
00009 */
00010 
00011 #include <stdlib.h>
00012 
00013 #include "cl/ArgParse.h"
00014 #include "gcl/SceneLang.h"
00015 #include "gcl/Readers.h"
00016 #include "gcl/Writers.h"
00017 #include "gcl/MRModel.h"
00018 #include "gcl/Avars.h"
00019 
00020  static StrConstArray gAvarNames;
00021  static ScalarList gAvarVals;
00022 
00023  static Int avarArg(Int argc, Char **argv)
00024 {
00025 Int i;
00026 GCLReal val;
00027 
00028 if (argc % 2 == 1)
00029 {
00030 cerr << "Error: wrong number of avar arguments." << endl;
00031 exit(1);
00032 }
00033 
00034 for (i = 0; i < argc; i += 2)
00035 {
00036 gAvarNames.Append(argv[i]);
00037 val = atof(argv[i + 1]);
00038 gAvarVals.Append(val);
00039 }
00040 
00041 return(0);
00042 }
00043 
00044  Void SetAvars(scScenePtr scene)
00045 {
00046 Int i;
00047 CreateAvarList makeAvarList;
00048 
00049 for (i = 0; i < gAvarNames.NumItems(); i++)
00050 cout << "avar " << gAvarNames[i] << " = " << gAvarVals[i] << endl;
00051 
00052 scene->ApplyAction(makeAvarList);
00053 #ifdef DEBUG
00054 cout << "scene avars:" << endl;
00055 for (i = 0; i < makeAvarList.avarList->NumItems(); i++)
00056 cout << makeAvarList.avarList->Item(i).name << " = " 
00057 << makeAvarList.avarList->Item(i).value << endl;
00058 #endif
00059 
00060 scene->Set(makeAvarList.avarList);
00061 
00062 for (i = 0; i < gAvarNames.NumItems(); i++)
00063 if (!makeAvarList.avarList->SetAvar(gAvarNames[i], gAvarVals[i]))
00064 cerr << "No such avar in scene: " << gAvarNames[i] 
00065 << " (ignoring) " << endl;
00066 }
00067 
00068  static Void PrintSceneInfo(scScenePtr scene)
00069 {
00070 FindDecInfo decInfo;
00071 
00072 scene->Decimate(decInfo, DecTris);
00073 
00074 cout << "polygons " << decInfo.numPolys << endl;
00075 cout << "triangles " << decInfo.numTris << endl;
00076 }
00077 
00078  Int main(Int argc, Char *argv[])
00079 {
00080 FileName inPath, outPath;
00081 Char *file1 = 0, *file2 = 0;
00082 Int formats, noRescale, writeCMB;
00083 scScenePtr scene;
00084 Double meshComp;
00085 ArgForm *arg_format;
00086 
00087 // command-line options
00088 
00089 meshComp = 1.0;
00090 
00091 arg_format = arg_to_form(0,
00092 "", "Usage: slconv [options]",
00093 
00094 "[%S]", &file1, "Input scene file",
00095 "[%S]", &file2, "Output scene file",
00096 "-set", ARG_SUBR(avarArg), "Set avar, e.g. -set light 0.5 height 0.2",
00097 "-meshComp %F", &meshComp, "Set mesh complexity for MR models",
00098 "-writeMRB", ARG_FLAG(&writeCMB), "Write multires model(s) in binary format",
00099 "-noRescale", ARG_FLAG(&noRescale), "Don't rescale the scene",
00100 "-formats", ARG_FLAG(&formats), "List supported file formats",
00101 0); 
00102 
00103 if (arg_parse_argv(argc, argv, arg_format) < 0)
00104 return(1);
00105 
00106 if (formats)
00107 {
00108 cout << "Input formats:" << endl;
00109 SceneReader::PrintSupportedFormats(cout);
00110 cout << "Output formats:" << endl;
00111 SceneWriter::PrintSupportedFormats(cout);
00112 return(0);
00113 }
00114 
00115 if (!file1)
00116 {
00117 arg_form_print(arg_format);
00118 return(0);
00119 }
00120 
00121 inPath.SetPath(file1);
00122 if (file2)
00123 outPath.SetPath(file2);
00124 
00125 // normalise or not? 
00126 
00127 slInit();
00128 scMRModel::SetComplexity(meshComp);
00129 scene = SceneReader::Load(inPath);
00130 if (!scene)
00131 return(1);
00132 
00133 if (!noRescale)
00134 scene->Normalise();
00135 
00136 SetAvars(scene);
00137 
00138 if (writeCMB)
00139 {
00140 // write out models as binary
00141 MRModelsFinder models;
00142 Int i;
00143 
00144 scene->ApplyAction(models);
00145 
00146 for (i = 0; i < models.NumModels(); i++)
00147 {
00148 cout << "writing model " << models.Model(i)->modelFile.GetFile() << endl;
00149 models.Model(i)->WriteBinary();
00150 }
00151 }
00152 else
00153 if (!file2)
00154 // dump information
00155 PrintSceneInfo(scene); 
00156 else
00157 // write out scene
00158 SceneWriter::Save(scene, outPath);
00159 
00160 return(0);
00161 }

Generated at Sat Aug 5 00:17:03 2000 for Graphics Class Library by doxygen 1.1.0 written by Dimitri van Heesch, © 1997-2000

AltStyle によって変換されたページ (->オリジナル) /