Skip to content

Commit

Permalink
Arnold : Added Arnold Operators support
Browse files Browse the repository at this point in the history
  • Loading branch information
boberfly committed May 2, 2024
1 parent c7e6514 commit 0dd683e
Show file tree
Hide file tree
Showing 16 changed files with 693 additions and 2 deletions.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Features
--------

- 3Delight : Added "3Delight Cloud" renderer, for rendering using the 3Delight cloud.
- Arnold : Added Arnold Operators support.

Improvements
-----------
Expand Down
66 changes: 66 additions & 0 deletions arnoldPlugins/gaffer.mtd
Original file line number Diff line number Diff line change
Expand Up @@ -3377,3 +3377,69 @@
[attr custom]
gaffer.layout.index INT 6
gaffer.layout.activator STRING "modeIsCustom"

# Standard Arnold Operators
##########################################################################

[node collection]

primaryInput STRING "input"

[node disable]

primaryInput STRING "input"

[node include_graph]

primaryInput STRING "input"

[node materialx]

primaryInput STRING "input"

gaffer.graphEditorLayout.defaultVisibility BOOL false

[attr input]
gaffer.layout.index INT 0
gaffer.graphEditorLayout.visible BOOL true

[attr enable]
gaffer.layout.index INT 1

[attr selection]
gaffer.layout.index INT 2

[attr filename]
widget STRING "filename"
gaffer.layout.index INT 3
gaffer.path.valid BOOL true
gaffer.path.leaf BOOL true
gaffer.path.bookmarks STRING "material"
gaffer.fileSystemPath.extensions STRING "mtlx"

[node merge]

primaryInput STRING "input"

[node set_parameter]

primaryInput STRING "input"

# Hide, because we don't support array parameters.
gaffer.nodeMenu.category STRING ""

[node set_transform]

primaryInput STRING "input"
gaffer.graphEditorLayout.defaultVisibility BOOL false

[attr input]
gaffer.graphEditorLayout.visible BOOL true

[node string_replace]

primaryInput STRING "input"

[node switch_operator]

primaryInput STRING "input"
88 changes: 88 additions & 0 deletions include/GafferArnold/ArnoldOperator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2024, Cinesite VFX Ltd. 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.
//
//////////////////////////////////////////////////////////////////////////

#pragma once

#include "GafferArnold/Export.h"
#include "GafferArnold/TypeIds.h"

#include "GafferScene/GlobalsProcessor.h"
#include "GafferScene/ShaderPlug.h"

namespace GafferArnold
{

class GAFFERARNOLD_API ArnoldOperator : public GafferScene::GlobalsProcessor
{

public :

explicit ArnoldOperator( const std::string &name=defaultName<ArnoldOperator>() );
~ArnoldOperator() override;

GAFFER_NODE_DECLARE_TYPE( GafferArnold::ArnoldOperator, ArnoldOperatorTypeId, GafferScene::GlobalsProcessor );

void affects( const Gaffer::Plug *input, AffectedPlugsContainer &outputs ) const override;

enum class Mode
{
Replace,
InsertFirst,
InsertLast
};

GafferScene::ShaderPlug *operatorPlug();
const GafferScene::ShaderPlug *operatorPlug() const;

Gaffer::IntPlug *modePlug();
const Gaffer::IntPlug *modePlug() const;

protected :

bool acceptsInput( const Gaffer::Plug *plug, const Gaffer::Plug *inputPlug ) const override;

void hashProcessedGlobals( const Gaffer::Context *context, IECore::MurmurHash &h ) const override;
IECore::ConstCompoundObjectPtr computeProcessedGlobals( const Gaffer::Context *context, IECore::ConstCompoundObjectPtr inputGlobals ) const override;

private :

static size_t g_firstPlugIndex;

};

IE_CORE_DECLAREPTR( ArnoldOperator )

} // namespace GafferArnold
1 change: 1 addition & 0 deletions include/GafferArnold/TypeIds.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ enum TypeId
ArnoldLightFilterTypeId = 110913,
ArnoldColorManagerTypeId = 110914,
ArnoldImagerTypeId = 110915,
ArnoldOperatorTypeId = 110916,

