Skip to content

Commit 74a1285

Browse files
Alex Fullerboberfly
authored andcommitted
usdAbc: Correctly interpret arbGeomParams from Alembic files
1 parent 4ed6128 commit 74a1285

4 files changed

Lines changed: 203 additions & 9 deletions

File tree

pxr/usd/plugin/usdAbc/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ pxr_register_test(testUsdAbcIndexedGeomArb
152152
USD_ABC_TESTSUFFIX=def
153153
)
154154

155+
pxr_register_test(testUsdAbcIndexedGeomArbLoad
156+
COMMAND "${CMAKE_INSTALL_PREFIX}/bin/usdcat test_indexed_primvar.abc --out good_indexed_primvar.usda"
157+
TESTENV testenv/testUsdAbcIndexedGeomArbLoad
158+
DIFF_COMPARE good_indexed_primvar.usda
159+
EXPECTED_RETURN_CODE 0
160+
ENV
161+
USD_ABC_TESTSUFFIX=def
162+
)
163+
155164
pxr_register_test(testUsdAbcInstancing
156165
PYTHON
157166
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
@@ -3029,15 +3029,6 @@ _ReadGprim(_PrimReaderContext* context)
30293029
context->Extract(GeomBaseSchemaInfo::defaultName());
30303030
}
30313031

3032-
static
3033-
void
3034-
_ReadArbGeomParams(_PrimReaderContext* context)
3035-
{
3036-
// Add primvars.
3037-
context->AddOutOfSchemaProperty(
3038-
UsdAbcPropertyNames->primvars, context->ExtractSchema(".arbGeomParams"));
3039-
}
3040-
30413032
static
30423033
void
30433034
_ReadUserProperties(_PrimReaderContext* context)
@@ -3109,6 +3100,137 @@ _ReadProperty(_PrimReaderContext* context, const char* name, TfToken propName, S
31093100
}
31103101
}
31113102

