Skip to content

Commit

Permalink
Added a Parent node to GafferScene module.
Browse files Browse the repository at this point in the history
This allows one hierarchy to be parented into another.

Fixes #91.
  • Loading branch information
johnhaddon committed Jan 16, 2014
1 parent fe56782 commit b14bea5
Show file tree
Hide file tree
Showing 11 changed files with 529 additions and 2 deletions.
87 changes: 87 additions & 0 deletions include/GafferScene/Parent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014, 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_PARENT_H
#define GAFFERSCENE_PARENT_H

#include "GafferScene/BranchCreator.h"

namespace GafferScene
{

class Parent : public BranchCreator
{

public :

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

IE_CORE_DECLARERUNTIMETYPEDEXTENSION( GafferScene::Parent, ParentTypeId, BranchCreator );

ScenePlug *childPlug();
const ScenePlug *childPlug() const;

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

protected :

virtual void hashBranchBound( const ScenePath &parentPath, const ScenePath &branchPath, const Gaffer::Context *context, IECore::MurmurHash &h ) const;
virtual Imath::Box3f computeBranchBound( const ScenePath &parentPath, const ScenePath &branchPath, const Gaffer::Context *context ) const;

virtual void hashBranchTransform( const ScenePath &parentPath, const ScenePath &branchPath, const Gaffer::Context *context, IECore::MurmurHash &h ) const;
virtual Imath::M44f computeBranchTransform( const ScenePath &parentPath, const ScenePath &branchPath, const Gaffer::Context *context ) const;

virtual void hashBranchAttributes( const ScenePath &parentPath, const ScenePath &branchPath, const Gaffer::Context *context, IECore::MurmurHash &h ) const;
virtual IECore::ConstCompoundObjectPtr computeBranchAttributes( const ScenePath &parentPath, const ScenePath &branchPath, const Gaffer::Context *context ) const;

virtual void hashBranchObject( const ScenePath &parentPath, const ScenePath &branchPath, const Gaffer::Context *context, IECore::MurmurHash &h ) const;
virtual IECore::ConstObjectPtr computeBranchObject( const ScenePath &parentPath, const ScenePath &branchPath, const Gaffer::Context *context ) const;

virtual void hashBranchChildNames( const ScenePath &parentPath, const ScenePath &branchPath, const Gaffer::Context *context, IECore::MurmurHash &h ) const;
virtual IECore::ConstInternedStringVectorDataPtr computeBranchChildNames( const ScenePath &parentPath, const ScenePath &branchPath, const Gaffer::Context *context ) const;

private :

static size_t g_firstPlugIndex;

};

IE_CORE_DECLAREPTR( Parent )

} // namespace GafferScene

#endif // GAFFERSCENE_PARENT_H
1 change: 1 addition & 0 deletions include/GafferScene/TypeIds.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ enum TypeId
SceneSwitchTypeId = 110563,
ShaderSwitchTypeId = 110564,
ParentConstraintTypeId = 110565,
ParentTypeId = 110566,

LastTypeId = 110650
};
Expand Down
47 changes: 47 additions & 0 deletions include/GafferSceneBindings/ParentBinding.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014, 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 GAFFERSCENEBINDINGS_PARENTBINDING_H
#define GAFFERSCENEBINDINGS_PARENTBINDING_H

namespace GafferSceneBindings
{

void bindParent();

} // namespace GafferSceneBindings

#endif // GAFFERSCENEBINDINGS_PARENTBINDING_H
150 changes: 150 additions & 0 deletions python/GafferSceneTest/ParentTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
##########################################################################
#
# Copyright (c) 2014, 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 GafferScene
import GafferSceneTest

class ParentTest( GafferSceneTest.SceneTestCase ) :

def test( self ) :

s = GafferScene.Sphere()
c = GafferScene.Cube()

g = GafferScene.Group()
g["in"].setInput( s["out"] )
g["in1"].setInput( c["out"] )

p = GafferScene.Parent()
p["in"].setInput( g["out"] )
p["parent"].setValue( "/group" )
p["child"].setInput( c["out"] )

self.assertEqual( p["out"].childNames( "/group" ), IECore.InternedStringVectorData( [ "sphere", "cube", "cube1" ] ) )
self.assertPathsEqual( p["out"], "/group/cube", p["out"], "/group/cube1" )

self.assertSceneValid( p["out"] )

