Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ Fixes
- Fixed refusal to show pop-up editors for plugs which had been ganged, animated or locked.
- Fixed refusal to edit optional parameters on lights, such as the renderer-specific parameters on USD lights.
- Fixed bug that misattributed shader parameter edits to ShaderTweaks nodes when the `shader` plug didn't match the inspected attribute.
- LightTool : Fixed messaging for parameters which were not editable, for example because they originated in a SceneReader.
- Fixed pasting of values onto animated cells. A keyframe is now created as needed.
- LightTool :
- Fixed messaging for parameters which were not editable, for example because they originated in a SceneReader.
- Fixed editing of animated parameters viewed through a TimeWarp. Keyframes are now made on the correct (warped) frame.

API
---
Expand Down
1 change: 0 additions & 1 deletion python/GafferSceneUI/_InspectorColumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,6 @@ def __matrixValue( objectMatrix, row, column ) :

return value

## \todo Support pasting `atTime` once `Inspection::edit()` has support for it.
def __pasteFunctionsOrNonPasteableReason( pathListing, objectMatrix ) :

if objectMatrix is None :
Expand Down
67 changes: 66 additions & 1 deletion python/GafferSceneUITest/AttributeInspectorTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __inspect( scene, path, attribute, editScope=None ) :
editScopePlug = Gaffer.Plug()
editScopePlug.setInput( editScope["enabled"] if editScope is not None else None )
inspector = GafferSceneUI.Private.AttributeInspector( scene, editScopePlug, attribute )
with Gaffer.Context() as context :
with Gaffer.Context( Gaffer.Context.current() ) as context :
context["scene:path"] = IECore.InternedStringVectorData( path.split( "/" )[1:] )
return inspector.inspect()

Expand Down Expand Up @@ -1497,3 +1497,68 @@ def testDisabledNodeIsNotSource( self ) :

inspection = self.__inspect( script["attributes2"]["out"], "/cube", "scene:visible", None )
self.assertEqual( inspection.source(), script["attributes1"]["out"] )

@GafferTest.TestRunner.CategorisedTestMethod( { "inspector" } )
def testEditAnimatedAttribute( self ) :

script = Gaffer.ScriptNode()

script["plane"] = GafferScene.Plane()
script["attributes"] = GafferScene.CustomAttributes()
script["attributes"]["in"].setInput( script["plane"]["out"] )
script["attributes"]["attributes"].addChild( Gaffer.NameValuePlug( "int", 1 ) )
script["attributes"]["attributes"].addChild( Gaffer.NameValuePlug( "float", 1.0 ) )
script["attributes"]["attributes"].addChild( Gaffer.NameValuePlug( "bool", True ) )

context = Gaffer.Context()

for attribute in script["attributes"]["attributes"] :

curve = Gaffer.Animation.acquire( attribute["value"] )
curve.addKey( Gaffer.Animation.Key( time = context.getTime(), value = 0 ) )

with context :
inspection = self.__inspect( script["attributes"]["out"], "/plane", attribute["name"].getValue(), None )

self.assertEqual( inspection.value().value, attribute["value"].getValue() )
newValue = type( inspection.value() )( 1 )
self.assertTrue( inspection.canEdit( newValue ) )
inspection.edit( newValue )

self.assertEqual( attribute["value"].getValue(), 1 )
self.assertTrue( Gaffer.Animation.acquire( attribute["value"] ).isSame( curve ) )
self.assertEqual( curve.getKey( context.getTime() ).getValue(), 1 )

@GafferTest.TestRunner.CategorisedTestMethod( { "inspector" } )
def testEditAnimationThroughTimeWarp( self ) :

script = Gaffer.ScriptNode()

script["plane"] = GafferScene.Plane()

script["attributes"] = GafferScene.CustomAttributes()
script["attributes"]["in"].setInput( script["plane"]["out"] )
script["attributes"]["attributes"].addChild( Gaffer.NameValuePlug( "test", 1.0 ) )

