Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdf -> usd: Materials #831

Merged
merged 38 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
9dfc9f2
sdf -> usd Parse links
ahcorde Jan 25, 2022
ffaf2f4
sdf -> usd: Added Visual and geometries
ahcorde Jan 26, 2022
2e3a060
sdf -> usd: Materials
ahcorde Jan 26, 2022
0a5a9a7
Fixed test
ahcorde Jan 26, 2022
071dc4b
Merge remote-tracking branch 'origin/ahcorde/sdf_to_usd_visuals' into…
ahcorde Jan 26, 2022
89daa0d
review feedback
adlarkin Jan 27, 2022
f48b35b
dont segfault when mesh failed to load
Jan 31, 2022
d932e90
fix error reporting
Jan 31, 2022
54b35e9
Merge branch 'sdf12' into ahcorde/sdf_to_usd_links
ahcorde Feb 1, 2022
f0331ca
Fixed scale and submesh name
ahcorde Feb 10, 2022
e85f60c
Merge remote-tracking branch 'origin/sdf12' into ahcorde/sdf_to_usd_l…
ahcorde Feb 14, 2022
a02a6e1
Use UsdError
ahcorde Feb 14, 2022
f898d26
codecheck, use USD component's visibility macro, properly construct w…
adlarkin Feb 14, 2022
258606c
Merge branch 'ahcorde/sdf_to_usd_links' into ahcorde/sdf_to_usd_visuals
adlarkin Feb 15, 2022
c43ba24
usd UsdErrors and USD component visibility
adlarkin Feb 15, 2022
f816dd4
Merge branch 'sdf12' into ahcorde/sdf_to_usd_links
adlarkin Feb 15, 2022
6f3490e
Merge branch 'ahcorde/sdf_to_usd_links' into ahcorde/sdf_to_usd_visuals
adlarkin Feb 15, 2022
379defd
review feedback
adlarkin Feb 17, 2022
0f4075f
Merge branch 'sdf12' into ahcorde/sdf_to_usd_visuals
adlarkin Feb 18, 2022
a98d481
Merge branch 'sdf12' into ahcorde/sdf_to_usd_visuals
adlarkin Feb 18, 2022
0cb1cc0
Merge branch 'sdf12' into ahcorde/sdf_to_usd_visuals
ahcorde Feb 18, 2022
00a55c5
Merge branch 'sdf12' into ahcorde/sdf_to_usd_visuals
ahcorde Feb 21, 2022
5ac37f7
Merge remote-tracking branch 'origin/ahcorde/sdf_to_usd_visuals' into…
ahcorde Feb 21, 2022
2085347
Merge branch 'sdf12' into ahcorde/sdf_to_usd_materials
ahcorde Feb 24, 2022
94969a0
Merge branch 'sdf12' into ahcorde/sdf_to_usd_materials
ahcorde Feb 25, 2022
361c569
Merge branch 'sdf12' into ahcorde/sdf_to_usd_materials
adlarkin Feb 25, 2022
c7114f8
Merge branch 'sdf12' into ahcorde/sdf_to_usd_materials
ahcorde Feb 25, 2022
7130c1f
initial review feedback
adlarkin Feb 25, 2022
14354fb
feedback
ahcorde Feb 28, 2022
430579f
more review feedback
adlarkin Mar 1, 2022
e40448f
Added feedback
ahcorde Mar 1, 2022
a603603
Fixed typo and docs
ahcorde Mar 1, 2022
67c54df
Merge branch 'sdf12' into ahcorde/sdf_to_usd_materials
scpeters Mar 2, 2022
830c11a
Feedback
ahcorde Mar 3, 2022
5f33b20
Merge branch 'sdf12' into ahcorde/sdf_to_usd_materials
ahcorde Mar 3, 2022
cdc0257
review feedback
adlarkin Mar 3, 2022
8b97a1c
common -> sdf material: use const raw pointer, not std::shared_ptr
adlarkin Mar 3, 2022
3095a50
sdf -> common material conversion: don't use std::shared_ptr
adlarkin Mar 3, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions test/sdf/basic_shapes.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@
<length>0.1</length>
</capsule>
</geometry>
<material>
<diffuse>0 0.1 0.2</diffuse>
<emissive>0.12 0.23 0.34 0.56</emissive>
</material>
</visual>
</link>
</model>
Expand All @@ -136,6 +140,18 @@
<scale>1.2 2.3 3.4</scale>
</mesh>
</geometry>
<material>
<diffuse>0.2 0.5 0.1 1.0</diffuse>
<specular>0.7 0.3 0.5 0.9</specular>
<pbr>
<metal>
<albedo_map>albedo_map.png</albedo_map>
<normal_map>normal_map.png</normal_map>
<roughness_map>roughness_map.png</roughness_map>
<metalness_map>metalness_map.png</metalness_map>
</metal>
</pbr>
</material>
</visual>
</link>
</model>
Expand Down
54 changes: 54 additions & 0 deletions usd/include/sdf/usd/Conversions.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2022 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/


