Skip to content

Commit d591e5f

Browse files
committed
LiveScene: Fix bug when querying scene with multiple parent in the hierarchy.
For example, previously with the following hierarchy: /sphereA/a /sphereA/b we would get the following result for the childNames of the root level ["sphereA", "sphereA"] instead of ["sphereA"] or with the following hierarchy: /sphereA/a /sphereA/b /sphereB/c we would get the following result for the childNames of "sphereA": ["a","b","c"] instead of ["a","b"]
1 parent ff5aee6 commit d591e5f

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed

src/IECoreNuke/LiveScene.cpp

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,10 +549,21 @@ void LiveScene::childNames( NameList &childNames ) const
549549
IECoreScene::SceneInterface::stringToPath( m_rootPath, rootPath );
550550
for ( auto& path : allPaths )
551551
{
552+
// ignore children with a different root path
553+
if ( !( path.rfind( m_rootPath, 0 ) == 0 ) )
554+
{
555+
continue;
556+
}
557+
552558
allPath.clear();
553559
IECoreScene::SceneInterface::stringToPath( path, allPath );
554560
if ( rootPath.size() < allPath.size() )
555561
{
562+
// ignore duplicates.
563+
if ( find( childNames.begin(), childNames.end(), allPath[rootPath.size()] ) != childNames.end() )
564+
{
565+
continue;
566+
}
556567
childNames.push_back( allPath[rootPath.size()] );
557568
}
558569
}
@@ -583,7 +594,16 @@ SceneInterfacePtr LiveScene::child( const Name &name, MissingBehaviour missingBe
583594
throw Exception( "IECoreNuke::LiveScene: Name\"" + name.string() + "\" is missing and LiveScene is read-only" );
584595
}
585596
}
586-
return new LiveScene( m_op, m_rootPath + "/" + name.string() );
597+
598+
IECoreScene::SceneInterface::Path newPath;
599+
IECoreScene::SceneInterface::stringToPath( m_rootPath, newPath );
600+
601+
newPath.push_back( name.string() );
602+
603+
std::string newRoot;
604+
IECoreScene::SceneInterface::pathToString( newPath, newRoot );
605+
606+
return new LiveScene( m_op, newRoot );
587607
}
588608

589609
ConstSceneInterfacePtr LiveScene::child( const Name &name, MissingBehaviour missingBehaviour ) const
@@ -603,7 +623,16 @@ ConstSceneInterfacePtr LiveScene::child( const Name &name, MissingBehaviour miss
603623
throw Exception( "IECoreNuke::LiveScene: Name\"" + name.string() + "\" is missing and LiveScene is read-only" );
604624
}
605625
}
606-
return new LiveScene( m_op, m_rootPath + "/" + name.string() );
626+
627+
IECoreScene::SceneInterface::Path newPath;
628+
IECoreScene::SceneInterface::stringToPath( m_rootPath, newPath );
629+
630+
newPath.push_back( name.string() );
631+
632+
std::string newRoot;
633+
IECoreScene::SceneInterface::pathToString( newPath, newRoot );
634+
635+
return new LiveScene( m_op, newRoot );
607636
}
608637

609638
SceneInterfacePtr LiveScene::createChild( const Name &name )
@@ -636,6 +665,7 @@ ConstSceneInterfacePtr LiveScene::scene( const Path &path, MissingBehaviour miss
636665

637666
std::string pathStr;
638667
IECoreScene::SceneInterface::pathToString( path, pathStr );
668+
639669
return new LiveScene( m_op, pathStr );
640670
}
641671

test/IECoreNuke/LiveSceneKnobTest.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,47 @@ def testBounds( self ):
191191

192192
self.assertEqual( subScene.readBound(0), subExpectedScene.readBound(0) )
193193

194+
def testDuplicatedParent( self ):
195+
import IECoreScene
196+
197+
sceneFile = "test/IECoreNuke/scripts/data/duplicateParent.scc"
198+
sceneReader = nuke.createNode( "ieSceneCacheReader" )
199+
sceneReader.knob( "file" ).setValue( sceneFile )
200+
expectedScene = IECoreScene.SharedSceneInterfaces.get( sceneFile )
201+
202+
sceneReader.forceValidate()
203+
widget = sceneReader.knob( "sceneView" )
204+
widget.setSelectedItems( ['/root/groupA/cube','/root/groupA/sphere', '/root/groupB/sphere'] )
205+
206+
n = nuke.createNode( "ieLiveScene" )
207+
n.setInput( 0, sceneReader )
208+
209+
liveScene = n.knob( "scene" ).getValue()
210+
self.assertEqual( set( liveScene.childNames() ), set( expectedScene.childNames() ) )
211+
212+
def testFilterDifferentParent( self ):
213+
import IECoreScene
214+
215+
sceneFile = "test/IECoreNuke/scripts/data/duplicateParent.scc"
216+
sceneReader = nuke.createNode( "ieSceneCacheReader" )
217+
sceneReader.knob( "file" ).setValue( sceneFile )
218+
expectedScene = IECoreScene.SharedSceneInterfaces.get( sceneFile )
219+
220+
sceneReader.forceValidate()
221+
widget = sceneReader.knob( "sceneView" )
222+
widget.setSelectedItems( ['/root/groupA/cube','/root/groupA/sphere', '/root/groupB/sphere'] )
223+
224+
n = nuke.createNode( "ieLiveScene" )
225+
n.setInput( 0, sceneReader )
226+
227+
liveScene = n.knob( "scene" ).getValue()
228+
229+
for subPath in ( ["groupA"], ["groupB"] ):
230+
subScene = liveScene.scene( subPath )
231+
subExpectedScene = expectedScene.scene( subPath )
232+
233+
self.assertCountEqual( subScene.childNames(), subExpectedScene.childNames() )
234+
194235
def testAnimatedBounds( self ):
195236
import IECoreScene
196237

13.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)