| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #include "test/experimental/usd/test_utils.h" |
| |
|
| | #include <string> |
| |
|
| | #include <gmock/gmock.h> |
| | #include <gtest/gtest.h> |
| | #include <pxr/base/gf/math.h> |
| | #include <pxr/base/gf/quatf.h> |
| | #include <pxr/base/tf/token.h> |
| | #include <pxr/usd/sdf/assetPath.h> |
| | #include <pxr/usd/sdf/childrenPolicies.h> |
| | #include <pxr/usd/sdf/declareHandles.h> |
| | #include <pxr/usd/sdf/fileFormat.h> |
| | #include <pxr/usd/sdf/path.h> |
| | #include <pxr/usd/sdf/schema.h> |
| | #include <pxr/usd/usd/common.h> |
| | #include <pxr/usd/usd/modelAPI.h> |
| | #include <pxr/usd/usd/stage.h> |
| | #include <pxr/usd/usd/timeCode.h> |
| | #include <pxr/usd/usdGeom/mesh.h> |
| | #include <pxr/usd/usdGeom/primvarsAPI.h> |
| | namespace mujoco { |
| | namespace usd { |
| |
|
| | using pxr::SdfPath; |
| |
|
| | pxr::SdfLayerRefPtr LoadLayer( |
| | const std::string& xml, |
| | const pxr::SdfFileFormat::FileFormatArguments& args) { |
| | auto layer = pxr::SdfLayer::CreateAnonymous( |
| | "test_layer", pxr::SdfFileFormat::FindByExtension("xml"), args); |
| | layer->ImportFromString(xml); |
| | EXPECT_THAT(layer, testing::NotNull()); |
| | return layer; |
| | } |
| |
|
| | pxr::UsdStageRefPtr OpenStageWithPhysics(const std::string& xml) { |
| | pxr::SdfFileFormat::FileFormatArguments args; |
| | args["usdMjcfToggleUsdPhysics"] = "true"; |
| | pxr::SdfLayerRefPtr layer = LoadLayer(xml, args); |
| | auto stage = pxr::UsdStage::Open(layer); |
| | EXPECT_THAT(stage, testing::NotNull()); |
| | return stage; |
| | } |
| |
|
| | template <> |
| | void ExpectAttributeEqual<pxr::SdfAssetPath>(pxr::UsdStageRefPtr stage, |
| | pxr::SdfPath path, |
| | const pxr::SdfAssetPath& value, |
| | const pxr::UsdTimeCode time) { |
| | auto attr = stage->GetAttributeAtPath(path); |
| | EXPECT_TRUE(attr.IsValid()); |
| | pxr::SdfAssetPath attr_value; |
| | attr.Get(&attr_value); |
| | EXPECT_EQ(attr_value.GetAssetPath(), value.GetAssetPath()); |
| | } |
| |
|
| | void ExpectAttributeHasConnection(pxr::UsdStageRefPtr stage, const char* path, |
| | const char* connection_path) { |
| | auto attr = stage->GetAttributeAtPath(SdfPath(path)); |
| | EXPECT_TRUE(attr.IsValid()); |
| | pxr::SdfPathVector sources; |
| | attr.GetConnections(&sources); |
| | EXPECT_EQ(sources.size(), 1); |
| | EXPECT_EQ(sources[0], SdfPath(connection_path)); |
| | } |
| |
|
| | void ExpectAllAuthoredAttributesMatchSchemaTypes(const pxr::UsdPrim& prim) { |
| | |
| | for (const pxr::UsdProperty& prop : prim.GetAuthoredProperties()) { |
| | |
| | if (pxr::UsdAttribute attr = prop.As<pxr::UsdAttribute>()) { |
| | |
| | const pxr::TfToken schemaTypeName = attr.GetTypeName().GetAsToken(); |
| |
|
| | |
| | |
| | |
| | if (schemaTypeName.IsEmpty()) { |
| | continue; |
| | } |
| |
|
| | |
| | |
| | const pxr::SdfPropertySpecHandleVector propStack = |
| | attr.GetPropertyStack(); |
| |
|
| | for (const pxr::SdfPropertySpecHandle& spec : propStack) { |
| | |
| | if (auto attrSpec = |
| | pxr::TfDynamic_cast<pxr::SdfAttributeSpecHandle>(spec)) { |
| | |
| | if (attrSpec->HasField(pxr::SdfFieldKeys->TypeName)) { |
| | const pxr::TfToken authoredTypeName = |
| | attrSpec->GetTypeName().GetAsToken(); |
| |
|
| | EXPECT_EQ(authoredTypeName, schemaTypeName) |
| | << "Type mismatch for attribute <" << attr.GetPath() |
| | << ">: expected schema-defined type '" |
| | << schemaTypeName.GetString() << "', got authored type '" |
| | << authoredTypeName.GetString() << "' in layer @" |
| | << attrSpec->GetLayer()->GetIdentifier() << "@"; |
| |
|
| | |
| | |
| | break; |
| | } |
| | } |
| | } |
| | } |
| | } |
| | } |
| |
|
| | bool AreQuatsSameRotation(const pxr::GfQuatf& q1, const pxr::GfQuatf& q2, |
| | float tolerance) { |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | const float dot = pxr::GfDot(q1, q2); |
| | return pxr::GfIsClose(pxr::GfAbs(dot), 1.0f, tolerance); |
| | } |
| | } |
| | } |
| |
|