Skip to content

Commit

Permalink
Merged in RND-699_Walter_UV_Smoothing_Issue (pull request #9)
Browse files Browse the repository at this point in the history
Patch 21 - Resolved texture stretching artifacts

Approved-by: Guillaume Laforge <[email protected]>
  • Loading branch information
Xue Cui committed Sep 25, 2018
2 parents ecd8472 + b65c54b commit b13147e
Show file tree
Hide file tree
Showing 2 changed files with 261 additions and 0 deletions.
1 change: 1 addition & 0 deletions vfx_platform_builder/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1820,6 +1820,7 @@ $(USD_STAMP) : $(ALEMBIC_STAMP) $(BOOST_STAMP) $(CMAKE_STAMP) $(DC_STAMP) $(EMBR
( git am $(THIS_DIR)/patches/USD/0018-RDO-the-ability-to-reference-a-root.patch ) && \
( git am $(THIS_DIR)/patches/USD/0019-RDO-USD-AlembicReader-Suppress-warnings.patch ) && \
( git am $(THIS_DIR)/patches/USD/0020-RDO-hdEngine-v0.8.5-broke-our-hdEmbree-plugin-when-used-.patch ) && \
( git am $(THIS_DIR)/patches/USD/0021-RDO-USD-Alembic-Fixed-texture-stretching-artifacts.patch ) && \
( printf "/find_library.*OPENEXR_.*_LIBRARY/a\nNAMES\n\044{OPENEXR_LIB}-2_2\n.\nw\nq" | ed -s cmake/modules/FindOpenEXR.cmake ) && \
( printf "/PATH_SUFFIXES/-a\n\"\044{OPENEXR_BASE_DIR}\"\n.\nw\nq" | ed -s cmake/modules/FindOpenEXR.cmake ) && \
( printf "/^namespace boost/s/namespace boost/namespace ${BOOST_NAMESPACE}/\nw\nq" | ed -s pxr/base/lib/tf/weakPtrFacade.h ) && \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
From f80b4a2a741834a4837d356cd35a4fd472484655 Mon Sep 17 00:00:00 2001
From: Snow <[email protected]>
Date: Tue, 25 Sep 2018 10:37:51 -0400
Subject: [PATCH] RDO: Fixed texture stretching artifacts

---
pxr/usd/plugin/usdAbc/alembicReader.cpp | 135 +++++++++++++++++++++++++++++---
pxr/usd/plugin/usdAbc/alembicUtil.cpp | 1 +
pxr/usd/plugin/usdAbc/alembicUtil.h | 5 +-
3 files changed, 127 insertions(+), 14 deletions(-)

diff --git a/pxr/usd/plugin/usdAbc/alembicReader.cpp b/pxr/usd/plugin/usdAbc/alembicReader.cpp
index 52ac3717..85344678 100644
--- a/pxr/usd/plugin/usdAbc/alembicReader.cpp
+++ b/pxr/usd/plugin/usdAbc/alembicReader.cpp
@@ -87,11 +87,34 @@ TF_DEFINE_ENV_SETTING(
USD_ABC_NUM_OGAWA_STREAMS, 4,
"The number of threads available for reading ogawa-backed files via UsdAbc.");

+TF_DEFINE_ENV_SETTING(
+ USD_ABC_WRITE_UV_AS_ST_TEXCOORD2FARRAY, false,
+ "Switch to true to enable writing Alembic uv sets as primvars:st with type "
+ "texCoord2fArray to USD");
+
namespace {

using namespace ::Alembic::AbcGeom;
using namespace UsdAbc_AlembicUtil;

+static const TfToken&
+_GetUVPropertyName()
+{
+ static const TfToken uvUsdAbcPropertyName =
+ (TfGetEnvSetting(USD_ABC_WRITE_UV_AS_ST_TEXCOORD2FARRAY)) ?
+ (UsdAbcPropertyNames->st) : (UsdAbcPropertyNames->uv);
+ return uvUsdAbcPropertyName;
+}
+
+static const SdfValueTypeName&
+_GetUVTypeName()
+{
+ static const SdfValueTypeName uvTypeName =
+ (TfGetEnvSetting(USD_ABC_WRITE_UV_AS_ST_TEXCOORD2FARRAY)) ?
+ (SdfValueTypeNames->TexCoord2fArray) : (SdfValueTypeNames->Float2Array);
+ return uvTypeName;
+}
+
static size_t
_GetNumOgawaStreams()
{
@@ -2216,8 +2239,14 @@ _PrimReaderContext::AddOutOfSchemaProperty(
_context.GetSchema().GetConversions().FindConverter(alembicType);
if (usdTypeName) {
_PrimReaderContext::Property &prop =
- _AddProperty(TfToken(name), usdTypeName, header->getMetaData(),
- sampleTimes, isOutOfSchema);
+ (TfGetEnvSetting(USD_ABC_WRITE_UV_AS_ST_TEXCOORD2FARRAY) &&
+ name == UsdAbcPropertyNames->uvIndices)?
+ (_AddProperty(UsdAbcPropertyNames->stIndices,
+ usdTypeName, header->getMetaData(),
+ sampleTimes, isOutOfSchema)) :
+ (_AddProperty(TfToken(name),
+ usdTypeName, header->getMetaData(),
+ sampleTimes, isOutOfSchema));

if (sampleTimes.size() <= 1)
{
@@ -2231,6 +2260,12 @@ _PrimReaderContext::AddOutOfSchemaProperty(
property.GetParent(), property.GetName(),
std::placeholders::_2, std::placeholders::_1);
}
+ else {
+ TF_WARN("No conversion for \"%s\" of type \"%s\" at <%s>",
+ name.c_str(),
+ alembicType.Stringify().c_str(),
+ GetPath().GetText());
+ }
}

_PrimReaderContext::Property&
@@ -2464,7 +2499,7 @@ struct _CopySynthetic {
};

/// Copy a value from a property of a given type to \c UsdValueType.
-template <class T, class UsdValueType = void>
+template <class T, class UsdValueType = void, bool expand = true>
struct _CopyGeneric {
typedef T PropertyType;
// This is defined for ITyped*Property.
@@ -2498,10 +2533,13 @@ struct _CopyGeneric {
};

/// Copy a ITypedGeomParam. These are either an ITypedArrayProperty or a
-/// compound property with an ITypedArrayProperty and indices. Either way
-/// we can call getExpanded() to get the un-indexed values.
-template <class T, class UsdValueType>
-struct _CopyGeneric<ITypedGeomParam<T>, UsdValueType> {
+/// compound property with an ITypedArrayProperty and indices. If the template
+/// parameter `expand` is true (which is the default), then we will call
+/// getExpanced() to get the un-indexed values. Otherwise we will get the
+/// indexed values, but _CopyIndices will need to be used to extract the
+/// indices.
+template <class T, class UsdValueType, bool expand>
+struct _CopyGeneric<ITypedGeomParam<T>, UsdValueType, expand> {
typedef ITypedGeomParam<T> GeomParamType;
typedef typename GeomParamType::prop_type PropertyType;
typedef typename PropertyType::traits_type AlembicTraits;
@@ -2529,12 +2567,57 @@ struct _CopyGeneric<ITypedGeomParam<T>, UsdValueType> {
const ISampleSelector& iss) const
{
typename GeomParamType::sample_type sample;
- object.getExpanded(sample, iss);
+ if (expand == false && object.isIndexed()) {
+ object.getIndexed(sample, iss);
+ } else {
+ object.getExpanded(sample, iss);
+ }
return dst.Set(_CopyGenericValue<AlembicTraits,
UsdValueType>(sample.getVals()));
}
};

+/// Copy a ITypedGeomParam's index list as an int array.
+/// If the Alembic property is not indexed, it will do nothing.
+template <class GeomParamType>
+struct _CopyIndices {
+ typedef typename GeomParamType::prop_type PropertyType;
+ typedef typename PropertyType::traits_type AlembicTraits;
+
+ GeomParamType object;
+ _CopyIndices(const AlembicProperty& object_) :
+ object(object_.Cast<GeomParamType>())
+ {
+ }
+
+ bool operator()(_IsValidTag) const
+ {
+ return object.valid();
+ }
+
+ const MetaData& operator()(_MetaDataTag) const
+ {
+ return object.getMetaData();
+ }
+
+ _AlembicTimeSamples operator()(_SampleTimesTag) const
+ {
+ return _GetSampleTimes(object);
+ }
+
+ bool operator()(const UsdAbc_AlembicDataAny& dst,
+ const ISampleSelector& iss) const
+ {
+ if (object.isIndexed()) {
+ typename GeomParamType::sample_type sample;
+ object.getIndexed(sample, iss);
+ return dst.Set(_CopyGenericValue<Uint32TPTraits,
+ int>(sample.getIndices()));
+ }
+ return false;
+ }
+};
+
/// Copy a bounding box from an IBox3dProperty.
struct _CopyBoundingBox : _CopyGeneric<IBox3dProperty> {
_CopyBoundingBox(const AlembicProperty& object_) :
@@ -3012,6 +3095,31 @@ _ReadOther(_PrimReaderContext* context)
}
}

+template<class T, class UsdValueType>
+void
+_ReadProperty(_PrimReaderContext* context, const char* name, TfToken propName, SdfValueTypeName typeName)
+{
+ // Read a generic Alembic property and convert it to a USD property.
+ // If the Alembic property is indexed, this will add both the values
+ // property and the indices property, in order to preserve topology.
+ auto prop = context->ExtractSchema(name);
+ if (prop.Cast<T>().isIndexed()) {
+ context->AddProperty(
+ propName,
+ typeName,
+ _CopyGeneric<T, UsdValueType, false>(prop));
+ context->AddProperty(
+ TfToken(SdfPath::JoinIdentifier(propName, UsdGeomTokens->indices)),
+ SdfValueTypeNames->IntArray,
+ _CopyIndices<T>(prop));
+ } else {
+ context->AddProperty(
+ propName,
+ typeName,
+ _CopyGeneric<T, UsdValueType>(prop));
+ }
+}
+
/* Unused
static
void
@@ -3206,6 +3314,9 @@ _ReadPolyMesh(_PrimReaderContext* context)
TfToken("doubleSided"),
SdfValueTypeNames->Bool,
_CopySynthetic(true));
+
+ // Read texture coordinates
+ _ReadProperty<IV2fGeomParam, GfVec2f>(context, "uv", _GetUVPropertyName(), _GetUVTypeName());
}

static
@@ -3291,17 +3402,15 @@ _ReadSubD(_PrimReaderContext* context)
SdfValueTypeNames->FloatArray,
_CopyGeneric<IFloatArrayProperty, float>(
context->ExtractSchema(".creaseSharpnesses")));
- context->AddProperty(
- UsdAbcPropertyNames->uv,
- SdfValueTypeNames->Float2Array,
- _CopyGeneric<IV2fGeomParam, GfVec2f>(
- context->ExtractSchema("uv")));

// Force doubleSided to avoid the problems with mirrored models.
context->AddRegularProperty(
TfToken("doubleSided"),
SdfValueTypeNames->Bool,
_CopySynthetic(true));
+
+ // Read texture coordinates
+ _ReadProperty<IV2fGeomParam, GfVec2f>(context, "uv", _GetUVPropertyName(), _GetUVTypeName());
}

static
diff --git a/pxr/usd/plugin/usdAbc/alembicUtil.cpp b/pxr/usd/plugin/usdAbc/alembicUtil.cpp
index e5587056..e9c48c35 100644
--- a/pxr/usd/plugin/usdAbc/alembicUtil.cpp
+++ b/pxr/usd/plugin/usdAbc/alembicUtil.cpp
@@ -341,6 +341,7 @@ UsdAbc_AlembicConversions::UsdAbc_AlembicConversions()
data.AddConverter<GfVec3f, float32_t, 3>(SdfValueTypeNames->Color3f);
data.AddConverter<GfVec3d, float64_t, 3>(SdfValueTypeNames->Color3d);
data.AddConverter<GfMatrix4d, float64_t, 16>(SdfValueTypeNames->Frame4d);
+ data.AddConverter<GfVec2f, float32_t, 2>(SdfValueTypeNames->TexCoord2f);
}

} // namespace UsdAbc_AlembicUtil
diff --git a/pxr/usd/plugin/usdAbc/alembicUtil.h b/pxr/usd/plugin/usdAbc/alembicUtil.h
index 1b0b3e51..e34fef84 100644
--- a/pxr/usd/plugin/usdAbc/alembicUtil.h
+++ b/pxr/usd/plugin/usdAbc/alembicUtil.h
@@ -106,7 +106,10 @@ TF_DECLARE_PUBLIC_TOKENS(UsdAbcPrimTypeNames, USD_ABC_PRIM_TYPE_NAMES);
(userProperties) \
/* end */
#define USD_ABC_POINTBASED_NAMES \
- ((uv, "primvars:uv"))
+ ((uv, "primvars:uv")) \
+ ((uvIndices, "primvars:uv:indices")) \
+ ((st, "primvars:st")) \
+ ((stIndices, "primvars:st:indices")) \
/* end */
#define USD_ABC_PROPERTY_NAMES \
USD_ABC_GPRIM_NAMES \
--
2.16.4

0 comments on commit b13147e

Please sign in to comment.