Visualization Library 2.0.0-b3

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
io3DS.hpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2017, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
32 #if !defined(Load3DS_INCLUDE_ONCE)
33 #define Load3DS_INCLUDE_ONCE
34 
35 #include <vlGraphics/Actor.hpp>
38 #include <vlCore/String.hpp>
39 #include <vector>
40 
41 namespace vl
42 {
43  class VirtualFile;
44 }
45 
46 namespace vl
47 {
48 //-----------------------------------------------------------------------------
49  VLGRAPHICS_EXPORT ref<ResourceDatabase> load3DS(VirtualFile* file);
50  VLGRAPHICS_EXPORT ref<ResourceDatabase> load3DS(const String& path);
51 //-----------------------------------------------------------------------------
52 // LoadWriter3DS
53 //-----------------------------------------------------------------------------
58  {
60 
61  public:
62  LoadWriter3DS(): ResourceLoadWriter("|3ds|", "|3ds|") {}
63 
65  {
66  return load3DS(path);
67  }
68 
70  {
71  return load3DS(file);
72  }
73 
75  bool writeResource(const String& /*path*/, ResourceDatabase* /*resource*/) const
76  {
77  return false;
78  }
79 
81  bool writeResource(VirtualFile* /*file*/, ResourceDatabase* /*resource*/) const
82  {
83  return false;
84  }
85  };
86 //-----------------------------------------------------------------------------
87 // A3DSLoader
88 //-----------------------------------------------------------------------------
93  {
94  public:
95  A3DSTexture(): mUScale(1), mVScale(1), mUOffset(1), mVOffset(1), mRotation(0),
96  mOpt_tile(true), mOpt_decal(false), mOpt_mirror(false), mOpt_negative(false),
97  mOpt_summed_area(false), mOpt_use_alpha(false), mOpt_one_channel_tint(false),
98  mOpt_ignore_alpha(false), mOpt_rgb_tint(false) {}
99 
101  float mUScale, mVScale, mUOffset, mVOffset, mRotation;
102  bool mOpt_tile;
106  bool mOpt_summed_area; // summed area map filtering (instead of pyramidal)
107  bool mOpt_use_alpha; // use alpha (toggles RGBluma/alpha. For masks RGB means RGBluma)
108  bool mOpt_one_channel_tint; // there is a one channel tint (either RGBluma or alpha)
109  bool mOpt_ignore_alpha; // ignore alpha (take RGBluma even if an alpha exists (?))
110  bool mOpt_rgb_tint; // there is a three channel tint (RGB tint)
111  };
112 //-----------------------------------------------------------------------------
117  {
118  public:
119  A3DSMaterial(): mShininess(0), mShininessStrength(0), mTransparency(0), mDoubleSided(false) {}
120 
122  fvec3 mAmbient, mDiffuse, mSpecular;
123  float mShininess, mShininessStrength;
128  };
129 //-----------------------------------------------------------------------------
134  {
135  public:
136  A3DSTriFace(): mA(0), mB(0), mC(0), mFlags(0), mSmoothingGroup(0), mMaterialIndex(-1) {}
137 
138  unsigned short mA,mB,mC,mFlags;
139  unsigned int mSmoothingGroup;
141  };
142 //-----------------------------------------------------------------------------
147  {
148  public:
150  std::vector<unsigned short> mMappedFace;
151  };
152 //-----------------------------------------------------------------------------
157  {
158  public:
159  A3DSVertex(): mSmoothingGroup(0), mIndex(-1) {}
160  bool operator<(const A3DSVertex& other) const
161  {
162  if (mPos.x() != other.mPos.x())
163  return mPos.x() < other.mPos.x();
164  else
165  if (mPos.y() != other.mPos.y())
166  return mPos.y() < other.mPos.y();
167  else
168  if (mPos.z() != other.mPos.z())
169  return mPos.z() < other.mPos.z();
170  else
171  if (mUV.s() != other.mUV.s())
172  return mUV.s() < other.mUV.s();
173  else
174  if (mUV.t() != other.mUV.t())
175  return mUV.t() < other.mUV.t();
176  else
177  return mSmoothingGroup < other.mSmoothingGroup;
178  }
179 
182  unsigned int mSmoothingGroup;
183  int mIndex;
184  };
185 //-----------------------------------------------------------------------------
190  {
191  public:
193  std::vector<A3DSVertex> mVertices;
194  std::vector<A3DSTriFace> mFaceList;
195  std::vector<A3DSMaterialFaceMapping> mMatFaceMap;
197  };
198 //-----------------------------------------------------------------------------
203  {
204  public:
205  A3DSLoader();
206  bool parse3DS(VirtualFile* file);
207 
208  protected:
209  fvec3 readVec3();
210  fvec3 readColByte3();
211  fvec3 readColFloat3();
212  String readLine();
213  float readWordPercent();
214  float readFloatPercent();
215  void readChunk();
216  bool skipChunk();
217  void read_3D_EDITOR_CHUNK();
218  fvec3 readColChunk();
219  float readPercentChunk();
220  void read_MATERIAL_BLOCK();
221  A3DSTexture readMapChunk();
222  void read_OBJECT_BLOCK();
223  void read_TRIANGULAR_MESH();
224 
225  public:
226  std::vector<A3DSObject> mObjects;
227  std::vector<A3DSMaterial> mMaterials;
228 
229  protected:
231  unsigned short mChunkId;
232  unsigned int mChunkLen;
234  };
235 //-----------------------------------------------------------------------------
236 }
237 
238 #endif
std::vector< unsigned short > mMappedFace
Definition: io3DS.hpp:150
bool mOpt_rgb_tint
Definition: io3DS.hpp:110
std::vector< A3DSMaterial > mMaterials
Definition: io3DS.hpp:227
const T_Scalar & t() const
Definition: Vector2.hpp:145
bool mCorrupted
Definition: io3DS.hpp:233
The A3DSMaterialFaceMapping class represents the material/face mapping in a 3DS file.
Definition: io3DS.hpp:146
float mVScale
Definition: io3DS.hpp:101
An abstract class representing a file.
Definition: VirtualFile.hpp:60
bool mOpt_tile
Definition: io3DS.hpp:102
const T_Scalar & s() const
Definition: Vector2.hpp:144
float mTransparency
Definition: io3DS.hpp:124
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
Definition: String.hpp:62
const T_Scalar & z() const
Definition: Vector3.hpp:91
bool mDoubleSided
Definition: io3DS.hpp:125
bool mOpt_summed_area
Definition: io3DS.hpp:106
std::vector< A3DSMaterialFaceMapping > mMatFaceMap
Definition: io3DS.hpp:195
fvec3 mSpecular
Definition: io3DS.hpp:122
fmat4 mCoordSystem
Definition: io3DS.hpp:196
The A3DSLoader class loads an Autodesk 3DS file and generates a vector of A3DSObject and A3DSMaterial...
Definition: io3DS.hpp:202
unsigned short mChunkId
Definition: io3DS.hpp:231
#define VL_INSTRUMENT_CLASS(ClassName, BaseClass)
Definition: TypeInfo.hpp:122
The A3DSMaterial class represents a material in a 3DS file.
Definition: io3DS.hpp:116
Visualization Library main namespace.
VirtualFile * mInputFile
Definition: io3DS.hpp:230
unsigned int mChunkLen
Definition: io3DS.hpp:232
std::vector< A3DSTriFace > mFaceList
Definition: io3DS.hpp:194
ref< ResourceDatabase > loadResource(const String &path) const
Definition: io3DS.hpp:64
The A3DSObject class represents an object in a 3DS file.
Definition: io3DS.hpp:189
unsigned int mSmoothingGroup
Definition: io3DS.hpp:182
int mMaterialIndex
Definition: io3DS.hpp:140
float mShininessStrength
Definition: io3DS.hpp:123
bool mOpt_one_channel_tint
Definition: io3DS.hpp:108
ref< ResourceDatabase > loadResource(VirtualFile *file) const
Definition: io3DS.hpp:69
bool writeResource(VirtualFile *, ResourceDatabase *) const
Not supported yet.
Definition: io3DS.hpp:81
bool writeResource(const String &, ResourceDatabase *) const
Not supported yet.
Definition: io3DS.hpp:75
const T_Scalar & y() const
Definition: Vector3.hpp:90
bool mOpt_mirror
Definition: io3DS.hpp:104
A3DSTexture mTexture1
Definition: io3DS.hpp:126
std::vector< A3DSVertex > mVertices
Definition: io3DS.hpp:193
std::vector< A3DSObject > mObjects
Definition: io3DS.hpp:226
bool mOpt_negative
Definition: io3DS.hpp:105
String mObjName
Definition: io3DS.hpp:192
unsigned short mFlags
Definition: io3DS.hpp:138
bool mOpt_decal
Definition: io3DS.hpp:103
String mFileName
Definition: io3DS.hpp:100
bool mOpt_use_alpha
Definition: io3DS.hpp:107
bool operator<(const A3DSVertex &other) const
Definition: io3DS.hpp:160
const T_Scalar & x() const
Definition: Vector3.hpp:89
bool mOpt_ignore_alpha
Definition: io3DS.hpp:109
The ref<> class is used to reference-count an Object.
Definition: Object.hpp:55
The A3DSTexture class represents a texture in a 3DS file.
Definition: io3DS.hpp:92
The ResourceLoadWriter class is an abstract class used to implement read/write support for one or mor...
unsigned int mSmoothingGroup
Definition: io3DS.hpp:139
fvec3 mPos
Definition: io3DS.hpp:180
The A3DSVertex class represents a vertex in a 3DS file.
Definition: io3DS.hpp:156
VLGRAPHICS_EXPORT ref< ResourceDatabase > load3DS(VirtualFile *file)
Definition: io3DS.cpp:694
A3DSTexture mTexture2
Definition: io3DS.hpp:127
The A3DSTriFace class represents a triangle in a 3DS file.
Definition: io3DS.hpp:133
The ResourceDatabase class contains and manipulates a set of resources.
String mMaterialName
Definition: io3DS.hpp:121
The LoadWriter3DS class is a ResourceLoadWriter capable of reading 3DS files.
Definition: io3DS.hpp:57