3DSHelper.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2021, assimp team
  5. All rights reserved.
  6. Redistribution and use of this software in source and binary forms,
  7. with or without modification, are permitted provided that the
  8. following conditions are met:
  9. * Redistributions of source code must retain the above
  10. copyright notice, this list of conditions and the
  11. following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the
  14. following disclaimer in the documentation and/or other
  15. materials provided with the distribution.
  16. * Neither the name of the assimp team, nor the names of its
  17. contributors may be used to endorse or promote products
  18. derived from this software without specific prior
  19. written permission of the assimp team.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ----------------------------------------------------------------------
  32. */
  33. /** @file Defines helper data structures for the import of 3DS files */
  34. #ifndef AI_3DSFILEHELPER_H_INC
  35. #define AI_3DSFILEHELPER_H_INC
  36. #include <assimp/SmoothingGroups.h>
  37. #include <assimp/SpatialSort.h>
  38. #include <assimp/StringUtils.h>
  39. #include <assimp/anim.h>
  40. #include <assimp/camera.h>
  41. #include <assimp/light.h>
  42. #include <assimp/material.h>
  43. #include <assimp/qnan.h>
  44. #include <stdio.h> //sprintf
  45. namespace Assimp {
  46. namespace D3DS {
  47. #include <assimp/Compiler/pushpack1.h>
  48. // ---------------------------------------------------------------------------
  49. /** Defines chunks and data structures.
  50. */
  51. namespace Discreet3DS {
  52. //! data structure for a single chunk in a .3ds file
  53. struct Chunk {
  54. uint16_t Flag;
  55. uint32_t Size;
  56. } PACK_STRUCT;
  57. //! Used for shading field in material3ds structure
  58. //! From AutoDesk 3ds SDK
  59. typedef enum {
  60. // translated to gouraud shading with wireframe active
  61. Wire = 0x0,
  62. // if this material is set, no vertex normals will
  63. // be calculated for the model. Face normals + gouraud
  64. Flat = 0x1,
  65. // standard gouraud shading
  66. Gouraud = 0x2,
  67. // phong shading
  68. Phong = 0x3,
  69. // cooktorrance or anistropic phong shading ...
  70. // the exact meaning is unknown, if you know it
  71. // feel free to tell me ;-)
  72. Metal = 0x4,
  73. // required by the ASE loader
  74. Blinn = 0x5
  75. } shadetype3ds;
  76. // Flags for animated keys
  77. enum {
  78. KEY_USE_TENS = 0x1,
  79. KEY_USE_CONT = 0x2,
  80. KEY_USE_BIAS = 0x4,
  81. KEY_USE_EASE_TO = 0x8,
  82. KEY_USE_EASE_FROM = 0x10
  83. };
  84. enum {
  85. // ********************************************************************
  86. // Basic chunks which can be found everywhere in the file
  87. CHUNK_VERSION = 0x0002,
  88. CHUNK_RGBF = 0x0010, // float4 R; float4 G; float4 B
  89. CHUNK_RGBB = 0x0011, // int1 R; int1 G; int B
  90. // Linear color values (gamma = 2.2?)
  91. CHUNK_LINRGBF = 0x0013, // float4 R; float4 G; float4 B
  92. CHUNK_LINRGBB = 0x0012, // int1 R; int1 G; int B
  93. CHUNK_PERCENTW = 0x0030, // int2 percentage
  94. CHUNK_PERCENTF = 0x0031, // float4 percentage
  95. CHUNK_PERCENTD = 0x0032, // float8 percentage
  96. // ********************************************************************
  97. // Prj master chunk
  98. CHUNK_PRJ = 0xC23D,
  99. // MDLI master chunk
  100. CHUNK_MLI = 0x3DAA,
  101. // Primary main chunk of the .3ds file
  102. CHUNK_MAIN = 0x4D4D,
  103. // Mesh main chunk
  104. CHUNK_OBJMESH = 0x3D3D,
  105. // Specifies the background color of the .3ds file
  106. // This is passed through the material system for
  107. // viewing purposes.
  108. CHUNK_BKGCOLOR = 0x1200,
  109. // Specifies the ambient base color of the scene.
  110. // This is added to all materials in the file
  111. CHUNK_AMBCOLOR = 0x2100,
  112. // Specifies the background image for the whole scene
  113. // This value is passed through the material system
  114. // to the viewer
  115. CHUNK_BIT_MAP = 0x1100,
  116. CHUNK_BIT_MAP_EXISTS = 0x1101,
  117. // ********************************************************************
  118. // Viewport related stuff. Ignored
  119. CHUNK_DEFAULT_VIEW = 0x3000,
  120. CHUNK_VIEW_TOP = 0x3010,
  121. CHUNK_VIEW_BOTTOM = 0x3020,
  122. CHUNK_VIEW_LEFT = 0x3030,
  123. CHUNK_VIEW_RIGHT = 0x3040,
  124. CHUNK_VIEW_FRONT = 0x3050,
  125. CHUNK_VIEW_BACK = 0x3060,
  126. CHUNK_VIEW_USER = 0x3070,
  127. CHUNK_VIEW_CAMERA = 0x3080,
  128. // ********************************************************************
  129. // Mesh chunks
  130. CHUNK_OBJBLOCK = 0x4000,
  131. CHUNK_TRIMESH = 0x4100,
  132. CHUNK_VERTLIST = 0x4110,
  133. CHUNK_VERTFLAGS = 0x4111,
  134. CHUNK_FACELIST = 0x4120,
  135. CHUNK_FACEMAT = 0x4130,
  136. CHUNK_MAPLIST = 0x4140,
  137. CHUNK_SMOOLIST = 0x4150,
  138. CHUNK_TRMATRIX = 0x4160,
  139. CHUNK_MESHCOLOR = 0x4165,
  140. CHUNK_TXTINFO = 0x4170,
  141. CHUNK_LIGHT = 0x4600,
  142. CHUNK_CAMERA = 0x4700,
  143. CHUNK_HIERARCHY = 0x4F00,
  144. // Specifies the global scaling factor. This is applied
  145. // to the root node's transformation matrix
  146. CHUNK_MASTER_SCALE = 0x0100,
  147. // ********************************************************************
  148. // Material chunks
  149. CHUNK_MAT_MATERIAL = 0xAFFF,
  150. // asciiz containing the name of the material
  151. CHUNK_MAT_MATNAME = 0xA000,
  152. CHUNK_MAT_AMBIENT = 0xA010, // followed by color chunk
  153. CHUNK_MAT_DIFFUSE = 0xA020, // followed by color chunk
  154. CHUNK_MAT_SPECULAR = 0xA030, // followed by color chunk
  155. // Specifies the shininess of the material
  156. // followed by percentage chunk
  157. CHUNK_MAT_SHININESS = 0xA040,
  158. CHUNK_MAT_SHININESS_PERCENT = 0xA041,
  159. // Specifies the shading mode to be used
  160. // followed by a short
  161. CHUNK_MAT_SHADING = 0xA100,
  162. // NOTE: Emissive color (self illumination) seems not
  163. // to be a color but a single value, type is unknown.
  164. // Make the parser accept both of them.
  165. // followed by percentage chunk (?)
  166. CHUNK_MAT_SELF_ILLUM = 0xA080,
  167. // Always followed by percentage chunk (?)
  168. CHUNK_MAT_SELF_ILPCT = 0xA084,
  169. // Always followed by percentage chunk
  170. CHUNK_MAT_TRANSPARENCY = 0xA050,
  171. // Diffuse texture channel 0
  172. CHUNK_MAT_TEXTURE = 0xA200,
  173. // Contains opacity information for each texel
  174. CHUNK_MAT_OPACMAP = 0xA210,
  175. // Contains a reflection map to be used to reflect
  176. // the environment. This is partially supported.
  177. CHUNK_MAT_REFLMAP = 0xA220,
  178. // Self Illumination map (emissive colors)
  179. CHUNK_MAT_SELFIMAP = 0xA33d,
  180. // Bumpmap. Not specified whether it is a heightmap
  181. // or a normal map. Assme it is a heightmap since
  182. // artist normally prefer this format.
  183. CHUNK_MAT_BUMPMAP = 0xA230,
  184. // Specular map. Seems to influence the specular color
  185. CHUNK_MAT_SPECMAP = 0xA204,
  186. // Holds shininess data.
  187. CHUNK_MAT_MAT_SHINMAP = 0xA33C,
  188. // Scaling in U/V direction.
  189. // (need to gen separate UV coordinate set
  190. // and do this by hand)
  191. CHUNK_MAT_MAP_USCALE = 0xA354,
  192. CHUNK_MAT_MAP_VSCALE = 0xA356,
  193. // Translation in U/V direction.
  194. // (need to gen separate UV coordinate set
  195. // and do this by hand)
  196. CHUNK_MAT_MAP_UOFFSET = 0xA358,
  197. CHUNK_MAT_MAP_VOFFSET = 0xA35a,
  198. // UV-coordinates rotation around the z-axis
  199. // Assumed to be in radians.
  200. CHUNK_MAT_MAP_ANG = 0xA35C,
  201. // Tiling flags for 3DS files
  202. CHUNK_MAT_MAP_TILING = 0xa351,
  203. // Specifies the file name of a texture
  204. CHUNK_MAPFILE = 0xA300,
  205. // Specifies whether a materail requires two-sided rendering
  206. CHUNK_MAT_TWO_SIDE = 0xA081,
  207. // ********************************************************************
  208. // Main keyframer chunk. Contains translation/rotation/scaling data
  209. CHUNK_KEYFRAMER = 0xB000,
  210. // Supported sub chunks
  211. CHUNK_TRACKINFO = 0xB002,
  212. CHUNK_TRACKOBJNAME = 0xB010,
  213. CHUNK_TRACKDUMMYOBJNAME = 0xB011,
  214. CHUNK_TRACKPIVOT = 0xB013,
  215. CHUNK_TRACKPOS = 0xB020,
  216. CHUNK_TRACKROTATE = 0xB021,
  217. CHUNK_TRACKSCALE = 0xB022,
  218. // ********************************************************************
  219. // Keyframes for various other stuff in the file
  220. // Partially ignored
  221. CHUNK_AMBIENTKEY = 0xB001,
  222. CHUNK_TRACKMORPH = 0xB026,
  223. CHUNK_TRACKHIDE = 0xB029,
  224. CHUNK_OBJNUMBER = 0xB030,
  225. CHUNK_TRACKCAMERA = 0xB003,
  226. CHUNK_TRACKFOV = 0xB023,
  227. CHUNK_TRACKROLL = 0xB024,
  228. CHUNK_TRACKCAMTGT = 0xB004,
  229. CHUNK_TRACKLIGHT = 0xB005,
  230. CHUNK_TRACKLIGTGT = 0xB006,
  231. CHUNK_TRACKSPOTL = 0xB007,
  232. CHUNK_FRAMES = 0xB008,
  233. // ********************************************************************
  234. // light sub-chunks
  235. CHUNK_DL_OFF = 0x4620,
  236. CHUNK_DL_OUTER_RANGE = 0x465A,
  237. CHUNK_DL_INNER_RANGE = 0x4659,
  238. CHUNK_DL_MULTIPLIER = 0x465B,
  239. CHUNK_DL_EXCLUDE = 0x4654,
  240. CHUNK_DL_ATTENUATE = 0x4625,
  241. CHUNK_DL_SPOTLIGHT = 0x4610,
  242. // camera sub-chunks
  243. CHUNK_CAM_RANGES = 0x4720
  244. };
  245. }
  246. // ---------------------------------------------------------------------------
  247. /** Helper structure representing a 3ds mesh face */
  248. struct Face : public FaceWithSmoothingGroup {
  249. };
  250. #ifdef _MSC_VER
  251. #pragma warning(push)
  252. #pragma warning(disable : 4315)
  253. #endif // _MSC_VER
  254. // ---------------------------------------------------------------------------
  255. /** Helper structure representing a texture */
  256. struct Texture {
  257. //! Default constructor
  258. Texture() AI_NO_EXCEPT
  259. : mTextureBlend(0.0f),
  260. mMapName(),
  261. mOffsetU(0.0),
  262. mOffsetV(0.0),
  263. mScaleU(1.0),
  264. mScaleV(1.0),
  265. mRotation(0.0),
  266. mMapMode(aiTextureMapMode_Wrap),
  267. bPrivate(),
  268. iUVSrc(0) {
  269. mTextureBlend = get_qnan();
  270. }
  271. Texture(const Texture &other) :
  272. mTextureBlend(other.mTextureBlend),
  273. mMapName(other.mMapName),
  274. mOffsetU(other.mOffsetU),
  275. mOffsetV(other.mOffsetV),
  276. mScaleU(other.mScaleU),
  277. mScaleV(other.mScaleV),
  278. mRotation(other.mRotation),
  279. mMapMode(other.mMapMode),
  280. bPrivate(other.bPrivate),
  281. iUVSrc(other.iUVSrc) {
  282. // empty
  283. }
  284. Texture(Texture &&other) AI_NO_EXCEPT : mTextureBlend(other.mTextureBlend),
  285. mMapName(std::move(other.mMapName)),
  286. mOffsetU(other.mOffsetU),
  287. mOffsetV(other.mOffsetV),
  288. mScaleU(other.mScaleU),
  289. mScaleV(other.mScaleV),
  290. mRotation(other.mRotation),
  291. mMapMode(other.mMapMode),
  292. bPrivate(other.bPrivate),
  293. iUVSrc(other.iUVSrc) {
  294. // empty
  295. }
  296. Texture &operator=(Texture &&other) AI_NO_EXCEPT {
  297. if (this == &other) {
  298. return *this;
  299. }
  300. mTextureBlend = other.mTextureBlend;
  301. mMapName = std::move(other.mMapName);
  302. mOffsetU = other.mOffsetU;
  303. mOffsetV = other.mOffsetV;
  304. mScaleU = other.mScaleU;
  305. mScaleV = other.mScaleV;
  306. mRotation = other.mRotation;
  307. mMapMode = other.mMapMode;
  308. bPrivate = other.bPrivate;
  309. iUVSrc = other.iUVSrc;
  310. return *this;
  311. }
  312. //! Specifies the blend factor for the texture
  313. ai_real mTextureBlend;
  314. //! Specifies the filename of the texture
  315. std::string mMapName;
  316. //! Specifies texture coordinate offsets/scaling/rotations
  317. ai_real mOffsetU;
  318. ai_real mOffsetV;
  319. ai_real mScaleU;
  320. ai_real mScaleV;
  321. ai_real mRotation;
  322. //! Specifies the mapping mode to be used for the texture
  323. aiTextureMapMode mMapMode;
  324. //! Used internally
  325. bool bPrivate;
  326. int iUVSrc;
  327. };
  328. #include <assimp/Compiler/poppack1.h>
  329. #ifdef _MSC_VER
  330. #pragma warning(pop)
  331. #endif // _MSC_VER
  332. // ---------------------------------------------------------------------------
  333. /** Helper structure representing a 3ds material */
  334. struct Material {
  335. //! Default constructor has been deleted
  336. Material() :
  337. mName(),
  338. mDiffuse(ai_real(0.6), ai_real(0.6), ai_real(0.6)),
  339. mSpecularExponent(ai_real(0.0)),
  340. mShininessStrength(ai_real(1.0)),
  341. mShading(Discreet3DS::Gouraud),
  342. mTransparency(ai_real(1.0)),
  343. mBumpHeight(ai_real(1.0)),
  344. mTwoSided(false) {
  345. // empty
  346. }
  347. //! Constructor with explicit name
  348. explicit Material(const std::string &name) :
  349. mName(name),
  350. mDiffuse(ai_real(0.6), ai_real(0.6), ai_real(0.6)),
  351. mSpecularExponent(ai_real(0.0)),
  352. mShininessStrength(ai_real(1.0)),
  353. mShading(Discreet3DS::Gouraud),
  354. mTransparency(ai_real(1.0)),
  355. mBumpHeight(ai_real(1.0)),
  356. mTwoSided(false) {
  357. // empty
  358. }
  359. Material(const Material &other) :
  360. mName(other.mName),
  361. mDiffuse(other.mDiffuse),
  362. mSpecularExponent(other.mSpecularExponent),
  363. mShininessStrength(other.mShininessStrength),
  364. mSpecular(other.mSpecular),
  365. mAmbient(other.mAmbient),
  366. mShading(other.mShading),
  367. mTransparency(other.mTransparency),
  368. sTexDiffuse(other.sTexDiffuse),
  369. sTexOpacity(other.sTexOpacity),
  370. sTexSpecular(other.sTexSpecular),
  371. sTexReflective(other.sTexReflective),
  372. sTexBump(other.sTexBump),
  373. sTexEmissive(other.sTexEmissive),
  374. sTexShininess(other.sTexShininess),
  375. mBumpHeight(other.mBumpHeight),
  376. mEmissive(other.mEmissive),
  377. sTexAmbient(other.sTexAmbient),
  378. mTwoSided(other.mTwoSided) {
  379. // empty
  380. }
  381. //! Move constructor. This is explicitly written because MSVC doesn't support defaulting it
  382. Material(Material &&other) AI_NO_EXCEPT : mName(std::move(other.mName)),
  383. mDiffuse(other.mDiffuse),
  384. mSpecularExponent(other.mSpecularExponent),
  385. mShininessStrength(other.mShininessStrength),
  386. mSpecular(other.mSpecular),
  387. mAmbient(other.mAmbient),
  388. mShading(other.mShading),
  389. mTransparency(other.mTransparency),
  390. sTexDiffuse(std::move(other.sTexDiffuse)),
  391. sTexOpacity(std::move(other.sTexOpacity)),
  392. sTexSpecular(std::move(other.sTexSpecular)),
  393. sTexReflective(std::move(other.sTexReflective)),
  394. sTexBump(std::move(other.sTexBump)),
  395. sTexEmissive(std::move(other.sTexEmissive)),
  396. sTexShininess(std::move(other.sTexShininess)),
  397. mBumpHeight(other.mBumpHeight),
  398. mEmissive(other.mEmissive),
  399. sTexAmbient(std::move(other.sTexAmbient)),
  400. mTwoSided(other.mTwoSided) {
  401. // empty
  402. }
  403. Material &operator=(Material &&other) AI_NO_EXCEPT {
  404. if (this == &other) {
  405. return *this;
  406. }
  407. mName = std::move(other.mName);
  408. mDiffuse = other.mDiffuse;
  409. mSpecularExponent = other.mSpecularExponent;
  410. mShininessStrength = other.mShininessStrength,
  411. mSpecular = other.mSpecular;
  412. mAmbient = other.mAmbient;
  413. mShading = other.mShading;
  414. mTransparency = other.mTransparency;
  415. sTexDiffuse = std::move(other.sTexDiffuse);
  416. sTexOpacity = std::move(other.sTexOpacity);
  417. sTexSpecular = std::move(other.sTexSpecular);
  418. sTexReflective = std::move(other.sTexReflective);
  419. sTexBump = std::move(other.sTexBump);
  420. sTexEmissive = std::move(other.sTexEmissive);
  421. sTexShininess = std::move(other.sTexShininess);
  422. mBumpHeight = other.mBumpHeight;
  423. mEmissive = other.mEmissive;
  424. sTexAmbient = std::move(other.sTexAmbient);
  425. mTwoSided = other.mTwoSided;
  426. return *this;
  427. }
  428. virtual ~Material() {
  429. // empty
  430. }
  431. //! Name of the material
  432. std::string mName;
  433. //! Diffuse color of the material
  434. aiColor3D mDiffuse;
  435. //! Specular exponent
  436. ai_real mSpecularExponent;
  437. //! Shininess strength, in percent
  438. ai_real mShininessStrength;
  439. //! Specular color of the material
  440. aiColor3D mSpecular;
  441. //! Ambient color of the material
  442. aiColor3D mAmbient;
  443. //! Shading type to be used
  444. Discreet3DS::shadetype3ds mShading;
  445. //! Opacity of the material
  446. ai_real mTransparency;
  447. //! Diffuse texture channel
  448. Texture sTexDiffuse;
  449. //! Opacity texture channel
  450. Texture sTexOpacity;
  451. //! Specular texture channel
  452. Texture sTexSpecular;
  453. //! Reflective texture channel
  454. Texture sTexReflective;
  455. //! Bump texture channel
  456. Texture sTexBump;
  457. //! Emissive texture channel
  458. Texture sTexEmissive;
  459. //! Shininess texture channel
  460. Texture sTexShininess;
  461. //! Scaling factor for the bump values
  462. ai_real mBumpHeight;
  463. //! Emissive color
  464. aiColor3D mEmissive;
  465. //! Ambient texture channel
  466. //! (used by the ASE format)
  467. Texture sTexAmbient;
  468. //! True if the material must be rendered from two sides
  469. bool mTwoSided;
  470. };
  471. // ---------------------------------------------------------------------------
  472. /** Helper structure to represent a 3ds file mesh */
  473. struct Mesh : public MeshWithSmoothingGroups<D3DS::Face> {
  474. //! Default constructor has been deleted
  475. Mesh() = delete;
  476. //! Constructor with explicit name
  477. explicit Mesh(const std::string &name) :
  478. mName(name) {
  479. }
  480. //! Name of the mesh
  481. std::string mName;
  482. //! Texture coordinates
  483. std::vector<aiVector3D> mTexCoords;
  484. //! Face materials
  485. std::vector<unsigned int> mFaceMaterials;
  486. //! Local transformation matrix
  487. aiMatrix4x4 mMat;
  488. };
  489. // ---------------------------------------------------------------------------
  490. /** Float key - quite similar to aiVectorKey and aiQuatKey. Both are in the
  491. C-API, so it would be difficult to make them a template. */
  492. struct aiFloatKey {
  493. double mTime; ///< The time of this key
  494. ai_real mValue; ///< The value of this key
  495. #ifdef __cplusplus
  496. // time is not compared
  497. bool operator==(const aiFloatKey &o) const { return o.mValue == this->mValue; }
  498. bool operator!=(const aiFloatKey &o) const { return o.mValue != this->mValue; }
  499. // Only time is compared. This operator is defined
  500. // for use with std::sort
  501. bool operator<(const aiFloatKey &o) const { return mTime < o.mTime; }
  502. bool operator>(const aiFloatKey &o) const { return mTime > o.mTime; }
  503. #endif
  504. };
  505. // ---------------------------------------------------------------------------
  506. /** Helper structure to represent a 3ds file node */
  507. struct Node {
  508. Node() = delete;
  509. explicit Node(const std::string &name) :
  510. mParent(nullptr),
  511. mName(name),
  512. mInstanceNumber(0),
  513. mHierarchyPos(0),
  514. mHierarchyIndex(0),
  515. mInstanceCount(1) {
  516. aRotationKeys.reserve(20);
  517. aPositionKeys.reserve(20);
  518. aScalingKeys.reserve(20);
  519. }
  520. ~Node() {
  521. for (unsigned int i = 0; i < mChildren.size(); ++i)
  522. delete mChildren[i];
  523. }
  524. //! Pointer to the parent node
  525. Node *mParent;
  526. //! Holds all child nodes
  527. std::vector<Node *> mChildren;
  528. //! Name of the node
  529. std::string mName;
  530. //! InstanceNumber of the node
  531. int32_t mInstanceNumber;
  532. //! Dummy nodes: real name to be combined with the $$$DUMMY
  533. std::string mDummyName;
  534. //! Position of the node in the hierarchy (tree depth)
  535. int16_t mHierarchyPos;
  536. //! Index of the node
  537. int16_t mHierarchyIndex;
  538. //! Rotation keys loaded from the file
  539. std::vector<aiQuatKey> aRotationKeys;
  540. //! Position keys loaded from the file
  541. std::vector<aiVectorKey> aPositionKeys;
  542. //! Scaling keys loaded from the file
  543. std::vector<aiVectorKey> aScalingKeys;
  544. // For target lights (spot lights and directional lights):
  545. // The position of the target
  546. std::vector<aiVectorKey> aTargetPositionKeys;
  547. // For cameras: the camera roll angle
  548. std::vector<aiFloatKey> aCameraRollKeys;
  549. //! Pivot position loaded from the file
  550. aiVector3D vPivot;
  551. //instance count, will be kept only for the first node
  552. int32_t mInstanceCount;
  553. //! Add a child node, setup the right parent node for it
  554. //! \param pc Node to be 'adopted'
  555. inline Node &push_back(Node *pc) {
  556. mChildren.push_back(pc);
  557. pc->mParent = this;
  558. return *this;
  559. }
  560. };
  561. // ---------------------------------------------------------------------------
  562. /** Helper structure analogue to aiScene */
  563. struct Scene {
  564. //! List of all materials loaded
  565. //! NOTE: 3ds references materials globally
  566. std::vector<Material> mMaterials;
  567. //! List of all meshes loaded
  568. std::vector<Mesh> mMeshes;
  569. //! List of all cameras loaded
  570. std::vector<aiCamera *> mCameras;
  571. //! List of all lights loaded
  572. std::vector<aiLight *> mLights;
  573. //! Pointer to the root node of the scene
  574. // --- moved to main class
  575. // Node* pcRootNode;
  576. };
  577. } // end of namespace D3DS
  578. } // end of namespace Assimp
  579. #endif // AI_XFILEHELPER_H_INC