| 127 | }; |
| 128 | |
| 129 | bool LoadMesh(std::string const & pathToMesh, bool isDefaultResource, TLoadingCompletion const & completionHandler, |
| 130 | TLoadingFailure const & failureHandler) |
| 131 | { |
| 132 | CHECK(completionHandler != nullptr, ()); |
| 133 | CHECK(failureHandler != nullptr, ()); |
| 134 | |
| 135 | fastObjMesh * meshData = nullptr; |
| 136 | try |
| 137 | { |
| 138 | ReaderPtr<Reader> reader = |
| 139 | isDefaultResource ? GetStyleReader().GetDefaultResourceReader(pathToMesh) : GetPlatform().GetReader(pathToMesh); |
| 140 | ReaderSource source(reader); |
| 141 | |
| 142 | // Read OBJ file. |
| 143 | fastObjCallbacks callbacks; |
| 144 | callbacks.file_open = fast_obj_adapter::FileOpen; |
| 145 | callbacks.file_close = fast_obj_adapter::FileClose; |
| 146 | callbacks.file_read = fast_obj_adapter::FileRead; |
| 147 | callbacks.file_size = fast_obj_adapter::FileSize; |
| 148 | meshData = fast_obj_read_with_callbacks(kMainFileId.data(), &callbacks, &source); |
| 149 | CHECK(meshData != nullptr, ()); |
| 150 | FastObjMeshGuard guard(meshData); |
| 151 | |
| 152 | // Fill buffers. |
| 153 | std::vector<float> positions; |
| 154 | if (meshData->position_count > 1) |
| 155 | positions.resize(meshData->index_count * kComponentsInVertex); |
| 156 | |
| 157 | std::vector<float> normals; |
| 158 | if (meshData->normal_count > 1) |
| 159 | normals.resize(meshData->index_count * kComponentsInNormal); |
| 160 | |
| 161 | std::vector<float> texCoords; |
| 162 | if (meshData->texcoord_count > 1) |
| 163 | texCoords.resize(meshData->index_count * kComponentsInTexCoord); |
| 164 | |
| 165 | for (uint32_t i = 0; i < meshData->index_count; ++i) |
| 166 | { |
| 167 | if (meshData->position_count > 1) |
| 168 | { |
| 169 | memcpy(&positions[i * kComponentsInVertex], &meshData->positions[meshData->indices[i].p * kComponentsInVertex], |
| 170 | sizeof(float) * kComponentsInVertex); |
| 171 | } |
| 172 | |
| 173 | if (meshData->normal_count > 1) |
| 174 | { |
| 175 | memcpy(&normals[i * kComponentsInNormal], &meshData->normals[meshData->indices[i].n * kComponentsInNormal], |
| 176 | sizeof(float) * kComponentsInNormal); |
| 177 | } |
| 178 | |
| 179 | if (meshData->texcoord_count > 1) |
| 180 | { |
| 181 | memcpy(&texCoords[i * kComponentsInTexCoord], |
| 182 | &meshData->texcoords[meshData->indices[i].t * kComponentsInTexCoord], |
| 183 | sizeof(float) * kComponentsInTexCoord); |
| 184 | } |
| 185 | } |
| 186 |
no test coverage detected