chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
5 / 30
16.7%
Branches:
1 / 16
6.2%
Functions:
2 / 5
40.0%

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
0/2
✗ Branch 1 not taken.
✗ Branch 4 not taken.
✗ return tinyusd::Stage::open(source.file.string());
19
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ } catch (const tinyusd::Error& error) {
20 ✗ throw Error("Reading USD \"{}\": tinyusd couldn't open it ({})", source.file.string(),
21
0/2
✗ Branch 3 not taken.
✗ Branch 6 not taken.
✗ 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
0/3
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ context.Report("opening", 1, 1);
52
53 ✗ ImportPlan plan;
54
0/1
✗ Branch 1 not taken.
✗ 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
0/2
✗ Branch 1 not taken.
✗ Branch 4 not taken.
✗ source.file.string());
64
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ return plan;
65 ✗ }
66 };
67
68 }
69
70 3 std::shared_ptr<Importer> CreateUsdImporter() {
71
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
3 return std::make_shared<UsdImporter>();
72 }
73
74 }
75