Visualization Library v1.0.3A lightweight C++ OpenGL middleware for 2D/3D graphics |
[Download] [Tutorials] [All Classes] [Grouped Classes] |
00001 /**************************************************************************************/ 00002 /* */ 00003 /* Visualization Library */ 00004 /* http://visualizationlibrary.org */ 00005 /* */ 00006 /* Copyright (c) 2005-2010, Michele Bosi */ 00007 /* All rights reserved. */ 00008 /* */ 00009 /* Redistribution and use in source and binary forms, with or without modification, */ 00010 /* are permitted provided that the following conditions are met: */ 00011 /* */ 00012 /* - Redistributions of source code must retain the above copyright notice, this */ 00013 /* list of conditions and the following disclaimer. */ 00014 /* */ 00015 /* - Redistributions in binary form must reproduce the above copyright notice, this */ 00016 /* list of conditions and the following disclaimer in the documentation and/or */ 00017 /* other materials provided with the distribution. */ 00018 /* */ 00019 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */ 00020 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 00021 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */ 00022 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */ 00023 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */ 00024 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 00025 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */ 00026 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ 00027 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 00028 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 00029 /* */ 00030 /**************************************************************************************/ 00031 00032 #if !defined(Load3DS_INCLUDE_ONCE) 00033 #define Load3DS_INCLUDE_ONCE 00034 00035 #include <vlGraphics/Actor.hpp> 00036 #include <vlCore/ResourceLoadWriter.hpp> 00037 #include <vlCore/ResourceDatabase.hpp> 00038 #include <vlCore/String.hpp> 00039 #include <vector> 00040 00041 namespace vl 00042 { 00043 class VirtualFile; 00044 } 00045 00046 namespace vl 00047 { 00048 //----------------------------------------------------------------------------- 00049 VLGRAPHICS_EXPORT ref<ResourceDatabase> load3DS(VirtualFile* file); 00050 VLGRAPHICS_EXPORT ref<ResourceDatabase> load3DS(const String& path); 00051 //----------------------------------------------------------------------------- 00052 // LoadWriter3DS 00053 //----------------------------------------------------------------------------- 00057 class LoadWriter3DS: public ResourceLoadWriter 00058 { 00059 VL_INSTRUMENT_CLASS(vl::LoadWriter3DS, ResourceLoadWriter) 00060 00061 public: 00062 LoadWriter3DS(): ResourceLoadWriter("|3ds|", "|3ds|") {} 00063 00064 ref<ResourceDatabase> loadResource(const String& path) const 00065 { 00066 return load3DS(path); 00067 } 00068 00069 ref<ResourceDatabase> loadResource(VirtualFile* file) const 00070 { 00071 return load3DS(file); 00072 } 00073 00075 bool writeResource(const String& /*path*/, ResourceDatabase* /*resource*/) const 00076 { 00077 return false; 00078 } 00079 00081 bool writeResource(VirtualFile* /*file*/, ResourceDatabase* /*resource*/) const 00082 { 00083 return false; 00084 } 00085 }; 00086 //----------------------------------------------------------------------------- 00087 // A3DSLoader 00088 //----------------------------------------------------------------------------- 00092 class A3DSTexture 00093 { 00094 public: 00095 A3DSTexture(): mUScale(1), mVScale(1), mUOffset(1), mVOffset(1), mRotation(0), 00096 mOpt_tile(true), mOpt_decal(false), mOpt_mirror(false), mOpt_negative(false), 00097 mOpt_summed_area(false), mOpt_use_alpha(false), mOpt_one_channel_tint(false), 00098 mOpt_ignore_alpha(false), mOpt_rgb_tint(false) {} 00099 00100 String mFileName; 00101 float mUScale, mVScale, mUOffset, mVOffset, mRotation; 00102 bool mOpt_tile; 00103 bool mOpt_decal; 00104 bool mOpt_mirror; 00105 bool mOpt_negative; 00106 bool mOpt_summed_area; // summed area map filtering (instead of pyramidal) 00107 bool mOpt_use_alpha; // use alpha (toggles RGBluma/alpha. For masks RGB means RGBluma) 00108 bool mOpt_one_channel_tint; // there is a one channel tint (either RGBluma or alpha) 00109 bool mOpt_ignore_alpha; // ignore alpha (take RGBluma even if an alpha exists (?)) 00110 bool mOpt_rgb_tint; // there is a three channel tint (RGB tint) 00111 }; 00112 //----------------------------------------------------------------------------- 00116 class A3DSMaterial 00117 { 00118 public: 00119 A3DSMaterial(): mShininess(0), mShininessStrength(0), mTransparency(0), mDoubleSided(false) {} 00120 00121 String mMaterialName; 00122 fvec3 mAmbient, mDiffuse, mSpecular; 00123 float mShininess, mShininessStrength; 00124 float mTransparency; 00125 bool mDoubleSided; 00126 A3DSTexture mTexture1; 00127 A3DSTexture mTexture2; 00128 }; 00129 //----------------------------------------------------------------------------- 00133 class A3DSTriFace 00134 { 00135 public: 00136 A3DSTriFace(): mA(0), mB(0), mC(0), mFlags(0), mSmoothingGroup(0), mMaterialIndex(-1) {} 00137 00138 unsigned short mA,mB,mC,mFlags; 00139 unsigned int mSmoothingGroup; 00140 int mMaterialIndex; 00141 }; 00142 //----------------------------------------------------------------------------- 00146 class A3DSMaterialFaceMapping 00147 { 00148 public: 00149 String mMaterialName; 00150 std::vector<unsigned short> mMappedFace; 00151 }; 00152 //----------------------------------------------------------------------------- 00156 class A3DSVertex 00157 { 00158 public: 00159 A3DSVertex(): mSmoothingGroup(0), mIndex(-1) {} 00160 bool operator<(const A3DSVertex& other) const 00161 { 00162 if (mPos.x() != other.mPos.x()) 00163 return mPos.x() < other.mPos.x(); 00164 else 00165 if (mPos.y() != other.mPos.y()) 00166 return mPos.y() < other.mPos.y(); 00167 else 00168 if (mPos.z() != other.mPos.z()) 00169 return mPos.z() < other.mPos.z(); 00170 else 00171 if (mUV.s() != other.mUV.s()) 00172 return mUV.s() < other.mUV.s(); 00173 else 00174 if (mUV.t() != other.mUV.t()) 00175 return mUV.t() < other.mUV.t(); 00176 else 00177 return mSmoothingGroup < other.mSmoothingGroup; 00178 } 00179 00180 fvec3 mPos; 00181 fvec2 mUV; 00182 unsigned int mSmoothingGroup; 00183 int mIndex; 00184 }; 00185 //----------------------------------------------------------------------------- 00189 class A3DSObject 00190 { 00191 public: 00192 String mObjName; 00193 std::vector<A3DSVertex> mVertices; 00194 std::vector<A3DSTriFace> mFaceList; 00195 std::vector<A3DSMaterialFaceMapping> mMatFaceMap; 00196 fmat4 mCoordSystem; 00197 }; 00198 //----------------------------------------------------------------------------- 00202 class VLGRAPHICS_EXPORT A3DSLoader 00203 { 00204 public: 00205 A3DSLoader(); 00206 bool parse3DS(VirtualFile* file); 00207 00208 protected: 00209 fvec3 readVec3(); 00210 fvec3 readColByte3(); 00211 fvec3 readColFloat3(); 00212 String readLine(); 00213 float readWordPercent(); 00214 float readFloatPercent(); 00215 void readChunk(); 00216 bool skipChunk(); 00217 void read_3D_EDITOR_CHUNK(); 00218 fvec3 readColChunk(); 00219 float readPercentChunk(); 00220 void read_MATERIAL_BLOCK(); 00221 A3DSTexture readMapChunk(); 00222 void read_OBJECT_BLOCK(); 00223 void read_TRIANGULAR_MESH(); 00224 00225 public: 00226 std::vector<A3DSObject> mObjects; 00227 std::vector<A3DSMaterial> mMaterials; 00228 00229 protected: 00230 VirtualFile *mInputFile; 00231 unsigned short mChunkId; 00232 unsigned int mChunkLen; 00233 bool mCorrupted; 00234 }; 00235 //----------------------------------------------------------------------------- 00236 } 00237 00238 #endif