-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in RND-699_Walter_UV_Smoothing_Issue (pull request #9)
Patch 21 - Resolved texture stretching artifacts Approved-by: Guillaume Laforge <[email protected]>
- Loading branch information
Showing
2 changed files
with
261 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
260 changes: 260 additions & 0 deletions
260
...latform_builder/patches/USD/0021-RDO-USD-Alembic-Fixed-texture-stretching-artifacts.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|