3103+
template<class T, class UsdValueType>
3104+
void
3105+
_ReadProperty(
3106+
_PrimReaderContext* context,
3107+
const AlembicProperty &prop,
3108+
const TfToken propName,
3109+
const SdfValueTypeName typeName)
3110+
{
3111+
if (prop.Cast<T>().isIndexed()) {
3112+
context->AddProperty(
3113+
propName,
3114+
typeName,
3115+
_CopyGeneric<T, UsdValueType, false>(prop));
3116+
context->AddProperty(
3117+
TfToken(SdfPath::JoinIdentifier(propName, UsdGeomTokens->indices)),
3118+
SdfValueTypeNames->IntArray,
3119+
_CopyIndices<T>(prop));
3120+
} else {
3121+
context->AddProperty(
3122+
propName,
3123+
typeName,
3124+
_CopyGeneric<T, UsdValueType>(prop));
3125+
}
3126+
}
3127+
3128+
static
3129+
void
3130+
_AddArbGeomProperty(
3131+
_PrimReaderContext *context,
3132+
const TfToken& propName,
3133+
const AlembicProperty& property)
3134+
{
3135+
if (property.Cast<IFloatGeomParam>().valid()) {
3136+
_ReadProperty<IFloatGeomParam, float>(
3137+
context, property, propName, SdfValueTypeNames->FloatArray);
3138+
}
3139+
else if (property.Cast<IDoubleGeomParam>().valid()) {
3140+
_ReadProperty<IDoubleGeomParam, double>(
3141+
context, property, propName, SdfValueTypeNames->DoubleArray);
3142+
}
3143+
else if (property.Cast<IV3dGeomParam>().valid()) {
3144+
_ReadProperty<IV3dGeomParam, GfVec3d>(
3145+
context, property, propName, SdfValueTypeNames->Vector3dArray);
3146+
}
3147+
else if(property.Cast<IStringGeomParam>().valid()) {
3148+
_ReadProperty<IStringGeomParam, std::string>(
3149+
context, property, propName, SdfValueTypeNames->StringArray);
3150+
}
3151+
else if (property.Cast<IV2fGeomParam>().valid()) {
3152+
_ReadProperty<IV2fGeomParam, GfVec2f>(
3153+
context, property, propName, SdfValueTypeNames->TexCoord2fArray);
3154+
}
3155+
else if (property.Cast<IV3fGeomParam>().valid()) {
3156+
_ReadProperty<IV3fGeomParam, GfVec3f>(
3157+
context, property, propName, SdfValueTypeNames->Vector3fArray);
3158+
}
3159+
else if (property.Cast<IC3fGeomParam>().valid()) {
3160+
_ReadProperty<IC3fGeomParam, GfVec3f>(
3161+
context, property, propName, SdfValueTypeNames->Color3fArray);
3162+
}
3163+
else if (property.Cast<IC4fGeomParam>().valid()) {
3164+
_ReadProperty<IC4fGeomParam, GfVec4f>(
3165+
context, property, propName, SdfValueTypeNames->Color4fArray);
3166+
}
3167+
else if(property.Cast<IN3fGeomParam>().valid()) {
3168+
_ReadProperty<IN3fGeomParam, GfVec3f>(
3169+
context, property, propName, SdfValueTypeNames->Normal3fArray);
3170+
}
3171+
else if (property.Cast<IP3fGeomParam>().valid()) {
3172+
_ReadProperty<IP3fGeomParam, GfVec3f>(
3173+
context, property, propName, SdfValueTypeNames->Point3fArray);
3174+
}
3175+
else if (property.Cast<IBoolGeomParam>().valid()) {
3176+
_ReadProperty<IBoolGeomParam, bool>(
3177+
context, property, propName, SdfValueTypeNames->BoolArray);
3178+
}
3179+
else if (property.Cast<IQuatfGeomParam>().valid()) {
3180+
_ReadProperty<IQuatfGeomParam, GfQuatf>(
3181+
context, property, propName, SdfValueTypeNames->QuatfArray);
3182+
}
3183+
else if (property.Cast<IQuatdGeomParam>().valid()) {
3184+
_ReadProperty<IQuatdGeomParam, GfQuatd>(
3185+
context, property, propName, SdfValueTypeNames->QuatdArray);
3186+
}
3187+
}
3188+
3189+
static
3190+
void
3191+
_ReadArbGeomParams(_PrimReaderContext* context)
3192+
{
3193+
// Get property info.
3194+
std::string name(UsdAbcPropertyNames->primvars);
3195+
const AlembicProperty& property = context->ExtractSchema(".arbGeomParams");
3196+
const PropertyHeader* header = property.GetHeader();
3197+
if (!header) {
3198+
// No such property.
3199+
return;
3200+
}
3201+
3202+
// .ArbGeomParams is a compound
3203+
if (!header->isCompound()) {
3204+
return;
3205+
}
3206+
3207+
ICompoundProperty compound = property.Cast<ICompoundProperty>();
3208+
3209+
// Fill usedNames.
3210+
std::set<std::string> usedNames;
3211+
for (size_t i = 0, n = compound.getNumProperties(); i != n; ++i) {
3212+
usedNames.insert(compound.getPropertyHeader(i).getName());
3213+
}
3214+
3215+
// Add each geom property
3216+
for (size_t i = 0, n = compound.getNumProperties(); i != n; ++i) {
3217+
const std::string rawName =
3218+
compound.getPropertyHeader(i).getName();
3219+
const std::string cleanName =
3220+
_CleanName(rawName, " .", usedNames,
3221+
_AlembicFixName(),
3222+
&SdfPath::IsValidIdentifier);
3223+
const TfToken namespacedName =
3224+
TfToken(SdfPath::JoinIdentifier(name, cleanName));
3225+
const SdfPath childPath = context->GetPath().AppendProperty(namespacedName);
3226+
3227+
_AddArbGeomProperty(
3228+
context,
3229+
namespacedName,
3230+
AlembicProperty(childPath, rawName, compound));
3231+
}
3232+
}
3233+
31123234
static
31133235
void
31143236
_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)