@@ -404,31 +404,15 @@ class USDScene::IO : public RefCounted
404404 public :
405405
406406 IO ( const std::string &fileName, IndexedIO::OpenMode openMode )
407- : m_fileName ( fileName ), m_openMode( openMode )
407+ : IO( fileName, makeStage ( fileName, openMode ), openMode )
408408 {
409- switch ( m_openMode )
410- {
411- case IndexedIO::Read :
412- m_stage = pxr::UsdStage::Open ( fileName );
413- if ( !m_stage )
414- {
415- throw IECore::Exception ( boost::str ( boost::format ( " USDScene : Failed to open USD file: '%1%'" ) % fileName ) );
416- }
417- break ;
418- case IndexedIO::Write :
419- m_stage = pxr::UsdStage::CreateNew ( fileName );
420- break ;
421- default :
422- throw Exception ( " Unsupported OpenMode" );
423- }
424-
425- initStage ();
426409 }
427410
428- IO ( const pxr::UsdStageRefPtr &stage, IndexedIO::OpenMode openMode )
429- : m_fileName( " " ), m_openMode( openMode ), m_stage( stage )
411+ IO ( const std::string &fileName, const pxr::UsdStageRefPtr &stage, IndexedIO::OpenMode openMode )
412+ : m_fileName( fileName ), m_openMode( openMode ), m_stage( stage ),
413+ m_rootPrim ( m_stage->GetPseudoRoot () ),
414+ m_timeCodesPerSecond( m_stage->GetTimeCodesPerSecond () )
430415 {
431- initStage ();
432416 }
433417
434418 ~IO () override
@@ -443,12 +427,6 @@ class USDScene::IO : public RefCounted
443427 }
444428 }
445429
446- void initStage ()
447- {
448- m_timeCodesPerSecond = m_stage->GetTimeCodesPerSecond ();
449- m_rootPrim = m_stage->GetPseudoRoot ();
450- }
451-
452430 const std::string &fileName () const
453431 {
454432 return m_fileName;
@@ -513,6 +491,25 @@ class USDScene::IO : public RefCounted
513491
514492 private :
515493
494+ static pxr::UsdStageRefPtr makeStage ( const std::string &fileName, IndexedIO::OpenMode openMode )
495+ {
496+ switch ( openMode )
497+ {
498+ case IndexedIO::Read : {
499+ pxr::UsdStageRefPtr stage = pxr::UsdStage::Open ( fileName );
500+ if ( !stage )
501+ {
502+ throw IECore::Exception ( boost::str ( boost::format ( " USDScene : Failed to open USD file: '%1%'" ) % fileName ) );
503+ }
504+ return stage;
505+ }
506+ case IndexedIO::Write :
507+ return pxr::UsdStage::CreateNew ( fileName );
508+ default :
509+ throw Exception ( " Unsupported OpenMode" );
510+ }
511+ }
512+
516513 std::string m_fileName;
517514 IndexedIO::OpenMode m_openMode;
518515 pxr::UsdStageRefPtr m_stage;
@@ -534,7 +531,7 @@ USDScene::USDScene( const std::string &fileName, IndexedIO::OpenMode openMode )
534531}
535532
536533USDScene::USDScene ( const pxr::UsdStageRefPtr &stage, IndexedIO::OpenMode openMode )
537- : m_root( new IO( stage, openMode ) ),
534+ : m_root( new IO( " " , stage, openMode ) ),
538535 m_location( new Location( m_root->root () ) )
539536{
540537}
0 commit comments