chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
5 / 32
15.6%
Branches:
1 / 19
5.3%
Functions:
2 / 5
40.0%

import/gltf.cpp
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 #include "chrono_batch_render/import/gltf.h"
3
4 #include <memory>
5 #include <string>
6
7 #include <cgltf.h>
8
9 #include "chrono_batch_render/util/error.h"
10 #include "chrono_batch_render/util/log.h"
11
12 namespace chrono::batch_render {
13 namespace {
14
15 using GltfData = std::unique_ptr<cgltf_data, decltype(&cgltf_free)>;
16
17 ✗ GltfData Parse(const ImportSource& source) {
18 ✗ const FileBytes bytes = source.ReadEntry();
19 ✗ const cgltf_options options{};
20 ✗ cgltf_data* data = nullptr;
21
0/3
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ if (const cgltf_result result = cgltf_parse(&options, bytes->data(), bytes->size(), &data);
22 result != cgltf_result_success) {
23 ✗ throw Error("Reading glTF \"{}\": cgltf couldn't parse it (result {})",
24
0/2
✗ Branch 2 not taken.
✗ Branch 5 not taken.
✗ source.file.string(), int(result));
25 }
26
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ return {data, cgltf_free};
27 ✗ }
28
29 void LoadBuffers(const cgltf_data&, const ImportSource&) {}
30
31 void DefineMaterials(ImportPlan&, std::string_view, const cgltf_data&) {}
32
33 void DefineMeshes(ImportPlan&, std::string_view, const cgltf_data&) {}
34
35 void DefineNodes(ImportPlan&, std::string_view, const cgltf_data&) {}
36
37 void DefineCameras(ImportPlan&, std::string_view, const cgltf_data&) {}
38
39 void DefineLights(ImportPlan&, std::string_view, const cgltf_data&) {}
40
41 3 class GltfImporter final : public Importer {
42 public:
43 ✗ std::string Name() const override {
44 ✗ return "glTF";
45 }
46
47 3 std::vector<std::string> Extensions() const override {
48 3 return {".gltf", ".glb"};
49 }
50
51 ✗ ImportPlan Read(std::string_view path, const ImportSource& source,
52 ImportContext& context) override {
53 ✗ context.Report("parsing", 0, 1);
54 ✗ const GltfData data = Parse(source);
55
0/1
✗ Branch 1 not taken.
✗ LoadBuffers(*data, source);
56
0/3
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ context.Report("parsing", 1, 1);
57
58 ✗ ImportPlan plan;
59
0/1
✗ Branch 1 not taken.
✗ plan.Define<Xform>(std::string(path));
60
0/1
✗ Branch 1 not taken.
✗ DefineMaterials(plan, path, *data);
61 ✗ DefineMeshes(plan, path, *data);
62 ✗ DefineNodes(plan, path, *data);
63 ✗ DefineCameras(plan, path, *data);
64 ✗ DefineLights(plan, path, *data);
65 ✗ Log(LogLevel::Warning,
66 "the glTF importer is a placeholder, so \"{}\" imports as an empty Xform",
67
0/2
✗ Branch 1 not taken.
✗ Branch 4 not taken.
✗ source.file.string());
68
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ return plan;
69 ✗ }
70 };
71
72 }
73
74 3 std::shared_ptr<Importer> CreateGltfImporter() {
75
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
3 return std::make_shared<GltfImporter>();
76 }
77
78 }
79