------------------------------------------------------------------------------------------------ Imports the given file into the given scene structure.
| 136 | // ------------------------------------------------------------------------------------------------ |
| 137 | // Imports the given file into the given scene structure. |
| 138 | void COBImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) { |
| 139 | COB::Scene scene; |
| 140 | |
| 141 | auto file = pIOHandler->Open(pFile, "rb"); |
| 142 | if (!file) { |
| 143 | ThrowException("Could not open " + pFile); |
| 144 | } |
| 145 | |
| 146 | std::unique_ptr<StreamReaderLE> stream(new StreamReaderLE(file)); |
| 147 | |
| 148 | // check header |
| 149 | static constexpr size_t HeaderSize = 32u; |
| 150 | char head[HeaderSize] = {}; |
| 151 | stream->CopyAndAdvance(head, HeaderSize); |
| 152 | |
| 153 | // load data into intermediate structures |
| 154 | if (head[15] == 'A') { |
| 155 | if (!isValidASCIIHeader(head)) { |
| 156 | ThrowException("Invalid ASCII file header"); |
| 157 | } |
| 158 | ReadAsciiFile(scene, stream.get()); |
| 159 | } else { |
| 160 | ReadBinaryFile(scene, stream.get()); |
| 161 | } |
| 162 | if (scene.nodes.empty()) { |
| 163 | ThrowException("No nodes loaded"); |
| 164 | } |
| 165 | |
| 166 | // sort faces by material indices |
| 167 | for (std::shared_ptr<Node> &n : scene.nodes) { |
| 168 | if (n->type == Node::TYPE_MESH) { |
| 169 | Mesh &mesh = (Mesh &)(*n); |
| 170 | for (Face &f : mesh.faces) { |
| 171 | mesh.temp_map[f.material].push_back(&f); |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | // count meshes |
| 177 | for (std::shared_ptr<Node> &n : scene.nodes) { |
| 178 | if (n->type == Node::TYPE_MESH) { |
| 179 | Mesh &mesh = (Mesh &)(*n); |
| 180 | if (mesh.vertex_positions.size() && mesh.texture_coords.size()) { |
| 181 | pScene->mNumMeshes += static_cast<unsigned int>(mesh.temp_map.size()); |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | pScene->mMeshes = new aiMesh *[pScene->mNumMeshes](); |
| 186 | pScene->mMaterials = new aiMaterial *[pScene->mNumMeshes](); |
| 187 | pScene->mNumMeshes = 0; |
| 188 | |
| 189 | // count lights and cameras |
| 190 | for (std::shared_ptr<Node> &n : scene.nodes) { |
| 191 | if (n->type == Node::TYPE_LIGHT) { |
| 192 | ++pScene->mNumLights; |
| 193 | } else if (n->type == Node::TYPE_CAMERA) { |
| 194 | ++pScene->mNumCameras; |
| 195 | } |
nothing calls this directly
no test coverage detected