| Line |
Branch |
Exec |
Source |
| 1 |
|
|
// SPDX-License-Identifier: BSD-3-Clause |
| 2 |
|
|
/// @file shade.cpp |
| 3 |
|
|
/// @brief UsdShade's registry entries and connections. |
| 4 |
|
|
#include "ernie/scene/schema/shade.h" |
| 5 |
|
|
|
| 6 |
|
|
#include <stdexcept> |
| 7 |
|
|
|
| 8 |
|
|
namespace ernie { |
| 9 |
|
|
namespace { |
| 10 |
|
|
|
| 11 |
|
|
constexpr std::string_view kConnect = ".connect"; |
| 12 |
|
|
|
| 13 |
|
|
/// Inputs and outputs are open on every connectable prim, as UsdShadeConnectableAPI makes them. |
| 14 |
|
|
#define ERNIE_CONNECTABLE .openNamespaces = {"inputs:", "outputs:"} |
| 15 |
|
|
|
| 16 |
|
10 |
std::string ConnectionAttribute(std::string_view input) { |
| 17 |
2/4
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 10 times.
✗ Branch 6 not taken.
|
20 |
return std::string(input) + std::string(kConnect); |
| 18 |
|
|
} |
| 19 |
|
|
|
| 20 |
|
|
} // namespace |
| 21 |
|
|
|
| 22 |
8/14
✓ Branch 0 taken 146 times.
✓ Branch 1 taken 14 times.
✓ Branch 3 taken 146 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 146 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 146 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 146 times.
✗ Branch 13 not taken.
✓ Branch 16 taken 146 times.
✓ Branch 17 taken 146 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
452 |
ERNIE_DEFINE_SCHEMA(MaterialBindingAPI, SingleApply, kInheritExtent, |
| 23 |
|
|
ERNIE_MATERIAL_BINDING_API_ATTRIBUTES, .openNamespaces = {"material:binding:"}) |
| 24 |
4/6
✓ Branch 0 taken 146 times.
✓ Branch 1 taken 147 times.
✓ Branch 3 taken 146 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 146 times.
✗ Branch 7 not taken.
|
293 |
ERNIE_DEFINE_SCHEMA(NodeGraph, Concrete, kNoExtent, ERNIE_NO_ATTRIBUTES, ERNIE_CONNECTABLE) |
| 25 |
4/6
✓ Branch 0 taken 146 times.
✓ Branch 1 taken 8 times.
✓ Branch 3 taken 146 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 146 times.
✗ Branch 7 not taken.
|
154 |
ERNIE_DEFINE_SCHEMA(Material, Concrete, kInheritExtent, ERNIE_NO_ATTRIBUTES) |
| 26 |
12/24
✓ Branch 0 taken 146 times.
✓ Branch 1 taken 13 times.
✓ Branch 3 taken 146 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 146 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 146 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 146 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 146 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 146 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 146 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 146 times.
✗ Branch 25 not taken.
✓ Branch 28 taken 584 times.
✓ Branch 29 taken 146 times.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
|
1327 |
ERNIE_DEFINE_SCHEMA(Shader, Concrete, kNoExtent, ERNIE_SHADER_ATTRIBUTES, ERNIE_CONNECTABLE) |
| 27 |
|
|
|
| 28 |
|
6 |
void Connect(Scene& scene, const Path& path, std::string_view input, const Connection& source) { |
| 29 |
3/6
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 6 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
|
18 |
scene.Set(path, ConnectionAttribute(input), source.prim.String() + "." + source.output); |
| 30 |
|
6 |
} |
| 31 |
|
|
|
| 32 |
|
3 |
std::optional<Connection> FindConnection(const Scene& scene, const Path& path, |
| 33 |
|
|
std::string_view input) { |
| 34 |
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 |
const std::optional<Value> value = scene.Get(path, ConnectionAttribute(input)); |
| 35 |
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 2 times.
|
3 |
if (!value) { |
| 36 |
|
1 |
return std::nullopt; |
| 37 |
|
|
} |
| 38 |
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 |
const std::string& text = *value->Get<std::string>(); |
| 39 |
|
2 |
const std::size_t dot = |
| 40 |
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 |
text.find('.', text.rfind('/') == std::string::npos ? 0 : text.rfind('/')); |
| 41 |
3/4
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 time.
|
2 |
if (dot == std::string::npos || dot + 1 == text.size()) { |
| 42 |
3/6
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 time.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 8 not taken.
|
3 |
throw std::invalid_argument("'" + path.String() + "': " + ConnectionAttribute(input) + |
| 43 |
1/2
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
|
2 |
" must be a prim path, a dot and a property, not '" + text + |
| 44 |
1/2
✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
|
3 |
"'"); |
| 45 |
|
|
} |
| 46 |
3/6
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 time.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 8 not taken.
|
3 |
return Connection{Path(text.substr(0, dot)), text.substr(dot + 1)}; |
| 47 |
|
2 |
} |
| 48 |
|
|
|
| 49 |
|
|
} // namespace ernie |
| 50 |
|
|
|