Skip to content

Commit 9bfdac1

Browse files
author
Alex Fuller
committed
usdAbc: Correctly interpret arbGeomParams from Alembic files
1 parent 270278a commit 9bfdac1

4 files changed

Lines changed: 207 additions & 9 deletions

File tree

pxr/usd/plugin/usdAbc/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ pxr_install_test_dir(
129129
DEST testUsdAbcIndexedGeomArb
130130
)
131131

132+
pxr_install_test_dir(
133+
SRC testenv/testUsdAbcIndexedGeomArbLoad
134+
DEST testUsdAbcIndexedGeomArbLoad
135+
)
136+
132137
pxr_install_test_dir(
133138
SRC testenv/testUsdAbcInstancing
134139
DEST testUsdAbcInstancing
@@ -234,6 +239,14 @@ pxr_register_test(testUsdAbcIndexedGeomArb
234239
USD_ABC_TESTSUFFIX=def
235240
)
236241

242+
pxr_register_test(testUsdAbcIndexedGeomArbLoad
243+
COMMAND "${CMAKE_INSTALL_PREFIX}/bin/usdcat test_indexed_primvar.abc --out good_indexed_primvar.usda"
244+
DIFF_COMPARE good_custom_indexed_primvar.usda
245+
EXPECTED_RETURN_CODE 0
246+
ENV
247+
USD_ABC_TESTSUFFIX=def
248+
)
249+
237250
pxr_register_test(testUsdAbcInstancing
238251
PYTHON
239252
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdAbcInstancing"

pxr/usd/plugin/usdAbc/alembicReader.cpp

Lines changed: 131 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2987,15 +2987,6 @@ _ReadGprim(_PrimReaderContext* context)
29872987
context->Extract(GeomBaseSchemaInfo::defaultName());
29882988
}
29892989

2990-
static
2991-
void
2992-
_ReadArbGeomParams(_PrimReaderContext* context)
2993-
{
2994-
// Add primvars.
2995-
context->AddOutOfSchemaProperty(
2996-
UsdAbcPropertyNames->primvars, context->ExtractSchema(".arbGeomParams"));
2997-
}
2998-
29992990
static
30002991
void
30012992
_ReadUserProperties(_PrimReaderContext* context)
@@ -3067,6 +3058,137 @@ _ReadProperty(_PrimReaderContext* context, const char* name, TfToken propName, S
30673058
}
30683059
}
30693060

