Blender V4.3
usd_imaging_test.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4#include "testing/testing.h"
5
6#include <pxr/usd/usd/stage.h>
7#include <pxr/usd/usdGeom/capsule.h>
8#include <pxr/usdImaging/usdImaging/capsuleAdapter.h>
9
10namespace blender::io::usd {
11
12class USDImagingTest : public testing::Test {};
13
14TEST_F(USDImagingTest, CapsuleAdapterTest)
15{
16 /* A simple test to exercise the UsdImagingGprimAdapter API to
17 * ensure the code compiles, links and returns reasonable results.
18 * We create a capsule shape on an in-memory stage and attempt
19 * to access the shape's points and topology. */
20
21 pxr::UsdStageRefPtr stage = pxr::UsdStage::CreateInMemory();
22
23 if (!stage) {
24 FAIL() << "Couldn't create in-memory stage.";
25 return;
26 }
27
28 pxr::UsdGeomCapsule capsule = pxr::UsdGeomCapsule::Define(stage, pxr::SdfPath("/Capsule"));
29
30 if (!capsule) {
31 FAIL() << "Couldn't create UsdGeomCapsule.";
32 return;
33 }
34
35 pxr::UsdImagingCapsuleAdapter capsule_adapter;
36 pxr::VtValue points_value = capsule_adapter.GetPoints(capsule.GetPrim(),
37 pxr::UsdTimeCode::Default());
38 if (!points_value.IsHolding<pxr::VtArray<pxr::GfVec3f>>()) {
39 FAIL() << "Mesh points value holding unexpected type.";
40 return;
41 }
42
43 pxr::VtArray<pxr::GfVec3f> points = points_value.Get<pxr::VtArray<pxr::GfVec3f>>();
44 EXPECT_FALSE(points.empty());
45
46 pxr::VtValue topology_value = capsule_adapter.GetTopology(
47 capsule.GetPrim(), pxr::SdfPath(), pxr::UsdTimeCode::Default());
48
49 if (!topology_value.IsHolding<pxr::HdMeshTopology>()) {
50 FAIL() << "Mesh topology value holding unexpected type.";
51 return;
52 }
53
54 pxr::HdMeshTopology topology = topology_value.Get<pxr::HdMeshTopology>();
55
56 pxr::VtArray<int> vertex_counts = topology.GetFaceVertexCounts();
57 EXPECT_FALSE(vertex_counts.empty());
58
59 pxr::VtArray<int> vertex_indices = topology.GetFaceVertexIndices();
60 EXPECT_FALSE(vertex_indices.empty());
61}
62
63} // namespace blender::io::usd
EvaluationStage stage
Definition deg_eval.cc:83
TEST_F(UsdCurvesTest, usd_export_curves)