| 378 | } |
| 379 | |
| 380 | uint32_t SDFGrid::loadPrimitivesFromFile(const std::filesystem::path& path, uint32_t gridWidth) |
| 381 | { |
| 382 | std::ifstream ifs(path); |
| 383 | if (!ifs.good()) |
| 384 | { |
| 385 | logWarning("Failed to open SDF grid file '{}' for reading.", path); |
| 386 | return false; |
| 387 | } |
| 388 | |
| 389 | std::vector<SDF3DPrimitive> primitives; |
| 390 | try |
| 391 | { |
| 392 | json j = json::parse(ifs); |
| 393 | primitives = j; |
| 394 | } |
| 395 | catch (const std::exception& e) |
| 396 | { |
| 397 | logWarning("Error when deserializing SDF grid from '{}': {}", path, e.what()); |
| 398 | return 0; |
| 399 | } |
| 400 | |
| 401 | setPrimitives(primitives, gridWidth); |
| 402 | |
| 403 | mInitializedWithPrimitives = true; |
| 404 | return (uint32_t)mPrimitives.size(); |
| 405 | } |
| 406 | |
| 407 | bool SDFGrid::writePrimitivesToFile(const std::filesystem::path& path) |
| 408 | { |
no test coverage detected