3061+
template<class T, class UsdValueType>
3062+
void
3063+
_ReadProperty(
3064+
_PrimReaderContext* context,
3065+
const AlembicProperty &prop,
3066+
const TfToken propName,
3067+
const SdfValueTypeName typeName)
3068+
{
3069+
if (prop.Cast<T>().isIndexed()) {
3070+
context->AddProperty(
3071+
propName,
3072+
typeName,
3073+
_CopyGeneric<T, UsdValueType, false>(prop));
3074+
context->AddProperty(
3075+
TfToken(SdfPath::JoinIdentifier(propName, UsdGeomTokens->indices)),
3076+
SdfValueTypeNames->IntArray,
3077+
_CopyIndices<T>(prop));
3078+
} else {
3079+
context->AddProperty(
3080+
propName,
3081+
typeName,
3082+
_CopyGeneric<T, UsdValueType>(prop));
3083+
}
3084+
}
3085+
3086+
static
3087+
void
3088+
_AddArbGeomProperty(
3089+
_PrimReaderContext *context,
3090+
const TfToken& propName,
3091+
const AlembicProperty& property)
3092+
{
3093+
if (property.Cast<IFloatGeomParam>().valid()) {
3094+
_ReadProperty<IFloatGeomParam, float>(
3095+
context, property, propName, SdfValueTypeNames->FloatArray);
3096+
}
3097+
else if (property.Cast<IDoubleGeomParam>().valid()) {
3098+
_ReadProperty<IDoubleGeomParam, double>(
3099+
context, property, propName, SdfValueTypeNames->DoubleArray);
3100+
}
3101+
else if (property.Cast<IV3dGeomParam>().valid()) {
3102+
_ReadProperty<IV3dGeomParam, GfVec3d>(
3103+
context, property, propName, SdfValueTypeNames->Vector3dArray);
3104+
}
3105+
else if(property.Cast<IStringGeomParam>().valid()) {
3106+
_ReadProperty<IStringGeomParam, std::string>(
3107+
context, property, propName, SdfValueTypeNames->StringArray);
3108+
}
3109+
else if (property.Cast<IV2fGeomParam>().valid()) {
3110+
_ReadProperty<IV2fGeomParam, GfVec2f>(
3111+
context, property, propName, SdfValueTypeNames->TexCoord2fArray);
3112+
}
3113+
else if (property.Cast<IV3fGeomParam>().valid()) {
3114+
_ReadProperty<IV3fGeomParam, GfVec3f>(
3115+
context, property, propName, SdfValueTypeNames->Vector3fArray);
3116+
}
3117+
else if (property.Cast<IC3fGeomParam>().valid()) {
3118+
_ReadProperty<IC3fGeomParam, GfVec3f>(
3119+
context, property, propName, SdfValueTypeNames->Color3fArray);
3120+
}
3121+
else if (property.Cast<IC4fGeomParam>().valid()) {
3122+
_ReadProperty<IC4fGeomParam, GfVec4f>(
3123+
context, property, propName, SdfValueTypeNames->Color4fArray);
3124+
}
3125+
else if(property.Cast<IN3fGeomParam>().valid()) {
3126+
_ReadProperty<IN3fGeomParam, GfVec3f>(
3127+
context, property, propName, SdfValueTypeNames->Normal3fArray);
3128+
}
3129+
else if (property.Cast<IP3fGeomParam>().valid()) {
3130+
_ReadProperty<IP3fGeomParam, GfVec3f>(
3131+
context, property, propName, SdfValueTypeNames->Point3fArray);
3132+
}
3133+
else if (property.Cast<IBoolGeomParam>().valid()) {
3134+
_ReadProperty<IBoolGeomParam, bool>(
3135+
context, property, propName, SdfValueTypeNames->BoolArray);
3136+
}
3137+
else if (property.Cast<IQuatfGeomParam>().valid()) {
3138+
_ReadProperty<IQuatfGeomParam, GfQuatf>(
3139+
context, property, propName, SdfValueTypeNames->QuatfArray);
3140+
}
3141+
else if (property.Cast<IQuatdGeomParam>().valid()) {
3142+
_ReadProperty<IQuatdGeomParam, GfQuatd>(
3143+
context, property, propName, SdfValueTypeNames->QuatdArray);
3144+
}
3145+
}
3146+
3147+
static
3148+
void
3149+
_ReadArbGeomParams(_PrimReaderContext* context)
3150+
{
3151+
// Get property info.
3152+
std::string name(UsdAbcPropertyNames->primvars);
3153+
AlembicProperty& property = context->ExtractSchema(".arbGeomParams");
3154+
const PropertyHeader* header = property.GetHeader();
3155+
if (!header) {
3156+
// No such property.
3157+
return;
3158+
}
3159+
3160+
// .ArbGeomParams is a compound
3161+
if (!header->isCompound()) {
3162+
return;
3163+
}
3164+
3165+
ICompoundProperty compound = property.Cast<ICompoundProperty>();
3166+
3167+
// Fill usedNames.
3168+
std::set<std::string> usedNames;
3169+
for (size_t i = 0, n = compound.getNumProperties(); i != n; ++i) {
3170+
usedNames.insert(compound.getPropertyHeader(i).getName());
3171+
}
3172+
3173+
// Add each geom property
3174+
for (size_t i = 0, n = compound.getNumProperties(); i != n; ++i) {
3175+
const std::string rawName =
3176+
compound.getPropertyHeader(i).getName();
3177+
const std::string cleanName =
3178+
_CleanName(rawName, " .", usedNames,
3179+
_AlembicFixName(),
3180+
&SdfPath::IsValidIdentifier);
3181+
const TfToken namespacedName =
3182+
TfToken(SdfPath::JoinIdentifier(name, cleanName));
3183+
const SdfPath childPath = context->GetPath().AppendProperty(namespacedName);
3184+
3185+
_AddArbGeomProperty(
3186+
context,
3187+
namespacedName,
3188+
AlembicProperty(childPath, rawName, compound));
3189+
}
3190+
}
3191+
30703192
static
30713193
void
30723194
_ReadOrientation(_PrimReaderContext* context)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#usda 1.0
2+
(
3+
defaultPrim = "cube"
4+
endTimeCode = 1.0000000298
5+
startTimeCode = 0
6+
upAxis = "Y"
7+
)
8+
9+
def Mesh "cube"
10+
{
11+
float3[] extent.timeSamples = {
12+
1.0000000298: [(-0.5, -0.5, -0.5), (0.5, 0.5, 0.5)],
13+
}
14+
int[] faceVertexCounts.timeSamples = {
15+
1.0000000298: [4, 4, 4, 4, 4, 4],
16+
}
17+
int[] faceVertexIndices.timeSamples = {
18+
1.0000000298: [0, 1, 2, 3, 4, 5, 2, 1, 6, 7, 5, 4, 0, 3, 7, 6, 5, 7, 3, 2, 6, 4, 1, 0],
19+
}
20+
normal3f[] normals (
21+
interpolation = "faceVarying"
22+
)
23+
normal3f[] normals.timeSamples = {
24+
1.0000000298: [(0, 0, -1), (0, 0, -1), (0, 0, -1), (0, 0, -1), (1, 0, 0), (1, 0, 0), (1, 0, 0), (1, 0, 0), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (-1, 0, 0), (-1, 0, 0), (-1, 0, 0), (-1, 0, 0), (0, 1, 0), (0, 1, 0), (0, 1, 0), (0, 1, 0), (0, -1, 0), (0, -1, 0), (0, -1, 0), (0, -1, 0)],
25+
}
26+
uniform token orientation = "leftHanded"
27+
point3f[] points (
28+
interpolation = "vertex"
29+
)
30+
point3f[] points.timeSamples = {
31+
1.0000000298: [(-0.5, -0.5, -0.5), (0.5, -0.5, -0.5), (0.5, 0.5, -0.5), (-0.5, 0.5, -0.5), (0.5, -0.5, 0.5), (0.5, 0.5, 0.5), (-0.5, -0.5, 0.5), (-0.5, 0.5, 0.5)],
32+
}
33+
point3f[] primvars:custom (
34+
interpolation = "faceVarying"
35+
)
36+
point3f[] primvars:custom.timeSamples = {
37+
0: [(0, 0, 1), (0, 0, -1), (0, 1, 0), (0, -1, 0), (1, 0, 0), (-1, 0, 0)],
38+
}
39+
int[] primvars:custom:indices (
40+
interpolation = "faceVarying"
41+
)
42+
int[] primvars:custom:indices.timeSamples = {
43+
0: [1, 1, 1, 1, 4, 4, 4, 4, 0, 0, 0, 0, 5, 5, 5, 5, 2, 2, 2, 2, 3, 3, 3, 3],
44+
}
45+
texCoord2f[] primvars:st (
46+
interpolation = "faceVarying"
47+
)
48+
texCoord2f[] primvars:st.timeSamples = {
49+
1.0000000298: [(0.375, 0), (0.625, 0), (0.375, 0.25), (0.625, 0.25), (0.375, 0.5), (0.625, 0.5), (0.375, 0.75), (0.625, 0.75), (0.375, 1), (0.625, 1), (0.125, 0), (0.875, 0), (0.125, 0.25), (0.875, 0.25)],
50+
}
51+
int[] primvars:st:indices (
52+
interpolation = "faceVarying"
53+
)
54+
int[] primvars:st:indices.timeSamples = {
55+
1.0000000298: [6, 7, 5, 4, 1, 3, 13, 11, 0, 2, 3, 1, 10, 12, 2, 0, 3, 2, 4, 5, 8, 9, 7, 6],
56+
}
57+
uniform token subdivisionScheme = "none"
58+
matrix4d xformOp:transform.timeSamples = {
59+
1.0000000298: ( (1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1) ),
60+
}
61+
uniform token[] xformOpOrder = ["xformOp:transform"]
62+
}
63+
Binary file not shown.

0 commit comments

Comments
 (0)