Skip to content

Commit

Permalink
Merge pull request #554 from johnhaddon/mapOffset
Browse files Browse the repository at this point in the history
Added a MapOffset node for offsetting texture coordinates.
  • Loading branch information
danieldresser committed Sep 26, 2013
2 parents 3eb68db + 504090f commit 7f50fd2
Show file tree
Hide file tree
Showing 9 changed files with 409 additions and 0 deletions.
84 changes: 84 additions & 0 deletions include/GafferScene/MapOffset.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2013, 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.
//
//////////////////////////////////////////////////////////////////////////

#ifndef GAFFERSCENE_MAPOFFSET_H
#define GAFFERSCENE_MAPOFFSET_H

#include "GafferScene/SceneElementProcessor.h"

namespace GafferScene
{

/// Applies offsets to texture coordinates.
class MapOffset : public SceneElementProcessor
{

public :

MapOffset( const std::string &name=defaultName<MapOffset>() );
virtual ~MapOffset();

IE_CORE_DECLARERUNTIMETYPEDEXTENSION( GafferScene::MapOffset, MapOffsetTypeId, SceneElementProcessor );

Gaffer::V2fPlug *offsetPlug();
const Gaffer::V2fPlug *offsetPlug() const;

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

Gaffer::StringPlug *sNamePlug();
const Gaffer::StringPlug *sNamePlug() const;

Gaffer::StringPlug *tNamePlug();
const Gaffer::StringPlug *tNamePlug() const;

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

protected :

virtual bool processesObject() const;
virtual void hashProcessedObject( const ScenePath &path, const Gaffer::Context *context, IECore::MurmurHash &h ) const;
virtual IECore::ConstObjectPtr computeProcessedObject( const ScenePath &path, const Gaffer::Context *context, IECore::ConstObjectPtr inputObject ) const;

private :

static size_t g_firstPlugIndex;

};

} // namespace GafferScene

#endif // GAFFERSCENE_MAPOFFSET_H
1 change: 1 addition & 0 deletions include/GafferScene/TypeIds.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ enum TypeId
PointConstraintTypeId = 110555,
CustomAttributesTypeId = 110556,
CustomOptionsTypeId = 110557,
MapOffsetTypeId = 110558,

LastTypeId = 110650
};
Expand Down
81 changes: 81 additions & 0 deletions python/GafferSceneTest/MapOffsetTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
##########################################################################
#
# Copyright (c) 2013, 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 os
import unittest

import IECore

import Gaffer
import GafferTest
import GafferScene
import GafferSceneTest

class MapOffsetTest( GafferSceneTest.SceneTestCase ) :

def test( self ) :

plane = GafferScene.Plane()
offset = GafferScene.MapOffset()
offset["in"].setInput( plane["out"] )

self.assertSceneValid( offset["out"] )
self.assertScenesEqual( offset["out"], plane["out"] )

inputObject = plane["out"].object( "/plane" )

self.assertEqual( offset["out"].object( "/plane" ), inputObject )

offset["udim"].setValue( 1022 )
self.assertSceneValid( offset["out"] )

for i, s in enumerate( offset["out"].object( "/plane" )["s"].data ) :
self.assertEqual( s, inputObject["s"].data[i] + 1 )

for i, t in enumerate( offset["out"].object( "/plane" )["t"].data ) :
self.assertEqual( t, inputObject["t"].data[i] + 2 )

offset["offset"].setValue( IECore.V2f( 0.5, 1.5 ) )
self.assertSceneValid( offset["out"] )

for i, s in enumerate( offset["out"].object( "/plane" )["s"].data ) :
self.assertEqual( s, inputObject["s"].data[i] + 1.5 )

for i, t in enumerate( offset["out"].object( "/plane" )["t"].data ) :
self.assertEqual( t, inputObject["t"].data[i] + 3.5 )

if __name__ == "__main__":
unittest.main()
1 change: 1 addition & 0 deletions python/GafferSceneTest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
from ShaderTest import ShaderTest
from TextTest import TextTest
from MapProjectionTest import MapProjectionTest
from MapOffsetTest import MapOffsetTest
from PointConstraintTest import PointConstraintTest
from SceneReaderTest import SceneReaderTest

Expand Down
59 changes: 59 additions & 0 deletions python/GafferSceneUI/MapOffsetUI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
##########################################################################
#
# Copyright (c) 2013, 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 Gaffer
import GafferUI
import GafferScene

GafferUI.Metadata.registerNodeDescription(

GafferScene.MapOffset,

"""Adds an offset to object texture coordinates. Provides a convenient way of looking at specific texture UDIMs.""",

"offset",
"An offset added to the texture coordinates. Note that moving the texture coordinates in the positive direction will move the texture in the negative direction.",

"udim",
"A specific UDIM to offset the texture coordinates to. The UDIM is converted to an offset which is added to the offset above.",

"sName",
"The name of the primitive variable holding the s coordinate.",

"tName",
"The name of the primitive variable holding the t coordinate.",

)
1 change: 1 addition & 0 deletions python/GafferSceneUI/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@
import InteractiveRenderUI
import SphereUI
import MapProjectionUI
import MapOffsetUI
import CustomAttributesUI
import CustomOptionsUI
Loading

0 comments on commit 7f50fd2

Please sign in to comment.