Skip to content

Commit

Permalink
SceneAlgo : ObjectProcessor object history fix
Browse files Browse the repository at this point in the history
Fixes #5406.
  • Loading branch information
ericmehl committed Nov 1, 2023
1 parent 03a2875 commit cd91b2d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Fixes
- Reference : Fixed rare reloading error.
- PlugLayout : Fixed lack of update when `layout:customWidget:*` metadata changes.
- Dispatch app : Removed unnecessary and misleading "Execute" button.
- SceneAlgo : Fixed computation of `ScenePlug.object` in networks with nodes derived from `ObjectProcessor`. These include : `CameraTweaks`, `ClosestPointSampler`, `CollectPrimitiveVariables`, `CopyPrimitiveVariables`, `CurveSampler`, `DeleteCurves`, `DeleteFaces`, `DeletePoints`, `MapOffset`, `MapProjection`, `MeshDistortion`, `MeshNormals`, `MeshSegments`, `MeshTangents`, `MeshToPoints`, `MeshType`, `Orientation`, `PointsType`, `PrimitiveSampler`, `PrimitiveVariables`, `ReverseWinding`, `ShufflePrimitiveVariables` and `UVSampler` (#5406).

API
---
Expand Down
32 changes: 32 additions & 0 deletions python/GafferSceneTest/SceneAlgoTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,38 @@ def testHistoryPerformanceAlreadyCached( self ) :
h = h.predecessors[-1]
self.assertEqual( h.context["seed"], 5 )

def testObjectProcessorHistory( self ) :

plane = GafferScene.Plane()

meshType = GafferScene.MeshType()
meshType["in"].setInput( plane["out"] )

def runTest() :

history = GafferScene.SceneAlgo.history( meshType["out"]["object"], "/plane" )

for plug, scenePath in [
( meshType["out"], "/plane" ),
( meshType["in"], "/plane" ),
( plane["out"], "/plane" ),
] :
self.assertEqual( history.scene, plug )
self.assertEqual( GafferScene.ScenePlug.pathToString( history.context["scene:path"] ), scenePath )
history = history.predecessors[0] if history.predecessors else None

self.assertIsNone( history )

runTest()

# Test running the test while everything is already cached still works, and doesn't add any
# new entries to the cache
Gaffer.ValuePlug.clearHashCache()
runTest()
before = Gaffer.ValuePlug.hashCacheTotalUsage()
runTest()
self.assertEqual( Gaffer.ValuePlug.hashCacheTotalUsage(), before )

def testHistoryWithNoComputes( self ) :

switch = Gaffer.Switch()
Expand Down
17 changes: 12 additions & 5 deletions src/GafferScene/SceneAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,8 @@ struct CapturedProcess

};

const InternedString g_processedObjectPlugName( "__processedObject" );

/// \todo Perhaps add this to the Gaffer module as a
/// public class, and expose it within the stats app?
/// Give a bit more thought to the CapturedProcess
Expand Down Expand Up @@ -432,7 +434,7 @@ class CapturingMonitor : public Monitor

CapturedProcess::Ptr capturedProcess;
ProcessOrScope entry;
if( !p->parent<ScenePlug>() || p->getName() != m_scenePlugChildName )
if( !shouldCapture( p ) )
{
// Parents may spawn other processes in support of the requested plug. This is one
// of these other plugs that isn't directly the requested plug. Instead of creating
Expand Down Expand Up @@ -491,10 +493,7 @@ class CapturingMonitor : public Monitor

bool forceMonitoring( const Plug *plug, const IECore::InternedString &processType ) override
{
if(
processType == g_hashProcessType &&
plug->parent<ScenePlug>() && plug->getName() == m_scenePlugChildName
)
if( processType == g_hashProcessType && shouldCapture( plug ) )
{
return true;
}
Expand All @@ -504,6 +503,14 @@ class CapturingMonitor : public Monitor

private :

bool shouldCapture( const Plug *plug ) const
{
return
( plug->parent<ScenePlug>() && plug->getName() == m_scenePlugChildName ) ||
( (Gaffer::TypeId)plug->typeId() == Gaffer::TypeId::ObjectPlugTypeId && plug->getName() == g_processedObjectPlugName )
;
}

using Mutex = tbb::spin_mutex;

Mutex m_mutex;
Expand Down

0 comments on commit cd91b2d

Please sign in to comment.