curve = Gaffer.Animation.acquire( script["attributes"]["attributes"][0]["value"] )
curve.insertKey( 0, 0 )
curve.insertKey( 10, 10 )

context = Gaffer.Context()

script["timeWarp"] = Gaffer.TimeWarp()
script["timeWarp"].setup( script["attributes"]["out"] )
script["timeWarp"]["in"].setInput( script["attributes"]["out"] )
script["timeWarp"]["offset"].setValue( 5 * context.getFramesPerSecond() )

context.setTime( 0 )
with context :
inspection = self.__inspect( script["timeWarp"]["out"], "/plane", "test", None )

# Viewing through a time warp, so we see the value from `time == 5`.
self.assertEqual( inspection.value().value, 5 )
# Meaning that when we edit, we should make a keyframe at `time == 5`.
inspection.edit( IECore.FloatData( 7 ) )
newKey = curve.getKey( 5 )
self.assertIsNotNone( newKey )
self.assertEqual( newKey.getValue(), 7 )
8 changes: 4 additions & 4 deletions src/GafferSceneUI/Inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ std::string nonEditableReason( const ValuePlug *plug )
return "";
}

void setPlugValue( ValuePlug *plug, const IECore::Object *value, bool dryRun )
void setPlugValue( ValuePlug *plug, const IECore::Object *value, float time, bool dryRun )
{
ValuePlug *valuePlug;
BoolPlug *enabledPlug = nullptr;
Expand Down Expand Up @@ -235,7 +235,7 @@ void setPlugValue( ValuePlug *plug, const IECore::Object *value, bool dryRun )
{
modePlug->setValue( TweakPlug::Mode::Create );
}
PlugAlgo::setValueFromData( valuePlug, data );
PlugAlgo::setValueOrInsertKeyFromData( valuePlug, time, data );
}

} // namespace
Expand Down Expand Up @@ -618,7 +618,7 @@ void Inspector::edit( const IECore::Object *value, Gaffer::EditScope *editScope,
if( plug )
{
plug = static_cast<ValuePlug *>( spreadsheetAwareSource( plug.get() ) );
setPlugValue( plug.get(), value, /* dryRun = */ true );
setPlugValue( plug.get(), value, history->context->getTime(), /* dryRun = */ true );
}
else
{
Expand Down Expand Up @@ -652,7 +652,7 @@ void Inspector::edit( const IECore::Object *value, Gaffer::EditScope *editScope,
acquireEdit( history, /* createIfNecessary = */ true, /* dryRun = */ false )
;
plug = static_cast<ValuePlug *>( spreadsheetAwareSource( plug.get() ) );
setPlugValue( plug.get(), value, /* dryRun = */ false );
setPlugValue( plug.get(), value, history->context->getTime(), /* dryRun = */ false );
}

void Inspector::disableEdit( const GafferScene::SceneAlgo::History *history, bool dryRun ) const
Expand Down
85 changes: 6 additions & 79 deletions src/GafferSceneUI/LightTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,10 @@
#include "GafferUI/ImageGadget.h"
#include "GafferUI/StandardStyle.h"

#include "Gaffer/Animation.h"
#include "Gaffer/Metadata.h"
#include "Gaffer/MetadataAlgo.h"
#include "Gaffer/NameValuePlug.h"
#include "Gaffer/OptionalValuePlug.h"
#include "Gaffer/PathFilter.h"
#include "Gaffer/ScriptNode.h"
#include "Gaffer/TweakPlug.h"
#include "Gaffer/UndoScope.h"

#include "IECoreGL/Camera.h"
Expand Down Expand Up @@ -144,45 +140,6 @@ const ModifiableEvent::Modifiers g_quadLightConstrainAspectRatioKey = Modifiable
const InternedString g_coneAngleParameter = "coneAngleParameter";
const InternedString g_penumbraAngleParameter = "penumbraAngleParameter";

// Return the plug that holds the value we need to edit, and make sure it's enabled.

/// \todo This currently does nothing to enable a row if is disabled. Is that worth doing?

Plug *activeValuePlug( Plug *sourcePlug )
{
if( auto nameValuePlug = runTimeCast<NameValuePlug>( sourcePlug ) )
{
nameValuePlug->enabledPlug()->setValue( true );
return nameValuePlug->valuePlug();
}
if( auto tweakPlug = runTimeCast<TweakPlug>( sourcePlug ) )
{
tweakPlug->enabledPlug()->setValue( true );
return tweakPlug->valuePlug();
}
if( auto optionalValuePlug = runTimeCast<OptionalValuePlug>( sourcePlug ) )
{
optionalValuePlug->enabledPlug()->setValue( true );
return optionalValuePlug->valuePlug();
}
return sourcePlug;
}

/// \todo We should be using `Inspector::edit()` to edit values, but
/// that doesn't currently support animation.
void setValueOrAddKey( FloatPlug *plug, float time, float value )
{
if( Animation::isAnimated( plug ) )
{
Animation::CurvePlug *curve = Animation::acquire( plug );
curve->insertKey( time, value );
}
else
{
plug->setValue( value );
}
}

const char *constantFragSource()
{
return
Expand Down Expand Up @@ -1016,17 +973,10 @@ class LightToolHandle : public Handle
continue;
}

ValuePlugPtr parameterPlug = it->second->acquireEdit();
auto floatPlug = runTimeCast<FloatPlug>( activeValuePlug( parameterPlug.get() ) );
if( !floatPlug )
{
throw Exception( fmt::format( "\"{}\" parameter must use `FloatPlug`", metaParameter.string() ) );
}

const float originalValue = it->second->typedValue<float>( 0.f );
const float nonZeroValue = originalValue == 0 ? 1.f : originalValue;
setValueOrAddKey( floatPlug, m_view->context()->getTime(), nonZeroValue * mult );

ConstFloatDataPtr newValue = new FloatData( nonZeroValue * mult );
it->second->edit( newValue.get() );
}
}

