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