Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
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
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& , ResourceDatabase* ) const
00076 {
00077 return false;
00078 }
00079
00081 bool writeResource(VirtualFile* , ResourceDatabase* ) const
00082 {
00083 return false;
00084 }
00085 };
00086
00087
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;
00107 bool mOpt_use_alpha;
00108 bool mOpt_one_channel_tint;
00109 bool mOpt_ignore_alpha;
00110 bool mOpt_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