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 public:
00060 virtual const char* className() { return "vl::LoadWriter3DS"; }
00061 LoadWriter3DS(): ResourceLoadWriter("|3ds|", "|3ds|") {}
00062
00063 ref<ResourceDatabase> loadResource(const String& path) const
00064 {
00065 return load3DS(path);
00066 }
00067
00068 ref<ResourceDatabase> loadResource(VirtualFile* file) const
00069 {
00070 return load3DS(file);
00071 }
00072
00074 bool writeResource(const String& , ResourceDatabase* ) const
00075 {
00076 return false;
00077 }
00078
00080 bool writeResource(VirtualFile* , ResourceDatabase* ) const
00081 {
00082 return false;
00083 }
00084 };
00085
00086
00087
00091 class A3DSTexture
00092 {
00093 public:
00094 A3DSTexture(): mUScale(1), mVScale(1), mUOffset(1), mVOffset(1), mRotation(0),
00095 mOpt_tile(true), mOpt_decal(false), mOpt_mirror(false), mOpt_negative(false),
00096 mOpt_summed_area(false), mOpt_use_alpha(false), mOpt_one_channel_tint(false),
00097 mOpt_ignore_alpha(false), mOpt_rgb_tint(false) {}
00098
00099 String mFileName;
00100 float mUScale, mVScale, mUOffset, mVOffset, mRotation;
00101 bool mOpt_tile;
00102 bool mOpt_decal;
00103 bool mOpt_mirror;
00104 bool mOpt_negative;
00105 bool mOpt_summed_area;
00106 bool mOpt_use_alpha;
00107 bool mOpt_one_channel_tint;
00108 bool mOpt_ignore_alpha;
00109 bool mOpt_rgb_tint;
00110 };
00111
00115 class A3DSMaterial
00116 {
00117 public:
00118 A3DSMaterial(): mShininess(0), mShininessStrength(0), mTransparency(0), mDoubleSided(false) {}
00119
00120 String mMaterialName;
00121 fvec3 mAmbient, mDiffuse, mSpecular;
00122 float mShininess, mShininessStrength;
00123 float mTransparency;
00124 bool mDoubleSided;
00125 A3DSTexture mTexture1;
00126 A3DSTexture mTexture2;
00127 };
00128
00132 class A3DSTriFace
00133 {
00134 public:
00135 A3DSTriFace(): mA(0), mB(0), mC(0), mFlags(0), mSmoothingGroup(0), mMaterialIndex(-1) {}
00136
00137 unsigned short mA,mB,mC,mFlags;
00138 unsigned int mSmoothingGroup;
00139 int mMaterialIndex;
00140 };
00141
00145 class A3DSMaterialFaceMapping
00146 {
00147 public:
00148 String mMaterialName;
00149 std::vector<unsigned short> mMappedFace;
00150 };
00151
00155 class A3DSVertex
00156 {
00157 public:
00158 A3DSVertex(): mSmoothingGroup(0), mIndex(-1) {}
00159 bool operator<(const A3DSVertex& other) const
00160 {
00161 if (mPos.x() != other.mPos.x())
00162 return mPos.x() < other.mPos.x();
00163 else
00164 if (mPos.y() != other.mPos.y())
00165 return mPos.y() < other.mPos.y();
00166 else
00167 if (mPos.z() != other.mPos.z())
00168 return mPos.z() < other.mPos.z();
00169 else
00170 if (mUV.s() != other.mUV.s())
00171 return mUV.s() < other.mUV.s();
00172 else
00173 if (mUV.t() != other.mUV.t())
00174 return mUV.t() < other.mUV.t();
00175 else
00176 return mSmoothingGroup < other.mSmoothingGroup;
00177 }
00178
00179 fvec3 mPos;
00180 fvec2 mUV;
00181 unsigned int mSmoothingGroup;
00182 int mIndex;
00183 };
00184
00188 class A3DSObject
00189 {
00190 public:
00191 String mObjName;
00192 std::vector<A3DSVertex> mVertices;
00193 std::vector<A3DSTriFace> mFaceList;
00194 std::vector<A3DSMaterialFaceMapping> mMatFaceMap;
00195 fmat4 mCoordSystem;
00196 };
00197
00201 class VLGRAPHICS_EXPORT A3DSLoader
00202 {
00203 public:
00204 A3DSLoader();
00205 bool parse3DS(VirtualFile* file);
00206
00207 protected:
00208 fvec3 readVec3();
00209 fvec3 readColByte3();
00210 fvec3 readColFloat3();
00211 String readLine();
00212 float readWordPercent();
00213 float readFloatPercent();
00214 void readChunk();
00215 bool skipChunk();
00216 void read_3D_EDITOR_CHUNK();
00217 fvec3 readColChunk();
00218 float readPercentChunk();
00219 void read_MATERIAL_BLOCK();
00220 A3DSTexture readMapChunk();
00221 void read_OBJECT_BLOCK();
00222 void read_TRIANGULAR_MESH();
00223
00224 public:
00225 std::vector<A3DSObject> mObjects;
00226 std::vector<A3DSMaterial> mMaterials;
00227
00228 protected:
00229 VirtualFile *mInputFile;
00230 unsigned short mChunkId;
00231 unsigned int mChunkLen;
00232 bool mCorrupted;
00233 };
00234
00235 }
00236
00237 #endif