------------------------------------------------------------------------------------------------ Imports the given file into the given scene structure.
| 94 | // ------------------------------------------------------------------------------------------------ |
| 95 | // Imports the given file into the given scene structure. |
| 96 | void OFFImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) { |
| 97 | std::unique_ptr<IOStream> file(pIOHandler->Open(pFile, "rb")); |
| 98 | |
| 99 | // Check whether we can read from the file |
| 100 | if (file == nullptr) { |
| 101 | throw DeadlyImportError("Failed to open OFF file ", pFile, "."); |
| 102 | } |
| 103 | |
| 104 | // allocate storage and copy the contents of the file to a memory buffer |
| 105 | std::vector<char> mBuffer2; |
| 106 | TextFileToBuffer(file.get(), mBuffer2); |
| 107 | const char *buffer = &mBuffer2[0]; |
| 108 | |
| 109 | // Proper OFF header parser. We only implement normal loading for now. |
| 110 | bool hasTexCoord = false, hasNormals = false, hasColors = false; |
| 111 | bool hasHomogenous = false, hasDimension = false; |
| 112 | unsigned int dimensions = 3; |
| 113 | const char *car = buffer; |
| 114 | const char *end = buffer + mBuffer2.size(); |
| 115 | NextToken(&car, end); |
| 116 | |
| 117 | if (car < end - 2 && car[0] == 'S' && car[1] == 'T') { |
| 118 | hasTexCoord = true; |
| 119 | car += 2; |
| 120 | } |
| 121 | if (car < end - 1 && car[0] == 'C') { |
| 122 | hasColors = true; |
| 123 | car++; |
| 124 | } |
| 125 | if (car < end - 1 && car[0] == 'N') { |
| 126 | hasNormals = true; |
| 127 | car++; |
| 128 | } |
| 129 | if (car < end - 1 && car[0] == '4') { |
| 130 | hasHomogenous = true; |
| 131 | car++; |
| 132 | } |
| 133 | if (car < end - 1 && car[0] == 'n') { |
| 134 | hasDimension = true; |
| 135 | car++; |
| 136 | } |
| 137 | if (car < end - 3 && car[0] == 'O' && car[1] == 'F' && car[2] == 'F') { |
| 138 | car += 3; |
| 139 | NextToken(&car, end); |
| 140 | } else { |
| 141 | // in case there is no OFF header (which is allowed by the |
| 142 | // specification...), then we might have unintentionally read an |
| 143 | // additional dimension from the primitive count fields |
| 144 | dimensions = 3; |
| 145 | hasHomogenous = false; |
| 146 | NextToken(&car, end); |
| 147 | |
| 148 | // at this point the next token should be an integer number |
| 149 | if (car >= end - 1 || *car < '0' || *car > '9') { |
| 150 | throw DeadlyImportError("OFF: Header is invalid"); |
| 151 | } |
| 152 | } |
| 153 | if (hasDimension) { |
nothing calls this directly
no test coverage detected