From f3c2f016beae3647910d1cd70e9f5c5a5fe8ef5f Mon Sep 17 00:00:00 2001 From: Yannic Schoof Date: Wed, 16 Mar 2022 12:11:46 -0700 Subject: [PATCH 01/10] options: Build maya IECoreUSD against the maya-usd plugin libraries if installed Note: - Autodesk does ship the USD libraries but not the header files. We try to find a local USD install of the version maya-usd is using and set the include directory respectively. If there is no compatible USD version present, we fall back to the cortex defined USD version and build `IECoreUSD` for Maya against this one. - In the transition from python 2 to 3, maya-usd is shipped with the libraries for both versions, so we have to add the python major version suffix for Maya 2022. The library folders for Maya 2020.4 don't have this suffix and because Maya 2023 is supposed to be python3 exclusively (Autodesk release notes),we assume the suffix to be removed in that version again --- config/ie/options | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/config/ie/options b/config/ie/options index 03aef8206d..5b072b95ab 100644 --- a/config/ie/options +++ b/config/ie/options @@ -326,6 +326,29 @@ if targetApp=="maya" : INSTALL_COREMAYA_POST_COMMAND="scons -i -f config/ie/postCoreMayaInstall MAYA_VERSION='" + mayaVersion + "' INSTALLPREFIX="+appPrefix+" install" WITH_MAYA_PLUGIN_LOADER = 1 + mayaUsdVersion = mayaReg.get( "mayaUsdVersion" ) + mayaUsdReg = IEEnv.registry["apps"]["mayaUsd"].get( mayaUsdVersion, {} ).get( platform ) + # If the Maya usd plugin is not in the registry we build against our standalone USD version + if mayaUsdReg : + pluginUsdVersion = mayaUsdReg["usdVersion"] + # Maya ships the USD libraries with the installation, but not the header files... we use the one that are installed by standalone usd + usdReg = IEEnv.registry["apps"]["usd"].get( pluginUsdVersion, {} ).get( platform ) + if usdReg : + USD_INCLUDE_PATH = os.path.join( usdReg["location"], targetApp, compatibilityVersion, "include" ) + + mayaLooseVersion = distutils.version.LooseVersion(mayaVersion) + if mayaLooseVersion >= "2022" and mayaLooseVersion < "2023": + # Maya 2022 installs the USD libs and the maya plugin itself for python 2 and 3. This is not the case for the 2020 version + # We make the assumption, that the python version suffix is for Maya 2022 only, because Maya 2023 will be python 3 exclusively. + mayaPythonMajorVersion = mayaReg["pythonVersion"].split(".")[0] + USD_LIB_PATH = os.path.join( mayaUsdReg["location"], "mayausd/USD{}/lib".format( mayaPythonMajorVersion ) ) + else: + USD_LIB_PATH = os.path.join( mayaUsdReg["location"], "mayausd/USD/lib" ) + + # Pixar introduced a library prefix `usd_` in USD v21.11, which Autodesk does not use yet, so we have to reset the prefix. + # See https://github.com/Autodesk/maya-usd/issues/2108 for reference + USD_LIB_PREFIX = "" if mayaUsdReg.get( "usdLibPrefix" ) == "" else mayaUsdReg.get( "usdLibPrefix" ) or USD_LIB_PREFIX + # find nuke if we're building for nuke if targetApp=="nuke" : From 76d5c98b8a6bcf47b616a94c086908c5a6c39405 Mon Sep 17 00:00:00 2001 From: John Haddon Date: Wed, 6 Apr 2022 10:08:01 +0100 Subject: [PATCH 02/10] USDScene : Register `.usdz` file format --- contrib/IECoreUSD/src/IECoreUSD/USDScene.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/IECoreUSD/src/IECoreUSD/USDScene.cpp b/contrib/IECoreUSD/src/IECoreUSD/USDScene.cpp index bb90939e75..eeb734a938 100644 --- a/contrib/IECoreUSD/src/IECoreUSD/USDScene.cpp +++ b/contrib/IECoreUSD/src/IECoreUSD/USDScene.cpp @@ -1440,5 +1440,6 @@ namespace SceneInterface::FileFormatDescription g_descriptionUSD( ".usd", IndexedIO::Read | IndexedIO::Write ); SceneInterface::FileFormatDescription g_descriptionUSDA( ".usda", IndexedIO::Read | IndexedIO::Write ); SceneInterface::FileFormatDescription g_descriptionUSDC( ".usdc", IndexedIO::Read | IndexedIO::Write ); +SceneInterface::FileFormatDescription g_descriptionUSDZ( ".usdz", IndexedIO::Read | IndexedIO::Write ); } // namespace From e9563be3a77c172a01f96051f0213c34c4bf7c4d Mon Sep 17 00:00:00 2001 From: Ivan Imanishi Date: Fri, 8 Apr 2022 15:14:06 -0700 Subject: [PATCH 03/10] Changes : Updated for new release --- Changes | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Changes b/Changes index e75da36894..f46363858e 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,10 @@ +10.3.5.0 (relative to 10.3.4.1) + +Improvements +------------ + +- USDScene : Registered .usdz file format (#1257). + 10.3.4.1 (relative to 10.3.4.0) ======== From 6a0316d590ecc5330f14a4c778daff0b2b83cfda Mon Sep 17 00:00:00 2001 From: Ivan Imanishi Date: Fri, 8 Apr 2022 15:15:13 -0700 Subject: [PATCH 04/10] SConstruct : Bump version to 10.3.5.0 --- SConstruct | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SConstruct b/SConstruct index 3f56b82ec1..981f706eb0 100644 --- a/SConstruct +++ b/SConstruct @@ -56,8 +56,8 @@ SConsignFile() ieCoreMilestoneVersion = 10 # for announcing major milestones - may contain all of the below ieCoreMajorVersion = 3 # backwards-incompatible changes -ieCoreMinorVersion = 4 # new backwards-compatible features -ieCorePatchVersion = 1 # bug fixes +ieCoreMinorVersion = 5 # new backwards-compatible features +ieCorePatchVersion = 0 # bug fixes ieCoreVersionSuffix = "" # used for alpha/beta releases. Example: "a1", "b2", etc. ########################################################################################### From dac816de62b3fdf2493146267371ab01677656c5 Mon Sep 17 00:00:00 2001 From: Yannic Schoof Date: Tue, 12 Apr 2022 16:13:56 -0700 Subject: [PATCH 05/10] options: Add Maya major version subfolder to `USD_LIB_PATH` --- config/ie/options | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/config/ie/options b/config/ie/options index 5b072b95ab..fda90d3143 100644 --- a/config/ie/options +++ b/config/ie/options @@ -336,14 +336,15 @@ if targetApp=="maya" : if usdReg : USD_INCLUDE_PATH = os.path.join( usdReg["location"], targetApp, compatibilityVersion, "include" ) + mayaMajorVersion = mayaVersion.split(".")[0] mayaLooseVersion = distutils.version.LooseVersion(mayaVersion) if mayaLooseVersion >= "2022" and mayaLooseVersion < "2023": # Maya 2022 installs the USD libs and the maya plugin itself for python 2 and 3. This is not the case for the 2020 version # We make the assumption, that the python version suffix is for Maya 2022 only, because Maya 2023 will be python 3 exclusively. mayaPythonMajorVersion = mayaReg["pythonVersion"].split(".")[0] - USD_LIB_PATH = os.path.join( mayaUsdReg["location"], "mayausd/USD{}/lib".format( mayaPythonMajorVersion ) ) + USD_LIB_PATH = os.path.join( mayaUsdReg["location"], mayaMajorVersion, "mayausd/USD{}/lib".format( mayaPythonMajorVersion ) ) else: - USD_LIB_PATH = os.path.join( mayaUsdReg["location"], "mayausd/USD/lib" ) + USD_LIB_PATH = os.path.join( mayaUsdReg["location"], mayaMajorVersion, "mayausd/USD/lib" ) # Pixar introduced a library prefix `usd_` in USD v21.11, which Autodesk does not use yet, so we have to reset the prefix. # See https://github.com/Autodesk/maya-usd/issues/2108 for reference From 8e2069739cd5dc0dfbfaa313fc1a57b78699db99 Mon Sep 17 00:00:00 2001 From: John Haddon Date: Fri, 4 Feb 2022 12:11:25 +0000 Subject: [PATCH 06/10] USDScene : Fix compatibility with USD 21.08 `GetPrimInMaster()` was deprecated in USD 20.11, when `GetPrimInPrototype()` was added. It was removed in USD 21.08. --- contrib/IECoreUSD/src/IECoreUSD/USDScene.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/contrib/IECoreUSD/src/IECoreUSD/USDScene.cpp b/contrib/IECoreUSD/src/IECoreUSD/USDScene.cpp index eeb734a938..4853e27d07 100644 --- a/contrib/IECoreUSD/src/IECoreUSD/USDScene.cpp +++ b/contrib/IECoreUSD/src/IECoreUSD/USDScene.cpp @@ -93,6 +93,10 @@ using namespace IECoreUSD; #define HasAuthoredValue HasAuthoredValueOpinion #endif +#if USD_VERSION < 2011 +#define GetPrimInPrototype GetPrimInMaster +#endif + namespace { @@ -105,7 +109,7 @@ void appendPrimOrMasterPath( const pxr::UsdPrim &prim, IECore::MurmurHash &h ) { if( prim.IsInstanceProxy() ) { - append( prim.GetPrimInMaster().GetPrimPath(), h ); + append( prim.GetPrimInPrototype().GetPrimPath(), h ); } else { From 6ce5969a4c0626f34fe701e869e00d66521132a1 Mon Sep 17 00:00:00 2001 From: Ivan Imanishi Date: Wed, 20 Apr 2022 16:36:20 -0700 Subject: [PATCH 07/10] Update Changes --- Changes | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Changes b/Changes index f46363858e..737613c66d 100644 --- a/Changes +++ b/Changes @@ -1,4 +1,13 @@ +10.3.5.1 (relative to 10.3.5.0) +======== + +Fixes +----- + +- USDScene : Fixed compatibility with USD 21.08 (#1259). + 10.3.5.0 (relative to 10.3.4.1) +======== Improvements ------------ From 366b72f48cf77faf796fd4ebb8454975ba38a5b7 Mon Sep 17 00:00:00 2001 From: Ivan Imanishi Date: Wed, 20 Apr 2022 16:37:33 -0700 Subject: [PATCH 08/10] SConstruct : Bumped version to 10.3.5.1 --- SConstruct | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SConstruct b/SConstruct index 981f706eb0..c6adc01eed 100644 --- a/SConstruct +++ b/SConstruct @@ -57,7 +57,7 @@ SConsignFile() ieCoreMilestoneVersion = 10 # for announcing major milestones - may contain all of the below ieCoreMajorVersion = 3 # backwards-incompatible changes ieCoreMinorVersion = 5 # new backwards-compatible features -ieCorePatchVersion = 0 # bug fixes +ieCorePatchVersion = 1 # bug fixes ieCoreVersionSuffix = "" # used for alpha/beta releases. Example: "a1", "b2", etc. ########################################################################################### From 1d6bdb8c42b76c1b287aa1b3715b10aafe05f9f3 Mon Sep 17 00:00:00 2001 From: John Haddon Date: Thu, 21 Apr 2022 11:06:00 +0100 Subject: [PATCH 09/10] USDScene : Support `doubleSided` attribute Write support is not ideal, because USD will only author `doubleSided` onto Gprims. So it is impossible to write onto transform-only locations, and `writeObject()` must be called before `writeAttribute()` on geometric locations. It may be possible to improve on this by buffering attributes and automatically inheriting them from transforms onto primitives, but it's not clear that the complexity is justified at this point. --- contrib/IECoreUSD/src/IECoreUSD/USDScene.cpp | 50 ++++++++++++ .../IECoreUSD/test/IECoreUSD/USDSceneTest.py | 80 +++++++++++++++++++ .../IECoreUSD/data/doubleSidedAttribute.usda | 16 ++++ 3 files changed, 146 insertions(+) create mode 100644 contrib/IECoreUSD/test/IECoreUSD/data/doubleSidedAttribute.usda diff --git a/contrib/IECoreUSD/src/IECoreUSD/USDScene.cpp b/contrib/IECoreUSD/src/IECoreUSD/USDScene.cpp index 4853e27d07..fce4291823 100644 --- a/contrib/IECoreUSD/src/IECoreUSD/USDScene.cpp +++ b/contrib/IECoreUSD/src/IECoreUSD/USDScene.cpp @@ -56,6 +56,7 @@ IECORE_PUSH_DEFAULT_VISIBILITY #include "pxr/usd/usd/stage.h" #include "pxr/usd/usdGeom/bboxCache.h" #include "pxr/usd/usdGeom/camera.h" +#include "pxr/usd/usdGeom/gprim.h" #include "pxr/usd/usdGeom/metrics.h" #include "pxr/usd/usdGeom/pointInstancer.h" #include "pxr/usd/usdGeom/primvar.h" @@ -803,6 +804,7 @@ namespace const IECore::InternedString g_purposeAttributeName( "usd:purpose" ); const IECore::InternedString g_kindAttributeName( "usd:kind" ); +const IECore::InternedString g_doubleSidedAttributeName( "doubleSided" ); } // namespace @@ -828,6 +830,10 @@ bool USDScene::hasAttribute( const SceneInterface::Name &name ) const pxr::TfToken kind; return model.GetKind( &kind ); } + else if( name == g_doubleSidedAttributeName ) + { + return pxr::UsdGeomGprim( m_location->prim ).GetDoubleSidedAttr().HasAuthoredValue(); + } else if( auto attribute = AttributeAlgo::findUSDAttribute( m_location->prim, name.string() ) ) { return attribute.HasAuthoredValue(); @@ -876,6 +882,11 @@ void USDScene::attributeNames( SceneInterface::NameList &attrs ) const attrs.push_back( g_kindAttributeName ); } + if( pxr::UsdGeomGprim( m_location->prim ).GetDoubleSidedAttr().HasAuthoredValue() ) + { + attrs.push_back( g_doubleSidedAttributeName ); + } + std::vector attributes = m_location->prim.GetAuthoredAttributes(); for( const auto &attribute : attributes ) { @@ -961,6 +972,16 @@ ConstObjectPtr USDScene::readAttribute( const SceneInterface::Name &name, double } return new StringData( kind.GetString() ); } + else if( name == g_doubleSidedAttributeName ) + { + pxr::UsdAttribute attr = pxr::UsdGeomGprim( m_location->prim ).GetDoubleSidedAttr(); + bool doubleSided; + if( attr.HasAuthoredValue() && attr.Get( &doubleSided, m_root->getTime( time ) ) ) + { + return new BoolData( doubleSided ); + } + return nullptr; + } else if( pxr::UsdAttribute attribute = AttributeAlgo::findUSDAttribute( m_location->prim, name.string() ) ) { return DataAlgo::fromUSD( attribute, m_root->getTime( time ) ); @@ -1022,6 +1043,28 @@ void USDScene::writeAttribute( const SceneInterface::Name &name, const Object *a } } } + else if( name == g_doubleSidedAttributeName ) + { + if( auto *data = reportedCast( attribute, "USDScene::writeAttribute", name.c_str() ) ) + { + pxr::UsdGeomGprim gprim( m_location->prim ); + if( gprim ) + { + gprim.GetDoubleSidedAttr().Set( data->readable(), m_root->getTime( time ) ); + } + else + { + // We're hamstrung by the fact that USD considers `doubleSided` to be a property + // of a Gprim and not an inheritable attribute as it was in RenderMan and is in Cortex. + // We can't author a Gprim here, because it isn't a concrete type, so we must rely on + // `writeObject()` having been called first to get a suitable concrete type in place. + IECore::msg( + IECore::Msg::Warning, "USDScene::writeAttribute", + boost::format( "Unable to write attribute \"%1%\" to \"%2%\", because it is not a Gprim" ) % name % m_location->prim.GetPath() + ); + } + } + } else if( const IECoreScene::ShaderNetwork *shaderNetwork = runTimeCast( attribute ) ) { m_shaders[name] = shaderNetwork; @@ -1356,6 +1399,13 @@ void USDScene::attributesHash( double time, IECore::MurmurHash &h ) const // Kind can not be animated so no need to update `mightBeTimeVarying`. } + auto doubleSidedAttr = pxr::UsdGeomGprim( m_location->prim ).GetDoubleSidedAttr(); + if( doubleSidedAttr && doubleSidedAttr.HasAuthoredValue() ) + { + haveAttributes = true; + mightBeTimeVarying |= doubleSidedAttr.ValueMightBeTimeVarying(); + } + std::vector attributes = m_location->prim.GetAuthoredAttributes(); for( const auto &attribute : attributes ) { diff --git a/contrib/IECoreUSD/test/IECoreUSD/USDSceneTest.py b/contrib/IECoreUSD/test/IECoreUSD/USDSceneTest.py index dfb2448f99..7c263a7337 100644 --- a/contrib/IECoreUSD/test/IECoreUSD/USDSceneTest.py +++ b/contrib/IECoreUSD/test/IECoreUSD/USDSceneTest.py @@ -2967,5 +2967,85 @@ def testExposedShaderInput( self ) : self.assertEqual( network.getOutput(), "surface" ) self.assertEqual( network.getShader( "surface" ).parameters["diffuse_roughness"].value, 0.75 ) + def testReadDoubleSidedAttribute( self ) : + + root = IECoreScene.SceneInterface.create( + os.path.join( os.path.dirname( __file__ ), "data", "doubleSidedAttribute.usda" ), + IECore.IndexedIO.OpenMode.Read + ) + + for name, doubleSided in { + "sphere" : None, + "singleSidedSphere" : False, + "doubleSidedSphere" : True + }.items() : + object = root.child( name ) + if doubleSided is None : + self.assertFalse( object.hasAttribute( "doubleSided" ) ) + self.assertNotIn( "doubleSided", object.attributeNames() ) + else : + self.assertTrue( object.hasAttribute( "doubleSided" ) ) + self.assertIn( "doubleSided", object.attributeNames() ) + self.assertEqual( object.readAttribute( "doubleSided", 1 ), IECore.BoolData( doubleSided ) ) + + def testWriteDoubleSidedAttribute( self ) : + + # Write via SceneInterface + + fileName = os.path.join( self.temporaryDirectory(), "doubleSidedAttribute.usda" ) + root = IECoreScene.SceneInterface.create( fileName, IECore.IndexedIO.OpenMode.Write ) + + toWrite = ( + ( "singleSidedSphere", "before", False ), + ( "doubleSidedSphere", "before", True ), + ( "doubleSidedSphereWrittenAfter", "after", True ), + ( "doubleSidedNoObject", "never", True ), + ( "sphere", "before", None ), + ) + + for name, writeObject, doubleSided in toWrite : + + child = root.createChild( name ) + if writeObject == "before" : + child.writeObject( IECoreScene.SpherePrimitive(), 1 ) + + if doubleSided is not None : + + with IECore.CapturingMessageHandler() as mh : + child.writeAttribute( "doubleSided", IECore.BoolData( doubleSided ), 1 ) + + if writeObject != "before" : + self.assertEqual( len( mh.messages ), 1 ) + self.assertEqual( + mh.messages[0].message, + 'Unable to write attribute "doubleSided" to "/{}", because it is not a Gprim'.format( + name + ) + ) + + if writeObject == "after" : + child.writeObject( IECoreScene.SpherePrimitive(), 1 ) + + del root, child + + # Verify via USD API + + stage = pxr.Usd.Stage.Open( fileName ) + + for name, writeObject, doubleSided in toWrite : + + if writeObject != "before" : + doubleSided = None + + if doubleSided is None : + self.assertFalse( + pxr.UsdGeom.Gprim( stage.GetPrimAtPath( "/" + name ) ).GetDoubleSidedAttr().HasAuthoredValue(), + ) + else : + self.assertEqual( + pxr.UsdGeom.Gprim( stage.GetPrimAtPath( "/" + name ) ).GetDoubleSidedAttr().Get( 1 ), + doubleSided + ) + if __name__ == "__main__": unittest.main() diff --git a/contrib/IECoreUSD/test/IECoreUSD/data/doubleSidedAttribute.usda b/contrib/IECoreUSD/test/IECoreUSD/data/doubleSidedAttribute.usda new file mode 100644 index 0000000000..1e5dd4c652 --- /dev/null +++ b/contrib/IECoreUSD/test/IECoreUSD/data/doubleSidedAttribute.usda @@ -0,0 +1,16 @@ +#usda 1.0 + +def Sphere "doubleSidedSphere" +{ + uniform bool doubleSided = 1 +} + +def Sphere "singleSidedSphere" +{ + uniform bool doubleSided = 0 +} + +def Sphere "sphere" +{ +} + From e3ee519d83aa8cc187eda6169901a55078e0b2e7 Mon Sep 17 00:00:00 2001 From: John Haddon Date: Tue, 26 Apr 2022 09:21:07 +0100 Subject: [PATCH 10/10] Bump version to 10.3.6.0 and update Changes --- Changes | 8 ++++++++ SConstruct | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Changes b/Changes index 737613c66d..871b34c3df 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,11 @@ +10.3.6.0 (relative to 10.3.5.1) +======== + +Improvements +------------ + +- USDScene : Added support for the `doubleSided` attribute. + 10.3.5.1 (relative to 10.3.5.0) ======== diff --git a/SConstruct b/SConstruct index c6adc01eed..c424ff859b 100644 --- a/SConstruct +++ b/SConstruct @@ -56,8 +56,8 @@ SConsignFile() ieCoreMilestoneVersion = 10 # for announcing major milestones - may contain all of the below ieCoreMajorVersion = 3 # backwards-incompatible changes -ieCoreMinorVersion = 5 # new backwards-compatible features -ieCorePatchVersion = 1 # bug fixes +ieCoreMinorVersion = 6 # new backwards-compatible features +ieCorePatchVersion = 0 # bug fixes ieCoreVersionSuffix = "" # used for alpha/beta releases. Example: "a1", "b2", etc. ###########################################################################################