def testParentAtRoot( self ) :

s = GafferScene.Sphere()
c = GafferScene.Cube()

g = GafferScene.Group()
g["in"].setInput( s["out"] )
g["in1"].setInput( c["out"] )

p = GafferScene.Parent()
p["in"].setInput( g["out"] )
p["parent"].setValue( "/" )
p["child"].setInput( c["out"] )

self.assertEqual( p["out"].childNames( "/" ), IECore.InternedStringVectorData( [ "group", "cube" ] ) )
self.assertPathsEqual( p["out"], "/group/cube", p["out"], "/cube" )

self.assertSceneValid( p["out"] )

def testUnconnected( self ) :

p = GafferScene.Parent()

self.assertEqual( p["out"].childNames( "/" ), IECore.InternedStringVectorData( [] ) )
self.assertSceneValid( p["out"] )

def testPassThroughWhenNoChild( self ) :

c = GafferScene.Cube()

p = GafferScene.Parent()
p["parent"].setValue( "/" )
p["in"].setInput( c["out"] )

self.assertScenesEqual( p["out"], c["out"] )

def testNameUniqueification( self ) :

c = GafferScene.Cube()

g = GafferScene.Group()
g["in"].setInput( c["out"] )
g["in1"].setInput( c["out"] )

p = GafferScene.Parent()
p["in"].setInput( g["out"] )
p["parent"].setValue( "/group" )
p["child"].setInput( c["out"] )

self.assertEqual( p["out"].childNames( "/group" ), IECore.InternedStringVectorData( [ "cube", "cube1", "cube2" ] ) )
self.assertSceneValid( p["out"] )

def testChildSmallerThanExistingChildren( self ) :

c = GafferScene.Cube()

cSmall = GafferScene.Cube()
cSmall["dimensions"].setValue( IECore.V3f( 0.1 ) )

g = GafferScene.Group()
g["in"].setInput( c["out"] )

p = GafferScene.Parent()
p["in"].setInput( g["out"] )
p["parent"].setValue( "/group" )
p["child"].setInput( cSmall["out"] )

self.assertSceneValid( p["out"] )

def testChildLargerThanExistingChildren( self ) :

c = GafferScene.Cube()

cLarge = GafferScene.Cube()
cLarge["dimensions"].setValue( IECore.V3f( 10 ) )

g = GafferScene.Group()
g["in"].setInput( c["out"] )

p = GafferScene.Parent()
p["in"].setInput( g["out"] )
p["parent"].setValue( "/group" )
p["child"].setInput( cLarge["out"] )

self.assertSceneValid( p["out"] )

if __name__ == "__main__":
unittest.main()
3 changes: 2 additions & 1 deletion python/GafferSceneTest/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
##########################################################################
#
# Copyright (c) 2012-2013, John Haddon. All rights reserved.
# Copyright (c) 2013, Image Engine Design Inc. All rights reserved.
# Copyright (c) 2013-2014, 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
Expand Down Expand Up @@ -88,6 +88,7 @@
from SceneSwitchTest import SceneSwitchTest
from ShaderSwitchTest import ShaderSwitchTest
from ParentConstraintTest import ParentConstraintTest
from ParentTest import ParentTest

if __name__ == "__main__":
import unittest
Expand Down
62 changes: 62 additions & 0 deletions python/GafferSceneUI/ParentUI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
##########################################################################
#
# Copyright (c) 2014, 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

##########################################################################
# Metadata
##########################################################################

Gaffer.Metadata.registerNodeDescription(

GafferScene.Parent,

"""Parents one scene hierarchy into another.""",

"child",
"The child hierarchy to be parented.",

)

##########################################################################
# Widgets and nodules
##########################################################################

GafferUI.PlugValueWidget.registerCreator( GafferScene.Parent.staticTypeId(), "child", None )

3 changes: 2 additions & 1 deletion python/GafferSceneUI/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
##########################################################################
#
# Copyright (c) 2012, John Haddon. All rights reserved.
# Copyright (c) 2012-2013, Image Engine Design Inc. All rights reserved.
# Copyright (c) 2012-2014, 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
Expand Down Expand Up @@ -71,3 +71,4 @@
import ShaderSwitchUI
import ShaderAssignmentUI
import ParentConstraintUI
import ParentUI
Loading

0 comments on commit b14bea5

Please sign in to comment.