00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <wx/stopwatch.h>
00013 #include "ioobj.h"
00014 #include "objparser.h"
00015 #include "objwriter.h"
00016
00017 using namespace VRUT;
00018
00019
00020 IOObjModule::IOObjModule(const MODULE_ID & _id, const wxString & _name, EventHandler * msgSink)
00021 : IOModule(_id, _name, 0, msgSink)
00022 {
00023 }
00024
00025
00026 IOObjModule::~IOObjModule()
00027 {
00028 }
00029
00030
00031 wxString IOObjModule::GetDesc() const
00032 {
00033 return wxT("Import and export OBJ files");
00034 }
00035
00036
00037 wxString IOObjModule::GetSupportedExts() const
00038 {
00039 return wxT("OBJ");
00040 }
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 bool IOObjModule::ImportScene(const wxString & fname, SCENE_ID _sceneID, const wxString & rootUid)
00057 {
00058 wxStopWatch sw;
00059 bool ret = false;
00060 wxInputStream * is = GetInputStream(fname);
00061 if (is)
00062 {
00063 OBJParser objParser(is, _sceneID, fname, this);
00064 ret = objParser.Parse(rootUid);
00065 delete is;
00066 }
00067 LOG(wxString::Format(wxT("<IOObjModule>Scene parsed in %.3f secs, ID %i"), 0.001f * sw.Time(), _sceneID));
00068 wxCommandEvent ev = Event::GET_EVT_IO_SCENE_IMPORT_DONE(_sceneID);
00069 PostToKernel(ev);
00070 return ret;
00071 }
00072
00073
00074 bool IOObjModule::ExportScene(const wxString & fname, const Scene * scene)
00075 {
00076 wxOutputStream * sceneStream = new wxFileOutputStream(fname);
00077 if (sceneStream && sceneStream->IsOk())
00078 {
00079 wxBufferedOutputStream *sceneStream2=new wxBufferedOutputStream(*sceneStream);
00080 OBJWriter objWriter(sceneStream2, scene);
00081 objWriter.Write();
00082 sceneStream2->Sync();
00083 SAFE_DELETE(sceneStream);
00084 return true;
00085 }
00086 SAFE_DELETE(sceneStream);
00087 return false;
00088 }
00089