-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[parsing] Add UsdParser smoke test stub
This turns up a slew of previously-unseen errors in our OpenUSD build system, which we also fix here.
- Loading branch information
1 parent
0bde095
commit a6e9a62
Showing
10 changed files
with
300 additions
and
46 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,75 @@ | ||
#include "drake/multibody/parsing/detail_usd_parser.h" | ||
|
||
#include <filesystem> | ||
#include <stdexcept> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "pxr/base/plug/registry.h" | ||
#include "pxr/usd/usd/stage.h" | ||
|
||
#include "drake/common/find_runfiles.h" | ||
#include "drake/common/unused.h" | ||
|
||
namespace drake { | ||
namespace multibody { | ||
namespace internal { | ||
|
||
namespace fs = std::filesystem; | ||
namespace pxr = drake_vendor_pxr; | ||
|
||
namespace { | ||
void InitializeOpenUsdLibrary() { | ||
// Register all relevant plugins. | ||
auto& registry = pxr::PlugRegistry::PlugRegistry::GetInstance(); | ||
std::vector<std::string> json_paths{{ | ||
"openusd_internal/pxr/usd/ar/plugInfo.json", | ||
"openusd_internal/pxr/usd/ndr/plugInfo.json", | ||
"openusd_internal/pxr/usd/sdf/plugInfo.json", | ||
"openusd_internal/pxr/usd/usdGeom/plugInfo.json", | ||
"openusd_internal/pxr/usd/usd/plugInfo.json", | ||
"openusd_internal/pxr/usd/usdShade/plugInfo.json", | ||
}}; | ||
for (const auto& json_path : json_paths) { | ||
const RlocationOrError location = FindRunfile(json_path); | ||
if (!location.error.empty()) { | ||
throw std::runtime_error(location.error); | ||
} | ||
const fs::path info_dir = fs::path(location.abspath).parent_path(); | ||
registry.RegisterPlugins(info_dir.string()); | ||
} | ||
} | ||
} // namespace | ||
|
||
UsdParser::UsdParser() { | ||
static const int ignored = []() { | ||
InitializeOpenUsdLibrary(); | ||
return 0; | ||
}(); | ||
unused(ignored); | ||
} | ||
|
||
UsdParser::~UsdParser() = default; | ||
|
||
std::optional<ModelInstanceIndex> UsdParser::AddModel( | ||
const DataSource& data_source, const std::string& model_name, | ||
const std::optional<std::string>& parent_model_name, | ||
const ParsingWorkspace& workspace) { | ||
unused(data_source, model_name, parent_model_name, workspace); | ||
throw std::runtime_error("UsdParser::AddModel is not implemented"); | ||
} | ||
|
||
std::vector<ModelInstanceIndex> UsdParser::AddAllModels( | ||
const DataSource& data_source, | ||
const std::optional<std::string>& parent_model_name, | ||
const ParsingWorkspace& workspace) { | ||
// Create a stage. This is just a simple placeholder at the moment. | ||
pxr::UsdStageRefPtr stage = pxr::UsdStage::CreateInMemory(); | ||
|
||
unused(data_source, parent_model_name, workspace); | ||
throw std::runtime_error("UsdParser::AddAllModels is not implemented"); | ||
} | ||
|
||
} // namespace internal | ||
} // namespace multibody | ||
} // namespace drake |
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,36 @@ | ||
#pragma once | ||
|
||
#include <optional> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "drake/multibody/parsing/detail_common.h" | ||
#include "drake/multibody/parsing/detail_parsing_workspace.h" | ||
#include "drake/multibody/tree/multibody_tree_indexes.h" | ||
|
||
namespace drake { | ||
namespace multibody { | ||
namespace internal { | ||
|
||
class UsdParser final : public ParserInterface { | ||
public: | ||
DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN(UsdParser) | ||
|
||
UsdParser(); | ||
|
||
~UsdParser() final; | ||
|
||
std::optional<ModelInstanceIndex> AddModel( | ||
const DataSource& data_source, const std::string& model_name, | ||
const std::optional<std::string>& parent_model_name, | ||
const ParsingWorkspace& workspace) final; | ||
|
||
std::vector<ModelInstanceIndex> AddAllModels( | ||
const DataSource& data_source, | ||
const std::optional<std::string>& parent_model_name, | ||
const ParsingWorkspace& workspace) final; | ||
}; | ||
|
||
} // namespace internal | ||
} // namespace multibody | ||
} // namespace drake |
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,37 @@ | ||
/* clang-format off to disable clang-format-includes */ | ||
#include "drake/multibody/parsing/detail_usd_parser.h" | ||
/* clang-format on */ | ||
|
||
#include <stdexcept> | ||
|
||
#include "drake/common/unused.h" | ||
|
||
namespace drake { | ||
namespace multibody { | ||
namespace internal { | ||
|
||
UsdParser::UsdParser() = default; | ||
|
||
UsdParser::~UsdParser() = default; | ||
|
||
std::optional<ModelInstanceIndex> UsdParser::AddModel( | ||
const DataSource& data_source, const std::string& model_name, | ||
const std::optional<std::string>& parent_model_name, | ||
const ParsingWorkspace& workspace) { | ||
unused(data_source, model_name, parent_model_name, workspace); | ||
throw std::runtime_error( | ||
"UsdParser is not available because WITH_USD is not ON"); | ||
} | ||
|
||
std::vector<ModelInstanceIndex> UsdParser::AddAllModels( | ||
const DataSource& data_source, | ||
const std::optional<std::string>& parent_model_name, | ||
const ParsingWorkspace& workspace) { | ||
unused(data_source, parent_model_name, workspace); | ||
throw std::runtime_error( | ||
"UsdParser is not available because WITH_USD is not ON"); | ||
} | ||
|
||
} // namespace internal | ||
} // namespace multibody | ||
} // namespace drake |
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,57 @@ | ||
#include "drake/multibody/parsing/detail_usd_parser.h" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include "drake/common/test_utilities/diagnostic_policy_test_base.h" | ||
#include "drake/common/test_utilities/expect_throws_message.h" | ||
|
||
namespace drake { | ||
namespace multibody { | ||
namespace internal { | ||
namespace { | ||
|
||
namespace fs = std::filesystem; | ||
|
||
using drake::internal::DiagnosticPolicy; | ||
using geometry::SceneGraph; | ||
|
||
class UsdParserTest : public test::DiagnosticPolicyTestBase { | ||
public: | ||
UsdParserTest() { plant_.RegisterAsSourceForSceneGraph(&scene_graph_); } | ||
|
||
std::vector<ModelInstanceIndex> ParseFile(const fs::path& filename) { | ||
const std::string source_filename = filename.string(); | ||
const DataSource source{DataSource::kFilename, &source_filename}; | ||
const std::optional<std::string> parent_model_name; | ||
internal::CollisionFilterGroupResolver resolver{&plant_}; | ||
ParsingWorkspace w{options_, package_map_, diagnostic_policy_, | ||
&plant_, &resolver, NoSelect}; | ||
UsdParser dut; | ||
auto result = dut.AddAllModels(source, parent_model_name, w); | ||
resolver.Resolve(diagnostic_policy_); | ||
return result; | ||
} | ||
|
||
// USD cannot delegate to any other parsers. | ||
static ParserInterface& NoSelect(const drake::internal::DiagnosticPolicy&, | ||
const std::string&) { | ||
DRAKE_UNREACHABLE(); | ||
} | ||
|
||
protected: | ||
ParsingOptions options_; | ||
PackageMap package_map_; | ||
MultibodyPlant<double> plant_{0.01}; | ||
SceneGraph<double> scene_graph_; | ||
}; | ||
|
||
TEST_F(UsdParserTest, Stub) { | ||
const fs::path filename{"no_such_file.usda"}; | ||
DRAKE_EXPECT_THROWS_MESSAGE(ParseFile(filename), | ||
".*UsdParser.*AddAllModels.*not implemented.*"); | ||
} | ||
|
||
} // namespace | ||
} // namespace internal | ||
} // namespace multibody | ||
} // namespace drake |
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 |
---|---|---|
@@ -1,37 +1,3 @@ | ||
load("//tools/workspace:generate_file.bzl", "generate_file") | ||
load("//tools/lint:lint.bzl", "add_lint_tests") | ||
|
||
# TODO(jwnimmer-tri) To prove that the @openusd_internal build system is | ||
# working properly, here we perform a smoke test of `usdcat --help`. Once | ||
# we have enough real unit tests in Drake that call into USD and prove out | ||
# the build, we should remove this simple smoke test. | ||
|
||
alias( | ||
name = "usdcat", | ||
actual = "@openusd_internal//:usdcat", | ||
tags = [ | ||
# Only compile this binary when the usdcat_help test needs it. | ||
"manual", | ||
], | ||
) | ||
|
||
generate_file( | ||
name = "empty.sh", | ||
# When WITH_USD is off, this serves as a test stub dummy. | ||
content = "echo 'WITH_USD is not ON'", | ||
) | ||
|
||
sh_test( | ||
name = "usdcat_help", | ||
srcs = select({ | ||
"//tools:with_usd": [":usdcat"], | ||
"//conditions:default": ["empty.sh"], | ||
}), | ||
args = ["--help"], | ||
tags = [ | ||
# TODO(jwnimmer-tri) Re-enable this once we fix Boost problems. | ||
"manual", | ||
], | ||
) | ||
|
||
add_lint_tests() |
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
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,20 @@ | ||
[openusd_internal] Opt-out of GNU libstdc++ extensions | ||
|
||
They are deprecated old smelly stuff that spews compiler warnings. | ||
This opt-out is a Drake choice, do we don't plan to upstream this patch. | ||
|
||
--- pxr/base/arch/defines.h | ||
+++ pxr/base/arch/defines.h | ||
@@ -88,10 +88,8 @@ | ||
// Features | ||
// | ||
|
||
-// Only use the GNU STL extensions on Linux when using gcc. | ||
-#if defined(ARCH_OS_LINUX) && defined(ARCH_COMPILER_GCC) | ||
-#define ARCH_HAS_GNU_STL_EXTENSIONS | ||
-#endif | ||
+// N.B. Drake never uses the GNU STL extensions. | ||
+// #define ARCH_HAS_GNU_STL_EXTENSIONS | ||
|
||
// The current version of Apple clang does not support the thread_local | ||
// keyword. |
Oops, something went wrong.