-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a Parent node to GafferScene module.
This allows one hierarchy to be parented into another. Fixes #91.
- Loading branch information
1 parent
fe56782
commit b14bea5
Showing
11 changed files
with
529 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.