1 /* 2 Open Asset Import Library (assimp) 3 ---------------------------------------------------------------------- 4 5 Copyright (c) 2006-2016, assimp team 6 All rights reserved. 7 8 Redistribution and use of this software in source and binary forms, 9 with or without modification, are permitted provided that the 10 following conditions are met: 11 12 * Redistributions of source code must retain the above 13 copyright notice, this list of conditions and the 14 following disclaimer. 15 16 * Redistributions in binary form must reproduce the above 17 copyright notice, this list of conditions and the 18 following disclaimer in the documentation and/or other 19 materials provided with the distribution. 20 21 * Neither the name of the assimp team, nor the names of its 22 contributors may be used to endorse or promote products 23 derived from this software without specific prior 24 written permission of the assimp team. 25 26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 30 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 31 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 32 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 33 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 34 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 36 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 38 ---------------------------------------------------------------------- 39 */ 40 41 /** @file PLYLoader.h 42 * @brief Declaration of the .ply importer class. 43 */ 44 #ifndef AI_PLYLOADER_H_INCLUDED 45 #define AI_PLYLOADER_H_INCLUDED 46 47 #include "BaseImporter.h" 48 #include <assimp/types.h> 49 #include "PlyParser.h" 50 #include <vector> 51 52 struct aiNode; 53 struct aiMaterial; 54 struct aiMesh; 55 56 namespace Assimp { 57 58 59 using namespace PLY; 60 61 // --------------------------------------------------------------------------- 62 /** Importer class to load the stanford PLY file format 63 */ 64 class PLYImporter : public BaseImporter 65 { 66 public: 67 PLYImporter(); 68 ~PLYImporter(); 69 70 71 public: 72 73 // ------------------------------------------------------------------- 74 /** Returns whether the class can handle the format of the given file. 75 * See BaseImporter::CanRead() for details. 76 */ 77 bool CanRead( const std::string& pFile, IOSystem* pIOHandler, 78 bool checkSig) const; 79 80 protected: 81 82 // ------------------------------------------------------------------- 83 /** Return importer meta information. 84 * See #BaseImporter::GetInfo for the details 85 */ 86 const aiImporterDesc* GetInfo () const; 87 88 // ------------------------------------------------------------------- 89 /** Imports the given file into the given scene structure. 90 * See BaseImporter::InternReadFile() for details 91 */ 92 void InternReadFile( const std::string& pFile, aiScene* pScene, 93 IOSystem* pIOHandler); 94 95 protected: 96 97 98 // ------------------------------------------------------------------- 99 /** Extract vertices from the DOM 100 */ 101 void LoadVertices(std::vector<aiVector3D>* pvOut, 102 bool p_bNormals = false); 103 104 // ------------------------------------------------------------------- 105 /** Extract vertex color channels from the DOM 106 */ 107 void LoadVertexColor(std::vector<aiColor4D>* pvOut); 108 109 // ------------------------------------------------------------------- 110 /** Extract texture coordinate channels from the DOM 111 */ 112 void LoadTextureCoordinates(std::vector<aiVector2D>* pvOut); 113 114 // ------------------------------------------------------------------- 115 /** Extract a face list from the DOM 116 */ 117 void LoadFaces(std::vector<PLY::Face>* pvOut); 118 119 // ------------------------------------------------------------------- 120 /** Extract a material list from the DOM 121 */ 122 void LoadMaterial(std::vector<aiMaterial*>* pvOut); 123 124 125 // ------------------------------------------------------------------- 126 /** Validate material indices, replace default material identifiers 127 */ 128 void ReplaceDefaultMaterial(std::vector<PLY::Face>* avFaces, 129 std::vector<aiMaterial*>* avMaterials); 130 131 132 // ------------------------------------------------------------------- 133 /** Convert all meshes into our ourer representation 134 */ 135 void ConvertMeshes(std::vector<PLY::Face>* avFaces, 136 const std::vector<aiVector3D>* avPositions, 137 const std::vector<aiVector3D>* avNormals, 138 const std::vector<aiColor4D>* avColors, 139 const std::vector<aiVector2D>* avTexCoords, 140 const std::vector<aiMaterial*>* avMaterials, 141 std::vector<aiMesh*>* avOut); 142 143 144 // ------------------------------------------------------------------- 145 /** Static helper to parse a color from four single channels in 146 */ 147 static void GetMaterialColor( 148 const std::vector<PLY::PropertyInstance>& avList, 149 unsigned int aiPositions[4], 150 PLY::EDataType aiTypes[4], 151 aiColor4D* clrOut); 152 153 154 // ------------------------------------------------------------------- 155 /** Static helper to parse a color channel value. The input value 156 * is normalized to 0-1. 157 */ 158 static float NormalizeColorValue ( 159 PLY::PropertyInstance::ValueUnion val, 160 PLY::EDataType eType); 161 162 163 /** Buffer to hold the loaded file */ 164 unsigned char* mBuffer; 165 166 /** Document object model representation extracted from the file */ 167 PLY::DOM* pcDOM; 168 }; 169 170 } // end of namespace Assimp 171 172 #endif // AI_3DSIMPORTER_H_INC 173