Skip to content

Commit

Permalink
Merge pull request #1673 from johnhaddon/arnoldUI
Browse files Browse the repository at this point in the history
ArnoldShaderUI : Update to use only metadata.
  • Loading branch information
andrewkaufman committed Mar 14, 2016
2 parents dff567a + 895aede commit f6b9abd
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 35 deletions.
70 changes: 35 additions & 35 deletions python/GafferArnoldUI/ArnoldShaderUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@
##########################################################################

import ctypes
import functools
import collections

import arnold

import IECore
import IECoreArnold

import Gaffer
Expand All @@ -64,8 +67,7 @@ def __aiMetadataGetStr( nodeEntry, paramName, name ) :
# and we don't want to have to keep making those temporarily later.
##########################################################################

__descriptions = {}
__plugValueWidgetCreators = {}
__metadata = collections.defaultdict( dict )

with IECoreArnold.UniverseBlock() :

Expand All @@ -77,7 +79,7 @@ def __aiMetadataGetStr( nodeEntry, paramName, name ) :

description = __aiMetadataGetStr( nodeEntry, None, "desc" )
if description is not None :
__descriptions[nodeName] = description
__metadata[nodeName]["description"] = description

paramIt = arnold.AiNodeEntryGetParamIterator( nodeEntry )
while not arnold.AiParamIteratorFinished( paramIt ) :
Expand All @@ -90,20 +92,22 @@ def __aiMetadataGetStr( nodeEntry, paramName, name ) :

description = __aiMetadataGetStr( nodeEntry, paramName, "desc" )
if description is not None :
__descriptions[paramPath] = description
__metadata[paramPath]["description"] = description

paramType = arnold.AiParamGetType( param )
if paramType == arnold.AI_TYPE_ENUM :

enum = arnold.AiParamGetEnum( param )
namesAndValues = []
presets = IECore.StringVectorData()
while True :
enumLabel = arnold.AiEnumGetString( enum, len( namesAndValues ) )
if not enumLabel :
preset = arnold.AiEnumGetString( enum, len( presets ) )
if not preset :
break
namesAndValues.append( ( enumLabel, enumLabel ) )
presets.append( preset )

__plugValueWidgetCreators[paramPath] = ( GafferUI.EnumPlugValueWidget, namesAndValues )
__metadata[paramPath]["plugValueWidget:type"] = "GafferUI.PresetsPlugValueWidget"
__metadata[paramPath]["presetNames"] = presets
__metadata[paramPath]["presetValues"] = presets

##########################################################################
# Gaffer Metadata queries. These are implemented using the preconstructed
Expand All @@ -115,41 +119,37 @@ def __nodeDescription( node ) :
shaderDefault = """Loads shaders for use in Arnold renderers. Use the ShaderAssignment node to assign shaders to objects in the scene."""
lightDefault = """Loads an Arnold light shader and uses it to output a scene with a single light."""

return __descriptions.get(
node["name"].getValue(),
return __metadata[node["name"].getValue()].get(
"description",
shaderDefault if isinstance( node, GafferArnold.ArnoldShader ) else lightDefault
)

def __plugDescription( plug ) :
def __plugMetadata( plug, name ) :

return __descriptions.get( plug.node()["name"].getValue() + "." + plug.getName() )
return __metadata[plug.node()["name"].getValue() + "." + plug.getName()].get( name )

for nodeType in ( GafferArnold.ArnoldShader, GafferArnold.ArnoldLight ) :

Gaffer.Metadata.registerNodeValue( nodeType, "description", __nodeDescription )
Gaffer.Metadata.registerPlugValue( nodeType, "parameters.*", "description", __plugDescription )

##########################################################################
# Nodule and widget creators
##########################################################################

def __parameterNoduleType( plug ) :
def __noduleType( plug ) :

if isinstance( plug, ( Gaffer.BoolPlug, Gaffer.IntPlug, Gaffer.StringPlug ) ) :
return ""

return "GafferUI::StandardNodule"

GafferUI.Metadata.registerPlugValue( GafferArnold.ArnoldShader, "parameters.*", "nodule:type", __parameterNoduleType )

def __plugValueWidgetCreator( plug ) :

paramPath = plug.node()["name"].getValue() + "." + plug.getName()
customCreator = __plugValueWidgetCreators.get( paramPath, None )
if customCreator is not None :
return customCreator[0]( plug, *customCreator[1:] )

return GafferUI.PlugValueWidget.create( plug, useTypeOnly=True )
for nodeType in ( GafferArnold.ArnoldShader, GafferArnold.ArnoldLight ) :

GafferUI.PlugValueWidget.registerCreator( GafferArnold.ArnoldShader, "parameters.*", __plugValueWidgetCreator )
GafferUI.PlugValueWidget.registerCreator( GafferArnold.ArnoldLight, "parameters.*", __plugValueWidgetCreator )
Gaffer.Metadata.registerNodeValue( nodeType, "description", __nodeDescription )
GafferUI.Metadata.registerPlugValue( nodeType, "parameters.*", "nodule:type", __noduleType )

for name in [
"description",
"presetNames",
"presetValues",
"plugValueWidget:type"
] :

Gaffer.Metadata.registerPlugValue(
nodeType,
"parameters.*",
name,
functools.partial( __plugMetadata, name = name )
)
82 changes: 82 additions & 0 deletions python/GafferArnoldUITest/ArnoldShaderUITest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
##########################################################################
#
# Copyright (c) 2016, 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 John Haddon 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 IECore

import Gaffer
import GafferUITest
import GafferArnold
import GafferArnoldUI

class ArnoldShaderUITest( GafferUITest.TestCase ) :

def testMetadata( self ) :

shader = GafferArnold.ArnoldShader()
shader.loadShader( "noise" )

self.assertEqual(
Gaffer.Metadata.plugValue( shader["parameters"]["octaves"], "nodule:type" ),
""
)

self.assertEqual(
Gaffer.Metadata.plugValue( shader["parameters"]["amplitude"], "nodule:type" ),
"GafferUI::StandardNodule"
)

self.assertEqual(
Gaffer.Metadata.plugValue( shader["parameters"]["octaves"], "plugValueWidget:type" ),
None
)

self.assertEqual(
Gaffer.Metadata.plugValue( shader["parameters"]["coord_space"], "plugValueWidget:type" ),
"GafferUI.PresetsPlugValueWidget"
)

self.assertEqual(
Gaffer.Metadata.plugValue( shader["parameters"]["coord_space"], "presetNames" ),
IECore.StringVectorData( [ "world", "object", "Pref" ] ),
)

self.assertEqual(
Gaffer.Metadata.plugValue( shader["parameters"]["coord_space"], "presetValues" ),
Gaffer.Metadata.plugValue( shader["parameters"]["coord_space"], "presetNames" ),
)

if __name__ == "__main__":
unittest.main()
1 change: 1 addition & 0 deletions python/GafferArnoldUITest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
##########################################################################

from DocumentationTest import DocumentationTest
from ArnoldShaderUITest import ArnoldShaderUITest

if __name__ == "__main__":
unittest.main()

0 comments on commit f6b9abd

Please sign in to comment.