#ifndef SDF_USD_CONVERSIONS_HH_
#define SDF_USD_CONVERSIONS_HH_

#include <memory>

#include <ignition/common/Material.hh>

#include "sdf/Material.hh"
#include "sdf/sdf_config.h"
#include "sdf/usd/Export.hh"

namespace sdf
{
// Inline bracket to help doxygen filtering.
inline namespace SDF_VERSION_NAMESPACE {
//
namespace usd
{
/// \brief Specialized conversion from an Ignition Common Material
/// to a SDF material
/// \param[in] _in Ignition Common Material.
/// \return SDF material.
IGNITION_SDFORMAT_USD_VISIBLE
sdf::Material convert(const ignition::common::Material *_in);

/// \brief Specialized conversion from an SDF material to a Ignition Common
/// material.
/// \param[in] _in SDF material.
/// \param[out] _out The Ignition Common Material.
IGNITION_SDFORMAT_USD_VISIBLE
void convert(const sdf::Material &_in, ignition::common::Material &_out);
}
}
}

#endif
3 changes: 3 additions & 0 deletions usd/include/sdf/usd/UsdError.hh
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ namespace sdf

/// \brief Invalid submesh primitive type
INVALID_SUBMESH_PRIMITIVE_TYPE,

/// \brief Invalid material
INVALID_MATERIAL,
};

class IGNITION_SDFORMAT_USD_VISIBLE UsdError
Expand Down
60 changes: 60 additions & 0 deletions usd/include/sdf/usd/sdf_parser/Material.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (C) 2022 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#ifndef SDF_USD_SDF_PARSER_MATERIALS_HH_
#define SDF_USD_SDF_PARSER_MATERIALS_HH_

// TODO(ahcorde) this is to remove deprecated "warnings" in usd, these warnings
// are reported using #pragma message so normal diagnostic flags cannot remove
// them. This workaround requires this block to be used whenever usd is
// included.
#pragma push_macro ("__DEPRECATED")
#undef __DEPRECATED
#include <pxr/usd/sdf/path.h>
#include <pxr/usd/usd/stage.h>
#include <pxr/usd/usdShade/material.h>
#pragma pop_macro ("__DEPRECATED")

#include "sdf/Material.hh"
#include "sdf/usd/Export.hh"
#include "sdf/usd/UsdError.hh"
#include "sdf/sdf_config.h"

namespace sdf
{
// Inline bracket to help doxygen filtering.
inline namespace SDF_VERSION_NAMESPACE {
//
namespace usd
{
/// \brief Parse an SDF material into a USD stage.
/// \param[in] _materialSdf The SDF material to parse.
/// \param[in] _stage The stage that should contain the USD representation
/// of _material.
/// \param[out] _materialPath USD Material path
/// \return UsdErrors, which is a list of UsdError objects. This list is
/// empty if no errors occurred when parsing _materialSdf its USD
/// representation
UsdErrors IGNITION_SDFORMAT_USD_VISIBLE ParseSdfMaterial(
const sdf::Material *_materialSdf,
pxr::UsdStageRefPtr &_stage,
pxr::SdfPath &_materialPath);
}
}
}

