-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support materials in the sdf2usd converter Co-authored-by: Ashton Larkin <[email protected]> Co-authored-by: Teo Koon Peng <[email protected]> Co-authored-by: Steve Peters <[email protected]>
- Loading branch information
1 parent
c7fd82d
commit 9641718
Showing
12 changed files
with
1,534 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.