|
| 1 | +########################################################################## |
| 2 | +# |
| 3 | +# Copyright (c) 2026, Cinesite VFX Ltd. All rights reserved. |
| 4 | +# |
| 5 | +# Redistribution and use in source and binary forms, with or without |
| 6 | +# modification, are permitted provided that the following conditions are |
| 7 | +# met: |
| 8 | +# |
| 9 | +# * Redistributions of source code must retain the above |
| 10 | +# copyright notice, this list of conditions and the following |
| 11 | +# disclaimer. |
| 12 | +# |
| 13 | +# * Redistributions in binary form must reproduce the above |
| 14 | +# copyright notice, this list of conditions and the following |
| 15 | +# disclaimer in the documentation and/or other materials provided with |
| 16 | +# the distribution. |
| 17 | +# |
| 18 | +# * Neither the name of John Haddon nor the names of |
| 19 | +# any other contributors to this software may be used to endorse or |
| 20 | +# promote products derived from this software without specific prior |
| 21 | +# written permission. |
| 22 | +# |
| 23 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
| 24 | +# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 25 | +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 26 | +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 27 | +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 28 | +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 29 | +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 30 | +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 31 | +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 32 | +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 33 | +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 34 | +# |
| 35 | +########################################################################## |
| 36 | + |
| 37 | +import unittest |
| 38 | + |
| 39 | +import imath |
| 40 | + |
| 41 | +import IECore |
| 42 | +import IECoreScene |
| 43 | + |
| 44 | +import Gaffer |
| 45 | +import GafferScene |
| 46 | +import GafferSceneTest |
| 47 | + |
| 48 | +class CurvesInterpolationTest( GafferSceneTest.SceneTestCase ) : |
| 49 | + |
| 50 | + def testPassThrough( self ) : |
| 51 | + |
| 52 | + objectToScene = GafferScene.ObjectToScene() |
| 53 | + objectToScene["object"].setValue( |
| 54 | + IECoreScene.CurvesPrimitive( |
| 55 | + IECore.IntVectorData( [ 4 ] ), IECore.CubicBasisf.catmullRom() |
| 56 | + ) |
| 57 | + ) |
| 58 | + |
| 59 | + interpolation = GafferScene.CurvesInterpolation() |
| 60 | + interpolation["in"].setInput( objectToScene["out"] ) |
| 61 | + |
| 62 | + # No filter |
| 63 | + |
| 64 | + self.assertTrue( interpolation["out"].exists( "/object" ) ) |
| 65 | + self.assertScenesEqual( interpolation["out"], interpolation["in"] ) |
| 66 | + self.assertSceneHashesEqual( interpolation["out"], interpolation["in"] ) |
| 67 | + |
| 68 | + # Filter, but not matching anything yet |
| 69 | + |
| 70 | + pathFilter = GafferScene.PathFilter() |
| 71 | + interpolation["filter"].setInput( pathFilter["out"] ) |
| 72 | + |
| 73 | + self.assertTrue( interpolation["out"].exists( "/object" ) ) |
| 74 | + self.assertScenesEqual( interpolation["out"], interpolation["in"] ) |
| 75 | + self.assertSceneHashesEqual( interpolation["out"], interpolation["in"] ) |
| 76 | + |
| 77 | + # Filter matching something, but node disabled |
| 78 | + |
| 79 | + pathFilter["paths"].setValue( IECore.StringVectorData( [ "/object" ] ) ) |
| 80 | + interpolation["enabled"].setValue( False ) |
| 81 | + |
| 82 | + self.assertTrue( interpolation["out"].exists( "/object" ) ) |
| 83 | + self.assertScenesEqual( interpolation["out"], interpolation["in"] ) |
| 84 | + self.assertSceneHashesEqual( interpolation["out"], interpolation["in"] ) |
| 85 | + |
| 86 | + # Node enabled, but not doing anything |
| 87 | + |
| 88 | + interpolation["enabled"].setValue( True ) |
| 89 | + |
| 90 | + self.assertTrue( interpolation["out"].exists( "/object" ) ) |
| 91 | + self.assertScenesEqual( interpolation["out"], interpolation["in"] ) |
| 92 | + self.assertSceneHashesEqual( interpolation["out"], interpolation["in"] ) |
| 93 | + |
| 94 | + def testChangeWrap( self ) : |
| 95 | + |
| 96 | + objectToScene = GafferScene.ObjectToScene() |
| 97 | + objectToScene["object"].setValue( |
| 98 | + IECoreScene.CurvesPrimitive( |
| 99 | + IECore.IntVectorData( [ 4 ] ), IECore.CubicBasisf.catmullRom(), |
| 100 | + wrap = IECoreScene.CurvesPrimitive.Wrap.Pinned, |
| 101 | + p = IECore.V3fVectorData( [ imath.V3f( x ) for x in range( 0, 4 ) ] ) |
| 102 | + ) |
| 103 | + ) |
| 104 | + |
| 105 | + pathFilter = GafferScene.PathFilter() |
| 106 | + pathFilter["paths"].setValue( IECore.StringVectorData( [ "/object" ] ) ) |
| 107 | + |
| 108 | + interpolation = GafferScene.CurvesInterpolation() |
| 109 | + interpolation["in"].setInput( objectToScene["out"] ) |
| 110 | + interpolation["filter"].setInput( pathFilter["out"] ) |
| 111 | + |
| 112 | + self.assertEqual( interpolation["out"].object( "/object" ).wrap(), IECoreScene.CurvesPrimitive.Wrap.Pinned ) |
| 113 | + |
| 114 | + interpolation["wrap"]["enabled"].setValue( True ) |
| 115 | + interpolation["wrap"]["value"].setValue( IECoreScene.CurvesPrimitive.Wrap.NonPeriodic ) |
| 116 | + |
| 117 | + self.assertEqual( interpolation["out"].object( "/object" ).wrap(), IECoreScene.CurvesPrimitive.Wrap.NonPeriodic ) |
| 118 | + self.assertEqual( interpolation["out"].object( "/object" )["P"], interpolation["in"].object( "/object" )["P"] ) |
| 119 | + |
| 120 | + interpolation["expandPinned"].setValue( True ) |
| 121 | + self.assertEqual( interpolation["out"].object( "/object" ).wrap(), IECoreScene.CurvesPrimitive.Wrap.NonPeriodic ) |
| 122 | + self.assertEqual( |
| 123 | + interpolation["out"].object( "/object" )["P"].data, |
| 124 | + IECore.V3fVectorData( [ imath.V3f( x ) for x in range( -1, 5 ) ], IECore.GeometricData.Interpretation.Point ) |
| 125 | + ) |
| 126 | + |
| 127 | + def testChangeBasis( self ) : |
| 128 | + |
| 129 | + objectToScene = GafferScene.ObjectToScene() |
| 130 | + objectToScene["object"].setValue( |
| 131 | + IECoreScene.CurvesPrimitive( |
| 132 | + IECore.IntVectorData( [ 4 ] ), IECore.CubicBasisf.catmullRom(), |
| 133 | + p = IECore.V3fVectorData( [ imath.V3f( x ) for x in range( 0, 4 ) ] ) |
| 134 | + ) |
| 135 | + ) |
| 136 | + |
| 137 | + pathFilter = GafferScene.PathFilter() |
| 138 | + pathFilter["paths"].setValue( IECore.StringVectorData( [ "/object" ] ) ) |
| 139 | + |
| 140 | + interpolation = GafferScene.CurvesInterpolation() |
| 141 | + interpolation["in"].setInput( objectToScene["out"] ) |
| 142 | + interpolation["filter"].setInput( pathFilter["out"] ) |
| 143 | + |
| 144 | + self.assertEqual( interpolation["out"].object( "/object" ).basis(), IECore.CubicBasisf.catmullRom() ) |
| 145 | + |
| 146 | + interpolation["basis"]["enabled"].setValue( True ) |
| 147 | + interpolation["basis"]["value"].setValue( IECore.StandardCubicBasis.BSpline ) |
| 148 | + |
| 149 | + self.assertEqual( interpolation["out"].object( "/object" ).basis(), IECore.CubicBasisf.bSpline() ) |
| 150 | + |
| 151 | +if __name__ == "__main__": |
| 152 | + unittest.main() |
0 commit comments