LastTypeId = 110924
};
Expand Down
131 changes: 131 additions & 0 deletions python/GafferArnoldTest/ArnoldOperatorTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
##########################################################################
#
# Copyright (c) 2024, Cinesite VFX Ltd. 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 unittest

import imath

import IECoreScene

import GafferTest
import GafferSceneTest
import GafferArnold

class ArnoldOperatorTest( GafferSceneTest.SceneTestCase ) :

def test( self ) :

operator = GafferArnold.ArnoldShader()
operator.loadShader( "switch_operator" )
operator["parameters"]["index"].setValue( 0 )

node = GafferArnold.ArnoldOperator()
node["operator"].setInput( operator["out"] )

for mode in node.Mode.values.values() :

# Since there is no upstream operator, all modes
# should have the same effect.
node["mode"].setValue( mode )

self.assertEqual(
node["out"].globals()["option:ai:operator"],
operator.attributes()["ai:operator"]
)

def testRejectsNonOperatorInputs( self ) :

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

node = GafferArnold.ArnoldOperator()
self.assertFalse( node["operator"].acceptsInput( shader["out"] ) )

def testModes( self ) :

def order( scene ) :

network = scene.globals()["option:ai:operator"]

result = []
shaderHandle = network.getOutput().shader
while shaderHandle :
result.append( network.getShader( shaderHandle ).parameters["index"].value )
shaderHandle = network.input( ( shaderHandle, "input" ) ).shader

result.reverse()
return result

operator1 = GafferArnold.ArnoldShader()
operator1.loadShader( "switch_operator" )
operator1["parameters"]["index"].setValue( 1 )

operator2 = GafferArnold.ArnoldShader()
operator2.loadShader( "switch_operator" )
operator2["parameters"]["index"].setValue( 2 )

operator3 = GafferArnold.ArnoldShader()
operator3.loadShader( "switch_operator" )
operator3["parameters"]["index"].setValue( 3 )

node1 = GafferArnold.ArnoldOperator()
node1["operator"].setInput( operator1["out"] )
self.assertEqual( order( node1["out"] ), [ 1 ] )

node2 = GafferArnold.ArnoldOperator()
node2["in"].setInput( node1["out"] )
node2["operator"].setInput( operator2["out"] )
self.assertEqual( order( node2["out"] ), [ 2 ] )

node2["mode"].setValue( GafferArnold.ArnoldOperator.Mode.InsertLast )
self.assertEqual( order( node2["out"] ), [ 1, 2 ] )

node2["mode"].setValue( GafferArnold.ArnoldOperator.Mode.InsertFirst )
self.assertEqual( order( node2["out"] ), [ 2, 1 ] )

node3 = GafferArnold.ArnoldOperator()
node3["in"].setInput( node2["out"] )
node3["operator"].setInput( operator3["out"] )
self.assertEqual( order( node3["out"] ), [ 3 ] )

node3["mode"].setValue( GafferArnold.ArnoldOperator.Mode.InsertLast )
self.assertEqual( order( node3["out"] ), [ 2, 1, 3 ] )

node3["mode"].setValue( GafferArnold.ArnoldOperator.Mode.InsertFirst )
self.assertEqual( order( node3["out"] ), [ 3, 2, 1 ] )

if __name__ == "__main__":
unittest.main()
1 change: 1 addition & 0 deletions python/GafferArnoldTest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
from .ArnoldLightFilterTest import ArnoldLightFilterTest
from .ArnoldColorManagerTest import ArnoldColorManagerTest
from .ArnoldImagerTest import ArnoldImagerTest
from .ArnoldOperatorTest import ArnoldOperatorTest
from .USDLightTest import USDLightTest

if __name__ == "__main__":
Expand Down
Loading

0 comments on commit 0dd683e

Please sign in to comment.