|
17 | 17 |
|
18 | 18 | #include <gtest/gtest.h>
|
19 | 19 |
|
| 20 | +#include <ignition/common/Material.hh> |
20 | 21 | #include <ignition/common/Util.hh>
|
21 | 22 |
|
22 | 23 | // TODO(ahcorde) this is to remove deprecated "warnings" in usd, these warnings
|
|
29 | 30 | #include <pxr/usd/usd/stage.h>
|
30 | 31 | #pragma pop_macro ("__DEPRECATED")
|
31 | 32 |
|
| 33 | +#include "Material.hh" |
| 34 | + |
| 35 | +#include "sdf/usd/UsdError.hh" |
32 | 36 | #include "sdf/usd/sdf_parser/World.hh"
|
| 37 | +#include "sdf/Material.hh" |
33 | 38 | #include "sdf/Root.hh"
|
34 | 39 | #include "test_config.h"
|
35 | 40 | #include "test_utils.hh"
|
36 | 41 | #include "../UsdTestUtils.hh"
|
| 42 | +#include "../Conversions.hh" |
37 | 43 |
|
38 | 44 | void CheckMaterial(
|
39 | 45 | const pxr::UsdPrim &_prim,
|
@@ -183,6 +189,64 @@ class UsdStageFixture : public::testing::Test
|
183 | 189 | public: pxr::UsdStageRefPtr stage;
|
184 | 190 | };
|
185 | 191 |
|
| 192 | +TEST_F(UsdStageFixture, MaterialTextureName) |
| 193 | +{ |
| 194 | + sdf::testing::ScopeExit removeCopiedMaterials( |
| 195 | + [] |
| 196 | + { |
| 197 | + ignition::common::removeAll( |
| 198 | + ignition::common::joinPaths(ignition::common::cwd(), "materials")); |
| 199 | + }); |
| 200 | + |
| 201 | + sdf::setFindCallback(sdf::usd::testing::findFileCb); |
| 202 | + ignition::common::addFindFileURICallback( |
| 203 | + std::bind(&sdf::usd::testing::FindResourceUri, std::placeholders::_1)); |
| 204 | + const auto path = sdf::testing::TestFile("sdf", "basic_shapes.sdf"); |
| 205 | + |
| 206 | + ignition::common::Material materialCommon; |
| 207 | + materialCommon.SetTextureImage("materials/textures/albedo_map.png"); |
| 208 | + |
| 209 | + const sdf::Material materialSdf = sdf::usd::convert(&materialCommon); |
| 210 | + |
| 211 | + const auto materialPathStr = std::string("/Looks/Material_0"); |
| 212 | + auto materialPath = pxr::SdfPath(materialPathStr); |
| 213 | + |
| 214 | + sdf::usd::UsdErrors errors = sdf::usd::ParseSdfMaterial(&materialSdf, |
| 215 | + stage, materialPath); |
| 216 | + EXPECT_TRUE(errors.empty()); |
| 217 | + |
| 218 | + { |
| 219 | + ASSERT_TRUE(this->stage->GetPrimAtPath(materialPath)); |
| 220 | + |
| 221 | + const std::string materialshaderPath = materialPathStr + "/Shader"; |
| 222 | + const auto materialShaderPrim = this->stage->GetPrimAtPath( |
| 223 | + pxr::SdfPath(materialshaderPath)); |
| 224 | + ASSERT_TRUE(materialShaderPrim); |
| 225 | + |
| 226 | + auto variantshader = pxr::UsdShadeShader(materialShaderPrim); |
| 227 | + ASSERT_TRUE(variantshader); |
| 228 | + |
| 229 | + std::vector<pxr::UsdShadeInput> inputs = variantshader.GetInputs(); |
| 230 | + |
| 231 | + bool checkedTextureInput = false; |
| 232 | + for (const auto &input : inputs) |
| 233 | + { |
| 234 | + if (input.GetBaseName() == "diffuse_texture") |
| 235 | + { |
| 236 | + pxr::SdfAssetPath materialPathUSD; |
| 237 | + pxr::UsdShadeInput diffuseTextureShaderInput = |
| 238 | + variantshader.GetInput(pxr::TfToken("diffuse_texture")); |
| 239 | + diffuseTextureShaderInput.Get(&materialPathUSD); |
| 240 | + EXPECT_EQ("materials/textures/albedo_map.png", |
| 241 | + materialPathUSD.GetAssetPath()); |
| 242 | + checkedTextureInput = true; |
| 243 | + break; |
| 244 | + } |
| 245 | + } |
| 246 | + EXPECT_TRUE(checkedTextureInput); |
| 247 | + } |
| 248 | +} |
| 249 | + |
186 | 250 | /////////////////////////////////////////////////
|
187 | 251 | TEST_F(UsdStageFixture, Material)
|
188 | 252 | {
|
|
0 commit comments