Expand All @@ -1042,19 +992,9 @@ class LightToolHandle : public Handle
continue;
}

ValuePlugPtr parameterPlug = it->second->acquireEdit();
auto floatPlug = runTimeCast<FloatPlug>( activeValuePlug( parameterPlug.get() ) );
if( !floatPlug )
{
throw Exception( fmt::format( "\"{}\" parameter must use `FloatPlug`", metaParameter.string() ) );
}

const float originalValue = it->second->typedValue<float>( 0.f );
setValueOrAddKey(
floatPlug,
m_view->context()->getTime(),
std::clamp( originalValue + incr, minValue, maxValue )
);
ConstFloatDataPtr newValue = new FloatData( std::clamp( originalValue + incr, minValue, maxValue ) );
it->second->edit( newValue.get() );
}
}

Expand Down Expand Up @@ -1665,29 +1605,16 @@ class SpotLightHandle : public LightToolHandle

auto it = m_handleType == HandleType::Cone ? coneIt : penumbraIt;

ValuePlugPtr plug = it->second->acquireEdit();
auto floatPlug = runTimeCast<FloatPlug>( activeValuePlug( plug.get() ) );
if( !floatPlug )
{
throw Exception(
fmt::format(
"Invalid type for \"{}\"",
m_handleType == HandleType::Cone ? g_coneAngleParameter.string() : g_penumbraAngleParameter.string()
)
);
}

// Clamp each individual cone angle as well
setValueOrAddKey(
floatPlug,
view()->context()->getTime(),
ConstFloatDataPtr newValue = new FloatData(
clampPlugAngle(
it->second->typedValue<float>( 0.f ) + angleDelta,
coneIt->second->typedValue<float>( 0.f ),
penumbraHandleAngle
)
);

it->second->edit( newValue.get() );
}

return true;
Expand Down
Loading