#endif
4 changes: 4 additions & 0 deletions usd/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
set(sources
Conversions.cc
UsdError.cc
sdf_parser/Geometry.cc
sdf_parser/Joint.cc
sdf_parser/Light.cc
sdf_parser/Link.cc
sdf_parser/Material.cc
sdf_parser/Model.cc
sdf_parser/Sensor.cc
sdf_parser/Visual.cc
Expand All @@ -30,11 +32,13 @@ set(gtest_sources
sdf_parser/Joint_Sdf2Usd_TEST.cc
sdf_parser/Light_Sdf2Usd_TEST.cc
sdf_parser/Link_Sdf2Usd_TEST.cc
sdf_parser/Material_Sdf2Usd_TEST.cc
# TODO(adlarkin) add a test for SDF -> USD models once model parsing
# functionality is complete
sdf_parser/Sensors_Sdf2Usd_TEST.cc
sdf_parser/Visual_Sdf2Usd_TEST.cc
sdf_parser/World_Sdf2Usd_TEST.cc
Conversions_TEST.cc
UsdError_TEST.cc
UsdUtils_TEST.cc
)
Expand Down
152 changes: 152 additions & 0 deletions usd/src/Conversions.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/*
* Copyright 2022 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#include "sdf/usd/Conversions.hh"

#include <ignition/common/Pbr.hh>

#include "sdf/Pbr.hh"

namespace sdf
{
inline namespace SDF_VERSION_NAMESPACE {
//
namespace usd
{
sdf::Material convert(const ignition::common::Material *_in)
{
sdf::Material out;
out.SetEmissive(_in->Emissive());
out.SetDiffuse(_in->Diffuse());
out.SetSpecular(_in->Specular());
out.SetAmbient(_in->Ambient());
out.SetRenderOrder(_in->RenderOrder());
out.SetLighting(_in->Lighting());
out.SetDoubleSided(_in->TwoSidedEnabled());
const ignition::common::Pbr * pbr = _in->PbrMaterial();
if (pbr != nullptr)
{
out.SetNormalMap(pbr->NormalMap());
sdf::Pbr pbrOut;
sdf::PbrWorkflow pbrWorkflow;
pbrWorkflow.SetAlbedoMap(pbr->AlbedoMap());
pbrWorkflow.SetMetalnessMap(pbr->MetalnessMap());
pbrWorkflow.SetEmissiveMap(pbr->EmissiveMap());
pbrWorkflow.SetRoughnessMap(pbr->RoughnessMap());
pbrWorkflow.SetSpecularMap(pbr->SpecularMap());
pbrWorkflow.SetEnvironmentMap(pbr->EnvironmentMap());
pbrWorkflow.SetAmbientOcclusionMap(pbr->AmbientOcclusionMap());
pbrWorkflow.SetLightMap(pbr->LightMap());
pbrWorkflow.SetRoughness(pbr->Roughness());
pbrWorkflow.SetGlossiness(pbr->Glossiness());
pbrWorkflow.SetMetalness(pbr->Metalness());

if (pbr->NormalMapType() == ignition::common::NormalMapSpace::TANGENT)
{
pbrWorkflow.SetNormalMap(
pbr->NormalMap(), sdf::NormalMapSpace::TANGENT);
}
else
{
pbrWorkflow.SetNormalMap(
pbr->NormalMap(), sdf::NormalMapSpace::OBJECT);
}

if (pbr->Type() == ignition::common::PbrType::METAL)
{
pbrOut.SetWorkflow(sdf::PbrWorkflowType::METAL, pbrWorkflow);
}
else if (pbr->Type() == ignition::common::PbrType::SPECULAR)
{
pbrOut.SetWorkflow(sdf::PbrWorkflowType::SPECULAR, pbrWorkflow);
}
out.SetPbrMaterial(pbrOut);
}
else if (!_in->TextureImage().empty())
{
sdf::Pbr pbrOut;
sdf::PbrWorkflow pbrWorkflow;
pbrWorkflow.SetAlbedoMap(_in->TextureImage());
pbrOut.SetWorkflow(sdf::PbrWorkflowType::SPECULAR, pbrWorkflow);
out.SetPbrMaterial(pbrOut);
}

return out;
}

void convert(const sdf::Material &_in, ignition::common::Material &_out)
{
_out.SetEmissive(_in.Emissive());
_out.SetDiffuse(_in.Diffuse());
_out.SetSpecular(_in.Specular());
_out.SetAmbient(_in.Ambient());
_out.SetRenderOrder(_in.RenderOrder());
_out.SetLighting(_in.Lighting());
_out.SetAlphaFromTexture(false, 0.5, _in.DoubleSided());

const sdf::Pbr * pbr = _in.PbrMaterial();
if (pbr != nullptr)
{
ignition::common::Pbr pbrOut;

const sdf::PbrWorkflow * pbrWorkflow =
pbr->Workflow(sdf::PbrWorkflowType::METAL);
if (pbrWorkflow)
{
pbrOut.SetType(ignition::common::PbrType::METAL);
}
else
{
pbrWorkflow = pbr->Workflow(sdf::PbrWorkflowType::SPECULAR);
if (pbrWorkflow)
{
pbrOut.SetType(ignition::common::PbrType::SPECULAR);
}
}
if (pbrWorkflow != nullptr)
{
pbrOut.SetAlbedoMap(pbrWorkflow->AlbedoMap());
pbrOut.SetMetalnessMap(pbrWorkflow->MetalnessMap());
pbrOut.SetEmissiveMap(pbrWorkflow->EmissiveMap());
pbrOut.SetRoughnessMap(pbrWorkflow->RoughnessMap());
pbrOut.SetSpecularMap(pbrWorkflow->SpecularMap());
pbrOut.SetEnvironmentMap(pbrWorkflow->EnvironmentMap());
pbrOut.SetAmbientOcclusionMap(pbrWorkflow->AmbientOcclusionMap());
pbrOut.SetLightMap(pbrWorkflow->LightMap());
pbrOut.SetRoughness(pbrWorkflow->Roughness());
pbrOut.SetGlossiness(pbrWorkflow->Glossiness());
pbrOut.SetMetalness(pbrWorkflow->Metalness());

if (pbrWorkflow->NormalMapType() == sdf::NormalMapSpace::TANGENT)
{
pbrOut.SetNormalMap(
pbrWorkflow->NormalMap(),
ignition::common::NormalMapSpace::TANGENT);
}
else if (pbrWorkflow->NormalMapType() == sdf::NormalMapSpace::OBJECT)
{
pbrOut.SetNormalMap(
pbrWorkflow->NormalMap(),
ignition::common::NormalMapSpace::OBJECT);
}
}
_out.SetPbrMaterial(pbrOut);
}
}
}
}
}
Loading