Skip to content

Commit 5e58b72

Browse files
authored
Merge branch 'sdf12' into ahcorde/usd_to_sdf_transforms
2 parents e2acde3 + e8de24e commit 5e58b72

File tree

4 files changed

+84
-5
lines changed

4 files changed

+84
-5
lines changed

usd/src/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,9 @@ if (TARGET UNIT_Light_Sdf2Usd_TEST)
9494
${sdf2usd_test_sources})
9595
endif()
9696

97+
if (TARGET UNIT_Material_Sdf2Usd_TEST)
98+
target_sources(UNIT_Material_Sdf2Usd_TEST PRIVATE
99+
${sdf2usd_test_sources})
100+
endif()
101+
97102
add_subdirectory(cmd)

usd/src/Conversions.cc

+14-5
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,14 @@ namespace sdf
4343
out.SetNormalMap(pbr->NormalMap());
4444
sdf::Pbr pbrOut;
4545
sdf::PbrWorkflow pbrWorkflow;
46-
pbrWorkflow.SetAlbedoMap(pbr->AlbedoMap());
46+
if (!pbr->AlbedoMap().empty())
47+
{
48+
pbrWorkflow.SetAlbedoMap(pbr->AlbedoMap());
49+
}
50+
else
51+
{
52+
pbrWorkflow.SetAlbedoMap(_in->TextureImage());
53+
}
4754
pbrWorkflow.SetMetalnessMap(pbr->MetalnessMap());
4855
pbrWorkflow.SetEmissiveMap(pbr->EmissiveMap());
4956
pbrWorkflow.SetRoughnessMap(pbr->RoughnessMap());
@@ -66,13 +73,15 @@ namespace sdf
6673
pbr->NormalMap(), sdf::NormalMapSpace::OBJECT);
6774
}
6875

69-
if (pbr->Type() == ignition::common::PbrType::METAL)
76+
if (pbr->Type() == ignition::common::PbrType::SPECULAR)
7077
{
71-
pbrOut.SetWorkflow(sdf::PbrWorkflowType::METAL, pbrWorkflow);
78+
pbrWorkflow.SetType(sdf::PbrWorkflowType::SPECULAR);
79+
pbrOut.SetWorkflow(sdf::PbrWorkflowType::SPECULAR, pbrWorkflow);
7280
}
73-
else if (pbr->Type() == ignition::common::PbrType::SPECULAR)
81+
else
7482
{
75-
pbrOut.SetWorkflow(sdf::PbrWorkflowType::SPECULAR, pbrWorkflow);
83+
pbrWorkflow.SetType(sdf::PbrWorkflowType::METAL);
84+
pbrOut.SetWorkflow(sdf::PbrWorkflowType::METAL, pbrWorkflow);
7685
}
7786
out.SetPbrMaterial(pbrOut);
7887
}

usd/src/sdf_parser/Material.cc

+1
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ namespace usd
192192
sdf::usd::UsdErrorCode::INVALID_PRIM_PATH,
193193
"Not able to cast the UsdShadeShader at path [" + shaderPath.GetString()
194194
+ "] to a Prim"));
195+
return errors;
195196
}
196197

197198
auto shaderOut = pxr::UsdShadeConnectableAPI(shaderPrim).CreateOutput(

usd/src/sdf_parser/Material_Sdf2Usd_TEST.cc

+64
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include <gtest/gtest.h>
1919

20+
#include <ignition/common/Material.hh>
2021
#include <ignition/common/Util.hh>
2122

2223
// TODO(ahcorde) this is to remove deprecated "warnings" in usd, these warnings
@@ -29,11 +30,16 @@
2930
#include <pxr/usd/usd/stage.h>
3031
#pragma pop_macro ("__DEPRECATED")
3132

33+
#include "Material.hh"
34+
35+
#include "sdf/usd/UsdError.hh"
3236
#include "sdf/usd/sdf_parser/World.hh"
37+
#include "sdf/Material.hh"
3338
#include "sdf/Root.hh"
3439
#include "test_config.h"
3540
#include "test_utils.hh"
3641
#include "../UsdTestUtils.hh"
42+
#include "../Conversions.hh"
3743

3844
void CheckMaterial(
3945
const pxr::UsdPrim &_prim,
@@ -183,6 +189,64 @@ class UsdStageFixture : public::testing::Test
183189
public: pxr::UsdStageRefPtr stage;
184190
};
185191

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+
186250
/////////////////////////////////////////////////
187251
TEST_F(UsdStageFixture, Material)
188252
{

0 commit comments

Comments
 (0)