00001 /* 00002 Sheep - A Rigid Body Dynamics Engine 00003 Copyright (C) 2001-2004 Francois Beaune 00004 Contact: http://toxicengine.sourceforge.net/ 00005 00006 This file is part of Sheep. 00007 00008 Sheep is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 2 of the License, or 00011 (at your option) any later version. 00012 00013 Sheep is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with Sheep; if not, write to the Free Software 00020 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 */ 00022 00023 #ifndef SHEEP_MESHIO_TRILOADER_H 00024 #define SHEEP_MESHIO_TRILOADER_H 00025 00026 #include "common/misc/binarystream.h" 00027 #include "imeshbuilder.h" 00028 #include "imeshloader.h" 00029 00030 #include "png.h" 00031 00032 #include <map> 00033 #include <string> 00034 00035 namespace sheep { 00036 00037 class ProgressMonitor; 00038 00039 class TRILoader : public IMeshLoader { 00040 public: 00041 struct ExtendedLoadingException : public LoadingException { 00042 ExtendedLoadingException(int offset) : 00043 m_offset(offset) {} 00044 00045 const int m_offset; //!< Offset in the file where the read error occurred, expressed in bytes (first byte is at offset 0). 00046 }; 00047 00048 //! File structure is broken. 00049 struct ReadingException : public ExtendedLoadingException { 00050 ReadingException(int offset) : ExtendedLoadingException(offset) {} 00051 }; 00052 00053 TRILoader(); 00054 00055 virtual void Load( 00056 const std::string &filename, 00057 IMeshBuilder &builder, 00058 int option_mask = DEFAULT_CONFIGURATION_BIT, 00059 ProgressMonitor *progmon = 0 00060 ) throw(LoadingException); 00061 00062 private: 00063 std::string m_path; 00064 std::string m_texture_filename; 00065 00066 IMeshBuilder::IGeometryBuilder *m_geombuilder; 00067 IMeshBuilder::IMaterialBuilder *m_matbuilder; 00068 00069 int m_option_mask; 00070 00071 ProgressMonitor *m_progmon; //!< May be 0. 00072 00073 BinaryStream m_stream; 00074 int m_offset; 00075 00076 std::map<int, IMeshBuilder::FeatureId> m_vertex_id; 00077 00078 png_structp m_png_ptr; 00079 png_infop m_info_ptr; 00080 png_infop m_end_info; 00081 00082 int m_texture_width; 00083 int m_texture_height; 00084 00085 char *m_comment_ptr; //!< Pointer to the comment string containing texture coordinates. 00086 00087 void read_error(); 00088 00089 void open_geometry_file(const std::string &filename); 00090 void read_geometry_file(); 00091 void close_geometry_file(); 00092 00093 void open_texture_file(const std::string &filename); 00094 void close_texture_file(); 00095 }; 00096 00097 #include "triloader.inl" 00098 00099 } 00100 00101 #endif // !SHEEP_MESHIO_TRILOADER_H
1.3.6