You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

200 line
5.0 KiB

  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2012, 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 XGLLoader.h
  34. * @brief Declaration of the .xgl/.zgl
  35. */
  36. #ifndef AI_XGLLOADER_H_INCLUDED
  37. #define AI_XGLLOADER_H_INCLUDED
  38. #include "BaseImporter.h"
  39. #include "irrXMLWrapper.h"
  40. #include "LogAux.h"
  41. namespace Assimp {
  42. // ---------------------------------------------------------------------------
  43. /** XGL/ZGL importer.
  44. *
  45. * Spec: http://vizstream.aveva.com/release/vsplatform/XGLSpec.htm
  46. */
  47. class XGLImporter : public BaseImporter, public LogFunctions<XGLImporter>
  48. {
  49. public:
  50. XGLImporter();
  51. ~XGLImporter();
  52. public:
  53. // -------------------------------------------------------------------
  54. /** Returns whether the class can handle the format of the given file.
  55. * See BaseImporter::CanRead() for details. */
  56. bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
  57. bool checkSig) const;
  58. protected:
  59. // -------------------------------------------------------------------
  60. /** Return importer meta information.
  61. * See #BaseImporter::GetInfo for the details */
  62. const aiImporterDesc* GetInfo () const;
  63. // -------------------------------------------------------------------
  64. /** Imports the given file into the given scene structure.
  65. * See BaseImporter::InternReadFile() for details */
  66. void InternReadFile( const std::string& pFile, aiScene* pScene,
  67. IOSystem* pIOHandler);
  68. private:
  69. struct TempScope
  70. {
  71. TempScope()
  72. : light()
  73. {}
  74. ~TempScope()
  75. {
  76. BOOST_FOREACH(aiMesh* m, meshes_linear) {
  77. delete m;
  78. }
  79. BOOST_FOREACH(aiMaterial* m, materials_linear) {
  80. delete m;
  81. }
  82. delete light;
  83. }
  84. void dismiss() {
  85. light = NULL;
  86. meshes_linear.clear();
  87. materials_linear.clear();
  88. meshes.clear();
  89. materials.clear();
  90. }
  91. std::multimap<unsigned int, aiMesh*> meshes;
  92. std::map<unsigned int, aiMaterial*> materials;
  93. std::vector<aiMesh*> meshes_linear;
  94. std::vector<aiMaterial*> materials_linear;
  95. aiLight* light;
  96. };
  97. struct TempMesh
  98. {
  99. std::map<unsigned int, aiVector3D> points;
  100. std::map<unsigned int, aiVector3D> normals;
  101. std::map<unsigned int, aiVector2D> uvs;
  102. };
  103. struct TempMaterialMesh
  104. {
  105. TempMaterialMesh()
  106. : pflags()
  107. , matid()
  108. {}
  109. std::vector<aiVector3D> positions, normals;
  110. std::vector<aiVector2D> uvs;
  111. std::vector<unsigned int> vcounts;
  112. unsigned int pflags;
  113. unsigned int matid;
  114. };
  115. struct TempFace
  116. {
  117. TempFace()
  118. : has_uv()
  119. , has_normal()
  120. {}
  121. aiVector3D pos;
  122. aiVector3D normal;
  123. aiVector2D uv;
  124. bool has_uv;
  125. bool has_normal;
  126. };
  127. private:
  128. void Cleanup();
  129. std::string GetElementName();
  130. bool ReadElement();
  131. bool ReadElementUpToClosing(const char* closetag);
  132. bool SkipToText();
  133. unsigned int ReadIDAttr();
  134. void ReadWorld(TempScope& scope);
  135. void ReadLighting(TempScope& scope);
  136. aiLight* ReadDirectionalLight();
  137. aiNode* ReadObject(TempScope& scope,bool skipFirst = false,const char* closetag = "object");
  138. bool ReadMesh(TempScope& scope);
  139. void ReadMaterial(TempScope& scope);
  140. aiVector2D ReadVec2();
  141. aiVector3D ReadVec3();
  142. aiColor3D ReadCol3();
  143. aiMatrix4x4 ReadTrafo();
  144. unsigned int ReadIndexFromText();
  145. float ReadFloat();
  146. aiMesh* ToOutputMesh(const TempMaterialMesh& m);
  147. void ReadFaceVertex(const TempMesh& t, TempFace& out);
  148. unsigned int ResolveMaterialRef(TempScope& scope);
  149. private:
  150. private:
  151. irr::io::IrrXMLReader* reader;
  152. aiScene* scene;
  153. };
  154. } // end of namespace Assimp
  155. #endif // AI_IRRMESHIMPORTER_H_INC