diff --git a/Changes b/Changes index 44b90490b9..9412a2bcdf 100644 --- a/Changes +++ b/Changes @@ -6,6 +6,11 @@ Fixes - PointInstancer : Fixed accessors to accept Varying primitive variables where Vertex is expected, since the two interpolations are equivalent. +API +--- + +- IECoreUSD::StageAlgo : Added new namespace with a `sceneInterface()` function, providing a SceneInterface for reading an existing `UsdStage`. + 10.7.4.0 (relative to 10.7.3.1) ======== diff --git a/contrib/IECoreUSD/include/IECoreUSD/StageAlgo.h b/contrib/IECoreUSD/include/IECoreUSD/StageAlgo.h new file mode 100644 index 0000000000..4711f9253e --- /dev/null +++ b/contrib/IECoreUSD/include/IECoreUSD/StageAlgo.h @@ -0,0 +1,58 @@ +////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2026, Image Engine Design Inc. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// * Neither the name of Image Engine Design nor the names of any +// other contributors to this software may be used to endorse or +// promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////// + +#ifndef IECOREUSD_STAGEALGO_H +#define IECOREUSD_STAGEALGO_H + +#include "IECoreUSD/Export.h" + +#include "IECoreScene/SceneInterface.h" + +IECORE_PUSH_DEFAULT_VISIBILITY +#include "pxr/usd/usd/stage.h" +IECORE_POP_DEFAULT_VISIBILITY + +namespace IECoreUSD +{ + +namespace StageAlgo +{ + +IECOREUSD_API IECoreScene::SceneInterfacePtr sceneInterface( const pxr::UsdStageRefPtr &stage ); + +} // namespace StageAlgo + +} // namespace IECoreUSD + +#endif // IECOREUSD_STAGEALGO_H diff --git a/contrib/IECoreUSD/python/IECoreUSD/__init__.py b/contrib/IECoreUSD/python/IECoreUSD/__init__.py index b0bc2f7391..f805ff059d 100644 --- a/contrib/IECoreUSD/python/IECoreUSD/__init__.py +++ b/contrib/IECoreUSD/python/IECoreUSD/__init__.py @@ -40,6 +40,8 @@ __import__( "pxr.Vt" ) __import__( "pxr.Sdf" ) +__import__( "IECoreScene" ) + from ._IECoreUSD import * __import__( "IECore" ).loadConfig( "CORTEX_STARTUP_PATHS", subdirectory = "IECoreUSD" ) diff --git a/contrib/IECoreUSD/src/IECoreUSD/StageAlgo.cpp b/contrib/IECoreUSD/src/IECoreUSD/StageAlgo.cpp new file mode 100644 index 0000000000..577e2549dc --- /dev/null +++ b/contrib/IECoreUSD/src/IECoreUSD/StageAlgo.cpp @@ -0,0 +1,44 @@ +////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2026, Image Engine Design Inc. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// * Neither the name of Image Engine Design nor the names of any +// other contributors to this software may be used to endorse or +// promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////// + +#include "IECoreUSD/StageAlgo.h" + +#include "USDScene.h" + +using namespace IECoreUSD; + +IECoreScene::SceneInterfacePtr IECoreUSD::StageAlgo::sceneInterface( const pxr::UsdStageRefPtr &stage ) +{ + return new USDScene( stage, IECore::IndexedIO::Read ); +} diff --git a/contrib/IECoreUSD/src/IECoreUSD/bindings/IEUSDModule.cpp b/contrib/IECoreUSD/src/IECoreUSD/bindings/IEUSDModule.cpp index 8336d3e6ea..486a6c7db4 100644 --- a/contrib/IECoreUSD/src/IECoreUSD/bindings/IEUSDModule.cpp +++ b/contrib/IECoreUSD/src/IECoreUSD/bindings/IEUSDModule.cpp @@ -34,6 +34,7 @@ #include "IECoreUSD/DataAlgo.h" #include "IECoreUSD/SceneCacheDataAlgo.h" +#include "IECoreUSD/StageAlgo.h" #include "IECoreScene/SceneInterface.h" @@ -101,8 +102,11 @@ struct PxrBoostConverter static void registerConverters() { boost::python::to_python_converter(); - /// \todo Add conversion from Python when we have - /// a use for it. See PyBindConverter for an example. + boost::python::converter::registry::push_back( + &FromPxrBoost::convertible, + &FromPxrBoost::construct, + boost::python::type_id() + ); } private : @@ -117,6 +121,25 @@ struct PxrBoostConverter } }; + struct FromPxrBoost + { + + static void *convertible( PyObject *object ) + { + return pxr::pxr_boost::python::extract( object ).check() ? object : nullptr; + } + + static void construct( PyObject *object, boost::python::converter::rvalue_from_python_stage1_data *data ) + { + void *storage = ( ( boost::python::converter::rvalue_from_python_storage * ) data )->storage.bytes; + T *t = new( storage ) T; + data->convertible = storage; + + *t = pxr::pxr_boost::python::extract( object )(); + } + + }; + }; #endif // PXR_VERSION >= 2505 @@ -129,6 +152,7 @@ BOOST_PYTHON_MODULE( _IECoreUSD ) PxrBoostConverter::registerConverters(); PxrBoostConverter::registerConverters(); PxrBoostConverter::registerConverters(); + PxrBoostConverter::registerConverters(); #endif { @@ -152,4 +176,12 @@ BOOST_PYTHON_MODULE( _IECoreUSD ) def( "toInternalPath", toInternalPath ); def( "fromInternalPath", fromInternalPath ); } + + { + object stageAlgoModule( handle<>( borrowed( PyImport_AddModule( "IECoreUSD.StageAlgo" ) ) ) ); + scope().attr( "StageAlgo" ) = stageAlgoModule; + scope stageAlgoModuleScope( stageAlgoModule ); + + def( "sceneInterface", &StageAlgo::sceneInterface ); + } } diff --git a/contrib/IECoreUSD/test/IECoreUSD/All.py b/contrib/IECoreUSD/test/IECoreUSD/All.py index 49ce9812ba..df83cc887d 100644 --- a/contrib/IECoreUSD/test/IECoreUSD/All.py +++ b/contrib/IECoreUSD/test/IECoreUSD/All.py @@ -41,6 +41,7 @@ from USDSceneTest import USDSceneTest from SceneCacheFileFormatTest import SceneCacheFileFormatTest from DataAlgoTest import DataAlgoTest +from StageAlgoTest import StageAlgoTest unittest.TestProgram( testRunner = unittest.TextTestRunner( diff --git a/contrib/IECoreUSD/test/IECoreUSD/StageAlgoTest.py b/contrib/IECoreUSD/test/IECoreUSD/StageAlgoTest.py new file mode 100644 index 0000000000..36284e6ec5 --- /dev/null +++ b/contrib/IECoreUSD/test/IECoreUSD/StageAlgoTest.py @@ -0,0 +1,58 @@ +########################################################################## +# +# Copyright (c) 2026, Image Engine Design Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# * Neither the name of Image Engine Design nor the names of any +# other contributors to this software may be used to endorse or +# promote products derived from this software without specific prior +# written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +########################################################################## + +import unittest + +import pxr.Usd +import pxr.UsdGeom + +import IECoreScene +import IECoreUSD + +class StageAlgoTest( unittest.TestCase ) : + + def testSceneInterface( self ) : + + stage = pxr.Usd.Stage.CreateInMemory() + pxr.UsdGeom.Sphere.Define( stage, "/sphere" ) + + root = IECoreUSD.StageAlgo.sceneInterface( stage ) + del stage + + self.assertIsInstance( root, IECoreScene.SceneInterface ) + self.assertEqual( root.childNames(), [ "sphere" ] ) + self.assertIsInstance( root.child( "sphere" ).readObject( 0 ), IECoreScene.SpherePrimitive ) + +if __name__ == "__main__": + unittest.main()