MS3DLoader.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2022, 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 MS3DLoader.h
  34. * @brief Declaration of the MS3D importer class.
  35. */
  36. #pragma once
  37. #ifndef AI_MS3DLOADER_H_INCLUDED
  38. #define AI_MS3DLOADER_H_INCLUDED
  39. #include <assimp/BaseImporter.h>
  40. #include <assimp/StreamReader.h>
  41. struct aiNode;
  42. namespace Assimp {
  43. // ----------------------------------------------------------------------------------------------
  44. /** Milkshape 3D importer implementation */
  45. // ----------------------------------------------------------------------------------------------
  46. class MS3DImporter : public BaseImporter {
  47. public:
  48. MS3DImporter();
  49. ~MS3DImporter() override = default;
  50. // -------------------------------------------------------------------
  51. /** Returns whether the class can handle the format of the given file.
  52. * See BaseImporter::CanRead() for details. */
  53. bool CanRead(const std::string &pFile, IOSystem *pIOHandler,
  54. bool checkSig) const override;
  55. protected:
  56. // -------------------------------------------------------------------
  57. /** Return importer meta information.
  58. * See #BaseImporter::GetInfo for the details */
  59. const aiImporterDesc *GetInfo() const override;
  60. // -------------------------------------------------------------------
  61. /** Imports the given file into the given scene structure.
  62. * See BaseImporter::InternReadFile() for details */
  63. void InternReadFile(const std::string &pFile, aiScene *pScene,
  64. IOSystem *pIOHandler) override;
  65. private:
  66. struct TempJoint;
  67. void CollectChildJoints(const std::vector<TempJoint> &joints, std::vector<bool> &hadit, aiNode *nd, const aiMatrix4x4 &absTrafo);
  68. void CollectChildJoints(const std::vector<TempJoint> &joints, aiNode *nd);
  69. template <typename T>
  70. void ReadComments(StreamReaderLE &stream, std::vector<T> &outp);
  71. private:
  72. aiScene *mScene;
  73. private:
  74. struct TempVertex {
  75. aiVector3D pos;
  76. unsigned int bone_id[4], ref_cnt;
  77. float weights[4];
  78. };
  79. struct TempTriangle {
  80. unsigned int indices[3];
  81. aiVector3D normals[3];
  82. aiVector2D uv[3];
  83. unsigned int sg, group;
  84. };
  85. struct TempGroup {
  86. char name[33]; // +0
  87. std::vector<unsigned int> triangles;
  88. unsigned int mat; // 0xff is no material
  89. std::string comment;
  90. };
  91. struct TempMaterial {
  92. // again, add an extra 0 character to all strings -
  93. char name[33];
  94. char texture[129];
  95. char alphamap[129];
  96. aiColor4D diffuse, specular, ambient, emissive;
  97. float shininess, transparency;
  98. std::string comment;
  99. };
  100. struct TempKeyFrame {
  101. float time;
  102. aiVector3D value;
  103. };
  104. struct TempJoint {
  105. char name[33];
  106. char parentName[33];
  107. aiVector3D rotation, position;
  108. std::vector<TempKeyFrame> rotFrames;
  109. std::vector<TempKeyFrame> posFrames;
  110. std::string comment;
  111. };
  112. //struct TempModel {
  113. // std::string comment;
  114. //};
  115. };
  116. } // namespace Assimp
  117. #endif