Panda3D
|
00001 // Filename: vrmlTrans.cxx 00002 // Created by: drose (01Oct04) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "vrmlTrans.h" 00016 #include "parse_vrml.h" 00017 #include "pystub.h" 00018 00019 //////////////////////////////////////////////////////////////////// 00020 // Function: VRMLTrans::Constructor 00021 // Access: Public 00022 // Description: 00023 //////////////////////////////////////////////////////////////////// 00024 VRMLTrans:: 00025 VRMLTrans() : 00026 WithOutputFile(true, true, false) 00027 { 00028 // Indicate the extension name we expect the user to supply for 00029 // output files. 00030 _preferred_extension = ".wrl"; 00031 00032 set_program_description 00033 ("This program reads a VRML 2.0 file (.wrl) and writes an " 00034 "essentially equivalent .wrl file. It is primarily useful for " 00035 "debugging the VRML parser that is part of the Pandatool library."); 00036 00037 clear_runlines(); 00038 add_runline("[opts] input.wrl > output.wrl"); 00039 add_runline("[opts] input.wrl output.wrl"); 00040 add_runline("[opts] -o output.wrl input.wrl"); 00041 00042 add_option 00043 ("o", "filename", 0, 00044 "Specify the filename to which the resulting .wrl file will be written. " 00045 "If this option is omitted, the last parameter name is taken to be the " 00046 "name of the output file.", 00047 &VRMLTrans::dispatch_filename, &_got_output_filename, &_output_filename); 00048 } 00049 00050 00051 //////////////////////////////////////////////////////////////////// 00052 // Function: VRMLTrans::run 00053 // Access: Public 00054 // Description: 00055 //////////////////////////////////////////////////////////////////// 00056 void VRMLTrans:: 00057 run() { 00058 nout << "Reading " << _input_filename << "\n"; 00059 00060 VrmlScene *scene = parse_vrml(_input_filename); 00061 if (scene == (VrmlScene *)NULL) { 00062 nout << "Unable to read.\n"; 00063 exit(1); 00064 } 00065 00066 get_output() << *scene << "\n"; 00067 } 00068 00069 00070 //////////////////////////////////////////////////////////////////// 00071 // Function: VRMLTrans::handle_args 00072 // Access: Protected, Virtual 00073 // Description: 00074 //////////////////////////////////////////////////////////////////// 00075 bool VRMLTrans:: 00076 handle_args(ProgramBase::Args &args) { 00077 if (!check_last_arg(args, 1)) { 00078 return false; 00079 } 00080 00081 if (args.empty()) { 00082 nout << "You must specify the .wrl file to read on the command line.\n"; 00083 return false; 00084 00085 } else if (args.size() != 1) { 00086 nout << "You must specify only one .wrl file to read on the command line.\n"; 00087 return false; 00088 } 00089 00090 _input_filename = args[0]; 00091 00092 return true; 00093 } 00094 00095 00096 int main(int argc, char *argv[]) { 00097 // A call to pystub() to force libpystub.so to be linked in. 00098 pystub(); 00099 00100 VRMLTrans prog; 00101 prog.parse_command_line(argc, argv); 00102 prog.run(); 00103 return 0; 00104 }