import/usd.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | #include "chrono_batch_render/import/usd.h" | ||
| 3 | |||
| 4 | #include <memory> | ||
| 5 | #include <string> | ||
| 6 | #include <vector> | ||
| 7 | |||
| 8 | #include <tinyusd/tinyusd.hpp> | ||
| 9 | |||
| 10 | #include "chrono_batch_render/util/error.h" | ||
| 11 | #include "chrono_batch_render/util/log.h" | ||
| 12 | |||
| 13 | namespace chrono::batch_render { | ||
| 14 | namespace { | ||
| 15 | |||
| 16 | ✗ | tinyusd::Stage Open(const ImportSource& source) { | |
| 17 | ✗ | try { | |
| 18 | ✗ | return tinyusd::Stage::open(source.file.string()); | |
| 19 | ✗ | } catch (const tinyusd::Error& error) { | |
| 20 | ✗ | throw Error("Reading USD \"{}\": tinyusd couldn't open it ({})", source.file.string(), | |
| 21 | ✗ | error.what()); | |
| 22 | ✗ | } | |
| 23 | } | ||
| 24 | |||
| 25 | void DefineMaterials(ImportPlan&, std::string_view, const tinyusd::Stage&) {} | ||
| 26 | |||
| 27 | void DefineMeshes(ImportPlan&, std::string_view, const tinyusd::Stage&) {} | ||
| 28 | |||
| 29 | void DefineXforms(ImportPlan&, std::string_view, const tinyusd::Stage&) {} | ||
| 30 | |||
| 31 | void DefineInstancers(ImportPlan&, std::string_view, const tinyusd::Stage&) {} | ||
| 32 | |||
| 33 | void DefineCameras(ImportPlan&, std::string_view, const tinyusd::Stage&) {} | ||
| 34 | |||
| 35 | void DefineLights(ImportPlan&, std::string_view, const tinyusd::Stage&) {} | ||
| 36 | |||
| 37 | 3 | class UsdImporter final : public Importer { | |
| 38 | public: | ||
| 39 | ✗ | std::string Name() const override { | |
| 40 | ✗ | return "USD"; | |
| 41 | } | ||
| 42 | |||
| 43 | 3 | std::vector<std::string> Extensions() const override { | |
| 44 | 3 | return {".usd", ".usda", ".usdc", ".usdz"}; | |
| 45 | } | ||
| 46 | |||
| 47 | ✗ | ImportPlan Read(std::string_view path, const ImportSource& source, | |
| 48 | ImportContext& context) override { | ||
| 49 | ✗ | context.Report("opening", 0, 1); | |
| 50 | ✗ | const tinyusd::Stage stage = Open(source); | |
| 51 | ✗ | context.Report("opening", 1, 1); | |
| 52 | |||
| 53 | ✗ | ImportPlan plan; | |
| 54 | ✗ | plan.Define<Xform>(std::string(path)); | |
| 55 | ✗ | DefineMaterials(plan, path, stage); | |
| 56 | ✗ | DefineMeshes(plan, path, stage); | |
| 57 | ✗ | DefineXforms(plan, path, stage); | |
| 58 | ✗ | DefineInstancers(plan, path, stage); | |
| 59 | ✗ | DefineCameras(plan, path, stage); | |
| 60 | ✗ | DefineLights(plan, path, stage); | |
| 61 | ✗ | Log(LogLevel::Warning, | |
| 62 | "the USD importer is a placeholder, so \"{}\" imports as an empty Xform", | ||
| 63 | ✗ | source.file.string()); | |
| 64 | ✗ | return plan; | |
| 65 | ✗ | } | |
| 66 | }; | ||
| 67 | |||
| 68 | } | ||
| 69 | |||
| 70 | 3 | std::shared_ptr<Importer> CreateUsdImporter() { | |
| 71 | 3 | return std::make_shared<UsdImporter>(); | |
| 72 | } | ||
| 73 | |||
| 74 | } | ||
| 75 |