Fix authoring type mismatch for geoms sizes attributes.
Fixes wrong sizes being displayed in usdview. Also introduce a new test to ensure we catch as many of those kinds of errors as possible in the future. PiperOrigin-RevId: 764388588 Change-Id: Id3c878edd054fe5272c42c9f960c65c850655559
This commit is contained in:
committed by
Copybara-Service
parent
287f46b220
commit
fc69ef1084
@@ -18,10 +18,13 @@
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.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>
|
||||
@@ -71,5 +74,50 @@ void ExpectAttributeHasConnection(pxr::UsdStageRefPtr stage, const char* path,
|
||||
EXPECT_EQ(sources.size(), 1);
|
||||
EXPECT_EQ(sources[0], SdfPath(connection_path));
|
||||
}
|
||||
|
||||
void ExpectAllAuthoredAttributesMatchSchemaTypes(const pxr::UsdPrim& prim) {
|
||||
// Get all properties on the prim that have authored opinions.
|
||||
for (const pxr::UsdProperty& prop : prim.GetAuthoredProperties()) {
|
||||
// We only care about attributes, as they are the ones with a typeName.
|
||||
if (pxr::UsdAttribute attr = prop.As<pxr::UsdAttribute>()) {
|
||||
// 1. Get the official, composed schema type name for the attribute.
|
||||
const pxr::TfToken schemaTypeName = attr.GetTypeName().GetAsToken();
|
||||
|
||||
// An empty schema type name means the attribute is not defined by
|
||||
// a schema, or is of a dynamically-determined type. We can't
|
||||
// check for a mismatch in this case.
|
||||
if (schemaTypeName.IsEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 2. Get the property stack to check for authored opinions.
|
||||
// The stack is ordered from strongest to weakest.
|
||||
const pxr::SdfPropertySpecHandleVector propStack =
|
||||
attr.GetPropertyStack();
|
||||
|
||||
for (const pxr::SdfPropertySpecHandle& spec : propStack) {
|
||||
// We only care about attribute specs.
|
||||
if (auto attrSpec = TfDynamic_cast<pxr::SdfAttributeSpecHandle>(spec)) {
|
||||
// 3. Check if this spec has an authored `typeName`.
|
||||
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() << "@";
|
||||
|
||||
// We've found the strongest authored opinion for `typeName`,
|
||||
// so we can stop checking the stack for this attribute.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace usd
|
||||
} // namespace mujoco
|
||||
|
||||
Reference in New Issue
Block a user