From da0b7d7662fe61289fcccda3177fcfda805d4871 Mon Sep 17 00:00:00 2001 From: John Haddon Date: Wed, 9 Jul 2025 17:08:34 +0100 Subject: [PATCH 01/15] CurvesPrimitiveEvaluatorTest : Remove reliance on IECoreGL Tests shouldn't have dependencies on other modules. We also weren't actually passing `visualTest = True` anywhere anyway, so the code was unused. --- .../CurvesPrimitiveEvaluatorTest.py | 50 ++++--------------- 1 file changed, 11 insertions(+), 39 deletions(-) diff --git a/test/IECoreScene/CurvesPrimitiveEvaluatorTest.py b/test/IECoreScene/CurvesPrimitiveEvaluatorTest.py index d5f2c9c7a8..ed422b218a 100644 --- a/test/IECoreScene/CurvesPrimitiveEvaluatorTest.py +++ b/test/IECoreScene/CurvesPrimitiveEvaluatorTest.py @@ -49,7 +49,7 @@ class CurvesPrimitiveEvaluatorTest( unittest.TestCase ) : - def runPointAtVTest( self, curvesPrimitive, expectedPositions=None, expectedLengths=None, visualTest=False, printPoints=False ) : + def runPointAtVTest( self, curvesPrimitive, expectedPositions=None, expectedLengths=None, printPoints=False ) : e = IECoreScene.CurvesPrimitiveEvaluator( curvesPrimitive ) r = e.createResult() @@ -84,34 +84,6 @@ def runPointAtVTest( self, curvesPrimitive, expectedPositions=None, expectedLeng print( repr( p ).replace( "),", "),\n" ) ) - if visualTest : - - import IECoreGL - IECoreGL.init( False ) - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - - pointsPrimitive = IECoreScene.PointsPrimitive( p ) - pointsPrimitive["constantwidth"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, IECore.FloatData( 0.1 ) ) - - with IECoreScene.WorldBlock( r ) : - - w = IECoreGL.SceneViewer( "scene", r.scene() ) - - with IECoreScene.AttributeBlock( r ) : - - r.shader( "surface", "red", { "gl:fragmentSource" : IECore.StringData( "void main() { gl_FragColor = vec4( 1, 0, 0, 1 ); }" ) } ) - r.setAttribute( "gl:curvesPrimitive:useGLLines", IECore.BoolData( True ) ) - curvesPrimitive.render( r ) - - with IECoreScene.AttributeBlock( r ) : - - r.shader( "surface", "blue", { "gl:fragmentSource" : IECore.StringData( "void main() { gl_FragColor = vec4( 0, 0, 1, 1 ); }" ) } ) - pointsPrimitive.render( r ) - - w.start() - def testLinearSubsetLength( self ) : pts = IECore.V3fVectorData() @@ -267,7 +239,7 @@ def test3SegmentBSpline( self ) : lengths = IECore.FloatVectorData( [ 2.2106194496154785 ] ) - self.runPointAtVTest( c, expectedPositions=expected, expectedLengths=lengths, visualTest=False, printPoints=False ) + self.runPointAtVTest( c, expectedPositions=expected, expectedLengths=lengths, printPoints=False ) def test3SegmentBSplineDoubledEndpoints( self ) : @@ -345,7 +317,7 @@ def test3SegmentBSplineDoubledEndpoints( self ) : lengths = IECore.FloatVectorData( [ 3.61808 ] ) - self.runPointAtVTest( c, expectedPositions=expected, expectedLengths=lengths, visualTest=False, printPoints=False ) + self.runPointAtVTest( c, expectedPositions=expected, expectedLengths=lengths, printPoints=False ) def test2Curve3SegmentBSpline( self ) : @@ -478,7 +450,7 @@ def test2Curve3SegmentBSpline( self ) : lengths = IECore.FloatVectorData( [ 2.2106194496154785, 2.2106194496154785 ] ) - self.runPointAtVTest( c, expectedPositions=expected, expectedLengths=lengths, visualTest=False, printPoints=False ) + self.runPointAtVTest( c, expectedPositions=expected, expectedLengths=lengths, printPoints=False ) def testPeriodicBSpline( self ) : @@ -553,7 +525,7 @@ def testPeriodicBSpline( self ) : lengths = IECore.FloatVectorData( [ 2.917539119 ] ) - self.runPointAtVTest( c, expectedPositions=expected, expectedLengths=lengths, visualTest=False, printPoints=False ) + self.runPointAtVTest( c, expectedPositions=expected, expectedLengths=lengths, printPoints=False ) def test2CurvePeriodicBSpline( self ) : @@ -682,7 +654,7 @@ def test2CurvePeriodicBSpline( self ) : lengths = IECore.FloatVectorData( [ 2.917539119, 2.917539119 ] ) - self.runPointAtVTest( c, expectedPositions=expected, expectedLengths=lengths, visualTest=False, printPoints=False ) + self.runPointAtVTest( c, expectedPositions=expected, expectedLengths=lengths, printPoints=False ) def test3SegmentLinear( self ) : @@ -757,7 +729,7 @@ def test3SegmentLinear( self ) : lengths = IECore.FloatVectorData( [ 5.0 ] ) - self.runPointAtVTest( c, expectedPositions=expected, expectedLengths=lengths, visualTest=False, printPoints=False ) + self.runPointAtVTest( c, expectedPositions=expected, expectedLengths=lengths, printPoints=False ) def test3SegmentLinearDoubledEndpoints( self ) : @@ -835,7 +807,7 @@ def test3SegmentLinearDoubledEndpoints( self ) : lengths = IECore.FloatVectorData( [ 5.0 ] ) - self.runPointAtVTest( c, expectedPositions=expected, expectedLengths=lengths, visualTest=False, printPoints=False ) + self.runPointAtVTest( c, expectedPositions=expected, expectedLengths=lengths, printPoints=False ) def test2Curve3SegmentLinear( self ) : @@ -967,7 +939,7 @@ def test2Curve3SegmentLinear( self ) : lengths = IECore.FloatVectorData( [ 5.0, 5.0 ] ) - self.runPointAtVTest( c, expectedPositions=expected, expectedLengths=lengths, visualTest=False, printPoints=False ) + self.runPointAtVTest( c, expectedPositions=expected, expectedLengths=lengths, printPoints=False ) def test3SegmentPeriodicLinear( self ) : @@ -1042,7 +1014,7 @@ def test3SegmentPeriodicLinear( self ) : lengths = IECore.FloatVectorData( [ 7.23606777 ] ) - self.runPointAtVTest( c, expectedPositions=expected, expectedLengths=lengths, visualTest=False, printPoints=False ) + self.runPointAtVTest( c, expectedPositions=expected, expectedLengths=lengths, printPoints=False ) def test2Curve3SegmentPeriodicLinear( self ) : @@ -1173,7 +1145,7 @@ def test2Curve3SegmentPeriodicLinear( self ) : lengths = IECore.FloatVectorData( [ 7.23606777, 7.23606777 ] ) - self.runPointAtVTest( c, expectedPositions=expected, expectedLengths=lengths, visualTest=False, printPoints=False ) + self.runPointAtVTest( c, expectedPositions=expected, expectedLengths=lengths, printPoints=False ) def testClosestPoint( self ) : From 1f4b87cb82cc9fc79814f98dbf2e4842a8feaaa0 Mon Sep 17 00:00:00 2001 From: John Haddon Date: Wed, 9 Jul 2025 17:11:40 +0100 Subject: [PATCH 02/15] IECoreGL : Remove tests that depend on GLRenderer We're about to remove the Renderer class and associated components, and these tests use them. This is the only part of this whole remove-the-renderer operation I feel bad about. There is some decent test coverage here, some of which is still relevent to the _new_ GLRenderer in Gaffer, which doesn't have as good coverage. On the bright side, it wasn't being run on CI anyway, and there's a good chance that any significant future overhaul of hardware rendering in Gaffer will mean a move away from OpenGL. --- test/IECoreGL/All.py | 19 - test/IECoreGL/Camera.py | 137 ---- test/IECoreGL/CoordinateSystemTest.py | 117 --- test/IECoreGL/CurvesPrimitiveTest.py | 760 ------------------ test/IECoreGL/DeferredRenderer.py | 128 --- test/IECoreGL/DiskPrimitiveTest.py | 163 ---- test/IECoreGL/ImmediateRenderer.py | 105 --- test/IECoreGL/InstancingTest.py | 144 ---- test/IECoreGL/MeshPrimitiveTest.py | 284 ------- test/IECoreGL/Orientation.py | 187 ----- test/IECoreGL/PointsPrimitive.py | 590 -------------- test/IECoreGL/Renderer.py | 1035 ------------------------- test/IECoreGL/Selection.py | 512 ------------ test/IECoreGL/ShadingTest.py | 1011 ------------------------ test/IECoreGL/TextTest.py | 137 ---- test/IECoreGL/Texture.py | 129 --- test/IECoreGL/UserAttributesTest.py | 98 --- 17 files changed, 5556 deletions(-) delete mode 100644 test/IECoreGL/Camera.py delete mode 100644 test/IECoreGL/CoordinateSystemTest.py delete mode 100644 test/IECoreGL/CurvesPrimitiveTest.py delete mode 100644 test/IECoreGL/DeferredRenderer.py delete mode 100644 test/IECoreGL/DiskPrimitiveTest.py delete mode 100644 test/IECoreGL/ImmediateRenderer.py delete mode 100644 test/IECoreGL/InstancingTest.py delete mode 100644 test/IECoreGL/MeshPrimitiveTest.py delete mode 100644 test/IECoreGL/Orientation.py delete mode 100644 test/IECoreGL/PointsPrimitive.py delete mode 100644 test/IECoreGL/Renderer.py delete mode 100644 test/IECoreGL/Selection.py delete mode 100644 test/IECoreGL/ShadingTest.py delete mode 100644 test/IECoreGL/TextTest.py delete mode 100644 test/IECoreGL/Texture.py delete mode 100644 test/IECoreGL/UserAttributesTest.py diff --git a/test/IECoreGL/All.py b/test/IECoreGL/All.py index 5ae926c5c8..03f145d009 100644 --- a/test/IECoreGL/All.py +++ b/test/IECoreGL/All.py @@ -38,42 +38,23 @@ from Shader import * from State import * -from Renderer import * from Group import * -from Texture import * -from ImmediateRenderer import * from NameStateComponent import * from HitRecord import * -from Selection import * -from Camera import * -from PointsPrimitive import * -from Orientation import * -from CurvesPrimitiveTest import * -from MeshPrimitiveTest import * from AlphaTextureTest import * from LuminanceTextureTest import * -from UserAttributesTest import * -from DeferredRenderer import * -from DiskPrimitiveTest import DiskPrimitiveTest from ToGLTextureConverter import TestToGLTexureConverter from PrimitiveTest import * -from CoordinateSystemTest import CoordinateSystemTest from TextureLoaderTest import TextureLoaderTest from FontTest import FontTest from FontLoaderTest import FontLoaderTest from ToGLConverterTest import ToGLConverterTest from CachedConverterTest import CachedConverterTest -from InstancingTest import InstancingTest from BufferTest import BufferTest -from ShadingTest import ShadingTest from ShaderLoaderTest import ShaderLoaderTest from ShaderStateComponentTest import ShaderStateComponentTest from ToGLStateConverterTest import ToGLStateConverterTest -if IECore.withFreeType() : - - from TextTest import * - unittest.TestProgram( testRunner = unittest.TextTestRunner( stream = IECore.CompoundStream( diff --git a/test/IECoreGL/Camera.py b/test/IECoreGL/Camera.py deleted file mode 100644 index 8476a25b25..0000000000 --- a/test/IECoreGL/Camera.py +++ /dev/null @@ -1,137 +0,0 @@ -########################################################################## -# -# Copyright (c) 2008-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 Image Engine Design 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 IECore -import IECoreScene -import IECoreImage -import IECoreGL -IECoreGL.init( False ) -import os.path -import os -import shutil - -class CameraTest( unittest.TestCase ) : - - def testPositioning( self ) : - - # render a plane at z = 0 with the default camera - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - r.setOption( "gl:searchPath:shader", IECore.StringData( os.path.join( os.path.dirname( __file__ ), "shaders" ) ) ) - r.display( os.path.join( os.path.dirname( __file__ ), "output", "testCamera.tif" ), "tiff", "rgba", {} ) - - r.camera( "main", { "resolution" : IECore.V2iData( imath.V2i( 512 ) ), "projection" : IECore.StringData( "perspective" ) } ) - - r.worldBegin() - r.shader( "surface", "color", { "colorValue" : IECore.Color3fData( imath.Color3f( 1, 0, 0 ) ) } ) - IECoreScene.MeshPrimitive.createPlane( imath.Box2f( imath.V2f( -0.1 ), imath.V2f( 0.1 ) ) ).render( r ) - r.worldEnd() - - # check that nothing appears in the output image - i = IECore.Reader.create( os.path.join( os.path.dirname( __file__ ), "output", "testCamera.tif" ) ).read() - dimensions = i.dataWindow.size() + imath.V2i( 1 ) - midpoint = dimensions.x * dimensions.y//2 + dimensions.x//2 - self.assertAlmostEqual( i["G"][midpoint], 0, 6 ) - - # render a plane at z = 0 with the camera moved back a touch to see it - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - r.setOption( "gl:searchPath:shader", IECore.StringData( os.path.join( os.path.dirname( __file__ ), "shaders" ) ) ) - r.display( os.path.join( os.path.dirname( __file__ ), "output", "testCamera.tif" ), "tiff", "rgba", {} ) - - r.transformBegin() - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, 1 ) ) ) - r.camera( "main", { "resolution" : IECore.V2iData( imath.V2i( 512 ) ), "projection" : IECore.StringData( "perspective" ) } ) - r.transformEnd() - - r.worldBegin() - - r.shader( "surface", "color", { "colorValue" : IECore.Color3fData( imath.Color3f( 1, 0, 0 ) ) } ) - IECoreScene.MeshPrimitive.createPlane( imath.Box2f( imath.V2f( -0.1 ), imath.V2f( 0.1 ) ) ).render( r ) - r.worldEnd() - - # check that something appears in the output image - i = IECore.Reader.create( os.path.join( os.path.dirname( __file__ ), "output", "testCamera.tif" ) ).read() - dimensions = i.dataWindow.size() + imath.V2i( 1 ) - midpoint = dimensions.x * dimensions.y//2 + dimensions.x//2 - self.assertAlmostEqual( i["A"][midpoint], 1, 6 ) - - def testXYOrientation( self ) : - - # render a red square at x==1, and a green one at y==1 - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - r.setOption( "gl:searchPath:shader", IECore.StringData( os.path.join( os.path.dirname( __file__ ), "shaders" ) ) ) - r.display( os.path.join( os.path.dirname( __file__ ), "output", "testCamera.tif" ), "tiff", "rgba", {} ) - r.transformBegin() - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, 1 ) ) ) - r.camera( "main", { "resolution" : IECore.V2iData( imath.V2i( 512 ) ) } ) - r.transformEnd() - - r.worldBegin() - r.shader( "surface", "color", { "colorValue" : IECore.Color3fData( imath.Color3f( 1, 0, 0 ) ) } ) - IECoreScene.MeshPrimitive.createPlane( imath.Box2f( imath.V2f( 0.75, -0.25 ), imath.V2f( 1.25, 0.25 ) ) ).render( r ) - r.shader( "surface", "color", { "colorValue" : IECore.Color3fData( imath.Color3f( 0, 1, 0 ) ) } ) - IECoreScene.MeshPrimitive.createPlane( imath.Box2f( imath.V2f( -0.25, 0.75 ), imath.V2f( 0.25, 1.25 ) ) ).render( r ) - r.worldEnd() - - # check we get the colors we'd expect where we expect them - i = IECore.Reader.create( os.path.join( os.path.dirname( __file__ ), "output", "testCamera.tif" ) ).read() - dimensions = i.dataWindow.size() + imath.V2i( 1 ) - index = dimensions.x * dimensions.y//2 + dimensions.x - 1 - self.assertAlmostEqual( i["A"][index], 1, 6 ) - self.assertAlmostEqual( i["R"][index], 1, 6 ) - self.assertAlmostEqual( i["G"][index], 0, 6 ) - self.assertAlmostEqual( i["B"][index], 0, 6 ) - index = dimensions.x//2 - self.assertAlmostEqual( i["A"][index], 1, 6 ) - self.assertAlmostEqual( i["R"][index], 0, 6 ) - self.assertAlmostEqual( i["G"][index], 1, 6 ) - self.assertAlmostEqual( i["B"][index], 0, 6 ) - - def setUp( self ) : - - if not os.path.isdir( os.path.join( "test", "IECoreGL", "output" ) ) : - os.makedirs( os.path.join( "test", "IECoreGL", "output" ) ) - - def tearDown( self ) : - - if os.path.isdir( os.path.join( "test", "IECoreGL", "output" ) ) : - shutil.rmtree( os.path.join( "test", "IECoreGL", "output" ) ) - -if __name__ == "__main__": - unittest.main() diff --git a/test/IECoreGL/CoordinateSystemTest.py b/test/IECoreGL/CoordinateSystemTest.py deleted file mode 100644 index 30d879902a..0000000000 --- a/test/IECoreGL/CoordinateSystemTest.py +++ /dev/null @@ -1,117 +0,0 @@ -########################################################################## -# -# Copyright (c) 2010-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 Image Engine Design 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 os.path -import shutil -import imath - -import IECore -import IECoreScene -import IECoreImage - -import IECoreGL -IECoreGL.init( False ) - -class CoordinateSystemTest( unittest.TestCase ) : - - __outputFileName = os.path.join( os.path.dirname( __file__ ), "output", "testCoordinateSystem.tif" ) - - def testNoVisualisation( self ) : - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - - r.camera( "main", { - "projection" : IECore.StringData( "orthographic" ), - "resolution" : IECore.V2iData( imath.V2i( 256 ) ), - "clippingPlanes" : IECore.V2fData( imath.V2f( 1, 1000 ) ), - "screenWindow" : IECore.Box2fData( imath.Box2f( imath.V2f( -1 ), imath.V2f( 1 ) ) ) - } - ) - r.display( self.__outputFileName, "tif", "rgba", {} ) - - with IECoreScene.WorldBlock( r ) : - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -5 ) ) ) - r.coordinateSystem( "myCoordSys" ) - - i = IECore.Reader.create( self.__outputFileName ).read() - - a = i["A"] - for i in range( a.size() ) : - self.assertEqual( a[i], 0 ) - - def testVisualisation( self ) : - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - - r.camera( "main", { - "projection" : IECore.StringData( "orthographic" ), - "resolution" : IECore.V2iData( imath.V2i( 256 ) ), - "clippingPlanes" : IECore.V2fData( imath.V2f( 1, 1000 ) ), - "screenWindow" : IECore.Box2fData( imath.Box2f( imath.V2f( -1 ), imath.V2f( 1 ) ) ) - } - ) - r.display( self.__outputFileName, "tif", "rgba", {} ) - - r.setOption( "gl:drawCoordinateSystems", IECore.BoolData( True ) ) - - with IECoreScene.WorldBlock( r ) : - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -5 ) ) ) - r.coordinateSystem( "myCoordSys" ) - - i = IECore.Reader.create( self.__outputFileName ).read() - - a = i["A"] - self.assertTrue( a[127*256 + 127] > 0 ) - self.assertTrue( a[127*256 + 255] > 0 ) - self.assertTrue( a[127] > 0 ) - self.assertEqual( a[200*127 + 127], 0 ) - self.assertEqual( a[120*127 + 127], 0 ) - - def setUp( self ) : - - if not os.path.isdir( os.path.join( "test", "IECoreGL", "output" ) ) : - os.makedirs( os.path.join( "test", "IECoreGL", "output" ) ) - - def tearDown( self ) : - - if os.path.isdir( os.path.join( "test", "IECoreGL", "output" ) ) : - shutil.rmtree( os.path.join( "test", "IECoreGL", "output" ) ) - -if __name__ == "__main__": - unittest.main() diff --git a/test/IECoreGL/CurvesPrimitiveTest.py b/test/IECoreGL/CurvesPrimitiveTest.py deleted file mode 100644 index f34544b976..0000000000 --- a/test/IECoreGL/CurvesPrimitiveTest.py +++ /dev/null @@ -1,760 +0,0 @@ -########################################################################## -# -# Copyright (c) 2008-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 Image Engine Design 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 os.path -import shutil -import imath - -import IECore -import IECoreScene -import IECoreImage - -import IECoreGL -IECoreGL.init( False ) - -# workaround lack of skipIf decorator for -# python < 2.7. -## \todo If we had an IECoreTest module we could -# put this there, along with the expectedFailure -# workaround from GafferTest. -try : - skipIf = unittest.skipIf -except AttributeError : - def skipIf( condition, reason ) : - if condition : - def ignoreFunction( f ) : - def noOp( *args ) : - pass - return ignoreFunction - else : - def callFunction( f ) : - return f - return callFunction - -class CurvesPrimitiveTest( unittest.TestCase ) : - - outputFileName = os.path.join( os.path.dirname( __file__ ), "output", "testCurves.tif" ) - - def showColorShader( self ) : - - fs = """ - #include "IECoreGL/FragmentShader.h" - - IECOREGL_FRAGMENTSHADER_IN vec3 fragmentCs; - void main() - { - gl_FragColor = vec4( fragmentCs, 1 ); - } - """ - - s = IECoreScene.Shader( "showColor", "surface" ) - s.parameters["gl:fragmentSource"] = IECore.StringData( fs ) - - return s - - def performTest( self, curvesPrimitive, attributes=[], testPixels=[], testImage=None, shader=None, diffImage=None ) : - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - r.setOption( "gl:searchPath:shader", IECore.StringData( os.path.join( os.path.dirname( __file__ ), "shaders" ) ) ) - r.setOption( "gl:searchPath:shaderInclude", IECore.StringData( os.path.join( ".", "glsl" ) ) ) - - r.camera( "main", { - "projection" : IECore.StringData( "orthographic" ), - "resolution" : IECore.V2iData( imath.V2i( 256 ) ), - "clippingPlanes" : IECore.V2fData( imath.V2f( 1, 1000 ) ), - "screenWindow" : IECore.Box2fData( imath.Box2f( imath.V2f( 0 ), imath.V2f( 1 ) ) ) - } - ) - r.display( self.outputFileName, "tif", "rgba", {} ) - - with IECoreScene.WorldBlock( r ) : - - for a in attributes : - r.setAttribute( a[0], a[1] ) - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -5 ) ) ) - - if shader : - shader.render( r ) - else : - r.shader( "surface", "color", { "colorValue" : IECore.Color3fData( imath.Color3f( 0, 0, 1 ) ) } ) - - curvesPrimitive.render( r ) - - i = IECore.Reader.create( self.outputFileName ).read() - dimensions = i.dataWindow.size() + imath.V2i( 1 ) - - for t in testPixels : - - xOffset = 1 if t[0].x == 1 else 0 - yOffset = 1 if t[0].y == 1 else 0 - index = dimensions.x * int(dimensions.y * t[0].y - yOffset) + int(dimensions.x * t[0].x) - xOffset - - self.assertAlmostEqual( i["R"][index], t[1].r, 6 ) - self.assertAlmostEqual( i["G"][index], t[1].g, 6 ) - self.assertAlmostEqual( i["B"][index], t[1].b, 6 ) - self.assertAlmostEqual( i["A"][index], t[1].a, 6 ) - - if testImage : - - # blue where there must be an object - # red where we don't mind - # black where there must be nothing - - a = i["A"] - - i2 = IECore.Reader.create( testImage ).read() - r2 = i2["R"] - b2 = i2["B"] - for i in range( r2.size() ) : - - if b2[i] > 0.5 : - self.assertEqual( a[i], 1 ) - elif r2[i] < 0.5 : - self.assertEqual( a[i], 0 ) - - if diffImage : - - expectedImage = IECore.Reader.create( diffImage ).read() - - self.assertEqual( IECoreImage.ImageDiffOp()( imageA = expectedImage, imageB = i, maxError = 0.05 ).value, False ) - - - def testAttributes( self ) : - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - - r.worldBegin() - - self.assertEqual( r.getAttribute( "gl:curvesPrimitive:useGLLines" ), IECore.BoolData( False ) ) - self.assertEqual( r.getAttribute( "gl:curvesPrimitive:glLineWidth" ), IECore.FloatData( 1 ) ) - self.assertEqual( r.getAttribute( "gl:curvesPrimitive:ignoreBasis" ), IECore.BoolData( False ) ) - - r.setAttribute( "gl:curvesPrimitive:useGLLines", IECore.BoolData( True ) ) - self.assertEqual( r.getAttribute( "gl:curvesPrimitive:useGLLines" ), IECore.BoolData( True ) ) - - r.setAttribute( "gl:curvesPrimitive:glLineWidth", IECore.FloatData( 2 ) ) - self.assertEqual( r.getAttribute( "gl:curvesPrimitive:glLineWidth" ), IECore.FloatData( 2 ) ) - - r.setAttribute( "gl:curvesPrimitive:ignoreBasis", IECore.BoolData( True ) ) - self.assertEqual( r.getAttribute( "gl:curvesPrimitive:ignoreBasis" ), IECore.BoolData( True ) ) - - r.worldEnd() - - def testLinearNonPeriodicAsLines( self ) : - - self.performTest( - - IECoreScene.CurvesPrimitive( - - IECore.IntVectorData( [ 4, 4 ] ), - IECore.CubicBasisf.linear(), - False, - IECore.V3fVectorData( - [ - imath.V3f( 1, 0, 0 ), - imath.V3f( 0, 0, 0 ), - imath.V3f( 0, 0.5, 0 ), - imath.V3f( 0.5, 0.5, 0 ), - - imath.V3f( 0.5, 0.5, 0 ), - imath.V3f( 1, 0.5, 0 ), - imath.V3f( 1, 1, 0 ), - imath.V3f( 0, 1, 0 ), - ] - ) - - ), - [ - ( "gl:curvesPrimitive:glLineWidth", IECore.FloatData( 4 ) ), - ( "gl:curvesPrimitive:useGLLines", IECore.BoolData( True ) ), - ], - [ - ( imath.V2f( 0, 0 ), imath.Color4f( 0, 0, 1, 1 ) ), - ( imath.V2f( 0.5, 0 ), imath.Color4f( 0, 0, 1, 1 ) ), - ( imath.V2f( 1, 0 ), imath.Color4f( 0, 0, 1, 1 ) ), - ( imath.V2f( 1, 0.25 ), imath.Color4f( 0, 0, 1, 1 ) ), - ( imath.V2f( 1, 0.5 ), imath.Color4f( 0, 0, 1, 1 ) ), - ( imath.V2f( 0, 0.25 ), imath.Color4f( 0, 0, 0, 0 ) ), - ( imath.V2f( 0, 0.5 ), imath.Color4f( 0, 0, 1, 1 ) ), - ( imath.V2f( 0.5, 0.5 ), imath.Color4f( 0, 0, 1, 1 ) ), - ( imath.V2f( 0, 0.75 ), imath.Color4f( 0, 0, 1, 1 ) ), - ( imath.V2f( 1, 0.75 ), imath.Color4f( 0, 0, 0, 0 ) ), - ( imath.V2f( 1, 1 ), imath.Color4f( 0, 0, 1, 1 ) ), - ( imath.V2f( 0.5, 1 ), imath.Color4f( 0, 0, 1, 1 ) ), - ( imath.V2f( 0, 1 ), imath.Color4f( 0, 0, 1, 1 ) ), - ] - ) - - def testOverriddenLinearPeriodicAsLines( self ) : - - self.performTest( - - IECoreScene.CurvesPrimitive( - - IECore.IntVectorData( [ 4 ] ), - IECore.CubicBasisf.bSpline(), - True, - IECore.V3fVectorData( - [ - imath.V3f( 1, 0, 0 ), - imath.V3f( 0, 0, 0 ), - imath.V3f( 0, 1, 0 ), - imath.V3f( 1, 1, 0 ), - ] - ) - - ), - [ - ( "gl:curvesPrimitive:glLineWidth", IECore.FloatData( 4 ) ), - ( "gl:curvesPrimitive:useGLLines", IECore.BoolData( True ) ), - ( "gl:curvesPrimitive:ignoreBasis", IECore.BoolData( True ) ), - ], - [ - ( imath.V2f( 0, 0 ), imath.Color4f( 0, 0, 1, 1 ) ), - ( imath.V2f( 0.5, 0 ), imath.Color4f( 0, 0, 1, 1 ) ), - ( imath.V2f( 1, 0 ), imath.Color4f( 0, 0, 1, 1 ) ), - ( imath.V2f( 1, 0.5 ), imath.Color4f( 0, 0, 1, 1 ) ), - ( imath.V2f( 1, 1 ), imath.Color4f( 0, 0, 1, 1 ) ), - ( imath.V2f( 0.5, 1 ), imath.Color4f( 0, 0, 1, 1 ) ), - ( imath.V2f( 0, 1 ), imath.Color4f( 0, 0, 1, 1 ) ), - ( imath.V2f( 0, 0.5 ), imath.Color4f( 0, 0, 1, 1 ) ), - ( imath.V2f( 0.5, 0.5 ), imath.Color4f( 0, 0, 0, 0 ) ), - ( imath.V2f( 0.1, 0.1 ), imath.Color4f( 0, 0, 0, 0 ) ), - ( imath.V2f( 0.9, 0.1 ), imath.Color4f( 0, 0, 0, 0 ) ), - ( imath.V2f( 0.9, 0.9 ), imath.Color4f( 0, 0, 0, 0 ) ), - ( imath.V2f( 0.1, 0.9 ), imath.Color4f( 0, 0, 0, 0 ) ), - - ] - ) - - @skipIf( IECoreGL.glslVersion() >= 150, "Modern GLSL version, no need to test fallback" ) - def testFallbackLinearPeriodicAsLines( self ) : - - # when the GLSL version is < 150, we should fall back - # to rendering everything as linear lines. - - self.performTest( - - IECoreScene.CurvesPrimitive( - - IECore.IntVectorData( [ 4 ] ), - IECore.CubicBasisf.bSpline(), - True, - IECore.V3fVectorData( - [ - imath.V3f( 1, 0, 0 ), - imath.V3f( 0, 0, 0 ), - imath.V3f( 0, 1, 0 ), - imath.V3f( 1, 1, 0 ), - ] - ) - - ), - [ - ( "gl:curvesPrimitive:glLineWidth", IECore.FloatData( 4 ) ), - ], - [ - ( imath.V2f( 0, 0 ), imath.Color4f( 0, 0, 1, 1 ) ), - ( imath.V2f( 0.5, 0 ), imath.Color4f( 0, 0, 1, 1 ) ), - ( imath.V2f( 1, 0 ), imath.Color4f( 0, 0, 1, 1 ) ), - ( imath.V2f( 1, 0.5 ), imath.Color4f( 0, 0, 1, 1 ) ), - ( imath.V2f( 1, 1 ), imath.Color4f( 0, 0, 1, 1 ) ), - ( imath.V2f( 0.5, 1 ), imath.Color4f( 0, 0, 1, 1 ) ), - ( imath.V2f( 0, 1 ), imath.Color4f( 0, 0, 1, 1 ) ), - ( imath.V2f( 0, 0.5 ), imath.Color4f( 0, 0, 1, 1 ) ), - ( imath.V2f( 0.5, 0.5 ), imath.Color4f( 0, 0, 0, 0 ) ), - ( imath.V2f( 0.1, 0.1 ), imath.Color4f( 0, 0, 0, 0 ) ), - ( imath.V2f( 0.9, 0.1 ), imath.Color4f( 0, 0, 0, 0 ) ), - ( imath.V2f( 0.9, 0.9 ), imath.Color4f( 0, 0, 0, 0 ) ), - ( imath.V2f( 0.1, 0.9 ), imath.Color4f( 0, 0, 0, 0 ) ), - - ] - ) - - def testLinearPeriodicAsLines( self ) : - - self.performTest( - - IECoreScene.CurvesPrimitive( - - IECore.IntVectorData( [ 4 ] ), - IECore.CubicBasisf.linear(), - True, - IECore.V3fVectorData( - [ - imath.V3f( 1, 0, 0 ), - imath.V3f( 0, 0, 0 ), - imath.V3f( 0, 1, 0 ), - imath.V3f( 1, 1, 0 ), - ] - ) - - ), - [ - ( "gl:curvesPrimitive:glLineWidth", IECore.FloatData( 4 ) ), - ( "gl:curvesPrimitive:useGLLines", IECore.BoolData( True ) ), - ], - [ - ( imath.V2f( 0, 0 ), imath.Color4f( 0, 0, 1, 1 ) ), - ( imath.V2f( 0.5, 0 ), imath.Color4f( 0, 0, 1, 1 ) ), - ( imath.V2f( 1, 0 ), imath.Color4f( 0, 0, 1, 1 ) ), - ( imath.V2f( 1, 0.5 ), imath.Color4f( 0, 0, 1, 1 ) ), - ( imath.V2f( 1, 1 ), imath.Color4f( 0, 0, 1, 1 ) ), - ( imath.V2f( 0.5, 1 ), imath.Color4f( 0, 0, 1, 1 ) ), - ( imath.V2f( 0, 1 ), imath.Color4f( 0, 0, 1, 1 ) ), - ( imath.V2f( 0, 0.5 ), imath.Color4f( 0, 0, 1, 1 ) ), - ( imath.V2f( 0.5, 0.5 ), imath.Color4f( 0, 0, 0, 0 ) ), - ( imath.V2f( 0.1, 0.1 ), imath.Color4f( 0, 0, 0, 0 ) ), - ( imath.V2f( 0.9, 0.1 ), imath.Color4f( 0, 0, 0, 0 ) ), - ( imath.V2f( 0.9, 0.9 ), imath.Color4f( 0, 0, 0, 0 ) ), - ( imath.V2f( 0.1, 0.9 ), imath.Color4f( 0, 0, 0, 0 ) ), - - ] - ) - - @skipIf( IECoreGL.glslVersion() < 150, "Insufficient GLSL version" ) - def testBSplinePeriodicAsLines( self ) : - - self.performTest( - - IECoreScene.CurvesPrimitive( - - IECore.IntVectorData( [ 4 ] ), - IECore.CubicBasisf.bSpline(), - True, - IECore.V3fVectorData( - [ - imath.V3f( 1, 0, 0 ), - imath.V3f( 0, 0, 0 ), - imath.V3f( 0, 1, 0 ), - imath.V3f( 1, 1, 0 ), - ] - ) - - ), - [ - ( "gl:curvesPrimitive:glLineWidth", IECore.FloatData( 2 ) ), - ( "gl:curvesPrimitive:useGLLines", IECore.BoolData( True ) ), - ], - [ - ], - os.path.join( os.path.dirname( __file__ ), "images", "periodicBSpline.tif" ) - ) - - @skipIf( IECoreGL.glslVersion() < 150, "Insufficient GLSL version" ) - def testBSplinePeriodicAsRibbons( self ) : - - c = IECoreScene.CurvesPrimitive( - - IECore.IntVectorData( [ 4 ] ), - IECore.CubicBasisf.bSpline(), - True, - IECore.V3fVectorData( - [ - imath.V3f( 1, 0, 0 ), - imath.V3f( 0, 0, 0 ), - imath.V3f( 0, 1, 0 ), - imath.V3f( 1, 1, 0 ), - ] - ) - - ) - c["width"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, IECore.FloatData( 0.05 ) ) - - self.performTest( - - c, - [ - ( "gl:primitive:wireframe", IECore.BoolData( True ) ), - ], - [ - ], - os.path.join( os.path.dirname( __file__ ), "images", "bSplineCircle.tif" ) - ) - - @skipIf( IECoreGL.glslVersion() < 150, "Insufficient GLSL version" ) - def testBezierAsRibbons( self ) : - - c = IECoreScene.CurvesPrimitive( - - IECore.IntVectorData( [ 4 ] ), - IECore.CubicBasisf.bezier(), - False, - IECore.V3fVectorData( - [ - imath.V3f( 0.8, 0.2, 0 ), - imath.V3f( 0.2, 0.2, 0 ), - imath.V3f( 0.2, 0.8, 0 ), - imath.V3f( 0.8, 0.8, 0 ), - ] - ) - - ) - c["width"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, IECore.FloatData( 0.05 ) ) - - self.performTest( - c, - [ - ( "gl:primitive:wireframe", IECore.BoolData( True ) ), - ], - [ - ], - os.path.join( os.path.dirname( __file__ ), "images", "bezierHorseShoe.tif" ) - ) - - @skipIf( IECoreGL.glslVersion() < 150, "Insufficient GLSL version" ) - def testLinearRibbons( self ) : - - c = IECoreScene.CurvesPrimitive( - - IECore.IntVectorData( [ 4 ] ), - IECore.CubicBasisf.linear(), - False, - IECore.V3fVectorData( - [ - imath.V3f( 0.8, 0.2, 0 ), - imath.V3f( 0.2, 0.2, 0 ), - imath.V3f( 0.2, 0.8, 0 ), - imath.V3f( 0.8, 0.8, 0 ), - ] - ) - - ) - c["width"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, IECore.FloatData( 0.035 ) ) - - self.performTest( - c, - [ - ( "gl:primitive:wireframe", IECore.BoolData( True ) ), - ], - [ - ], - os.path.join( os.path.dirname( __file__ ), "images", "linearHorseShoeRibbon.tif" ) - ) - - @skipIf( IECoreGL.glslVersion() < 150, "Insufficient GLSL version" ) - def testLinearPeriodicRibbons( self ) : - - c = IECoreScene.CurvesPrimitive( - - IECore.IntVectorData( [ 4 ] ), - IECore.CubicBasisf.linear(), - True, - IECore.V3fVectorData( - [ - imath.V3f( 0.8, 0.2, 0 ), - imath.V3f( 0.2, 0.2, 0 ), - imath.V3f( 0.2, 0.8, 0 ), - imath.V3f( 0.8, 0.8, 0 ), - ] - ) - - ) - c["width"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, IECore.FloatData( 0.05 ) ) - - self.performTest( - c, - [ - ( "gl:primitive:wireframe", IECore.BoolData( True ) ), - ], - [ - ], - os.path.join( os.path.dirname( __file__ ), "images", "linearPeriodicRibbon.tif" ) - ) - - @skipIf( IECoreGL.glslVersion() < 150, "Insufficient GLSL version" ) - def testSeveralBSplineRibbons( self ) : - - c = IECoreScene.CurvesPrimitive( - - IECore.IntVectorData( [ 4, 4 ] ), - IECore.CubicBasisf.bSpline(), - True, - IECore.V3fVectorData( - [ - imath.V3f( 0.4, 0.2, 0 ), - imath.V3f( 0.2, 0.2, 0 ), - imath.V3f( 0.2, 0.4, 0 ), - imath.V3f( 0.4, 0.4, 0 ), - - imath.V3f( 0.8, 0.6, 0 ), - imath.V3f( 0.6, 0.6, 0 ), - imath.V3f( 0.6, 0.8, 0 ), - imath.V3f( 0.8, 0.8, 0 ), - ] - ) - - ) - c["width"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, IECore.FloatData( 0.035 ) ) - - self.performTest( - c, - [ - ( "gl:primitive:wireframe", IECore.BoolData( True ) ), - ], - [ - ], - os.path.join( os.path.dirname( __file__ ), "images", "twoBSplineCircles.tif" ) - ) - - @skipIf( IECoreGL.glslVersion() < 150, "Insufficient GLSL version" ) - def testSeveralBSplineLines( self ) : - - self.performTest( - IECoreScene.CurvesPrimitive( - - IECore.IntVectorData( [ 4, 4 ] ), - IECore.CubicBasisf.bSpline(), - True, - IECore.V3fVectorData( - [ - imath.V3f( 0.4, 0.2, 0 ), - imath.V3f( 0.2, 0.2, 0 ), - imath.V3f( 0.2, 0.4, 0 ), - imath.V3f( 0.4, 0.4, 0 ), - - imath.V3f( 0.8, 0.6, 0 ), - imath.V3f( 0.6, 0.6, 0 ), - imath.V3f( 0.6, 0.8, 0 ), - imath.V3f( 0.8, 0.8, 0 ), - ] - ) - - ), - [ - ( "gl:curvesPrimitive:glLineWidth", IECore.FloatData( 1 ) ), - ( "gl:curvesPrimitive:useGLLines", IECore.BoolData( True ) ), - ], - [ - ], - diffImage = os.path.join( os.path.dirname( __file__ ), "expectedOutput", "twoBSplineCirclesAsLines.tif" ) - ) - - @skipIf( IECoreGL.glslVersion() < 150, "Insufficient GLSL version" ) - def testRibbonWindingOrder( self ) : - - c = IECoreScene.CurvesPrimitive( - - IECore.IntVectorData( [ 4 ] ), - IECore.CubicBasisf.bSpline(), - True, - IECore.V3fVectorData( - [ - imath.V3f( 1, 0, 0 ), - imath.V3f( 0, 0, 0 ), - imath.V3f( 0, 1, 0 ), - imath.V3f( 1, 1, 0 ), - ] - ) - - ) - c["width"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, IECore.FloatData( 0.05 ) ) - - - self.performTest( - c, - [ - ( "doubleSided", IECore.BoolData( False ) ), - ], - [ - ], - os.path.join( os.path.dirname( __file__ ), "images", "bSplineCircle.tif" ) - ) - - @skipIf( IECoreGL.glslVersion() < 150, "Insufficient GLSL version" ) - def testLinearRibbonWindingOrder( self ) : - - c = IECoreScene.CurvesPrimitive( - - IECore.IntVectorData( [ 4 ] ), - IECore.CubicBasisf.linear(), - True, - IECore.V3fVectorData( - [ - imath.V3f( 0.8, 0.2, 0 ), - imath.V3f( 0.2, 0.2, 0 ), - imath.V3f( 0.2, 0.8, 0 ), - imath.V3f( 0.8, 0.8, 0 ), - ] - ) - - ) - c["width"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, IECore.FloatData( 0.05 ) ) - - self.performTest( - c, - [ - ( "doubleSided", IECore.BoolData( False ) ), - ], - [ - ], - os.path.join( os.path.dirname( __file__ ), "images", "linearPeriodicRibbon.tif" ) - ) - - def testLinearLinesWithVertexColor( self ) : - - c = IECoreScene.CurvesPrimitive( - - IECore.IntVectorData( [ 4, 4 ] ), - IECore.CubicBasisf.linear(), - False, - IECore.V3fVectorData( - [ - imath.V3f( 1, 0, 0 ), - imath.V3f( 0, 0, 0 ), - imath.V3f( 0, 0.5, 0 ), - imath.V3f( 0.5, 0.5, 0 ), - - imath.V3f( 0.5, 0.5, 0 ), - imath.V3f( 1, 0.5, 0 ), - imath.V3f( 1, 1, 0 ), - imath.V3f( 0, 1, 0 ), - ] - ) - - ) - c["Cs"] = IECoreScene.PrimitiveVariable( - IECoreScene.PrimitiveVariable.Interpolation.Vertex, - IECore.Color3fVectorData( - [ - imath.Color3f( 1, 0, 0 ), - imath.Color3f( 0, 1, 0 ), - imath.Color3f( 0, 0, 1 ), - imath.Color3f( 0, 1, 0 ), - - imath.Color3f( 1, 0, 0 ), - imath.Color3f( 0, 1, 0 ), - imath.Color3f( 0, 0, 1 ), - imath.Color3f( 0, 1, 0 ), - ] - ) - ) - - self.performTest( - - c, - [ - ( "gl:curvesPrimitive:glLineWidth", IECore.FloatData( 4 ) ), - ( "gl:curvesPrimitive:useGLLines", IECore.BoolData( True ) ), - ], - diffImage = os.path.join( os.path.dirname( __file__ ), "expectedOutput", "linearLinesWithVertexColor.tif" ), - shader = self.showColorShader(), - ) - - def testLinearLinesWithUniformColor( self ) : - - c = IECoreScene.CurvesPrimitive( - - IECore.IntVectorData( [ 4, 4 ] ), - IECore.CubicBasisf.linear(), - False, - IECore.V3fVectorData( - [ - imath.V3f( 1, 0, 0 ), - imath.V3f( 0, 0, 0 ), - imath.V3f( 0, 0.5, 0 ), - imath.V3f( 0.5, 0.5, 0 ), - - imath.V3f( 0.5, 0.5, 0 ), - imath.V3f( 1, 0.5, 0 ), - imath.V3f( 1, 1, 0 ), - imath.V3f( 0, 1, 0 ), - ] - ) - - ) - c["Cs"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Uniform, IECore.Color3fVectorData( [ imath.Color3f( 1, 0, 0 ), imath.Color3f( 0, 1, 0 ) ] ) ) - - self.performTest( - - c, - [ - ( "gl:curvesPrimitive:glLineWidth", IECore.FloatData( 4 ) ), - ( "gl:curvesPrimitive:useGLLines", IECore.BoolData( True ) ), - ], - diffImage = os.path.join( os.path.dirname( __file__ ), "expectedOutput", "linearLinesWithUniformColor.tif" ), - shader = self.showColorShader(), - ) - - def testLinearLinesWithConstantColor( self ) : - - c = IECoreScene.CurvesPrimitive( - - IECore.IntVectorData( [ 4, 4 ] ), - IECore.CubicBasisf.linear(), - False, - IECore.V3fVectorData( - [ - imath.V3f( 1, 0, 0 ), - imath.V3f( 0, 0, 0 ), - imath.V3f( 0, 0.5, 0 ), - imath.V3f( 0.5, 0.5, 0 ), - - imath.V3f( 0.5, 0.5, 0 ), - imath.V3f( 1, 0.5, 0 ), - imath.V3f( 1, 1, 0 ), - imath.V3f( 0, 1, 0 ), - ] - ) - - ) - c["Cs"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, IECore.Color3fData( imath.Color3f( 1, 0, 0 ) ) ) - - self.performTest( - - c, - [ - ( "gl:curvesPrimitive:glLineWidth", IECore.FloatData( 4 ) ), - ( "gl:curvesPrimitive:useGLLines", IECore.BoolData( True ) ), - ], - diffImage = os.path.join( os.path.dirname( __file__ ), "expectedOutput", "linearLinesWithConstantColor.tif" ), - shader = self.showColorShader(), - ) - - def setUp( self ) : - - if not os.path.isdir( os.path.join( "test", "IECoreGL", "output" ) ) : - os.makedirs( os.path.join( "test", "IECoreGL", "output" ) ) - - def tearDown( self ) : - - if os.path.isdir( os.path.join( "test", "IECoreGL", "output" ) ) : - shutil.rmtree( os.path.join( "test", "IECoreGL", "output" ) ) - -if __name__ == "__main__": - unittest.main() diff --git a/test/IECoreGL/DeferredRenderer.py b/test/IECoreGL/DeferredRenderer.py deleted file mode 100644 index e550a42137..0000000000 --- a/test/IECoreGL/DeferredRenderer.py +++ /dev/null @@ -1,128 +0,0 @@ -########################################################################## -# -# Copyright (c) 2008, 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 Image Engine Design 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 random -import IECore -import IECoreScene -import IECoreGL - - -IECoreGL.init( False ) - -class TestDeferredRenderer( unittest.TestCase ) : - - def __traverseGroup( self, g, result ) : - - n = g.getState().get( IECoreGL.NameStateComponent.staticTypeId() ) - - if n != None: - - result.append( n.name() ) - - else : - - result.append( "None" ) - - for c in g.children() : - - self.__traverseGroup( c, result ) - - def __buildGroup( self, parent, depth, name, maxDepth = 10 ) : - """ Build a random hierarchy with uniquely named children """ - - if depth >= maxDepth : - - return - - numChildren = int( 4 * random.random() ) - - for c in range( 0, numChildren ) : - - n = name + "." + str( c ) - - child = IECoreScene.Group() - - attributes = IECoreScene.AttributeState() - child.addState( attributes ) - - attributes.attributes["name"] = IECore.StringData( n ) - - parent.addChild( child ) - - if random.random() > 0.1 : - self.__buildGroup( child, depth + 1, n, maxDepth = maxDepth ) - - def testSceneOrder( self ) : - - # Make sure that scene order is consistent across multiple renders/renderers - - random.seed( 300 ) - root = IECoreScene.Group() - self.__buildGroup( root, 0, "root" ) - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - - r.worldBegin() - root.render( r ) - r.worldEnd() - - result = [] - self.__traverseGroup( r.scene().root(), result ) - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - - r.worldBegin() - root.render( r ) - r.worldEnd() - - result2 = [] - self.__traverseGroup( r.scene().root(), result2 ) - - self.assertEqual( result, result2 ) - - r.worldBegin() - root.render( r ) - r.worldEnd() - - result2 = [] - self.__traverseGroup( r.scene().root(), result2 ) - - self.assertEqual( result, result2 ) - - -if __name__ == "__main__": - unittest.main() diff --git a/test/IECoreGL/DiskPrimitiveTest.py b/test/IECoreGL/DiskPrimitiveTest.py deleted file mode 100644 index b77d19b6eb..0000000000 --- a/test/IECoreGL/DiskPrimitiveTest.py +++ /dev/null @@ -1,163 +0,0 @@ -########################################################################## -# -# Copyright (c) 2009-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 Image Engine Design 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 os.path -import shutil -import imath - -import IECore -import IECoreScene -import IECoreImage - -import IECoreGL -IECoreGL.init( False ) - -class DiskPrimitiveTest( unittest.TestCase ) : - - outputFileName = os.path.join( os.path.dirname( __file__ ), "output", "testDisk.tif" ) - - def test( self ) : - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - r.setOption( "gl:searchPath:shader", IECore.StringData( os.path.join( os.path.dirname( __file__ ), "shaders" ) ) ) - - r.camera( "main", { - "projection" : IECore.StringData( "orthographic" ), - "resolution" : IECore.V2iData( imath.V2i( 256 ) ), - "clippingPlanes" : IECore.V2fData( imath.V2f( 1, 1000 ) ), - "screenWindow" : IECore.Box2fData( imath.Box2f( imath.V2f( -1 ), imath.V2f( 1 ) ) ) - } - ) - r.display( self.outputFileName, "tif", "rgba", {} ) - - with IECoreScene.WorldBlock( r ) : - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -5 ) ) ) - - r.shader( "surface", "color", { "colorValue" : IECore.Color3fData( imath.Color3f( 0, 0, 1 ) ) } ) - r.disk( 1, 0, 360, {} ) - - i = IECore.Reader.create( self.outputFileName ).read() - reader = IECore.Reader.create( os.path.join( os.path.dirname( __file__ ), "images", "disk.tif" ) ) - reader["rawChannels"].setTypedValue( True ) - i2 = reader.read() - - # blue where there must be an object - # red where we don't mind - # black where there must be nothing - - a = i["A"] - - r2 = i2["R"] - b2 = i2["B"] - for i in range( r2.size() ) : - - if b2[i] > 0.5 : - self.assertEqual( a[i], 1 ) - elif r2[i] < 0.5 : - self.assertEqual( a[i], 0 ) - - def testWindingOrder( self ) : - - # camera facing single sided - should be visible - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - r.setOption( "gl:searchPath:shader", IECore.StringData( os.path.join( os.path.dirname( __file__ ), "shaders" ) ) ) - - r.camera( "main", { - "projection" : IECore.StringData( "orthographic" ), - "resolution" : IECore.V2iData( imath.V2i( 256 ) ), - "clippingPlanes" : IECore.V2fData( imath.V2f( 1, 1000 ) ), - "screenWindow" : IECore.Box2fData( imath.Box2f( imath.V2f( -1 ), imath.V2f( 1 ) ) ) - } - ) - r.display( self.outputFileName, "tif", "rgba", {} ) - - with IECoreScene.WorldBlock( r ) : - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -5 ) ) ) - r.setAttribute( "doubleSided", IECore.BoolData( False ) ) - - r.shader( "surface", "color", { "colorValue" : IECore.Color3fData( imath.Color3f( 0, 0, 1 ) ) } ) - r.disk( 1, 0, 360, {} ) - - image = IECore.Reader.create( self.outputFileName ).read() - dimensions = image.dataWindow.size() + imath.V2i( 1 ) - index = dimensions.x * dimensions.y//2 + dimensions.x//2 - self.assertEqual( image["A"][index], 1 ) - - # back facing single sided - should be invisible - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - r.setOption( "gl:searchPath:shader", IECore.StringData( os.path.join( os.path.dirname( __file__ ), "shaders" ) ) ) - - r.camera( "main", { - "projection" : IECore.StringData( "orthographic" ), - "resolution" : IECore.V2iData( imath.V2i( 256 ) ), - "clippingPlanes" : IECore.V2fData( imath.V2f( 1, 1000 ) ), - "screenWindow" : IECore.Box2fData( imath.Box2f( imath.V2f( -1 ), imath.V2f( 1 ) ) ) - } - ) - r.display( self.outputFileName, "tif", "rgba", {} ) - - with IECoreScene.WorldBlock( r ) : - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -5 ) ) ) - r.setAttribute( "doubleSided", IECore.BoolData( False ) ) - r.setAttribute( "rightHandedOrientation", IECore.BoolData( False ) ) - - r.shader( "surface", "color", { "colorValue" : IECore.Color3fData( imath.Color3f( 0, 0, 1 ) ) } ) - r.disk( 1, 0, 360, {} ) - - image = IECore.Reader.create( self.outputFileName ).read() - dimensions = image.dataWindow.size() + imath.V2i( 1 ) - index = dimensions.x * dimensions.y//2 + dimensions.x//2 - self.assertEqual( image["A"][index], 0 ) - - def setUp( self ) : - - if not os.path.isdir( os.path.join( "test", "IECoreGL", "output" ) ) : - os.makedirs( os.path.join( "test", "IECoreGL", "output" ) ) - - def tearDown( self ) : - - if os.path.isdir( os.path.join( "test", "IECoreGL", "output" ) ) : - shutil.rmtree( os.path.join( "test", "IECoreGL", "output" ) ) - -if __name__ == "__main__": - unittest.main() diff --git a/test/IECoreGL/ImmediateRenderer.py b/test/IECoreGL/ImmediateRenderer.py deleted file mode 100644 index d97acac24b..0000000000 --- a/test/IECoreGL/ImmediateRenderer.py +++ /dev/null @@ -1,105 +0,0 @@ -########################################################################## -# -# Copyright (c) 2007-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 Image Engine Design 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 os.path -import shutil -import imath - -import IECore -import IECoreImage -import IECoreGL - -IECoreGL.init( False ) - -class TestImmediateRenderer( unittest.TestCase ) : - - def test( self ) : - - outputFileName = os.path.join( os.path.dirname( __file__ ), "output", "testImmediate.tif" ) - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - r.setOption( "gl:searchPath:shader", IECore.StringData( os.path.join( os.path.dirname( __file__ ), "shaders" ) ) ) - - r.camera( "main", { - "projection" : IECore.StringData( "perspective" ), - "projection:fov" : IECore.FloatData( 45 ), - "resolution" : IECore.V2iData( imath.V2i( 256 ) ), - "clippingPlanes" : IECore.V2fData( imath.V2f( 1, 1000 ) ), - } - ) - r.display( outputFileName, "tif", "rgba", {} ) - - r.worldBegin() - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -5 ) ) ) - r.shader( "surface", "color", { "colorValue" : IECore.Color3fData( imath.Color3f( 0, 0, 1 ) ) } ) - r.sphere( 1, -1, 1, 360, {} ) - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 1, 0 ) ) ) - r.shader( "surface", "color", { "colorValue" : IECore.Color3fData( imath.Color3f( 1, 1, 0 ) ) } ) - r.sphere( 1, -1, 1, 360, {} ) - r.worldEnd() - - i = IECore.Reader.create( outputFileName ).read() - dimensions = i.dataWindow.size() + imath.V2i( 1 ) - index = int(dimensions.x * 0.5) - self.assertAlmostEqual( i["A"][index], 1, 6 ) - self.assertAlmostEqual( i["R"][index], 1, 6 ) - self.assertAlmostEqual( i["G"][index], 1, 6 ) - self.assertAlmostEqual( i["B"][index], 0, 6 ) - index = dimensions.x * int(dimensions.y * 0.5) + int(dimensions.x * 0.5) - self.assertAlmostEqual( i["A"][index], 1, 6 ) - self.assertAlmostEqual( i["R"][index], 0, 6 ) - self.assertAlmostEqual( i["G"][index], 0, 6 ) - self.assertAlmostEqual( i["B"][index], 1, 6 ) - index = 0 - self.assertAlmostEqual( i["A"][index], 0, 6 ) - self.assertAlmostEqual( i["R"][index], 0, 6 ) - self.assertAlmostEqual( i["G"][index], 0, 6 ) - self.assertAlmostEqual( i["B"][index], 0, 6 ) - - def setUp( self ) : - - if not os.path.isdir( os.path.join( "test", "IECoreGL", "output" ) ) : - os.makedirs( os.path.join( "test", "IECoreGL", "output" ) ) - - def tearDown( self ) : - - if os.path.isdir( os.path.join( "test", "IECoreGL", "output" ) ) : - shutil.rmtree( os.path.join( "test", "IECoreGL", "output" ) ) - -if __name__ == "__main__": - unittest.main() diff --git a/test/IECoreGL/InstancingTest.py b/test/IECoreGL/InstancingTest.py deleted file mode 100644 index 2d26058730..0000000000 --- a/test/IECoreGL/InstancingTest.py +++ /dev/null @@ -1,144 +0,0 @@ -########################################################################## -# -# Copyright (c) 2012, 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 Image Engine Design 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 IECore -import IECoreScene -import IECoreGL - -IECoreGL.init( False ) - -class InstancingTest( unittest.TestCase ) : - - class RandomMeshProcedural( IECoreScene.Renderer.Procedural ) : - - def __init__( self, meshes, name="/1", depth=0, maxDepth=8 ) : - - IECoreScene.Renderer.Procedural.__init__( self ) - - self.__meshes = meshes - self.__depth = depth - self.__maxDepth = maxDepth - self.__name = name - - def bound( self ) : - - b = imath.Box3f() - for m in self.__meshes : - b.extendBy( m.bound() ) - return b - - def render( self, renderer ) : - - with IECoreScene.AttributeBlock( renderer ) : - - renderer.setAttribute( "name", IECore.StringData( self.__name ) ) - - if self.__depth < self.__maxDepth : - - for n in ( "1", "2" ) : - renderer.procedural( - InstancingTest.RandomMeshProcedural( - self.__meshes, - self.__name + "/" + n, - self.__depth + 1, - self.__maxDepth, - ) - ) - - else : - - mesh = self.__meshes[ int( self.__name.split( "/" )[-1] ) - 1 ] - mesh.render( renderer ) - - def hash( self ): - - h = IECore.MurmurHash() - return h - - def __collectMeshes( self, group, result ) : - - name = group.getState().get( IECoreGL.NameStateComponent.staticTypeId() ) - - for c in group.children() : - if isinstance( c, IECoreGL.Group ) : - self.__collectMeshes( c, result ) - else : - d = result.setdefault( name.name().split( "/" )[-1], [] ) - d.append( c ) - - def testAutomaticInstancingOn( self ) : - - m1 = IECoreScene.MeshPrimitive.createPlane( imath.Box2f( imath.V2f( 0 ), imath.V2f( 1 ) ) ) - m2 = IECoreScene.MeshPrimitive.createPlane( imath.Box2f( imath.V2f( -1 ), imath.V2f( 1 ) ) ) - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - - with IECoreScene.WorldBlock( r ) : - - r.procedural( self.RandomMeshProcedural( [ m1, m2 ] ) ) - - meshes = {} - self.__collectMeshes( r.scene().root(), meshes ) - - for meshList in meshes.values() : - for i in range( 0, len( meshList ) ) : - self.assertTrue( meshList[i].isSame( meshList[0] ) ) - - def testAutomaticInstancingOff( self ) : - - m1 = IECoreScene.MeshPrimitive.createPlane( imath.Box2f( imath.V2f( 0 ), imath.V2f( 1 ) ) ) - m2 = IECoreScene.MeshPrimitive.createPlane( imath.Box2f( imath.V2f( -1 ), imath.V2f( 1 ) ) ) - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - - with IECoreScene.WorldBlock( r ) : - - r.setAttribute( "automaticInstancing", IECore.BoolData( False ) ) - - r.procedural( self.RandomMeshProcedural( [ m1, m2 ] ) ) - - meshes = {} - self.__collectMeshes( r.scene().root(), meshes ) - - for meshList in meshes.values() : - for i in range( 1, len( meshList ) ) : - self.assertFalse( meshList[i].isSame( meshList[0] ) ) - -if __name__ == "__main__": - unittest.main() diff --git a/test/IECoreGL/MeshPrimitiveTest.py b/test/IECoreGL/MeshPrimitiveTest.py deleted file mode 100644 index 4e4aad7546..0000000000 --- a/test/IECoreGL/MeshPrimitiveTest.py +++ /dev/null @@ -1,284 +0,0 @@ -########################################################################## -# -# Copyright (c) 2008-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 Image Engine Design 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 os -import shutil -import imath - -import IECore -import IECoreScene -import IECoreImage -import IECoreGL - -IECoreGL.init( False ) - -class MeshPrimitiveTest( unittest.TestCase ) : - - outputFileName = os.path.join( os.path.dirname( __file__ ), "output", "testMesh.tif" ) - - def testVertexAttributes( self ) : - - vertexSource = """ - #include "IECoreGL/VertexShader.h" - - IECOREGL_VERTEXSHADER_IN vec3 vertexP; - IECOREGL_VERTEXSHADER_IN vec2 vertexuv; - IECOREGL_VERTEXSHADER_OUT vec4 color; - - void main() - { - vec4 pCam = gl_ModelViewMatrix * vec4( vertexP, 1 ); - gl_Position = gl_ProjectionMatrix * pCam; - // Note that we're only flipping V here because the expected - // output image was generated with the wrong texture coordinates. - // It is _not_ expected that you would need to modify texture - // coordinates in the general case. - color = vec4(vertexuv.x, 1.0 - vertexuv.y, 0.0, 1.0); - } - """ - - fragmentSource = """ - varying vec4 color; - - void main() - { - gl_FragColor = color; - } - """ - - m = IECore.Reader.create( os.path.join( "test", "IECore", "data", "cobFiles", "pSphereShape1.cob" ) ).read() - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - - r.camera( "main", { - "projection" : IECore.StringData( "orthographic" ), - "resolution" : IECore.V2iData( imath.V2i( 256 ) ), - "clippingPlanes" : IECore.V2fData( imath.V2f( 1, 1000 ) ), - "screenWindow" : IECore.Box2fData( imath.Box2f( imath.V2f( -1 ), imath.V2f( 1 ) ) ) - } - ) - r.display( self.outputFileName, "tif", "rgba", {} ) - - with IECoreScene.WorldBlock( r ) : - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -15 ) ) ) - r.shader( "surface", "showUV", - { "gl:fragmentSource" : IECore.StringData( fragmentSource ), - "gl:vertexSource" : IECore.StringData( vertexSource ) - } - ) - - m.render( r ) - - reader = IECore.Reader.create( os.path.join( os.path.dirname( __file__ ), "expectedOutput", "meshST.tif" ) ) - reader["rawChannels"].setTypedValue( True ) - expectedImage = reader.read() - actualImage = IECore.Reader.create( self.outputFileName ).read() - - self.assertEqual( IECoreImage.ImageDiffOp()( imageA = expectedImage, imageB = actualImage, maxError = 0.05 ).value, False ) - - def testUniformCs( self ) : - - fragmentSource = """ - #include "IECoreGL/FragmentShader.h" - - IECOREGL_FRAGMENTSHADER_IN vec3 fragmentCs; - - void main() - { - gl_FragColor = vec4( fragmentCs, 1.0 ); - } - """ - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - - r.camera( "main", { - "projection" : IECore.StringData( "orthographic" ), - "resolution" : IECore.V2iData( imath.V2i( 256 ) ), - "clippingPlanes" : IECore.V2fData( imath.V2f( 1, 1000 ) ), - "screenWindow" : IECore.Box2fData( imath.Box2f( imath.V2f( -1 ), imath.V2f( 1 ) ) ) - } - ) - r.display( self.outputFileName, "tif", "rgba", {} ) - - with IECoreScene.WorldBlock( r ) : - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -15 ) ) ) - - r.shader( "surface", "test", { "gl:fragmentSource" : IECore.StringData( fragmentSource ) } ) - - m = IECoreScene.MeshPrimitive.createPlane( imath.Box2f( imath.V2f( -1 ), imath.V2f( 1 ) ), imath.V2i( 2 ) ) - m["Cs"] = IECoreScene.PrimitiveVariable( - IECoreScene.PrimitiveVariable.Interpolation.Uniform, - IECore.Color3fVectorData( [ - imath.Color3f( 1, 0, 0 ), - imath.Color3f( 0, 1, 0 ), - imath.Color3f( 0, 0, 1 ), - imath.Color3f( 1, 1, 1, ), - ] ) - ) - - m.render( r ) - - image = IECore.Reader.create( self.outputFileName ).read() - dimensions = image.dataWindow.size() + imath.V2i( 1 ) - index = dimensions.x * int(dimensions.y * 0.75) + int(dimensions.x * 0.25) - self.assertAlmostEqual( image["R"][index], 1, 6 ) - self.assertAlmostEqual( image["G"][index], 0, 6 ) - self.assertAlmostEqual( image["B"][index], 0, 6 ) - - index = dimensions.x * int(dimensions.y * 0.75) + int(dimensions.x * 0.75) - self.assertAlmostEqual( image["R"][index], 0, 6 ) - self.assertAlmostEqual( image["G"][index], 1, 6 ) - self.assertAlmostEqual( image["B"][index], 0, 6 ) - - index = dimensions.x * int(dimensions.y * 0.25) + int(dimensions.x * 0.75) - self.assertAlmostEqual( image["R"][index], 1, 6 ) - self.assertAlmostEqual( image["G"][index], 1, 6 ) - self.assertAlmostEqual( image["B"][index], 1, 6 ) - - index = dimensions.x * int(dimensions.y * 0.25) + int(dimensions.x * 0.25) - self.assertAlmostEqual( image["R"][index], 0, 6 ) - self.assertAlmostEqual( image["G"][index], 0, 6 ) - self.assertAlmostEqual( image["B"][index], 1, 6 ) - - def testBound( self ) : - - m = IECoreScene.MeshPrimitive.createPlane( imath.Box2f( imath.V2f( -0.5 ), imath.V2f( 0.5 ) ) ) - m2 = IECoreGL.ToGLMeshConverter( m ).convert() - - self.assertEqual( m.bound(), m2.bound() ) - - def testFaceNormals( self ) : - - # when a polygon mesh has no normals, we must calculate face normals so we can - # shade it in a faceted manner. - - fragmentSource = """ - #include "IECoreGL/FragmentShader.h" - IECOREGL_FRAGMENTSHADER_IN vec3 fragmentN; - - void main() - { - gl_FragColor = vec4( fragmentN, 1.0 ); - } - """ - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - - r.camera( "main", { - "projection" : IECore.StringData( "orthographic" ), - "resolution" : IECore.V2iData( imath.V2i( 256 ) ), - "clippingPlanes" : IECore.V2fData( imath.V2f( 1, 1000 ) ), - "screenWindow" : IECore.Box2fData( imath.Box2f( imath.V2f( -1 ), imath.V2f( 1 ) ) ) - } - ) - r.display( self.outputFileName, "tif", "rgba", {} ) - - with IECoreScene.WorldBlock( r ) : - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -15 ) ) ) - - r.shader( "surface", "test", { "gl:fragmentSource" : IECore.StringData( fragmentSource ) } ) - - m = IECoreScene.MeshPrimitive.createPlane( imath.Box2f( imath.V2f( -0.5 ), imath.V2f( 0.5 ) ) ) - del m["N"] - self.assertTrue( "N" not in m ) - m.render( r ) - - image = IECore.Reader.create( self.outputFileName ).read() - dimensions = image.dataWindow.size() + imath.V2i( 1 ) - index = dimensions.x * dimensions.y//2 + dimensions.x//2 - self.assertAlmostEqual( image["R"][index], 0, 6 ) - self.assertAlmostEqual( image["G"][index], 0, 6 ) - self.assertAlmostEqual( image["B"][index], 1, 6 ) - - def testIndexedUV( self ) : - - fragmentSource = """ - varying vec2 fragmentuv; - - void main() - { - gl_FragColor = vec4( fragmentuv.x, fragmentuv.y, 0, 1 ); - } - """ - - m = IECoreScene.MeshPrimitive.createPlane( imath.Box2f( imath.V2f( -1 ), imath.V2f( 1 ) ), imath.V2i( 100 ) ) - self.assertTrue( m["uv"].indices is not None ) - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - - r.camera( "main", { - "projection" : IECore.StringData( "orthographic" ), - "resolution" : IECore.V2iData( imath.V2i( 64 ) ), - "clippingPlanes" : IECore.V2fData( imath.V2f( 1, 1000 ) ), - "screenWindow" : IECore.Box2fData( imath.Box2f( imath.V2f( -1 ), imath.V2f( 1 ) ) ) - } - ) - r.display( os.path.join( os.path.dirname( __file__ ), "output", "testMesh.exr" ), "exr", "rgba", {} ) - - with IECoreScene.WorldBlock( r ) : - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -15 ) ) ) - r.shader( "surface", "showUV", - { - "gl:fragmentSource" : IECore.StringData( fragmentSource ), - } - ) - - m.render( r ) - - expectedImage = IECore.Reader.create( os.path.join( os.path.dirname( __file__ ), "expectedOutput", "meshIndexedUVs.exr" ) ).read() - actualImage = IECore.Reader.create( os.path.join( os.path.dirname( __file__ ), "output", "testMesh.exr" ) ).read() - - self.assertEqual( IECoreImage.ImageDiffOp()( imageA = expectedImage, imageB = actualImage, maxError = 0.05 ).value, False ) - - def setUp( self ) : - - if not os.path.isdir( os.path.join( "test", "IECoreGL", "output" ) ) : - os.makedirs( os.path.join( "test", "IECoreGL", "output" ) ) - - def tearDown( self ) : - - if os.path.isdir( os.path.join( "test", "IECoreGL", "output" ) ) : - shutil.rmtree( os.path.join( "test", "IECoreGL", "output" ) ) - -if __name__ == "__main__": - unittest.main() diff --git a/test/IECoreGL/Orientation.py b/test/IECoreGL/Orientation.py deleted file mode 100644 index e58a29092d..0000000000 --- a/test/IECoreGL/Orientation.py +++ /dev/null @@ -1,187 +0,0 @@ -########################################################################## -# -# Copyright (c) 2008-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 Image Engine Design 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 IECore -import IECoreScene -import IECoreImage -import IECoreGL -IECoreGL.init( False ) -import os.path -import os -import shutil -import math - -class OrientationTest( unittest.TestCase ) : - - ## Makes a plane on the XY plane which appears with an anticlockwise winding order when - # viewing down the negative Z axis. - def makePlane( self ) : - - V = imath.V3f - p = IECore.V3fVectorData( [ V( 1, -1, 0 ), V( 1, 1, 0 ), V( -1, 1, 0 ), V( -1, -1, 0 ) ] ) - nVerts = IECore.IntVectorData( [ 4 ] ) - vertIds = IECore.IntVectorData( [ 0, 1, 2, 3 ] ) - - return IECoreScene.MeshPrimitive( nVerts, vertIds, "linear", p ) - - def testAttribute( self ) : - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - r.worldBegin() - self.assertEqual( r.getAttribute( "rightHandedOrientation" ), IECore.BoolData( True ) ) - r.setAttribute( "rightHandedOrientation", IECore.BoolData( False ) ) - self.assertEqual( r.getAttribute( "rightHandedOrientation" ), IECore.BoolData( False ) ) - r.worldEnd() - - def testMesh( self ) : - - """Check that anticlockwise winding order is considered front facing by default.""" - - outputFileName = os.path.join( os.path.dirname( __file__ ), "output", "testOrientation.tif" ) - - # render a single sided plane that shouldn't be backface culled - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - r.display( outputFileName, "tiff", "rgba", {} ) - r.camera( "main", { "resolution" : IECore.V2iData( imath.V2i( 256 ) ) } ) - r.worldBegin() - r.setAttribute( "doubleSided", IECore.BoolData( False ) ) - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -5 ) ) ) - self.makePlane().render( r ) - r.worldEnd() - - # check that something appears in the output image - i = IECore.Reader.create( outputFileName ).read() - dimensions = i.dataWindow.size() + imath.V2i( 1 ) - index = dimensions.x * int(dimensions.y * 0.5) + int(dimensions.x * 0.5) - self.assertEqual( i["A"][index], 1 ) - - # render a plane that should be backface culled - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - r.display( outputFileName, "tiff", "rgba", {} ) - r.camera( "main", { "resolution" : IECore.V2iData( imath.V2i( 256 ) ) } ) - r.worldBegin() - r.setAttribute( "doubleSided", IECore.BoolData( False ) ) - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -5 ) ) ) - r.concatTransform( imath.M44f().rotate( imath.V3f( 0, math.pi, 0 ) ) ) - self.makePlane().render( r ) - r.worldEnd() - - # check that nothing appears in the output image - i = IECore.Reader.create( outputFileName ).read() - dimensions = i.dataWindow.size() + imath.V2i( 1 ) - index = dimensions.x * int(dimensions.y * 0.5) + int(dimensions.x * 0.5) - self.assertEqual( i["A"][index], 0 ) - - def testFlippingTransforms( self ) : - - """Check that flipping transforms are automatically compensated for.""" - - outputFileName = os.path.join( os.path.dirname( __file__ ), "output", "testOrientation.tif" ) - - # render a single sided plane that shouldn't be backface culled, even though - # the negative transform has reversed the winding order - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - r.display( outputFileName, "tiff", "rgba", {} ) - r.camera( "main", { "resolution" : IECore.V2iData( imath.V2i( 256 ) ) } ) - r.worldBegin() - self.assertEqual( r.getAttribute( "rightHandedOrientation" ), IECore.BoolData( True ) ) - r.setAttribute( "doubleSided", IECore.BoolData( False ) ) - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -5 ) ) ) - r.concatTransform( imath.M44f().scale( imath.V3f( -1, 1, 1 ) ) ) - self.assertEqual( r.getAttribute( "rightHandedOrientation" ), IECore.BoolData( False ) ) - self.makePlane().render( r ) - r.worldEnd() - - # check that something appears in the output image - i = IECore.Reader.create( outputFileName ).read() - dimensions = i.dataWindow.size() + imath.V2i( 1 ) - index = dimensions.x * int(dimensions.y * 0.5) + int(dimensions.x * 0.5) - self.assertEqual( i["A"][index], 1 ) - - def testFlippingTransformsAndTransformEnd( self ) : - - """Check that flipped orientations are restored at transformEnd.""" - - outputFileName = os.path.join( os.path.dirname( __file__ ), "output", "testOrientation.tif" ) - - # render a single sided plane that shouldn't be backface culled, even though - # the negative transform has reversed the winding order - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - r.display( outputFileName, "tiff", "rgba", {} ) - r.camera( "main", { "resolution" : IECore.V2iData( imath.V2i( 256 ) ) } ) - r.worldBegin() - if 1 : - - self.assertEqual( r.getAttribute( "rightHandedOrientation" ), IECore.BoolData( True ) ) - r.setAttribute( "doubleSided", IECore.BoolData( False ) ) - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -5 ) ) ) - - r.transformBegin() - if 1 : - - r.concatTransform( imath.M44f().scale( imath.V3f( -1, 1, 1 ) ) ) - self.assertEqual( r.getAttribute( "rightHandedOrientation" ), IECore.BoolData( False ) ) - self.makePlane().render( r ) - - r.transformEnd() ## \todo We need to fix our transformEnd implementation. - - self.assertEqual( r.getAttribute( "rightHandedOrientation" ), IECore.BoolData( True ) ) - - r.worldEnd() - - # check that something appears in the output image - i = IECore.Reader.create( outputFileName ).read() - dimensions = i.dataWindow.size() + imath.V2i( 1 ) - index = dimensions.x * int(dimensions.y * 0.5) + int(dimensions.x * 0.5) - self.assertEqual( i["A"][index], 1 ) - - def setUp( self ) : - - if not os.path.isdir( os.path.join( "test", "IECoreGL", "output" ) ) : - os.makedirs( os.path.join( "test", "IECoreGL", "output" ) ) - - def tearDown( self ) : - - if os.path.isdir( os.path.join( "test", "IECoreGL", "output" ) ) : - shutil.rmtree( os.path.join( "test", "IECoreGL", "output" ) ) - -if __name__ == "__main__": - unittest.main() diff --git a/test/IECoreGL/PointsPrimitive.py b/test/IECoreGL/PointsPrimitive.py deleted file mode 100644 index 5cdc6bcb7b..0000000000 --- a/test/IECoreGL/PointsPrimitive.py +++ /dev/null @@ -1,590 +0,0 @@ -########################################################################## -# -# Copyright (c) 2007-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 Image Engine Design 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 random -import os -import shutil -import imath - -import IECore -import IECoreScene -import IECoreImage -import IECoreGL - -IECoreGL.init( False ) - -class TestPointsPrimitive( unittest.TestCase ) : - - outputFileName = os.path.join( os.path.dirname( __file__ ), "output", "testPoints.exr" ) - - def testStateComponentsInstantiation( self ): - - IECoreGL.PointsPrimitive.UseGLPoints( IECoreGL.GLPointsUsage.ForPointsOnly ) - IECoreGL.PointsPrimitive.GLPointWidth( 1.5 ) - - def testStateComponentsUsage( self ): - - g = IECoreGL.Group() - g.getState().add( IECoreGL.PointsPrimitive.UseGLPoints( IECoreGL.GLPointsUsage.ForPointsAndDisks ) ) - g.getState().add( IECoreGL.PointsPrimitive.GLPointWidth( 2.3 ) ) - - def testVertexAttributes( self ) : - - # if rendering points and requiring custom vertex attributes to be passed - # to the fragment shader, you are now required to provide your own vertex shader. - # however, handy macros exist to make the instancing and aiming easy. - vertexSource = """ - #include \"IECoreGL/PointsPrimitive.h\" - #include \"IECoreGL/VertexShader.h\" - - IECOREGL_POINTSPRIMITIVE_DECLAREVERTEXPARAMETERS - - IECOREGL_VERTEXSHADER_IN vec3 instanceP; - // although we don't need to pass st to the fragment shader, everything - // ceases to work on os x if we don't. - IECOREGL_VERTEXSHADER_IN vec2 instancest; - IECOREGL_VERTEXSHADER_IN float vertexgreyTo255; - - IECOREGL_VERTEXSHADER_OUT float fragmentGrey; - IECOREGL_VERTEXSHADER_OUT vec2 fragmentst; - - void main() - { - mat4 instanceMatrix = IECOREGL_POINTSPRIMITIVE_INSTANCEMATRIX; - vec4 pCam = instanceMatrix * vec4( instanceP, 1 ); - gl_Position = gl_ProjectionMatrix * pCam; - fragmentst = instancest; - fragmentGrey = float( vertexgreyTo255 ) / 255.0; - } - """ - - fragmentSource = """ - #include \"IECoreGL/FragmentShader.h\" - - IECOREGL_FRAGMENTSHADER_IN float fragmentGrey; - - void main() - { - gl_FragColor = vec4( fragmentGrey, fragmentGrey, fragmentGrey, 1.0 ); - } - """ - - numPoints = 100 - p = IECore.V3fVectorData( numPoints ) - g = IECore.IntVectorData( numPoints ) - random.seed( 0 ) - for i in range( 0, numPoints ) : - p[i] = imath.V3f( random.random() * 4, random.random() * 4, random.random() * 4 ) - g[i] = int( random.uniform( 0.0, 255.0 ) ) - p = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, p ) - g = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, g ) - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - r.setOption( "gl:searchPath:shaderInclude", IECore.StringData( os.path.join( ".", "glsl" ) ) ) - - r.camera( "main", { - "projection" : IECore.StringData( "orthographic" ), - "resolution" : IECore.V2iData( imath.V2i( 256 ) ), - "clippingPlanes" : IECore.V2fData( imath.V2f( 1, 1000 ) ), - "screenWindow" : IECore.Box2fData( imath.Box2f( imath.V2f( -3 ), imath.V2f( 3 ) ) ) - } - ) - r.display( self.outputFileName, "exr", "rgba", {} ) - - with IECoreScene.WorldBlock( r ) : - - r.concatTransform( imath.M44f().translate( imath.V3f( -2, -2, -10 ) ) ) - r.shader( "surface", "grey", { "gl:vertexSource" : vertexSource, "gl:fragmentSource" : IECore.StringData( fragmentSource ) } ) - r.points( numPoints, { "P" : p, "greyTo255" : g } ) - - reader = IECore.Reader.create( os.path.join( os.path.dirname( __file__ ), "expectedOutput", "pointVertexAttributes.tif" ) ) - reader["rawChannels"].setTypedValue( True ) - expectedImage = reader.read() - actualImage = IECore.Reader.create( self.outputFileName ).read() - - self.assertEqual( IECoreImage.ImageDiffOp()( imageA = expectedImage, imageB = actualImage, maxError = 0.05 ).value, False ) - - def testEmptyPointsPrimitive( self ): - - fragmentSource = """ - uniform int greyTo255; - - void main() - { - float g = float( greyTo255 ) / 255.0; - gl_FragColor = vec4( g, g, g, 1 ); - } - """ - p = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.V3fVectorData() ) - g = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.IntVectorData() ) - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - r.setOption( "gl:searchPath:shaderInclude", IECore.StringData( os.path.join( ".", "glsl" ) ) ) - r.camera( "main", { - "projection" : IECore.StringData( "orthographic" ), - "resolution" : IECore.V2iData( imath.V2i( 256 ) ), - "clippingPlanes" : IECore.V2fData( imath.V2f( 1, 1000 ) ), - "screenWindow" : IECore.Box2fData( imath.Box2f( imath.V2f( -3 ), imath.V2f( 3 ) ) ) - } - ) - r.display( self.outputFileName, "exr", "rgba", {} ) - with IECoreScene.WorldBlock( r ) : - r.shader( "surface", "grey", { "gl:fragmentSource" : IECore.StringData( fragmentSource ) } ) - r.points( 0, { "P" : p, "greyTo255" : g } ) # it should not crash rendering 0 points. - - def performAimTest( self, projection, expectedImage, particleType ) : - - fragmentSource = """ - void main() - { - gl_FragColor = vec4( 1, 1, 1, 1 ); - } - """ - - p = IECore.V3fVectorData() - for x in range( -2, 3 ) : - for y in range( -2, 3 ) : - p.append( imath.V3f( x, y, 0 ) ) - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - r.setOption( "gl:searchPath:shaderInclude", IECore.StringData( os.path.join( ".", "glsl" ) ) ) - - r.camera( "main", { - "projection" : IECore.StringData( projection ), - "focalLength" : IECore.FloatData( 5.671281819617709 ), - "resolution" : IECore.V2iData( imath.V2i( 256 ) ), - "clippingPlanes" : IECore.V2fData( imath.V2f( 1, 1000 ) ), - "aperture" : IECore.V2fData( imath.V2f( 6 ) ) - } - ) - r.display( self.outputFileName, "exr", "rgba", {} ) - - with IECoreScene.WorldBlock( r ) : - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -6 ) ) ) - - r.shader( "surface", "white", { "gl:fragmentSource" : IECore.StringData( fragmentSource ) } ) - r.points( p.size(), { - "P" : IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, p ), - "constantwidth" : IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, IECore.FloatData( 0.75 ) ), - "type" : IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Uniform, IECore.StringData( particleType ) ) - } - ) - - expectedImage = IECore.Reader.create( os.path.join( os.path.dirname( __file__ ), "expectedOutput", expectedImage ) ).read() - actualImage = IECore.Reader.create( self.outputFileName ).read() - - self.assertEqual( IECoreImage.ImageDiffOp()( imageA = expectedImage, imageB = actualImage, maxError = 0.08 ).value, False ) - - def testPerspectiveAimedPoints( self ) : - - self.performAimTest( "perspective", "aimedPerspectivePoints.tif", "particle" ) - - def testOrthographicAimedPoints( self ) : - - self.performAimTest( "orthographic", "aimedOrthographicPoints.tif", "particle" ) - - def testPerspectiveAimedPatches( self ) : - - self.performAimTest( "perspective", "aimedPerspectivePatches.tif", "patch" ) - - def testOrthographicAimedPatches( self ) : - - self.performAimTest( "orthographic", "aimedOrthographicPatches.tif", "patch" ) - - def testGLPoints( self ) : - - fragmentSource = """ - void main() - { - gl_FragColor = vec4( 1, 1, 1, 1 ); - } - """ - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - r.setOption( "gl:searchPath:shaderInclude", IECore.StringData( os.path.join( ".", "glsl" ) ) ) - - r.camera( "main", { - "projection" : IECore.StringData( "orthographic" ), - "projection:fov" : IECore.FloatData( 20 ), - "resolution" : IECore.V2iData( imath.V2i( 256 ) ), - "clippingPlanes" : IECore.V2fData( imath.V2f( 1, 1000 ) ), - "screenWindow" : IECore.Box2fData( imath.Box2f( imath.V2f( -3 ), imath.V2f( 3 ) ) ) - } - ) - r.display( self.outputFileName, "tif", "rgba", {} ) - - with IECoreScene.WorldBlock( r ) : - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -6 ) ) ) - - r.shader( "surface", "white", { "gl:fragmentSource" : IECore.StringData( fragmentSource ) } ) - - with IECoreScene.AttributeBlock( r ) : - - r.setAttribute( "gl:pointsPrimitive:glPointWidth", IECore.FloatData( 20 ) ) - - r.points( 1, { - "P" : IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.V3fVectorData( [ imath.V3f( 0 ) ] ) ), - "type" : IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Uniform, IECore.StringData( "gl:point" ) ) - } - ) - - with IECoreScene.AttributeBlock( r ) : - - r.setAttribute( "gl:pointsPrimitive:glPointWidth", IECore.FloatData( 10 ) ) - - r.points( 1, { - "P" : IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.V3fVectorData( [ imath.V3f( 1, 0, 0 ) ] ) ), - "type" : IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Uniform, IECore.StringData( "gl:point" ) ) - } - ) - - expectedImage = IECore.Reader.create( os.path.join( os.path.dirname( __file__ ), "expectedOutput", "glPoints.tif" ) ).read() - actualImage = IECore.Reader.create( self.outputFileName ).read() - - self.assertEqual( IECoreImage.ImageDiffOp()( imageA = expectedImage, imageB = actualImage, maxError = 0.05 ).value, False ) - - def testTexturing( self ) : - - fragmentSource = """ - uniform sampler2D texture; - varying vec2 fragmentuv; - - void main() - { - gl_FragColor = texture2D( texture, fragmentuv ); - } - """ - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - r.setOption( "gl:searchPath:texture", IECore.StringData( "." + os.path.sep ) ) - r.setOption( "gl:searchPath:shaderInclude", IECore.StringData( os.path.join( ".", "glsl" ) ) ) - r.camera( "main", { - "projection" : IECore.StringData( "orthographic" ), - "resolution" : IECore.V2iData( imath.V2i( 1024 ) ), - "clippingPlanes" : IECore.V2fData( imath.V2f( 1, 1000 ) ), - "screenWindow" : IECore.Box2fData( imath.Box2f( imath.V2f( -.5 ), imath.V2f( .5 ) ) ) - } - ) - r.display( self.outputFileName, "exr", "rgba", {} ) - - with IECoreScene.WorldBlock( r ) : - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -6 ) ) ) - - r.shader( - "surface", "test", - { - "gl:fragmentSource" : IECore.StringData( fragmentSource ), - "texture" : os.path.join( "test", "IECoreGL", "images", "numbers.exr" ), - } - ) - - r.points( 1, { - "P" : IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.V3fVectorData( [ imath.V3f( 0 ) ] ) ), - "type" : IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Uniform, IECore.StringData( "patch" ) ) - } ) - - expectedImage = IECore.Reader.create( os.path.join( "test", "IECoreGL", "images", "numbers.exr" ) ).read() - actualImage = IECore.Reader.create( self.outputFileName ).read() - self.assertEqual( IECoreImage.ImageDiffOp()( imageA = expectedImage, imageB = actualImage, maxError = 0.05 ).value, False ) - - def testWindingOrder( self ) : - - def performTest( rightHandedOrientation, expectedAlpha ) : - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - r.setOption( "gl:searchPath:shaderInclude", IECore.StringData( os.path.join( ".", "glsl" ) ) ) - r.camera( "main", { - "projection" : IECore.StringData( "orthographic" ), - "resolution" : IECore.V2iData( imath.V2i( 1024 ) ), - "clippingPlanes" : IECore.V2fData( imath.V2f( 1, 1000 ) ), - "screenWindow" : IECore.Box2fData( imath.Box2f( imath.V2f( -.5 ), imath.V2f( .5 ) ) ) - } - ) - r.display( self.outputFileName, "exr", "rgba", {} ) - - with IECoreScene.WorldBlock( r ) : - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -6 ) ) ) - r.setAttribute( "doubleSided", IECore.BoolData( False ) ) - r.setAttribute( "rightHandedOrientation", IECore.BoolData( rightHandedOrientation ) ) - - r.points( 1, { - "P" : IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.V3fVectorData( [ imath.V3f( 0 ) ] ) ), - } ) - - i = IECore.Reader.create( self.outputFileName ).read() - dimensions = i.dataWindow.size() + imath.V2i( 1 ) - index = dimensions.x * int(dimensions.y * 0.5) + int(dimensions.x * 0.5) - self.assertEqual( i["A"][index], expectedAlpha ) - - performTest( True, 1 ) - performTest( False, 0 ) - - def testAspectAndRotation( self ) : - - fragmentSource = """ - void main() - { - gl_FragColor = vec4( 1, 1, 1, 1 ); - } - """ - - random = imath.Rand48() - - p = IECore.V3fVectorData() - r = IECore.FloatVectorData() - w = IECore.FloatVectorData() - a = IECore.FloatVectorData() - for x in range( -2, 3 ) : - for y in range( -2, 3 ) : - p.append( imath.V3f( x, y, 0 ) ) - r.append( random.nextf( 0, 360 ) ) - w.append( random.nextf( 0.25, 0.5 ) ) - a.append( random.nextf( 0.5, 2 ) ) - - renderer = IECoreGL.Renderer() - renderer.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - renderer.setOption( "gl:searchPath:shaderInclude", IECore.StringData( os.path.join( ".", "glsl" ) ) ) - - renderer.camera( "main", { - "projection" : IECore.StringData( "orthographic" ), - "resolution" : IECore.V2iData( imath.V2i( 512 ) ), - "clippingPlanes" : IECore.V2fData( imath.V2f( 1, 1000 ) ), - "screenWindow" : IECore.Box2fData( imath.Box2f( imath.V2f( -3 ), imath.V2f( 3 ) ) ) - } - ) - renderer.display( self.outputFileName, "exr", "rgba", { "quantize" : IECore.FloatVectorData( [ 0, 0, 0, 0 ] ) } ) - - with IECoreScene.WorldBlock( renderer ) : - - renderer.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -6 ) ) ) - - renderer.shader( "surface", "white", { "gl:fragmentSource" : IECore.StringData( fragmentSource ) } ) - renderer.points( p.size(), { - "P" : IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, p ), - "patchrotation" : IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, r ), - "width" : IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, w ), - "patchaspectratio" : IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, a ), - "type" : IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Uniform, IECore.StringData( "patch" ) ), - } - ) - - expectedImage = IECore.Reader.create( os.path.join( os.path.dirname( __file__ ), "expectedOutput", "rotatedPointPatches.exr" ) ).read() - actualImage = IECore.Reader.create( self.outputFileName ).read() - - self.assertEqual( IECoreImage.ImageDiffOp()( imageA = expectedImage, imageB = actualImage, maxError = 0.08 ).value, False ) - - def testBound( self ) : - - p = IECoreGL.PointsPrimitive( IECoreGL.PointsPrimitive.Type.Point ) - - self.assertEqual( p.bound(), imath.Box3f() ) - - p.addPrimitiveVariable( - "P", - IECoreScene.PrimitiveVariable( - IECoreScene.PrimitiveVariable.Interpolation.Vertex, - IECore.V3fVectorData( [ imath.V3f( -1 ), imath.V3f( 10 ) ] ) - ) - ) - - self.assertEqual( p.bound(), imath.Box3f( imath.V3f( -1.5 ), imath.V3f( 10.5 ) ) ) - - p.addPrimitiveVariable( - "constantwidth", - IECoreScene.PrimitiveVariable( - IECoreScene.PrimitiveVariable.Interpolation.Constant, - IECore.FloatData( 2 ) - ) - ) - - self.assertEqual( p.bound(), imath.Box3f( imath.V3f( -2 ), imath.V3f( 11 ) ) ) - - p.addPrimitiveVariable( - "width", - IECoreScene.PrimitiveVariable( - IECoreScene.PrimitiveVariable.Interpolation.Vertex, - IECore.FloatVectorData( [ .5, 2 ] ) - ) - ) - - self.assertEqual( p.bound(), imath.Box3f( imath.V3f( -1.5 ), imath.V3f( 12 ) ) ) - - p.addPrimitiveVariable( - "patchaspectratio", - IECoreScene.PrimitiveVariable( - IECoreScene.PrimitiveVariable.Interpolation.Vertex, - IECore.FloatVectorData( [ .5, 4 ] ) - ) - ) - - self.assertEqual( p.bound(), imath.Box3f( imath.V3f( -2 ), imath.V3f( 12 ) ) ) - - def testUniformShaderParameters( self ) : - - fragmentSource = """ - uniform vec3 myColor; - void main() - { - gl_FragColor = vec4( myColor, 1 ); - } - """ - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - r.setOption( "gl:searchPath:shaderInclude", IECore.StringData( os.path.join( ".", "glsl" ) ) ) - r.camera( "main", { - "projection" : IECore.StringData( "orthographic" ), - "resolution" : IECore.V2iData( imath.V2i( 1024 ) ), - "clippingPlanes" : IECore.V2fData( imath.V2f( 1, 1000 ) ), - "screenWindow" : IECore.Box2fData( imath.Box2f( imath.V2f( -.5 ), imath.V2f( .5 ) ) ) - } - ) - r.display( self.outputFileName, "exr", "rgba", {} ) - - with IECoreScene.WorldBlock( r ) : - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -6 ) ) ) - - r.shader( "surface", "test", { "gl:fragmentSource" : fragmentSource, "myColor" : imath.Color3f( 1, 0, 0 ) } ) - - r.points( 1, { - "P" : IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.V3fVectorData( [ imath.V3f( 0 ) ] ) ), - } ) - - i = IECore.Reader.create( self.outputFileName ).read() - dimensions = i.dataWindow.size() + imath.V2i( 1 ) - index = dimensions.x * int(dimensions.y * 0.5) + int(dimensions.x * 0.5) - self.assertEqual( i["A"][index], 1 ) - self.assertEqual( i["R"][index], 1 ) - self.assertEqual( i["G"][index], 0 ) - self.assertEqual( i["B"][index], 0 ) - - def testWireframeShading( self ) : - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - - r.camera( - "main", - { - "projection" : IECore.StringData( "orthographic" ), - "resolution" : IECore.V2iData( imath.V2i( 1024 ) ), - "clippingPlanes" : IECore.V2fData( imath.V2f( 1, 1000 ) ), - "screenWindow" : IECore.Box2fData( imath.Box2f( imath.V2f( -.5 ), imath.V2f( .5 ) ) ) - } - ) - - r.display( self.outputFileName, "exr", "rgba", {} ) - - with IECoreScene.WorldBlock( r ) : - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -6 ) ) ) - r.setAttribute( "gl:primitive:wireframe", True ) - r.setAttribute( "gl:primitive:wireframeColor", imath.Color4f( 1, 0, 0, 1 ) ) - r.setAttribute( "gl:primitive:wireframeWidth", 5.0 ) - r.setAttribute( "gl:primitive:solid", False ) - - r.points( 1, { - "P" : IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.V3fVectorData( [ imath.V3f( 0 ) ] ) ), - } ) - - i = IECore.Reader.create( self.outputFileName ).read() - dimensions = i.dataWindow.size() + imath.V2i( 1 ) - index = dimensions.x * int(dimensions.y * 0.5) + int(dimensions.x * 0.5) - self.assertEqual( i["A"][index], 1 ) - self.assertEqual( i["R"][index], 1 ) - self.assertEqual( i["G"][index], 0 ) - self.assertEqual( i["B"][index], 0 ) - - def testVertexCs( self ) : - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - - r.camera( - "main", - { - "projection" : IECore.StringData( "orthographic" ), - "resolution" : IECore.V2iData( imath.V2i( 1024 ) ), - "clippingPlanes" : IECore.V2fData( imath.V2f( 1, 1000 ) ), - "screenWindow" : IECore.Box2fData( imath.Box2f( imath.V2f( -1), imath.V2f( 1 ) ) ) - } - ) - - r.display( self.outputFileName, "exr", "rgba", {} ) - - with IECoreScene.WorldBlock( r ) : - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -6 ) ) ) - - r.points( 2, { - "P" : IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.V3fVectorData( [ imath.V3f( -.5 ), imath.V3f( .5 ) ] ) ), - "Cs" : IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.Color3fVectorData( [ imath.Color3f( 1, 0, 0 ), imath.Color3f( 0, 1, 0 ) ] ) ), - } ) - - i = IECore.Reader.create( self.outputFileName ).read() - dimensions = i.dataWindow.size() + imath.V2i( 1 ) - index = dimensions.x * int(dimensions.y * 0.75) + int(dimensions.x * 0.25) - self.assertEqual( i["A"][index], 1 ) - self.assertEqual( i["R"][index], 1 ) - self.assertEqual( i["G"][index], 0 ) - self.assertEqual( i["B"][index], 0 ) - - index = dimensions.x * int(dimensions.y * 0.25) + int(dimensions.x * 0.75) - self.assertEqual( i["A"][index], 1 ) - self.assertEqual( i["R"][index], 0 ) - self.assertEqual( i["G"][index], 1 ) - self.assertEqual( i["B"][index], 0 ) - - def setUp( self ) : - - if not os.path.isdir( os.path.join( "test", "IECoreGL", "output" ) ) : - os.makedirs( os.path.join( "test", "IECoreGL", "output" ) ) - - def tearDown( self ) : - - if os.path.isdir( os.path.join( "test", "IECoreGL", "output" ) ) : - shutil.rmtree( os.path.join( "test", "IECoreGL", "output" ) ) - -if __name__ == "__main__": - unittest.main() diff --git a/test/IECoreGL/Renderer.py b/test/IECoreGL/Renderer.py deleted file mode 100644 index effdd751ca..0000000000 --- a/test/IECoreGL/Renderer.py +++ /dev/null @@ -1,1035 +0,0 @@ -########################################################################## -# -# Copyright (c) 2007-2013, Image Engine Design Inc. All rights reserved. -# Copyright (c) 2011, John Haddon. 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 Image Engine Design 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 os -import os.path -import threading -import math -import shutil -import imath - -import IECore -import IECoreScene -import IECoreImage -import IECoreGL - -IECoreGL.init( False ) - -class TestRenderer( unittest.TestCase ) : - - def testOptions( self ) : - - os.environ["IECOREGL_TEXTURE_PATHS"] = "textureDefault" - os.environ["IECOREGL_SHADER_PATHS"] = "shaderDefault" - - r = IECoreGL.Renderer() - - self.assertEqual( r.typeName(), "IECoreGL::Renderer" ) - - self.assertEqual( r.getOption( "searchPath:texture" ), IECore.StringData( "textureDefault" ) ) - self.assertEqual( r.getOption( "gl:searchPath:texture" ), IECore.StringData( "textureDefault" ) ) - - r.setOption( "searchPath:texture", IECore.StringData( "a" ) ) - self.assertEqual( r.getOption( "searchPath:texture" ), IECore.StringData( "a" ) ) - self.assertEqual( r.getOption( "gl:searchPath:texture" ), IECore.StringData( "a" ) ) - - r.setOption( "gl:searchPath:texture", IECore.StringData( "b" ) ) - self.assertEqual( r.getOption( "searchPath:texture" ), IECore.StringData( "b" ) ) - self.assertEqual( r.getOption( "gl:searchPath:texture" ), IECore.StringData( "b" ) ) - - self.assertEqual( r.getOption( "searchPath:shader" ), IECore.StringData( "shaderDefault" ) ) - self.assertEqual( r.getOption( "gl:searchPath:shader" ), IECore.StringData( "shaderDefault" ) ) - - r.setOption( "searchPath:shader", IECore.StringData( "s" ) ) - self.assertEqual( r.getOption( "searchPath:shader" ), IECore.StringData( "s" ) ) - self.assertEqual( r.getOption( "gl:searchPath:shader" ), IECore.StringData( "s" ) ) - - r.setOption( "gl:searchPath:shader", IECore.StringData( "t" ) ) - self.assertEqual( r.getOption( "searchPath:shader" ), IECore.StringData( "t" ) ) - self.assertEqual( r.getOption( "gl:searchPath:shader" ), IECore.StringData( "t" ) ) - - self.assertEqual( r.getOption( "shutter" ), IECore.V2fData( imath.V2f( 0 ) ) ) - r.setOption( "shutter", IECore.V2fData( imath.V2f( 1, 2 ) ) ) - self.assertEqual( r.getOption( "shutter" ), IECore.V2fData( imath.V2f( 1, 2 ) ) ) - - self.assertEqual( r.getOption( "gl:drawCoordinateSystems" ), IECore.BoolData( False ) ) - r.setOption( "gl:drawCoordinateSystems", IECore.BoolData( True ) ) - self.assertEqual( r.getOption( "gl:drawCoordinateSystems" ), IECore.BoolData( True ) ) - - def testAttributes( self ) : - - deferred = IECoreGL.Renderer() - deferred.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - - immediate = IECoreGL.Renderer() - immediate.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - - - for r in [ deferred, immediate ] : - - r.worldBegin() - - self.assertEqual( r.getAttribute( "color" ), IECore.Color3fData( imath.Color3f( 1 ) ) ) - self.assertEqual( r.getAttribute( "opacity" ), IECore.Color3fData( imath.Color3f( 1 ) ) ) - self.assertEqual( r.getAttribute( "gl:color" ), IECore.Color4fData( imath.Color4f( 1 ) ) ) - self.assertEqual( r.getAttribute( "gl:blend:color" ), IECore.Color4fData( imath.Color4f( 1 ) ) ) - self.assertEqual( r.getAttribute( "gl:blend:srcFactor" ), IECore.StringData( "srcAlpha" ) ) - self.assertEqual( r.getAttribute( "gl:blend:dstFactor" ), IECore.StringData( "oneMinusSrcAlpha" ) ) - self.assertEqual( r.getAttribute( "gl:blend:equation" ), IECore.StringData( "add" ) ) - self.assertEqual( r.getAttribute( "gl:shade:transparent" ), IECore.BoolData( False ) ) - self.assertEqual( r.getAttribute( "gl:primitive:sortForTransparency" ), IECore.BoolData( True ) ) - self.assertEqual( r.getAttribute( "name" ), IECore.StringData( "unnamed" ) ) - self.assertEqual( r.getAttribute( "doubleSided" ), IECore.BoolData( True ) ) - self.assertEqual( r.getAttribute( "gl:smoothing:points" ), IECore.BoolData( False ) ) - self.assertEqual( r.getAttribute( "gl:smoothing:lines" ), IECore.BoolData( False ) ) - self.assertEqual( r.getAttribute( "gl:smoothing:polygons" ), IECore.BoolData( False ) ) - self.assertEqual( r.getAttribute( "gl:procedural:reentrant" ), IECore.BoolData( True ) ) - if IECore.withFreeType() : - self.assertEqual( r.getAttribute( "gl:textPrimitive:type" ), IECore.StringData( "mesh" ) ) - self.assertEqual( r.getAttribute( "gl:depthTest" ), IECore.BoolData( True ) ) - self.assertEqual( r.getAttribute( "gl:depthMask" ), IECore.BoolData( True ) ) - self.assertEqual( r.getAttribute( "gl:alphaTest" ), IECore.BoolData( False ) ) - - self.assertEqual( r.getAttribute( "gl:alphaTest:mode" ), IECore.StringData( "always" ) ) - self.assertEqual( r.getAttribute( "gl:alphaTest:value" ), IECore.FloatData( 0.0 ) ) - - self.assertEqual( r.getAttribute( "gl:visibility:camera" ), IECore.BoolData( True ) ) - - self.assertEqual( r.getAttribute( "gl:automaticInstancing" ), IECore.BoolData( True ) ) - self.assertEqual( r.getAttribute( "automaticInstancing" ), IECore.BoolData( True ) ) - - r.setAttribute( "color", IECore.Color3fData( imath.Color3f( 0, 1, 2 ) ) ) - self.assertEqual( r.getAttribute( "color" ), IECore.Color3fData( imath.Color3f( 0, 1, 2 ) ) ) - - # opacity is an odd one - it's set as a color but as it's averaged internally - # the result you get should be a greyscale value. - r.setAttribute( "opacity", IECore.Color3fData( imath.Color3f( 3, 1, 2 ) ) ) - self.assertEqual( r.getAttribute( "opacity" ), IECore.Color3fData( imath.Color3f( 2 ) ) ) - - self.assertEqual( r.getAttribute( "gl:color" ), IECore.Color4fData( imath.Color4f( 0, 1, 2, 2 ) ) ) - r.setAttribute( "gl:color", IECore.Color4fData( imath.Color4f( 1, 2, 3, 4 ) ) ) - self.assertEqual( r.getAttribute( "gl:color" ), IECore.Color4fData( imath.Color4f( 1, 2, 3, 4 ) ) ) - - r.setAttribute( "gl:blend:color", IECore.Color4fData( imath.Color4f( 0, 1, 0, 1 ) ) ) - self.assertEqual( r.getAttribute( "gl:blend:color" ), IECore.Color4fData( imath.Color4f( 0, 1, 0, 1 ) ) ) - - r.attributeBegin() - r.setAttribute( "color", IECore.Color3fData( imath.Color3f( 0 ) ) ) - self.assertEqual( r.getAttribute( "gl:color" ), IECore.Color4fData( imath.Color4f( 0, 0, 0, 4 ) ) ) - r.attributeEnd() - self.assertEqual( r.getAttribute( "gl:color" ), IECore.Color4fData( imath.Color4f( 1, 2, 3, 4 ) ) ) - - factors = [ "zero", "one", "srcColor", "oneMinusSrcColor", "dstColor", "oneMinusDstColor", - "srcAlpha", "oneMinusSrcAlpha", "dstAlpha", "oneMinusDstAlpha", "dstAlpha", "oneMinusDstAlpha", - "constantColor", "oneMinusConstantColor", "constantAlpha", "oneMinusConstantAlpha" ] - for f in factors : - last = r.getAttribute( "gl:blend:dstFactor" ) - r.setAttribute( "gl:blend:srcFactor", IECore.StringData( f ) ) - self.assertEqual( r.getAttribute( "gl:blend:srcFactor" ), IECore.StringData( f ) ) - self.assertEqual( r.getAttribute( "gl:blend:dstFactor" ), last ) - last = r.getAttribute( "gl:blend:srcFactor" ) - r.setAttribute( "gl:blend:dstFactor", IECore.StringData( f ) ) - self.assertEqual( r.getAttribute( "gl:blend:srcFactor" ), IECore.StringData( f ) ) - self.assertEqual( r.getAttribute( "gl:blend:dstFactor" ), last ) - - for e in ["add", "subtract", "reverseSubtract", "min", "max"] : - r.setAttribute( "gl:blend:equation", IECore.StringData( e ) ) - self.assertEqual( r.getAttribute( "gl:blend:equation" ), IECore.StringData( e ) ) - - r.setAttribute( "name", IECore.StringData( "sphere" ) ) - self.assertEqual( r.getAttribute( "name" ), IECore.StringData( "sphere" ) ) - - r.setAttribute( "doubleSided", IECore.BoolData( False ) ) - self.assertEqual( r.getAttribute( "doubleSided" ), IECore.BoolData( False ) ) - - r.setAttribute( "gl:smoothing:points", IECore.BoolData( True ) ) - self.assertEqual( r.getAttribute( "gl:smoothing:points" ), IECore.BoolData( True ) ) - r.setAttribute( "gl:smoothing:lines", IECore.BoolData( True ) ) - self.assertEqual( r.getAttribute( "gl:smoothing:lines" ), IECore.BoolData( True ) ) - r.setAttribute( "gl:smoothing:polygons", IECore.BoolData( True ) ) - self.assertEqual( r.getAttribute( "gl:smoothing:polygons" ), IECore.BoolData( True ) ) - - r.setAttribute( "gl:procedural:reentrant", IECore.BoolData( False ) ) - self.assertEqual( r.getAttribute( "gl:procedural:reentrant" ), IECore.BoolData( False ) ) - - if IECore.withFreeType() : - r.setAttribute( "gl:textPrimitive:type", IECore.StringData( "sprite" ) ) - self.assertEqual( r.getAttribute( "gl:textPrimitive:type" ), IECore.StringData( "sprite" ) ) - - r.setAttribute( "gl:depthTest", IECore.BoolData( False ) ) - self.assertEqual( r.getAttribute( "gl:depthTest" ), IECore.BoolData( False ) ) - - r.setAttribute( "gl:depthMask", IECore.BoolData( False ) ) - self.assertEqual( r.getAttribute( "gl:depthMask" ), IECore.BoolData( False ) ) - - r.setAttribute( "gl:alphaTest", IECore.BoolData( True ) ) - self.assertEqual( r.getAttribute( "gl:alphaTest" ), IECore.BoolData( True ) ) - - alphaTestModes = [ "never", "less", "equal", "lequal", "greater", "notequal", "gequal", "always" ] - value = 0.1 - for m in alphaTestModes : - last = r.getAttribute( "gl:alphaTest:value" ) - r.setAttribute( "gl:alphaTest:mode", IECore.StringData( m ) ) - self.assertEqual( r.getAttribute( "gl:alphaTest:mode" ), IECore.StringData( m ) ) - self.assertEqual( r.getAttribute( "gl:alphaTest:value" ), last ) - - last = r.getAttribute( "gl:alphaTest:mode" ) - r.setAttribute( "gl:alphaTest:value", IECore.FloatData( value ) ) - self.assertEqual( r.getAttribute( "gl:alphaTest:value" ), IECore.FloatData( value ) ) - self.assertEqual( r.getAttribute( "gl:alphaTest:mode" ), last ) - - value += 0.05 - - r.setAttribute( "gl:visibility:camera", IECore.BoolData( False ) ) - self.assertEqual( r.getAttribute( "gl:visibility:camera" ), IECore.BoolData( False ) ) - - r.setAttribute( "gl:automaticInstancing", IECore.BoolData( False ) ) - self.assertEqual( r.getAttribute( "gl:automaticInstancing" ), IECore.BoolData( False ) ) - self.assertEqual( r.getAttribute( "automaticInstancing" ), IECore.BoolData( False ) ) - r.setAttribute( "automaticInstancing", IECore.BoolData( True ) ) - self.assertEqual( r.getAttribute( "automaticInstancing" ), IECore.BoolData( True ) ) - self.assertEqual( r.getAttribute( "gl:automaticInstancing" ), IECore.BoolData( True ) ) - - r.worldEnd() - - def testOtherRendererAttributes( self ) : - - """Attributes destined for other renderers should be silently ignored.""" - - deferred = IECoreGL.Renderer() - deferred.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - - immediate = IECoreGL.Renderer() - immediate.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - - with IECore.CapturingMessageHandler() as handler : - - for r in [ deferred, immediate ] : - - r.worldBegin() - - r.setAttribute( "ri:visibility:diffuse", IECore.IntData( 0 ) ) - - r.worldEnd() - - self.assertEqual( len( handler.messages ), 0 ) - - def testStackBug( self ) : - - # This should produce a yellow sphere in between two red spheres. It does in the DeferredRenderer but - # currently fails in the ImmediateRenderer. - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - r.setOption( "gl:searchPath:shader", IECore.StringData( os.path.join( os.path.dirname( __file__ ), "shaders" ) ) ) - r.display( os.path.join( os.path.dirname( __file__ ), "output", "testStackBug.tif" ), "tiff", "rgba", {} ) - r.worldBegin() - - r.shader( "surface", "rgbColor", { "red" : IECore.FloatData( 1 ), "green" : IECore.FloatData( 0 ), "blue" : IECore.FloatData( 0 ) } ) - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -5 ) ) ) - - r.attributeBegin() - - r.shader( "surface", "rgbColor", { "red" : IECore.FloatData( 1 ), "green" : IECore.FloatData( 1 ), "blue" : IECore.FloatData( 0 ) } ) - r.sphere( 1, -1, 1, 360, {} ) - - r.attributeEnd() - - r.concatTransform( imath.M44f().translate( imath.V3f( -1, 0, 0 ) ) ) - r.sphere( 1, -1, 1, 360, {} ) - - r.concatTransform( imath.M44f().translate( imath.V3f( 2, 0, 0 ) ) ) - r.sphere( 1, -1, 1, 360, {} ) - - r.worldEnd() - - i = IECore.Reader.create( os.path.join( os.path.dirname( __file__ ), "output", "testStackBug.tif" ) ).read() - dimensions = i.dataWindow.size() + imath.V2i( 1 ) - index = dimensions.x * int(dimensions.y * 0.5) + int(dimensions.x * 0.5) - self.assertAlmostEqual( i["R"][index], 1, 6 ) - self.assertAlmostEqual( i["G"][index], 1, 6 ) - self.assertAlmostEqual( i["B"][index], 0, 6 ) - - index = dimensions.x * int(dimensions.y * 0.5) - self.assertAlmostEqual( i["R"][index], 1, 6 ) - self.assertAlmostEqual( i["G"][index], 0, 6 ) - self.assertAlmostEqual( i["B"][index], 0, 6 ) - - index = dimensions.x * int(dimensions.y * 0.5) + int(dimensions.x * 1) - 1 - self.assertAlmostEqual( i["R"][index], 1, 6 ) - self.assertAlmostEqual( i["G"][index], 0, 6 ) - self.assertAlmostEqual( i["B"][index], 0, 6 ) - - def testPrimVars( self ) : - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - r.setOption( "gl:searchPath:shader", IECore.StringData( os.path.join( os.path.dirname( __file__ ), "shaders" ) ) ) - r.display( os.path.join( os.path.dirname( __file__ ), "output", "testPrimVars.tif" ), "tiff", "rgba", {} ) - r.worldBegin() - - r.shader( "surface", "rgbColor", {} ) - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -5 ) ) ) - - r.attributeBegin() - - # should make red, green and blue spheres - r.sphere( - 1, -1, 1, 360, - { - "red" : IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, IECore.FloatData( 1 ) ), - "green" : IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, IECore.FloatData( 0 ) ), - "blue" : IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, IECore.FloatData( 0 ) ), - } - ) - - r.attributeEnd() - - r.concatTransform( imath.M44f().translate( imath.V3f( -1, 0, 0 ) ) ) - r.sphere( - 1, -1, 1, 360, - { - "red" : IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, IECore.FloatData( 0 ) ), - "green" : IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, IECore.FloatData( 1 ) ), - "blue" : IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, IECore.FloatData( 0 ) ), - } - ) - - r.concatTransform( imath.M44f().translate( imath.V3f( 2, 0, 0 ) ) ) - r.sphere( - 1, -1, 1, 360, - { - "red" : IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, IECore.FloatData( 0 ) ), - "green" : IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, IECore.FloatData( 0 ) ), - "blue" : IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, IECore.FloatData( 1 ) ), - } - ) - - r.worldEnd() - - i = IECore.Reader.create( os.path.join( os.path.dirname( __file__ ), "output", "testPrimVars.tif" ) ).read() - dimensions = i.dataWindow.size() + imath.V2i( 1 ) - index = dimensions.x * int(dimensions.y * 0.5) - self.assertAlmostEqual( i["R"][index], 0, 6 ) - self.assertAlmostEqual( i["G"][index], 1, 6 ) - self.assertAlmostEqual( i["B"][index], 0, 6 ) - - index = dimensions.x * int(dimensions.y * 0.5) + int(dimensions.x * 0.5) - self.assertAlmostEqual( i["R"][index], 1, 6 ) - self.assertAlmostEqual( i["G"][index], 0, 6 ) - self.assertAlmostEqual( i["B"][index], 0, 6 ) - - index = dimensions.x * int(dimensions.y * 0.5) + int(dimensions.x * 1) - 1 - self.assertAlmostEqual( i["R"][index], 0, 6 ) - self.assertAlmostEqual( i["G"][index], 0, 6 ) - self.assertAlmostEqual( i["B"][index], 1, 6 ) - - ## \todo Make this assert something - def testShader( self ) : - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - r.setOption( "gl:searchPath:shader", IECore.StringData( os.path.join( os.path.dirname( __file__ ), "shaders" ) ) ) - r.setOption( "gl:searchPath:shaderInclude", IECore.StringData( os.path.join( os.path.dirname( __file__ ), "shaders", "include" ) ) ) - - r.worldBegin() - r.shader( "surface", "color", { "colorValue" : IECore.Color3fData( imath.Color3f( 1, 0, 0 ) ) } ) - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -5 ) ) ) - r.sphere( 1, -1, 1, 360, {} ) - r.worldEnd() - - s = r.scene() - - s.render( IECoreGL.State( True ) ) - - def __countChildrenRecursive( self, g ) : - if not isinstance( g, IECoreGL.Group ): - return 1 - count = 0 - for c in g.children(): - count += self.__countChildrenRecursive( c ) - return count - - def testEdits( self ): - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - - r.worldBegin() - r.worldEnd() - - with IECore.CapturingMessageHandler() as handler : - - r.attributeBegin() - r.setAttribute( "gl:color", IECore.Color4fData( imath.Color4f( 1, 2, 3, 4 ) ) ) - r.attributeEnd() - - self.assertEqual( len( handler.messages ), 3 ) - - with IECore.CapturingMessageHandler() as handler : - - r.command( "editBegin", {} ) - r.attributeBegin() - r.setAttribute( "gl:color", IECore.Color4fData( imath.Color4f( 1, 2, 3, 4 ) ) ) - r.attributeEnd() - r.command( "editEnd", {} ) - - self.assertEqual( len( handler.messages ), 0 ) - - def testRemoveObject( self ) : - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - with IECoreScene.WorldBlock( r ) : - - r.setAttribute( "name", "sphereOne" ) - - r.sphere( 1, -1, 1, 360, {} ) - - r.setAttribute( "name", "sphereTwo" ) - - r.sphere( 1, -1, 1, 360, {} ) - - with IECoreScene.AttributeBlock( r ) : - - r.sphere( 1, -1, 1, 360, {} ) - - r.setAttribute( "name", "sphereOne" ) - - r.sphere( 1, -1, 1, 360, {} ) - r.sphere( 1, -1, 1, 360, {} ) - r.sphere( 1, -1, 1, 360, {} ) - - s = r.scene() - self.assertEqual( len( s.root().children() ), 3 ) - - # check that trying to remove objects when not in an editBegin/editEnd block - # fails and prints a message - - errorCatcher = IECore.CapturingMessageHandler() - with errorCatcher : - commandResult = r.command( "removeObject", { "name" : IECore.StringData( "sphereOne" ) } ) - - self.assertEqual( commandResult, None ) - self.assertEqual( len( errorCatcher.messages ), 1 ) - - # check we can remove one object without affecting the other - - r.command( "editBegin", {} ) - commandResult = r.command( "removeObject", { "name" : IECore.StringData( "sphereOne" ) } ) - r.command( "editEnd", {} ) - - self.assertEqual( commandResult, IECore.BoolData( True ) ) - self.assertEqual( len( s.root().children() ), 2 ) - self.assertEqual( self.__countChildrenRecursive( s.root() ), 2 ) - - # now we test that either the sphere and the following attribute block ( instantiates as a Group ) are removed - r.command( "editBegin", {} ) - commandResult = r.command( "removeObject", { "name" : IECore.StringData( "sphereTwo" ) } ) - r.command( "editEnd", {} ) - - self.assertEqual( commandResult, IECore.BoolData( True ) ) - self.assertEqual( len( s.root().children() ), 0 ) - - def testEditQuery( self ) : - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - with IECoreScene.WorldBlock( r ) : - self.assertEqual( r.command( "editQuery", {} ), IECore.BoolData( False ) ) - - self.assertEqual( r.command( "editQuery", {} ), IECore.BoolData( False ) ) - r.command( "editBegin", {} ) - self.assertEqual( r.command( "editQuery", {} ), IECore.BoolData( True ) ) - r.command( "editEnd", {} ) - self.assertEqual( r.command( "editQuery", {} ), IECore.BoolData( False ) ) - - def testRemoveObjectDuringProcedural( self ) : - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - with IECoreScene.WorldBlock( r ) : - - r.setAttribute( "name", "sphereOne" ) - - r.sphere( 1, -1, 1, 360, {} ) - - r.setAttribute( "name", "sphereTwo" ) - - r.sphere( 1, -1, 1, 360, {} ) - - s = r.scene() - self.assertEqual( len( s.root().children() ), 2 ) - - class RemovalProcedural( IECoreScene.Renderer.Procedural ): - - def __init__( proc ): - IECoreScene.Renderer.Procedural.__init__( proc ) - - def bound( proc ) : - return imath.Box3f( imath.V3f( -1 ), imath.V3f( 1 ) ) - - def render( proc, renderer ): - commandResult = renderer.command( "removeObject", { "name" : IECore.StringData( "sphereOne" ) } ) - self.assertEqual( commandResult, IECore.BoolData( True ) ) - - def hash( self ): - h = IECore.MurmurHash() - return h - - r.command( "editBegin", {} ) - r.procedural( RemovalProcedural() ) - r.command( "editEnd", {} ) - - self.assertEqual( len( s.root().children() ), 1 ) - self.assertEqual( self.__countChildrenRecursive( r.scene().root() ), 1 ) - - def testRemoveObjectWithResourcesDuringProcedural( self ) : - - r = IECoreGL.Renderer() - r.setOption( "gl:searchPath:shader", IECore.StringData( os.path.join( os.path.dirname( __file__ ), "shaders" ) ) ) - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - with IECoreScene.WorldBlock( r ) : - - with IECoreScene.AttributeBlock( r ) : - - r.setAttribute( "name", "sphereOne" ) - - r.shader( "surface", "image", { - "texture" : IECore.SplinefColor3fData( - IECore.SplinefColor3f( - IECore.CubicBasisf.catmullRom(), - ( - ( 0, imath.Color3f( 1 ) ), - ( 0, imath.Color3f( 1 ) ), - ( 1, imath.Color3f( 0 ) ), - ( 1, imath.Color3f( 0 ) ), - ), - ), - ), - } ) - - r.sphere( 1, -1, 1, 360, {} ) - - s = r.scene() - self.assertEqual( len( s.root().children()[0].children() ), 1 ) - - s.render() - - class RemovalProcedural( IECoreScene.Renderer.Procedural ): - - def __init__( proc, level=0 ) : - - IECoreScene.Renderer.Procedural.__init__( proc ) - - def bound( proc ) : - - return imath.Box3f( imath.V3f( -1 ), imath.V3f( 1 ) ) - - def render( proc, renderer ): - - commandResult = renderer.command( "removeObject", { "name" : IECore.StringData( "sphereOne" ) } ) - self.assertEqual( commandResult, IECore.BoolData( True ) ) - - def hash( self ): - - h = IECore.MurmurHash() - return h - - r.command( "editBegin", {} ) - - # typically you wouldn't call a renderer method on a separate thread like this. we're just - # doing it here to force the procedural onto a different thread. if left to its own devices - # the renderer will run procedurals on different threads, but it equally well might call - # them on the main thread. we force the procedural onto a separate thread so we can reliably - # exercise a problem we're trying to address. - t = threading.Thread( target=IECore.curry( r.procedural, RemovalProcedural() ) ) - t.start() - t.join() - - # if an edit session removes objects which use gl resources (shaders, textures etc), - # then it's essential that the editEnd call occurs on the thread with the correct gl context. - # this is so the gl resources can be deleted in the correct context. - r.command( "editEnd", {} ) - - self.assertEqual( len( s.root().children() ), 0 ) - - def testParallelRenders( self ): - - allScenes = [] - - def threadedRendering(): - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - r.setOption( "gl:searchPath:shader", IECore.StringData( os.path.join( os.path.dirname( __file__ ), "shaders" ) ) ) - r.setOption( "gl:searchPath:shaderInclude", IECore.StringData( os.path.join( os.path.dirname( __file__ ), "shaders", "include" ) ) ) - - r.worldBegin() - r.shader( "surface", "failWithoutPreprocessing", {} ) - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -5 ) ) ) - r.worldEnd() - allScenes.append( r.scene() ) - - for i in range( 0, 100 ): - newThread = threading.Thread(target=threadedRendering) - newThread.start() - - while len(allScenes) < 100 : - pass - - for s in allScenes : - s.render( IECoreGL.State( True ) ) - - class RecursiveProcedural( IECoreScene.Renderer.Procedural ): - """Creates a pyramid of spheres""" - - maxLevel = 5 - threadsUsed = set() - - def __init__( self, level = 0 ): - IECoreScene.Renderer.Procedural.__init__( self ) - self.__level = level - if level == 0 : - self.threadsUsed.clear() - - def bound( self ) : - return imath.Box3f( imath.V3f( -1 ), imath.V3f( 1 ) ) - - def render( self, renderer ): - # registers this thread id - self.threadsUsed.add( threading.currentThread().getName() ) - renderer.attributeBegin() - renderer.setAttribute( "color", IECore.Color3fData( imath.Color3f( float(self.__level)/self.maxLevel, 0, 1 - float(self.__level)/self.maxLevel ) ) ) - renderer.transformBegin() - renderer.concatTransform( imath.M44f().translate(imath.V3f( 0, 0.5, 0 )) ) - renderer.concatTransform( imath.M44f().scale( imath.V3f(0.5) ) ) - renderer.sphere( 1, -1, 1, 360, {} ) - renderer.transformEnd() - # end of recursion - if self.__level < self.maxLevel : - renderer.transformBegin() - renderer.concatTransform( imath.M44f().translate(imath.V3f( 0, -0.5, 0 )) ) - for i in range( 0, 2 ) : - renderer.transformBegin() - renderer.concatTransform( imath.M44f().translate(imath.V3f( (i - 0.5) , 0, 0)) ) - renderer.concatTransform( imath.M44f().scale( imath.V3f(0.5) ) ) - proc = TestRenderer.RecursiveProcedural( self.__level + 1 ) - renderer.procedural( proc ) - renderer.transformEnd() - renderer.transformEnd() - renderer.attributeEnd() - - def hash( self ): - - h = IECore.MurmurHash() - return h - - def testMultithreadedProcedural( self ): - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - r.setOption( "gl:searchPath:shader", IECore.StringData( os.path.join( os.path.dirname( __file__ ), "shaders" ) ) ) - r.setOption( "gl:searchPath:shaderInclude", IECore.StringData( os.path.join( os.path.dirname( __file__ ), "shaders", "include" ) ) ) - r.worldBegin() - p = self.RecursiveProcedural() - r.procedural( p ) - r.worldEnd() - - self.assertTrue( len(self.RecursiveProcedural.threadsUsed) > 1 ) - - def testParallelMultithreadedProcedurals( self ): - - renders = [] - - def newRender(): - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - r.setOption( "gl:searchPath:shader", IECore.StringData( os.path.join( os.path.dirname( __file__ ), "shaders" ) ) ) - r.setOption( "gl:searchPath:shaderInclude", IECore.StringData( os.path.join( os.path.dirname( __file__ ), "shaders", "include" ) ) ) - r.worldBegin() - p = self.RecursiveProcedural() - r.procedural( p ) - r.worldEnd() - renders.append( 0 ) - - threads = [] - for i in range( 0,10 ): - newThread = threading.Thread(target=newRender) - newThread.start() - threads.append( newThread ) - - for t in threads : - t.join() - - def testDisableProceduralThreading( self ): - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - r.setOption( "gl:searchPath:shader", IECore.StringData( os.path.join( os.path.dirname( __file__ ), "shaders" ) ) ) - r.setOption( "gl:searchPath:shaderInclude", IECore.StringData( os.path.join( os.path.dirname( __file__ ), "shaders", "include" ) ) ) - with IECoreScene.WorldBlock( r ) : - r.setAttribute( "gl:procedural:reentrant", IECore.BoolData( False ) ) - p = self.RecursiveProcedural() - r.procedural( p ) - - self.assertEqual( len( self.RecursiveProcedural.threadsUsed ), 1 ) - - def testObjectSpaceCulling( self ): - - p = self.RecursiveProcedural() - - def renderWithCulling( box ): - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - r.worldBegin() - r.sphere( 1.5, 0, 1, 360, {} ) - r.procedural( p ) - r.attributeBegin() - if True: - r.setAttribute( "gl:cullingSpace", IECore.StringData( "object" ) ) - r.setAttribute( "gl:cullingBox", IECore.Box3fData( box ) ) - # everything in this block is culled - r.sphere( 1.5, 0, 1, 360, {} ) - r.procedural( p ) - r.attributeEnd() - r.worldEnd() - return self.__countChildrenRecursive( r.scene().root() ) - - noCullingCounter = renderWithCulling( imath.Box3f() ) - - # verify that only half of the things are renderer when the giving culling box is defined. - self.assertEqual( renderWithCulling( imath.Box3f( imath.V3f(2,-1,-1), imath.V3f(3,1,1) ) ) * 2, noCullingCounter ) - - def testWorldSpaceCulling( self ): - - p = self.RecursiveProcedural() - box = imath.Box3f( imath.V3f(0.001,-1,-1), imath.V3f(1,1,1) ) - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - r.worldBegin() - r.setAttribute( "gl:cullingSpace", IECore.StringData( "world" ) ) - r.setAttribute( "gl:cullingBox", IECore.Box3fData( box ) ) - r.sphere( 1, 0, 1, 360, {} ) # half-inside : 1 element - r.procedural( p ) # half-inside: 32 elements (full procedural renders 63 elements) - r.transformBegin() - if True: - r.concatTransform( imath.M44f().translate( imath.V3f(-2, 0, 0) ) ) - # everything in this block is culled - r.sphere( 1, 0, 1, 360, {} ) - r.procedural( p ) - r.transformEnd() - r.worldEnd() - self.assertEqual( self.__countChildrenRecursive( r.scene().root() ), 33 ) - - def testTransformsInImmediateRenderer( self ): - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - r.transformBegin() - r.concatTransform( imath.M44f().rotate( imath.V3f( 1, 1, 1 ) ) ) - r.camera( "main", { "resolution" : IECore.V2iData( imath.V2i( 512 ) ), "projection" : IECore.StringData( "perspective" ) } ) - r.transformEnd() - r.worldBegin() - # confirm that the camera transformation is not affecting the world space matrix - r.concatTransform( imath.M44f().translate( imath.V3f( 1, 0, 0 ) ) ) - self.assertTrue( r.getTransform().equalWithAbsError( imath.M44f().translate( imath.V3f( 1, 0, 0 ) ), 1e-4 ) ) - # confirm that setting the world space transform does not affect the camera matrix (that was already set in openGL ) - r.setTransform( imath.M44f().translate( imath.V3f( 0, 1, 0 ) ) ) - self.assertTrue( r.getTransform().equalWithAbsError( imath.M44f().translate( imath.V3f( 0, 1, 0 ) ), 1e-4 ) ) - r.worldEnd() - - def testTransformsInDeferredRenderer( self ): - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - r.transformBegin() - r.concatTransform( imath.M44f().rotate( imath.V3f( 1, 1, 1 ) ) ) - r.camera( "main", { "resolution" : IECore.V2iData( imath.V2i( 512 ) ), "projection" : IECore.StringData( "perspective" ) } ) - r.transformEnd() - r.worldBegin() - # confirm that the camera transformation is not affecting the world space matrix - self.assertTrue( r.getTransform().equalWithAbsError( imath.M44f(), 1e-4 ) ) - r.concatTransform( imath.M44f().translate( imath.V3f( 1, 0, 0 ) ) ) - r.concatTransform( imath.M44f().rotate( imath.V3f( 1, 1, 1 ) ) ) - m = r.getTransform() - r.transformBegin() - if True: - # confirm that the transformBegin did not change the current transform - self.assertTrue( r.getTransform().equalWithAbsError( m, 1e-4 ) ) - # confirm that concatenate transform works - r.concatTransform( imath.M44f().translate( imath.V3f( 1, 0, 0 ) ) ) - self.assertTrue( r.getTransform().equalWithAbsError( imath.M44f().translate( imath.V3f( 1, 0, 0 ) ) * m, 1e-4 ) ) - r.concatTransform( imath.M44f().scale( imath.V3f(0.5) ) ) - self.assertTrue( r.getTransform().equalWithAbsError( imath.M44f().scale( imath.V3f(0.5) ) * imath.M44f().translate( imath.V3f( 1, 0, 0 ) ) * m, 1e-4 ) ) - - # confirm that setting the world space transform works too - m2 = imath.M44f().translate( imath.V3f( 0, 1, 0 ) ) - r.setTransform( m2 ) - self.assertTrue( r.getTransform().equalWithAbsError( m2, 1e-4 ) ) - - r.attributeBegin() - if True: - # confirm that the attributeBegin did not change the current transform - self.assertTrue( r.getTransform().equalWithAbsError( m2, 1e-4 ) ) - # confirm that setting the world space transform works too - r.setTransform( imath.M44f().rotate( imath.V3f( 3, 1, 0 ) ) ) - self.assertTrue( r.getTransform().equalWithAbsError( imath.M44f().rotate( imath.V3f( 3, 1, 0 ) ), 1e-4 ) ) - r.attributeEnd() - # confirms that attributeEnd recovers the matrix. - self.assertTrue( r.getTransform().equalWithAbsError( m2, 1e-4 ) ) - - r.transformEnd() - # confirms that transformEnd recovers the matrix. - self.assertTrue( r.getTransform().equalWithAbsError( m, 1e-4 ) ) - - r.worldEnd() - - def testInstances(self): - - r = IECoreGL.Renderer() - r.instanceBegin( "instanceA", {} ) - r.concatTransform( imath.M44f().translate( imath.V3f( 1, 0, 0 ) ) ) - r.transformBegin() - r.concatTransform( imath.M44f().translate( imath.V3f( 1, 0, 0 ) ) ) - r.sphere( 1, -1, 1, 360, {} ) - r.concatTransform( imath.M44f().translate( imath.V3f( 1, 0, 0 ) ) ) - r.sphere( 1, -1, 1, 360, {} ) - r.transformEnd() - r.concatTransform( imath.M44f().translate( imath.V3f( -1, 0, 0 ) ) ) - r.sphere( 1, -1, 1, 360, {} ) - r.instanceEnd() - - r.instanceBegin( "instanceB", {} ) - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, 10 ) ) ) - r.instance( "instanceA" ) - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, 20 ) ) ) - r.instance( "instanceA" ) - r.instanceEnd() - - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - r.worldBegin() - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 5, 0 ) ) ) - r.instance( "instanceB" ) - r.setTransform( imath.M44f().translate( imath.V3f( 0, 10, 0 ) ) ) - r.instance( "instanceB" ) - r.worldEnd() - - g = r.scene().root() - - self.assertEqual( self.__countChildrenRecursive( g ), 12 ) - self.assertTrue( g.bound().min().equalWithAbsError( imath.V3f( -1, 4, 9 ), 0.001 ) ) - self.assertTrue( g.bound().max().equalWithAbsError( imath.V3f( 4, 11, 31 ), 0.001 ) ) - - def testCuriousCrashOnThreadedProceduralsAndAttribute( self ): - - myMesh = IECore.Reader.create( os.path.join( "test", "IECore", "data", "cobFiles", "pSphereShape1.cob" ) ).read() - - class MyProc( IECoreScene.Renderer.Procedural ): - def __init__( self, level = 0 ): - IECoreScene.Renderer.Procedural.__init__( self ) - self.__level = level - def bound( self ) : - return imath.Box3f( imath.V3f( -1 ), imath.V3f( 1 ) ) - def render( self, renderer ): - if self.__level < 2 : - for i in range( 0, 50 ) : - renderer.procedural( MyProc( self.__level + 1 ) ) - else: - g = IECoreScene.Group() - g.addChild( myMesh ) - g.addState( IECoreScene.AttributeState( { "name" : IECore.StringData( str(self.__level) ) } ) ) - g.render( renderer ) - - def hash( self ): - h = IECore.MurmurHash() - return h - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - r.worldBegin() - p = MyProc() - r.procedural( p ) - r.worldEnd() - - def testDepthTest( self ) : - - def doTest( depthTest, r, g, b ) : - - renderer = IECoreGL.Renderer() - renderer.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - renderer.setOption( "gl:searchPath:shader", IECore.StringData( os.path.join( os.path.dirname( __file__ ), "shaders" ) ) ) - - renderer.camera( "main", { - "projection" : IECore.StringData( "orthographic" ), - "resolution" : IECore.V2iData( imath.V2i( 256 ) ), - "clippingPlanes" : IECore.V2fData( imath.V2f( 1, 1000 ) ), - "screenWindow" : IECore.Box2fData( imath.Box2f( imath.V2f( -1 ), imath.V2f( 1 ) ) ) - } - ) - renderer.display( os.path.join( os.path.dirname( __file__ ), "output", "depthTest.tif" ), "tif", "rgba", {} ) - - m = IECoreScene.MeshPrimitive.createPlane( imath.Box2f( imath.V2f( -1 ), imath.V2f( 1 ) ) ) - - with IECoreScene.WorldBlock( renderer ) : - - renderer.setAttribute( "gl:depthTest", IECore.BoolData( depthTest ) ) - - renderer.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -1 ) ) ) - renderer.shader( "surface", "color", { "colorValue" : IECore.Color3fData( imath.Color3f( 1, 0, 0 ) ) } ) - m.render( renderer ) - - renderer.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -1 ) ) ) - renderer.shader( "surface", "color", { "colorValue" : IECore.Color3fData( imath.Color3f( 0, 1, 0 ) ) } ) - m.render( renderer ) - - i = IECore.Reader.create( os.path.join( os.path.dirname( __file__ ), "output", "depthTest.tif" ) ).read() - for p in i["R"] : - self.assertAlmostEqual( p, r, 6 ) - for p in i["G"] : - self.assertAlmostEqual( p, g, 6 ) - for p in i["B"] : - self.assertAlmostEqual( p, b, 6 ) - - doTest( True, 1, 0, 0 ) - doTest( False, 0, 1, 0 ) - - def testCameraVisibility( self ) : - - def doRender( mode, visibility ) : - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( mode ) ) - r.setOption( "gl:searchPath:shaderInclude", IECore.StringData( os.path.join( ".", "glsl" ) ) ) - - r.camera( "main", { - "projection" : IECore.StringData( "perspective" ), - "projection:fov" : IECore.FloatData( 20 ), - "resolution" : IECore.V2iData( imath.V2i( 256 ) ), - "clippingPlanes" : IECore.V2fData( imath.V2f( 1, 1000 ) ), - "screenWindow" : IECore.Box2fData( imath.Box2f( imath.V2f( -3 ), imath.V2f( 3 ) ) ) - } - ) - if mode=="immediate" : - r.display( os.path.join( os.path.dirname( __file__ ), "output", "testCameraVisibility.tif" ), "tif", "rgba", {} ) - - with IECoreScene.WorldBlock( r ) : - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -5 ) ) ) - - r.setAttribute( "gl:visibility:camera", IECore.BoolData( visibility ) ) - r.points( 1, { "P" : IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.V3fVectorData( [ imath.V3f( 0 ) ] ) ) } ) - - return r - - # test immediate renderer by checking images - - doRender( "immediate", True ) - i = IECore.Reader.create( os.path.join( os.path.dirname( __file__ ), "output", "testCameraVisibility.tif" ) ).read() - self.assertTrue( i["A"][256 * 128 + 128] > .99 ) - - doRender( "immediate", False ) - i = IECore.Reader.create( os.path.join( os.path.dirname( __file__ ), "output", "testCameraVisibility.tif" ) ).read() - self.assertEqual( i["A"], IECore.FloatVectorData( [ 0 ] * 256 * 256 ) ) - - # test deferred renderer by checking scene - - r = doRender( "deferred", True ) - self.assertEqual( len( r.scene().root().children()[0].children() ), 1 ) - - r = doRender( "deferred", False ) - self.assertEqual( len( r.scene().root().children() ), 0 ) - - def testWarningMessages( self ): - r = IECoreGL.Renderer() - - r.setOption( "gl:searchPath:shader", IECore.StringData( os.path.join( os.path.dirname( __file__ ), "shaders" ) ) ) - - # gl renderer only supports "surface" shaders, so it should complain about this: - c = IECore.CapturingMessageHandler() - with c : - with IECoreScene.WorldBlock( r ): - r.shader( "shader", "color", { "colorValue" : IECore.Color3fData( imath.Color3f( 1, 0, 0 ) ) } ) - - self.assertEqual( len( c.messages ), 1 ) - self.assertEqual( c.messages[0].level, IECore.Msg.Level.Warning ) - - # it should just ignore this, because of the "ri:" prefix: - c = IECore.CapturingMessageHandler() - with c : - with IECoreScene.WorldBlock( r ): - r.shader( "ri:shader", "color", { "colorValue" : IECore.Color3fData( imath.Color3f( 1, 0, 0 ) ) } ) - - self.assertEqual( len( c.messages ), 0 ) - - # this should work fine: - c = IECore.CapturingMessageHandler() - with c : - with IECoreScene.WorldBlock( r ): - r.shader( "gl:surface", "color", { "colorValue" : IECore.Color3fData( imath.Color3f( 1, 0, 0 ) ) } ) - - self.assertEqual( len( c.messages ), 0 ) - - - # it should just ignore this, because of the "lg:" prefix: - c = IECore.CapturingMessageHandler() - with c : - with IECoreScene.WorldBlock( r ): - r.shader( "lg:shader", "color", { "colorValue" : IECore.Color3fData( imath.Color3f( 1, 0, 0 ) ) } ) - - self.assertEqual( len( c.messages ), 0 ) - - # this aint right!: - c = IECore.CapturingMessageHandler() - with c : - with IECoreScene.WorldBlock( r ): - r.shader( "gl:nonsense", "color", { "colorValue" : IECore.Color3fData( imath.Color3f( 1, 0, 0 ) ) } ) - - self.assertEqual( len( c.messages ), 1 ) - self.assertEqual( c.messages[0].level, IECore.Msg.Level.Warning ) - - def setUp( self ) : - - if not os.path.isdir( os.path.join( "test", "IECoreGL", "output" ) ) : - os.makedirs( os.path.join( "test", "IECoreGL", "output" ) ) - - def tearDown( self ) : - - if os.path.isdir( os.path.join( "test", "IECoreGL", "output" ) ) : - shutil.rmtree( os.path.join( "test", "IECoreGL", "output" ) ) - -if __name__ == "__main__": - unittest.main() diff --git a/test/IECoreGL/Selection.py b/test/IECoreGL/Selection.py deleted file mode 100644 index 095912df68..0000000000 --- a/test/IECoreGL/Selection.py +++ /dev/null @@ -1,512 +0,0 @@ -########################################################################## -# -# Copyright (c) 2008-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 Image Engine Design 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 inspect -import os.path -import imath - -import IECore -import IECoreScene - -import IECoreGL -IECoreGL.init( False ) - -class TestSelection( unittest.TestCase ) : - - def testSelect( self ) : - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - r.setOption( "gl:searchPath:shader", IECore.StringData( os.path.join( os.path.dirname( __file__ ), "shaders" ) ) ) - - with IECoreScene.WorldBlock( r ) : - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -5 ) ) ) - - r.setAttribute( "name", IECore.StringData( "one" ) ) - r.shader( "surface", "color", { "colorValue" : IECore.Color3fData( imath.Color3f( 1, 0, 0 ) ) } ) - r.sphere( 1, -1, 1, 360, {} ) - - r.concatTransform( imath.M44f().translate( imath.V3f( -1, 0, 0 ) ) ) - r.setAttribute( "name", IECore.StringData( "two" ) ) - r.sphere( 1, -1, 1, 360, {} ) - - r.concatTransform( imath.M44f().translate( imath.V3f( 2, 0, 0 ) ) ) - r.setAttribute( "name", IECore.StringData( "three" ) ) - r.sphere( 1, -1, 1, 360, {} ) - - s = r.scene() - s.setCamera( IECoreGL.Camera( imath.M44f(), False ) ) - - ss = s.select( IECoreGL.Selector.Mode.GLSelect, imath.Box2f( imath.V2f( 0 ), imath.V2f( 1 ) ) ) - names = [ IECoreGL.NameStateComponent.nameFromGLName( x.name ) for x in ss ] - self.assertEqual( len( names ), 3 ) - self.assertTrue( "one" in names ) - self.assertTrue( "two" in names ) - self.assertTrue( "three" in names ) - - def testRegionSelect( self ) : - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - r.setOption( "gl:searchPath:shader", IECore.StringData( os.path.join( os.path.dirname( __file__ ), "shaders" ) ) ) - - with IECoreScene.WorldBlock( r ) : - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -5 ) ) ) - - r.shader( "surface", "color", { "colorValue" : IECore.Color3fData( imath.Color3f( 1, 0, 0 ) ) } ) - r.concatTransform( imath.M44f().translate( imath.V3f( -2, -2, 0 ) ) ) - r.setAttribute( "name", IECore.StringData( "red" ) ) - r.sphere( 1, -1, 1, 360, {} ) - - r.shader( "surface", "color", { "colorValue" : IECore.Color3fData( imath.Color3f( 0, 1, 0 ) ) } ) - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 4, 0 ) ) ) - r.setAttribute( "name", IECore.StringData( "green" ) ) - r.sphere( 1, -1, 1, 360, {} ) - - r.shader( "surface", "color", { "colorValue" : IECore.Color3fData( imath.Color3f( 0, 0, 1 ) ) } ) - r.concatTransform( imath.M44f().translate( imath.V3f( 4, 0, 0 ) ) ) - r.setAttribute( "name", IECore.StringData( "blue" ) ) - r.sphere( 1, -1, 1, 360, {} ) - - r.shader( "surface", "color", { "colorValue" : IECore.Color3fData( imath.Color3f( 1, 1, 1 ) ) } ) - r.concatTransform( imath.M44f().translate( imath.V3f( 0, -4, 0 ) ) ) - r.setAttribute( "name", IECore.StringData( "white" ) ) - r.sphere( 1, -1, 1, 360, {} ) - - s = r.scene() - s.setCamera( IECoreGL.Camera( imath.M44f(), False ) ) - - ss = s.select( IECoreGL.Selector.Mode.GLSelect, imath.Box2f( imath.V2f( 0, 0.5 ), imath.V2f( 0.5, 1 ) ) ) - self.assertEqual( len( ss ), 1 ) - self.assertEqual( IECoreGL.NameStateComponent.nameFromGLName( ss[0].name ), "red" ) - - ss = s.select( IECoreGL.Selector.Mode.GLSelect, imath.Box2f( imath.V2f( 0 ), imath.V2f( 0.5 ) ) ) - self.assertEqual( len( ss ), 1 ) - self.assertEqual( IECoreGL.NameStateComponent.nameFromGLName( ss[0].name ), "green" ) - - ss = s.select( IECoreGL.Selector.Mode.GLSelect, imath.Box2f( imath.V2f( 0.5, 0 ), imath.V2f( 1, 0.5 ) ) ) - self.assertEqual( len( ss ), 1 ) - self.assertEqual( IECoreGL.NameStateComponent.nameFromGLName( ss[0].name ), "blue" ) - - ss = s.select( IECoreGL.Selector.Mode.GLSelect, imath.Box2f( imath.V2f( 0.5 ), imath.V2f( 1 ) ) ) - self.assertEqual( len( ss ), 1 ) - self.assertEqual( IECoreGL.NameStateComponent.nameFromGLName( ss[0].name ), "white" ) - - def testIDSelect( self ) : - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - - with IECoreScene.WorldBlock( r ) : - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -5 ) ) ) - - r.concatTransform( imath.M44f().translate( imath.V3f( -1, 0, 0 ) ) ) - r.setAttribute( "name", IECore.StringData( "frontLeft" ) ) - r.sphere( 1, -1, 1, 360, {} ) - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -1 ) ) ) - r.setAttribute( "name", IECore.StringData( "backLeft" ) ) - r.sphere( 1, -1, 1, 360, {} ) - - r.concatTransform( imath.M44f().translate( imath.V3f( 2, 0, 1 ) ) ) - r.setAttribute( "name", IECore.StringData( "frontRight" ) ) - r.sphere( 1, -1, 1, 360, {} ) - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -1 ) ) ) - r.setAttribute( "name", IECore.StringData( "backRight" ) ) - r.sphere( 1, -1, 1, 360, {} ) - - s = r.scene() - s.setCamera( IECoreGL.Camera() ) - - ss = s.select( IECoreGL.Selector.Mode.IDRender, imath.Box2f( imath.V2f( 0.25, 0.5 ), imath.V2f( 0.26, 0.51 ) ) ) - self.assertEqual( len( ss ), 1 ) - self.assertEqual( IECoreGL.NameStateComponent.nameFromGLName( ss[0].name ), "frontLeft" ) - - ss = s.select( IECoreGL.Selector.Mode.IDRender, imath.Box2f( imath.V2f( 0.75, 0.5 ), imath.V2f( 0.76, 0.51 ) ) ) - self.assertEqual( len( ss ), 1 ) - self.assertEqual( IECoreGL.NameStateComponent.nameFromGLName( ss[0].name ), "frontRight" ) - - def testIDSelectDepths( self ) : - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - - with IECoreScene.WorldBlock( r ) : - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -5 ) ) ) - - r.setAttribute( "name", IECore.StringData( "ball" ) ) - r.sphere( 1, -1, 1, 360, {} ) - - scene = r.scene() - scene.setCamera( IECoreGL.Camera() ) - - s1 = scene.select( IECoreGL.Selector.Mode.GLSelect, imath.Box2f( imath.V2f( 0 ), imath.V2f( 1 ) ) ) - self.assertEqual( len( s1 ), 1 ) - self.assertEqual( IECoreGL.NameStateComponent.nameFromGLName( s1[0].name ), "ball" ) - - s2 = scene.select( IECoreGL.Selector.Mode.IDRender, imath.Box2f( imath.V2f( 0 ), imath.V2f( 1 ) ) ) - self.assertEqual( len( s2 ), 1 ) - self.assertEqual( IECoreGL.NameStateComponent.nameFromGLName( s2[0].name ), "ball" ) - - self.assertAlmostEqual( s1[0].depthMin, s2[0].depthMin, 5 ) - - def testOcclusionQuerySelect( self ) : - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - - with IECoreScene.WorldBlock( r ) : - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -5 ) ) ) - - r.concatTransform( imath.M44f().translate( imath.V3f( -1, 0, 0 ) ) ) - r.setAttribute( "name", IECore.StringData( "frontLeft" ) ) - r.sphere( 1, -1, 1, 360, {} ) - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -1 ) ) ) - r.setAttribute( "name", IECore.StringData( "backLeft" ) ) - r.sphere( 1, -1, 1, 360, {} ) - - r.concatTransform( imath.M44f().translate( imath.V3f( 2, 0, 1 ) ) ) - r.setAttribute( "name", IECore.StringData( "frontRight" ) ) - r.sphere( 1, -1, 1, 360, {} ) - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -1 ) ) ) - r.setAttribute( "name", IECore.StringData( "backRight" ) ) - r.sphere( 1, -1, 1, 360, {} ) - - s = r.scene() - s.setCamera( IECoreGL.Camera() ) - - ss = s.select( IECoreGL.Selector.Mode.OcclusionQuery, imath.Box2f( imath.V2f( 0, 0 ), imath.V2f( 0.25, 1 ) ) ) - self.assertEqual( len( ss ), 2 ) - self.assertEqual( set( [ IECoreGL.NameStateComponent.nameFromGLName( x.name ) for x in ss ] ), set( ( "frontLeft", "backLeft" ) ) ) - - ss = s.select( IECoreGL.Selector.Mode.OcclusionQuery, imath.Box2f( imath.V2f( 0.75, 0 ), imath.V2f( 1, 1 ) ) ) - self.assertEqual( len( ss ), 2 ) - self.assertEqual( set( [ IECoreGL.NameStateComponent.nameFromGLName( x.name ) for x in ss ] ), set( ( "frontRight", "backRight" ) ) ) - - def testIDSelectWithAdditionalDisplayStyles( self ) : - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - - with IECoreScene.WorldBlock( r ) : - - r.setAttribute( "gl:primitive:wireframe", IECore.BoolData( True ) ) - r.setAttribute( "gl:primitive:bound", IECore.BoolData( True ) ) - r.setAttribute( "gl:primitive:outline", IECore.BoolData( True ) ) - r.setAttribute( "gl:primitive:points", IECore.BoolData( True ) ) - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -5 ) ) ) - - r.concatTransform( imath.M44f().translate( imath.V3f( -1, 0, 0 ) ) ) - r.setAttribute( "name", IECore.StringData( "frontLeft" ) ) - r.sphere( 1, -1, 1, 360, {} ) - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -1 ) ) ) - r.setAttribute( "name", IECore.StringData( "backLeft" ) ) - r.sphere( 1, -1, 1, 360, {} ) - - r.concatTransform( imath.M44f().translate( imath.V3f( 2, 0, 1 ) ) ) - r.setAttribute( "name", IECore.StringData( "frontRight" ) ) - r.sphere( 1, -1, 1, 360, {} ) - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -1 ) ) ) - r.setAttribute( "name", IECore.StringData( "backRight" ) ) - r.sphere( 1, -1, 1, 360, {} ) - - s = r.scene() - s.setCamera( IECoreGL.Camera() ) - - ss = s.select( IECoreGL.Selector.Mode.IDRender, imath.Box2f( imath.V2f( 0.25, 0.5 ), imath.V2f( 0.26, 0.51 ) ) ) - self.assertEqual( len( ss ), 1 ) - self.assertEqual( IECoreGL.NameStateComponent.nameFromGLName( ss[0].name ), "frontLeft" ) - - ss = s.select( IECoreGL.Selector.Mode.IDRender, imath.Box2f( imath.V2f( 0.75, 0.5 ), imath.V2f( 0.76, 0.51 ) ) ) - self.assertEqual( len( ss ), 1 ) - self.assertEqual( IECoreGL.NameStateComponent.nameFromGLName( ss[0].name ), "frontRight" ) - - def testPointsPrimitiveSelect( self ) : - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - r.setOption( "gl:searchPath:shader", IECore.StringData( os.path.join( os.path.dirname( __file__ ), "shaders" ) ) ) - - with IECoreScene.WorldBlock( r ) : - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -5 ) ) ) - - r.setAttribute( "name", IECore.StringData( "pointsNeedSelectingToo" ) ) - r.points( 1, { "P" : IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.V3fVectorData( [ imath.V3f( 0 ) ] ) ) } ) - - s = r.scene() - s.setCamera( IECoreGL.Camera( imath.M44f(), False ) ) - - for mode in ( IECoreGL.Selector.Mode.GLSelect, IECoreGL.Selector.Mode.OcclusionQuery, IECoreGL.Selector.Mode.IDRender ) : - ss = s.select( mode, imath.Box2f( imath.V2f( 0 ), imath.V2f( 1 ) ) ) - names = [ IECoreGL.NameStateComponent.nameFromGLName( x.name ) for x in ss ] - self.assertEqual( len( names ), 1 ) - self.assertEqual( names[0], "pointsNeedSelectingToo" ) - - def testCurvesPrimitiveSelect( self ) : - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - r.setOption( "gl:searchPath:shader", IECore.StringData( os.path.join( os.path.dirname( __file__ ), "shaders" ) ) ) - - with IECoreScene.WorldBlock( r ) : - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -5 ) ) ) - - r.setAttribute( "name", IECore.StringData( "curvesNeedSelectingToo" ) ) - - r.curves( - IECore.CubicBasisf.linear(), - False, - IECore.IntVectorData( [ 2 ] ), - { - "P" : IECoreScene.PrimitiveVariable( - IECoreScene.PrimitiveVariable.Interpolation.Vertex, - IECore.V3fVectorData( [ imath.V3f( -1, -1, 0, ), imath.V3f( 1, 1, 0 ) ] ) - ) - } - ) - - s = r.scene() - s.setCamera( IECoreGL.Camera( imath.M44f(), False ) ) - - for mode in ( IECoreGL.Selector.Mode.GLSelect, IECoreGL.Selector.Mode.OcclusionQuery, IECoreGL.Selector.Mode.IDRender ) : - ss = s.select( mode, imath.Box2f( imath.V2f( 0 ), imath.V2f( 1 ) ) ) - names = [ IECoreGL.NameStateComponent.nameFromGLName( x.name ) for x in ss ] - self.assertEqual( len( names ), 1 ) - self.assertEqual( names[0], "curvesNeedSelectingToo" ) - - def testCurvesPrimitiveSelectUsingLines( self ) : - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - r.setOption( "gl:searchPath:shader", IECore.StringData( os.path.join( os.path.dirname( __file__ ), "shaders" ) ) ) - - with IECoreScene.WorldBlock( r ) : - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -5 ) ) ) - - r.setAttribute( "name", IECore.StringData( "curvesNeedSelectingToo" ) ) - r.setAttribute( "gl:curvesPrimitive:useGLLines", IECore.BoolData( True ) ) - - r.curves( - IECore.CubicBasisf.linear(), - False, - IECore.IntVectorData( [ 2 ] ), - { - "P" : IECoreScene.PrimitiveVariable( - IECoreScene.PrimitiveVariable.Interpolation.Vertex, - IECore.V3fVectorData( [ imath.V3f( -1, -1, 0, ), imath.V3f( 1, 1, 0 ) ] ) - ) - } - ) - - s = r.scene() - s.setCamera( IECoreGL.Camera( imath.M44f(), False ) ) - - for mode in ( IECoreGL.Selector.Mode.GLSelect, IECoreGL.Selector.Mode.OcclusionQuery, IECoreGL.Selector.Mode.IDRender ) : - ss = s.select( mode, imath.Box2f( imath.V2f( 0 ), imath.V2f( 1 ) ) ) - names = [ IECoreGL.NameStateComponent.nameFromGLName( x.name ) for x in ss ] - self.assertEqual( len( names ), 1 ) - self.assertEqual( names[0], "curvesNeedSelectingToo" ) - - def testCurvesPrimitiveSelectUsingWireframeLines( self ) : - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - r.setOption( "gl:searchPath:shader", IECore.StringData( os.path.join( os.path.dirname( __file__ ), "shaders" ) ) ) - - with IECoreScene.WorldBlock( r ) : - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -5 ) ) ) - - r.setAttribute( "name", IECore.StringData( "curvesNeedSelectingToo" ) ) - r.setAttribute( "gl:curvesPrimitive:useGLLines", IECore.BoolData( True ) ) - r.setAttribute( "gl:primitive:wireframe", IECore.BoolData( True ) ) - r.setAttribute( "gl:primitive:solid", IECore.BoolData( False ) ) - - r.curves( - IECore.CubicBasisf.linear(), - False, - IECore.IntVectorData( [ 2 ] ), - { - "P" : IECoreScene.PrimitiveVariable( - IECoreScene.PrimitiveVariable.Interpolation.Vertex, - IECore.V3fVectorData( [ imath.V3f( -1, -1, 0, ), imath.V3f( 1, 1, 0 ) ] ) - ) - } - ) - - s = r.scene() - s.setCamera( IECoreGL.Camera( imath.M44f(), False ) ) - - for mode in ( IECoreGL.Selector.Mode.GLSelect, IECoreGL.Selector.Mode.OcclusionQuery, IECoreGL.Selector.Mode.IDRender ) : - ss = s.select( mode, imath.Box2f( imath.V2f( 0 ), imath.V2f( 1 ) ) ) - names = [ IECoreGL.NameStateComponent.nameFromGLName( x.name ) for x in ss ] - self.assertEqual( len( names ), 1 ) - self.assertEqual( names[0], "curvesNeedSelectingToo" ) - - def testContextManager( self ) : - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - r.setOption( "gl:searchPath:shader", IECore.StringData( os.path.join( os.path.dirname( __file__ ), "shaders" ) ) ) - - with IECoreScene.WorldBlock( r ) : - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -5 ) ) ) - - r.setAttribute( "name", IECore.StringData( "one" ) ) - r.shader( "surface", "color", { "colorValue" : IECore.Color3fData( imath.Color3f( 1, 0, 0 ) ) } ) - r.sphere( 1, -1, 1, 360, {} ) - - r.concatTransform( imath.M44f().translate( imath.V3f( -1, 0, 0 ) ) ) - r.setAttribute( "name", IECore.StringData( "two" ) ) - r.sphere( 1, -1, 1, 360, {} ) - - scene = r.scene() - scene.setCamera( None ) - - IECoreGL.Camera( imath.M44f(), False ).render( IECoreGL.State.defaultState() ) - - hits = [] - with IECoreGL.Selector( imath.Box2f( imath.V2f( 0 ), imath.V2f( 1 ) ), IECoreGL.Selector.Mode.IDRender, hits ) as selector : - IECoreGL.State.bindBaseState() - selector.baseState().bind() - scene.root().render( selector.baseState() ) - - names = [ IECoreGL.NameStateComponent.nameFromGLName( x.name ) for x in hits ] - self.assertEqual( len( names ), 2 ) - self.assertTrue( "one" in names ) - self.assertTrue( "two" in names ) - - def testSelectableFlag( self ) : - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - r.setOption( "gl:searchPath:shader", IECore.StringData( os.path.join( os.path.dirname( __file__ ), "shaders" ) ) ) - - with IECoreScene.WorldBlock( r ) : - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -5 ) ) ) - - r.setAttribute( "name", IECore.StringData( "selectableObj" ) ) - r.shader( "surface", "color", { "colorValue" : IECore.Color3fData( imath.Color3f( 1, 0, 0 ) ) } ) - r.sphere( 1, -1, 1, 360, {} ) - - r.concatTransform( imath.M44f().translate( imath.V3f( -1, 0, 0 ) ) ) - r.setAttribute( "name", IECore.StringData( "unselectableObj" ) ) - r.setAttribute( "gl:primitive:selectable", IECore.BoolData( False ) ) - - r.sphere( 1, -1, 1, 360, {} ) - - s = r.scene() - s.setCamera( IECoreGL.Camera( imath.M44f(), False ) ) - - for mode in ( IECoreGL.Selector.Mode.GLSelect, IECoreGL.Selector.Mode.OcclusionQuery, IECoreGL.Selector.Mode.IDRender ) : - ss = s.select( mode, imath.Box2f( imath.V2f( 0 ), imath.V2f( 1 ) ) ) - names = [ IECoreGL.NameStateComponent.nameFromGLName( x.name ) for x in ss ] - self.assertEqual( names, [ "selectableObj" ] ) - - def testIDSelectWithCustomVertexShader( self ) : - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - - with IECoreScene.WorldBlock( r ) : - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -5 ) ) ) - - # translate to the left with the transform stack - r.concatTransform( imath.M44f().translate( imath.V3f( -1, 0, 0 ) ) ) - - # but translate back to the right using a vertex shader - r.shader( - - "gl:surface", "test", { - - "gl:vertexSource" : inspect.cleandoc( """ - - #version 120 - #if __VERSION__ <= 120 - #define in attribute - #endif - - uniform vec3 offset; - - in vec3 vertexP; - void main() - { - vec3 translatedVertexP = vertexP + offset; - vec4 pCam = gl_ModelViewMatrix * vec4( translatedVertexP, 1 ); - gl_Position = gl_ProjectionMatrix * pCam; - } - - """ ), - - "offset" : imath.V3f( 2, 0, 0 ), - - } - - ) - - r.setAttribute( "name", IECore.StringData( "sphere" ) ) - r.sphere( 1, -1, 1, 360, {} ) - - s = r.scene() - s.setCamera( IECoreGL.Camera() ) - - # on the left should be nothing, because the vertex shader moved it over - ss = s.select( IECoreGL.Selector.Mode.IDRender, imath.Box2f( imath.V2f( 0.25, 0.5 ), imath.V2f( 0.26, 0.51 ) ) ) - self.assertEqual( len( ss ), 0 ) - - # and on the right we should find the sphere - ss = s.select( IECoreGL.Selector.Mode.IDRender, imath.Box2f( imath.V2f( 0.75, 0.5 ), imath.V2f( 0.76, 0.51 ) ) ) - self.assertEqual( len( ss ), 1 ) - self.assertEqual( IECoreGL.NameStateComponent.nameFromGLName( ss[0].name ), "sphere" ) - -if __name__ == "__main__": - unittest.main() diff --git a/test/IECoreGL/ShadingTest.py b/test/IECoreGL/ShadingTest.py deleted file mode 100644 index 9cffe9f290..0000000000 --- a/test/IECoreGL/ShadingTest.py +++ /dev/null @@ -1,1011 +0,0 @@ -########################################################################## -# -# Copyright (c) 2012-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 Image Engine Design 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 shutil -import inspect -import imath -import tempfile - -import IECore -import IECoreScene -import IECoreImage -import IECoreGL - -IECoreGL.init( False ) - -class ShadingTest( unittest.TestCase ) : - - __imageFileName = os.path.join( os.path.dirname( __file__ ), "output", "test.tif" ) - - def mesh( self ) : - - m = IECoreScene.MeshPrimitive.createPlane( imath.Box2f( imath.V2f( -0.1 ), imath.V2f( 0.1 ) ) ) - m["N"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, IECore.V3fVectorData( [ imath.V3f( 0, 0, 1 ) ] * 4 ) ) - return m - - def constantShader( self ) : - - s = IECoreScene.Shader( "test", "gl:surface" ) - - s.parameters["gl:fragmentSource"] = """ - #include "IECoreGL/FragmentShader.h" - - IECOREGL_FRAGMENTSHADER_IN vec3 fragmentCs; - - void main() - { - gl_FragColor = vec4( fragmentCs, 1.0 ); - } - """ - - return s - - def colorShader( self ) : - - s = IECoreScene.Shader( "test", "gl:surface" ) - - s.parameters["gl:fragmentSource"] = """ - - uniform bool rB; - - uniform float rF; - uniform int gI; - - uniform vec2 rgF; - uniform ivec2 rgI; - - uniform vec3 rgbF; - uniform ivec3 rgbI; - - void main() - { - gl_FragColor = vec4( - float( rB ) + rF + rgF.r + float( rgI.r ) + rgbF.r + float( rgbI.r ), - float( gI ) + rgF.g + float( rgI.g ) + rgbF.g + float( rgbI.g ), - rgbF.b + float( rgbI.b ), - 1.0 - ); - } - """ - - return s - - def textureShader( self ) : - - s = IECoreScene.Shader( "test", "gl:surface" ) - - s.parameters["gl:fragmentSource"] = """ - - uniform sampler2D sampler; - - varying vec2 fragmentuv; - - void main() - { - gl_FragColor = vec4( texture2D( sampler, fragmentuv ).rgb, 1 ); - } - """ - - return s - - def geometryShader( self ) : - - s = IECoreScene.Shader( "test", "gl:surface" ) - - s.parameters["gl:geometrySource"] = """ -#version 150 - - layout( points ) in; - layout( points, max_vertices=3 ) out; - - void main() - { - for( int i = -1; i<2; i++ ) - { - gl_Position = gl_in[0].gl_Position + vec4( 0.5 * i, 0, 0, 0 ); - EmitVertex(); - } - } - """ - - s.parameters["gl:fragmentSource"] = """ - void main() - { - gl_FragColor = vec4( 1.0, 1.0, 1.0, 1.0 ); - } - """ - - return s - - def floatArrayShader( self ) : - - s = IECoreScene.Shader( "test", "gl:surface" ) - - s.parameters["gl:fragmentSource"] = """ - - uniform float f[8]; - uniform vec2 f2[8]; - uniform vec3 f3[8]; - uniform vec4 f4[8]; - - void main() - { - vec3 accum = vec3( 0 ); - for( int i = 0; i < 8; i += 1 ) accum += 0.01 * ( vec3(f[i], 0, 0) + vec3(f2[i], 0) + f3[i] + f4[i].xyz ); - gl_FragColor = vec4( accum, 1.0); - } - """ - - return s - - def intArrayShader( self ) : - - s = IECoreScene.Shader( "test", "gl:surface" ) - - s.parameters["gl:fragmentSource"] = """ - - uniform int i[8]; - uniform ivec2 i2[8]; - uniform ivec3 i3[8]; - - void main() - { - vec3 accum = vec3( 0 ); - for( int j = 0; j < 8; j += 1 ) accum += 0.01 * ( vec3(i[j], 0, 0) + vec3(i2[j], 0) + vec3( i3[j] ) ); - gl_FragColor = vec4( accum, 1.0); - } - """ - - return s - - def matrixShader( self ) : - - s = IECoreScene.Shader( "test", "gl:surface" ) - - s.parameters["gl:fragmentSource"] = """ - - uniform mat3 m3; - uniform mat3 m3v[8]; - uniform mat4 m4; - uniform mat4 m4v[8]; - - void main() - { - vec3 accum = vec3( 0 ); - for( int i = 0; i < 8; i += 1 ) accum += m3v[i] * vec3( 0, 1, 0 ) + (m4v[i] * vec4( 0, 1, 0, 0 )).xyz; - gl_FragColor = vec4( m3 * vec3( 0, 0, 1) + (m4 * vec4( 0, 0, 1, 1 )).xyz + accum, 1.0); - } - """ - - return s - - def offsetShader( self, offset ) : - - s = IECoreScene.Shader( "test", "gl:surface" ) - - s.parameters["gl:vertexSource"] = inspect.cleandoc( """ - - #version 120 - #if __VERSION__ <= 120 - #define in attribute - #endif - - uniform vec3 offset; - - in vec3 vertexP; - void main() - { - vec3 translatedVertexP = vertexP + offset; - vec4 pCam = gl_ModelViewMatrix * vec4( translatedVertexP, 1 ); - gl_Position = gl_ProjectionMatrix * pCam; - } - - """ ) - - s.parameters["gl:fragmentSource"] = inspect.cleandoc( """ - - void main() - { - - gl_FragColor = vec4( 1, 0, 0, 1 ); - - } - - """ ) - - s.parameters["offset"] = offset - - return s - - def renderImage( self, group ) : - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - - r.camera( - "main", { - "projection" : "orthographic" , - "resolution" : imath.V2i( 256 ), - "clippingPlanes" : imath.V2f( 1, 1000 ), - "screenWindow" : imath.Box2f( imath.V2f( -0.5 ), imath.V2f( 0.5 ) ) - } - ) - r.display( self.__imageFileName, "tif", "rgba", {} ) - r.setOption( "gl:searchPath:texture", IECore.StringData( "." + os.path.sep ) ) - r.setOption( "gl:searchPath:shader", IECore.StringData( os.path.join( ".", "test", "IECoreGL", "shaders" ) ) ) - - with IECoreScene.WorldBlock( r ) : - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -5 ) ) ) - - group.render( r ) - - return IECore.Reader.create( self.__imageFileName ).read() - - def assertImageValues( self, image, tests ) : - - dimensions = image.dataWindow.size() + imath.V2i( 1 ) - - for t in tests : - - index = dimensions.x * int(dimensions.y * t[0].y) + int(dimensions.x * t[0].x) - - c = imath.Color4f( - image["R"][index], - image["G"][index], - image["B"][index], - image["A"][index], - ) - - for i in range( 4 ): - if abs( c[i] - t[1][i] ) > 0.01: - raise AssertionError( repr( c ) + " != " + repr( t[1] ) ) - - def splineGradient( self, color0, color1 ) : - - return IECore.SplinefColor3fData( - IECore.SplinefColor3f( - IECore.CubicBasisf.catmullRom(), - ( - ( 0, color0 ), - ( 0, color0 ), - ( 1, color1 ), - ( 1, color1 ), - ), - ), - ) - - def testBasicPositioning( self ) : - - g = IECoreScene.Group() - g.addChild( self.mesh() ) - - image = self.renderImage( g ) - - self.assertImageValues( - image, - [ - ( imath.V2f( 0.5 ), imath.Color4f( 1, 1, 1, 1 ) ), - ( imath.V2f( 0.3, 0.5 ), imath.Color4f( 0, 0, 0, 0 ) ), - ] - ) - - def testUniformBoolParameters( self ) : - - c1 = IECoreScene.Group() - c1.addChild( self.mesh() ) - c1.addState( self.colorShader() ) - - c2 = c1.copy() - c1.state()[0].parameters["rB"] = IECore.BoolData( 1 ) - - c1.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( 0.2, 0, 0 ) ) ) ) - c2.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( -0.2, 0, 0 ) ) ) ) - - g = IECoreScene.Group() - g.addChild( c1 ) - g.addChild( c2 ) - - image = self.renderImage( g ) - - self.assertImageValues( - image, - [ - ( imath.V2f( 0.7, 0.5 ), imath.Color4f( 1, 0, 0, 1 ) ), - ( imath.V2f( 0.3, 0.5 ), imath.Color4f( 0, 0, 0, 1 ) ), - ] - ) - - def testUniformFloatParameters( self ) : - - c1 = IECoreScene.Group() - c1.addChild( self.mesh() ) - c1.addState( self.colorShader() ) - - c2 = c1.copy() - c1.state()[0].parameters["rF"] = IECore.FloatData( 1 ) - - c1.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( 0.2, 0, 0 ) ) ) ) - c2.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( -0.2, 0, 0 ) ) ) ) - - g = IECoreScene.Group() - g.addChild( c1 ) - g.addChild( c2 ) - - image = self.renderImage( g ) - - self.assertImageValues( - image, - [ - ( imath.V2f( 0.7, 0.5 ), imath.Color4f( 1, 0, 0, 1 ) ), - ( imath.V2f( 0.3, 0.5 ), imath.Color4f( 0, 0, 0, 1 ) ), - ] - ) - - def testUniformIntParameters( self ) : - - c1 = IECoreScene.Group() - c1.addChild( self.mesh() ) - c1.addState( self.colorShader() ) - - c2 = c1.copy() - c1.state()[0].parameters["gI"] = IECore.FloatData( 1 ) - - c1.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( 0.2, 0, 0 ) ) ) ) - c2.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( -0.2, 0, 0 ) ) ) ) - - g = IECoreScene.Group() - g.addChild( c1 ) - g.addChild( c2 ) - - image = self.renderImage( g ) - - self.assertImageValues( - image, - [ - ( imath.V2f( 0.7, 0.5 ), imath.Color4f( 0, 1, 0, 1 ) ), - ( imath.V2f( 0.3, 0.5 ), imath.Color4f( 0, 0, 0, 1 ) ), - ] - ) - - def testUniform2fParameters( self ) : - - c1 = IECoreScene.Group() - c1.addChild( self.mesh() ) - c1.addState( self.colorShader() ) - - c2 = c1.copy() - c1.state()[0].parameters["rgF"] = IECore.V2fData( imath.V2f( 0, 1 ) ) - c2.state()[0].parameters["rgF"] = IECore.V2fData( imath.V2f( 1, 0 ) ) - - c1.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( 0.2, 0, 0 ) ) ) ) - c2.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( -0.2, 0, 0 ) ) ) ) - - g = IECoreScene.Group() - g.addChild( c1 ) - g.addChild( c2 ) - - image = self.renderImage( g ) - - self.assertImageValues( - image, - [ - ( imath.V2f( 0.7, 0.5 ), imath.Color4f( 0, 1, 0, 1 ) ), - ( imath.V2f( 0.3, 0.5 ), imath.Color4f( 1, 0, 0, 1 ) ), - ] - ) - - def testUniform2iParameters( self ) : - - c1 = IECoreScene.Group() - c1.addChild( self.mesh() ) - c1.addState( self.colorShader() ) - - c2 = c1.copy() - c1.state()[0].parameters["rgF"] = IECore.V2iData( imath.V2i( 0, 1 ) ) - c2.state()[0].parameters["rgF"] = IECore.V2iData( imath.V2i( 1, 0 ) ) - - c1.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( 0.2, 0, 0 ) ) ) ) - c2.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( -0.2, 0, 0 ) ) ) ) - - g = IECoreScene.Group() - g.addChild( c1 ) - g.addChild( c2 ) - - image = self.renderImage( g ) - - self.assertImageValues( - image, - [ - ( imath.V2f( 0.7, 0.5 ), imath.Color4f( 0, 1, 0, 1 ) ), - ( imath.V2f( 0.3, 0.5 ), imath.Color4f( 1, 0, 0, 1 ) ), - ] - ) - - def testUniform3fParameters( self ) : - - c1 = IECoreScene.Group() - c1.addChild( self.mesh() ) - c1.addState( self.colorShader() ) - - c2 = c1.copy() - c1.state()[0].parameters["rgbF"] = IECore.V3fData( imath.V3f( 0, 1, 1 ) ) - c2.state()[0].parameters["rgbF"] = IECore.V3fData( imath.V3f( 1, 1, 0 ) ) - - c1.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( 0.2, 0, 0 ) ) ) ) - c2.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( -0.2, 0, 0 ) ) ) ) - - g = IECoreScene.Group() - g.addChild( c1 ) - g.addChild( c2 ) - - image = self.renderImage( g ) - - self.assertImageValues( - image, - [ - ( imath.V2f( 0.7, 0.5 ), imath.Color4f( 0, 1, 1, 1 ) ), - ( imath.V2f( 0.3, 0.5 ), imath.Color4f( 1, 1, 0, 1 ) ), - ] - ) - - def testUniform3iParameters( self ) : - - c1 = IECoreScene.Group() - c1.addChild( self.mesh() ) - c1.addState( self.colorShader() ) - - c2 = c1.copy() - c1.state()[0].parameters["rgbI"] = IECore.V3iData( imath.V3i( 0, 1, 1 ) ) - c2.state()[0].parameters["rgbI"] = IECore.V3iData( imath.V3i( 1, 1, 0 ) ) - - c1.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( 0.2, 0, 0 ) ) ) ) - c2.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( -0.2, 0, 0 ) ) ) ) - - g = IECoreScene.Group() - g.addChild( c1 ) - g.addChild( c2 ) - - image = self.renderImage( g ) - - self.assertImageValues( - image, - [ - ( imath.V2f( 0.7, 0.5 ), imath.Color4f( 0, 1, 1, 1 ) ), - ( imath.V2f( 0.3, 0.5 ), imath.Color4f( 1, 1, 0, 1 ) ), - ] - ) - - def testConstantPrimVarTemporarilyOverridesShaderParameter( self ) : - - c1 = IECoreScene.Group() - c1.addChild( self.mesh() ) - c1.addState( self.colorShader() ) - - c2 = c1.copy() - c1.state()[0].parameters["rgbF"] = IECore.V3iData( imath.V3i( 0, 1, 1 ) ) - c1.children()[0]["rgbF"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Constant, IECore.V3fData( imath.V3f( 1, 1, 0 ) ) ) - - c1.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( 0.2, 0, 0 ) ) ) ) - c2.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( -0.2, 0, 0 ) ) ) ) - - g = IECoreScene.Group() - g.addChild( c1 ) - g.addChild( c2 ) - - image = self.renderImage( g ) - - self.assertImageValues( - image, - [ - ( imath.V2f( 0.7, 0.5 ), imath.Color4f( 1, 1, 0, 1 ) ), - ( imath.V2f( 0.3, 0.5 ), imath.Color4f( 0, 0, 0, 1 ) ), - ] - ) - - def testSplineAsTexture( self ) : - - c1 = IECoreScene.Group() - c1.addChild( self.mesh() ) - c1.addState( self.textureShader() ) - - c2 = c1.copy() - c1.state()[0].parameters["sampler"] = self.splineGradient( imath.Color3f( 1, 0, 0 ), imath.Color3f( 1, 0, 0 ) ) - - c1.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( 0.2, 0, 0 ) ) ) ) - c2.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( -0.2, 0, 0 ) ) ) ) - - g = IECoreScene.Group() - g.addChild( c1 ) - g.addChild( c2 ) - - image = self.renderImage( g ) - - self.assertImageValues( - image, - [ - ( imath.V2f( 0.7, 0.5 ), imath.Color4f( 1, 0, 0, 1 ) ), - ( imath.V2f( 0.3, 0.5 ), imath.Color4f( 0, 0, 0, 1 ) ), - ] - ) - - def testImageFileAsTexture( self ) : - - c1 = IECoreScene.Group() - c1.addChild( self.mesh() ) - c1.addState( self.textureShader() ) - - c2 = c1.copy() - c1.state()[0].parameters["sampler"] = IECore.StringData( os.path.join( os.path.dirname( __file__ ), "images", "yellow.exr" ) ) - - c1.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( 0.2, 0, 0 ) ) ) ) - c2.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( -0.2, 0, 0 ) ) ) ) - - g = IECoreScene.Group() - g.addChild( c1 ) - g.addChild( c2 ) - - image = self.renderImage( g ) - - self.assertImageValues( - image, - [ - ( imath.V2f( 0.7, 0.5 ), imath.Color4f( 1, 1, 0, 1 ) ), - ( imath.V2f( 0.3, 0.5 ), imath.Color4f( 0, 0, 0, 1 ) ), - ] - ) - - - def testCompoundDataAsTexture( self ) : - - c1 = IECoreScene.Group() - c1.addChild( self.mesh() ) - c1.addState( self.textureShader() ) - - yellowImage = IECore.Reader.create( os.path.join( os.path.dirname( __file__ ), "images", "yellow.exr" ) ).read() - yellowCompoundData = IECore.CompoundData( { - "dataWindow" : IECore.Box2iData( yellowImage.dataWindow ), - "displayWindow" : IECore.Box2iData( yellowImage.displayWindow ), - "channels" : { - "R" : yellowImage["R"], - "G" : yellowImage["G"], - "B" : yellowImage["B"], - } - } ) - - - c2 = c1.copy() - c1.state()[0].parameters["sampler"] = yellowCompoundData - - c1.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( 0.2, 0, 0 ) ) ) ) - c2.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( -0.2, 0, 0 ) ) ) ) - - g = IECoreScene.Group() - g.addChild( c1 ) - g.addChild( c2 ) - - image = self.renderImage( g ) - - self.assertImageValues( - image, - [ - ( imath.V2f( 0.7, 0.5 ), imath.Color4f( 1, 1, 0, 1 ) ), - ( imath.V2f( 0.3, 0.5 ), imath.Color4f( 0, 0, 0, 1 ) ), - ] - ) - - def testWireframe( self ) : - - g = IECoreScene.Group() - g.addChild( self.mesh() ) - - g.addState( - IECoreScene.AttributeState( - { - "gl:primitive:solid" : IECore.BoolData( False ), - "gl:primitive:wireframe" : IECore.BoolData( True ), - "gl:primitive:wireframeColor" : imath.Color4f( 1, 0, 0, 1 ), - "gl:primitive:wireframeWidth" : 6.0, - } - ) - ) - - image = self.renderImage( g ) - - self.assertImageValues( - image, - [ - ( imath.V2f( 0.5, 0.5 ), imath.Color4f( 1, 0, 0, 1 ) ), - ( imath.V2f( 0.55, 0.5 ), imath.Color4f( 0, 0, 0, 0 ) ), - ] - ) - - def testSameMeshTwoShaders( self ) : - - c1 = IECoreScene.Group() - c1.addChild( self.mesh() ) - c1.addState( self.colorShader() ) - c1.state()[0].parameters["rgbF"] = IECore.V3fData( imath.V3f( 0, 1, 1 ) ) - - c2 = IECoreScene.Group() - c2.addChild( self.mesh() ) - c2.addState( self.textureShader() ) - c2.state()[0].parameters["sampler"] = IECore.StringData( os.path.join( os.path.dirname( __file__ ), "images", "yellow.exr" ) ) - - c1.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( 0.2, 0, 0 ) ) ) ) - c2.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( -0.2, 0, 0 ) ) ) ) - - g = IECoreScene.Group() - g.addChild( c1 ) - g.addChild( c2 ) - - image = self.renderImage( g ) - - self.assertImageValues( - image, - [ - ( imath.V2f( 0.7, 0.5 ), imath.Color4f( 0, 1, 1, 1 ) ), - ( imath.V2f( 0.3, 0.5 ), imath.Color4f( 1, 1, 0, 1 ) ), - ] - ) - - def testGeometryShaderViaParameters( self ) : - - if IECoreGL.glslVersion() < 150 : - # no point testing unavailable functionality - return - - g = IECoreScene.Group() - - p = IECoreScene.PointsPrimitive( IECore.V3fVectorData( [ imath.V3f( 0 ) ] ) ) - p["type"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Uniform, IECore.StringData( "gl:point" ) ) - g.addChild( p ) - - g.addState( IECoreScene.AttributeState( { "gl:pointsPrimitive:glPointWidth" : IECore.FloatData( 4 ) } ) ) - g.addState( self.geometryShader() ) - - image = self.renderImage( g ) - - self.assertImageValues( - image, - [ - ( imath.V2f( 0.125, 0.5 ), imath.Color4f( 0, 0, 0, 0 ) ), - ( imath.V2f( 0.25, 0.5 ), imath.Color4f( 1, 1, 1, 1 ) ), - ( imath.V2f( 0.375, 0.5 ), imath.Color4f( 0, 0, 0, 0 ) ), - ( imath.V2f( 0.5, 0.5 ), imath.Color4f( 1, 1, 1, 1 ) ), - ( imath.V2f( 0.625, 0.5 ), imath.Color4f( 0, 0, 0, 0 ) ), - ( imath.V2f( 0.75, 0.5 ), imath.Color4f( 1, 1, 1, 1 ) ), - ( imath.V2f( 0.875, 0.5 ), imath.Color4f( 0, 0, 0, 0 ) ), - ] - ) - - def testGeometryShaderViaFile( self ) : - - if IECoreGL.glslVersion() < 150 : - # no point testing unavailable functionality - return - - g = IECoreScene.Group() - - p = IECoreScene.PointsPrimitive( IECore.V3fVectorData( [ imath.V3f( 0 ) ] ) ) - p["type"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Uniform, IECore.StringData( "gl:point" ) ) - g.addChild( p ) - - g.addState( IECoreScene.AttributeState( { "gl:pointsPrimitive:glPointWidth" : IECore.FloatData( 4 ) } ) ) - g.addState( IECoreScene.Shader( "pointTripler", "gl:surface" ) ) - - image = self.renderImage( g ) - - self.assertImageValues( - image, - [ - ( imath.V2f( 0.125, 0.5 ), imath.Color4f( 0, 0, 0, 0 ) ), - ( imath.V2f( 0.25, 0.5 ), imath.Color4f( 1, 1, 1, 1 ) ), - ( imath.V2f( 0.375, 0.5 ), imath.Color4f( 0, 0, 0, 0 ) ), - ( imath.V2f( 0.5, 0.5 ), imath.Color4f( 1, 1, 1, 1 ) ), - ( imath.V2f( 0.625, 0.5 ), imath.Color4f( 0, 0, 0, 0 ) ), - ( imath.V2f( 0.75, 0.5 ), imath.Color4f( 1, 1, 1, 1 ) ), - ( imath.V2f( 0.875, 0.5 ), imath.Color4f( 0, 0, 0, 0 ) ), - ] - ) - - def testCsParameterTrumpsColorAttribute( self ) : - - # if there is no Cs parameter value specified then we should get - # Cs from the attribute state. - - g = IECoreScene.Group() - g.addChild( self.mesh() ) - - g.addState( IECoreScene.AttributeState( { "color" : imath.Color3f( 1, 0, 0 ) } ) ) - g.addState( self.constantShader() ) - - image = self.renderImage( g ) - self.assertImageValues( image, [ ( imath.V2f( 0.5 ), imath.Color4f( 1, 0, 0, 1 ) ) ] ) - - # but if there is a Cs parameter, it should override the colour - # from the attribute state. - - g = IECoreScene.Group() - g.addChild( self.mesh() ) - - g.addState( IECoreScene.AttributeState( { "color" : imath.Color3f( 1, 0, 0 ) } ) ) - - s = self.constantShader() - s.parameters["Cs"] = imath.Color3f( 0, 1, 0 ) - g.addState( s ) - - image = self.renderImage( g ) - self.assertImageValues( image, [ ( imath.V2f( 0.5 ), imath.Color4f( 0, 1, 0, 1 ) ) ] ) - - def testColorAttributeDoesntAffectWireframe( self ) : - - g = IECoreScene.Group() - g.addChild( self.mesh() ) - - g.addState( - IECoreScene.AttributeState( - { - "color" : imath.Color3f( 1, 0, 0 ), - "gl:primitive:solid" : IECore.BoolData( False ), - "gl:primitive:wireframe" : IECore.BoolData( True ), - "gl:primitive:wireframeColor" : imath.Color4f( 0, 1, 0, 1 ), - "gl:primitive:wireframeWidth" : 6.0, - } - ) - ) - - image = self.renderImage( g ) - - self.assertImageValues( - image, - [ - ( imath.V2f( 0.5, 0.5 ), imath.Color4f( 0, 1, 0, 1 ) ), - ] - ) - - def testVertexCsDoesntAffectWireframe( self ) : - - m = self.mesh() - m["Cs"] = IECoreScene.PrimitiveVariable( - IECoreScene.PrimitiveVariable.Interpolation.Vertex, - IECore.Color3fVectorData( - [ imath.Color3f( 0 ) ] * len( m["P"].data ) - ) - ) - - g = IECoreScene.Group() - g.addChild( m ) - - g.addState( - IECoreScene.AttributeState( - { - "gl:primitive:solid" : IECore.BoolData( True ), - "gl:primitive:wireframe" : IECore.BoolData( True ), - "gl:primitive:wireframeColor" : imath.Color4f( 0, 1, 0, 1 ), - "gl:primitive:wireframeWidth" : 6.0, - } - ) - ) - - image = self.renderImage( g ) - # wireframe is green, and vertex Cs is black, - # so there should be no contribution from - # wireframe or solid shading in the red channel. - self.assertAlmostEqual( sum( image["R"] ), 0, 4 ) - # black vertex colour should have no effect on - # green wireframe, so we should have some wireframe - # contribution in the green channel. - self.assertNotAlmostEqual( sum( image["G"] ), 0, 4 ) - self.assertTrue( sum( image["G"] ) > 0 ) - - def testUniformFloatArrayParameters( self ) : - - c1 = IECoreScene.Group() - c1.addChild( self.mesh() ) - c1.addState( self.floatArrayShader() ) - - c2 = c1.copy() - c3 = c1.copy() - c4 = c1.copy() - c1.state()[0].parameters["f"] = IECore.FloatVectorData( [ i for i in range( 8 ) ] ) - c2.state()[0].parameters["f2"] = IECore.V2fVectorData( [ imath.V2f( i, 100.0 / 16) for i in range( 8 ) ] ) - c3.state()[0].parameters["f3"] = IECore.V3fVectorData( [ imath.V3f( i, 100.0 / 16, 100 * 0.5 ** ( i + 2 )) for i in range( 8 ) ] ) - c4.state()[0].parameters["f4"] = IECore.Color4fVectorData( [ imath.Color4f( i, 100.0 / 32, 100 * 0.5 ** ( i + 2), 0.0 ) for i in range( 8 ) ] ) - - c1.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( -0.2, 0.2, 0 ) ) ) ) - c2.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( 0.2, 0.2, 0 ) ) ) ) - c3.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( -0.2, -0.2, 0 ) ) ) ) - c4.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( 0.2, -0.2, 0 ) ) ) ) - - g = IECoreScene.Group() - g.addChild( c1 ) - g.addChild( c2 ) - g.addChild( c3 ) - g.addChild( c4 ) - - image = self.renderImage( g ) - - self.assertImageValues( - image, - [ - ( imath.V2f( 0.3, 0.3 ), imath.Color4f( 0.28, 0, 0, 1 ) ), - ( imath.V2f( 0.7, 0.3 ), imath.Color4f( 0.28, 0.5, 0, 1 ) ), - ( imath.V2f( 0.3, 0.7 ), imath.Color4f( 0.28, 0.5, 0.5, 1 ) ), - ( imath.V2f( 0.7, 0.7 ), imath.Color4f( 0.28, 0.25, 0.5, 1 ) ), - ] - ) - - def testUniformIntArrayParameters( self ) : - - c1 = IECoreScene.Group() - c1.addChild( self.mesh() ) - c1.addState( self.intArrayShader() ) - - c2 = c1.copy() - c3 = c1.copy() - c1.state()[0].parameters["i"] = IECore.FloatVectorData( [ i for i in range( 8 ) ] ) - c2.state()[0].parameters["i2"] = IECore.V2fVectorData( [ imath.V2f( i, 100.0 / 16) for i in range( 8 ) ] ) - c3.state()[0].parameters["i3"] = IECore.V3fVectorData( [ imath.V3f( i, 100.0 / 16, 100 * 0.5 ** ( i + 2 )) for i in range( 8 ) ] ) - - c1.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( -0.2, 0.2, 0 ) ) ) ) - c2.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( 0.2, 0.2, 0 ) ) ) ) - c3.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( -0.2, -0.2, 0 ) ) ) ) - - g = IECoreScene.Group() - g.addChild( c1 ) - g.addChild( c2 ) - g.addChild( c3 ) - - image = self.renderImage( g ) - temporaryDirectory = tempfile.mkdtemp( prefix="IECoreGL" ) - shutil.copy( self.__imageFileName, os.path.join( temporaryDirectory, "foo.exr" ) ) - - self.assertImageValues( - image, - [ - ( imath.V2f( 0.3, 0.3 ), imath.Color4f( 0.28, 0, 0, 1 ) ), - ( imath.V2f( 0.7, 0.3 ), imath.Color4f( 0.28, 0.48, 0, 1 ) ), - ( imath.V2f( 0.3, 0.7 ), imath.Color4f( 0.28, 0.48, 0.47, 1 ) ), - ] - ) - - shutil.rmtree( temporaryDirectory ) - - def testMatrixParameters( self ) : - - c1 = IECoreScene.Group() - c1.addChild( self.mesh() ) - c1.addState( self.matrixShader() ) - - c2 = c1.copy() - c3 = c1.copy() - c4 = c1.copy() - c1.state()[0].parameters["m3"] = IECore.M33fData( imath.M33f( *[ i * 0.1 for i in range( 9 ) ] ) ) - c2.state()[0].parameters["m4"] = IECore.M44fData( imath.M44f( *[ i * 0.01 for i in range( 16 ) ] ) ) - c3.state()[0].parameters["m3v"] = IECore.M33fVectorData( [ imath.M33f( *[0,0,0, i * 0.01, i * 0.02, i * 0.03, 0,0,0] ) for i in range( 8 ) ] ) - c4.state()[0].parameters["m4v"] = IECore.M44fVectorData( [ imath.M44f( *[0,0,0,0, i * 0.005, i * 0.01, i * 0.02, 0, 0,0,0,0,0,0,0,0 ] ) for i in range( 8 ) ] ) - - c1.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( -0.2, 0.2, 0 ) ) ) ) - c2.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( 0.2, 0.2, 0 ) ) ) ) - c3.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( -0.2, -0.2, 0 ) ) ) ) - c4.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( 0.2, -0.2, 0 ) ) ) ) - - g = IECoreScene.Group() - g.addChild( c1 ) - g.addChild( c2 ) - g.addChild( c3 ) - g.addChild( c4 ) - - image = self.renderImage( g ) - - self.assertImageValues( - image, - [ - ( imath.V2f( 0.3, 0.3 ), imath.Color4f( 0.6, 0.7, 0.8, 1 ) ), - ( imath.V2f( 0.7, 0.3 ), imath.Color4f( 0.20, 0.22, 0.24, 1 ) ), - ( imath.V2f( 0.3, 0.7 ), imath.Color4f( 0.28, 0.56, 0.84, 1 ) ), - ( imath.V2f( 0.7, 0.7 ), imath.Color4f( 0.14, 0.28, 0.56, 1 ) ), - ] - ) - - def testWireframeWithCustomVertexShader( self ) : - - def renderOffsetImage( offset ) : - - m = self.mesh() - - g = IECoreScene.Group() - g.addChild( m ) - - g.addState( - IECoreScene.AttributeState( - { - "gl:primitive:solid" : IECore.BoolData( True ), - "gl:primitive:wireframe" : IECore.BoolData( True ), - "gl:primitive:wireframeColor" : imath.Color4f( 0, 1, 0, 1 ), - "gl:primitive:wireframeWidth" : 6.0, - } - ) - ) - g.addState( self.offsetShader( offset = offset ) ) - - return self.renderImage( g ) - - # Offset shader offsets in X in the vertex shader, - # and renders red in the fragment shader. The wireframe - # shading should inherit the offset but not the red. - - image = renderOffsetImage( offset = imath.V3f( 0.2, 0, 0 ) ) - - self.assertImageValues( - image, - [ - ( imath.V2f( 0.5, 0.5 ), imath.Color4f( 0, 0, 0, 0 ) ), - ( imath.V2f( 0.6, 0.5 ), imath.Color4f( 0, 1, 0, 1 ) ), - ( imath.V2f( 0.65, 0.5 ), imath.Color4f( 1, 0, 0, 1 ) ), - ( imath.V2f( 0.7, 0.5 ), imath.Color4f( 0, 1, 0, 1 ) ), - ( imath.V2f( 0.75, 0.5 ), imath.Color4f( 1, 0, 0, 1 ) ), - ( imath.V2f( 0.8, 0.5 ), imath.Color4f( 0, 1, 0, 1 ) ), - ] - ) - - image = renderOffsetImage( offset = imath.V3f( -0.2, 0, 0 ) ) - - self.assertImageValues( - image, - [ - ( imath.V2f( 0.2, 0.5 ), imath.Color4f( 0, 1, 0, 1 ) ), - ( imath.V2f( 0.25, 0.5 ), imath.Color4f( 1, 0, 0, 1 ) ), - ( imath.V2f( 0.3, 0.5 ), imath.Color4f( 0, 1, 0, 1 ) ), - ( imath.V2f( 0.35, 0.5 ), imath.Color4f( 1, 0, 0, 1 ) ), - ( imath.V2f( 0.4, 0.5 ), imath.Color4f( 0, 1, 0, 1 ) ), - ( imath.V2f( 0.5, 0.5 ), imath.Color4f( 0, 0, 0, 0 ) ), - ] - ) - - def setUp( self ) : - - if not os.path.isdir( os.path.join( "test", "IECoreGL", "output" ) ) : - os.makedirs( os.path.join( "test", "IECoreGL", "output" ) ) - - def tearDown( self ) : - - if os.path.isdir( os.path.join( "test", "IECoreGL", "output" ) ) : - shutil.rmtree( os.path.join( "test", "IECoreGL", "output" ) ) - -if __name__ == "__main__": - unittest.main() diff --git a/test/IECoreGL/TextTest.py b/test/IECoreGL/TextTest.py deleted file mode 100644 index 1a1046f52b..0000000000 --- a/test/IECoreGL/TextTest.py +++ /dev/null @@ -1,137 +0,0 @@ -########################################################################## -# -# Copyright (c) 2008-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 Image Engine Design 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 os.path -import shutil -import imath - -import IECore -import IECoreScene -import IECoreImage - -import IECoreGL -IECoreGL.init( False ) - -class TextTest( unittest.TestCase ) : - - outputFileName = os.path.join( os.path.dirname( __file__ ), "output", "testText.tif" ) - - def testMeshes( self ) : - - os.environ["IECORE_FONT_PATHS"] = "test" - - r = IECoreGL.Renderer() - - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - - self.assertEqual( r.getOption( "searchPath:font" ), IECore.StringData( "test" ) ) - r.setOption( "searchPath:font", IECore.StringData( os.path.join( "test", "IECore", "data", "fonts" ) ) ) - self.assertEqual( r.getOption( "searchPath:font" ), IECore.StringData( os.path.join( "test", "IECore", "data", "fonts" ) ) ) - - r.setOption( "gl:searchPath:shader", IECore.StringData( os.path.join( os.path.dirname( __file__ ), "shaders" ) ) ) - - r.camera( "main", { - "projection" : IECore.StringData( "orthographic" ), - "resolution" : IECore.V2iData( imath.V2i( 256 ) ), - "clippingPlanes" : IECore.V2fData( imath.V2f( 1, 1000 ) ), - "screenWindow" : IECore.Box2fData( imath.Box2f( imath.V2f( 0 ), imath.V2f( 1 ) ) ), - } - ) - r.display( self.outputFileName, "tiff", "rgba", {} ) - - with IECoreScene.WorldBlock( r ) : - - r.shader( "surface", "color", { "colorValue" : IECore.Color3fData( imath.Color3f( 0, 0, 1 ) ) } ) - - r.concatTransform( imath.M44f().translate( imath.V3f( 0.1, 0.1, -3 ) ) ) - r.concatTransform( imath.M44f().scale( imath.V3f( 0.15 ) ) ) - - r.text( "Vera.ttf", "hello world", 1, {} ) - - imageCreated = IECore.Reader.create( self.outputFileName ).read() - expectedImage = IECore.Reader.create( os.path.join( os.path.dirname( __file__ ), "images", "helloWorld.tif" ) ).read() - - self.assertEqual( IECoreImage.ImageDiffOp()( imageA=imageCreated, imageB=expectedImage, maxError=0.004 ), IECore.BoolData( False ) ) - - def testSprites( self ) : - - r = IECoreGL.Renderer() - - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - - self.assertEqual( r.getOption( "searchPath:font" ), IECore.StringData( "test" ) ) - r.setOption( "searchPath:font", IECore.StringData( os.path.join( "test", "IECore", "data", "fonts" ) ) ) - self.assertEqual( r.getOption( "searchPath:font" ), IECore.StringData( os.path.join( "test", "IECore", "data", "fonts" ) ) ) - - r.setOption( "gl:searchPath:shader", IECore.StringData( os.path.join( os.path.dirname( __file__ ), "shaders" ) ) ) - - r.camera( "main", { - "projection" : IECore.StringData( "orthographic" ), - "resolution" : IECore.V2iData( imath.V2i( 256 ) ), - "clippingPlanes" : IECore.V2fData( imath.V2f( 1, 1000 ) ), - "screenWindow" : IECore.Box2fData( imath.Box2f( imath.V2f( 0 ), imath.V2f( 1 ) ) ), - } - ) - r.display( self.outputFileName, "tiff", "rgba", {} ) - - with IECoreScene.WorldBlock( r ) : - - r.concatTransform( imath.M44f().translate( imath.V3f( 0.1, 0.1, -3 ) ) ) - r.concatTransform( imath.M44f().scale( imath.V3f( 0.15 ) ) ) - - r.setAttribute( "gl:depthMask", IECore.BoolData( False ) ) - r.setAttribute( "gl:textPrimitive:type", IECore.StringData( "sprite" ) ) - - r.text( "Vera.ttf", "hello world", 1, {} ) - - imageCreated = IECore.Reader.create( self.outputFileName ).read() - reader = IECore.Reader.create( os.path.join( os.path.dirname( __file__ ), "images", "helloWorldSprites.tif" ) ) - reader["rawChannels"].setTypedValue( True ) - expectedImage = reader.read() - - self.assertEqual( IECoreImage.ImageDiffOp()( imageA=imageCreated, imageB=expectedImage, maxError=0.0575 ), IECore.BoolData( False ) ) - - def setUp( self ) : - - if not os.path.isdir( os.path.join( "test", "IECoreGL", "output" ) ) : - os.makedirs( os.path.join( "test", "IECoreGL", "output" ) ) - - def tearDown( self ) : - - if os.path.isdir( os.path.join( "test", "IECoreGL", "output" ) ) : - shutil.rmtree( os.path.join( "test", "IECoreGL", "output" ) ) - -if __name__ == "__main__": - unittest.main() diff --git a/test/IECoreGL/Texture.py b/test/IECoreGL/Texture.py deleted file mode 100644 index 45b9e52e47..0000000000 --- a/test/IECoreGL/Texture.py +++ /dev/null @@ -1,129 +0,0 @@ -########################################################################## -# -# Copyright (c) 2007-2010, 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 Image Engine Design 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. -# -########################################################################## - -from __future__ import with_statement - -import unittest -import os.path -import shutil -import imath - -import IECore -import IECoreScene -import IECoreImage -import IECoreGL - -IECoreGL.init( False ) - -class TestTexture( unittest.TestCase ) : - - def testConstructor( self ) : - - i = IECore.Reader.create( os.path.join( os.path.dirname( __file__ ), "images", "colorBarsWithAlphaF512x512.exr" ) ).read() - - t = IECoreGL.ColorTexture( i ) - self.assertTrue( isinstance( t, IECoreGL.ColorTexture ) ) - - ii = t.imagePrimitive() - self.assertTrue( isinstance( ii, IECoreImage.ImagePrimitive ) ) - self.assertEqual( sorted( ii.keys() ), [ "A", "B", "G", "R" ] ) - self.assertTrue( ii.channelsValid() ) - - def performShaderParameterTest( self, shaderParameter ) : - - outputFileName = os.path.join( os.path.dirname( __file__ ), "output", "testTexture.tif" ) - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - - r.camera( "main", { - "projection" : IECore.StringData( "perspective" ), - "projection:fov" : IECore.FloatData( 45 ), - "resolution" : IECore.V2iData( imath.V2i( 256 ) ), - "clippingPlanes" : IECore.V2fData( imath.V2f( 1, 1000 ) ), - "screenWindow" : IECore.Box2fData( imath.Box2f( imath.V2f( -0.5 ), imath.V2f( 0.5 ) ) ) - } - ) - r.display( outputFileName, "tif", "rgba", {} ) - - vs = """ - void main() - { - gl_Position = ftransform(); - gl_TexCoord[0] = gl_MultiTexCoord0; - } - """ - - fs = """ - uniform sampler2D testSampler; - void main() - { - gl_FragColor = vec4( texture2D( testSampler, gl_TexCoord[0].xy ).rgb, 1.0 ); - } - """ - - with IECoreScene.WorldBlock( r ) : - - r.concatTransform( imath.M44f().translate( imath.V3f( 0, 0, -5 ) ) ) - - r.shader( "surface", "color", - { - "gl:vertexSource" : vs, - "gl:fragmentSource" : fs, - "testSampler" : shaderParameter, - } - ) - - r.sphere( 1, -1, 1, 360, {} ) - - def testEmptyStringShaderParameter( self ) : - - self.performShaderParameterTest( IECore.StringData( "" ) ) - - def testMissingStringShaderParameter( self ) : - - self.performShaderParameterTest( IECore.StringData( "thisFileDoesntExist" ) ) - - def setUp( self ) : - - if not os.path.isdir( os.path.join( "test", "IECoreGL", "output" ) ) : - os.makedirs( os.path.join( "test", "IECoreGL", "output" ) ) - - def tearDown( self ) : - - if os.path.isdir( os.path.join( "test", "IECoreGL", "output" ) ) : - shutil.rmtree( os.path.join( "test", "IECoreGL", "output" ) ) - -if __name__ == "__main__": - unittest.main() diff --git a/test/IECoreGL/UserAttributesTest.py b/test/IECoreGL/UserAttributesTest.py deleted file mode 100644 index a5b813b7b7..0000000000 --- a/test/IECoreGL/UserAttributesTest.py +++ /dev/null @@ -1,98 +0,0 @@ -########################################################################## -# -# Copyright (c) 2008-2011, 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 Image Engine Design 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 IECore -import IECoreScene -import IECoreGL -IECoreGL.init( False ) -import os.path -import os -import math - -class UserAtributesTest( unittest.TestCase ) : - - def testUserAttributesInDeferredMode( self ) : - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "deferred" ) ) - r.worldBegin() - - self.assertEqual( r.getAttribute( "user:notSetYet" ), None ) - - r.setAttribute( "user:test", IECore.FloatData( 1 ) ) - self.assertEqual( r.getAttribute( "user:test" ), IECore.FloatData( 1 ) ) - - r.attributeBegin() - - self.assertEqual( r.getAttribute( "user:test" ), IECore.FloatData( 1 ) ) - - r.setAttribute( "user:test2", IECore.IntData( 10 ) ) - self.assertEqual( r.getAttribute( "user:test2" ), IECore.IntData( 10 ) ) - - r.attributeEnd() - - self.assertEqual( r.getAttribute( "user:test" ), IECore.FloatData( 1 ) ) - self.assertEqual( r.getAttribute( "user:test2" ), None ) - - r.worldEnd() - - def testUserAttributesInImmediateMode( self ) : - - r = IECoreGL.Renderer() - r.setOption( "gl:mode", IECore.StringData( "immediate" ) ) - r.worldBegin() - - self.assertEqual( r.getAttribute( "user:notSetYet" ), None ) - - r.setAttribute( "user:test", IECore.FloatData( 1 ) ) - self.assertEqual( r.getAttribute( "user:test" ), IECore.FloatData( 1 ) ) - - r.attributeBegin() - - self.assertEqual( r.getAttribute( "user:test" ), IECore.FloatData( 1 ) ) - - r.setAttribute( "user:test2", IECore.IntData( 10 ) ) - self.assertEqual( r.getAttribute( "user:test2" ), IECore.IntData( 10 ) ) - - r.attributeEnd() - - self.assertEqual( r.getAttribute( "user:test" ), IECore.FloatData( 1 ) ) - self.assertEqual( r.getAttribute( "user:test2" ), None ) - - r.worldEnd() - - -if __name__ == "__main__": - unittest.main() From 3e3f66a92db52689259e3569d66ebd0bde9feca7 Mon Sep 17 00:00:00 2001 From: John Haddon Date: Tue, 8 Jul 2025 10:20:24 +0100 Subject: [PATCH 03/15] Renderable : Remove `render()` method This was used to render via the ancient `IECoreScene::Renderer` class, which has been superseded by a new Renderer class in GafferScene. The new Renderer is just passed objects directly, and doesn't have a method for each object type. --- Changes | 1 + include/IECoreScene/AttributeState.h | 3 -- include/IECoreScene/Camera.h | 3 -- include/IECoreScene/ClippingPlane.h | 2 - include/IECoreScene/CoordinateSystem.h | 6 --- include/IECoreScene/CurvesPrimitive.h | 1 - include/IECoreScene/DiskPrimitive.h | 1 - include/IECoreScene/ExternalProcedural.h | 1 - include/IECoreScene/Group.h | 12 ----- include/IECoreScene/Light.h | 3 -- include/IECoreScene/MatrixMotionTransform.h | 1 - include/IECoreScene/MatrixTransform.h | 1 - include/IECoreScene/MeshPrimitive.h | 3 -- include/IECoreScene/MotionPrimitive.h | 3 -- include/IECoreScene/NURBSPrimitive.h | 2 - include/IECoreScene/Options.h | 3 -- include/IECoreScene/Output.h | 2 - include/IECoreScene/PatchMeshPrimitive.h | 2 - include/IECoreScene/PointsPrimitive.h | 2 - include/IECoreScene/Renderable.h | 5 -- include/IECoreScene/Shader.h | 3 -- include/IECoreScene/SpherePrimitive.h | 2 - include/IECoreVDB/VDBObject.h | 1 - src/IECoreScene/AttributeState.cpp | 10 ---- src/IECoreScene/Camera.cpp | 8 ---- src/IECoreScene/ClippingPlane.cpp | 7 --- src/IECoreScene/CoordinateSystem.cpp | 14 ------ src/IECoreScene/CurvesPrimitive.cpp | 7 --- src/IECoreScene/DiskPrimitive.cpp | 8 ---- src/IECoreScene/ExternalProcedural.cpp | 7 --- src/IECoreScene/Group.cpp | 37 --------------- src/IECoreScene/Light.cpp | 7 --- src/IECoreScene/MatrixMotionTransform.cpp | 27 ----------- src/IECoreScene/MatrixTransform.cpp | 7 --- src/IECoreScene/MeshPrimitive.cpp | 6 --- src/IECoreScene/MotionPrimitive.cpp | 47 ------------------- src/IECoreScene/NURBSPrimitive.cpp | 7 --- src/IECoreScene/Options.cpp | 10 ---- src/IECoreScene/Output.cpp | 7 --- src/IECoreScene/PatchMeshPrimitive.cpp | 15 ------ src/IECoreScene/PointsPrimitive.cpp | 7 --- src/IECoreScene/Renderable.cpp | 8 ---- src/IECoreScene/Shader.cpp | 7 --- src/IECoreScene/SpherePrimitive.cpp | 8 ---- src/IECoreScene/bindings/GroupBinding.cpp | 29 ------------ .../bindings/RenderableBinding.cpp | 8 ---- src/IECoreVDB/VDBObject.cpp | 4 -- 47 files changed, 1 insertion(+), 364 deletions(-) diff --git a/Changes b/Changes index 56e2adbc4f..1bd712a0db 100644 --- a/Changes +++ b/Changes @@ -12,6 +12,7 @@ Fixes Breaking Changes ---------------- +- Renderable : Removed `render()` method. - IECoreHoudini : Removed. - IECoreMaya : Removed. - IECoreNuke : Removed. diff --git a/include/IECoreScene/AttributeState.h b/include/IECoreScene/AttributeState.h index e641d784d9..c047cb571d 100644 --- a/include/IECoreScene/AttributeState.h +++ b/include/IECoreScene/AttributeState.h @@ -63,9 +63,6 @@ class IECORESCENE_API AttributeState : public StateRenderable /// (it calls readable() or writable() for you). IECore::CompoundDataPtr attributesData(); - /// Calls renderer->setAttribute() for each name, data pair in attributes() - void render( Renderer *renderer ) const override; - private: IECore::CompoundDataPtr m_attributes; diff --git a/include/IECoreScene/Camera.h b/include/IECoreScene/Camera.h index d9d2b88efe..772b2e12b5 100644 --- a/include/IECoreScene/Camera.h +++ b/include/IECoreScene/Camera.h @@ -242,9 +242,6 @@ class IECORESCENE_API Camera : public PreWorldRenderable /// horizontal field of view ( in degrees ) void setFocalLengthFromFieldOfView( float horizontalFOV ); - void render( Renderer *renderer ) const override; - - private: Imath::Box2f defaultApertureRect() const; diff --git a/include/IECoreScene/ClippingPlane.h b/include/IECoreScene/ClippingPlane.h index becd091639..4b757a2c97 100644 --- a/include/IECoreScene/ClippingPlane.h +++ b/include/IECoreScene/ClippingPlane.h @@ -50,8 +50,6 @@ class IECORESCENE_API ClippingPlane : public PreWorldRenderable IE_CORE_DECLAREEXTENSIONOBJECT( ClippingPlane, ClippingPlaneTypeId, PreWorldRenderable ); - void render( Renderer *renderer ) const override; - }; IE_CORE_DECLAREPTR( ClippingPlane ); diff --git a/include/IECoreScene/CoordinateSystem.h b/include/IECoreScene/CoordinateSystem.h index 66d25cd4a7..b63c78b7f3 100644 --- a/include/IECoreScene/CoordinateSystem.h +++ b/include/IECoreScene/CoordinateSystem.h @@ -68,12 +68,6 @@ class IECORESCENE_API CoordinateSystem : public StateRenderable /// Sets the Transform applied to the coordinate system. void setTransform( TransformPtr transform ); - /// Calls renderer->coordinateSystem( name ). If a transform - /// has been applied then also scopes this in a - /// transformBegin/transformEnd with the appropriate - /// transformation. - void render( Renderer *renderer ) const override; - private: std::string m_name; diff --git a/include/IECoreScene/CurvesPrimitive.h b/include/IECoreScene/CurvesPrimitive.h index 808773d8d2..835028c740 100644 --- a/include/IECoreScene/CurvesPrimitive.h +++ b/include/IECoreScene/CurvesPrimitive.h @@ -64,7 +64,6 @@ class IECORESCENE_API CurvesPrimitive : public Primitive bool periodic() const; void setTopology( IECore::ConstIntVectorDataPtr verticesPerCurve, const IECore::CubicBasisf &basis, bool periodic ); - void render( Renderer *renderer ) const override; /// Follows the RenderMan specification for variable sizes. size_t variableSize( PrimitiveVariable::Interpolation interpolation ) const override; /// Returns the variable size for a single curve. diff --git a/include/IECoreScene/DiskPrimitive.h b/include/IECoreScene/DiskPrimitive.h index fa1a50190a..eb2d6bcfa7 100644 --- a/include/IECoreScene/DiskPrimitive.h +++ b/include/IECoreScene/DiskPrimitive.h @@ -67,7 +67,6 @@ class IECORESCENE_API DiskPrimitive : public Primitive size_t variableSize( PrimitiveVariable::Interpolation interpolation ) const override; Imath::Box3f bound() const override; - void render( Renderer *renderer ) const override; void topologyHash( IECore::MurmurHash &h ) const override; diff --git a/include/IECoreScene/ExternalProcedural.h b/include/IECoreScene/ExternalProcedural.h index 4e33c248c6..b7f418ada1 100644 --- a/include/IECoreScene/ExternalProcedural.h +++ b/include/IECoreScene/ExternalProcedural.h @@ -65,7 +65,6 @@ class IECORESCENE_API ExternalProcedural : public VisibleRenderable IECore::CompoundData *parameters(); const IECore::CompoundData *parameters() const; - void render( Renderer *renderer ) const override; Imath::Box3f bound() const override; private : diff --git a/include/IECoreScene/Group.h b/include/IECoreScene/Group.h index 3f0b52be10..84d11d8497 100644 --- a/include/IECoreScene/Group.h +++ b/include/IECoreScene/Group.h @@ -121,18 +121,6 @@ class IECORESCENE_API Group : public VisibleRenderable Group *parent(); const Group *parent() const; - /// Renders all the children in an attribute block along - /// with the transform and state. - void render( Renderer *renderer ) const override; - /// As above, but can optionally omit the - /// attribute block scoping. - void render( Renderer *renderer, bool inAttributeBlock ) const; - /// Renders all the held state, without any attributeBegin/End. - /// Doesn't render the transform. - void renderState( Renderer *renderer ) const; - /// Renders all the held children, without any attributeBegin/End. - void renderChildren( Renderer *renderer ) const; - /// Returns the union of the bounds of the children, transformed /// by transformMatrix(). Imath::Box3f bound() const override; diff --git a/include/IECoreScene/Light.h b/include/IECoreScene/Light.h index a8dd8b355b..57fe57a68e 100644 --- a/include/IECoreScene/Light.h +++ b/include/IECoreScene/Light.h @@ -68,9 +68,6 @@ class IECORESCENE_API Light : public StateRenderable IECore::CompoundDataPtr parametersData(); const IECore::CompoundDataPtr parametersData() const; - /// Sets this light in Renderer. - void render( Renderer *renderer ) const override; - private: static TypeDescription m_description; diff --git a/include/IECoreScene/MatrixMotionTransform.h b/include/IECoreScene/MatrixMotionTransform.h index e653780043..c5bcd075c1 100644 --- a/include/IECoreScene/MatrixMotionTransform.h +++ b/include/IECoreScene/MatrixMotionTransform.h @@ -54,7 +54,6 @@ class IECORESCENE_API MatrixMotionTransform : public Transform MatrixMotionTransform(); ~MatrixMotionTransform() override; - void render( Renderer *renderer ) const override; Imath::M44f transform( float time = 0 ) const override; //! @name Snapshots diff --git a/include/IECoreScene/MatrixTransform.h b/include/IECoreScene/MatrixTransform.h index 63b28a8b88..9f804166d2 100644 --- a/include/IECoreScene/MatrixTransform.h +++ b/include/IECoreScene/MatrixTransform.h @@ -50,7 +50,6 @@ class IECORESCENE_API MatrixTransform : public Transform MatrixTransform( const Imath::M44f &matrix = Imath::M44f() ); ~MatrixTransform() override; - void render( Renderer *renderer ) const override; Imath::M44f transform( float time = 0 ) const override; /// The transform this object applies. It can diff --git a/include/IECoreScene/MeshPrimitive.h b/include/IECoreScene/MeshPrimitive.h index 649b724e91..e5f916f81d 100644 --- a/include/IECoreScene/MeshPrimitive.h +++ b/include/IECoreScene/MeshPrimitive.h @@ -152,9 +152,6 @@ class IECORESCENE_API MeshPrimitive : public Primitive size_t variableSize( PrimitiveVariable::Interpolation interpolation ) const override; - /// Render the mesh - void render( Renderer *renderer ) const override; - /// Creates a box mesh. /// \todo Add subdivisions and texture coordinates. static MeshPrimitivePtr createBox( const Imath::Box3f &b ); diff --git a/include/IECoreScene/MotionPrimitive.h b/include/IECoreScene/MotionPrimitive.h index 5ca95817e9..c4136a92bc 100644 --- a/include/IECoreScene/MotionPrimitive.h +++ b/include/IECoreScene/MotionPrimitive.h @@ -75,9 +75,6 @@ class IECORESCENE_API MotionPrimitive : public VisibleRenderable void removeSnapshot( PrimitivePtr primitive ); //@} - /// May throw an Exception if the contained Primitives are not - /// compatible with each other. - void render( Renderer *renderer ) const override; Imath::Box3f bound() const override; private: diff --git a/include/IECoreScene/NURBSPrimitive.h b/include/IECoreScene/NURBSPrimitive.h index 9dab831af1..c149c0061d 100644 --- a/include/IECoreScene/NURBSPrimitive.h +++ b/include/IECoreScene/NURBSPrimitive.h @@ -81,8 +81,6 @@ class IECORESCENE_API NURBSPrimitive : public Primitive size_t variableSize( PrimitiveVariable::Interpolation interpolation ) const override; - void render( Renderer *renderer ) const override; - void topologyHash( IECore::MurmurHash &h ) const override; private: diff --git a/include/IECoreScene/Options.h b/include/IECoreScene/Options.h index 1710c81fde..88bb707301 100644 --- a/include/IECoreScene/Options.h +++ b/include/IECoreScene/Options.h @@ -61,9 +61,6 @@ class IECORESCENE_API Options : public PreWorldRenderable /// (it calls readable() or writable() for you). IECore::CompoundDataPtr optionsData(); - /// Calls renderer->setOptions() for each name, data pair in options() - void render( Renderer *renderer ) const override; - private: IECore::CompoundDataPtr m_options; diff --git a/include/IECoreScene/Output.h b/include/IECoreScene/Output.h index 952514e2d7..b8718ed087 100644 --- a/include/IECoreScene/Output.h +++ b/include/IECoreScene/Output.h @@ -69,8 +69,6 @@ class IECORESCENE_API Output : public PreWorldRenderable IECore::CompoundData *parametersData(); const IECore::CompoundData *parametersData() const; - void render( Renderer *renderer ) const override; - private: std::string m_name; diff --git a/include/IECoreScene/PatchMeshPrimitive.h b/include/IECoreScene/PatchMeshPrimitive.h index 7fc99c4431..1bb8473880 100644 --- a/include/IECoreScene/PatchMeshPrimitive.h +++ b/include/IECoreScene/PatchMeshPrimitive.h @@ -82,8 +82,6 @@ class IECORESCENE_API PatchMeshPrimitive : public Primitive bool uPeriodic() const; bool vPeriodic() const; - void render( Renderer *renderer ) const override; - /// Follows the RenderMan specification for variable sizes. size_t variableSize( PrimitiveVariable::Interpolation interpolation ) const override; diff --git a/include/IECoreScene/PointsPrimitive.h b/include/IECoreScene/PointsPrimitive.h index 6d4adc5779..30db1058b1 100644 --- a/include/IECoreScene/PointsPrimitive.h +++ b/include/IECoreScene/PointsPrimitive.h @@ -74,8 +74,6 @@ class IECORESCENE_API PointsPrimitive : public Primitive /// and 1 for all other types. size_t variableSize( PrimitiveVariable::Interpolation interpolation ) const override; - void render( Renderer *renderer ) const override; - void topologyHash( IECore::MurmurHash &h ) const override; private: diff --git a/include/IECoreScene/Renderable.h b/include/IECoreScene/Renderable.h index ac275bebd1..4cb26d6398 100644 --- a/include/IECoreScene/Renderable.h +++ b/include/IECoreScene/Renderable.h @@ -43,8 +43,6 @@ namespace IECoreScene { -IE_CORE_FORWARDDECLARE( Renderer ); - /// An abstract class to define objects which are renderable /// \ingroup renderingGroup class IECORESCENE_API Renderable : public IECore::BlindDataHolder @@ -56,9 +54,6 @@ class IECORESCENE_API Renderable : public IECore::BlindDataHolder IE_CORE_DECLAREEXTENSIONOBJECT( Renderable, RenderableTypeId, IECore::BlindDataHolder ); - /// Render the object held by this instance via the given renderer. - virtual void render( Renderer *renderer ) const = 0; - private: static const unsigned int m_ioVersion; diff --git a/include/IECoreScene/Shader.h b/include/IECoreScene/Shader.h index d0d45074fa..9abf500a08 100644 --- a/include/IECoreScene/Shader.h +++ b/include/IECoreScene/Shader.h @@ -72,9 +72,6 @@ class IECORESCENE_API Shader : public StateRenderable IECore::CompoundData *parametersData(); const IECore::CompoundData *parametersData() const; - /// Sets this shader as the current shader in Renderer. - void render( Renderer *renderer ) const override; - private: std::string m_name; diff --git a/include/IECoreScene/SpherePrimitive.h b/include/IECoreScene/SpherePrimitive.h index c3594b413a..52118edb1e 100644 --- a/include/IECoreScene/SpherePrimitive.h +++ b/include/IECoreScene/SpherePrimitive.h @@ -84,8 +84,6 @@ class IECORESCENE_API SpherePrimitive : public Primitive size_t variableSize( PrimitiveVariable::Interpolation interpolation ) const override; Imath::Box3f bound() const override; - /// Render the sphere - void render( Renderer *renderer ) const override; void topologyHash( IECore::MurmurHash &h ) const override; diff --git a/include/IECoreVDB/VDBObject.h b/include/IECoreVDB/VDBObject.h index 699d03cf52..3bc9e5f516 100644 --- a/include/IECoreVDB/VDBObject.h +++ b/include/IECoreVDB/VDBObject.h @@ -81,7 +81,6 @@ class IECOREVDB_API VDBObject : public IECoreScene::VisibleRenderable std::vector gridNames() const; Imath::Box3f bound() const override; - void render( IECoreScene::Renderer *renderer ) const override; IECore::CompoundObjectPtr metadata( const std::string &name ); diff --git a/src/IECoreScene/AttributeState.cpp b/src/IECoreScene/AttributeState.cpp index 63616ee038..f1892464bc 100644 --- a/src/IECoreScene/AttributeState.cpp +++ b/src/IECoreScene/AttributeState.cpp @@ -34,8 +34,6 @@ #include "IECoreScene/AttributeState.h" -#include "IECoreScene/Renderer.h" - using namespace IECore; using namespace IECoreScene; using namespace boost; @@ -73,14 +71,6 @@ CompoundDataPtr AttributeState::attributesData() return m_attributes; } -void AttributeState::render( Renderer *renderer ) const -{ - for( CompoundDataMap::const_iterator it=attributes().begin(); it!=attributes().end(); it++ ) - { - renderer->setAttribute( it->first, it->second ); - } -} - bool AttributeState::isEqualTo( const Object *other ) const { if( !StateRenderable::isEqualTo( other ) ) diff --git a/src/IECoreScene/Camera.cpp b/src/IECoreScene/Camera.cpp index 727a8ae689..b70ccfef72 100644 --- a/src/IECoreScene/Camera.cpp +++ b/src/IECoreScene/Camera.cpp @@ -36,8 +36,6 @@ #include "IECore/AngleConversion.h" -#include "IECoreScene/Renderer.h" - #include "IECore/MurmurHash.h" #include "IECore/SimpleTypedData.h" @@ -438,9 +436,3 @@ void Camera::setFocalLengthFromFieldOfView( float horizontalFOV ) { setFocalLength( getAperture()[0] * 0.5f / tan( 0.5f * IECore::degreesToRadians( horizontalFOV ) ) ); } - -void Camera::render( Renderer *renderer ) const -{ - // The old renderer interface takes unused name parameter - renderer->camera( "", m_parameters->readable() ); -} diff --git a/src/IECoreScene/ClippingPlane.cpp b/src/IECoreScene/ClippingPlane.cpp index 470893c09a..37716e6227 100644 --- a/src/IECoreScene/ClippingPlane.cpp +++ b/src/IECoreScene/ClippingPlane.cpp @@ -34,8 +34,6 @@ #include "IECoreScene/ClippingPlane.h" -#include "IECoreScene/Renderer.h" - using namespace IECore; using namespace IECoreScene; @@ -78,8 +76,3 @@ void ClippingPlane::hash( MurmurHash &h ) const { PreWorldRenderable::hash( h ); } - -void ClippingPlane::render( Renderer *renderer ) const -{ - renderer->command( "clippingPlane", CompoundDataMap() ); -} diff --git a/src/IECoreScene/CoordinateSystem.cpp b/src/IECoreScene/CoordinateSystem.cpp index edf175705f..b7cd32ffde 100644 --- a/src/IECoreScene/CoordinateSystem.cpp +++ b/src/IECoreScene/CoordinateSystem.cpp @@ -34,9 +34,7 @@ #include "IECoreScene/CoordinateSystem.h" -#include "IECoreScene/Renderer.h" #include "IECoreScene/Transform.h" -#include "IECoreScene/TransformBlock.h" #include "IECore/MurmurHash.h" @@ -88,18 +86,6 @@ void CoordinateSystem::setTransform( TransformPtr transform ) m_transform = transform; } -void CoordinateSystem::render( Renderer *renderer ) const -{ - TransformBlock transformBlock( renderer, static_cast( m_transform ) ); - - if( m_transform ) - { - m_transform->render( renderer ); - } - - renderer->coordinateSystem( m_name ); -} - bool CoordinateSystem::isEqualTo( const Object *other ) const { if( !StateRenderable::isEqualTo( other ) ) diff --git a/src/IECoreScene/CurvesPrimitive.cpp b/src/IECoreScene/CurvesPrimitive.cpp index 7e2c712160..6ac82db2be 100644 --- a/src/IECoreScene/CurvesPrimitive.cpp +++ b/src/IECoreScene/CurvesPrimitive.cpp @@ -34,8 +34,6 @@ #include "IECoreScene/CurvesPrimitive.h" -#include "IECoreScene/Renderer.h" - #include "IECore/MurmurHash.h" using namespace IECore; @@ -215,11 +213,6 @@ void CurvesPrimitive::setTopology( ConstIntVectorDataPtr verticesPerCurve, const } } -void CurvesPrimitive::render( Renderer *renderer ) const -{ - renderer->curves( m_basis, m_periodic, m_vertsPerCurve, variables ); -} - size_t CurvesPrimitive::variableSize( PrimitiveVariable::Interpolation interpolation ) const { switch( interpolation ) diff --git a/src/IECoreScene/DiskPrimitive.cpp b/src/IECoreScene/DiskPrimitive.cpp index 410aded8cb..e36ddf8277 100644 --- a/src/IECoreScene/DiskPrimitive.cpp +++ b/src/IECoreScene/DiskPrimitive.cpp @@ -34,8 +34,6 @@ #include "IECoreScene/DiskPrimitive.h" -#include "IECoreScene/Renderer.h" - #include "IECore/Exception.h" #include "IECore/MurmurHash.h" @@ -126,12 +124,6 @@ Imath::Box3f DiskPrimitive::bound() const ); } -void DiskPrimitive::render( Renderer *renderer ) const -{ - assert( renderer ); - renderer->disk( m_radius, m_z, m_thetaMax, variables ); -} - void DiskPrimitive::copyFrom( const Object *other, IECore::Object::CopyContext *context ) { Primitive::copyFrom( other, context ); diff --git a/src/IECoreScene/ExternalProcedural.cpp b/src/IECoreScene/ExternalProcedural.cpp index f403131ccd..04cf3e65ea 100644 --- a/src/IECoreScene/ExternalProcedural.cpp +++ b/src/IECoreScene/ExternalProcedural.cpp @@ -34,8 +34,6 @@ #include "IECoreScene/ExternalProcedural.h" -#include "IECoreScene/Renderer.h" - using namespace IECore; using namespace IECoreScene; @@ -86,11 +84,6 @@ const CompoundData *ExternalProcedural::parameters() const return m_parameters.get(); } -void ExternalProcedural::render( Renderer *renderer ) const -{ - renderer->procedural( new Renderer::ExternalProcedural( m_fileName, m_bound, m_parameters->readable() ) ); -} - Imath::Box3f ExternalProcedural::bound() const { return m_bound; diff --git a/src/IECoreScene/Group.cpp b/src/IECoreScene/Group.cpp index 430fe73c97..97ad0ac17e 100644 --- a/src/IECoreScene/Group.cpp +++ b/src/IECoreScene/Group.cpp @@ -34,9 +34,7 @@ #include "IECoreScene/Group.h" -#include "IECoreScene/AttributeBlock.h" #include "IECoreScene/AttributeState.h" -#include "IECoreScene/Renderer.h" #include "IECore/MurmurHash.h" @@ -440,41 +438,6 @@ void Group::hash( MurmurHash &h ) const } } -void Group::render( Renderer *renderer ) const -{ - render( renderer, true ); -} - -void Group::render( Renderer *renderer, bool inAttributeBlock ) const -{ - /// \todo I wonder if this should just use a transform block if - /// the Group doesn't have any state? - AttributeBlock attributeBlock( renderer, inAttributeBlock ); - - if( m_transform ) - { - m_transform->render( renderer ); - } - renderState( renderer ); - renderChildren( renderer ); -} - -void Group::renderState( Renderer *renderer ) const -{ - for( StateContainer::const_iterator it=state().begin(); it!=state().end(); it++ ) - { - (*it)->render( renderer ); - } -} - -void Group::renderChildren( Renderer *renderer ) const -{ - for( ChildContainer::const_iterator it=children().begin(); it!=children().end(); it++ ) - { - (*it)->render( renderer ); - } -} - Imath::Box3f Group::bound() const { Box3f result; diff --git a/src/IECoreScene/Light.cpp b/src/IECoreScene/Light.cpp index ecd463704a..558478e4fc 100644 --- a/src/IECoreScene/Light.cpp +++ b/src/IECoreScene/Light.cpp @@ -34,8 +34,6 @@ #include "IECoreScene/Light.h" -#include "IECoreScene/Renderer.h" - #include "IECore/MurmurHash.h" #include "boost/format.hpp" @@ -105,11 +103,6 @@ const CompoundDataPtr Light::parametersData() const return m_parameters; } -void Light::render( Renderer *renderer ) const -{ - renderer->light( m_name, m_handle, parameters() ); -} - bool Light::isEqualTo( const Object *other ) const { if( !StateRenderable::isEqualTo( other ) ) diff --git a/src/IECoreScene/MatrixMotionTransform.cpp b/src/IECoreScene/MatrixMotionTransform.cpp index 82f381b61f..db9ed78606 100644 --- a/src/IECoreScene/MatrixMotionTransform.cpp +++ b/src/IECoreScene/MatrixMotionTransform.cpp @@ -34,8 +34,6 @@ #include "IECoreScene/MatrixMotionTransform.h" -#include "IECoreScene/Renderer.h" - #include "IECore/MurmurHash.h" #include "Imath/ImathFun.h" @@ -63,31 +61,6 @@ MatrixMotionTransform::~MatrixMotionTransform() { } -void MatrixMotionTransform::render( Renderer *renderer ) const -{ - if( !m_snapshots.size() ) - { - return; - } - if( m_snapshots.size()==1 ) - { - renderer->concatTransform( m_snapshots.begin()->second ); - return; - } - - set times; - for( SnapshotMap::const_iterator it = m_snapshots.begin(); it!=m_snapshots.end(); it++ ) - { - times.insert( it->first ); - } - renderer->motionBegin( times ); - for( SnapshotMap::const_iterator it = m_snapshots.begin(); it!=m_snapshots.end(); it++ ) - { - renderer->concatTransform( it->second ); - } - renderer->motionEnd(); -} - Imath::M44f MatrixMotionTransform::transform( float time ) const { if( !m_snapshots.size() ) diff --git a/src/IECoreScene/MatrixTransform.cpp b/src/IECoreScene/MatrixTransform.cpp index 6ad433f106..1c28c7d434 100644 --- a/src/IECoreScene/MatrixTransform.cpp +++ b/src/IECoreScene/MatrixTransform.cpp @@ -34,8 +34,6 @@ #include "IECoreScene/MatrixTransform.h" -#include "IECoreScene/Renderer.h" - #include "IECore/MurmurHash.h" using namespace IECore; @@ -55,11 +53,6 @@ MatrixTransform::~MatrixTransform() { } -void MatrixTransform::render( Renderer *renderer ) const -{ - renderer->concatTransform( matrix ); -} - Imath::M44f MatrixTransform::transform( float time ) const { return matrix; diff --git a/src/IECoreScene/MeshPrimitive.cpp b/src/IECoreScene/MeshPrimitive.cpp index 7825b617a9..1567c4500e 100644 --- a/src/IECoreScene/MeshPrimitive.cpp +++ b/src/IECoreScene/MeshPrimitive.cpp @@ -35,7 +35,6 @@ #include "IECoreScene/MeshPrimitive.h" #include "IECoreScene/PolygonIterator.h" -#include "IECoreScene/Renderer.h" #include "IECore/ClassData.h" #include "IECore/MurmurHash.h" @@ -454,11 +453,6 @@ size_t MeshPrimitive::variableSize( PrimitiveVariable::Interpolation interpolati } } -void MeshPrimitive::render( Renderer *renderer ) const -{ - renderer->mesh( m_verticesPerFace, m_vertexIds, m_interpolation, variables ); -} - void MeshPrimitive::copyFrom( const Object *other, IECore::Object::CopyContext *context ) { Primitive::copyFrom( other, context ); diff --git a/src/IECoreScene/MotionPrimitive.cpp b/src/IECoreScene/MotionPrimitive.cpp index efc3cb8f6c..ee72208da5 100644 --- a/src/IECoreScene/MotionPrimitive.cpp +++ b/src/IECoreScene/MotionPrimitive.cpp @@ -34,8 +34,6 @@ #include "IECoreScene/MotionPrimitive.h" -#include "IECoreScene/Renderer.h" - #include "IECore/MurmurHash.h" #include "boost/format.hpp" @@ -96,51 +94,6 @@ MotionPrimitive::SnapshotMap &MotionPrimitive::snapshots() return m_snapshots; } -void MotionPrimitive::render( Renderer *renderer ) const -{ - if( !m_snapshots.size() ) - { - return; - } - if( m_snapshots.size()==1 ) - { - m_snapshots.begin()->second->render( renderer ); - return; - } - - IECore::TypeId t = m_snapshots.begin()->second->typeId(); - size_t cs = m_snapshots.begin()->second->variableSize( PrimitiveVariable::Constant ); - size_t us = m_snapshots.begin()->second->variableSize( PrimitiveVariable::Uniform ); - size_t vs = m_snapshots.begin()->second->variableSize( PrimitiveVariable::Varying ); - size_t ves = m_snapshots.begin()->second->variableSize( PrimitiveVariable::Vertex ); - size_t fs = m_snapshots.begin()->second->variableSize( PrimitiveVariable::FaceVarying ); - - set times; - for( SnapshotMap::const_iterator it=m_snapshots.begin(); it!=m_snapshots.end(); it++ ) - { - if( it->second->typeId()!=t ) - { - throw Exception( "Primitive types do not match." ); - } - if( it->second->variableSize( PrimitiveVariable::Constant )!=cs || - it->second->variableSize( PrimitiveVariable::Uniform )!=us || - it->second->variableSize( PrimitiveVariable::Varying )!=vs || - it->second->variableSize( PrimitiveVariable::Vertex )!=ves || - it->second->variableSize( PrimitiveVariable::FaceVarying )!=fs - ) - { - throw Exception( "Primitive variable sizes do not match." ); - } - times.insert( it->first ); - } - renderer->motionBegin( times ); - for( SnapshotMap::const_iterator it=m_snapshots.begin(); it!=m_snapshots.end(); it++ ) - { - it->second->render( renderer ); - } - renderer->motionEnd(); -} - Imath::Box3f MotionPrimitive::bound() const { Imath::Box3f result; diff --git a/src/IECoreScene/NURBSPrimitive.cpp b/src/IECoreScene/NURBSPrimitive.cpp index 239d63b5a3..5d3725c74d 100644 --- a/src/IECoreScene/NURBSPrimitive.cpp +++ b/src/IECoreScene/NURBSPrimitive.cpp @@ -34,8 +34,6 @@ #include "IECoreScene/NURBSPrimitive.h" -#include "IECoreScene/Renderer.h" - #include "IECore/MurmurHash.h" using namespace std; @@ -253,11 +251,6 @@ size_t NURBSPrimitive::variableSize( PrimitiveVariable::Interpolation interpolat } } -void NURBSPrimitive::render( Renderer *renderer ) const -{ - renderer->nurbs( m_uOrder, m_uKnot, m_uMin, m_uMax, m_vOrder, m_vKnot, m_vMin, m_vMax, variables ); -} - void NURBSPrimitive::copyFrom( const Object *other, IECore::Object::CopyContext *context ) { Primitive::copyFrom( other, context ); diff --git a/src/IECoreScene/Options.cpp b/src/IECoreScene/Options.cpp index 7e0f759233..730cbacc41 100644 --- a/src/IECoreScene/Options.cpp +++ b/src/IECoreScene/Options.cpp @@ -35,8 +35,6 @@ #include "IECoreScene/Options.h" -#include "IECoreScene/Renderer.h" - using namespace IECore; using namespace IECoreScene; using namespace boost; @@ -74,14 +72,6 @@ CompoundDataPtr Options::optionsData() return m_options; } -void Options::render( Renderer *renderer ) const -{ - for( CompoundDataMap::const_iterator it=options().begin(); it!=options().end(); it++ ) - { - renderer->setOption( it->first, it->second ); - } -} - bool Options::isEqualTo( const Object *other ) const { if( !PreWorldRenderable::isEqualTo( other ) ) diff --git a/src/IECoreScene/Output.cpp b/src/IECoreScene/Output.cpp index 2bd380a0b3..bc9fe38e65 100644 --- a/src/IECoreScene/Output.cpp +++ b/src/IECoreScene/Output.cpp @@ -34,8 +34,6 @@ #include "IECoreScene/Output.h" -#include "IECoreScene/Renderer.h" - #include "IECore/MurmurHash.h" using namespace IECore; @@ -194,8 +192,3 @@ const IECore::CompoundData *Output::parametersData() const { return m_parameters.get(); } - -void Output::render( Renderer *renderer ) const -{ - renderer->display( m_name, m_type, m_data, m_parameters->readable() ); -} diff --git a/src/IECoreScene/PatchMeshPrimitive.cpp b/src/IECoreScene/PatchMeshPrimitive.cpp index 2bb320b38e..e7207da1e0 100644 --- a/src/IECoreScene/PatchMeshPrimitive.cpp +++ b/src/IECoreScene/PatchMeshPrimitive.cpp @@ -34,8 +34,6 @@ #include "IECoreScene/PatchMeshPrimitive.h" -#include "IECoreScene/Renderer.h" - #include "IECore/MurmurHash.h" #include "IECore/SimpleTypedData.h" @@ -327,19 +325,6 @@ bool PatchMeshPrimitive::vPeriodic() const return m_vPeriodic; } -void PatchMeshPrimitive::render( Renderer *renderer ) const -{ - renderer->patchMesh( - m_uBasis, - m_vBasis, - m_uPoints, - m_uPeriodic, - m_vPoints, - m_vPeriodic, - Primitive::variables - ); -} - size_t PatchMeshPrimitive::variableSize( PrimitiveVariable::Interpolation interpolation ) const { switch ( interpolation ) diff --git a/src/IECoreScene/PointsPrimitive.cpp b/src/IECoreScene/PointsPrimitive.cpp index 4e86e317c1..524266de0e 100644 --- a/src/IECoreScene/PointsPrimitive.cpp +++ b/src/IECoreScene/PointsPrimitive.cpp @@ -34,8 +34,6 @@ #include "IECoreScene/PointsPrimitive.h" -#include "IECoreScene/Renderer.h" - #include "IECore/MessageHandler.h" #include "IECore/MurmurHash.h" #include "IECore/SimpleTypedData.h" @@ -251,8 +249,3 @@ size_t PointsPrimitive::variableSize( PrimitiveVariable::Interpolation interpola return 1; } } - -void PointsPrimitive::render( Renderer *renderer ) const -{ - renderer->points( getNumPoints(), variables ); -} diff --git a/src/IECoreScene/Renderable.cpp b/src/IECoreScene/Renderable.cpp index dbcda09526..ceaa002a2f 100644 --- a/src/IECoreScene/Renderable.cpp +++ b/src/IECoreScene/Renderable.cpp @@ -82,11 +82,3 @@ void Renderable::hash( MurmurHash &h ) const { BlindDataHolder::hash( h ); } - -void Renderable::render( Renderer *renderer ) const -{ -#ifndef NDEBUG - bool unimplemented = false; - assert(unimplemented); -#endif -} diff --git a/src/IECoreScene/Shader.cpp b/src/IECoreScene/Shader.cpp index 6bad2f2f88..2ab1474109 100644 --- a/src/IECoreScene/Shader.cpp +++ b/src/IECoreScene/Shader.cpp @@ -34,8 +34,6 @@ #include "IECoreScene/Shader.h" -#include "IECoreScene/Renderer.h" - #include "IECore/MurmurHash.h" using namespace IECore; @@ -103,11 +101,6 @@ const CompoundData *Shader::parametersData() const return m_parameters.get(); } -void Shader::render( Renderer *renderer ) const -{ - renderer->shader( m_type, m_name, parameters() ); -} - bool Shader::isEqualTo( const Object *other ) const { if( !StateRenderable::isEqualTo( other ) ) diff --git a/src/IECoreScene/SpherePrimitive.cpp b/src/IECoreScene/SpherePrimitive.cpp index 54144ddcda..0a0602f031 100644 --- a/src/IECoreScene/SpherePrimitive.cpp +++ b/src/IECoreScene/SpherePrimitive.cpp @@ -34,8 +34,6 @@ #include "IECoreScene/SpherePrimitive.h" -#include "IECoreScene/Renderer.h" - #include "IECore/Exception.h" #include "IECore/MurmurHash.h" #include "IECore/SimpleTypedData.h" @@ -155,12 +153,6 @@ Imath::Box3f SpherePrimitive::bound() const ); } -void SpherePrimitive::render( Renderer *renderer ) const -{ - assert( renderer ); - renderer->sphere( m_radius, m_zMin, m_zMax, m_thetaMax, variables ); -} - void SpherePrimitive::copyFrom( const Object *other, IECore::Object::CopyContext *context ) { Primitive::copyFrom( other, context ); diff --git a/src/IECoreScene/bindings/GroupBinding.cpp b/src/IECoreScene/bindings/GroupBinding.cpp index 6744b45f47..aa9d002688 100644 --- a/src/IECoreScene/bindings/GroupBinding.cpp +++ b/src/IECoreScene/bindings/GroupBinding.cpp @@ -39,7 +39,6 @@ #include "GroupBinding.h" #include "IECoreScene/Group.h" -#include "IECoreScene/Renderer.h" #include "IECorePython/RunTimeTypedBinding.h" #include "IECorePython/ScopedGILRelease.h" @@ -74,30 +73,6 @@ static list state( Group &g ) return result; } -static void render( const Group &group, Renderer *renderer ) -{ - IECorePython::ScopedGILRelease gilRelease; - group.render( renderer ); -} - -static void render2( const Group &group, Renderer *renderer, bool inAttributeBlock ) -{ - IECorePython::ScopedGILRelease gilRelease; - group.render( renderer, inAttributeBlock ); -} - -static void renderState( const Group &group, Renderer *renderer ) -{ - IECorePython::ScopedGILRelease gilRelease; - group.renderState( renderer ); -} - -static void renderChildren( const Group &group, Renderer *renderer ) -{ - IECorePython::ScopedGILRelease gilRelease; - group.renderChildren( renderer ); -} - static DataPtr getAttribute( Group &g, const std::string &name ) { ConstDataPtr d = g.getAttribute( name ); @@ -132,10 +107,6 @@ void bindGroup() .def( "transformMatrix", &Group::transformMatrix, transformMatrixOverloads() ) .def( "globalTransformMatrix", &Group::globalTransformMatrix, globalTransformMatrixOverloads() ) .def( "parent", (Group *(Group::*)())&Group::parent, return_value_policy() ) - .def( "render", &render ) - .def( "render", &render2 ) - .def( "renderState", &renderState ) - .def( "renderChildren", &renderChildren ) ; } diff --git a/src/IECoreScene/bindings/RenderableBinding.cpp b/src/IECoreScene/bindings/RenderableBinding.cpp index caf4185320..a9c8100c25 100644 --- a/src/IECoreScene/bindings/RenderableBinding.cpp +++ b/src/IECoreScene/bindings/RenderableBinding.cpp @@ -39,7 +39,6 @@ #include "RenderableBinding.h" #include "IECoreScene/Renderable.h" -#include "IECoreScene/Renderer.h" #include "IECorePython/RunTimeTypedBinding.h" #include "IECorePython/ScopedGILRelease.h" @@ -51,16 +50,9 @@ using namespace IECoreScene; namespace IECoreSceneModule { -static void render( const Renderable &renderable, Renderer *renderer ) -{ - IECorePython::ScopedGILRelease gilRelease; - renderable.render( renderer ); -} - void bindRenderable() { RunTimeTypedClass( "An abstract class to define objects which are renderable" ) - .def( "render", &render ) ; } diff --git a/src/IECoreVDB/VDBObject.cpp b/src/IECoreVDB/VDBObject.cpp index 8a3d8244e0..d6726aeba7 100644 --- a/src/IECoreVDB/VDBObject.cpp +++ b/src/IECoreVDB/VDBObject.cpp @@ -195,10 +195,6 @@ Imath::Box3f VDBObject::bound() const return combinedBounds; } -void VDBObject::render( IECoreScene::Renderer *renderer ) const -{ -} - IECore::CompoundObjectPtr VDBObject::metadata( const std::string &name ) { CompoundObjectPtr metadata = new CompoundObject(); From 9313e33708cf01dcfc2475790e7d73ca7f846cf3 Mon Sep 17 00:00:00 2001 From: John Haddon Date: Wed, 9 Jul 2025 16:50:52 +0100 Subject: [PATCH 04/15] Remove `*Block` classes used with Renderer These are no longer used now that we're removed `Renderable::render()`. --- Changes | 1 + include/IECoreScene/AttributeBlock.h | 69 -------------------------- include/IECoreScene/EditBlock.h | 73 ---------------------------- include/IECoreScene/MotionBlock.h | 69 -------------------------- include/IECoreScene/TransformBlock.h | 69 -------------------------- include/IECoreScene/WorldBlock.h | 69 -------------------------- python/IECoreScene/AttributeBlock.py | 51 ------------------- python/IECoreScene/EditBlock.py | 51 ------------------- python/IECoreScene/MotionBlock.py | 52 -------------------- python/IECoreScene/TransformBlock.py | 51 ------------------- python/IECoreScene/WorldBlock.py | 51 ------------------- python/IECoreScene/__init__.py | 5 -- src/IECoreScene/AttributeBlock.cpp | 56 --------------------- src/IECoreScene/EditBlock.cpp | 58 ---------------------- src/IECoreScene/MotionBlock.cpp | 56 --------------------- src/IECoreScene/TransformBlock.cpp | 56 --------------------- src/IECoreScene/WorldBlock.cpp | 56 --------------------- 17 files changed, 1 insertion(+), 892 deletions(-) delete mode 100644 include/IECoreScene/AttributeBlock.h delete mode 100644 include/IECoreScene/EditBlock.h delete mode 100644 include/IECoreScene/MotionBlock.h delete mode 100644 include/IECoreScene/TransformBlock.h delete mode 100644 include/IECoreScene/WorldBlock.h delete mode 100644 python/IECoreScene/AttributeBlock.py delete mode 100644 python/IECoreScene/EditBlock.py delete mode 100644 python/IECoreScene/MotionBlock.py delete mode 100644 python/IECoreScene/TransformBlock.py delete mode 100644 python/IECoreScene/WorldBlock.py delete mode 100644 src/IECoreScene/AttributeBlock.cpp delete mode 100644 src/IECoreScene/EditBlock.cpp delete mode 100644 src/IECoreScene/MotionBlock.cpp delete mode 100644 src/IECoreScene/TransformBlock.cpp delete mode 100644 src/IECoreScene/WorldBlock.cpp diff --git a/Changes b/Changes index 1bd712a0db..5b99c9b673 100644 --- a/Changes +++ b/Changes @@ -13,6 +13,7 @@ Breaking Changes ---------------- - Renderable : Removed `render()` method. +- AttributeBlock, EditBlock, MotionBlock, TransformBlock, WorldBlock : Removed. - IECoreHoudini : Removed. - IECoreMaya : Removed. - IECoreNuke : Removed. diff --git a/include/IECoreScene/AttributeBlock.h b/include/IECoreScene/AttributeBlock.h deleted file mode 100644 index 08a5306dbf..0000000000 --- a/include/IECoreScene/AttributeBlock.h +++ /dev/null @@ -1,69 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2009-2011, 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 Image Engine Design 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 IECORESCENE_ATTRIBUTEBLOCK_H -#define IECORESCENE_ATTRIBUTEBLOCK_H - -#include "IECoreScene/Export.h" -#include "IECoreScene/Renderer.h" - -#include "boost/noncopyable.hpp" - -namespace IECoreScene -{ - -/// The AttributeBlock class provides a simple means of ensuring that renderer->attributeBegin() -/// calls are matched by renderer->attributeEnd() calls, even in the face of exceptions and -/// multiple return statements from a function. -/// \ingroup renderingGroup -class IECORESCENE_API AttributeBlock : public boost::noncopyable -{ - public : - - /// Starts a new attribute block, calling renderer->attributeBegin(). If active is false - /// then nothing is done. - AttributeBlock( RendererPtr renderer, bool active=true ); - /// Closes the attribute block by calling renderer->attributeEnd(). If active was false - /// in the constructor then nothing is done. - ~AttributeBlock(); - - private : - - RendererPtr m_renderer; - -}; - -} // namespace IECoreScene - -#endif // IECORESCENE_ATTRIBUTEBLOCK_H diff --git a/include/IECoreScene/EditBlock.h b/include/IECoreScene/EditBlock.h deleted file mode 100644 index 2cf2126a68..0000000000 --- a/include/IECoreScene/EditBlock.h +++ /dev/null @@ -1,73 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// 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 Image Engine Design 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 IECORESCENE_EDITBLOCK_H -#define IECORESCENE_EDITBLOCK_H - -#include "IECoreScene/Export.h" - -#include "IECore/CompoundData.h" - -#include "boost/noncopyable.hpp" - -namespace IECoreScene -{ - -class Renderer; - -/// The EditBlock class provides a simple means of ensuring that renderer->editBegin() -/// calls are matched by renderer->editEnd() calls, even in the face of exceptions and -/// multiple return statements from a function. -/// \ingroup renderingGroup -class IECORESCENE_API EditBlock : public boost::noncopyable -{ - - public : - - /// Starts a new edit block, calling renderer->editBegin(). If renderer is NULL - /// then nothing is done, otherwise it is the responsibility of the caller to - /// ensure the renderer remains alive for the lifetime of this object. - EditBlock( Renderer *renderer, const std::string &editType, const IECore::CompoundDataMap ¶meters ); - /// Closes the edit block by calling renderer->editEnd(). - ~EditBlock(); - - private : - - Renderer *m_renderer; - -}; - -} // namespace IECoreScene - -#endif // IECORESCENE_EDITBLOCK_H diff --git a/include/IECoreScene/MotionBlock.h b/include/IECoreScene/MotionBlock.h deleted file mode 100644 index f63903a101..0000000000 --- a/include/IECoreScene/MotionBlock.h +++ /dev/null @@ -1,69 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2011, 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 Image Engine Design 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 IECORESCENE_MOTIONBLOCK_H -#define IECORESCENE_MOTIONBLOCK_H - -#include "IECoreScene/Export.h" -#include "IECoreScene/Renderer.h" - -#include "boost/noncopyable.hpp" - -namespace IECoreScene -{ - -/// The MotionBlock class provides a simple means of ensuring that renderer->motionBegin() -/// calls are matched by renderer->motionEnd() calls, even in the face of exceptions and -/// multiple return statements from a function. -/// \ingroup renderingGroup -class IECORESCENE_API MotionBlock : public boost::noncopyable -{ - public : - - /// Starts a new motion block, calling renderer->motionBegin(). If active is false - /// or times.size() < 2 then nothing is done. - MotionBlock( RendererPtr renderer, const std::set ×, bool active=true ); - /// Closes the motion block by calling renderer->motionEnd(), unless no block was - /// created in the constructor for any reason. - ~MotionBlock(); - - private : - - RendererPtr m_renderer; - -}; - -} // namespace IECoreScene - -#endif // IECORESCENE_MOTIONBLOCK_H diff --git a/include/IECoreScene/TransformBlock.h b/include/IECoreScene/TransformBlock.h deleted file mode 100644 index 6278917360..0000000000 --- a/include/IECoreScene/TransformBlock.h +++ /dev/null @@ -1,69 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2010-2011, 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 Image Engine Design 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 IECORESCENE_TRANSFORMBLOCK_H -#define IECORESCENE_TRANSFORMBLOCK_H - -#include "IECoreScene/Export.h" -#include "IECoreScene/Renderer.h" - -#include "boost/noncopyable.hpp" - -namespace IECoreScene -{ - -/// The TransformBlock class provides a simple means of ensuring that renderer->transformBegin() -/// calls are matched by renderer->transformEnd() calls, even in the face of exceptions and -/// multiple return statements from a function. -/// \ingroup renderingGroup -class IECORESCENE_API TransformBlock : public boost::noncopyable -{ - public : - - /// Starts a new transform block, calling renderer->transformBegin(). If active is false - /// then nothing is done. - TransformBlock( RendererPtr renderer, bool active=true ); - /// Closes the transform block by calling renderer->transformEnd(). If active was false - /// in the constructor then nothing is done. - ~TransformBlock(); - - private : - - RendererPtr m_renderer; - -}; - -} // namespace IECoreScene - -#endif // IECORESCENE_TRANSFORMBLOCK_H diff --git a/include/IECoreScene/WorldBlock.h b/include/IECoreScene/WorldBlock.h deleted file mode 100644 index a3ad413f8c..0000000000 --- a/include/IECoreScene/WorldBlock.h +++ /dev/null @@ -1,69 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2010-2011, 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 Image Engine Design 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 IECORESCENE_WORLDBLOCK_H -#define IECORESCENE_WORLDBLOCK_H - -#include "IECoreScene/Export.h" -#include "IECoreScene/Renderer.h" - -#include "boost/noncopyable.hpp" - -namespace IECoreScene -{ - -/// The WorldBlock class provides a simple means of ensuring that renderer->worldBegin() -/// calls are matched by renderer->worldEnd() calls, even in the face of exceptions and -/// multiple return statements from a function. -/// \ingroup renderingGroup -class IECORESCENE_API WorldBlock : public boost::noncopyable -{ - public : - - /// Starts a new world block, calling renderer->worldBegin(). If active is false - /// then nothing is done. - WorldBlock( RendererPtr renderer, bool active=true ); - /// Closes the world block by calling renderer->worldEnd(). If active was false - /// in the constructor then nothing is done. - ~WorldBlock(); - - private : - - RendererPtr m_renderer; - -}; - -} // namespace IECoreScene - -#endif // IECORESCENE_WORLDBLOCK_H diff --git a/python/IECoreScene/AttributeBlock.py b/python/IECoreScene/AttributeBlock.py deleted file mode 100644 index 6c8dc382ca..0000000000 --- a/python/IECoreScene/AttributeBlock.py +++ /dev/null @@ -1,51 +0,0 @@ -########################################################################## -# -# Copyright (c) 2008, 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 Image Engine Design 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. -# -########################################################################## - -## A context object intended for use with python's "with" syntax. It calls -# renderer.attributeBegin() in enter and renderer.attributeEnd() in exit. -class AttributeBlock : - - def __init__( self, renderer ) : - - self.__renderer = renderer - - def __enter__( self ) : - - self.__renderer.attributeBegin() - - def __exit__( self, type, value, traceBack ) : - - self.__renderer.attributeEnd() - - diff --git a/python/IECoreScene/EditBlock.py b/python/IECoreScene/EditBlock.py deleted file mode 100644 index 4cb188e676..0000000000 --- a/python/IECoreScene/EditBlock.py +++ /dev/null @@ -1,51 +0,0 @@ -########################################################################## -# -# 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 Image Engine Design 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. -# -########################################################################## - -class EditBlock : - - def __init__( self, renderer, editType, parameters ) : - - self.__renderer = renderer - self.__editType = editType - self.__parameters = parameters - - def __enter__( self ) : - - if self.__renderer is not None : - self.__renderer.editBegin( self.__editType, self.__parameters ) - - def __exit__( self, type, value, traceBack ) : - - if self.__renderer is not None : - self.__renderer.editEnd() diff --git a/python/IECoreScene/MotionBlock.py b/python/IECoreScene/MotionBlock.py deleted file mode 100644 index c5a0b17fe0..0000000000 --- a/python/IECoreScene/MotionBlock.py +++ /dev/null @@ -1,52 +0,0 @@ -########################################################################## -# -# Copyright (c) 2009, 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 Image Engine Design 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. -# -########################################################################## - -## A context object intended for use with python's "with" syntax. It calls -# renderer.motionBegin() in enter and renderer.motionEnd() in exit. -class MotionBlock : - - def __init__( self, renderer, times ) : - - self.__renderer = renderer - self.__times = times - - def __enter__( self ) : - - self.__renderer.motionBegin( self.__times ) - - def __exit__( self, type, value, traceBack ) : - - self.__renderer.motionEnd() - - diff --git a/python/IECoreScene/TransformBlock.py b/python/IECoreScene/TransformBlock.py deleted file mode 100644 index ef500308fd..0000000000 --- a/python/IECoreScene/TransformBlock.py +++ /dev/null @@ -1,51 +0,0 @@ -########################################################################## -# -# Copyright (c) 2008, 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 Image Engine Design 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. -# -########################################################################## - -## A context object intended for use with python's "with" syntax. It calls -# renderer.transformBegin() in enter and renderer.transformEnd() in exit. -class TransformBlock : - - def __init__( self, renderer ) : - - self.__renderer = renderer - - def __enter__( self ) : - - self.__renderer.transformBegin() - - def __exit__( self, type, value, traceBack ) : - - self.__renderer.transformEnd() - - diff --git a/python/IECoreScene/WorldBlock.py b/python/IECoreScene/WorldBlock.py deleted file mode 100644 index 543a2c5bba..0000000000 --- a/python/IECoreScene/WorldBlock.py +++ /dev/null @@ -1,51 +0,0 @@ -########################################################################## -# -# Copyright (c) 2008, 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 Image Engine Design 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. -# -########################################################################## - -## A context object intended for use with python's "with" syntax. It calls -# renderer.worldBegin() in enter and renderer.worldEnd() in exit. -class WorldBlock : - - def __init__( self, renderer ) : - - self.__renderer = renderer - - def __enter__( self ) : - - self.__renderer.worldBegin() - - def __exit__( self, type, value, traceBack ) : - - self.__renderer.worldEnd() - - diff --git a/python/IECoreScene/__init__.py b/python/IECoreScene/__init__.py index bdb7e1d134..0e435943a0 100644 --- a/python/IECoreScene/__init__.py +++ b/python/IECoreScene/__init__.py @@ -38,11 +38,6 @@ from .RemovePrimitiveVariables import RemovePrimitiveVariables from .RenamePrimitiveVariables import RenamePrimitiveVariables -from .AttributeBlock import AttributeBlock -from .TransformBlock import TransformBlock -from .WorldBlock import WorldBlock -from .EditBlock import EditBlock -from .MotionBlock import MotionBlock from .IDXReader import IDXReader from .SWAReader import SWAReader diff --git a/src/IECoreScene/AttributeBlock.cpp b/src/IECoreScene/AttributeBlock.cpp deleted file mode 100644 index ea9843462f..0000000000 --- a/src/IECoreScene/AttributeBlock.cpp +++ /dev/null @@ -1,56 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2009-2010, 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 Image Engine Design 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. -// -////////////////////////////////////////////////////////////////////////// - -#include "IECoreScene/AttributeBlock.h" - -using namespace IECore; -using namespace IECoreScene; - -AttributeBlock::AttributeBlock( RendererPtr renderer, bool active ) - : m_renderer( active ? renderer : nullptr ) -{ - if( m_renderer ) - { - m_renderer->attributeBegin(); - } -} - -AttributeBlock::~AttributeBlock() -{ - if( m_renderer ) - { - m_renderer->attributeEnd(); - } -} - diff --git a/src/IECoreScene/EditBlock.cpp b/src/IECoreScene/EditBlock.cpp deleted file mode 100644 index e045e0fda0..0000000000 --- a/src/IECoreScene/EditBlock.cpp +++ /dev/null @@ -1,58 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// 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 Image Engine Design 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. -// -////////////////////////////////////////////////////////////////////////// - -#include "IECoreScene/EditBlock.h" - -#include "IECoreScene/Renderer.h" - -using namespace IECore; -using namespace IECoreScene; - -EditBlock::EditBlock( Renderer *renderer, const std::string &editType, const CompoundDataMap ¶meters ) - : m_renderer( renderer ) -{ - if( m_renderer ) - { - m_renderer->editBegin( editType, parameters ); - } -} - -EditBlock::~EditBlock() -{ - if( m_renderer ) - { - m_renderer->editEnd(); - } -} - diff --git a/src/IECoreScene/MotionBlock.cpp b/src/IECoreScene/MotionBlock.cpp deleted file mode 100644 index 23a731cbbf..0000000000 --- a/src/IECoreScene/MotionBlock.cpp +++ /dev/null @@ -1,56 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2011, 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 Image Engine Design 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. -// -////////////////////////////////////////////////////////////////////////// - -#include "IECoreScene/MotionBlock.h" - -using namespace IECore; -using namespace IECoreScene; - -MotionBlock::MotionBlock( RendererPtr renderer, const std::set ×, bool active ) - : m_renderer( ( active && times.size() > 1 ) ? renderer : nullptr ) -{ - if( m_renderer ) - { - m_renderer->motionBegin( times ); - } -} - -MotionBlock::~MotionBlock() -{ - if( m_renderer ) - { - m_renderer->motionEnd(); - } -} - diff --git a/src/IECoreScene/TransformBlock.cpp b/src/IECoreScene/TransformBlock.cpp deleted file mode 100644 index 657d1c2bef..0000000000 --- a/src/IECoreScene/TransformBlock.cpp +++ /dev/null @@ -1,56 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2010, 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 Image Engine Design 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. -// -////////////////////////////////////////////////////////////////////////// - -#include "IECoreScene/TransformBlock.h" - -using namespace IECore; -using namespace IECoreScene; - -TransformBlock::TransformBlock( RendererPtr renderer, bool active ) - : m_renderer( active ? renderer : nullptr ) -{ - if( m_renderer ) - { - m_renderer->transformBegin(); - } -} - -TransformBlock::~TransformBlock() -{ - if( m_renderer ) - { - m_renderer->transformEnd(); - } -} - diff --git a/src/IECoreScene/WorldBlock.cpp b/src/IECoreScene/WorldBlock.cpp deleted file mode 100644 index 5911eea27e..0000000000 --- a/src/IECoreScene/WorldBlock.cpp +++ /dev/null @@ -1,56 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2010, 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 Image Engine Design 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. -// -////////////////////////////////////////////////////////////////////////// - -#include "IECoreScene/WorldBlock.h" - -using namespace IECore; -using namespace IECoreScene; - -WorldBlock::WorldBlock( RendererPtr renderer, bool active ) - : m_renderer( active ? renderer : nullptr ) -{ - if( m_renderer ) - { - m_renderer->worldBegin(); - } -} - -WorldBlock::~WorldBlock() -{ - if( m_renderer ) - { - m_renderer->worldEnd(); - } -} - From ac1348a7e6795d76c04efc989a9444314d3add65 Mon Sep 17 00:00:00 2001 From: John Haddon Date: Tue, 8 Jul 2025 09:52:14 +0100 Subject: [PATCH 05/15] IECoreScene : Remove Renderer class This was superseded by Gaffer's own Renderer class way back in 2016. Removing it paves the way for Gaffer's version making its way back into Cortex. --- Changes | 2 +- include/IECoreGL/Renderer.h | 501 ---- include/IECoreGL/TypeIds.h | 8 +- include/IECoreGL/bindings/RendererBinding.h | 45 - .../IECoreGL/private/RendererImplementation.h | 118 - .../private/RendererImplementation.inl | 55 - include/IECoreScene/Renderer.h | 415 ---- include/IECoreScene/TypeIds.h | 2 +- .../DeferredRendererImplementation.cpp | 532 ----- .../ImmediateRendererImplementation.cpp | 225 -- src/IECoreGL/Renderer.cpp | 2078 ----------------- src/IECoreGL/RendererImplementation.cpp | 45 - src/IECoreGL/bindings/IECoreGLBinding.cpp | 2 - src/IECoreGL/bindings/RendererBinding.cpp | 91 - src/IECoreScene/Renderer.cpp | 102 - src/IECoreScene/bindings/IECoreScene.cpp | 2 - src/IECoreScene/bindings/RendererBinding.cpp | 432 ---- src/IECoreScene/bindings/RendererBinding.h | 43 - 18 files changed, 6 insertions(+), 4692 deletions(-) delete mode 100644 include/IECoreGL/Renderer.h delete mode 100644 include/IECoreGL/bindings/RendererBinding.h delete mode 100644 include/IECoreGL/private/RendererImplementation.h delete mode 100644 include/IECoreGL/private/RendererImplementation.inl delete mode 100644 include/IECoreScene/Renderer.h delete mode 100644 src/IECoreGL/DeferredRendererImplementation.cpp delete mode 100644 src/IECoreGL/ImmediateRendererImplementation.cpp delete mode 100644 src/IECoreGL/Renderer.cpp delete mode 100644 src/IECoreGL/RendererImplementation.cpp delete mode 100644 src/IECoreGL/bindings/RendererBinding.cpp delete mode 100644 src/IECoreScene/Renderer.cpp delete mode 100644 src/IECoreScene/bindings/RendererBinding.cpp delete mode 100644 src/IECoreScene/bindings/RendererBinding.h diff --git a/Changes b/Changes index 5b99c9b673..092419189a 100644 --- a/Changes +++ b/Changes @@ -13,7 +13,7 @@ Breaking Changes ---------------- - Renderable : Removed `render()` method. -- AttributeBlock, EditBlock, MotionBlock, TransformBlock, WorldBlock : Removed. +- Renderer, AttributeBlock, EditBlock, MotionBlock, TransformBlock, WorldBlock : Removed. - IECoreHoudini : Removed. - IECoreMaya : Removed. - IECoreNuke : Removed. diff --git a/include/IECoreGL/Renderer.h b/include/IECoreGL/Renderer.h deleted file mode 100644 index 028b746ab5..0000000000 --- a/include/IECoreGL/Renderer.h +++ /dev/null @@ -1,501 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2013, Image Engine Design Inc. All rights reserved. -// Copyright (c) 2011, John Haddon. 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 Image Engine Design 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 IECOREGL_RENDERER_H -#define IECOREGL_RENDERER_H - -#include "IECoreGL/Export.h" -#include "IECoreGL/TypeIds.h" - -#include "IECoreScene/Renderer.h" - -namespace IECoreGL -{ - -IE_CORE_FORWARDDECLARE( Scene ); -IE_CORE_FORWARDDECLARE( TextureLoader ); -IE_CORE_FORWARDDECLARE( ShaderLoader ); - -/// \addtogroup environmentGroup -/// -/// IECOREGL_SHADER_PATHS
-/// IECOREGL_SHADER_INCLUDE_PATHS
-/// IECOREGL_TEXTURE_PATHS
-/// IECORE_FONT_PATHS
-/// Used to specify default resource locations for the IECoreGL::Renderer. - -/// The IECoreGL::Renderer class implements the IECore::Renderer interface to -/// allow rendering to OpenGL. Immediate mode rendering allows the generation of -/// images and deferred mode rendering allows scenes to be captured for later interactive -/// display. -/// \ingroup renderingGroup -class IECOREGL_API Renderer : public IECoreScene::Renderer -{ - public : - - Renderer(); - ~Renderer() override; - - IE_CORE_DECLARERUNTIMETYPEDEXTENSION( IECoreGL::Renderer, RendererTypeId, IECoreScene::Renderer ); - - /// \par Standard options supported : - /// - /// \li "searchPath:font" - /// - /// \par Implementation specific options supported : - /// - /// "gl:mode" StringData - /// Valid values are "immediate" or "deferred". In immediate mode rendering is - /// performed in a streaming fashion, drawing each primitive as it is - /// specified. In deferred mode rendering is performed by building a Scene - /// object which can be retrieved for further use by using the scene() method - /// after the render is complete. Future versions may support advanced features - /// such as motion blur and depth of field when in deferred mode but not in immediate mode. - /// - /// "searchPath:shader" StringData - /// "gl:searchPath:shader" StringData - /// Specifies a set of colon separated paths on which to search for GLSL shaders. The default - /// value is obtained from the environment variable IECOREGL_SHADER_PATHS. - /// - /// "searchPath:shaderInclude" StringData - /// "gl:searchPath:shaderInclude" StringData - /// Specifies a set of colon separated paths on which to search for include files for GLSL shaders. The default - /// value is obtained from the environment variable IECOREGL_SHADER_INCLUDE_PATHS. - /// - /// "searchPath:texture" StringData - /// "gl:searchPath:texture" StringData - /// Specifies a set of colon separated paths on which to search for textures. The default - /// value is obtained from the environment variable IECOREGL_TEXTURE_PATHS. Any image file format - /// for which an IECore::Reader is available is suitable for use as a texture. - /// - /// "shutter" V2fData - /// - /// "gl:drawCoordinateSystems" BoolData false - /// When this is true, coordinate systems created with the coordinateSystem() method - /// will be visualised. - void setOption( const std::string &name, IECore::ConstDataPtr value ) override; - IECore::ConstDataPtr getOption( const std::string &name ) const override; - - void camera( const std::string &unusedName, const IECore::CompoundDataMap ¶meters ) override; - void display( const std::string &name, const std::string &type, const std::string &data, const IECore::CompoundDataMap ¶meters ) override; - - void worldBegin() override; - void worldEnd() override; - /// When in deferred mode (see setOption above), this method will return the Scene that - /// was generated. - /// \threading The Renderer tries very hard not to need a GL context to operate in when in deferred mode. This allows it to evaluate multiple - /// procedurals concurrently in separate threads (GL wants only one threading talking to a context). When the scene is rendered for the first - /// time it will instantiate various OpenGL resources (textures and shaders and the like) in the current GL context. It is therefore important that - /// the scene is destroyed from the same thread that renders it, so that the resources are released in the correct context. As the resources are - /// also shared by caches (TextureLoaders and ShaderLoaders) in the Renderer, it is also important that the renderer is destroyed from this same - /// thread. - ScenePtr scene(); - - void transformBegin() override; - void transformEnd() override; - void setTransform( const Imath::M44f &m ) override; - void setTransform( const std::string &coordinateSystem ) override; - Imath::M44f getTransform() const override; - Imath::M44f getTransform( const std::string &coordinateSystem ) const override; - void concatTransform( const Imath::M44f &m ) override; - void coordinateSystem( const std::string &name ) override; - - void attributeBegin() override; - void attributeEnd() override; - /// \par Standard attributes supported : - //////////////////////////////////////////////////////////// - /// - /// \li "color"
- /// Sets the rgb components of the current OpenGL - /// color. - /// \li "opacity"
- /// Sets the alpha component of the current OpenGL - /// color to the average of the rgb components of - /// opacity. - /// - /// \li "doubleSided" - /// \li "rightHandedOrientation" - /// \li "name" - /// - /// \li "user:*" - /// - /// \par Implementation specific attributes : - //////////////////////////////////////////////////////////// - /// - /// \li "gl:color" Color4fData Color4f( 1.0f ) - /// Sets the current OpenGL color including the - /// alpha component. - /// - /// \par Implementation specific shading attributes : - //////////////////////////////////////////////////////////// - /// - /// \li "gl:shade:transparent" BoolData false
- /// Signifies that shading may result in - /// transparent results. This is necessary as - /// it's nontrivial to determine this - /// information by querying the shader, and - /// other parts of the system may need to - /// know when transparency is present - for - /// example to trigger depth sorting. - /// - /// \par Implementation specific primitive style attributes : - //////////////////////////////////////////////////////////// - /// - /// \li "gl:primitive:wireframe" BoolData false
- /// Draw a wireframe for each primitive. - /// - /// \li "gl:primitive:wireframeWidth" FloatData 1.0f
- /// The line width of the wireframe of the primitive. - /// - /// \li "gl:primitive:wireframeColor" Color4fData
- /// The color of the wireframes drawn. - /// - /// \li "gl:primitive:bound" BoolData false
- /// Draw a bounding box for each primitive. - /// - /// \li "gl:primitive:boundColor" Color4fData
- /// The color of the bounding boxes drawn. - /// - /// \li "gl:primitive:solid" BoolData true
- /// Draw each primitive solid. - /// - /// \li "gl:primitive:outline" BoolData false
- /// Draw an outline for each primitive. Note that the results - /// of having this on with filled mode off will probably be - /// undesirable. - /// - /// \li "gl:primitive:outlineColor" Color4fData
- /// The color of the outlines drawn. - /// - /// \li "gl:primitive:outlineWidth" FloatData 1.0f
- /// The line width of the outlines of the primitive. - /// - /// \li "gl:primitive:points" BoolData false
- /// Draw the vertices of each primitive as points. - /// - /// \li "gl:primitive:pointWidth" FloatData 1.0f
- /// The width of the points used to draw vertices. - /// - /// \li "gl:primitive:pointColor" Color4fData
- /// The color of the points drawn. - /// - /// \li "gl:primitive:selectable" BoolData true
- /// Allow the primitive to be selected. ( ie. it will be drawn when we render for selection purposes ) - /// - /// \li "gl:primitive:sortForTransparency" BoolData true
- /// Causes the individual components of a - /// primitive to be sorted in depth when the "gl:shade:transparent" - /// attribute is true. - /// This is currently supported only by the - /// points primitive. - /// - /// \par Implementation specific points primitive attributes : - //////////////////////////////////////////////////////////// - /// - /// \li "gl:pointsPrimitive:useGLPoints" StringData "forGLPoints"
- /// Can be used to force the use of lightweight glPoints - /// representation of points primitives with types other than "gl:point". - /// Valid values are :

- /// "forGLPoints"
- /// Use lightweight points only if type is "gl:point"

- /// "forParticlesAndDisks"
- /// Use lightweight points as a stand in for particle and disk types.

- /// "forAll"
- /// Use lightweight points as a stand in for all point types.

- /// - /// \li "gl:pointsPrimitive:glPointWidth" FloatData 1.0f
- /// The size of the points (in pixels) used when rendering lightweight - /// points. - /// - /// \par Implementation specific curves primitive attributes : - //////////////////////////////////////////////////////////// - /// - /// \li "gl:curvesPrimitive:useGLLines" BoolData false
- /// When this is true then lightweight OpenGL line primitives are used - /// for representing curves. - /// - /// \li "gl:curvesPrimitive:glLineWidth" FloatData 1.0f
- /// Specifies the line width (in pixels) which is used when - /// rendering lightweight line primitives. - /// - /// \li "gl:curvesPrimitive:ignoreBasis" BoolData false
- /// When this is true, all curves are rendered as if they were linear. - /// - /// \par Implementation specific text primitive attributes : - //////////////////////////////////////////////////////////// - /// - /// \li "gl:textPrimitive:type" StringData "mesh"
- /// Controls the basic method used for text rendering. A value - /// of "mesh" specifies that text primitives are rendered as - /// triangulated meshes, and a value of "sprite" specifies rendering - /// as textured planes. The former allows completely customisable shading - /// using the current shader, whereas the latter is shaded constantly - /// using the current colour, but may offer better anti-aliasing and/or - /// speed. - /// - /// \par Implementation specific blending attributes : - //////////////////////////////////////////////////////////// - /// - /// \li "gl:blend:srcFactor" StringData "srcAlpha"
- /// \li "gl:blend:dstFactor" StringData "oneMinusSrcAlpha"
- /// These attributes are mapped onto calls to glBlendFunc. - /// They accept only the values below, which - /// correspond directly to one of the GLenum blending - /// values.

- /// "zero"
- /// "one"
- /// "srcColor"
- /// "oneMinusSrcColor"
- /// "dstColor"
- /// "oneMinusDstColor"
- /// "srcAlpha"
- /// "oneMinusSrcAlpha"
- /// "dstAlpha"
- /// "oneMinusDstAlpha"
- /// "constantColor"
- /// "oneMinusConstantColor"
- /// "constantAlpha"
- /// "oneMinusConstantAlpha"
- /// - /// \li "gl:blend:color" Color4fData 1 1 1 1
- /// Used to specify glBlendColor(), only taking effect when using - /// either "constantColor" or "oneMinusConstantColor" for one or - /// other of the blend factors above. - /// - /// \li "gl:blend:equation" StringData "add"
- /// Controls how the src and dst values are combined after being weighted - /// by srcFactor and dstFactor - this maps onto a call to glBlendEquation. - /// Valid values are listed below, and map directly onto the corresponding - /// GLenum values.

- /// "add"
- /// "subtract"
- /// "reverseSubtract"
- /// "min"
- /// "max"
- /// - /// \li "gl:alphaTest" BoolData false
- /// When this is true, gl alpha testing will be enabled. - /// - /// \li "gl:alphaTest:value" FloatData 0
- /// Alpha test comparison value for glAlphaFunc - /// - /// \li "gl:alphaTest:mode" StringData "always"
- /// Alpha test comparison mode for glAlphaFunc. - /// Valid values are listed below, and map directly onto the corresponding - /// GLenum values.

- /// "never"
- /// "less"
- /// "equal"
- /// "lequal"
- /// "greater"
- /// "notequal"
- /// "gequal"
- /// "always"
- /// - /// \par Implementation specific antialiasing attributes : - /////////////////////////////////////////////////////////// - /// - /// \li "gl:smoothing:points" BoolData false
- /// \li "gl:smoothing:lines" BoolData false
- /// \li "gl:smoothing:polygons" BoolData false
- /// These attributes enable GL_POINT_SMOOTH, GL_LINE_SMOOTH and - /// GL_POLYGON_SMOOTH respectively. - /// - /// \par Implementation specific procedural attributes : - //////////////////////////////////////////////////////////// - /// - /// \li "gl:procedural:reentrant" BoolData true
- /// When true, procedurals may be evaluated in multiple parallel threads. - /// When false they will be evaluated from the same thread they were specified - /// from. - /// \par Implementation specific depth buffer attributes : - //////////////////////////////////////////////////////////// - /// - /// \li "gl:depthTest" BoolData true
- /// Maps to glEnable/Disable GL_DEPTH_TEST - /// - /// \li "gl:depthMask" BoolData true
- /// Maps to glDepthMask GL_TRUE/GL_FALSE - /// - /// \par Implementation specific visibility attributes : - //////////////////////////////////////////////////////////// - /// - /// \li "gl:visibility:camera" BoolData true
- /// Specifies whether or not objects are visible to the camera. - /// If a procedural is not visible then it will not be opened - /// to discover if it's contents might turn visibility back on. - /// - /// \par Instancing attributes : - //////////////////////////////////////////////////////////// - /// - /// \li "automaticInstancing" BoolData true
- /// \li "gl:automaticInstancing" BoolData true
- /// Specifies that instances are automatically created if - /// identical primitives are passed to the renderer - /// repeatedly. This is currently implemented only for the - /// mesh, points and curves primitive types. - //////////////////////////////////////////////////////////// - void setAttribute( const std::string &name, IECore::ConstDataPtr value ) override; - IECore::ConstDataPtr getAttribute( const std::string &name ) const override; - /// Supports only shader type "surface" or "gl:surface", looking for "name.vert" and "name.frag" GLSL source files - /// in the paths defined by the "searchPath:shader" option. Alternatively if the parameter list contains - /// "gl:vertexSource" and/or a "gl:fragmentSource" StringData then a new shader is created using the source provided. - /// For shaders with sampler2D parameters, texture files for these parameters may be specified by passing the filename - /// to an image as StringData. - /// \todo Add support for "textureParameterName:filter" and "textureParameterName:wrap" parameters which set wrapping - /// and filtering on a ShaderStateComponent. - void shader( const std::string &type, const std::string &name, const IECore::CompoundDataMap ¶meters ) override; - void light( const std::string &name, const std::string &handle, const IECore::CompoundDataMap ¶meters ) override; - void illuminate( const std::string &lightHandle, bool on ) override; - - void motionBegin( const std::set × ) override; - void motionEnd() override; - - /// Supports the following primitive variables : - /// - /// Vertex V3fVectorData "P" - /// - /// Uniform StringData "type" - /// Used to determine how the points are rendered. Supported types are : - /// - /// "gl:point" - /// Rendered as GL_POINTS - /// - /// "particle" (the default) - /// "disk" - /// "blobby" - /// Rendered as camera facing disks. The "width" and "constantwidth" variables are supported. - /// Blobby is provided for vague compatibility with the IECoreRI::RIRenderer and 3delight. - /// - /// "patch" - /// Rendered as camera facing patches. Supports the "width" and "constantwidth" variables - /// and in addition the "patchaspectratio" and "patchrotation" variables. See the 3delight - /// documentation for a description of how these can be used. - /// - /// "sphere" - /// Rendered as spheres. Supports "width" and "constantwidth" variables to define the - /// sizes of the spheres. - /// - /// Constant FloatData "constantwidth" - /// - /// Vertex|Varying FloatVectorData "width" - /// - /// Constant|Vertex|Varying FloatData|FloatVectorData "patchaspectratio" - /// Constant|Vertex|Varying FloatData|FloatVectorData "patchrotation" - /// These two are used only by the "patch" type. - void points( size_t numPoints, const IECoreScene::PrimitiveVariableMap &primVars ) override; - void disk( float radius, float z, float thetaMax, const IECoreScene::PrimitiveVariableMap &primVars ) override; - /// Supports the following primitive variables : - /// - /// Vertex V3fVectorData "P" - /// Constant FloatData "width" - void curves( const IECore::CubicBasisf &basis, bool periodic, IECore::ConstIntVectorDataPtr numVertices, const IECoreScene::PrimitiveVariableMap &primVars ) override; - void text( const std::string &font, const std::string &text, float kerning = 1.0f, const IECoreScene::PrimitiveVariableMap &primVars=IECoreScene::PrimitiveVariableMap() ) override; - void sphere( float radius, float zMin, float zMax, float thetaMax, const IECoreScene::PrimitiveVariableMap &primVars ) override; - /// Supports the following image formats specified as primitive variables : - /// - /// "R", "G", "B", "A" : UCharVectorData - /// "R", "G", "B", "A" : CharVectorData - /// "R", "G", "B", "A" : UIntVectorData - /// "R", "G", "B", "A" : IntVectorData - /// "R", "G", "B", "A" : HalfVectorData - /// "R", "G", "B", "A" : FloatVectorData - /// "R", "G", "B", "A" : DoubleVectorData - /// - /// As a convenience the names "r", "g", "b", "a" or "red", "green", "blue", "alpha" can - /// appear in place of "R", "G", "B", "A". - /// - /// Currently assumes dataWindow==displayWindow. - void image( const Imath::Box2i &dataWindow, const Imath::Box2i &displayWindow, const IECoreScene::PrimitiveVariableMap &primVars ) override; - /// All meshes are treated as having interpolation=="linear". - /// \todo Support normals and st. - void mesh( IECore::ConstIntVectorDataPtr vertsPerFace, IECore::ConstIntVectorDataPtr vertIds, const std::string &interpolation, const IECoreScene::PrimitiveVariableMap &primVars ) override; - /// Not implemented - void nurbs( int uOrder, IECore::ConstFloatVectorDataPtr uKnot, float uMin, float uMax, int vOrder, IECore::ConstFloatVectorDataPtr vKnot, float vMin, float vMax, const IECoreScene::PrimitiveVariableMap &primVars ) override; - /// Not implemented - void patchMesh( const IECore::CubicBasisf &uBasis, const IECore::CubicBasisf &vBasis, int nu, bool uPeriodic, int nv, bool vPeriodic, const IECoreScene::PrimitiveVariableMap &primVars ) override; - /// Not implemented - void geometry( const std::string &type, const IECore::CompoundDataMap &topology, const IECoreScene::PrimitiveVariableMap &primVars ) override; - void procedural( IECoreScene::Renderer::ProceduralPtr proc ) override; - - void instanceBegin( const std::string &name, const IECore::CompoundDataMap ¶meters ) override; - void instanceEnd() override; - void instance( const std::string &name ) override; - - /// \par Commands implemented - /// - /// "removeObject"
- /// Expects a StringData parameter named "name", which specifies the name of an object to remove from the scene. - /// This only has any effect in deferred mode. - /// "editBegin"
- /// This parameter-less command marks the start of an edit to an existing scene, and should be called before - /// any other changes are made when re-using an existing renderer, that has already reached worldEnd. - /// "editEnd"
- /// This parameter-less command marks the end of an edit to an existing scene, and should be called after - /// other changes have been made when re-using an existing renderer. Note that if a scene has been drawn - /// with renderer->scene()->render() prior to this edit, then it is essential that editEnd is called by the - /// same thread on which drawing was performed, so that GL resources can be released in the appropriate context. - /// "editQuery"
- /// This parameter-less command returns BoolData( true ) if an edit is in progress, and BoolData( false ) - /// otherwise. - /// \todo Consider generalising an interface for scene edits and making it a standard part of the documentation - /// in IECore. Any such interface should take into account support for PRMan's new rerendering API. - IECore::DataPtr command( const std::string &name, const IECore::CompoundDataMap ¶meters ) override; - - /// \todo Implement the existing editing commands in this new form. - void editBegin( const std::string &name, const IECore::CompoundDataMap ¶meters ) override; - void editEnd() override; - - /// Returns the internal ShaderLoader object used to load the shaders for this renderer. - /// If called before worldBegin it returns 0. - ShaderLoader *shaderLoader(); - - /// Returns the internal TextureLoader object. - /// If called before worldBegin it returns 0. - TextureLoader *textureLoader(); - - struct MemberData; - - private : - - MemberData *m_data; - -}; - -IE_CORE_DECLAREPTR( Renderer ); - -} // namespace IECoreGL - -#endif // IECOREGL_RENDERER_H diff --git a/include/IECoreGL/TypeIds.h b/include/IECoreGL/TypeIds.h index 7645b9b97c..aadcadc37c 100644 --- a/include/IECoreGL/TypeIds.h +++ b/include/IECoreGL/TypeIds.h @@ -49,7 +49,7 @@ enum TypeId RenderableTypeId = 105006, BindableTypeId = 105007, TextureTypeId = 105008, - RendererTypeId = 105009, + RendererTypeId = 105009, // Obsolete, available for reuse ShaderTypeId = 105010, PrimitiveTypeId = 105011, PointsPrimitiveTypeId = 105012, @@ -58,8 +58,8 @@ enum TypeId QuadPrimitiveTypeId = 105015, SpherePrimitiveTypeId = 105016, BoxPrimitiveTypeId = 105017, - RendererImplementationTypeId = 105018, - DeferredRendererImplementationTypeId = 105019, + RendererImplementationTypeId = 105018, // Obsolete, available for reuse + DeferredRendererImplementationTypeId = 105019, // Obsolete, available for reuse PrimitiveWireframeWidthTypeId = 105020, PrimitiveOutlineWidthTypeId = 105021, PrimitivePointsTypeId = 105022, @@ -69,7 +69,7 @@ enum TypeId FrameBufferTypeId = 105026, DepthTextureTypeId = 105027, ColorTextureTypeId = 105028, - ImmediateRendererImplementationTypeId = 105029, + ImmediateRendererImplementationTypeId = 105029, // Obsolete, available for reuse BlendFuncStateComponentTypeId = 105030, BlendColorStateComponentTypeId = 105031, BlendEquationStateComponentTypeId = 105032, diff --git a/include/IECoreGL/bindings/RendererBinding.h b/include/IECoreGL/bindings/RendererBinding.h deleted file mode 100644 index 6ec9dea621..0000000000 --- a/include/IECoreGL/bindings/RendererBinding.h +++ /dev/null @@ -1,45 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007, 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 Image Engine Design 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 IE_COREGL_RENDERERBINDING_H -#define IE_COREGL_RENDERERBINDING_H - -namespace IECoreGL -{ - -void bindRenderer(); - -} - -#endif // IE_COREGL_RENDERERBINDING_H diff --git a/include/IECoreGL/private/RendererImplementation.h b/include/IECoreGL/private/RendererImplementation.h deleted file mode 100644 index f5d6b4ccd7..0000000000 --- a/include/IECoreGL/private/RendererImplementation.h +++ /dev/null @@ -1,118 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-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 Image Engine Design 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 IECOREGL_RENDERERIMPLEMENTATION_H -#define IECOREGL_RENDERERIMPLEMENTATION_H - -#include "IECoreGL/TypeIds.h" - -#include "IECoreScene/Renderer.h" - -#include "IECore/Data.h" -#include "IECore/Export.h" -#include "IECore/InternedString.h" -#include "IECore/RunTimeTyped.h" - -IECORE_PUSH_DEFAULT_VISIBILITY -#include "Imath/ImathMatrix.h" -IECORE_POP_DEFAULT_VISIBILITY - -namespace IECoreGL -{ - -IE_CORE_FORWARDDECLARE( StateComponent ); -IE_CORE_FORWARDDECLARE( Primitive ); -IE_CORE_FORWARDDECLARE( Camera ); -IE_CORE_FORWARDDECLARE( Display ); -IE_CORE_FORWARDDECLARE( Group ); - -/// RendererImplementation classes are used by the Renderer -/// class to do some of it's work. -class RendererImplementation : public IECore::RunTimeTyped -{ - - public : - - IE_CORE_DECLARERUNTIMETYPEDEXTENSION( RendererImplementation, RendererImplementationTypeId, IECore::RunTimeTyped ) - - RendererImplementation(); - ~RendererImplementation() override; - - /// Guaranteed to be called at least once before worldBegin(), - /// and never after worldBegin(). - virtual void addCamera( CameraPtr camera ) = 0; - /// Never called after worldBegin(). - virtual void addDisplay( ConstDisplayPtr display ) = 0; - - virtual void worldBegin() = 0; - virtual void worldEnd() = 0; - - /// Transform calls guaranteed only to be called after worldBegin(). - virtual void transformBegin() = 0; - virtual void transformEnd() = 0; - - virtual void setTransform( const Imath::M44f &m ) = 0; - virtual Imath::M44f getTransform() const = 0; - virtual void concatTransform( const Imath::M44f &matrix ) = 0; - - virtual void attributeBegin() = 0; - virtual void attributeEnd() = 0; - - virtual void addState( StateComponentPtr state ) = 0; - virtual StateComponent *getState( IECore::TypeId type ) = 0; - template - T *getState(); - - // Set a custom state - virtual void addUserAttribute( const IECore::InternedString &name, IECore::DataPtr value ) = 0; - // Get a custom state or 0 if not defined. - virtual IECore::Data *getUserAttribute( const IECore::InternedString &name ) = 0; - // Get a casted custom state or 0 if not present or incompatible type. - template - T *getUserAttribute( const IECore::InternedString &name ); - - virtual void addPrimitive( ConstPrimitivePtr primitive ) = 0; - - virtual void addProcedural( IECoreScene::Renderer::ProceduralPtr proc, IECoreScene::RendererPtr renderer ) = 0; - - virtual void addInstance( IECoreGL::GroupPtr grp ) = 0; -}; - -IE_CORE_DECLAREPTR( RendererImplementation ); - -} // namespace IECoreGL - -#include "IECoreGL/private/RendererImplementation.inl" - -#endif // IECOREGL_RENDERERIMPLEMENTATION_H diff --git a/include/IECoreGL/private/RendererImplementation.inl b/include/IECoreGL/private/RendererImplementation.inl deleted file mode 100644 index e5670912df..0000000000 --- a/include/IECoreGL/private/RendererImplementation.inl +++ /dev/null @@ -1,55 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2010, 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 Image Engine Design 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 IECOREGL_RENDERERIMPLEMENTATION_INL -#define IECOREGL_RENDERERIMPLEMENTATION_INL - -namespace IECoreGL -{ - -template -T *RendererImplementation::getState() -{ - return IECore::assertedStaticCast( getState( T::staticTypeId() ) ); -} - -template -T *RendererImplementation::getUserAttribute( const IECore::InternedString &name ) -{ - return IECore::runTimeCast( getUserAttribute( name ) ); -} - -} // namespace IECoreGL - -#endif // IECOREGL_RENDERERIMPLEMENTATION_H diff --git a/include/IECoreScene/Renderer.h b/include/IECoreScene/Renderer.h deleted file mode 100644 index 85a46526dc..0000000000 --- a/include/IECoreScene/Renderer.h +++ /dev/null @@ -1,415 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-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 Image Engine Design 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 IECORESCENE_RENDERER_H -#define IECORESCENE_RENDERER_H - -#include "IECoreScene/Export.h" -#include "IECoreScene/PrimitiveVariable.h" -#include "IECoreScene/TypeIds.h" - -#include "IECore/CompoundData.h" -#include "IECore/CubicBasis.h" -#include "IECore/Export.h" -#include "IECore/MurmurHash.h" -#include "IECore/RunTimeTyped.h" -#include "IECore/VectorTypedData.h" - -IECORE_PUSH_DEFAULT_VISIBILITY -#include "Imath/ImathBox.h" -#include "Imath/ImathMatrix.h" -IECORE_POP_DEFAULT_VISIBILITY - -#include - -namespace IECoreScene -{ - -IE_CORE_FORWARDDECLARE( Renderer ); - -/// The Renderer class provides a means of describing scenes for rendering. Its -/// interface is modelled closely on OpenGL/Renderman with an attribute and -/// transform stack etc. Renderer implementations should flag errors and warnings -/// using the MessageHandler class rather than by throwing Exceptions - it's often -/// more useful to have an incomplete image for diagnosis of the problem than to -/// have an Exception thrown. -/// -/// \par Naming conventions -/// -/// Many of the calls in the Renderer interface associate a name with a piece of -/// data. Both the setOption() and setAttribute() calls take a name to specify what -/// is being modified and a DataPtr to specify the new value. Many other calls -/// accept either a CompoundDataMap or a PrimitiveVariableMap, both of which may -/// contain many named pieces of Data. -/// -/// A naming convention exists to specify that particular data is intended only -/// for a particular Renderer implementation. This allows rendering to be -/// customised for a particular implementation without causing other implementations -/// to error due to unsupported features. The convention for each name is as -/// follows : -/// -/// \li "name"
-/// Should be supported by all Renderer implementations. For instance, the "doubleSided" -/// attribute should be supported by all Renderers. A warning message should be -/// output if the name is not recognised and supported. -/// -/// \li "prefix:name"
-/// Used to specify data intended only for a particular implementation. Implementations -/// silently ignore all data destined for other implementations. For instance, the -/// "gl:primitive:wireframe" attribute is used by the GL renderer implementation but -/// silently ignored by other implementations. -/// -/// \li "user:name"
-/// Used to specify data for the purposes of users. The renderer should store the value -/// and make it available for query, but otherwise it should have no effect. This applies -/// mostly to the attribute and option calls. -/// \ingroup renderingGroup -class IECORESCENE_API Renderer : public IECore::RunTimeTyped -{ - - public : - - IE_CORE_DECLARERUNTIMETYPEDEXTENSION( Renderer, RendererTypeId, IECore::RunTimeTyped ); - - Renderer(); - ~Renderer() override; - - //! @name Options - /// Options are named items of data which control some global aspect of the - /// render. These functions allow their setting and getting. All options must - /// be set before a call to worldBegin() - it is invalid to change an option - /// after worldBegin(). - /// - /// \par Standard SearchPath Options - ///
- /// \li "searchPath:font" StringData
- /// A colon separated list of paths to search for fonts on - these are used - /// by the text() primitive. The default value should come from the - /// IECORE_FONT_PATHS environment variable if set. - /// - /// \par Rerendering Options - ///
- /// \li "editable" BoolData
- /// This option must be set to enable the use of the interactive rerendering - /// methods defined below. - /////////////////////////////////////////////////////////////////////////// - //@{ - /// Set an option. Must not be called after worldBegin(). - virtual void setOption( const std::string &name, IECore::ConstDataPtr value ) = 0; - /// Get the value of a previously set option. - virtual IECore::ConstDataPtr getOption( const std::string &name ) const = 0; - //@} - - /// This renderer interface is now pretty heavily deprecated, in favor of the new - /// interface in Gaffer. - /// The camera name is now unused, since the only use of this interface - /// is now IECoreGL's renderers, which only support one camera anyway. - /// - /// We now have nice accessors on IECoreScene::Camera, so I would recommend using those - /// rather than manually setting parameter names here. If you have to use this - /// interface for some reason, I would recommend creating an IECoreScene::Camera, - /// using the accessors to set it up, and then calling - /// camera->render( renderer ); - virtual void camera( const std::string &unusedName, const IECore::CompoundDataMap ¶meters ) = 0; - - /// Specifies an image to be output from the renderer. In the case of file outputs name - /// specified the filename. type specifies the type of output to create and data specifies - /// the data to be output, for instance "rgba". parameters provides an implementation specific - /// set of parameters to control other aspects of the image created. It is only valid to call this - /// before worldBegin. - virtual void display( const std::string &name, const std::string &type, const std::string &data, const IECore::CompoundDataMap ¶meters ) = 0; - - //! @name World block - /// Once all options, cameras and displays are specified, a world block - /// is created in which the visible elements of the scene are described. - /////////////////////////////////////////////////////////////////////////// - //@{ - /// Starts the world block and resets the current transform to the - /// identity. - virtual void worldBegin() = 0; - /// Finishes the world block. - virtual void worldEnd() = 0; - //@} - - //! @name Transforms - /// The Renderer manages a hierarchical set of transforms, applying the - /// current transform to all cameras and primitives that are created. - /////////////////////////////////////////////////////////////////////////// - //@{ - /// Push a new transform state identical to the current one. Modifications - /// can then be made locally before calling transformEnd() to return to the - /// previous transform state. - virtual void transformBegin() = 0; - /// Returns to the transform state saved by the last transformBegin() call. - virtual void transformEnd() = 0; - /// Sets the current transform. - virtual void setTransform( const Imath::M44f &m ) = 0; - /// Sets the current transform to a coordinate system previously - /// created with a call to coordinateSystem(). - virtual void setTransform( const std::string &coordinateSystem ) = 0; - /// Returns the current transform. - virtual Imath::M44f getTransform() const = 0; - /// Returns the transform associated with the named coordinate system. - virtual Imath::M44f getTransform( const std::string &coordinateSystem ) const = 0; - /// Concatenates the specified transform onto the current transform. - virtual void concatTransform( const Imath::M44f &m ) = 0; - /// Creates a named coordinate system from the current transform. Coordinate systems - /// are scoped by attributeBegin/attributeEnd blocks. - virtual void coordinateSystem( const std::string &name ) = 0; - //@} - - //! @name Attributes - /// Attributes are named items of data which control some per-object aspect - /// of the render. Attributes may be set both before and after worldBegin(), - /// and are scoped between attributeBegin(), attributeEnd() calls. - //////////////////////////////////////////////////////////////////////////// - //@{ - /// Push a new attribute state onto the attribute stack. This is identical - /// to the current state, but subsequent calls to setAttribute() will be - /// discarded by the matching attributeEnd(). - virtual void attributeBegin() = 0; - /// Return to the attribute state saved by the last call to attributeBegin(). - virtual void attributeEnd() = 0; - /// Sets the named attribute to the specified value. - /// - /// \par Standard Attributes - ///
- /// The following standard attributes should be supported by all implementations - /// wherever possible : - /// - /// \li "color" Color3fData
- /// The color of primitives. Defaults to 1, 1, 1 if not specified. - /// - /// \li "opacity" Color3fData
- /// The opacity of primitives. Defaults to 1, 1, 1 if not specified. - /// - /// \li "doubleSided" BoolData
- /// When true both sides of a primitive are rendered, when false - /// only one side is. Defaults to true. - /// - /// \li "rightHandedOrientation" BoolData
- /// Controls which side of a primitive - /// is forward facing. This attribute starts with a value of true, - /// because the camera is specified in a right handed coordinate system - - /// a value of false specifies that the current orientation is left handed. - /// The renderer will automatically toggle the value whenever a transformation - /// flips the sense of the current object space coordinate system (this - /// happens when a transform has a negative determinant - typically a - /// negative scaling in some axis). You can change the interpretation of - /// "forward facing" by flipping the attribute value at any time - see - /// the documentation for the various primitives below for how orientation - /// affects the way their front face is defined. - /// - /// \li "name" StringData "unnamed"\li - /// A descriptive name for the object. - /// - /// \li "user:*"
- /// Should be stored for later query, but have no other effect upon the - /// rendering process. - virtual void setAttribute( const std::string &name, IECore::ConstDataPtr value ) = 0; - /// Return the value of the named attribute. - virtual IECore::ConstDataPtr getAttribute( const std::string &name ) const = 0; - /// Specifies a shader to be applied to subsequent primitives. - virtual void shader( const std::string &type, const std::string &name, const IECore::CompoundDataMap ¶meters ) = 0; - /// Specifies a light to apply to subsequent primitives. - virtual void light( const std::string &name, const std::string &handle, const IECore::CompoundDataMap ¶meters ) = 0; - /// Turns the specified light on or off for the current attribute state. - virtual void illuminate( const std::string &lightHandle, bool on ) = 0; - //@} - - //! @name Motion blur - //////////////////////////////////////////////////////////////////////////// - //@{ - /// Starts a new motion block. You should then make times.size() calls - /// to one of the primitive or transform functions to specify the motion - /// for the block. - virtual void motionBegin( const std::set × ) = 0; - /// Ends a motion block. Should be called when times.size() calls to an - /// appropriate primitive or transform function have been made following - /// a motionBegin() call. - virtual void motionEnd() = 0; - //@} - - //! @name Primitives - /// Primitives specify actual visible objects to be rendered. Each primitive - /// has a topology which is usually specified in a manner unique to that type, - /// and a set of PrimitiveVariables which is specified in the same manner - /// for all primitives - these specify data to vary over the surface of the - /// primitive. - /// \todo Better documentation for the calls below, particularly in relation - /// to the rightHandedOrientation attribute. - //////////////////////////////////////////////////////////////////////////// - //@{ - /// Renders a set of points. - virtual void points( size_t numPoints, const PrimitiveVariableMap &primVars ) = 0; - /// Renders a disk of the specified radius on the xy plane, at the specified z value. - /// If the "rightHandedOrientation" attribute is true then the normal faces down - /// positive z, otherwise it faces down negative z. - virtual void disk( float radius, float z, float thetaMax, const PrimitiveVariableMap &primVars ) = 0; - /// Renders a set of curves. - virtual void curves( const IECore::CubicBasisf &basis, bool periodic, IECore::ConstIntVectorDataPtr numVertices, const PrimitiveVariableMap &primVars ) = 0; - /// Renders some text. - virtual void text( const std::string &font, const std::string &text, float kerning = 1.0f, const PrimitiveVariableMap &primVars=PrimitiveVariableMap() ) = 0; - /// Renders a sphere of the specified radius. zMin and zMax are measured as a proportion of the radius - so no matter - /// what the radius, the default values will always give a full sphere. If the "rightHandedOrientation" - /// attribute is true then the normals point outwards, otherwise they point inwards. - /// \todo Give this the default values it talks about. - virtual void sphere( float radius, float zMin, float zMax, float thetaMax, const PrimitiveVariableMap &primVars ) = 0; - /// Renders an image. - /// \todo Clarify the intended use of dataWindow and displayWindow. - virtual void image( const Imath::Box2i &dataWindow, const Imath::Box2i &displayWindow, const PrimitiveVariableMap &primVars ) = 0; - /// Renders a mesh. The geometric normal of a face will be facing camera if the winding order of its vertices is anticlockwise from - /// the point of view of the camera and the "rightHandedOrientation" attribute is true. If the "rightHandedOrientation" attribute - /// is false then faces whose vertices wind /clockwise/ with respect to the camera are considered forward facing instead. - virtual void mesh( IECore::ConstIntVectorDataPtr vertsPerFace, IECore::ConstIntVectorDataPtr vertIds, const std::string &interpolation, const PrimitiveVariableMap &primVars ) = 0; - /// Renders a nurbs surface. - virtual void nurbs( int uOrder, IECore::ConstFloatVectorDataPtr uKnot, float uMin, float uMax, int vOrder, IECore::ConstFloatVectorDataPtr vKnot, float vMin, float vMax, const PrimitiveVariableMap &primVars ) = 0; - /// Render a patch mesh. - virtual void patchMesh( const IECore::CubicBasisf &uBasis, const IECore::CubicBasisf &vBasis, int nu, bool uPeriodic, int nv, bool vPeriodic, const PrimitiveVariableMap &primVars ) = 0; - /// Generic call for specifying renderer specify geometry types. - virtual void geometry( const std::string &type, const IECore::CompoundDataMap &topology, const PrimitiveVariableMap &primVars ) = 0; - //@} - - /// The Procedural class defines an interface via which the Renderer can - /// ask for geometry to be generated in a deferred fashion, at a time - /// which is convenient to it. - class IECORESCENE_API Procedural : public IECore::RefCounted - { - public : - - IE_CORE_DECLAREMEMBERPTR( Procedural ); - - Procedural(); - ~Procedural() override; - - /// Returns a bounding box guaranteed to completely - /// contain the geometry generated by the render() - /// method. - virtual Imath::Box3f bound() const = 0; - /// Called when the renderer is ready to receive the procedural - /// geometry. Any relevant methods of renderer may be called, but - /// the geometry generated must be contained within the - /// box returned by bound(). - virtual void render( Renderer *renderer ) const = 0; - /// Implement this to return a hash for procedural level instancing. - /// Procedurals with the same hash will be reused by renderers that - /// support this feature. If computing a sensible hash is difficult - /// or impossible, return IECore::MurmurHash() from this function - /// and this feature will be disabled. - virtual IECore::MurmurHash hash() const = 0; - - /// Sentinel value which may be returned by bound() - /// implementations if a bound is not available, or - /// computing one would be prohibitively expensive. - /// Renderers should expand such procedurals - /// unconditionally. - static const Imath::Box3f noBound; - - }; - IE_CORE_DECLAREPTR( Procedural ); - - /// A placeholder for specifying a procedural which the Renderer - /// must load from a file on disk. - class IECORESCENE_API ExternalProcedural : public Procedural - { - public : - - IE_CORE_DECLAREMEMBERPTR( ExternalProcedural ) - - ExternalProcedural( const std::string &fileName, const Imath::Box3f &bound, const IECore::CompoundDataMap ¶meters ); - ~ExternalProcedural() override; - - const std::string &fileName() const; - const IECore::CompoundDataMap ¶meters() const; - - Imath::Box3f bound() const override; - void render( Renderer *renderer ) const override; - IECore::MurmurHash hash() const override; - - private : - - std::string m_fileName; - Imath::Box3f m_bound; - IECore::CompoundDataMap m_parameters; - - }; - IE_CORE_DECLAREPTR( ExternalProcedural ); - - /// Renders a piece of procedural geometry. - virtual void procedural( ProceduralPtr proc ) = 0; - - //! @name Instancing - /// These methods provide a means of describing a portion of a scene once and reusing - /// it many times. - /////////////////////////////////////////////////////////////////////////////////////// - //@{ - /// Starts the description of a portion of a scene to be instanced. - virtual void instanceBegin( const std::string &name, const IECore::CompoundDataMap ¶meters ) = 0; - /// Ends the description of an instance. - virtual void instanceEnd() = 0; - /// Instantiates a previously described instance at the current transform position, and - /// using the current attribute state. - virtual void instance( const std::string &name ) = 0; - //@} - - /// Generic call for executing arbitrary renderer commands. This is intended to allow - /// derived classes to support calls such as RiMakeTexture via calls of the form - /// renderer->command( "ri:makeTexture", ... ). - /// - /// Renderers supporting arbitrary clipping planes should implement a "clippingPlane" - /// command which must be issued before worldBegin(), and which makes a clipping plane - /// using the current transformation. - /// - /// \todo Make a dedicated virtual clippingPlane() method for the next major version. - virtual IECore::DataPtr command( const std::string &name, const IECore::CompoundDataMap ¶meters ) = 0; - - //! @name Interactive rerendering - /// These methods provide a means of upating the scene following a call to worldEnd(), - /// causing the renderer to interactively rerender the scene. - /////////////////////////////////////////////////////////////////////////////////////// - //@{ - /// Starts a new scene edit of the specified type. The standard functions above for - /// declaring the scene can then be used to perform the edit. - /// \todo Better define the semantics of this function as we implement it for different - /// renderers. - virtual void editBegin( const std::string &editType, const IECore::CompoundDataMap ¶meters ) = 0; - /// Ends the current scene edit. - virtual void editEnd() = 0; - //@} - -}; - -} - -#endif // IECORESCENE_RENDERER_H diff --git a/include/IECoreScene/TypeIds.h b/include/IECoreScene/TypeIds.h index bfb8e42538..a6229acd94 100644 --- a/include/IECoreScene/TypeIds.h +++ b/include/IECoreScene/TypeIds.h @@ -47,7 +47,7 @@ enum TypeId ShaderTypeId = 108004, PDCParticleReaderTypeId = 108005, PDCParticleWriterTypeId = 108006, - RendererTypeId = 108007, + RendererTypeId = 108007, // Obsolete, available for reuse PrimitiveOpTypeId = 108008, ParticleReaderTypeId = 108009, ParticleWriterTypeId = 108010, diff --git a/src/IECoreGL/DeferredRendererImplementation.cpp b/src/IECoreGL/DeferredRendererImplementation.cpp deleted file mode 100644 index 13bc67b499..0000000000 --- a/src/IECoreGL/DeferredRendererImplementation.cpp +++ /dev/null @@ -1,532 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2012, 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 Image Engine Design 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. -// -////////////////////////////////////////////////////////////////////////// - -#include "IECoreGL/private/DeferredRendererImplementation.h" - -#include "IECoreGL/Camera.h" -#include "IECoreGL/Group.h" -#include "IECoreGL/Primitive.h" -#include "IECoreGL/Scene.h" -#include "IECoreGL/State.h" -#include "IECoreGL/StateComponent.h" -#include "IECoreGL/Texture.h" -#include "IECoreGL/private/Display.h" - -#include "IECore/MessageHandler.h" - -#include "boost/noncopyable.hpp" - -#include "tbb/task.h" -#include "tbb/task_scheduler_init.h" - -#include - -using namespace IECoreGL; -using namespace Imath; -using namespace std; - -DeferredRendererImplementation::DeferredRendererImplementation() -{ - - m_defaultContext = new RenderContext(); - m_defaultContext->transformStack.push( M44f() ); - - m_scene = new Scene; -} - -DeferredRendererImplementation::~DeferredRendererImplementation() -{ -} - -void DeferredRendererImplementation::addCamera( CameraPtr camera ) -{ - m_scene->setCamera( camera ); -} - -void DeferredRendererImplementation::addDisplay( ConstDisplayPtr display ) -{ - IECore::msg( IECore::Msg::Error, "DeferredRendererImplementation::addDisplay", "Not implemented" ); -} - -void DeferredRendererImplementation::worldBegin() -{ - if( m_defaultContext->transformStack.size()>1 ) - { - IECore::msg( IECore::Msg::Error, "DeferredRendererImplementation::worldBegin", "Mismatched transformBegin/transformEnd detected." ); - } - if( m_defaultContext->stateStack.size()>0 ) - { - IECore::msg( IECore::Msg::Error, "DeferredRendererImplementation::worldBegin", "Mismatched attributeBegin/attributeEnd detected." ); - } - - m_defaultContext->localTransform = M44f(); - m_defaultContext->transformStack = TransformStack(); - m_defaultContext->transformStack.push( M44f() ); - - m_defaultContext->stateStack.push_back( new State( false ) ); - - m_defaultContext->groupStack.push( m_scene->root() ); /// \todo this group should have the attribute state accumulated before worldBegin -} - -void DeferredRendererImplementation::worldEnd() -{ - // check if no procedural threads are running. - if ( m_threadContextPool.size() != 0 ) - { - IECore::msg( IECore::Msg::Error, "DeferredRendererImplementation::worldEnd", "Detected threads for procedural rendering that are still running!" ); - } - - if( m_defaultContext->transformStack.size()!=1 ) - { - IECore::msg( IECore::Msg::Error, "DeferredRendererImplementation::worldEnd", "Bad nesting of transformBegin/transformEnd detected." ); - } - - if( m_defaultContext->stateStack.size()!=1 ) - { - IECore::msg( IECore::Msg::Error, "DeferredRendererImplementation::worldEnd", "Bad nesting of attributeBegin/attributeEnd detected." ); - } - - m_defaultContext->localTransform = M44f(); - m_defaultContext->transformStack = TransformStack(); - m_defaultContext->transformStack.push( M44f() ); - - /// \todo This is where we would do our rendering and saving of images. -} - -void DeferredRendererImplementation::transformBegin() -{ - RenderContext *curContext = currentContext(); - - GroupPtr g = new Group; - g->setTransform( curContext->localTransform ); - { - std::lock_guard lock( curContext->groupStack.top()->mutex() ); - curContext->groupStack.top()->addChild( g ); - } - curContext->groupStack.push( g ); - - curContext->transformStack.push( curContext->localTransform * curContext->transformStack.top() ); - curContext->localTransform = Imath::M44f(); -} - -void DeferredRendererImplementation::transformEnd() -{ - RenderContext *curContext = currentContext(); - - if( curContext->transformStack.size()<=1 ) - { - IECore::msg( IECore::Msg::Warning, "DeferredRendererImplementation::transformEnd", "Bad nesting." ); - return; - } - - // recover local transform from group and remove group from stack - curContext->transformStack.pop(); - curContext->localTransform = curContext->groupStack.top()->getTransform(); - curContext->groupStack.pop(); - -} - -void DeferredRendererImplementation::setTransform( const Imath::M44f &m ) -{ - RenderContext *curContext = currentContext(); - - // figure out the local transformation from the last group that lead us to the given matrix. - curContext->localTransform = m * curContext->transformStack.top().inverse(); - -} - -Imath::M44f DeferredRendererImplementation::getTransform() const -{ - const RenderContext *curContext = currentContext(); - // return the current world matrix - return curContext->localTransform * curContext->transformStack.top(); -} - -void DeferredRendererImplementation::concatTransform( const Imath::M44f &matrix ) -{ - RenderContext *curContext = currentContext(); - - curContext->localTransform = matrix * curContext->localTransform; -} - -void DeferredRendererImplementation::attributeBegin() -{ - RenderContext *curContext = currentContext(); - - GroupPtr g = new Group; - g->setTransform( curContext->localTransform ); - g->setState( new State( **(curContext->stateStack.rbegin()) ) ); - { - std::lock_guard lock( curContext->groupStack.top()->mutex() ); - curContext->groupStack.top()->addChild( g ); - } - curContext->groupStack.push( g ); - - curContext->transformStack.push( curContext->localTransform * curContext->transformStack.top() ); - curContext->localTransform = Imath::M44f(); - curContext->stateStack.push_back( new State( false ) ); -} - -void DeferredRendererImplementation::attributeEnd() -{ - RenderContext *curContext = currentContext(); - - if( curContext->stateStack.size()<=1 ) - { - IECore::msg( IECore::Msg::Warning, "DeferredRendererImplementation::attributeEnd", "Bad nesting." ); - return; - } - curContext->stateStack.pop_back(); - - // recover local transform from group and remove group from stack - curContext->transformStack.pop(); - curContext->localTransform = curContext->groupStack.top()->getTransform(); - curContext->groupStack.pop(); -} - -void DeferredRendererImplementation::addState( StateComponentPtr state ) -{ - RenderContext *curContext = currentContext(); - - (*(curContext->stateStack).rbegin())->add( state ); -} - -StateComponent *DeferredRendererImplementation::getState( IECore::TypeId type ) -{ - RenderContext *curContext = currentContext(); - - for( StateStack::reverse_iterator it=curContext->stateStack.rbegin(); it!=curContext->stateStack.rend(); it++ ) - { - StateComponentPtr c = (*it)->get( type ); - if( c ) - { - return c.get(); - } - } - return const_cast( State::defaultState()->get( type ) ); -} - -void DeferredRendererImplementation::addUserAttribute( const IECore::InternedString &name, IECore::DataPtr value ) -{ - RenderContext *curContext = currentContext(); - - (*(curContext->stateStack).rbegin())->userAttributes()->writable()[ name ] = value; -} - -IECore::Data *DeferredRendererImplementation::getUserAttribute( const IECore::InternedString &name ) -{ - RenderContext *curContext = currentContext(); - - for( StateStack::reverse_iterator it=curContext->stateStack.rbegin(); it!=curContext->stateStack.rend(); it++ ) - { - IECore::CompoundDataMap &attrs = (*it)->userAttributes()->writable(); - IECore::CompoundDataMap::iterator attrIt = attrs.find( name ); - if( attrIt != attrs.end() ) - { - return attrIt->second.get(); - } - } - return nullptr; -} - -void DeferredRendererImplementation::addPrimitive( ConstPrimitivePtr primitive ) -{ - bool visible = static_cast( getState( CameraVisibilityStateComponent::staticTypeId() ) )->value(); - if( !visible ) - { - return; - } - - RenderContext *curContext = currentContext(); - - GroupPtr g = new Group; - g->setTransform( curContext->localTransform ); - g->setState( new State( **(curContext->stateStack.rbegin()) ) ); - /// \todo Make Groups have only const access to children and we won't need this - /// cast. This is going to be particularly important going forwards, as the key - /// to decent speed and memory usage is going to be automatically instanced primitives, - /// each referencing potentially shared vertex buffer objects. Modifying one of those - /// could have bad consequences for the others. - g->addChild( boost::const_pointer_cast( primitive ) ); - - { - std::lock_guard lock( curContext->groupStack.top()->mutex() ); - curContext->groupStack.top()->addChild( g ); - } -} - -void DeferredRendererImplementation::addInstance( GroupPtr grp ) -{ - bool visible = static_cast( getState( CameraVisibilityStateComponent::staticTypeId() ) )->value(); - if( !visible ) - { - return; - } - - RenderContext *curContext = currentContext(); - - GroupPtr g = new Group; - g->setTransform( curContext->localTransform ); - g->setState( new State( **(curContext->stateStack.rbegin()) ) ); - g->addChild( grp ); - - { - std::lock_guard lock( curContext->groupStack.top()->mutex() ); - curContext->groupStack.top()->addChild( g ); - } -} - -// Class that sets the scope of a RenderContext on the renderer thread. -struct DeferredRendererImplementation::ScopedRenderContext : private boost::noncopyable -{ - public: - - // Sets the context on the given renderer, to be reverted on the destructor. - // context should be a RenderContext with just one element on each stack. - // msgContext is used on error messages only. - ScopedRenderContext( RenderContextPtr context, DeferredRendererImplementation &renderer, const char *msgContext ) : m_renderer(renderer), m_context( context ), m_msgContext( msgContext ) - { - if ( m_context->transformStack.size() != 1 || - m_context->stateStack.size() != 1 || - m_context->groupStack.size() != 1 ) - { - throw IECore::Exception( "The given context must have just one element at each stack member!" ); - } - - renderer.pushContext( context ); - } - - ~ScopedRenderContext() - { - // unregisters this thread context. - RenderContextPtr removedContext = m_renderer.popContext(); - - if ( m_context.get() != removedContext.get() ) - { - IECore::msg( IECore::Msg::Error, m_msgContext, "Corrupted render context stack!" ); - } - - if ( m_context->transformStack.size() != 1 ) - { - IECore::msg( IECore::Msg::Error, m_msgContext, "Bad nesting of transformBegin/transformEnd detected." ); - } - if ( m_context->stateStack.size() != 1 ) - { - IECore::msg( IECore::Msg::Error, m_msgContext, "Bad nesting of attributeBegin/attributeEnd detected." ); - } - } - - private: - - DeferredRendererImplementation &m_renderer; - RenderContextPtr m_context; - const char *m_msgContext; -}; - -class DeferredRendererImplementation::ProceduralTask : public tbb::task, private boost::noncopyable -{ - public: - - ProceduralTask( DeferredRendererImplementation &renderer, IECoreScene::Renderer::ProceduralPtr proc, IECoreScene::RendererPtr param ) : - m_renderer(renderer), m_procedural(proc), m_param(param), m_taskList(nullptr) - { - m_numSubtasks = 0; - RenderContext *curContext = m_renderer.currentContext(); - - // create a RenderContext for a new Procedural based on the current context - StatePtr completeState = new State( false ); - for ( StateStack::iterator it = curContext->stateStack.begin(); it != curContext->stateStack.end(); it++ ) - { - completeState->add( *it ); - } - m_proceduralContext = new RenderContext(); - m_proceduralContext->localTransform = curContext->localTransform; - m_proceduralContext->transformStack.push( curContext->transformStack.top() ); - m_proceduralContext->stateStack.push_back( completeState ); - m_proceduralContext->groupStack.push( curContext->groupStack.top() ); - } - - ~ProceduralTask() override - { - } - - task* execute() override - { - tbb::task_list taskList; - - m_taskList = &taskList; - - // activates the render context on the task's thread. - ScopedRenderContext scopedProceduralContext( m_proceduralContext, m_renderer, "DeferredRendererImplementation::ProceduralTask::execute" ); - m_procedural->render( m_param.get() ); - set_ref_count( m_numSubtasks + 1 ); - spawn_and_wait_for_all(taskList); - taskList.clear(); - m_taskList = nullptr; - return nullptr; - } - - void addSubtask( ProceduralTask& subtask ) - { - if ( !m_taskList ) - { - IECore::msg( IECore::Msg::Error, "DeferredRendererImplementation::ProceduralTask::addSubtask", "No tasklist!" ); - return; - } - m_taskList->push_back( subtask ); - m_numSubtasks++; - } - - private : - - std::atomic m_numSubtasks; - RenderContextPtr m_proceduralContext; - DeferredRendererImplementation &m_renderer; - IECoreScene::Renderer::ProceduralPtr m_procedural; - IECoreScene::RendererPtr m_param; - tbb::task_list *m_taskList; -}; - - - -void DeferredRendererImplementation::addProcedural( IECoreScene::Renderer::ProceduralPtr proc, IECoreScene::RendererPtr renderer ) -{ - bool visible = static_cast( getState( CameraVisibilityStateComponent::staticTypeId() ) )->value(); - if( !visible ) - { - return; - } - - bool withThreads = static_cast( getState( ProceduralThreadingStateComponent::staticTypeId() ) )->value(); - if( withThreads ) - { - bool mainProcedural = ( m_threadContextPool.size() == 0 ); - - if ( mainProcedural ) - { - // the init is necessary for tbb < 2.2, whereas it is automatically - // created for us in tbb >= 2.2. tbb documentation indicates that it is - // fine to create multiple instances though so we create one just in case. - tbb::task_scheduler_init init; - - // create root task. - tbb::task_group_context taskGroupContext( tbb::task_group_context::isolated ); - ProceduralTask& a = *new( ProceduralTask::allocate_root( taskGroupContext ) ) ProceduralTask( *this, proc, renderer ); - tbb::task::spawn_root_and_wait(a); - // check if all contexts were cleared - for ( ThreadRenderContext::const_iterator it = m_threadContextPool.begin(); it != m_threadContextPool.end(); it++ ) - { - if ( (*it).size() ) - { - IECore::msg( IECore::Msg::Error, "DeferredRendererImplementation::procedural", "Non empty thread render context detected!" ); - } - } - m_threadContextPool.clear(); - } - else - { - ProceduralTask *parentTask = dynamic_cast< ProceduralTask *>(&ProceduralTask::self()); - if ( parentTask ) - { - // add a child task to the current task - ProceduralTask& a = *new(parentTask->allocate_child()) ProceduralTask( *this, proc, renderer ); - // register this class on the parent task - parentTask->addSubtask( a ); - } - else - { - // Somehow the parent task is not ProceduralTask... - IECore::msg( IECore::Msg::Error, "DeferredRendererImplementation::procedural", "Incompatible parent task type!" ); - } - } - } - else - { - // threading not wanted - just execute immediately - proc->render( renderer.get() ); - } -} - -ScenePtr DeferredRendererImplementation::scene() -{ - return m_scene; -} - -const DeferredRendererImplementation::RenderContext *DeferredRendererImplementation::currentContext() const -{ - if ( m_threadContextPool.size() == 0 ) - { - // If no thread context created so far than there's no procedural being rendered. Returns the default context. - return m_defaultContext.get(); - } - - ThreadRenderContext::reference myThreadContext = m_threadContextPool.local(); - if ( myThreadContext.size() == 0 ) - { - // The user created a new thread from the procedural render call... - // there's no way to know which context it should be using. - throw IECore::Exception( "Invalid thread used on deferred render! Procedurals should not instantiate threads!" ); - } - - return myThreadContext.top().get(); -} - -DeferredRendererImplementation::RenderContext *DeferredRendererImplementation::currentContext() -{ - // get the const version of current context and avoid code duplication. - return const_cast< RenderContext * >( - static_cast< const DeferredRendererImplementation & >(*this).currentContext() - ); -} - -void DeferredRendererImplementation::pushContext( RenderContextPtr context ) -{ - ThreadRenderContext::reference myThreadContext = m_threadContextPool.local(); - - myThreadContext.push( context ); -} - -DeferredRendererImplementation::RenderContextPtr DeferredRendererImplementation::popContext() -{ - ThreadRenderContext::reference myThreadContext = m_threadContextPool.local(); - if ( myThreadContext.size() == 0 ) - { - throw IECore::Exception( "Corrupted thread context stack!" ); - } - RenderContextPtr top = myThreadContext.top(); - - myThreadContext.pop(); - - return top; -} diff --git a/src/IECoreGL/ImmediateRendererImplementation.cpp b/src/IECoreGL/ImmediateRendererImplementation.cpp deleted file mode 100644 index 7446306c30..0000000000 --- a/src/IECoreGL/ImmediateRendererImplementation.cpp +++ /dev/null @@ -1,225 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2012, 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 Image Engine Design 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. -// -////////////////////////////////////////////////////////////////////////// - -#include "IECoreGL/private/ImmediateRendererImplementation.h" - -#include "IECoreGL/ColorTexture.h" -#include "IECoreGL/DepthTexture.h" -#include "IECoreGL/Exception.h" -#include "IECoreGL/FrameBuffer.h" -#include "IECoreGL/Group.h" -#include "IECoreGL/Camera.h" -#include "IECoreGL/Primitive.h" -#include "IECoreGL/ShaderStateComponent.h" -#include "IECoreGL/State.h" -#include "IECoreGL/StateComponent.h" -#include "IECoreGL/private/Display.h" - -#include "IECore/MessageHandler.h" -#include "IECore/Writer.h" - -#include - -using namespace IECoreGL; -using namespace Imath; -using namespace std; - -ImmediateRendererImplementation::ImmediateRendererImplementation() -{ - m_stateStack.push( new State( true ) ); -} - -ImmediateRendererImplementation::~ImmediateRendererImplementation() -{ -} - -void ImmediateRendererImplementation::addCamera( CameraPtr camera ) -{ - m_camera = camera; -} - -void ImmediateRendererImplementation::addDisplay( ConstDisplayPtr display ) -{ - m_displays.push_back( display ); -} - -void ImmediateRendererImplementation::worldBegin() -{ - unsigned int width = m_camera->getResolution().x; - unsigned int height = m_camera->getResolution().y; - try - { - m_frameBuffer = new FrameBuffer; - m_frameBuffer->setColor( new ColorTexture( width, height ) ); - IECoreGL::Exception::throwIfError(); - m_frameBuffer->setDepth( new DepthTexture( width, height ) ); - IECoreGL::Exception::throwIfError(); - m_frameBuffer->validate(); - m_frameBufferBinding = new FrameBuffer::ScopedBinding( *m_frameBuffer ); - } - catch( const std::exception &e ) - { - IECore::msg( IECore::Msg::Error, "Renderer::worldBegin", boost::format( "Unable to make framebuffer (%s)." ) % e.what() ); - } - - glPushAttrib( GL_ALL_ATTRIB_BITS ); - - m_camera->render( m_stateStack.top().get() ); - - glViewport( 0, 0, width, height ); - glClearColor( 0.0, 0.0, 0.0, 0.0 ); - glClearDepth( 1.0 ); - glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); - - m_stateStack.push( new State( *(m_stateStack.top()) ) ); - - State::bindBaseState(); - m_stateStack.top()->bind(); -} - -void ImmediateRendererImplementation::worldEnd() -{ - m_stateStack.pop(); - glPopAttrib(); - if( m_frameBuffer ) - { - for( unsigned int i=0; idisplay( m_frameBuffer ); - } - } - - delete m_frameBufferBinding; - m_frameBufferBinding = nullptr; -} - -void ImmediateRendererImplementation::transformBegin() -{ - glPushMatrix(); -} - -void ImmediateRendererImplementation::transformEnd() -{ - glPopMatrix(); -} - -void ImmediateRendererImplementation::setTransform( const Imath::M44f &m ) -{ - // assumes world coordinate system is the identity matrix. - glLoadMatrixf( ( m * m_camera->getTransform().inverse() ).getValue() ); -} - -Imath::M44f ImmediateRendererImplementation::getTransform() const -{ - // get the current open GL model-view matrix and take the camera out of it to return the world space matrix. - return Camera::matrix() * m_camera->getTransform(); -} - -void ImmediateRendererImplementation::concatTransform( const Imath::M44f &matrix ) -{ - glMultMatrixf( matrix.getValue() ); -} - -void ImmediateRendererImplementation::attributeBegin() -{ - transformBegin(); - m_stateStack.push( new State( *(m_stateStack.top()) ) ); -} - -void ImmediateRendererImplementation::attributeEnd() -{ - if( m_stateStack.size()<=1 ) - { - IECore::msg( IECore::Msg::Warning, "ImmediateRendererImplementation::attributeEnd", "Bad nesting." ); - return; - } - m_stateStack.pop(); - m_stateStack.top()->bind(); - transformEnd(); -} - -void ImmediateRendererImplementation::addState( StateComponentPtr state ) -{ - m_stateStack.top()->add( state ); - state->bind(); -} - -StateComponent *ImmediateRendererImplementation::getState( IECore::TypeId type ) -{ - return m_stateStack.top()->get( type ); -} - -void ImmediateRendererImplementation::addUserAttribute( const IECore::InternedString &name, IECore::DataPtr value ) -{ - m_stateStack.top()->userAttributes()->writable()[ name ] = value; -} - -IECore::Data *ImmediateRendererImplementation::getUserAttribute( const IECore::InternedString &name ) -{ - State *curState = m_stateStack.top().get(); - IECore::CompoundDataMap &attrs = curState->userAttributes()->writable(); - IECore::CompoundDataMap::iterator attrIt = attrs.find( name ); - if( attrIt != attrs.end() ) - { - return attrIt->second.get(); - } - return nullptr; -} - -void ImmediateRendererImplementation::addPrimitive( ConstPrimitivePtr primitive ) -{ - bool visible = static_cast( getState( CameraVisibilityStateComponent::staticTypeId() ) )->value(); - if( visible ) - { - primitive->render( m_stateStack.top().get() ); - } -} - -void ImmediateRendererImplementation::addProcedural( IECoreScene::Renderer::ProceduralPtr proc, IECoreScene::RendererPtr renderer ) -{ - bool visible = static_cast( getState( CameraVisibilityStateComponent::staticTypeId() ) )->value(); - if( visible ) - { - proc->render( renderer.get() ); - } -} - -void ImmediateRendererImplementation::addInstance( GroupPtr grp ) -{ - bool visible = static_cast( getState( CameraVisibilityStateComponent::staticTypeId() ) )->value(); - if( visible ) - { - grp->render( m_stateStack.top().get() ); - } -} diff --git a/src/IECoreGL/Renderer.cpp b/src/IECoreGL/Renderer.cpp deleted file mode 100644 index 7730e1b994..0000000000 --- a/src/IECoreGL/Renderer.cpp +++ /dev/null @@ -1,2078 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2013, Image Engine Design Inc. All rights reserved. -// Copyright (c) 2011, John Haddon. 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 Image Engine Design 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. -// -////////////////////////////////////////////////////////////////////////// - -#include "IECoreGL/Renderer.h" - -#include "IECoreGL/CachedConverter.h" -#include "IECoreGL/ColorTexture.h" -#include "IECoreGL/CurvesPrimitive.h" -#include "IECoreGL/DiskPrimitive.h" -#include "IECoreGL/Font.h" -#include "IECoreGL/FontLoader.h" -#include "IECoreGL/GL.h" -#include "IECoreGL/Group.h" -#include "IECoreGL/LuminanceTexture.h" -#include "IECoreGL/MeshPrimitive.h" -#include "IECoreGL/NameStateComponent.h" -#include "IECoreGL/Camera.h" -#include "IECoreGL/PointsPrimitive.h" -#include "IECoreGL/QuadPrimitive.h" -#include "IECoreGL/Scene.h" -#include "IECoreGL/Shader.h" -#include "IECoreGL/ShaderLoader.h" -#include "IECoreGL/ShaderStateComponent.h" -#include "IECoreGL/SpherePrimitive.h" -#include "IECoreGL/State.h" -#include "IECoreGL/TextPrimitive.h" -#include "IECoreGL/TextureLoader.h" -#include "IECoreGL/ToGLCameraConverter.h" -#include "IECoreGL/ToGLMeshConverter.h" -#include "IECoreGL/TypedStateComponent.h" -#include "IECoreGL/private/DeferredRendererImplementation.h" -#include "IECoreGL/private/Display.h" -#include "IECoreGL/private/ImmediateRendererImplementation.h" - -#include "IECoreScene/Camera.h" -#include "IECoreScene/CurvesPrimitive.h" -#include "IECoreScene/MeshNormalsOp.h" -#include "IECoreScene/MeshPrimitive.h" -#include "IECoreScene/PointsPrimitive.h" -#include "IECoreScene/Transform.h" - -#include "IECore/BoxOps.h" -#include "IECore/MatrixAlgo.h" -#include "IECore/MessageHandler.h" -#include "IECore/SimpleTypedData.h" -#include "IECore/SplineData.h" - -#include "Imath/ImathBoxAlgo.h" - -#include -#include - -// Windows defines SearchPath, breaking our use of `IECore::SearchPath`. -#ifdef SearchPath -#undef SearchPath -#endif - -using namespace IECore; -using namespace IECoreScene; -using namespace IECoreGL; -using namespace Imath; -using namespace std; - -IE_CORE_DEFINERUNTIMETYPED( IECoreGL::Renderer ); - -///////////////////////////////////////////////////////////////////////////////////////////////////////// -// static utility functions -///////////////////////////////////////////////////////////////////////////////////////////////////////// - -template -typename T::ConstPtr castWithWarning( ConstDataPtr data, const std::string &name, const std::string &context ) -{ - typename T::ConstPtr c = runTimeCast( data ); - if( !c ) - { - msg( Msg::Warning, context, boost::format( "Expected \"%s\" to be of type \"%s\"." ) % name % T::staticTypeName() ); - } - return c; -} - -template -T parameterValue( const char *name, const CompoundDataMap ¶meters, T defaultValue ) -{ - CompoundDataMap::const_iterator it = parameters.find( name ); - if( it!=parameters.end() ) - { - typename TypedData::ConstPtr p = runTimeCast >( it->second ); - if( p ) - { - return p->readable(); - } - } - return defaultValue; -} - -///////////////////////////////////////////////////////////////////////////////////////////////////////// -// member data held in a single structure -///////////////////////////////////////////////////////////////////////////////////////////////////////// - -/// \todo Now we're adding methods to this, we should probably rename it to Impl -/// or Implementation. We should perhaps also rename the RendererImplementation -/// classes to RendererBackend or something to avoid confusion. -struct IECoreGL::Renderer::MemberData -{ - enum Mode - { - Immediate, - Deferred - }; - - struct - { - Mode mode; - V2f shutter; - IECore::CompoundDataMap user; - string fontSearchPath; - string fontSearchPathDefault; - string shaderSearchPath; - string shaderSearchPathDefault; - string shaderIncludePath; - string shaderIncludePathDefault; - string textureSearchPath; - string textureSearchPathDefault; - vector cameras; - vector displays; - bool drawCoordinateSystems; - } options; - - /// This is used only before worldBegin, so we can correctly get the transforms for cameras. - /// After worldBegin the transform stack is taken care of by the backend implementations. - std::stack transformStack; - - bool inWorld; - bool inEdit; - RendererImplementationPtr implementation; - ShaderLoaderPtr shaderLoader; - TextureLoaderPtr textureLoader; -#ifdef IECORE_WITH_FREETYPE - FontLoaderPtr fontLoader; -#endif // IECORE_WITH_FREETYPE - - typedef std::map InstanceMap; - InstanceMap instances; - Group *currentInstance; - - CachedConverterPtr cachedConverter; - - // we don't want to just destroy objects in the removeObject command, as we could be in - // any thread at the time, and we can only destroy gl resources on the thread which has - // the gl context. so we stash them in here until the editEnd command, and then destroy - // them. the implication is therefore that editEnd must be called on the main gl thread, - // but that procedurals are free to call removeObject regardless of which thread they're - // being called from. - std::set removedObjects; - std::mutex removedObjectsMutex; - - void addPrimitive( const IECoreScene::Primitive *corePrimitive ) - { - ConstPrimitivePtr glPrimitive; - if( implementation->getState()->value() ) - { - glPrimitive = IECore::runTimeCast( cachedConverter->convert( corePrimitive ) ); - } - else - { - ToGLConverterPtr converter = ToGLConverter::create( corePrimitive, IECoreGL::Primitive::staticTypeId() ); - glPrimitive = IECore::runTimeCast( converter->convert() ); - } - - addPrimitive( glPrimitive ); - } - - void addPrimitive( IECoreGL::ConstPrimitivePtr glPrimitive ) - { - if( currentInstance ) - { - addCurrentInstanceChild( glPrimitive ); - } - else if( checkCulling( glPrimitive->bound() ) ) - { - implementation->addPrimitive( glPrimitive ); - } - } - - void addCurrentInstanceChild( IECoreGL::ConstRenderablePtr child ) - { - IECoreGL::GroupPtr childGroup = new IECoreGL::Group(); - childGroup->setTransform( transformStack.top() ); - /// \todo See todo in DeferredRendererImplementation::addPrimitive(). - childGroup->addChild( boost::const_pointer_cast( child ) ); - currentInstance->addChild( childGroup ); - } - - bool checkCulling( const Imath::Box3f &bound ) - { - const Imath::Box3f &cullBox = implementation->getState()->value(); - if( cullBox.isEmpty() ) - { - // culling is disabled... p should be rendered. - return true; - } - - if( bound == Procedural::noBound ) - { - return true; - } - - Imath::Box3f b = bound; - switch( implementation->getState()->value() ) - { - case ObjectSpace : - // if in local space we don't have to transform bounding box of p. - break; - case WorldSpace : - // transform procedural bounding box to world space to match culling box space. - b = Imath::transform( b, implementation->getTransform() ); - break; - default : - msg( Msg::Warning, "Renderer::checkCulling", "Unnexpected culling space!" ); - return true; - } - return cullBox.intersects( b ); - } - -}; - -///////////////////////////////////////////////////////////////////////////////////////////////////////// -// structors -///////////////////////////////////////////////////////////////////////////////////////////////////////// - -IECoreGL::Renderer::Renderer() -{ - m_data = new MemberData; - - m_data->options.mode = MemberData::Immediate; - m_data->options.shutter = V2f( 0 ); - - const char *fontPath = getenv( "IECORE_FONT_PATHS" ); - m_data->options.fontSearchPath = m_data->options.fontSearchPathDefault = fontPath ? fontPath : ""; - const char *shaderPath = getenv( "IECOREGL_SHADER_PATHS" ); - m_data->options.shaderSearchPath = m_data->options.shaderSearchPathDefault = shaderPath ? shaderPath : ""; - const char *shaderIncludePath = getenv( "IECOREGL_SHADER_INCLUDE_PATHS" ); - m_data->options.shaderIncludePath = m_data->options.shaderIncludePathDefault = shaderIncludePath ? shaderIncludePath : ""; - const char *texturePath = getenv( "IECOREGL_TEXTURE_PATHS" ); - m_data->options.textureSearchPath = m_data->options.textureSearchPathDefault = texturePath ? texturePath : ""; - m_data->options.drawCoordinateSystems = false; - - m_data->transformStack.push( M44f() ); - - m_data->inWorld = false; - m_data->inEdit = false; - m_data->currentInstance = nullptr; - m_data->implementation = nullptr; - m_data->shaderLoader = nullptr; - - m_data->cachedConverter = CachedConverter::defaultCachedConverter(); -} - -IECoreGL::Renderer::~Renderer() -{ - delete m_data; -} - -///////////////////////////////////////////////////////////////////////////////////////////////////////// -// options etc -///////////////////////////////////////////////////////////////////////////////////////////////////////// - -typedef void (*OptionSetter)( const std::string &name, IECore::ConstDataPtr value, IECoreGL::Renderer::MemberData *memberData ); -typedef std::map OptionSetterMap; - -typedef IECore::DataPtr (*OptionGetter)( const std::string &name, IECoreGL::Renderer::MemberData *memberData ); -typedef std::map OptionGetterMap; - -static void modeOptionSetter( const std::string &name, IECore::ConstDataPtr value, IECoreGL::Renderer::MemberData *memberData ) -{ - if( ConstStringDataPtr s = castWithWarning( value, name, "Renderer::setOption" ) ) - { - if( s->readable()=="immediate" ) - { - memberData->options.mode = IECoreGL::Renderer::MemberData::Immediate; - } - else if( s->readable()=="deferred" ) - { - memberData->options.mode = IECoreGL::Renderer::MemberData::Deferred; - } - else - { - msg( Msg::Warning, "Renderer::setOption", boost::format( "Unsuppported mode value \"%s\"." ) % s->readable() ); - } - } - return; -} - -static IECore::DataPtr modeOptionGetter( const std::string &name, IECoreGL::Renderer::MemberData *memberData ) -{ - switch( memberData->options.mode ) - { - case IECoreGL::Renderer::MemberData::Immediate : - return new StringData( "immediate" ); - default : - return new StringData( "deferred" ); - } -} - -static void shutterOptionSetter( const std::string &name, IECore::ConstDataPtr value, IECoreGL::Renderer::MemberData *memberData ) -{ - if( ConstV2fDataPtr s = castWithWarning( value, name, "Renderer::setOption" ) ) - { - memberData->options.shutter = s->readable(); - } -} - -static IECore::DataPtr shutterOptionGetter( const std::string &name, IECoreGL::Renderer::MemberData *memberData ) -{ - return new V2fData( memberData->options.shutter ); -} - -static void fontSearchPathOptionSetter( const std::string &name, IECore::ConstDataPtr value, IECoreGL::Renderer::MemberData *memberData ) -{ - if( ConstStringDataPtr s = castWithWarning( value, name, "Renderer::setOption" ) ) - { - memberData->options.fontSearchPath = s->readable(); - } -} - -static IECore::DataPtr fontSearchPathOptionGetter( const std::string &name, IECoreGL::Renderer::MemberData *memberData ) -{ - return new StringData( memberData->options.fontSearchPath ); -} - -static void shaderSearchPathOptionSetter( const std::string &name, IECore::ConstDataPtr value, IECoreGL::Renderer::MemberData *memberData ) -{ - if( ConstStringDataPtr s = castWithWarning( value, name, "Renderer::setOption" ) ) - { - memberData->options.shaderSearchPath = s->readable(); - } -} - -static IECore::DataPtr shaderSearchPathOptionGetter( const std::string &name, IECoreGL::Renderer::MemberData *memberData ) -{ - return new StringData( memberData->options.shaderSearchPath ); -} - -static void shaderIncludePathOptionSetter( const std::string &name, IECore::ConstDataPtr value, IECoreGL::Renderer::MemberData *memberData ) -{ - if( ConstStringDataPtr s = castWithWarning( value, name, "Renderer::setOption" ) ) - { - memberData->options.shaderIncludePath = s->readable(); - } -} - -static IECore::DataPtr shaderIncludePathOptionGetter( const std::string &name, IECoreGL::Renderer::MemberData *memberData ) -{ - return new StringData( memberData->options.shaderIncludePath ); -} - -static void textureSearchPathOptionSetter( const std::string &name, IECore::ConstDataPtr value, IECoreGL::Renderer::MemberData *memberData ) -{ - if( ConstStringDataPtr s = castWithWarning( value, name, "Renderer::setOption" ) ) - { - memberData->options.textureSearchPath = s->readable(); - } -} - -static IECore::DataPtr textureSearchPathOptionGetter( const std::string &name, IECoreGL::Renderer::MemberData *memberData ) -{ - return new StringData( memberData->options.textureSearchPath ); -} - -static void drawCoordinateSystemsOptionSetter( const std::string &name, IECore::ConstDataPtr value, IECoreGL::Renderer::MemberData *memberData ) -{ - if( ConstBoolDataPtr b = castWithWarning( value, name, "Renderer::setOption" ) ) - { - memberData->options.drawCoordinateSystems = b->readable(); - } -} - -static IECore::DataPtr drawCoordinateSystemsOptionGetter( const std::string &name, IECoreGL::Renderer::MemberData *memberData ) -{ - return new BoolData( memberData->options.drawCoordinateSystems ); -} - -static const OptionSetterMap *optionSetters() -{ - static OptionSetterMap *o = new OptionSetterMap; - if( !o->size() ) - { - (*o)["gl:mode"] = modeOptionSetter; - (*o)["shutter"] = shutterOptionSetter; - (*o)["searchPath:font"] = fontSearchPathOptionSetter; - (*o)["gl:searchPath:shader"] = shaderSearchPathOptionSetter; - (*o)["searchPath:shader"] = shaderSearchPathOptionSetter; - (*o)["gl:searchPath:shaderInclude"] = shaderIncludePathOptionSetter; - (*o)["searchPath:shaderInclude"] = shaderIncludePathOptionSetter; - (*o)["gl:searchPath:texture"] = textureSearchPathOptionSetter; - (*o)["searchPath:texture"] = textureSearchPathOptionSetter; - (*o)["gl:drawCoordinateSystems"] = drawCoordinateSystemsOptionSetter; - } - return o; -} - -static const OptionGetterMap *optionGetters() -{ - static OptionGetterMap *o = new OptionGetterMap; - if( !o->size() ) - { - (*o)["gl:mode"] = modeOptionGetter; - (*o)["shutter"] = shutterOptionGetter; - (*o)["searchPath:font"] = fontSearchPathOptionGetter; - (*o)["gl:searchPath:shader"] = shaderSearchPathOptionGetter; - (*o)["searchPath:shader"] = shaderSearchPathOptionGetter; - (*o)["gl:searchPath:shaderInclude"] = shaderIncludePathOptionGetter; - (*o)["searchPath:shaderInclude"] = shaderIncludePathOptionGetter; - (*o)["gl:searchPath:texture"] = textureSearchPathOptionGetter; - (*o)["searchPath:texture"] = textureSearchPathOptionGetter; - (*o)["gl:drawCoordinateSystems"] = drawCoordinateSystemsOptionGetter; - } - return o; -} - -void IECoreGL::Renderer::setOption( const std::string &name, IECore::ConstDataPtr value ) -{ - if( m_data->inWorld ) - { - msg( Msg::Warning, "Renderer::setOption", "Cannot call setOption after worldBegin()." ); - return; - } - - const OptionSetterMap *o = optionSetters(); - OptionSetterMap::const_iterator it = o->find( name ); - if( it!=o->end() ) - { - it->second( name, value, m_data ); - } - else if( name.compare( 0, 5, "user:" )==0 ) - { - m_data->options.user[name] = value->copy(); - } - else if( name.compare( 0, 3, "gl:" )==0 || name.find( ':' )==string::npos ) - { - msg( Msg::Warning, "Renderer::setOption", boost::format( "Unsuppported option \"%s\"." ) % name ); - return; - } -} - -IECore::ConstDataPtr IECoreGL::Renderer::getOption( const std::string &name ) const -{ - const OptionGetterMap *o = optionGetters(); - OptionGetterMap::const_iterator it = o->find( name ); - if( it!=o->end() ) - { - return it->second( name, m_data ); - } - else if( name.compare( 0, 5, "user:" )==0 ) - { - IECore::CompoundDataMap::const_iterator optionIt = m_data->options.user.find( name ); - if( optionIt!=m_data->options.user.end() ) - { - return optionIt->second; - } - else - { - return nullptr; - } - } - else if( name.compare( 0, 3, "gl:" )==0 || name.find( ':' )==string::npos ) - { - msg( Msg::Warning, "Renderer::getOption", boost::format( "Unsuppported option \"%s\"." ) % name ); - return nullptr; - } - - return nullptr; -} - - -void IECoreGL::Renderer::camera( const std::string &unusedName, const IECore::CompoundDataMap ¶meters ) -{ - if( m_data->inWorld ) - { - msg( Msg::Warning, "IECoreGL::Renderer::camera", "Cameras can not be specified after worldBegin." ); - return; - } - if ( m_data->currentInstance ) - { - msg( Msg::Warning, "IECoreGL::Renderer::camera", "Cameras can not be specified during instance definition." ); - return; - } - - try - { - IECoreScene::CameraPtr coreCamera = new IECoreScene::Camera( new CompoundData( parameters ) ); - - IECoreGL::CameraPtr camera = IECore::runTimeCast( ToGLCameraConverter( coreCamera ).convert() ); - - // TODO delete this - // Cortex cameras are now driven by physical parameters, not a screenWindow - // But for compatibility with the deprecated GL stuff, if someone tries to override the computed - // frustum, then stomp that straight onto the GL camera - /*auto screenWindowParm = parameters.find( "screenWindow" ); - if( screenWindowParm != parameters.end() ) - { - Box2fData *screenWindowData = runTimeCast< Box2fData >( screenWindowParm->second.get() ); - if( screenWindowData ) - { - camera->setNormalizedScreenWindow( screenWindowData->readable() ); - } - }*/ - - // we have to store these till worldBegin, as only then are we sure what sort of renderer backend we have - if( camera ) - { - camera->setTransform( m_data->transformStack.top() ); - m_data->options.cameras.push_back( camera ); - } - } - catch( const std::exception &e ) - { - msg( Msg::Error, "IECoreGL::Renderer::camera", e.what() ); - return; - } -} - - -void IECoreGL::Renderer::display( const std::string &name, const std::string &type, const std::string &data, const IECore::CompoundDataMap ¶meters ) -{ - // we store displays till worldbegin, as until that point we don't have a renderer implementation to pass - // them to - if( m_data->inWorld ) - { - msg( Msg::Warning, "IECoreGL::Renderer::display", "Displays can not be specified after worldBegin." ); - return; - } - if ( m_data->currentInstance ) - { - msg( Msg::Warning, "IECoreGL::Renderer::display", "Displays can not be specified during instance definition." ); - return; - } - m_data->options.displays.push_back( new Display( name, type, data, parameters ) ); -} - -///////////////////////////////////////////////////////////////////////////////////////////////////////// -// world begin/end -///////////////////////////////////////////////////////////////////////////////////////////////////////// - -void IECoreGL::Renderer::worldBegin() -{ - if( m_data->inWorld ) - { - msg( Msg::Warning, "Renderer::worldBegin", "Cannot call worldBegin() again before worldEnd()." ); - return; - } - if ( m_data->currentInstance ) - { - msg( Msg::Warning, "IECoreGL::Renderer::worldBegin", "worldBegin can not be called during instance definition." ); - return; - } - - m_data->inWorld = true; - - if( m_data->options.mode==MemberData::Deferred ) - { - m_data->implementation = new DeferredRendererImplementation; - } - else - { - m_data->implementation = new ImmediateRendererImplementation; - } - - if( m_data->options.shaderSearchPath==m_data->options.shaderSearchPathDefault && m_data->options.shaderIncludePath==m_data->options.shaderIncludePathDefault ) - { - // use the shared default cache if we can - m_data->shaderLoader = ShaderLoader::defaultShaderLoader(); - } - else - { - IECore::SearchPath includePaths( m_data->options.shaderIncludePath ); - m_data->shaderLoader = new ShaderLoader( IECore::SearchPath( m_data->options.shaderSearchPath ), &includePaths ); - } - - if( m_data->options.textureSearchPath==m_data->options.textureSearchPathDefault ) - { - // use the shared default cache if we can - m_data->textureLoader = TextureLoader::defaultTextureLoader(); - } - else - { - m_data->textureLoader = new TextureLoader( IECore::SearchPath( m_data->options.textureSearchPath ) ); - } - -#ifdef IECORE_WITH_FREETYPE - if( m_data->options.fontSearchPath==m_data->options.fontSearchPathDefault ) - { - // use the shared default cache if we can - m_data->fontLoader = FontLoader::defaultFontLoader(); - } - else - { - m_data->fontLoader = new FontLoader( IECore::SearchPath( m_data->options.fontSearchPath ) ); - } -#endif // IECORE_WITH_FREETYPE - - if( m_data->options.cameras.size() ) - { - for( unsigned int i=0; ioptions.cameras.size(); i++ ) - { - m_data->implementation->addCamera( m_data->options.cameras[i] ); - } - } - else - { - // specify the default camera - IECoreScene::ConstCameraPtr defaultCamera = new IECoreScene::Camera(); - IECoreGL::CameraPtr camera = IECore::runTimeCast( ToGLCameraConverter( defaultCamera ).convert() ); - m_data->implementation->addCamera( camera ); - } - - for( unsigned int i=0; ioptions.displays.size(); i++ ) - { - m_data->implementation->addDisplay( m_data->options.displays[i] ); - } - m_data->implementation->worldBegin(); - - ShaderStateComponentPtr defaultShaderState = new ShaderStateComponent( m_data->shaderLoader, m_data->textureLoader, "", "", "", new CompoundObject ); - m_data->implementation->addState( defaultShaderState ); -} - -void IECoreGL::Renderer::worldEnd() -{ - if( !m_data->inWorld ) - { - msg( Msg::Warning, "Renderer::worldEnd", "Cannot call worldEnd() before worldBegin()." ); - return; - } - if ( m_data->currentInstance ) - { - msg( Msg::Warning, "IECoreGL::Renderer::worldEnd", "worldEnd can not be called during instance definition." ); - return; - } - m_data->implementation->worldEnd(); - m_data->inWorld = false; - m_data->cachedConverter->clearUnused(); -} - -ScenePtr IECoreGL::Renderer::scene() -{ - DeferredRendererImplementationPtr r = runTimeCast( m_data->implementation ); - if( r ) - { - return r->scene(); - } - return nullptr; -} - -///////////////////////////////////////////////////////////////////////////////////////////////////////// -// transforms -///////////////////////////////////////////////////////////////////////////////////////////////////////// - -void IECoreGL::Renderer::transformBegin() -{ - if( m_data->inWorld ) - { - m_data->implementation->transformBegin(); - } - else - { - m_data->transformStack.push( m_data->transformStack.top() ); - } -} - -void IECoreGL::Renderer::transformEnd() -{ - if( m_data->inWorld ) - { - bool wasRight = ( determinant( m_data->implementation->getTransform() ) >= 0 ); - m_data->implementation->transformEnd(); - bool isRight = ( determinant( m_data->implementation->getTransform() ) >= 0 ); - - if ( wasRight != isRight ) - { - bool l = m_data->implementation->getState()->value(); - m_data->implementation->addState( new RightHandedOrientationStateComponent( !l ) ); - } - } - else - { - if( m_data->transformStack.size() ) - { - m_data->transformStack.pop(); - } - else - { - msg( Msg::Error, "IECoreGL::Renderer::transformEnd", "Bad nesting detected." ); - } - } -} - -void IECoreGL::Renderer::setTransform( const Imath::M44f &m ) -{ - if( m_data->inWorld ) - { - m_data->implementation->setTransform( m ); - - if( determinant( m ) < 0.0f ) - { - bool l = m_data->implementation->getState()->value(); - m_data->implementation->addState( new RightHandedOrientationStateComponent( !l ) ); - } - } - else - { - m_data->transformStack.top() = m; - } -} - -void IECoreGL::Renderer::setTransform( const std::string &coordinateSystem ) -{ - msg( Msg::Warning, "Renderer::setTransform", "Not implemented" ); -} - -Imath::M44f IECoreGL::Renderer::getTransform() const -{ - if( m_data->inWorld ) - { - return m_data->implementation->getTransform(); - } - else - { - return m_data->transformStack.top(); - } -} - -Imath::M44f IECoreGL::Renderer::getTransform( const std::string &coordinateSystem ) const -{ - msg( Msg::Warning, "Renderer::getTransform", "Not implemented" ); - return M44f(); -} - -void IECoreGL::Renderer::concatTransform( const Imath::M44f &m ) -{ - if( m_data->inWorld ) - { - m_data->implementation->concatTransform( m ); - if( determinant( m ) < 0.0f ) - { - bool l = m_data->implementation->getState()->value(); - m_data->implementation->addState( new RightHandedOrientationStateComponent( !l ) ); - } - } - else - { - m_data->transformStack.top() = m * m_data->transformStack.top(); - } -} - -void IECoreGL::Renderer::coordinateSystem( const std::string &name ) -{ - if( m_data->options.drawCoordinateSystems ) - { - IntVectorDataPtr numVerticesData = new IntVectorData; - std::vector &numVertices = numVerticesData->writable(); - numVertices.push_back( 2 ); - numVertices.push_back( 2 ); - numVertices.push_back( 2 ); - - V3fVectorDataPtr pointsData = new V3fVectorData(); - std::vector &points = pointsData->writable(); - points.push_back( V3f( 0 ) ); - points.push_back( V3f( 1, 0, 0 ) ); - points.push_back( V3f( 0 ) ); - points.push_back( V3f( 0, 1, 0 ) ); - points.push_back( V3f( 0 ) ); - points.push_back( V3f( 0, 0, 1 ) ); - - PrimitiveVariableMap primVars; - primVars["P"] = PrimitiveVariable( PrimitiveVariable::Vertex, pointsData ); - - attributeBegin(); - setAttribute( "name", new StringData( "coordinateSystem:" + name ) ); - setAttribute( "gl:curvesPrimitive:useGLLines", new BoolData( true ) ); - setAttribute( "gl:curvesPrimitive:glLineWidth", new FloatData( 2 ) ); - curves( CubicBasisf::linear(), false, numVerticesData, primVars ); - attributeEnd(); - } -} - -///////////////////////////////////////////////////////////////////////////////////////////////////////// -// attribute state -///////////////////////////////////////////////////////////////////////////////////////////////////////// - -typedef void (*AttributeSetter)( const std::string &name, IECore::ConstDataPtr value, IECoreGL::Renderer::MemberData *memberData ); -typedef std::map AttributeSetterMap; -typedef IECore::ConstDataPtr (*AttributeGetter)( const std::string &name, const IECoreGL::Renderer::MemberData *memberData ); -typedef std::map AttributeGetterMap; - -template -static void typedAttributeSetter( const std::string &name, IECore::ConstDataPtr value, IECoreGL::Renderer::MemberData *memberData ) -{ - typedef IECore::TypedData DataType; - typename DataType::ConstPtr d = runTimeCast( value ); - if( !d ) - { - msg( Msg::Warning, "Renderer::setAttribute", boost::format( "Expected data of type \"%s\" for attribute \"%s\"." ) % DataType::staticTypeName() % name ); - return; - } - memberData->implementation->addState( new T( d->readable() ) ); -} - -template -static IECore::ConstDataPtr typedAttributeGetter( const std::string &name, const IECoreGL::Renderer::MemberData *memberData ) -{ - typedef IECore::TypedData DataType; - const T *a = memberData->implementation->template getState(); - return new DataType( a->value() ); -} - -static void colorAttributeSetter( const std::string &name, IECore::ConstDataPtr value, IECoreGL::Renderer::MemberData *memberData ) -{ - ConstColor3fDataPtr d = castWithWarning( value, name, "Renderer::setAttribute" ); - if( d ) - { - Color::ConstPtr c = memberData->implementation->getState(); - Color4f cc = c->value(); - cc[0] = d->readable()[0]; - cc[1] = d->readable()[1]; - cc[2] = d->readable()[2]; - memberData->implementation->addState( new Color( cc ) ); - } -} - -static IECore::ConstDataPtr colorAttributeGetter( const std::string &name, const IECoreGL::Renderer::MemberData *memberData ) -{ - const IECoreGL::Color *a = memberData->implementation->getState(); - Color4f c = a->value(); - return new Color3fData( Color3f( c[0], c[1], c[2] ) ); -} - -static IECore::ConstDataPtr opacityAttributeGetter( const std::string &name, const IECoreGL::Renderer::MemberData *memberData ) -{ - const IECoreGL::Color *a = memberData->implementation->getState(); - Color4f c = a->value(); - return new Color3fData( Color3f( c[3] ) ); -} - -static void opacityAttributeSetter( const std::string &name, IECore::ConstDataPtr value, IECoreGL::Renderer::MemberData *memberData ) -{ - ConstColor3fDataPtr d = castWithWarning( value, name, "Renderer::setAttribute" ); - if( d ) - { - const Color *c = memberData->implementation->getState(); - Color4f cc = c->value(); - cc[3] = (d->readable()[0] + d->readable()[1] + d->readable()[2]) / 3.0f; - memberData->implementation->addState( new Color( cc ) ); - } -} - -static IECore::ConstDataPtr blendFactorGetter( const std::string &name, const IECoreGL::Renderer::MemberData *memberData ) -{ - const BlendFuncStateComponent *b = memberData->implementation->getState(); - GLenum f = name=="gl:blend:srcFactor" ? b->value().src : b->value().dst; - switch( f ) - { - case GL_ZERO : - return new StringData( "zero" ); - case GL_ONE : - return new StringData( "one" ); - case GL_SRC_COLOR : - return new StringData( "srcColor" ); - case GL_ONE_MINUS_SRC_COLOR : - return new StringData( "oneMinusSrcColor" ); - case GL_DST_COLOR : - return new StringData( "dstColor" ); - case GL_ONE_MINUS_DST_COLOR : - return new StringData( "oneMinusDstColor" ); - case GL_SRC_ALPHA : - return new StringData( "srcAlpha" ); - case GL_ONE_MINUS_SRC_ALPHA : - return new StringData( "oneMinusSrcAlpha" ); - case GL_DST_ALPHA : - return new StringData( "dstAlpha" ); - case GL_ONE_MINUS_DST_ALPHA : - return new StringData( "oneMinusDstAlpha" ); - case GL_CONSTANT_COLOR : - return new StringData( "constantColor" ); - case GL_ONE_MINUS_CONSTANT_COLOR : - return new StringData( "oneMinusConstantColor" ); - case GL_CONSTANT_ALPHA : - return new StringData( "constantAlpha" ); - case GL_ONE_MINUS_CONSTANT_ALPHA : - return new StringData( "oneMinusConstantAlpha" ); - default : - msg( Msg::Warning, "Renderer::getAttribute", boost::format( "Invalid state for \"%s\"." ) % name ); - return new StringData( "invalid" ); - } -} - -static void blendFactorSetter( const std::string &name, IECore::ConstDataPtr value, IECoreGL::Renderer::MemberData *memberData ) -{ - ConstStringDataPtr d = castWithWarning( value, name, "Renderer::setAttribute" ); - if( !d ) - { - return; - } - - GLenum f; - const std::string &v = d->readable(); - if( v=="zero" ) - { - f = GL_ZERO; - } - else if( v=="one" ) - { - f = GL_ONE; - } - else if( v=="srcColor" ) - { - f = GL_SRC_COLOR; - } - else if( v=="oneMinusSrcColor" ) - { - f = GL_ONE_MINUS_SRC_COLOR; - } - else if( v=="dstColor" ) - { - f = GL_DST_COLOR; - } - else if( v=="oneMinusDstColor" ) - { - f = GL_ONE_MINUS_DST_COLOR; - } - else if( v=="srcAlpha" ) - { - f = GL_SRC_ALPHA; - } - else if( v=="oneMinusSrcAlpha" ) - { - f = GL_ONE_MINUS_SRC_ALPHA; - } - else if( v=="dstAlpha" ) - { - f = GL_DST_ALPHA; - } - else if( v=="oneMinusDstAlpha" ) - { - f = GL_ONE_MINUS_DST_ALPHA; - } - else if( v=="constantColor" ) - { - f = GL_CONSTANT_COLOR; - } - else if( v=="oneMinusConstantColor" ) - { - f = GL_ONE_MINUS_CONSTANT_COLOR; - } - else if( v=="constantAlpha" ) - { - f = GL_CONSTANT_ALPHA; - } - else if( v=="oneMinusConstantAlpha" ) - { - f = GL_ONE_MINUS_CONSTANT_ALPHA; - } - else - { - msg( Msg::Error, "Renderer::setAttribute", boost::format( "Unsupported value \"%s\" for attribute \"%s\"." ) % v % name ); - return; - } - const BlendFuncStateComponent *b = memberData->implementation->getState(); - BlendFactors bf = b->value(); - if( name=="gl:blend:srcFactor" ) - { - bf.src = f; - } - else - { - bf.dst = f; - } - memberData->implementation->addState( new BlendFuncStateComponent( bf ) ); -} - -static void alphaFuncSetter( const std::string &name, IECore::ConstDataPtr value, IECoreGL::Renderer::MemberData *memberData ) -{ - - const AlphaFuncStateComponent *a = memberData->implementation->getState(); - AlphaFunc af = a->value(); - - if( name == "gl:alphaTest:mode" ) - { - ConstStringDataPtr d = castWithWarning( value, name, "Renderer::setAttribute" ); - if( !d ) - { - return; - } - - GLenum m; - const std::string &v = d->readable(); - if( v=="never" ) - { - m = GL_NEVER; - } - else if( v=="less" ) - { - m = GL_LESS; - } - else if( v=="equal" ) - { - m = GL_EQUAL; - } - else if( v=="lequal" ) - { - m = GL_LEQUAL; - } - else if( v=="greater" ) - { - m = GL_GREATER; - } - else if( v=="notequal" ) - { - m = GL_NOTEQUAL; - } - else if( v=="gequal" ) - { - m = GL_GEQUAL; - } - else if( v=="always" ) - { - m = GL_ALWAYS; - } - else - { - msg( Msg::Error, "Renderer::setAttribute", boost::format( "Unsupported value \"%s\" for attribute \"%s\"." ) % v % name ); - return; - } - af.mode = m; - } - else if( name == "gl:alphaTest:value" ) - { - ConstFloatDataPtr d = castWithWarning( value, name, "Renderer::setAttribute" ); - if( !d ) - { - return; - } - af.value = d->readable(); - } - else - { - return; - } - - memberData->implementation->addState( new AlphaFuncStateComponent( af ) ); -} - -static IECore::ConstDataPtr alphaFuncGetter( const std::string &name, const IECoreGL::Renderer::MemberData *memberData ) -{ - const AlphaFuncStateComponent *b = memberData->implementation->getState(); - - if( name == "gl:alphaTest:mode" ) - { - GLenum m = b->value().mode; - switch( m ) - { - case GL_NEVER: - return new StringData( "never" ); - case GL_LESS: - return new StringData( "less" ); - case GL_EQUAL: - return new StringData( "equal" ); - case GL_LEQUAL: - return new StringData( "lequal" ); - case GL_GREATER: - return new StringData( "greater" ); - case GL_NOTEQUAL: - return new StringData( "notequal" ); - case GL_GEQUAL: - return new StringData( "gequal" ); - case GL_ALWAYS: - return new StringData( "always" ); - default : - msg( Msg::Warning, "Renderer::getAttribute", boost::format( "Invalid state for \"%s\"." ) % name ); - return new StringData( "invalid" ); - } - } - else if( name == "gl:alphaTest:value" ) - { - return new FloatData( b->value().value ); - } - - msg( Msg::Warning, "Renderer::getAttribute", boost::format( "Invalid state for \"%s\"." ) % name ); - return nullptr; -} - -static IECore::ConstDataPtr blendEquationGetter( const std::string &name, const IECoreGL::Renderer::MemberData *memberData ) -{ - const BlendEquationStateComponent *b = memberData->implementation->getState(); - switch( b->value() ) - { - case GL_FUNC_ADD : - return new StringData( "add" ); - case GL_FUNC_SUBTRACT : - return new StringData( "subtract" ); - case GL_FUNC_REVERSE_SUBTRACT : - return new StringData( "reverseSubtract" ); - case GL_MIN : - return new StringData( "min" ); - case GL_MAX : - return new StringData( "max" ); - default : - msg( Msg::Warning, "Renderer::getAttribute", boost::format( "Invalid state for \"%s\"." ) % name ); - return new StringData( "invalid" ); - } -} - -static void blendEquationSetter( const std::string &name, IECore::ConstDataPtr value, IECoreGL::Renderer::MemberData *memberData ) -{ - ConstStringDataPtr d = castWithWarning( value, name, "Renderer::setAttribute" ); - if( !d ) - { - return; - } - - GLenum f; - const std::string &v = d->readable(); - if( v=="add" ) - { - f = GL_FUNC_ADD; - } - else if( v=="subtract" ) - { - f = GL_FUNC_SUBTRACT; - } - else if( v=="reverseSubtract" ) - { - f = GL_FUNC_REVERSE_SUBTRACT; - } - else if( v=="min" ) - { - f = GL_MIN; - } - else if( v=="max" ) - { - f = GL_MAX; - } - else - { - msg( Msg::Error, "Renderer::setAttribute", boost::format( "Unsupported value \"%s\" for attribute \"%s\"." ) % v % name ); - return; - } - - memberData->implementation->addState( new BlendEquationStateComponent( f ) ); -} - -static IECore::ConstDataPtr pointsPrimitiveUseGLPointsGetter( const std::string &name, const IECoreGL::Renderer::MemberData *memberData ) -{ - const IECoreGL::PointsPrimitive::UseGLPoints *b = memberData->implementation->getState(); - switch( b->value() ) - { - case ForPointsOnly : - return new StringData( "forGLPoints" ); - case ForPointsAndDisks : - return new StringData( "forParticlesAndDisks" ); - case ForAll : - return new StringData( "forAll" ); - default : - msg( Msg::Warning, "Renderer::getAttribute", boost::format( "Invalid state for \"%s\"." ) % name ); - return new StringData( "invalid" ); - } - -} - -static void pointsPrimitiveUseGLPointsSetter( const std::string &name, IECore::ConstDataPtr value, IECoreGL::Renderer::MemberData *memberData ) -{ - ConstStringDataPtr d = castWithWarning( value, name, "Renderer::setAttribute" ); - if( !d ) - { - return; - } - GLPointsUsage u; - const std::string &v = d->readable(); - if( v=="forGLPoints" ) - { - u = ForPointsOnly; - } - else if( v=="forParticlesAndDisks" ) - { - u = ForPointsAndDisks; - } - else if( v=="forAll" ) - { - u = ForAll; - } - else - { - msg( Msg::Error, "Renderer::setAttribute", boost::format( "Unsupported value \"%s\" for attribute \"%s\"." ) % v % name ); - return; - } - memberData->implementation->addState( new IECoreGL::PointsPrimitive::UseGLPoints( u ) ); -} - -static IECore::ConstDataPtr nameGetter( const std::string &name, const IECoreGL::Renderer::MemberData *memberData ) -{ - const NameStateComponent *n = memberData->implementation->getState(); - return new StringData( n->name() ); -} - -static void nameSetter( const std::string &name, IECore::ConstDataPtr value, IECoreGL::Renderer::MemberData *memberData ) -{ - ConstStringDataPtr d = castWithWarning( value, name, "Renderer::setAttribute" ); - if( !d ) - { - return; - } - memberData->implementation->addState( new NameStateComponent( d->readable() ) ); -} - -static IECore::ConstDataPtr textPrimitiveTypeGetter( const std::string &name, const IECoreGL::Renderer::MemberData *memberData ) -{ - -#ifdef IECORE_WITH_FREETYPE - - const TextPrimitive::Type *b = memberData->implementation->getState(); - switch( b->value() ) - { - case TextPrimitive::Mesh : - return new StringData( "mesh" ); - case TextPrimitive::Sprite : - return new StringData( "sprite" ); - default : - msg( Msg::Warning, "Renderer::getAttribute", boost::format( "Invalid state for \"%s\"." ) % name ); - return new StringData( "invalid" ); - } - -#else - - IECore::msg( IECore::Msg::Warning, "Renderer::getAttribute", "IECore was not built with FreeType support." ); - return 0; - -#endif // IECORE_WITH_FREETYPE - -} - -static void textPrimitiveTypeSetter( const std::string &name, IECore::ConstDataPtr value, IECoreGL::Renderer::MemberData *memberData ) -{ - -#ifdef IECORE_WITH_FREETYPE - - ConstStringDataPtr d = castWithWarning( value, name, "Renderer::setAttribute" ); - if( !d ) - { - return; - } - TextPrimitive::RenderType t; - const std::string &v = d->readable(); - if( v=="mesh" ) - { - t = TextPrimitive::Mesh; - } - else if( v=="sprite" ) - { - t = TextPrimitive::Sprite; - } - else - { - msg( Msg::Error, "Renderer::setAttribute", boost::format( "Unsupported value \"%s\" for attribute \"%s\"." ) % v % name ); - return; - } - memberData->implementation->addState( new TextPrimitive::Type( t ) ); - -#else - - IECore::msg( IECore::Msg::Warning, "Renderer::setAttribute", "IECore was not built with FreeType support." ); - -#endif // IECORE_WITH_FREETYPE - -} - -template -static IECore::ConstDataPtr rendererSpaceGetter( const std::string &name, const IECoreGL::Renderer::MemberData *memberData ) -{ - typename T::ConstPtr b = memberData->implementation->getState< T >(); - switch( b->value() ) - { - case ObjectSpace : - return new StringData( "object" ); - case WorldSpace : - return new StringData( "world" ); - default : - msg( Msg::Warning, "Renderer::getAttribute", boost::format( "Invalid state for \"%s\"." ) % name ); - return new StringData( "invalid" ); - } -} - -template -static void rendererSpaceSetter( const std::string &name, IECore::ConstDataPtr value, IECoreGL::Renderer::MemberData *memberData ) -{ - ConstStringDataPtr d = castWithWarning( value, name, "Renderer::setAttribute" ); - if( !d ) - { - return; - } - RendererSpace s; - const std::string &v = d->readable(); - if( v=="object" ) - { - s = ObjectSpace; - } - else if ( v == "world" ) - { - s = WorldSpace; - } - else - { - msg( Msg::Error, "Renderer::setAttribute", boost::format( "Unsupported value \"%s\" for attribute \"%s\"." ) % v % name ); - return; - } - memberData->implementation->addState( new T( s ) ); -} - -static const AttributeSetterMap *attributeSetters() -{ - static AttributeSetterMap *a = new AttributeSetterMap; - if( !a->size() ) - { - (*a)["gl:primitive:wireframe"] = typedAttributeSetter; - (*a)["gl:primitive:wireframeWidth"] = typedAttributeSetter; - (*a)["gl:primitive:bound"] = typedAttributeSetter; - (*a)["gl:primitive:solid"] = typedAttributeSetter; - (*a)["gl:primitive:outline"] = typedAttributeSetter; - (*a)["gl:primitive:outlineWidth"] = typedAttributeSetter; - (*a)["gl:primitive:points"] = typedAttributeSetter; - (*a)["gl:primitive:pointWidth"] = typedAttributeSetter; - (*a)["gl:primitive:sortForTransparency"] = typedAttributeSetter; - (*a)["gl:primitive:wireframeColor"] = typedAttributeSetter; - (*a)["gl:primitive:boundColor"] = typedAttributeSetter; - (*a)["gl:primitive:outlineColor"] = typedAttributeSetter; - (*a)["gl:primitive:pointColor"] = typedAttributeSetter; - (*a)["gl:primitive:selectable"] = typedAttributeSetter; - (*a)["gl:color"] = typedAttributeSetter; - (*a)["color"] = colorAttributeSetter; - (*a)["opacity"] = opacityAttributeSetter; - (*a)["gl:blend:color"] = typedAttributeSetter; - (*a)["gl:blend:srcFactor"] = blendFactorSetter; - (*a)["gl:blend:dstFactor"] = blendFactorSetter; - (*a)["gl:blend:equation"] = blendEquationSetter; - (*a)["gl:shade:transparent"] = typedAttributeSetter; - (*a)["gl:pointsPrimitive:useGLPoints"] = pointsPrimitiveUseGLPointsSetter; - (*a)["gl:pointsPrimitive:glPointWidth"] = typedAttributeSetter; - (*a)["name"] = nameSetter; - (*a)["doubleSided"] = typedAttributeSetter; - (*a)["rightHandedOrientation"] = typedAttributeSetter; - (*a)["gl:curvesPrimitive:useGLLines"] = typedAttributeSetter; - (*a)["gl:curvesPrimitive:glLineWidth"] = typedAttributeSetter; - (*a)["gl:curvesPrimitive:ignoreBasis"] = typedAttributeSetter; - (*a)["gl:smoothing:points"] = typedAttributeSetter; - (*a)["gl:smoothing:lines"] = typedAttributeSetter; - (*a)["gl:smoothing:polygons"] = typedAttributeSetter; - (*a)["gl:textPrimitive:type"] = textPrimitiveTypeSetter; - (*a)["gl:cullingSpace"] = rendererSpaceSetter; - (*a)["gl:cullingBox"] = typedAttributeSetter; - (*a)["gl:procedural:reentrant"] = typedAttributeSetter; - (*a)["gl:visibility:camera"] = typedAttributeSetter; - (*a)["gl:depthTest"] = typedAttributeSetter; - (*a)["gl:depthMask"] = typedAttributeSetter; - (*a)["gl:alphaTest"] = typedAttributeSetter; - (*a)["gl:alphaTest:mode"] = alphaFuncSetter; - (*a)["gl:alphaTest:value"] = alphaFuncSetter; - (*a)["automaticInstancing"] = typedAttributeSetter; - (*a)["gl:automaticInstancing"] = typedAttributeSetter; - } - return a; -} - -static const AttributeGetterMap *attributeGetters() -{ - static AttributeGetterMap *a = new AttributeGetterMap; - if( !a->size() ) - { - (*a)["gl:primitive:wireframe"] = typedAttributeGetter; - (*a)["gl:primitive:wireframeWidth"] = typedAttributeGetter; - (*a)["gl:primitive:bound"] = typedAttributeGetter; - (*a)["gl:primitive:solid"] = typedAttributeGetter; - (*a)["gl:primitive:outline"] = typedAttributeGetter; - (*a)["gl:primitive:outlineWidth"] = typedAttributeGetter; - (*a)["gl:primitive:points"] = typedAttributeGetter; - (*a)["gl:primitive:pointWidth"] = typedAttributeGetter; - (*a)["gl:primitive:sortForTransparency"] = typedAttributeGetter; - (*a)["gl:primitive:wireframeColor"] = typedAttributeGetter; - (*a)["gl:primitive:boundColor"] = typedAttributeGetter; - (*a)["gl:primitive:outlineColor"] = typedAttributeGetter; - (*a)["gl:primitive:pointColor"] = typedAttributeGetter; - (*a)["gl:primitive:selectable"] = typedAttributeGetter; - (*a)["gl:color"] = typedAttributeGetter; - (*a)["color"] = colorAttributeGetter; - (*a)["opacity"] = opacityAttributeGetter; - (*a)["gl:blend:color"] = typedAttributeGetter; - (*a)["gl:blend:srcFactor"] = blendFactorGetter; - (*a)["gl:blend:dstFactor"] = blendFactorGetter; - (*a)["gl:blend:equation"] = blendEquationGetter; - (*a)["gl:shade:transparent"] = typedAttributeGetter; - (*a)["gl:pointsPrimitive:useGLPoints"] = pointsPrimitiveUseGLPointsGetter; - (*a)["gl:pointsPrimitive:glPointWidth"] = typedAttributeGetter; - (*a)["name"] = nameGetter; - (*a)["doubleSided"] = typedAttributeGetter; - (*a)["rightHandedOrientation"] = typedAttributeGetter; - (*a)["gl:curvesPrimitive:useGLLines"] = typedAttributeGetter; - (*a)["gl:curvesPrimitive:glLineWidth"] = typedAttributeGetter; - (*a)["gl:curvesPrimitive:ignoreBasis"] = typedAttributeGetter; - (*a)["gl:smoothing:points"] = typedAttributeGetter; - (*a)["gl:smoothing:lines"] = typedAttributeGetter; - (*a)["gl:smoothing:polygons"] = typedAttributeGetter; - (*a)["gl:textPrimitive:type"] = textPrimitiveTypeGetter; - (*a)["gl:cullingSpace"] = rendererSpaceGetter; - (*a)["gl:cullingBox"] = typedAttributeGetter; - (*a)["gl:procedural:reentrant"] = typedAttributeGetter; - (*a)["gl:visibility:camera"] = typedAttributeGetter; - (*a)["gl:depthTest"] = typedAttributeGetter; - (*a)["gl:depthMask"] = typedAttributeGetter; - (*a)["gl:alphaTest"] = typedAttributeGetter; - (*a)["gl:alphaTest:mode"] = alphaFuncGetter; - (*a)["gl:alphaTest:value"] = alphaFuncGetter; - (*a)["automaticInstancing"] = typedAttributeGetter; - (*a)["gl:automaticInstancing"] = typedAttributeGetter; - } - return a; -} - -void IECoreGL::Renderer::attributeBegin() -{ - if ( !m_data->inWorld ) - { - msg( Msg::Warning, "Renderer::attributeBegin", "Unsupported attributeBegin outside world begin/end blocks." ); - return; - } - m_data->implementation->attributeBegin(); -} - -void IECoreGL::Renderer::attributeEnd() -{ - if ( !m_data->inWorld ) - { - msg( Msg::Warning, "Renderer::attributeBegin", "Unsupported attributeBegin outside world begin/end blocks." ); - return; - } - m_data->implementation->attributeEnd(); -} - -void IECoreGL::Renderer::setAttribute( const std::string &name, IECore::ConstDataPtr value ) -{ - if ( !m_data->inWorld ) - { - msg( Msg::Warning, "Renderer::setAttribute", "Unsupported setAttribute outside world begin/end blocks." ); - return; - } - const AttributeSetterMap *s = attributeSetters(); - AttributeSetterMap::const_iterator it = s->find( name ); - if( it!=s->end() ) - { - it->second( name, value, m_data ); - } - else if( name.compare( 0, 5, "user:" )==0 ) - { - m_data->implementation->addUserAttribute( name, value->copy() ); - } - else if( name.find_first_of( ":" )!=string::npos ) - { - // prefixed for some other renderer, so we can ignore it - } - else - { - msg( Msg::Warning, "Renderer::setAttribute", boost::format( "Unsupported attribute \"%s\"." ) % name ); - } -} - -IECore::ConstDataPtr IECoreGL::Renderer::getAttribute( const std::string &name ) const -{ - if ( !m_data->inWorld ) - { - msg( Msg::Warning, "Renderer::getAttribute", "Unsupported getAttribute outside world begin/end blocks." ); - return nullptr; - } - - const AttributeGetterMap *g = attributeGetters(); - AttributeGetterMap::const_iterator it = g->find( name ); - if( it!=g->end() ) - { - return it->second( name, m_data ); - } - else if( name.compare( 0, 5, "user:" )==0 ) - { - return m_data->implementation->getUserAttribute( name ); - } - else if( name.find_first_of( ":" )!=string::npos ) - { - // prefixed for some other renderer, so we can ignore it - return nullptr; - } - else - { - msg( Msg::Warning, "Renderer::getAttribute", boost::format( "Unsupported attribute \"%s\"." ) % name ); - } - return nullptr; -} - -void IECoreGL::Renderer::shader( const std::string &type, const std::string &name, const IECore::CompoundDataMap ¶meters ) -{ - if ( !m_data->inWorld ) - { - msg( Msg::Warning, "Renderer::shader", "Unsupported shader call outside world begin/end blocks." ); - return; - } - - if( type=="surface" || type=="gl:surface" ) - { - string vertexSource = parameterValue( "gl:vertexSource", parameters, "" ); - string geometrySource = parameterValue( "gl:geometrySource", parameters, "" ); - string fragmentSource = parameterValue( "gl:fragmentSource", parameters, "" ); - - if( vertexSource == "" && geometrySource == "" && fragmentSource == "" ) - { - m_data->shaderLoader->loadSource( name, vertexSource, geometrySource, fragmentSource ); - } - - CompoundObjectPtr parametersData = new CompoundObject; - for( CompoundDataMap::const_iterator it=parameters.begin(); it!=parameters.end(); it++ ) - { - if( it->first!="gl:fragmentSource" && it->first!="gl:geometrySource" && it->first!="gl:vertexSource" ) - { - parametersData->members()[it->first] = it->second; - } - } - - ShaderStateComponentPtr shaderState = new ShaderStateComponent( m_data->shaderLoader, m_data->textureLoader, vertexSource, geometrySource, fragmentSource, parametersData ); - m_data->implementation->addState( shaderState ); - } - else if( type.find( "gl:" ) == 0 || type.find_first_of( ":" ) == string::npos ) - { - msg( Msg::Warning, "Renderer::shader", boost::format( "Unsupported shader type \"%s\"." ) % type ); - } -} - -void IECoreGL::Renderer::light( const std::string &name, const std::string &handle, const IECore::CompoundDataMap ¶meters ) -{ - msg( Msg::Warning, "Renderer::light", "Not implemented" ); -} - -void IECoreGL::Renderer::illuminate( const std::string &lightHandle, bool on ) -{ - msg( Msg::Warning, "Renderer::illuminate", "Not implemented" ); -} - -///////////////////////////////////////////////////////////////////////////////////////////////////////// -// motion -///////////////////////////////////////////////////////////////////////////////////////////////////////// - -void IECoreGL::Renderer::motionBegin( const std::set × ) -{ - msg( Msg::Warning, "Renderer::motionBegin", "Not implemented" ); -} - -void IECoreGL::Renderer::motionEnd() -{ - msg( Msg::Warning, "Renderer::motionEnd", "Not implemented" ); -} - -///////////////////////////////////////////////////////////////////////////////////////////////////////// -// primitives -///////////////////////////////////////////////////////////////////////////////////////////////////////// - -static void addPrimVarsToPrimitive( IECoreGL::PrimitivePtr primitive, const IECoreScene::PrimitiveVariableMap &primVars ) -{ - // add primVars to the gl primitive - for( IECoreScene::PrimitiveVariableMap::const_iterator it=primVars.begin(); it!=primVars.end(); it++ ) - { - try - { - primitive->addPrimitiveVariable( it->first, it->second ); - } - catch( const std::exception &e ) - { - IECore::msg( IECore::Msg::Error, "Renderer::addPrimitive", boost::format( "Failed to add primitive variable %s (%s)." ) % it->first % e.what() ); - } - } -} - -void IECoreGL::Renderer::points( size_t numPoints, const IECoreScene::PrimitiveVariableMap &primVars ) -{ - try - { - IECoreScene::PointsPrimitivePtr p = new IECoreScene::PointsPrimitive( numPoints ); - p->variables = primVars; - m_data->addPrimitive( p.get() ); - } - catch( const std::exception &e ) - { - msg( Msg::Warning, "Renderer::points", e.what() ); - return; - } -} - -void IECoreGL::Renderer::disk( float radius, float z, float thetaMax, const IECoreScene::PrimitiveVariableMap &primVars ) -{ - DiskPrimitivePtr prim = new DiskPrimitive( radius, z, thetaMax ); - addPrimVarsToPrimitive( prim, primVars ); - m_data->addPrimitive( prim ); -} - -void IECoreGL::Renderer::curves( const IECore::CubicBasisf &basis, bool periodic, IECore::ConstIntVectorDataPtr numVertices, const IECoreScene::PrimitiveVariableMap &primVars ) -{ - try - { - IECoreScene::CurvesPrimitivePtr c = new IECoreScene::CurvesPrimitive( numVertices, basis, periodic ); - c->variables = primVars; - m_data->addPrimitive( c.get() ); - } - catch( const std::exception &e ) - { - msg( Msg::Warning, "Renderer::curves", e.what() ); - return; - } -} - -void IECoreGL::Renderer::text( const std::string &font, const std::string &text, float kerning, const IECoreScene::PrimitiveVariableMap &primVars ) -{ - -#ifdef IECORE_WITH_FREETYPE - FontPtr f = m_data->fontLoader->load( font ); - - if( !f ) - { - IECore::msg( IECore::Msg::Warning, "Renderer::text", boost::format( "Font \"%s\" not found." ) % font ); - return; - } - - f->coreFont()->setKerning( kerning ); - - TextPrimitivePtr prim = new TextPrimitive( text, f ); - addPrimVarsToPrimitive( prim, primVars ); - m_data->addPrimitive( prim ); -#else - IECore::msg( IECore::Msg::Warning, "Renderer::text", "IECore was not built with FreeType support." ); -#endif // IECORE_WITH_FREETYPE -} - -void IECoreGL::Renderer::sphere( float radius, float zMin, float zMax, float thetaMax, const IECoreScene::PrimitiveVariableMap &primVars ) -{ - SpherePrimitivePtr prim = new SpherePrimitive( radius, zMin, zMax, thetaMax ); - addPrimVarsToPrimitive( prim, primVars ); - m_data->addPrimitive( prim ); -} - -static const std::string &imageFragmentShader() -{ - // fragment shader - static const std::string shaderCode = - "uniform sampler2D texture;" - "" - "varying vec2 fragmentuv;" - "" - "void main()" - "{" - " gl_FragColor = texture2D( texture, fragmentuv );" - "}"; - return shaderCode; -} - -/// \todo This positions images incorrectly when dataWindow!=displayWindow. This is because the texture -/// contains only the dataWindow contents, but we've positioned the card as if it will contain the whole -/// displayWindow. -void IECoreGL::Renderer::image( const Imath::Box2i &dataWindow, const Imath::Box2i &displayWindow, const IECoreScene::PrimitiveVariableMap &primVars ) -{ - if ( m_data->currentInstance ) - { - IECore::msg( IECore::Msg::Warning, "Renderer::image", "Images currently not supported inside instances." ); - return; - } - - IECoreImage::ImagePrimitivePtr image = new IECoreImage::ImagePrimitive( dataWindow, displayWindow ); - Imath::V3f boxMin( displayWindow.min.x, displayWindow.min.y, 0.0 ); - Imath::V3f boxMax( 1.0f + displayWindow.max.x, 1.0f + displayWindow.max.y, 0.0 ); - Imath::V3f center = (boxMin + boxMax) / 2.0; - Imath::Box3f bound( boxMin - center, boxMax - center ); - - if( !m_data->checkCulling( bound ) ) - { - return; - } - - for( const auto &primVar : primVars ) - { - if( - primVar.second.interpolation == PrimitiveVariable::Vertex || - primVar.second.interpolation == PrimitiveVariable::Varying || - primVar.second.interpolation == PrimitiveVariable::FaceVarying - ) - { - image->channels[primVar.first] = primVar.second.data; - } - } - - IECore::CompoundObjectPtr params = new IECore::CompoundObject(); - params->members()[ "texture" ] = image; - - ShaderStateComponentPtr shaderState = new ShaderStateComponent( m_data->shaderLoader, m_data->textureLoader, "", "", imageFragmentShader(), params ); - - m_data->implementation->transformBegin(); - - M44f xform; - xform[3][0] = center.x; - xform[3][1] = center.y; - xform[3][2] = center.z; - - xform[0][0] = boxSize( bound ).x ; - xform[1][1] = boxSize( bound ).y ; - xform[2][2] = 1.0; - - m_data->implementation->concatTransform( xform ); - m_data->implementation->attributeBegin(); - m_data->implementation->addState( shaderState ); - QuadPrimitivePtr quad = new QuadPrimitive( 1.0, 1.0 ); - m_data->implementation->addPrimitive( quad ); - m_data->implementation->attributeEnd(); - - m_data->implementation->transformEnd(); -} - -void IECoreGL::Renderer::mesh( IECore::ConstIntVectorDataPtr vertsPerFace, IECore::ConstIntVectorDataPtr vertIds, const std::string &interpolation, const IECoreScene::PrimitiveVariableMap &primVars ) -{ - try - { - IECoreScene::MeshPrimitivePtr m = new IECoreScene::MeshPrimitive; - IECoreScene::PrimitiveVariableMap::const_iterator it = primVars.find( "P" ); - if( it == primVars.end() ) - { - throw IECore::Exception( "Trying to render a mesh without \"P\"" ); - } - - IECore::V3fVectorDataPtr pData = runTimeCast< IECore::V3fVectorData >( it->second.data ); - if( !pData ) - { - throw IECore::Exception( "Mesh \"P\" variable has incorrect type" ); - } - - m->setTopologyUnchecked( vertsPerFace, vertIds, pData->readable().size(), interpolation ); - m->variables = primVars; - m_data->addPrimitive( m.get() ); - } - catch( const std::exception &e ) - { - msg( Msg::Warning, "Renderer::mesh", e.what() ); - return; - } -} - -void IECoreGL::Renderer::nurbs( int uOrder, IECore::ConstFloatVectorDataPtr uKnot, float uMin, float uMax, int vOrder, IECore::ConstFloatVectorDataPtr vKnot, float vMin, float vMax, const IECoreScene::PrimitiveVariableMap &primVars ) -{ - msg( Msg::Warning, "Renderer::nurbs", "Not implemented" ); -} - -void IECoreGL::Renderer::patchMesh( const IECore::CubicBasisf &uBasis, const IECore::CubicBasisf &vBasis, int nu, bool uPeriodic, int nv, bool vPeriodic, const IECoreScene::PrimitiveVariableMap &primVars ) -{ - msg( Msg::Warning, "Renderer::patchMesh", "Not implemented" ); -} - -void IECoreGL::Renderer::geometry( const std::string &type, const IECore::CompoundDataMap &topology, const IECoreScene::PrimitiveVariableMap &primVars ) -{ - msg( Msg::Warning, "Renderer::geometry", boost::format( "Geometry type \"%s\" not implemented." ) % type ); -} - -void IECoreGL::Renderer::procedural( IECoreScene::Renderer::ProceduralPtr proc ) -{ - if ( m_data->currentInstance ) - { - IECore::msg( IECore::Msg::Warning, "Renderer::procedural", "Procedurals currently not supported inside instances." ); - return; - } - if ( m_data->checkCulling( proc->bound() ) ) - { - if( ExternalProcedural *externalProcedural = dynamic_cast( proc.get() ) ) - { - attributeBegin(); - setAttribute( "gl:primitive:wireframe", new BoolData( true ) ); - setAttribute( "gl:primitive:solid", new BoolData( false ) ); - setAttribute( "gl:curvesPrimitive:useGLLines", new BoolData( true ) ); - IECoreScene::CurvesPrimitive::createBox( externalProcedural->bound() )->render( this ); - attributeEnd(); - } - else - { - m_data->implementation->addProcedural( proc, this ); - } - } -} - -///////////////////////////////////////////////////////////////////////////////////////////////////////// -// instancing -///////////////////////////////////////////////////////////////////////////////////////////////////////// - -void IECoreGL::Renderer::instanceBegin( const std::string &name, const IECore::CompoundDataMap ¶meters ) -{ - if ( m_data->inWorld ) - { - msg( Msg::Warning, "Renderer::instanceBegin", "Unsupported instanceBegin call after worldBegin." ); - return; - } - if ( m_data->currentInstance ) - { - IECore::msg( IECore::Msg::Warning, "Renderer::instanceBegin", "Instance already being defined!" ); - return; - } - MemberData::InstanceMap::const_iterator it = m_data->instances.find( name ); - if ( it != m_data->instances.end() ) - { - msg( Msg::Warning, "Renderer::instance", boost::format( "Overwriting instance named \"%s\"." ) % name ); - return; - } - m_data->currentInstance = new Group(); - m_data->instances[ name ] = m_data->currentInstance; -} - -void IECoreGL::Renderer::instanceEnd() -{ - if ( m_data->inWorld ) - { - msg( Msg::Warning, "Renderer::instanceEnd", "Unsupported instanceEnd call after worldBegin." ); - return; - } - if ( !m_data->currentInstance ) - { - IECore::msg( IECore::Msg::Warning, "Renderer::instanceEnd", "instanceEnd called when no instances are being defined!" ); - return; - } - m_data->currentInstance = nullptr; -} - -void IECoreGL::Renderer::instance( const std::string &name ) -{ - MemberData::InstanceMap::iterator it = m_data->instances.find( name ); - if ( it == m_data->instances.end() ) - { - msg( Msg::Warning, "Renderer::instance", boost::format( "No instance named \"%s\" was found." ) % name ); - return; - } - if ( m_data->currentInstance ) - { - // instance called within another instance - m_data->addCurrentInstanceChild( it->second ); - } - else if ( m_data->inWorld ) - { - m_data->implementation->addInstance( it->second ); - } - else - { - msg( Msg::Warning, "Renderer::instance", "Unsupported call to instance outside world and instance block!" ); - } -} - -///////////////////////////////////////////////////////////////////////////////////////////////////////// -// commands -///////////////////////////////////////////////////////////////////////////////////////////////////////// - -typedef IECore::DataPtr (*Command)( const std::string &name, const IECore::CompoundDataMap ¶meters, IECoreGL::Renderer::MemberData *memberData ); -typedef std::map CommandMap; - -bool removeObjectWalk( IECoreGL::GroupPtr parent, IECoreGL::GroupPtr child, const std::string &objectName, IECoreGL::Renderer::MemberData *memberData ) -{ - const NameStateComponent *stateName = child->getState()->get(); - if( stateName && stateName->name()==objectName ) - { - if( parent ) - { - { - std::lock_guard lock( parent->mutex() ); - parent->removeChild( child.get() ); - } - { - std::lock_guard lock2( memberData->removedObjectsMutex ); - memberData->removedObjects.insert( child ); - } - } - else - { - // no parent, ie we're at the root of the Scene. just remove all the children. - std::lock_guard lock( child->mutex() ); - std::lock_guard lock2( memberData->removedObjectsMutex ); - for( IECoreGL::Group::ChildContainer::const_iterator it=child->children().begin(); it!=child->children().end(); it++ ) - { - memberData->removedObjects.insert( *it ); - } - child->clearChildren(); - } - return true; - } - - bool result = false; - std::lock_guard lock( child->mutex() ); - IECoreGL::Group::ChildContainer::const_iterator it = child->children().begin(); - while( it!=child->children().end() ) - { - IECoreGL::GroupPtr g = IECore::runTimeCast( *it ); - it++; - if( g ) - { - result = result | removeObjectWalk( child, g, objectName, memberData ); - } - } - if ( result && child->children().size() == 0 && parent ) - { - // group after removal became empty, remove it too. - { - std::lock_guard parentLock( parent->mutex() ); - parent->removeChild( child.get() ); - } - { - std::lock_guard lock2( memberData->removedObjectsMutex ); - memberData->removedObjects.insert( child ); - } - } - return result; -} - -IECore::DataPtr removeObjectCommand( const std::string &name, const IECore::CompoundDataMap ¶meters, IECoreGL::Renderer::MemberData *memberData ) -{ - DeferredRendererImplementationPtr r = runTimeCast( memberData->implementation ); - if( !r ) - { - msg( Msg::Warning, "Renderer::command", "removeObject command operates only in deferred mode" ); - return nullptr; - } - - if( !memberData->inEdit ) - { - msg( Msg::Warning, "Renderer::command", "removeObject command operates only within an editBegin/editEnd block" ); - return nullptr; - } - - string objectName = parameterValue( "name", parameters, "" ); - if( objectName=="" ) - { - msg( Msg::Warning, "Renderer::command", "removeObject command expects StringData parameter \"name\"" ); - return nullptr; - } - - ScenePtr scene = r->scene(); - bool result = removeObjectWalk( nullptr, r->scene()->root(), objectName, memberData ); - - return new IECore::BoolData( result ); -} - -IECore::DataPtr editBeginCommand( const std::string &name, const IECore::CompoundDataMap ¶meters, IECoreGL::Renderer::MemberData *memberData ) -{ - DeferredRendererImplementationPtr r = runTimeCast( memberData->implementation ); - if( !r ) - { - msg( Msg::Warning, "Renderer::command", "editBegin command operates only in deferred mode" ); - return nullptr; - } - - memberData->inWorld = true; - memberData->inEdit = true; - return new IECore::BoolData( true ); -} - -IECore::DataPtr editEndCommand( const std::string &name, const IECore::CompoundDataMap ¶meters, IECoreGL::Renderer::MemberData *memberData ) -{ - DeferredRendererImplementationPtr r = runTimeCast( memberData->implementation ); - if( !r ) - { - msg( Msg::Warning, "Renderer::command", "editEnd command operates only in deferred mode" ); - return nullptr; - } - - memberData->inWorld = false; - memberData->inEdit = false; - // we defer final destruction of objects till now, so we don't destroy gl resources directly in removeObjectCommand. - // we could be on any thread in removeObjectCommand (it can be called from procedurals) but we require that editEnd - // is called on the GL thread, so this is therefore the only safe place to do the destruction. - memberData->removedObjects.clear(); - return new IECore::BoolData( true ); -} - -IECore::DataPtr editQueryCommand( const std::string &name, const IECore::CompoundDataMap ¶meters, IECoreGL::Renderer::MemberData *memberData ) -{ - DeferredRendererImplementationPtr r = runTimeCast( memberData->implementation ); - if( !r ) - { - msg( Msg::Warning, "Renderer::command", "editQuery command operates only in deferred mode" ); - return nullptr; - } - - return new IECore::BoolData( memberData->inEdit ); -} - -static const CommandMap &commands() -{ - static CommandMap c; - if( !c.size() ) - { - c["removeObject"] = removeObjectCommand; - c["editBegin"] = editBeginCommand; - c["editEnd"] = editEndCommand; - c["editQuery"] = editQueryCommand; - } - return c; -} - -IECore::DataPtr IECoreGL::Renderer::command( const std::string &name, const IECore::CompoundDataMap ¶meters ) -{ - if ( m_data->currentInstance ) - { - IECore::msg( IECore::Msg::Warning, "Renderer::command", "Commands not supported inside instances." ); - return nullptr; - } - const CommandMap &c = commands(); - CommandMap::const_iterator it = c.find( name ); - if( it!=c.end() ) - { - return it->second( name, parameters, m_data ); - } - - if( name.compare( 0, 3, "gl:" )==0 || name.find( ':' )==string::npos ) - { - msg( Msg::Warning, "Renderer::command", boost::format( "Unsuppported command \"%s\"." ) % name ); - return nullptr; - } - - return nullptr; -} - -void IECoreGL::Renderer::editBegin( const std::string &name, const IECore::CompoundDataMap ¶meters ) -{ - msg( Msg::Warning, "Renderer::editBegin", "Not implemented" ); -} - -void IECoreGL::Renderer::editEnd() -{ - msg( Msg::Warning, "Renderer::editEnd", "Not implemented" ); -} - -IECoreGL::ShaderLoader *IECoreGL::Renderer::shaderLoader() -{ - return m_data->shaderLoader.get(); -} - -IECoreGL::TextureLoader *IECoreGL::Renderer::textureLoader() -{ - return m_data->textureLoader.get(); -} diff --git a/src/IECoreGL/RendererImplementation.cpp b/src/IECoreGL/RendererImplementation.cpp deleted file mode 100644 index e5beac4e93..0000000000 --- a/src/IECoreGL/RendererImplementation.cpp +++ /dev/null @@ -1,45 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007, 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 Image Engine Design 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. -// -////////////////////////////////////////////////////////////////////////// - -#include "IECoreGL/private/RendererImplementation.h" - -using namespace IECoreGL; - -RendererImplementation::RendererImplementation() -{ -} - -RendererImplementation::~RendererImplementation() -{ -} diff --git a/src/IECoreGL/bindings/IECoreGLBinding.cpp b/src/IECoreGL/bindings/IECoreGLBinding.cpp index ff4a979eec..255cb88109 100644 --- a/src/IECoreGL/bindings/IECoreGLBinding.cpp +++ b/src/IECoreGL/bindings/IECoreGLBinding.cpp @@ -55,7 +55,6 @@ #include "IECoreGL/bindings/PointsPrimitiveBinding.h" #include "IECoreGL/bindings/PrimitiveBinding.h" #include "IECoreGL/bindings/RenderableBinding.h" -#include "IECoreGL/bindings/RendererBinding.h" #include "IECoreGL/bindings/SceneBinding.h" #include "IECoreGL/bindings/SelectorBinding.h" #include "IECoreGL/bindings/ShaderBinding.h" @@ -80,7 +79,6 @@ using namespace boost::python; BOOST_PYTHON_MODULE( _IECoreGL ) { - bindRenderer(); bindBindable(); bindShader(); bindTexture(); diff --git a/src/IECoreGL/bindings/RendererBinding.cpp b/src/IECoreGL/bindings/RendererBinding.cpp deleted file mode 100644 index a623b4c0e7..0000000000 --- a/src/IECoreGL/bindings/RendererBinding.cpp +++ /dev/null @@ -1,91 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2012, 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 Image Engine Design 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. -// -////////////////////////////////////////////////////////////////////////// - -#include "boost/python.hpp" - -#include "IECoreGL/bindings/RendererBinding.h" - -#include "IECoreGL/Renderer.h" -#include "IECoreGL/Scene.h" -#include "IECoreGL/ShaderLoader.h" -#include "IECoreGL/TextureLoader.h" - -#include "IECorePython/RunTimeTypedBinding.h" - -#include "IECore/SimpleTypedData.h" - -using namespace boost::python; -using namespace IECore; - -namespace IECoreGL -{ - -static ShaderLoaderPtr shaderLoader( Renderer &r ) -{ - return r.shaderLoader(); -} - -static TextureLoaderPtr textureLoader( Renderer &r ) -{ - return r.textureLoader(); -} - -static void worldBegin( Renderer &r ) -{ - if ( boost::static_pointer_cast(r.getOption( "gl:mode" ))->readable() == "deferred" ) - { - // The deferred render uses multiple threads when rendering procedurals. So we enable threads for python here. - // \todo Consider moving this to IECore::Renderer::worldBegin binding (assuming all decent renderers are multithreaded). -#if PY_VERSION_HEX < 0x03090000 - if ( !PyEval_ThreadsInitialized() ) - { - PyEval_InitThreads(); - } -#endif - } - r.worldBegin(); -} - -void bindRenderer() -{ - IECorePython::RunTimeTypedClass() - .def( init<>() ) - .def( "worldBegin", &worldBegin ) - .def( "scene", &Renderer::scene ) - .def( "shaderLoader", &shaderLoader ) - .def( "textureLoader", &textureLoader ) - ; -} - -} diff --git a/src/IECoreScene/Renderer.cpp b/src/IECoreScene/Renderer.cpp deleted file mode 100644 index 064d5128c2..0000000000 --- a/src/IECoreScene/Renderer.cpp +++ /dev/null @@ -1,102 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2009, 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 Image Engine Design 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. -// -////////////////////////////////////////////////////////////////////////// - -#include "IECoreScene/Renderer.h" - -#include "IECore/CompoundObject.h" -#include "IECore/CompoundParameter.h" - -using namespace Imath; -using namespace IECore; -using namespace IECoreScene; - -const Box3f Renderer::Procedural::noBound( V3f( -std::numeric_limits::infinity() ), V3f( std::numeric_limits::infinity() ) ); - -IE_CORE_DEFINERUNTIMETYPED( Renderer ); - -Renderer::Renderer() -{ -} - -Renderer::~Renderer() -{ -} - -Renderer::Procedural::Procedural() -{ -} - -Renderer::Procedural::~Procedural() -{ -} - -Renderer::ExternalProcedural::ExternalProcedural( const std::string &fileName, const Imath::Box3f &bound, const CompoundDataMap ¶meters ) - : m_fileName( fileName ), m_bound( bound ), m_parameters( parameters ) -{ -} - -Renderer::ExternalProcedural::~ExternalProcedural() -{ -} - -const std::string &Renderer::ExternalProcedural::fileName() const -{ - return m_fileName; -} - -const CompoundDataMap &Renderer::ExternalProcedural::parameters() const -{ - return m_parameters; -} - -Imath::Box3f Renderer::ExternalProcedural::bound() const -{ - return m_bound; -} - -void Renderer::ExternalProcedural::render( Renderer *renderer ) const -{ -} - -MurmurHash Renderer::ExternalProcedural::hash() const -{ - MurmurHash h; - h.append( m_fileName ); - for( CompoundDataMap::const_iterator it = m_parameters.begin(), eIt = m_parameters.end(); it != eIt; ++it ) - { - h.append( it->first ); - it->second->hash( h ); - } - return h; -} diff --git a/src/IECoreScene/bindings/IECoreScene.cpp b/src/IECoreScene/bindings/IECoreScene.cpp index 59a68e51ac..fb1939e22a 100644 --- a/src/IECoreScene/bindings/IECoreScene.cpp +++ b/src/IECoreScene/bindings/IECoreScene.cpp @@ -91,7 +91,6 @@ #include "PrimitiveVariableBinding.h" #include "RemoveSmoothSkinningInfluencesOpBinding.h" #include "RenderableBinding.h" -#include "RendererBinding.h" #include "ReorderSmoothSkinningInfluencesOpBinding.h" #include "SampledSceneInterfaceBinding.h" #include "SceneCacheBinding.h" @@ -128,7 +127,6 @@ BOOST_PYTHON_MODULE(_IECoreScene) bindRenderable(); bindStateRenderable(); bindVisibleRenderable(); - bindRenderer(); bindParticleWriter(); bindPDCParticleWriter(); bindPrimitive(); diff --git a/src/IECoreScene/bindings/RendererBinding.cpp b/src/IECoreScene/bindings/RendererBinding.cpp deleted file mode 100644 index 827ae0c819..0000000000 --- a/src/IECoreScene/bindings/RendererBinding.cpp +++ /dev/null @@ -1,432 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2010, 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 Image Engine Design 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. -// -////////////////////////////////////////////////////////////////////////// - -// This include needs to be the very first to prevent problems with warnings -// regarding redefinition of _POSIX_C_SOURCE -#include "boost/python.hpp" - -#include "RendererBinding.h" - -#include "IECoreScene/Renderer.h" - -#include "IECorePython/RunTimeTypedBinding.h" -#include "IECorePython/ScopedGILLock.h" -#include "IECorePython/ScopedGILRelease.h" - -#include "IECore/CompoundObject.h" -#include "IECore/MessageHandler.h" - -#include "boost/python/suite/indexing/container_utils.hpp" - -using namespace boost::python; -using namespace boost; -using namespace std; -using namespace IECore; -using namespace IECorePython; -using namespace IECoreScene; -using namespace IECoreSceneModule; - -namespace -{ - -class ProceduralWrapper : public RefCountedWrapper -{ - public : - - ProceduralWrapper( PyObject *wrapperSelf ) - : RefCountedWrapper( wrapperSelf ) - { - }; - - Imath::Box3f bound() const override - { - ScopedGILLock gilLock; - try - { - object o = this->methodOverride( "bound" ); - if( o ) - { - return extract( o() ); - } - else - { - msg( Msg::Error, "ProceduralWrap::bound", "bound() python method not defined" ); - } - } - catch( const error_already_set & ) - { - PyErr_Print(); - } - catch( const std::exception &e ) - { - msg( Msg::Error, "ProceduralWrap::bound", e.what() ); - } - catch( ... ) - { - msg( Msg::Error, "ProceduralWrap::bound", "Caught unknown exception" ); - } - return Imath::Box3f(); // empty - } - - void render( Renderer *r ) const override - { - ScopedGILLock gilLock; - // ideally we might not do any exception handling here, and always leave it to the host. - // but in our case the host is mainly 3delight and that does no exception handling at all. - try - { - object o = this->methodOverride( "render" ); - if( o ) - { - o( RendererPtr( r ) ); - } - else - { - msg( Msg::Error, "ProceduralWrap::render", "render() python method not defined" ); - } - } - catch( const error_already_set & ) - { - PyErr_Print(); - } - catch( const std::exception &e ) - { - msg( Msg::Error, "ProceduralWrap::render", e.what() ); - } - catch( ... ) - { - msg( Msg::Error, "ProceduralWrap::render", "Caught unknown exception" ); - } - } - - MurmurHash hash() const override - { - ScopedGILLock gilLock; - // ideally we might not do any exception handling here, and always leave it to the host. - // but in our case the host is mainly 3delight and that does no exception handling at all. - try - { - object o = this->methodOverride( "hash" ); - if( o ) - { - return extract( o() ); - } - else - { - msg( Msg::Error, "ProceduralWrap::hash", "hash() python method not defined" ); - } - } - catch( const error_already_set & ) - { - PyErr_Print(); - } - catch( const std::exception &e ) - { - msg( Msg::Error, "ProceduralWrap::hash", e.what() ); - } - catch( ... ) - { - msg( Msg::Error, "ProceduralWrap::hash", "Caught unknown exception" ); - } - return MurmurHash(); - } - -}; - -static void fillCompoundDataMap( CompoundDataMap &m, const dict &d ) -{ - boost::python::list keys = d.keys(); - for( unsigned i=0; i( keys[i] ); - m[c] = extract( d[keys[i]] ); - } -} - -static void fillPrimitiveVariableMap( PrimitiveVariableMap &m, const dict &d ) -{ - boost::python::list keys = d.keys(); - for( unsigned i=0; i( keys[i] )] = extract( d[keys[i]] ); - } -} - -static DataPtr getOption( Renderer &r, const std::string &name ) -{ - ConstDataPtr d = r.getOption( name ); - if( d ) - { - return d->copy(); - } - return nullptr; -} - -static void camera( Renderer &r, const std::string &name, const dict ¶meters ) -{ - CompoundDataMap p; - fillCompoundDataMap( p, parameters ); - r.camera( name, p ); -} - -static void display( Renderer &r, const std::string &name, const std::string &type, const std::string &data, const dict ¶meters ) -{ - CompoundDataMap p; - fillCompoundDataMap( p, parameters ); - r.display( name, type, data, p ); -} - -static DataPtr getAttribute( Renderer &r, const std::string &name ) -{ - ConstDataPtr d = r.getAttribute( name ); - if( d ) - { - return d->copy(); - } - return nullptr; -} - -static void shader( Renderer &r, const std::string &type, const std::string &name, const dict ¶meters ) -{ - CompoundDataMap p; - fillCompoundDataMap( p, parameters ); - r.shader( type, name, p ); -} - -static void light( Renderer &r, const std::string &name, const std::string &handle, const dict ¶meters ) -{ - CompoundDataMap p; - fillCompoundDataMap( p, parameters ); - r.light( name, handle, p ); -} - -static void motionBegin( Renderer &r, const boost::python::list × ) -{ - std::set t; - for( unsigned i=0; i( times[i] ) ); - } - r.motionBegin( t ); -} - -static void points( Renderer &r, size_t numPoints, const dict &primVars ) -{ - PrimitiveVariableMap p; - fillPrimitiveVariableMap( p, primVars ); - r.points( numPoints, p ); -} - -static void disk( Renderer &r, float radius, float z, float thetaMax, const dict &primVars ) -{ - PrimitiveVariableMap p; - fillPrimitiveVariableMap( p, primVars ); - r.disk( radius, z, thetaMax, p ); -} - -static void curves( Renderer &r, const CubicBasisf &basis, bool periodic, ConstIntVectorDataPtr numVertices, const dict &primVars ) -{ - PrimitiveVariableMap p; - fillPrimitiveVariableMap( p, primVars ); - r.curves( basis, periodic, numVertices, p ); -} - -static void text( Renderer &r, const std::string &font, const std::string &text, float kerning, const dict &primVars ) -{ - PrimitiveVariableMap p; - fillPrimitiveVariableMap( p, primVars ); - r.text( font, text, kerning, p ); -} - -static void sphere( Renderer &r, float radius, float zMin, float zMax, float thetaMax, const dict &primVars ) -{ - PrimitiveVariableMap p; - fillPrimitiveVariableMap( p, primVars ); - r.sphere( radius, zMin, zMax, thetaMax, p ); -} - -static void image( Renderer &r, const Imath::Box2i &dataWindow, const Imath::Box2i &displayWindow, const dict &primVars ) -{ - PrimitiveVariableMap p; - fillPrimitiveVariableMap( p, primVars ); - r.image( dataWindow, displayWindow, p ); -} - -static void mesh( Renderer &r, ConstIntVectorDataPtr vertsPerFace, ConstIntVectorDataPtr vertIds, const std::string &interpolation, const dict &primVars ) -{ - PrimitiveVariableMap p; - fillPrimitiveVariableMap( p, primVars ); - r.mesh( vertsPerFace, vertIds, interpolation, p ); -} - -static void nurbs( Renderer &r, int uOrder, ConstFloatVectorDataPtr uKnot, float uMin, float uMax, int vOrder, ConstFloatVectorDataPtr vKnot, float vMin, float vMax, const dict &primVars ) -{ - PrimitiveVariableMap p; - fillPrimitiveVariableMap( p, primVars ); - r.nurbs( uOrder, uKnot, uMin, uMax, vOrder, vKnot, vMin, vMax, p ); -} - -static void patchMesh( Renderer &r, const CubicBasisf &uBasis, const CubicBasisf &vBasis, int nu, bool uPeriodic, int nv, bool vPeriodic, const dict &primVars ) -{ - PrimitiveVariableMap p; - fillPrimitiveVariableMap( p, primVars ); - r.patchMesh( uBasis, vBasis, nu, uPeriodic, nv, vPeriodic, p ); -} - -static void geometry( Renderer &r, const std::string &type, const dict &topology, const dict &primVars ) -{ - CompoundDataMap t; - fillCompoundDataMap( t, topology ); - - PrimitiveVariableMap p; - fillPrimitiveVariableMap( p, primVars ); - r.geometry( type, t, p ); -} - -static void instanceBegin( Renderer &r, const std::string &name, const dict ¶meters ) -{ - CompoundDataMap p; - fillCompoundDataMap( p, parameters ); - r.instanceBegin( name, p ); -} - -static IECore::DataPtr command( Renderer &r, const std::string &name, const dict ¶meters ) -{ - CompoundDataMap p; - fillCompoundDataMap( p, parameters ); - return r.command( name, p ); -} - -static void procedural( Renderer &r, Renderer::ProceduralPtr proc ) -{ - ScopedGILRelease gilRelease; - r.procedural( proc ); -} - -static void worldEnd( Renderer &r ) -{ - ScopedGILRelease gilRelease; - r.worldEnd(); -} - -static void editBegin( Renderer &r, const std::string &name, const dict ¶meters ) -{ - IECore::CompoundDataMap p; - fillCompoundDataMap( p, parameters ); - r.editBegin( name, p ); -} - -static Renderer::ExternalProceduralPtr externalProceduralConstructor( const char *fileName, const Imath::Box3f &bound, const dict ¶meters ) -{ - CompoundDataMap p; - fillCompoundDataMap( p, parameters ); - return new Renderer::ExternalProcedural( fileName, bound, p ); -} - -} // namespace - -namespace IECoreSceneModule -{ - -void bindRenderer() -{ - scope rendererScope = RunTimeTypedClass( "An abstract class to define a renderer" ) - .def("setOption", &Renderer::setOption) - .def("getOption", &getOption, "Returns a copy of the internal option data." ) - - .def("camera", &camera) - .def("display", &display) - - .def("worldBegin", &Renderer::worldBegin) - .def("worldEnd", &worldEnd) - - .def("transformBegin", &Renderer::transformBegin) - .def("transformEnd", &Renderer::transformEnd) - .def("setTransform", (void (Renderer::*)( const Imath::M44f &))&Renderer::setTransform) - .def("setTransform", (void (Renderer::*)( const std::string &))&Renderer::setTransform) - .def("getTransform", (Imath::M44f (Renderer::*)() const )&Renderer::getTransform) - .def("getTransform", (Imath::M44f (Renderer::*)( const std::string &) const ) &Renderer::getTransform) - .def("concatTransform", &Renderer::concatTransform) - .def("coordinateSystem", &Renderer::coordinateSystem) - - .def("attributeBegin", &Renderer::attributeBegin) - .def("attributeEnd", &Renderer::attributeEnd) - .def("setAttribute", &Renderer::setAttribute) - .def("getAttribute", &getAttribute, "Returns a copy of the internal attribute data.") - - .def("shader", &shader) - .def("light", &light) - .def("illuminate", &Renderer::illuminate) - - .def("motionBegin", &motionBegin) - .def("motionEnd", &Renderer::motionEnd) - - .def("points", &points) - .def("disk", &disk) - .def("curves", &curves) - .def("text", &text) - .def("sphere", &sphere) - .def("image", &image) - .def("mesh", &mesh) - .def("nurbs", &nurbs) - .def("patchMesh", &patchMesh) - .def("geometry", &geometry) - - .def("procedural", &procedural) - - .def("instanceBegin", &instanceBegin) - .def("instanceEnd", &Renderer::instanceEnd) - .def("instance", &Renderer::instance) - - .def("command", &command) - - .def("editBegin", &editBegin) - .def("editEnd", &Renderer::editEnd) - ; - - RefCountedClass( "Procedural" ) - .def( init<>() ) - .def( "bound", &Renderer::Procedural::bound ) - .def( "render", &Renderer::Procedural::render ) - .def( "hash", &Renderer::Procedural::hash ) - .def_readonly( "noBound", &Renderer::Procedural::noBound ) - ; - - RefCountedClass( "ExternalProcedural" ) - .def( "__init__", make_constructor( externalProceduralConstructor ) ) - ; - -} - -} // namespace IECoreSceneModule diff --git a/src/IECoreScene/bindings/RendererBinding.h b/src/IECoreScene/bindings/RendererBinding.h deleted file mode 100644 index a69267af48..0000000000 --- a/src/IECoreScene/bindings/RendererBinding.h +++ /dev/null @@ -1,43 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2010, 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 Image Engine Design 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 IECORESCENEMODULE_RENDERERBINDING_H -#define IECORESCENEMODULE_RENDERERBINDING_H - -namespace IECoreSceneModule -{ -void bindRenderer(); -} - -#endif // IECORESCENEMODULE_RENDERERBINDING_H From 254b61b0cd10d39badf53e8d23120355a5c9791d Mon Sep 17 00:00:00 2001 From: John Haddon Date: Tue, 8 Jul 2025 10:32:51 +0100 Subject: [PATCH 06/15] CoordinateSystem : Remove transform This is unused now we've removed Renderer. In Gaffer's representation, the transform is held outside the CoordinateSystem anyway, and having an internal one was confusing and prone to error. --- Changes | 1 + include/IECoreScene/CoordinateSystem.h | 18 +----- src/IECoreScene/CoordinateSystem.cpp | 62 +------------------ .../bindings/CoordinateSystemBinding.cpp | 7 +-- test/IECoreScene/CoordinateSystemTest.py | 62 ------------------- 5 files changed, 6 insertions(+), 144 deletions(-) diff --git a/Changes b/Changes index 092419189a..b15dd814c0 100644 --- a/Changes +++ b/Changes @@ -13,6 +13,7 @@ Breaking Changes ---------------- - Renderable : Removed `render()` method. +- CoordinateSystem : Removed transform. - Renderer, AttributeBlock, EditBlock, MotionBlock, TransformBlock, WorldBlock : Removed. - IECoreHoudini : Removed. - IECoreMaya : Removed. diff --git a/include/IECoreScene/CoordinateSystem.h b/include/IECoreScene/CoordinateSystem.h index b63c78b7f3..2c1e12bdfc 100644 --- a/include/IECoreScene/CoordinateSystem.h +++ b/include/IECoreScene/CoordinateSystem.h @@ -41,17 +41,13 @@ namespace IECoreScene { -IE_CORE_FORWARDDECLARE( Transform ) - -/// This calls allows the specification of coordinate systems to -/// Renderers. +/// Allows the specification of coordinate systems to Renderers. /// \ingroup renderingGroup class IECORESCENE_API CoordinateSystem : public StateRenderable { public: - CoordinateSystem(); - CoordinateSystem( const std::string &name, TransformPtr transform=nullptr ); + CoordinateSystem( const std::string &name = "unspecified" ); ~CoordinateSystem() override; IE_CORE_DECLAREEXTENSIONOBJECT( CoordinateSystem, CoordinateSystemTypeId, StateRenderable ); @@ -59,19 +55,9 @@ class IECORESCENE_API CoordinateSystem : public StateRenderable const std::string &getName() const; void setName( const std::string &name ); - /// Returns the Transform applied to the coordinate system. - /// This is the local transform relative to the parent of - /// the coordinate system (usually a Group). May return 0 - /// if no transform has been applied. - Transform *getTransform(); - const Transform *getTransform() const; - /// Sets the Transform applied to the coordinate system. - void setTransform( TransformPtr transform ); - private: std::string m_name; - TransformPtr m_transform; static const unsigned int m_ioVersion; }; diff --git a/src/IECoreScene/CoordinateSystem.cpp b/src/IECoreScene/CoordinateSystem.cpp index b7cd32ffde..6f05a020d2 100644 --- a/src/IECoreScene/CoordinateSystem.cpp +++ b/src/IECoreScene/CoordinateSystem.cpp @@ -34,8 +34,6 @@ #include "IECoreScene/CoordinateSystem.h" -#include "IECoreScene/Transform.h" - #include "IECore/MurmurHash.h" using namespace IECore; @@ -47,13 +45,8 @@ static IndexedIO::EntryID g_transformEntry("transform"); const unsigned int CoordinateSystem::m_ioVersion = 0; IE_CORE_DEFINEOBJECTTYPEDESCRIPTION( CoordinateSystem ); -CoordinateSystem::CoordinateSystem() - : m_name( "unspecified" ), m_transform( nullptr ) -{ -} - -CoordinateSystem::CoordinateSystem( const std::string &name, TransformPtr transform ) - : m_name( name ), m_transform( transform ) +CoordinateSystem::CoordinateSystem( const std::string &name ) + : m_name( name ) { } @@ -71,21 +64,6 @@ void CoordinateSystem::setName( const std::string &name ) m_name = name; } -Transform *CoordinateSystem::getTransform() -{ - return m_transform.get(); -} - -const Transform *CoordinateSystem::getTransform() const -{ - return m_transform.get(); -} - -void CoordinateSystem::setTransform( TransformPtr transform ) -{ - m_transform = transform; -} - bool CoordinateSystem::isEqualTo( const Object *other ) const { if( !StateRenderable::isEqualTo( other ) ) @@ -97,14 +75,6 @@ bool CoordinateSystem::isEqualTo( const Object *other ) const { return false; } - if( (bool)m_transform != (bool)c->m_transform ) - { - return false; - } - if( m_transform ) - { - return m_transform->isEqualTo( c->m_transform.get() ); - } return true; } @@ -112,10 +82,6 @@ void CoordinateSystem::memoryUsage( Object::MemoryAccumulator &a ) const { StateRenderable::memoryUsage( a ); a.accumulate( m_name.capacity() + sizeof( m_name ) ); - if( m_transform ) - { - a.accumulate( m_transform.get() ); - } } void CoordinateSystem::copyFrom( const Object *other, CopyContext *context ) @@ -123,14 +89,6 @@ void CoordinateSystem::copyFrom( const Object *other, CopyContext *context ) StateRenderable::copyFrom( other, context ); const CoordinateSystem *c = static_cast( other ); m_name = c->m_name; - if( c->m_transform ) - { - m_transform = context->copy( c->m_transform.get() ); - } - else - { - m_transform = nullptr; - } } void CoordinateSystem::save( SaveContext *context ) const @@ -138,10 +96,6 @@ void CoordinateSystem::save( SaveContext *context ) const StateRenderable::save( context ); IndexedIOPtr container = context->container( staticTypeName(), m_ioVersion ); container->write( g_nameEntry, m_name ); - if( m_transform ) - { - context->save( m_transform.get(), container.get(), g_transformEntry ); - } } void CoordinateSystem::load( LoadContextPtr context ) @@ -150,22 +104,10 @@ void CoordinateSystem::load( LoadContextPtr context ) unsigned int v = m_ioVersion; ConstIndexedIOPtr container = context->container( staticTypeName(), v ); container->read( g_nameEntry, m_name ); - m_transform = nullptr; - try - { - m_transform = context->load( container.get(), g_transformEntry ); - } - catch( ... ) - { - } } void CoordinateSystem::hash( MurmurHash &h ) const { StateRenderable::hash( h ); h.append( m_name ); - if( m_transform ) - { - m_transform->hash( h ); - } } diff --git a/src/IECoreScene/bindings/CoordinateSystemBinding.cpp b/src/IECoreScene/bindings/CoordinateSystemBinding.cpp index fa7049d518..2dba6ddcbf 100644 --- a/src/IECoreScene/bindings/CoordinateSystemBinding.cpp +++ b/src/IECoreScene/bindings/CoordinateSystemBinding.cpp @@ -37,7 +37,6 @@ #include "CoordinateSystemBinding.h" #include "IECoreScene/CoordinateSystem.h" -#include "IECoreScene/Transform.h" #include "IECorePython/RunTimeTypedBinding.h" @@ -51,13 +50,9 @@ namespace IECoreSceneModule void bindCoordinateSystem() { RunTimeTypedClass() - .def( init<>() ) - .def( init() ) - .def( init() ) + .def( init( ( arg( "name" ) = "unspecified" ) ) ) .def( "getName", &CoordinateSystem::getName, return_value_policy() ) .def( "setName", &CoordinateSystem::setName ) - .def( "getTransform", (Transform *(CoordinateSystem::*)())&CoordinateSystem::getTransform, return_value_policy() ) - .def( "setTransform", &CoordinateSystem::setTransform ) ; } diff --git a/test/IECoreScene/CoordinateSystemTest.py b/test/IECoreScene/CoordinateSystemTest.py index a8261eed68..c02bdd6a6f 100644 --- a/test/IECoreScene/CoordinateSystemTest.py +++ b/test/IECoreScene/CoordinateSystemTest.py @@ -70,57 +70,10 @@ def testHash( self ) : b.setName( "a" ) self.assertEqual( a.hash(), b.hash() ) - b.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( 1 ) ) ) ) - self.assertNotEqual( a.hash(), b.hash() ) - - def testTransform( self ) : - - c = IECoreScene.CoordinateSystem() - self.assertEqual( c.getTransform(), None ) - - c = IECoreScene.CoordinateSystem( "test" ) - self.assertEqual( c.getName(), "test" ) - self.assertEqual( c.getTransform(), None ) - self.assertEqual( c, c.copy() ) - - c = IECoreScene.CoordinateSystem( "test", IECoreScene.MatrixTransform( imath.M44f() ) ) - self.assertEqual( c.getName(), "test" ) - self.assertEqual( c.getTransform(), IECoreScene.MatrixTransform( imath.M44f() ) ) - self.assertEqual( c, c.copy() ) - - cc = c.copy() - self.assertEqual( cc.getTransform(), IECoreScene.MatrixTransform( imath.M44f() ) ) - self.assertFalse( c.getTransform().isSame( cc.getTransform() ) ) - - c.setTransform( IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( 1 ) ) ) ) - self.assertEqual( c.getTransform(), IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( 1 ) ) ) ) - - c.setTransform( None ) - self.assertEqual( c.getTransform(), None ) - - cc = c.copy() - self.assertEqual( cc.getTransform(), None ) - def testLoadCobFromBeforeTransforms( self ) : c = IECore.ObjectReader( os.path.join( "test", "IECore", "data", "cobFiles", "coordinateSystemBeforeTransforms.cob" ) ).read() - self.assertEqual( c.getName(), "test" ) - self.assertEqual( c.getTransform(), None ) - - def testLoadCobWithTransform( self ) : - - c = IECoreScene.CoordinateSystem( "test", IECoreScene.MatrixTransform( imath.M44f() ) ) - IECore.ObjectWriter( c, os.path.join( "test", "IECore", "data", "coordSys.cob" ) ).write() - c = IECore.ObjectReader( os.path.join( "test", "IECore", "data", "coordSys.cob" ) ).read() - - self.assertEqual( c.getTransform(), IECoreScene.MatrixTransform( imath.M44f() ) ) - - c = IECoreScene.CoordinateSystem( "test", None ) - IECore.ObjectWriter( c, os.path.join( "test", "IECore", "data", "coordSys.cob" ) ).write() - c = IECore.ObjectReader( os.path.join( "test", "IECore", "data", "coordSys.cob" ) ).read() - - self.assertEqual( c.getTransform(), None ) def testEquality( self ) : @@ -134,21 +87,6 @@ def testEquality( self ) : self.assertNotEqual( c2, c1 ) c1.setName( "test" ) - c1.setTransform( IECoreScene.MatrixTransform( imath.M44f() ) ) - self.assertNotEqual( c1, c2 ) - self.assertNotEqual( c2, c1 ) - - c2.setTransform( IECoreScene.MatrixTransform( imath.M44f() ) ) - self.assertEqual( c1, c2 ) - self.assertEqual( c2, c1 ) - - def testMemoryUsage( self ) : - - c = IECoreScene.CoordinateSystem( "test" ) - m = c.memoryUsage() - c.setTransform( IECoreScene.MatrixTransform( imath.M44f() ) ) - self.assertTrue( c.memoryUsage() > m ) - def tearDown( self ) : if os.path.exists( os.path.join( "test", "IECore", "data", "coordSys.cob" ) ) : From 501861cbb641ba3d58cfe9c4d78d3b2037b0f059 Mon Sep 17 00:00:00 2001 From: John Haddon Date: Tue, 8 Jul 2025 10:41:17 +0100 Subject: [PATCH 07/15] Options : Remove This serves no purpose now that Renderer is removed. Gaffer has an entirely different representation for options. --- Changes | 1 + include/IECoreScene/Options.h | 75 ------------- include/IECoreScene/TypeIds.h | 2 +- src/IECoreScene/Options.cpp | 117 -------------------- src/IECoreScene/bindings/IECoreScene.cpp | 2 - src/IECoreScene/bindings/OptionsBinding.cpp | 58 ---------- src/IECoreScene/bindings/OptionsBinding.h | 45 -------- test/IECoreScene/All.py | 1 - test/IECoreScene/OptionsTest.py | 74 ------------- 9 files changed, 2 insertions(+), 373 deletions(-) delete mode 100644 include/IECoreScene/Options.h delete mode 100644 src/IECoreScene/Options.cpp delete mode 100644 src/IECoreScene/bindings/OptionsBinding.cpp delete mode 100644 src/IECoreScene/bindings/OptionsBinding.h delete mode 100644 test/IECoreScene/OptionsTest.py diff --git a/Changes b/Changes index b15dd814c0..51e66ab474 100644 --- a/Changes +++ b/Changes @@ -14,6 +14,7 @@ Breaking Changes - Renderable : Removed `render()` method. - CoordinateSystem : Removed transform. +- Options : Removed. - Renderer, AttributeBlock, EditBlock, MotionBlock, TransformBlock, WorldBlock : Removed. - IECoreHoudini : Removed. - IECoreMaya : Removed. diff --git a/include/IECoreScene/Options.h b/include/IECoreScene/Options.h deleted file mode 100644 index 88bb707301..0000000000 --- a/include/IECoreScene/Options.h +++ /dev/null @@ -1,75 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2012, John Haddon. 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 Image Engine Design 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 IECORESCENE_OPTIONS_H -#define IECORESCENE_OPTIONS_H - -#include "IECoreScene/Export.h" -#include "IECoreScene/PreWorldRenderable.h" - -namespace IECoreScene -{ - -/// A class to manipulate the options of a Renderer. -/// \ingroup renderingGroup -class IECORESCENE_API Options : public PreWorldRenderable -{ - public: - - /// Options is referenced directly rather than copied. - Options( IECore::CompoundDataPtr options ); - Options( const IECore::CompoundDataMap &options = IECore::CompoundDataMap() ); - ~Options() override; - - IE_CORE_DECLAREEXTENSIONOBJECT( Options, OptionsTypeId, PreWorldRenderable ); - - IECore::CompoundDataMap &options(); - const IECore::CompoundDataMap &options() const; - /// This is mostly of use for the binding - the options() - /// function gives more direct access to the contents of the CompoundData - /// (it calls readable() or writable() for you). - IECore::CompoundDataPtr optionsData(); - - private: - - IECore::CompoundDataPtr m_options; - - static const unsigned int m_ioVersion; -}; - -IE_CORE_DECLAREPTR( Options ); - -} // namespace IECoreScene - -#endif // IECORESCENE_OPTIONS_H diff --git a/include/IECoreScene/TypeIds.h b/include/IECoreScene/TypeIds.h index a6229acd94..58b20eaf66 100644 --- a/include/IECoreScene/TypeIds.h +++ b/include/IECoreScene/TypeIds.h @@ -129,7 +129,7 @@ enum TypeId PointDistributionOpTypeId = 108086, DiskPrimitiveTypeId = 108087, MeshFaceFilterOpTypeId = 108088, - OptionsTypeId = 108089, + OptionsTypeId = 108089, // Obsolete, available for reuse SceneInterfaceTypeId = 108090, SampledSceneInterfaceTypeId = 108091, LinkedSceneTypeId = 108092, diff --git a/src/IECoreScene/Options.cpp b/src/IECoreScene/Options.cpp deleted file mode 100644 index 730cbacc41..0000000000 --- a/src/IECoreScene/Options.cpp +++ /dev/null @@ -1,117 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2012, John Haddon. All rights reserved. -// 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 Image Engine Design 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. -// -////////////////////////////////////////////////////////////////////////// - -#include "IECoreScene/Options.h" - -using namespace IECore; -using namespace IECoreScene; -using namespace boost; - -static IndexedIO::EntryID g_optionsEntry("options"); -const unsigned int Options::m_ioVersion = 0; -IE_CORE_DEFINEOBJECTTYPEDESCRIPTION( Options ); - -Options::Options( CompoundDataPtr options ) - : m_options( options ? options : CompoundDataPtr( new CompoundData() ) ) -{ -} - -Options::Options( const CompoundDataMap &options ) - : m_options( new CompoundData( options ) ) -{ -} - -Options::~Options() -{ -} - -CompoundDataMap &Options::options() -{ - return m_options->writable(); -} - -const CompoundDataMap &Options::options() const -{ - return m_options->readable(); -} - -CompoundDataPtr Options::optionsData() -{ - return m_options; -} - -bool Options::isEqualTo( const Object *other ) const -{ - if( !PreWorldRenderable::isEqualTo( other ) ) - { - return false; - } - const Options *s = static_cast( other ); - return m_options->isEqualTo( s->m_options.get() ); -} - -void Options::memoryUsage( Object::MemoryAccumulator &a ) const -{ - PreWorldRenderable::memoryUsage( a ); - a.accumulate( m_options.get() ); -} - -void Options::copyFrom( const Object *other, CopyContext *context ) -{ - PreWorldRenderable::copyFrom( other, context ); - const Options *s = static_cast( other ); - m_options = context->copy( s->m_options.get() ); -} - -void Options::save( SaveContext *context ) const -{ - PreWorldRenderable::save( context ); - IndexedIOPtr container = context->container( staticTypeName(), m_ioVersion ); - context->save( m_options.get(), container.get(), g_optionsEntry ); -} - -void Options::load( LoadContextPtr context ) -{ - PreWorldRenderable::load( context ); - unsigned int v = m_ioVersion; - ConstIndexedIOPtr container = context->container( staticTypeName(), v ); - m_options = context->load( container.get(), g_optionsEntry ); -} - -void Options::hash( MurmurHash &h ) const -{ - PreWorldRenderable::hash( h ); - m_options->hash( h ); -} diff --git a/src/IECoreScene/bindings/IECoreScene.cpp b/src/IECoreScene/bindings/IECoreScene.cpp index fb1939e22a..5843c9d3aa 100644 --- a/src/IECoreScene/bindings/IECoreScene.cpp +++ b/src/IECoreScene/bindings/IECoreScene.cpp @@ -73,7 +73,6 @@ #include "NURBSPrimitiveBinding.h" #include "NormalizeSmoothSkinningWeightsOpBinding.h" #include "OBJReaderBinding.h" -#include "OptionsBinding.h" #include "OutputBinding.h" #include "PDCParticleReaderBinding.h" #include "PDCParticleWriterBinding.h" @@ -194,7 +193,6 @@ BOOST_PYTHON_MODULE(_IECoreScene) bindLight(); bindContrastSmoothSkinningWeightsOp(); bindDiskPrimitive(); - bindOptions(); bindSceneInterface(); bindSharedSceneInterfaces(); bindSampledSceneInterface(); diff --git a/src/IECoreScene/bindings/OptionsBinding.cpp b/src/IECoreScene/bindings/OptionsBinding.cpp deleted file mode 100644 index 9bbf4fa714..0000000000 --- a/src/IECoreScene/bindings/OptionsBinding.cpp +++ /dev/null @@ -1,58 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2012, John Haddon. 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 Image Engine Design 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. -// -////////////////////////////////////////////////////////////////////////// - -#include "boost/python.hpp" - -#include "OptionsBinding.h" - -#include "IECoreScene/Options.h" - -#include "IECorePython/RunTimeTypedBinding.h" - -using namespace boost::python; -using namespace IECore; -using namespace IECorePython; -using namespace IECoreScene; - -namespace IECoreSceneModule -{ - void bindOptions() - { - RunTimeTypedClass( "Options" ) - .def( init<>() ) - .def( init() ) - .add_property( "options", &Options::optionsData ) - ; - } -} diff --git a/src/IECoreScene/bindings/OptionsBinding.h b/src/IECoreScene/bindings/OptionsBinding.h deleted file mode 100644 index 07d458e139..0000000000 --- a/src/IECoreScene/bindings/OptionsBinding.h +++ /dev/null @@ -1,45 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2012, John Haddon. 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 Image Engine Design 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 IECORESCENEMODULE_OPTIONSBINDING_H -#define IECORESCENEMODULE_OPTIONSBINDING_H - -namespace IECoreSceneModule -{ - -void bindOptions(); - -} // namespace IECoreSceneModule - -#endif // IECORESCENEMODULE_OPTIONSBINDING_H diff --git a/test/IECoreScene/All.py b/test/IECoreScene/All.py index 42369efdf2..c425385b64 100644 --- a/test/IECoreScene/All.py +++ b/test/IECoreScene/All.py @@ -94,7 +94,6 @@ from ContrastSmoothSkinningWeightsOpTest import ContrastSmoothSkinningWeightsOpTest from DiskPrimitiveTest import DiskPrimitiveTest from SWAReaderTest import SWAReaderTest -from OptionsTest import OptionsTest from SceneCacheTest import SceneCacheTest from LinkedSceneTest import LinkedSceneTest from ExternalProceduralTest import ExternalProceduralTest diff --git a/test/IECoreScene/OptionsTest.py b/test/IECoreScene/OptionsTest.py deleted file mode 100644 index 0446f2460d..0000000000 --- a/test/IECoreScene/OptionsTest.py +++ /dev/null @@ -1,74 +0,0 @@ -########################################################################## -# -# Copyright (c) 2012, John Haddon. 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 Image Engine Design 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 IECore -import IECoreScene - -class OptionsTest( unittest.TestCase ) : - - def testCopy( self ) : - - o = IECoreScene.Options() - o.options["test"] = IECore.FloatData( 10 ) - - oo = o.copy() - self.assertEqual( o, oo ) - - def testConstructFromDict( self ) : - - o = IECoreScene.Options( { - "a" : IECore.StringData( "a" ), - "b" : IECore.IntData( 10 ), - } ) - - self.assertEqual( len( o.options ), 2 ) - self.assertEqual( o.options["a"], IECore.StringData( "a" ) ) - self.assertEqual( o.options["b"], IECore.IntData( 10 ) ) - - def testHash( self ) : - - o1 = IECoreScene.Options() - o2 = IECoreScene.Options() - - self.assertEqual( o1.hash(), o2.hash() ) - - o1.options["a"] = IECore.StringData( "a" ) - self.assertNotEqual( o1.hash(), o2.hash() ) - - o2.options["a"] = IECore.StringData( "a" ) - self.assertEqual( o1.hash(), o2.hash() ) - -if __name__ == "__main__": - unittest.main() From 8d5f4f72db0302070f633180a7a06036cabaa543 Mon Sep 17 00:00:00 2001 From: John Haddon Date: Tue, 8 Jul 2025 10:52:38 +0100 Subject: [PATCH 08/15] IECoreScene : Remove CurveExtrudeOp I don't see how this can be useful any more, since none of our renderer backends support PatchMeshes. We're also moving away from Ops in favour of Algo. --- Changes | 1 + include/IECoreScene/CurveExtrudeOp.h | 92 --- include/IECoreScene/TypeIds.h | 2 +- src/IECoreScene/CurveExtrudeOp.cpp | 593 ------------------ .../bindings/CurveExtrudeOpBinding.cpp | 60 -- .../bindings/CurveExtrudeOpBinding.h | 43 -- src/IECoreScene/bindings/IECoreScene.cpp | 2 - test/IECoreScene/All.py | 1 - test/IECoreScene/CurveExtrudeOp.py | 65 -- 9 files changed, 2 insertions(+), 857 deletions(-) delete mode 100644 include/IECoreScene/CurveExtrudeOp.h delete mode 100644 src/IECoreScene/CurveExtrudeOp.cpp delete mode 100644 src/IECoreScene/bindings/CurveExtrudeOpBinding.cpp delete mode 100644 src/IECoreScene/bindings/CurveExtrudeOpBinding.h delete mode 100644 test/IECoreScene/CurveExtrudeOp.py diff --git a/Changes b/Changes index 51e66ab474..2d28990649 100644 --- a/Changes +++ b/Changes @@ -15,6 +15,7 @@ Breaking Changes - Renderable : Removed `render()` method. - CoordinateSystem : Removed transform. - Options : Removed. +- CurveExtrudeOp : Removed. - Renderer, AttributeBlock, EditBlock, MotionBlock, TransformBlock, WorldBlock : Removed. - IECoreHoudini : Removed. - IECoreMaya : Removed. diff --git a/include/IECoreScene/CurveExtrudeOp.h b/include/IECoreScene/CurveExtrudeOp.h deleted file mode 100644 index 9256dc9042..0000000000 --- a/include/IECoreScene/CurveExtrudeOp.h +++ /dev/null @@ -1,92 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2009-2011, 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 Image Engine Design 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 IECORESCENE_CURVEEXTRUDEOP_H -#define IECORESCENE_CURVEEXTRUDEOP_H - -#include "IECoreScene/CurvesPrimitive.h" -#include "IECoreScene/Export.h" -#include "IECoreScene/PatchMeshPrimitive.h" -#include "IECoreScene/TypedPrimitiveParameter.h" - -#include "IECore/NumericParameter.h" -#include "IECore/Op.h" -#include "IECore/SimpleTypedParameter.h" - -#include - -namespace IECoreScene -{ - -/// The CurveExtrudeOp lofts RiCurves into RiPatchMesh cylinders, obeying any width primvars present. -/// \ingroup geometryProcessingGroup -class IECORESCENE_API CurveExtrudeOp : public IECore::Op -{ - public : - - IE_CORE_DECLARERUNTIMETYPEDEXTENSION( CurveExtrudeOp, CurveExtrudeOpTypeId, IECore::Op ); - - CurveExtrudeOp(); - ~CurveExtrudeOp() override; - - CurvesPrimitiveParameter *curvesParameter(); - const CurvesPrimitiveParameter *curvesParameter() const; - - IECore::V2iParameter *resolutionParameter(); - const IECore::V2iParameter *resolutionParameter() const; - - protected : - - IECore::ObjectPtr doOperation( const IECore::CompoundObject *operands ) override; - - void buildReferenceFrames( const std::vector< Imath::V3f > &points, std::vector< Imath::V3f > &tangents, std::vector< Imath::M44f > &frames ) const; - - PatchMeshPrimitivePtr buildPatchMesh( const CurvesPrimitive * curves, unsigned curveIndex, unsigned vertexOffset, unsigned varyingOffset ) const; - - private : - - CurvesPrimitiveParameterPtr m_curvesParameter; - IECore::V2iParameterPtr m_resolutionParameter; - - struct VaryingFn; - struct VertexFn; - struct UniformFn; - -}; - -IE_CORE_DECLAREPTR( CurveExtrudeOp ); - -} // namespace IECoreScene - -#endif // IECORESCENE_CURVEEXTRUDEOP_H diff --git a/include/IECoreScene/TypeIds.h b/include/IECoreScene/TypeIds.h index 58b20eaf66..5d60fc9e3d 100644 --- a/include/IECoreScene/TypeIds.h +++ b/include/IECoreScene/TypeIds.h @@ -98,7 +98,7 @@ enum TypeId MeshTangentsOpTypeId = 108055, PatchMeshPrimitiveTypeId = 108056, CurvesPrimitiveParameterTypeId = 108057, - CurveExtrudeOpTypeId = 108058, + CurveExtrudeOpTypeId = 108058, // Obsolete, available for reuse ParameterisedProceduralTypeId = 108059, NParticleReaderTypeId = 108060, CurvesMergeOpTypeId = 108061, diff --git a/src/IECoreScene/CurveExtrudeOp.cpp b/src/IECoreScene/CurveExtrudeOp.cpp deleted file mode 100644 index 439312b8a2..0000000000 --- a/src/IECoreScene/CurveExtrudeOp.cpp +++ /dev/null @@ -1,593 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2009-2010, 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 Image Engine Design 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. -// -////////////////////////////////////////////////////////////////////////// - -#include "IECoreScene/CurveExtrudeOp.h" - -#include "IECoreScene/CurvesPrimitive.h" -#include "IECoreScene/Group.h" -#include "IECoreScene/PatchMeshPrimitive.h" -#include "IECoreScene/TypedObjectParameter.h" - -#include "IECore/CompoundParameter.h" -#include "IECore/DespatchTypedData.h" -#include "IECore/Interpolator.h" -#include "IECore/Math.h" -#include "IECore/MessageHandler.h" -#include "IECore/Object.h" -#include "IECore/SimpleTypedData.h" -#include "IECore/TypedObjectParameter.h" -#include "IECore/VectorTypedData.h" - -#include "Imath/ImathFrame.h" - -#include -#include -#include - -#include - -using namespace IECore; -using namespace IECoreScene; -using namespace Imath; -using namespace std; - -IE_CORE_DEFINERUNTIMETYPED( CurveExtrudeOp ); - -CurveExtrudeOp::CurveExtrudeOp() - : Op( - "The CurveExtrudeOp creates a group of PatchMesh geometries by lofting a circle along each given CurvesPrimitive.", - new GroupParameter( - "result", - "Resulting group of patch meshes.", - new Group() - ) - ) -{ - m_curvesParameter = new CurvesPrimitiveParameter( - "curves", - "The curves to convert into patch meshes.", - new CurvesPrimitive() - ); - - m_resolutionParameter = new V2iParameter( - "resolution", - "The resolution in U and V for each generated PatchMesh. U goes around the curve, V goes along the curve.", - V2i( 6, 30 ) - ); - - parameters()->addParameter( m_curvesParameter ); - parameters()->addParameter( m_resolutionParameter ); -} - -CurveExtrudeOp::~CurveExtrudeOp() -{ -} - -CurvesPrimitiveParameter * CurveExtrudeOp::curvesParameter() -{ - return m_curvesParameter.get(); -} - -const CurvesPrimitiveParameter * CurveExtrudeOp::curvesParameter() const -{ - return m_curvesParameter.get(); -} - -void CurveExtrudeOp::buildReferenceFrames( const std::vector< Imath::V3f > &points, std::vector< Imath::V3f > &tangents, std::vector< M44f > &frames ) const -{ - /// \todo This disregads the "N" primvar which is possibly specified on the CurvesPrimitive - std::vector< Imath::V3f >::size_type numPoints = points.size(); - assert( tangents.size() == numPoints ); - - frames.resize( numPoints ); - - frames[ 0 ] = Imath::firstFrame( - points[ 0 ], - points[ 1 ], - points[ 2 ] - ); - - for( unsigned int i = 1; i < numPoints - 1; i++ ) - { - frames[ i ] = Imath::nextFrame( - frames[ i - 1 ], - points[ i - 1 ], - points[ i ], - tangents[ i - 1 ], - tangents[ i ] - ); - } - - frames[ numPoints - 1 ] = Imath::lastFrame( - frames[ numPoints - 2 ], - points[ numPoints - 2 ], - points[ numPoints - 1 ] - ); -} - -struct CurveExtrudeOp::VaryingFn -{ - typedef DataPtr ReturnType; - - const std::string &m_primVarName; - ConstCurvesPrimitivePtr m_curves; - const unsigned m_curveIndex; - const unsigned m_varyingOffset; - const V2i &m_resolution; - - VaryingFn( const std::string &primVarName, ConstCurvesPrimitivePtr curves, unsigned curveIndex, unsigned varyingOffset, const V2i &resolution ) : m_primVarName( primVarName ), m_curves( curves ), m_curveIndex( curveIndex ), m_varyingOffset( varyingOffset ), m_resolution( resolution ) - { - } - - template - DataPtr operator() ( T *data ) const - { - assert( data ); - typedef typename T::ValueType::value_type Value; - - const unsigned vPoints = m_resolution.y; - const unsigned uPoints = m_resolution.x; - - typename T::Ptr newData = new T(); - newData->writable().reserve( ( vPoints ) * uPoints ); - - for ( unsigned int v = 0; v < vPoints; v++ ) - { - int iSeg; - float fSeg; - - if ( v == vPoints - 1 ) - { - iSeg = m_curves->numSegments( m_curveIndex ) - 1; - fSeg = 0.9999f; - } - else - { - float curveParam = float(v) / ( vPoints - 1 ); - fSeg = curveParam * m_curves->numSegments( m_curveIndex ); - iSeg = (int)floor( fSeg ); - fSeg = fSeg - iSeg; - } - - for ( unsigned u = 0; u < uPoints ; u ++) - { - Value value; - LinearInterpolator()( - data->readable()[ m_varyingOffset + iSeg ], - data->readable()[ m_varyingOffset + iSeg + 1], - fSeg, - value - ); - newData->writable().push_back( value ); - } - } - - return newData; - } - - struct ErrorHandler - { - template - void operator()( const T *data, const F& functor ) - { - assert( data ); - throw InvalidArgumentException( ( boost::format( "CurveExtrudeOp: Invalid data type \"%s\" for primitive variable \"%s\"." ) % Object::typeNameFromTypeId( data->typeId() ) % functor.m_primVarName ).str() ); - } - }; -}; - -struct CurveExtrudeOp::VertexFn -{ - typedef DataPtr ReturnType; - - const std::string &m_primVarName; - const CurvesPrimitive * m_curves; - const unsigned m_curveIndex; - const unsigned m_varyingOffset; - const V2i &m_resolution; - - VertexFn( const std::string &primVarName, const CurvesPrimitive * curves, unsigned curveIndex, unsigned varyingOffset, const V2i &resolution ) : m_primVarName( primVarName ), m_curves( curves ), m_curveIndex( curveIndex ), m_varyingOffset( varyingOffset ), m_resolution( resolution ) - { - } - - template - DataPtr operator() ( T * data ) const - { - assert( data ); - typedef typename T::ValueType::value_type Value; - - const unsigned vPoints = m_resolution.y; - const unsigned uPoints = m_resolution.x; - - typename T::Ptr newData = new T(); - newData->writable().reserve( ( vPoints + 2 ) * uPoints ); - - for ( unsigned int v = 0; v < vPoints; v++ ) - { - size_t iSeg; - float fSeg; - - if ( v == vPoints - 1 ) - { - iSeg = m_curves->numSegments( m_curveIndex ) - 1; - fSeg = 0.9999f; - } - else - { - float curveParam = float(v) / ( vPoints - 1 ); - fSeg = curveParam * m_curves->numSegments( m_curveIndex ); - iSeg = (size_t)floor( fSeg ); - fSeg = fSeg - iSeg; - } - - const int num = v == 0 || v == vPoints - 1 ? 2 : 1; - - const size_t i0 = iSeg; - const size_t i1 = std::min( iSeg + 1, m_curves->variableSize( PrimitiveVariable::Varying, m_curveIndex ) ); - - for ( int x = 0; x < num; x++) - { - for ( unsigned u = 0; u < uPoints ; u ++) - { - Value value; - LinearInterpolator()( - data->readable()[ m_varyingOffset + i0 ], - data->readable()[ m_varyingOffset + i1], - fSeg, - value - ); - newData->writable().push_back( value ); - } - } - } - - return newData; - } - - struct ErrorHandler - { - template - void operator()( const T *data, const F& functor ) - { - assert( data ); - throw InvalidArgumentException( ( boost::format( "CurveExtrudeOp: Invalid data type \"%s\" for vertex primitive variable \"%s\"." ) % Object::typeNameFromTypeId( data->typeId() ) % functor.m_primVarName ).str() ); - } - }; -}; - - -struct CurveExtrudeOp::UniformFn -{ - typedef DataPtr ReturnType; - - const std::string &m_primVarName; - const CurvesPrimitive * m_curves; - const unsigned m_curveIndex; - - UniformFn( const std::string &primVarName, const CurvesPrimitive * curves, unsigned curveIndex ) : m_primVarName( primVarName ), m_curves( curves ), m_curveIndex( curveIndex ) - { - } - - template - DataPtr operator() ( T *data ) const - { - assert( data ); - return new TypedData< typename T::ValueType::value_type >( data->readable()[ m_curveIndex ] ); - } - - struct ErrorHandler - { - template - void operator()( const T *data, const F& functor ) - { - assert( data ); - throw InvalidArgumentException( ( boost::format( "CurveExtrudeOp: Invalid data type \"%s\" for uniform primitive variable \"%s\"." ) % Object::typeNameFromTypeId( data->typeId() ) % functor.m_primVarName ).str() ); - } - }; -}; - - -PatchMeshPrimitivePtr CurveExtrudeOp::buildPatchMesh( const CurvesPrimitive * curves, unsigned curveIndex, unsigned vertexOffset, unsigned varyingOffset ) const -{ - if ( curves->periodic() ) - { - throw InvalidArgumentException( "CurveExtrudeOp: Cannot convert periodic curves" ); - } - - PrimitiveVariableMap::const_iterator it = curves->variables.find( "P" ); - if ( it == curves->variables.end() ) - { - throw InvalidArgumentException( "CurveExtrudeOp: Input curve has no 'P' primvar" ); - } - ConstV3fVectorDataPtr pData = runTimeCast< const V3fVectorData >( it->second.data ); - if ( !pData ) - { - throw InvalidArgumentException( "CurveExtrudeOp: Input curve has no 'P' primvar of type V3fVectorData" ); - } - - float width = 1.0f; - it = curves->variables.find( "constantwidth" ); - if ( it != curves->variables.end() ) - { - ConstFloatDataPtr widthData = nullptr; - if ( it->second.interpolation == PrimitiveVariable::Constant ) - { - widthData = runTimeCast< const FloatData >( it->second.data ); - } - - if ( widthData ) - { - width = widthData->readable(); - } - else - { - msg( Msg::Warning, "CurveExtrudeOp", "Ignoring malformed primvar 'constantwidth'" ); - } - } - - ConstFloatVectorDataPtr varyingWidthData = nullptr; - ConstFloatVectorDataPtr vertexWidthData = nullptr; - it = curves->variables.find( "width" ); - if ( it != curves->variables.end() ) - { - if ( it->second.interpolation == PrimitiveVariable::Varying ) - { - varyingWidthData = runTimeCast< const FloatVectorData >( it->second.data ); - } - else if ( it->second.interpolation == PrimitiveVariable::Vertex ) - { - vertexWidthData = runTimeCast< const FloatVectorData >( it->second.data ); - } - - if ( !varyingWidthData && !vertexWidthData) - { - msg( Msg::Warning, "CurveExtrudeOp", "Ignoring malformed primvar 'width'" ); - } - } - - const V2i &resolution = m_resolutionParameter->getTypedValue(); - - const unsigned int vPoints = resolution.y; - const unsigned int uPoints = resolution.x; - - PatchMeshPrimitivePtr patchMesh = new PatchMeshPrimitive( - uPoints, - vPoints + 2, // End points are duplicated - CubicBasisf::catmullRom(), - CubicBasisf::catmullRom(), - true, - false - ); - - for ( PrimitiveVariableMap::const_iterator vIt = curves->variables.begin(); vIt != curves->variables.end(); ++vIt ) - { - if ( vIt->second.interpolation == PrimitiveVariable::FaceVarying || vIt->second.interpolation == PrimitiveVariable::Varying ) - { - VaryingFn varyingFn( vIt->first, curves, curveIndex, varyingOffset, resolution ); - assert( vIt->second.data ); - - patchMesh->variables[ vIt->first ] = PrimitiveVariable( - vIt->second.interpolation, - despatchTypedData( vIt->second.data.get(), varyingFn ) - ); - - } - else if ( vIt->second.interpolation == PrimitiveVariable::Vertex ) - { - VertexFn vertexFn( vIt->first, curves, curveIndex, vertexOffset, resolution ); - assert( vIt->second.data ); - - patchMesh->variables[ vIt->first ] = PrimitiveVariable( - vIt->second.interpolation, - despatchTypedData( vIt->second.data.get(), vertexFn ) - ); - - } - else if ( vIt->second.interpolation == PrimitiveVariable::Constant ) - { - patchMesh->variables[ vIt->first ] = PrimitiveVariable( vIt->second.interpolation, vIt->second.data->copy() ); - } - else if ( vIt->second.interpolation == PrimitiveVariable::Uniform ) - { - UniformFn uniformFn( vIt->first, curves, curveIndex ); - patchMesh->variables[ vIt->first ] = PrimitiveVariable( - PrimitiveVariable::Constant, - despatchTypedData( vIt->second.data.get(), uniformFn ) - ); - } - } - - if ( varyingWidthData ) - { - assert( !vertexWidthData ); - PrimitiveVariableMap::const_iterator vIt = patchMesh->variables.find( "width" ); - assert( vIt != patchMesh->variables.end() ); - - varyingWidthData = runTimeCast< const FloatVectorData >( vIt->second.data ); - assert( varyingWidthData ); - } - else if ( vertexWidthData ) - { - PrimitiveVariableMap::const_iterator vIt = patchMesh->variables.find( "width" ); - assert( vIt != patchMesh->variables.end() ); - - vertexWidthData = runTimeCast< const FloatVectorData >( vIt->second.data ); - assert( vertexWidthData ); - } - - const V3fVectorData::ValueType &p = pData->readable(); - - V3fVectorData::ValueType resampledPoints; - resampledPoints.reserve( vPoints ); - - V3fVectorData::ValueType resampledTangents; - resampledPoints.reserve( vPoints ); - - /// \todo Make adaptive - for ( unsigned v = 0; v < vPoints; v ++) - { - size_t iSeg; - float fSeg; - - /// Make sure we don't fall off the end of the curve - if ( v == vPoints - 1 ) - { - iSeg = curves->numSegments( curveIndex ) - 1; - fSeg = 1.0f - std::numeric_limits::epsilon(); - } - else - { - float curveParam = float(v) / ( vPoints - 1 ); - fSeg = curveParam * curves->numSegments( curveIndex ); - iSeg = (size_t)floor( fSeg ); - fSeg = fSeg - iSeg; - } - - size_t segmentStart = iSeg; - - size_t i0 = std::min( segmentStart + 0, curves->variableSize( PrimitiveVariable::Vertex, curveIndex ) ); - size_t i1 = std::min( segmentStart + 1, curves->variableSize( PrimitiveVariable::Vertex, curveIndex ) ); - size_t i2 = std::min( segmentStart + 2, curves->variableSize( PrimitiveVariable::Vertex, curveIndex ) ); - size_t i3 = std::min( segmentStart + 3, curves->variableSize( PrimitiveVariable::Vertex, curveIndex ) ); - - const Imath::V3f &p0 = p[ vertexOffset + i0 ]; - const Imath::V3f &p1 = p[ vertexOffset + i1 ]; - const Imath::V3f &p2 = p[ vertexOffset + i2 ]; - const Imath::V3f &p3 = p[ vertexOffset + i3 ]; - - Imath::V3f pt = curves->basis()( - fSeg, - p0, p1, p2, p3 - ); - - resampledPoints.push_back( pt ); - - resampledTangents.push_back( - curves->basis().derivative( - fSeg, - p0, p1, p2, p3 - ).normalized() - ); - - } - assert( resampledPoints.size() == vPoints ); - assert( resampledTangents.size() == vPoints ); - - std::vector< M44f > frames; - - buildReferenceFrames( resampledPoints, resampledTangents, frames ); - assert( frames.size() == vPoints ); - - std::vector< V3f > patchP; - patchP.reserve( uPoints * ( vPoints + 2 ) ); - - for ( unsigned int v = 0; v < vPoints; v++ ) - { - if ( varyingWidthData ) - { - assert( !vertexWidthData ); - assert( v * uPoints < varyingWidthData->readable().size() ); - width = varyingWidthData->readable()[v * uPoints]; - } - else if ( vertexWidthData ) - { - assert( (v+1) * uPoints < vertexWidthData->readable().size() ); - width = vertexWidthData->readable()[(v+1) * uPoints]; - } - - const float radius = width / 2.0f; - - /// Double up end points - const int num = v == 0 || v == vPoints - 1 ? 2 : 1; - - for ( int x = 0; x < num; x++) - { - for( unsigned int u = 0; u < uPoints; u++ ) - { - /// We're periodic in 'u', so no need to close the curve. - /// Go from -PI to PI, in order to make the periodicity work, and to give the - /// surface the correct orientation. - float theta = -2.0 * M_PI * float(u) / float(uPoints) - M_PI; - - V3f circlePoint( - 0.0, - radius * cos( theta ), - radius * sin( theta ) - ); - - circlePoint = circlePoint * frames[v]; - - patchP.push_back( circlePoint ); - } - } - } - - patchMesh->variables["P"] = PrimitiveVariable( PrimitiveVariable::Vertex, new V3fVectorData( patchP ) ); - - assert( patchMesh->arePrimitiveVariablesValid() ); - - return patchMesh; -} - -ObjectPtr CurveExtrudeOp::doOperation( const CompoundObject * operands ) -{ - CurvesPrimitive * curves = m_curvesParameter->getTypedValue(); - assert( curves ); - assert( curves->arePrimitiveVariablesValid() ); - - GroupPtr group = new Group(); - - const IntVectorData * verticesPerCurve = curves->verticesPerCurve(); - assert( verticesPerCurve ); - - unsigned numCurves = verticesPerCurve->readable().size(); - unsigned vertexOffset = 0; - unsigned varyingOffset = 0; - for ( unsigned curveIndex = 0; curveIndex < numCurves; curveIndex++ ) - { - int numVertices = curves->variableSize( PrimitiveVariable::Vertex, curveIndex ); - - PatchMeshPrimitivePtr patchMesh = buildPatchMesh( curves, curveIndex, vertexOffset, varyingOffset ); - assert( patchMesh ); - - group->addChild( patchMesh ); - - vertexOffset += numVertices; - varyingOffset += curves->variableSize( PrimitiveVariable::Varying, curveIndex ); - } - - assert( group->children().size() == numCurves ); - - return group; -} diff --git a/src/IECoreScene/bindings/CurveExtrudeOpBinding.cpp b/src/IECoreScene/bindings/CurveExtrudeOpBinding.cpp deleted file mode 100644 index e39d68d6be..0000000000 --- a/src/IECoreScene/bindings/CurveExtrudeOpBinding.cpp +++ /dev/null @@ -1,60 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2008-2010, 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 Image Engine Design 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. -// -////////////////////////////////////////////////////////////////////////// - -#include "boost/python.hpp" - -#include "CurveExtrudeOpBinding.h" - -#include "IECoreScene/CurveExtrudeOp.h" - -#include "IECorePython/RunTimeTypedBinding.h" - -#include "IECore/CompoundObject.h" - -using namespace boost; -using namespace boost::python; -using namespace IECorePython; -using namespace IECoreScene; - -namespace IECoreSceneModule -{ - -void bindCurveExtrudeOp() -{ - RunTimeTypedClass() - .def( init<>() ) - ; -} - -} // namespace IECoreSceneModule diff --git a/src/IECoreScene/bindings/CurveExtrudeOpBinding.h b/src/IECoreScene/bindings/CurveExtrudeOpBinding.h deleted file mode 100644 index 8daae9496c..0000000000 --- a/src/IECoreScene/bindings/CurveExtrudeOpBinding.h +++ /dev/null @@ -1,43 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2009-2010, 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 Image Engine Design 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 IECORESCENEMODULE_CURVEEXTRUDEOPBINDING_H -#define IECORESCENEMODULE_CURVEEXTRUDEOPBINDING_H - -namespace IECoreSceneModule -{ -void bindCurveExtrudeOp(); -} - -#endif // IECORESCENEMODULE_CURVEEXTRUDEOPBINDING_H diff --git a/src/IECoreScene/bindings/IECoreScene.cpp b/src/IECoreScene/bindings/IECoreScene.cpp index 5843c9d3aa..c86d6110a6 100644 --- a/src/IECoreScene/bindings/IECoreScene.cpp +++ b/src/IECoreScene/bindings/IECoreScene.cpp @@ -41,7 +41,6 @@ #include "CompressSmoothSkinningDataOpBinding.h" #include "ContrastSmoothSkinningWeightsOpBinding.h" #include "CoordinateSystemBinding.h" -#include "CurveExtrudeOpBinding.h" #include "CurveLineariserBinding.h" #include "CurveTangentsOpBinding.h" #include "CurvesAlgoBinding.h" @@ -170,7 +169,6 @@ BOOST_PYTHON_MODULE(_IECoreScene) bindOBJReader(); bindOutput(); bindPatchMeshPrimitive(); - bindCurveExtrudeOp(); bindNParticleReader(); bindCurvesMergeOp(); bindCurvesPrimitiveEvaluator(); diff --git a/test/IECoreScene/All.py b/test/IECoreScene/All.py index c425385b64..d2b32d210e 100644 --- a/test/IECoreScene/All.py +++ b/test/IECoreScene/All.py @@ -70,7 +70,6 @@ from CoordinateSystemTest import * from OutputTest import OutputTest from PatchMeshPrimitiveTest import * -from CurveExtrudeOp import * from NParticleReader import * from OBJReaderTest import TestOBJReader from CurvesMergeOpTest import CurvesMergeOpTest diff --git a/test/IECoreScene/CurveExtrudeOp.py b/test/IECoreScene/CurveExtrudeOp.py deleted file mode 100644 index 7450cbf43a..0000000000 --- a/test/IECoreScene/CurveExtrudeOp.py +++ /dev/null @@ -1,65 +0,0 @@ -########################################################################## -# -# Copyright (c) 2009, 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 Image Engine Design 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 os.path -import math -import unittest -import imath -import IECore -import IECoreScene - -class CurveExtrudeOpTest( unittest.TestCase ) : - - def testIt( self ) : - - c = IECore.Reader.create( os.path.join( "test", "IECore", "data", "cobFiles", "torusCurves.cob" ) ).read() - assert( c.arePrimitiveVariablesValid() ) - - op = IECoreScene.CurveExtrudeOp() - - patchGroup = op( - curves = c, - resolution = imath.V2i( 6, 30 ) - ) - - self.assertEqual( len( patchGroup.children() ), 193 ) - - for child in patchGroup.children() : - - self.assertTrue( child.arePrimitiveVariablesValid() ) - -if __name__ == "__main__": - unittest.main() - From 64466f33f85d5593ee2e86c43c3fa4ebc42dcb1a Mon Sep 17 00:00:00 2001 From: John Haddon Date: Wed, 9 Jul 2025 17:56:19 +0100 Subject: [PATCH 09/15] Remove IDXReader It returns Group objects, which are not useable or renderable in Gaffer. This could probably be salvaged by returning a single PointsPrimitive with per-point information to identify the station, but someone with skin in that game would need to step up to do it. --- Changes | 2 +- python/IECoreScene/IDXReader.py | 257 ------------------------------ python/IECoreScene/__init__.py | 1 - test/IECoreScene/All.py | 1 - test/IECoreScene/IDXReaderTest.py | 92 ----------- test/IECoreScene/SWAReaderTest.py | 1 - 6 files changed, 1 insertion(+), 353 deletions(-) delete mode 100644 python/IECoreScene/IDXReader.py delete mode 100644 test/IECoreScene/IDXReaderTest.py diff --git a/Changes b/Changes index 2d28990649..9810638720 100644 --- a/Changes +++ b/Changes @@ -15,7 +15,7 @@ Breaking Changes - Renderable : Removed `render()` method. - CoordinateSystem : Removed transform. - Options : Removed. -- CurveExtrudeOp : Removed. +- CurveExtrudeOp, IDXReader : Removed. - Renderer, AttributeBlock, EditBlock, MotionBlock, TransformBlock, WorldBlock : Removed. - IECoreHoudini : Removed. - IECoreMaya : Removed. diff --git a/python/IECoreScene/IDXReader.py b/python/IECoreScene/IDXReader.py deleted file mode 100644 index 9f67d9fa4b..0000000000 --- a/python/IECoreScene/IDXReader.py +++ /dev/null @@ -1,257 +0,0 @@ -########################################################################## -# -# Copyright (c) 2010, 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 Image Engine Design 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 re -import imath - -import IECore -import IECoreScene - -class IDXReader( IECore.Reader ) : - - def __init__( self, fileName=None ) : - - IECore.Reader.__init__( - self, - "Reads Leica Geosystems IDX files" - ) - - if fileName is not None : - self["fileName"].setTypedValue( fileName ) - - @staticmethod - def canRead( fileName ) : - - try : - f = open( fileName, "r" ) - return f.read( 6 )=="HEADER" - except : - return False - - def doOperation( self, args ) : - - f = open( args["fileName"].value, "r" ) - - l = "".join( f.readlines() ) - - dbMatch = re.search( "^DATABASE(.*)END DATABASE", l, re.MULTILINE | re.DOTALL ) - if dbMatch is None : - raise RuntimeError( "Unable to find database block in file \"%s\"" % args["fileName"].value ) - - headerMatch = re.search( "^HEADER(.*)END HEADER", l, re.MULTILINE | re.DOTALL ) - if headerMatch is None : - raise RuntimeError( "Unable to find header block in file \"%s\"" % args["fileName"].value ) - - projMatch = re.search( "PROJECT(.*?)END PROJECT", headerMatch.group( 1 ), re.MULTILINE | re.DOTALL ) - if projMatch is None : - raise RuntimeError( "Unable to find project block in file \"%s\"" % args["fileName"].value ) - - theoMatch = re.search( "^THEODOLITE(.*?)END THEODOLITE", l, re.MULTILINE | re.DOTALL ) - if theoMatch is None : - raise RuntimeError( "Unable to find theodolite block in file \"%s\"" % args["fileName"].value ) - - pointsMatch = re.search( r"POINTS\(([^)]*)\)(.*?)END POINTS", dbMatch.group( 1 ), re.MULTILINE | re.DOTALL ) - if pointsMatch is None : - raise RuntimeError( "Unable to find points block in file \"%s\"" % args["fileName"].value ) - - annotationMatch = re.search( r"ANNOTATIONS\(([^)]*)\)(.*?)END ANNOTATIONS", dbMatch.group( 1 ), re.MULTILINE | re.DOTALL ) - if annotationMatch is None : - raise RuntimeError( "Unable to find annotation block in file \"%s\"" % args["fileName"].value ) - - setupSlopeMatch = re.finditer( r"SETUP(.*?)END SETUP.*?SLOPE\(([^)]*)\)(.*?)END SLOPE", theoMatch.group( 1 ), re.MULTILINE | re.DOTALL ) - if setupSlopeMatch is None : - raise RuntimeError( "Unable to setup/slope block in file \"%s\"" % args["fileName"].value ) - - # Extract the Points from the database, these all have 'absolute' positions based on where the - # Station was registered as being. - points = self.__extractRows( pointsMatch.group(1), pointsMatch.group(2), "PointNo" ) - if not points : - raise ValueError( "No points in file..." ) - - # Extract any annotations in the points database - annotations = self.__extractRows( annotationMatch.group(1), annotationMatch.group(2), "PointNo" ) - - # Find out a little about our project - projInfo = self.__extractFields( projMatch.group(1) ) - - # We're going to return a group of PointsPrimitives, one for each station. - g = IECoreScene.Group() - - for s in setupSlopeMatch: - - try: - members = self.__extractRows( s.group(2), s.group(3), "TgtNo" ) - except ValueError : - continue - - p = IECore.V3fVectorData() - ids = IECore.StringVectorData() - nos = IECore.IntVectorData() - dates = IECore.StringVectorData() - codes = IECore.StringVectorData() - annotations = IECore.StringVectorData() - - for k in members.keys() : - - if k not in points : - continue - - if "East" not in points[k] or "North" not in points[k] or "Elevation" not in points[k]: - # some rows seem to have missing data - not much we can do about that - continue - - try : - x = float( points[k]["East"] ) - y = float( points[k]["Elevation"] ) - z = -float( points[k]["North"] ) # Handedness... - except ValueError: - continue; - - p.append( imath.V3f( x, y, z ) ) - - nos.append( int(points[k]["PointNo"]) ) - - ids.append( points[k]["PointID"] if "PointID" in points[k] else "" ) - dates.append( points[k]["Date"] if "Date" in points[k] else "" ) - codes.append( points[k]["Code"] if "Code" in points[k] else "" ) - - if k in annotations : - annotations.append( annotations[k]["Annotation"] ) - else : - annotations.append( "" ) - - primitive = IECoreScene.PointsPrimitive( p ) - - # Extract any available station info from the SETUP block - stnInfo = self.__extractFields( s.group(1) ) - for d in stnInfo.keys() : - primitive.blindData()[d] = IECore.StringData( stnInfo[d] ) - - # Store our station information on the primitive - if "STN_NO" in stnInfo: - - stnNo = stnInfo["STN_NO"] - - if stnNo in points : - tx = float( points[ stnNo ]["East"] ) - ty = float( points[ stnNo ]["Elevation"] ) - tz = -float( points[ stnNo ]["North"] ) # Handedness... - primitive.blindData()["STN_POSITION"] = IECore.V3fData( imath.V3f( tx, ty, tz ) ) - - if stnNo in annotations: - primitive.blindData()["STN_ANNOTATION"] = IECore.StringData( annotations[stnNo]["Annotation"] ) - - # copy Project Information to the primitive - for f in projInfo: - primitive.blindData()["PROJECT_%s" % f] = IECore.StringData( projInfo[f] ) - - primitive["PointID"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, ids ) - primitive["PointNo"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, nos ) - primitive["Date"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, dates ) - primitive["Code"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, codes ) - primitive["Annotation"] = IECoreScene.PrimitiveVariable( IECoreScene.PrimitiveVariable.Interpolation.Vertex, annotations ) - - if primitive.numPoints > 0 : - g.addChild( primitive ) - - return g - - # Extracts a row into a dictionary, or list, depending on wether a keyColumns name is specified - # \param columnString A comma separated list of column names - # \param rows A string containing all the rows of data - # \paran keyColumn (optional) The string name of a column to use as a key in the output. If specified - # a dictionary will be returned, rather than an ordered list. - def __extractRows( self, columnString, rows, keyColumn=None ) : - - columnNames = [ x.strip() for x in columnString.split( "," ) ] - numColumns = len( columnNames ) - - if keyColumn and keyColumn not in columnNames : - raise ValueError( "Unable to find the requested key column '%s' (%s)" % ( keyColumn, columnNames ) ) - - if keyColumn: - keyIndex = columnNames.index( keyColumn ) - output = {} - else : - output = [] - - rows = rows.split( "\n" ) - for row in rows : - - thisRow = {} - - columns = [ x.strip( " \t\r;\"\'" ) for x in row.split( "," ) ] - if len( columns ) != numColumns : - continue - - try : - for i in range(numColumns): - thisRow[ columnNames[i] ] = columns[i] - except ValueError : - # some rows seem to have missing data - not much we can do about that - continue - - if keyColumn: - output[ columns[keyIndex] ] = thisRow - else: - output.append( thisRow ) - - return output - - # Extracts fields from a simple NAME VALUE line. - # \param data A string containing the field block - # \prarm names A list of field NAMEs to extract. Any missing names will be omitted from the - # returned dictionary. - # \return A dictionary of NAME : VALUE pairs. All data remains as strings. - def __extractFields( self, data, names=None ) : - - fields = {} - - if names: - for n in names: - match = re.search( n+r'[\s]+"{0,1}?([:\\/\-,.\w.]+)"{0,1}?', data, re.MULTILINE | re.DOTALL ) - if match: - fields[n] = match.group(1) - else: - - lines = data.split( "\n" ) - for l in lines: - match = re.search( r'([\w.]+)[\s]+"{0,1}?([:\\/\-,.\w. ]+)"{0,1}?', l.strip( " \t\r;\"\'" ), re.MULTILINE | re.DOTALL ) - if match: - fields[match.group(1)] = match.group(2) - - return fields - -IECore.registerRunTimeTyped( IDXReader ) -IECore.Reader.registerReader( "idx", IDXReader.canRead, IDXReader, IDXReader.staticTypeId() ) diff --git a/python/IECoreScene/__init__.py b/python/IECoreScene/__init__.py index 0e435943a0..c54763bd3a 100644 --- a/python/IECoreScene/__init__.py +++ b/python/IECoreScene/__init__.py @@ -38,7 +38,6 @@ from .RemovePrimitiveVariables import RemovePrimitiveVariables from .RenamePrimitiveVariables import RenamePrimitiveVariables -from .IDXReader import IDXReader from .SWAReader import SWAReader __import__( "IECore" ).loadConfig( "CORTEX_STARTUP_PATHS", subdirectory = "IECoreScene" ) diff --git a/test/IECoreScene/All.py b/test/IECoreScene/All.py index d2b32d210e..f45327a838 100644 --- a/test/IECoreScene/All.py +++ b/test/IECoreScene/All.py @@ -75,7 +75,6 @@ from CurvesMergeOpTest import CurvesMergeOpTest from CurvesPrimitiveEvaluatorTest import CurvesPrimitiveEvaluatorTest from CurveLineariserTest import CurveLineariserTest -from IDXReaderTest import IDXReaderTest from CurveTangentsOpTest import CurveTangentsOpTest from SmoothSkinningDataTest import * from PrimitiveVariableTest import PrimitiveVariableTest diff --git a/test/IECoreScene/IDXReaderTest.py b/test/IECoreScene/IDXReaderTest.py deleted file mode 100644 index d8a34cc0c6..0000000000 --- a/test/IECoreScene/IDXReaderTest.py +++ /dev/null @@ -1,92 +0,0 @@ -########################################################################## -# -# Copyright (c) 2010, 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 Image Engine Design 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 os -import IECore -import IECoreScene - -class IDXReaderTest( unittest.TestCase ) : - - def testConstruction( self ) : - - r = IECoreScene.IDXReader() - self.assertEqual( r["fileName"].getTypedValue(), "" ) - - r = IECoreScene.IDXReader( os.path.join( "test", "IECore", "data", "idxFiles", "test.idx" ) ) - self.assertEqual( r["fileName"].getTypedValue(), os.path.join( "test", "IECore", "data", "idxFiles", "test.idx" ) ) - - def testReading( self ) : - - r = IECoreScene.IDXReader( os.path.join( "test", "IECore", "data", "idxFiles", "test.idx" ) ) - - o = r.read() - - self.assertTrue( o.isInstanceOf( IECoreScene.Group.staticTypeId() ) ) - - self.assertEqual( len(o.children()), 1 ) - - c = o.children()[0] - - self.assertEqual( c.numPoints, 6 ) - - # We're not order preserving - - for k in [ "000", "001", "002", "003", "004", "005" ] : - self.assertTrue( k in c["PointID"].data ) - - for p in [ - imath.V3f( 63.204863, 0.831837, -33.969296 ), - imath.V3f( 62.345470, 0.707662, -34.099882 ), - imath.V3f( 63.104346, 0.708060, -34.025762 ), - imath.V3f( 63.096101, -0.973316, -34.031914 ), - imath.V3f( 62.338136, -0.974567, -34.112893 ), - imath.V3f( 54.252821, 0.716216, -34.849839 ), - ]: - self.assertTrue( p in c["P"].data ) - - def testCanRead( self ) : - - self.assertTrue( IECoreScene.IDXReader.canRead( os.path.join( "test", "IECore", "data", "idxFiles", "test.idx" ) ) ) - self.assertFalse( IECoreScene.IDXReader.canRead( os.path.join( "test", "IECore", "data", "cobFiles", "ball.cob" ) ) ) - - def testRegistration( self ) : - - r = IECore.Reader.create( os.path.join( "test", "IECore", "data", "idxFiles", "test.idx" ) ) - self.assertTrue( isinstance( r, IECoreScene.IDXReader ) ) - -if __name__ == "__main__": - unittest.main() - diff --git a/test/IECoreScene/SWAReaderTest.py b/test/IECoreScene/SWAReaderTest.py index b411bbd6aa..e3bdcabf5e 100644 --- a/test/IECoreScene/SWAReaderTest.py +++ b/test/IECoreScene/SWAReaderTest.py @@ -101,7 +101,6 @@ def testReading( self ) : def testCanRead( self ) : self.assertTrue( IECoreScene.SWAReader.canRead( os.path.join( "test", "IECore", "data", "swaFiles", "test.swa" ) ) ) - self.assertFalse( IECoreScene.IDXReader.canRead( os.path.join( "test", "IECore", "data", "cobFiles/ball.cob" ) ) ) self.assertFalse( IECoreScene.SWAReader.canRead( os.path.join( "test", "IECore", "data", "idxFiles", "test.idx" ) ) ) self.assertFalse( IECoreScene.SWAReader.canRead( os.path.join( "test", "IECore", "data", "empty" ) ) ) From 5437f0641eacf344a9c26508ed8d9541da0b0900 Mon Sep 17 00:00:00 2001 From: John Haddon Date: Tue, 8 Jul 2025 10:57:11 +0100 Subject: [PATCH 10/15] Font : Remove `meshGroup()` method This removes the last use of the Group class. --- Changes | 1 + include/IECoreScene/Font.h | 4 --- src/IECoreScene/Font.cpp | 45 ------------------------ src/IECoreScene/bindings/FontBinding.cpp | 2 -- test/IECoreScene/FontTest.py | 16 --------- 5 files changed, 1 insertion(+), 67 deletions(-) diff --git a/Changes b/Changes index 9810638720..28ddb4c2f9 100644 --- a/Changes +++ b/Changes @@ -14,6 +14,7 @@ Breaking Changes - Renderable : Removed `render()` method. - CoordinateSystem : Removed transform. +- Font : Removed `meshGroup()` method. - Options : Removed. - CurveExtrudeOp, IDXReader : Removed. - Renderer, AttributeBlock, EditBlock, MotionBlock, TransformBlock, WorldBlock : Removed. diff --git a/include/IECoreScene/Font.h b/include/IECoreScene/Font.h index e28477787a..4dda266ac6 100644 --- a/include/IECoreScene/Font.h +++ b/include/IECoreScene/Font.h @@ -50,7 +50,6 @@ namespace IECoreScene { IE_CORE_FORWARDDECLARE( MeshPrimitive ); -IE_CORE_FORWARDDECLARE( Group ); /// The Font class allows the loading of fonts and their /// conversion to MeshPrimitives. @@ -91,9 +90,6 @@ class IECORESCENE_API Font : public IECore::RunTimeTyped /// Returns a mesh representing the specified string, /// using the current curve tolerance and kerning. MeshPrimitivePtr mesh( const std::string &text ) const; - /// Returns a group representing the specified string, - /// using the current curve tolerance and kerning. - GroupPtr meshGroup( const std::string &text ) const; /// Returns the necessary appropriate offset between the /// origins of the first and second characters, taking /// into account the current kerning. diff --git a/src/IECoreScene/Font.cpp b/src/IECoreScene/Font.cpp index 56d6b2b577..ce2241fc4a 100644 --- a/src/IECoreScene/Font.cpp +++ b/src/IECoreScene/Font.cpp @@ -34,8 +34,6 @@ #include "IECoreScene/Font.h" -#include "IECoreScene/Group.h" -#include "IECoreScene/MatrixTransform.h" #include "IECoreScene/MeshAlgo.h" #include "IECoreScene/MeshPrimitive.h" #include "IECoreScene/TransformOp.h" @@ -397,44 +395,6 @@ class Font::Implementation : public IECore::RefCounted return MeshAlgo::merge( meshes ); } - GroupPtr meshGroup( const std::string &text ) const - { - GroupPtr result = new Group; - - if( !text.size() ) - { - return result; - } - - V3f translate( 0.0f ); - for( unsigned i=0; iprimitive->variableSize( PrimitiveVariable::Uniform ) ) - { - GroupPtr g = new Group; - g->addChild( character->primitive->copy() ); - g->setTransform( new MatrixTransform( M44f().setTranslation( translate ) ) ); - result->addChild( g ); - } - - if( iadvance; @@ -642,11 +602,6 @@ MeshPrimitivePtr Font::mesh( const std::string &text ) const return m_implementation->mesh( text ); } -GroupPtr Font::meshGroup( const std::string &text ) const -{ - return m_implementation->meshGroup( text ); -} - Imath::V2f Font::advance( char first, char second ) const { return m_implementation->advance( first, second ); diff --git a/src/IECoreScene/bindings/FontBinding.cpp b/src/IECoreScene/bindings/FontBinding.cpp index 4c3fcf0e48..c882e35c1a 100644 --- a/src/IECoreScene/bindings/FontBinding.cpp +++ b/src/IECoreScene/bindings/FontBinding.cpp @@ -39,7 +39,6 @@ #include "FontBinding.h" #include "IECoreScene/Font.h" -#include "IECoreScene/Group.h" #include "IECoreScene/MeshPrimitive.h" #include "IECorePython/RunTimeTypedBinding.h" @@ -89,7 +88,6 @@ void bindFont() .def( "getLineSpacing", &Font::getLineSpacing ) .def( "mesh", &mesh1 ) .def( "mesh", &mesh2 ) - .def( "meshGroup", &Font::meshGroup ) .def( "advance", &Font::advance ) .def( "bound", (Imath::Box2f (Font::*)( )const)&Font::bound ) .def( "bound", (Imath::Box2f (Font::*)( char )const)&Font::bound ) diff --git a/test/IECoreScene/FontTest.py b/test/IECoreScene/FontTest.py index 121ab8e318..ba334cbbd1 100644 --- a/test/IECoreScene/FontTest.py +++ b/test/IECoreScene/FontTest.py @@ -50,25 +50,9 @@ def testConstructors( self ) : def test( self ) : f = IECoreScene.Font( os.path.join( "test", "IECore", "data", "fonts", "Vera.ttf" ) ) - - g = f.meshGroup( "hello world" ) m = f.mesh( "hello world" ) - - self.assertTrue( g.isInstanceOf( IECoreScene.Group.staticTypeId() ) ) self.assertTrue( m.isInstanceOf( IECoreScene.MeshPrimitive.staticTypeId() ) ) - v = 0 - for c in g.children() : - - self.assertTrue( c.isInstanceOf( IECoreScene.Group.staticTypeId() ) ) - self.assertEqual( len( c.children() ), 1 ) - self.assertTrue( c.children()[0].isInstanceOf( IECoreScene.MeshPrimitive.staticTypeId() ) ) - self.assertEqual( c.children()[0]["P"].data.getInterpretation(), IECore.GeometricData.Interpretation.Point ) - - v += c.children()[0]["P"].data.size() - - self.assertEqual( v, m["P"].data.size() ) - def testCharBound( self ) : f = IECoreScene.Font( os.path.join( "test", "IECore", "data", "fonts", "Vera.ttf" ) ) From 108fa0b16975be8afe8cc86af3e8a3d45bbc8864 Mon Sep 17 00:00:00 2001 From: John Haddon Date: Tue, 8 Jul 2025 11:04:07 +0100 Subject: [PATCH 11/15] Group, Transform, AttributeState : Remove These are no longer useful for rendering because the Renderer class has gone. And they've not useful in Gaffer because it represents grouping, transform and attributes using a different mechanism. --- Changes | 2 +- .../src/IECoreAlembic/CameraReader.cpp | 1 - include/IECoreScene/AttributeState.h | 78 --- include/IECoreScene/Group.h | 143 ------ include/IECoreScene/MatrixMotionTransform.h | 78 --- include/IECoreScene/MatrixTransform.h | 69 --- include/IECoreScene/Transform.h | 76 --- include/IECoreScene/TypeIds.h | 22 +- include/IECoreScene/TypedObjectParameter.h | 15 - src/IECoreGL/ToGLCameraConverter.cpp | 1 - src/IECoreScene/AttributeState.cpp | 116 ----- src/IECoreScene/Group.cpp | 449 ------------------ src/IECoreScene/MatrixMotionTransform.cpp | 166 ------- src/IECoreScene/MatrixTransform.cpp | 104 ---- src/IECoreScene/Transform.cpp | 83 ---- src/IECoreScene/TypedObjectParameter.cpp | 15 - .../bindings/AttributeStateBinding.cpp | 58 --- .../bindings/AttributeStateBinding.h | 45 -- src/IECoreScene/bindings/GroupBinding.cpp | 113 ----- src/IECoreScene/bindings/GroupBinding.h | 43 -- src/IECoreScene/bindings/IECoreScene.cpp | 10 - .../bindings/MatrixMotionTransformBinding.cpp | 125 ----- .../bindings/MatrixMotionTransformBinding.h | 43 -- .../bindings/MatrixTransformBinding.cpp | 60 --- .../bindings/MatrixTransformBinding.h | 43 -- src/IECoreScene/bindings/TransformBinding.cpp | 61 --- src/IECoreScene/bindings/TransformBinding.h | 43 -- .../bindings/TypedObjectParameterBinding.cpp | 10 - test/IECoreScene/All.py | 3 - test/IECoreScene/AttributeStateTest.py | 75 --- test/IECoreScene/Group.py | 325 ------------- test/IECoreScene/Transform.py | 123 ----- 32 files changed, 12 insertions(+), 2586 deletions(-) delete mode 100644 include/IECoreScene/AttributeState.h delete mode 100644 include/IECoreScene/Group.h delete mode 100644 include/IECoreScene/MatrixMotionTransform.h delete mode 100644 include/IECoreScene/MatrixTransform.h delete mode 100644 include/IECoreScene/Transform.h delete mode 100644 src/IECoreScene/AttributeState.cpp delete mode 100644 src/IECoreScene/Group.cpp delete mode 100644 src/IECoreScene/MatrixMotionTransform.cpp delete mode 100644 src/IECoreScene/MatrixTransform.cpp delete mode 100644 src/IECoreScene/Transform.cpp delete mode 100644 src/IECoreScene/bindings/AttributeStateBinding.cpp delete mode 100644 src/IECoreScene/bindings/AttributeStateBinding.h delete mode 100644 src/IECoreScene/bindings/GroupBinding.cpp delete mode 100644 src/IECoreScene/bindings/GroupBinding.h delete mode 100644 src/IECoreScene/bindings/MatrixMotionTransformBinding.cpp delete mode 100644 src/IECoreScene/bindings/MatrixMotionTransformBinding.h delete mode 100644 src/IECoreScene/bindings/MatrixTransformBinding.cpp delete mode 100644 src/IECoreScene/bindings/MatrixTransformBinding.h delete mode 100644 src/IECoreScene/bindings/TransformBinding.cpp delete mode 100644 src/IECoreScene/bindings/TransformBinding.h delete mode 100644 test/IECoreScene/AttributeStateTest.py delete mode 100644 test/IECoreScene/Group.py delete mode 100644 test/IECoreScene/Transform.py diff --git a/Changes b/Changes index 28ddb4c2f9..da4d1c1c05 100644 --- a/Changes +++ b/Changes @@ -15,7 +15,7 @@ Breaking Changes - Renderable : Removed `render()` method. - CoordinateSystem : Removed transform. - Font : Removed `meshGroup()` method. -- Options : Removed. +- Options, Group, Transform, MatrixTransform, MatrixMotionTransform, AttributeState : Removed. - CurveExtrudeOp, IDXReader : Removed. - Renderer, AttributeBlock, EditBlock, MotionBlock, TransformBlock, WorldBlock : Removed. - IECoreHoudini : Removed. diff --git a/contrib/IECoreAlembic/src/IECoreAlembic/CameraReader.cpp b/contrib/IECoreAlembic/src/IECoreAlembic/CameraReader.cpp index c7687fce52..e900794212 100644 --- a/contrib/IECoreAlembic/src/IECoreAlembic/CameraReader.cpp +++ b/contrib/IECoreAlembic/src/IECoreAlembic/CameraReader.cpp @@ -36,7 +36,6 @@ #include "IECoreAlembic/ObjectReader.h" #include "IECoreScene/Camera.h" -#include "IECoreScene/Transform.h" #include "IECore/SimpleTypedData.h" diff --git a/include/IECoreScene/AttributeState.h b/include/IECoreScene/AttributeState.h deleted file mode 100644 index c047cb571d..0000000000 --- a/include/IECoreScene/AttributeState.h +++ /dev/null @@ -1,78 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2010, 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 Image Engine Design 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 IECORESCENE_ATTRIBUTESTATE_H -#define IECORESCENE_ATTRIBUTESTATE_H - -#include "IECoreScene/Export.h" -#include "IECoreScene/StateRenderable.h" - -namespace IECoreScene -{ - -/// A class to manipulate the attribute state of a Renderer. -/// \todo Make order of rendering match order of addition - there are cases where -/// 3delight cares very much what order attributes are specified in (subsurface attributes in particular). -/// \ingroup renderingGroup -class IECORESCENE_API AttributeState : public StateRenderable -{ - public: - - /// Attributes is referenced directly rather than copied. - AttributeState( IECore::CompoundDataPtr attributes ); - AttributeState( const IECore::CompoundDataMap &attributes = IECore::CompoundDataMap() ); - ~AttributeState() override; - - IE_CORE_DECLAREEXTENSIONOBJECT( AttributeState, AttributeStateTypeId, StateRenderable ); - - IECore::CompoundDataMap &attributes(); - const IECore::CompoundDataMap &attributes() const; - /// This is mostly of use for the binding - the attributes() - /// function gives more direct access to the contents of the CompoundData - /// (it calls readable() or writable() for you). - IECore::CompoundDataPtr attributesData(); - - private: - - IECore::CompoundDataPtr m_attributes; - - static const unsigned int m_ioVersion; -}; - -IE_CORE_DECLAREPTR( AttributeState ); - -} // namespace IECoreScene - - -#endif // IECORESCENE_ATTRIBUTESTATE_H diff --git a/include/IECoreScene/Group.h b/include/IECoreScene/Group.h deleted file mode 100644 index 84d11d8497..0000000000 --- a/include/IECoreScene/Group.h +++ /dev/null @@ -1,143 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2011, 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 Image Engine Design 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 IECORESCENE_GROUP_H -#define IECORESCENE_GROUP_H - -#include "IECoreScene/Export.h" -#include "IECoreScene/StateRenderable.h" -#include "IECoreScene/Transform.h" -#include "IECoreScene/VisibleRenderable.h" - -namespace IECoreScene -{ - -IE_CORE_FORWARDDECLARE( Group ); - -/// This class allows the grouping and rendering of a set -/// of VisibleRenderables, applying a specific set of Transforms -/// and StateRenderables to them. -/// \ingroup renderingGroup -class IECORESCENE_API Group : public VisibleRenderable -{ - - public: - - typedef std::vector ChildContainer; - typedef std::vector StateContainer; - - /// \todo Add a constructor taking a list of children and state - /// and an optional transform, and bind it. - Group(); - ~Group() override; - - IE_CORE_DECLAREEXTENSIONOBJECT( Group, GroupTypeId, VisibleRenderable ); - - /// Returns the Transform applied to the children of - /// this Group. This is the local transform for the Group - /// and takes no account of any transforms in the parents - /// of the Group. May return 0 if no transform has been - /// applied. - Transform *getTransform(); - const Transform *getTransform() const; - /// Sets the local transform applied to the children - /// of this Group. - void setTransform( TransformPtr transform ); - /// Returns the actual local transform matrix applied - /// to this Group, evaluated at the specified time. - Imath::M44f transformMatrix( float time = 0 ) const; - /// Returns the final transform applied to the children - /// of this Group when all parent transforms have been - /// concatenated together with the local transform. - Imath::M44f globalTransformMatrix( float time = 0 ) const; - - /// Adds some state to the Group. Throws an Exception if - /// an attempt is made to add something deriving from Transform - - /// setTransform() should be used for that. - void addState( StateRenderablePtr state ); - /// Removes some state from the Group. If the state - /// is not present already then an Exception is thrown. - void removeState( StateRenderablePtr state ); - /// Removes all state from the Group. - void clearState(); - /// Const access to the internal data structure used - /// to hold the state. - const StateContainer &state() const; - /// Query an attribute from the group's scope. Tries to - /// find the attribute in the group's state, then traverses - /// the group's parents - const IECore::Data *getAttribute( const std::string &name ) const; - /// Set an attribute on this group. - void setAttribute( const std::string &name, IECore::ConstDataPtr value ); - - /// Adds a child to this Group. If the child is a Group itself - /// and already has a parent then it will be removed from that - /// parent before being added. Other VisibleRenderables may be - /// parented under many Groups to provide instancing capabilities. - void addChild( VisibleRenderablePtr child ); - /// Removes a child from the Group - has no effect if child is currently - /// not a child. If the child is not a member of the group then - /// an Exception is thrown. - void removeChild( VisibleRenderablePtr child ); - /// Removes all children from the Group. - void clearChildren(); - /// Const access to the internal data structure used to hold - /// the children. - const ChildContainer &children() const; - - /// Returns the parent for this Group, returning 0 if no - /// parent exists. - Group *parent(); - const Group *parent() const; - - /// Returns the union of the bounds of the children, transformed - /// by transformMatrix(). - Imath::Box3f bound() const override; - - private: - - static bool entryListCompare( const IECore::IndexedIO::EntryID& a, const IECore::IndexedIO::EntryID& b ); - - static const unsigned int m_ioVersion; - - TransformPtr m_transform; - Group *m_parent; // not a smart pointer to avoid cylic references - StateContainer m_state; - ChildContainer m_children; - -}; - -} // namespace IECoreScene - -#endif // IECORESCENE_GROUP_H diff --git a/include/IECoreScene/MatrixMotionTransform.h b/include/IECoreScene/MatrixMotionTransform.h deleted file mode 100644 index c5bcd075c1..0000000000 --- a/include/IECoreScene/MatrixMotionTransform.h +++ /dev/null @@ -1,78 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2010, 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 Image Engine Design 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 IECORESCENE_MATRIXMOTIONTRANSFORM_H -#define IECORESCENE_MATRIXMOTIONTRANSFORM_H - -#include "IECoreScene/Export.h" -#include "IECoreScene/Transform.h" - -namespace IECoreScene -{ - -class IECORESCENE_API MatrixMotionTransform : public Transform -{ - public: - - /// A type to map between points in time and - /// corresponding matrices. - typedef std::map SnapshotMap; - - IE_CORE_DECLAREEXTENSIONOBJECT( MatrixMotionTransform, MatrixMotionTransformTypeId, Transform ); - - MatrixMotionTransform(); - ~MatrixMotionTransform() override; - - Imath::M44f transform( float time = 0 ) const override; - - //! @name Snapshots - //////////////////////////////////////////// - //@{ - const SnapshotMap &snapshots() const; - SnapshotMap &snapshots(); - //@} - - private: - - static const unsigned int m_ioVersion; - - SnapshotMap m_snapshots; - -}; - -IE_CORE_DECLAREPTR( MatrixMotionTransform ); - -} - -#endif // IECORESCENE_MATRIXMOTIONTRANSFORM_H diff --git a/include/IECoreScene/MatrixTransform.h b/include/IECoreScene/MatrixTransform.h deleted file mode 100644 index 9f804166d2..0000000000 --- a/include/IECoreScene/MatrixTransform.h +++ /dev/null @@ -1,69 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2010, 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 Image Engine Design 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 IECORESCENE_MATRIXTRANSFORM_H -#define IECORESCENE_MATRIXTRANSFORM_H - -#include "IECoreScene/Export.h" -#include "IECoreScene/Transform.h" - -namespace IECoreScene -{ - -class IECORESCENE_API MatrixTransform : public Transform -{ - public: - - IE_CORE_DECLAREEXTENSIONOBJECT( MatrixTransform, MatrixTransformTypeId, Transform ); - - MatrixTransform( const Imath::M44f &matrix = Imath::M44f() ); - ~MatrixTransform() override; - - Imath::M44f transform( float time = 0 ) const override; - - /// The transform this object applies. It can - /// be modified freely. - Imath::M44f matrix; - - private: - - static const unsigned int m_ioVersion; - -}; - -IE_CORE_DECLAREPTR( MatrixTransform ); - -} - -#endif // IECORESCENE_MATRIXTRANSFORM_H diff --git a/include/IECoreScene/Transform.h b/include/IECoreScene/Transform.h deleted file mode 100644 index 31e53e2866..0000000000 --- a/include/IECoreScene/Transform.h +++ /dev/null @@ -1,76 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2011, 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 Image Engine Design 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 IECORESCENE_TRANSFORM_H -#define IECORESCENE_TRANSFORM_H - -#include "IECoreScene/Export.h" -#include "IECoreScene/StateRenderable.h" - -#include "IECore/Export.h" - -IECORE_PUSH_DEFAULT_VISIBILITY -#include "Imath/ImathMatrix.h" -IECORE_POP_DEFAULT_VISIBILITY - -namespace IECoreScene -{ - -/// An abstract class to define objects which apply a transform to the -/// state of a Renderer. -/// \ingroup renderingGroup -class IECORESCENE_API Transform : public StateRenderable -{ - public: - - Transform(); - ~Transform() override; - - IE_CORE_DECLAREEXTENSIONOBJECT( Transform, TransformTypeId, StateRenderable ); - - /// Returns the transform this object represents, - /// evaluated at the requested time. - virtual Imath::M44f transform( float time = 0 ) const = 0; - - private: - - static const unsigned int m_ioVersion; - -}; - -IE_CORE_DECLAREPTR( Transform ); - -} - -#endif // IECORESCENE_TRANSFORM_H diff --git a/include/IECoreScene/TypeIds.h b/include/IECoreScene/TypeIds.h index 5d60fc9e3d..9a308e565d 100644 --- a/include/IECoreScene/TypeIds.h +++ b/include/IECoreScene/TypeIds.h @@ -52,25 +52,25 @@ enum TypeId ParticleReaderTypeId = 108009, ParticleWriterTypeId = 108010, MotionPrimitiveTypeId = 108011, - TransformTypeId = 108012, - MatrixTransformTypeId = 108013, - MotionTransformTypeId = 108014, - MatrixMotionTransformTypeId = 108015, - GroupTypeId = 108016, - AttributeStateTypeId = 108017, + TransformTypeId = 108012, // Obsolete, available for reuse + MatrixTransformTypeId = 108013, // Obsolete, available for reuse + MotionTransformTypeId = 108014, // Obsolete, available for reuse + MatrixMotionTransformTypeId = 108015, // Obsolete, available for reuse + GroupTypeId = 108016, // Obsolete, available for reuse + AttributeStateTypeId = 108017, // Obsolete, available for reuse VisibleRenderableTypeId = 108018, StateRenderableTypeId = 108019, OBJReaderTypeId = 108020, PointNormalsOpTypeId = 108021, // Obsolete, available for reuse PointDensitiesOpTypeId = 108022, // Obsolete, available for reuse StateRenderableParameterTypeId = 108023, - AttributeStateParameterTypeId = 108024, + AttributeStateParameterTypeId = 108024, // Obsolete, available for reuse ShaderParameterTypeId = 108025, - TransformParameterTypeId = 108026, - MatrixMotionTransformParameterTypeId = 108027, - MatrixTransformParameterTypeId = 108028, + TransformParameterTypeId = 108026, // Obsolete, available for reuse + MatrixMotionTransformParameterTypeId = 108027, // Obsolete, available for reuse + MatrixTransformParameterTypeId = 108028, // Obsolete, available for reuse VisibleRenderableParameterTypeId = 108029, - GroupParameterTypeId = 108030, + GroupParameterTypeId = 108030, // Obsolete, available for reuse MotionPrimitiveParameterTypeId = 108031, PrimitiveParameterTypeId = 108032, MeshPrimitiveParameterTypeId = 108033, diff --git a/include/IECoreScene/TypedObjectParameter.h b/include/IECoreScene/TypedObjectParameter.h index d51057619b..85571bf8b9 100644 --- a/include/IECoreScene/TypedObjectParameter.h +++ b/include/IECoreScene/TypedObjectParameter.h @@ -42,35 +42,20 @@ namespace IECoreScene IE_CORE_FORWARDDECLARE( Renderable ) IE_CORE_FORWARDDECLARE( StateRenderable ) -IE_CORE_FORWARDDECLARE( AttributeState ) IE_CORE_FORWARDDECLARE( Shader ) -IE_CORE_FORWARDDECLARE( Transform ) -IE_CORE_FORWARDDECLARE( MatrixMotionTransform ) -IE_CORE_FORWARDDECLARE( MatrixTransform ) IE_CORE_FORWARDDECLARE( VisibleRenderable ) -IE_CORE_FORWARDDECLARE( Group ) IE_CORE_FORWARDDECLARE( SmoothSkinningData ) typedef IECore::TypedObjectParameter RenderableParameter; typedef IECore::TypedObjectParameter StateRenderableParameter; -typedef IECore::TypedObjectParameter AttributeStateParameter; typedef IECore::TypedObjectParameter ShaderParameter; -typedef IECore::TypedObjectParameter TransformParameter; -typedef IECore::TypedObjectParameter MatrixMotionTransformParameter; -typedef IECore::TypedObjectParameter MatrixTransformParameter; typedef IECore::TypedObjectParameter VisibleRenderableParameter; -typedef IECore::TypedObjectParameter GroupParameter; typedef IECore::TypedObjectParameter SmoothSkinningDataParameter; IE_CORE_DECLAREPTR( RenderableParameter ); IE_CORE_DECLAREPTR( StateRenderableParameter ); -IE_CORE_DECLAREPTR( AttributeStateParameter ); IE_CORE_DECLAREPTR( ShaderParameter ); -IE_CORE_DECLAREPTR( TransformParameter ); -IE_CORE_DECLAREPTR( MatrixMotionTransformParameter ); -IE_CORE_DECLAREPTR( MatrixTransformParameter ); IE_CORE_DECLAREPTR( VisibleRenderableParameter ); -IE_CORE_DECLAREPTR( GroupParameter ); IE_CORE_DECLAREPTR( SmoothSkinningDataParameter ); } // namespace IECoreScene diff --git a/src/IECoreGL/ToGLCameraConverter.cpp b/src/IECoreGL/ToGLCameraConverter.cpp index 736bd0d6b9..412bd500c0 100644 --- a/src/IECoreGL/ToGLCameraConverter.cpp +++ b/src/IECoreGL/ToGLCameraConverter.cpp @@ -37,7 +37,6 @@ #include "IECoreGL/Camera.h" #include "IECoreScene/Camera.h" -#include "IECoreScene/Transform.h" #include "IECore/CompoundParameter.h" #include "IECore/Exception.h" diff --git a/src/IECoreScene/AttributeState.cpp b/src/IECoreScene/AttributeState.cpp deleted file mode 100644 index f1892464bc..0000000000 --- a/src/IECoreScene/AttributeState.cpp +++ /dev/null @@ -1,116 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-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 Image Engine Design 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. -// -////////////////////////////////////////////////////////////////////////// - -#include "IECoreScene/AttributeState.h" - -using namespace IECore; -using namespace IECoreScene; -using namespace boost; - -static IndexedIO::EntryID g_attributesEntry("attributes"); -const unsigned int AttributeState::m_ioVersion = 0; -IE_CORE_DEFINEOBJECTTYPEDESCRIPTION( AttributeState ); - -AttributeState::AttributeState( CompoundDataPtr attributes ) - : m_attributes( attributes ? attributes : CompoundDataPtr( new CompoundData() ) ) -{ -} - -AttributeState::AttributeState( const CompoundDataMap &attributes ) - : m_attributes( new CompoundData( attributes ) ) -{ -} - -AttributeState::~AttributeState() -{ -} - -CompoundDataMap &AttributeState::attributes() -{ - return m_attributes->writable(); -} - -const CompoundDataMap &AttributeState::attributes() const -{ - return m_attributes->readable(); -} - -CompoundDataPtr AttributeState::attributesData() -{ - return m_attributes; -} - -bool AttributeState::isEqualTo( const Object *other ) const -{ - if( !StateRenderable::isEqualTo( other ) ) - { - return false; - } - const AttributeState *s = static_cast( other ); - return m_attributes->isEqualTo( s->m_attributes.get() ); -} - -void AttributeState::memoryUsage( Object::MemoryAccumulator &a ) const -{ - StateRenderable::memoryUsage( a ); - a.accumulate( m_attributes.get() ); -} - -void AttributeState::copyFrom( const Object *other, CopyContext *context ) -{ - StateRenderable::copyFrom( other, context ); - const AttributeState *s = static_cast( other ); - m_attributes = context->copy( s->m_attributes.get() ); -} - -void AttributeState::save( SaveContext *context ) const -{ - StateRenderable::save( context ); - IndexedIOPtr container = context->container( staticTypeName(), m_ioVersion ); - context->save( m_attributes.get(), container.get(), g_attributesEntry ); -} - -void AttributeState::load( LoadContextPtr context ) -{ - StateRenderable::load( context ); - unsigned int v = m_ioVersion; - ConstIndexedIOPtr container = context->container( staticTypeName(), v ); - m_attributes = context->load( container.get(), g_attributesEntry ); -} - -void AttributeState::hash( MurmurHash &h ) const -{ - StateRenderable::hash( h ); - m_attributes->hash( h ); -} diff --git a/src/IECoreScene/Group.cpp b/src/IECoreScene/Group.cpp deleted file mode 100644 index 97ad0ac17e..0000000000 --- a/src/IECoreScene/Group.cpp +++ /dev/null @@ -1,449 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-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 Image Engine Design 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. -// -////////////////////////////////////////////////////////////////////////// - -#include "IECoreScene/Group.h" - -#include "IECoreScene/AttributeState.h" - -#include "IECore/MurmurHash.h" - -#include "Imath/ImathBoxAlgo.h" - -#include "boost/format.hpp" -#include "boost/lexical_cast.hpp" - -#include - -using namespace IECore; -using namespace IECoreScene; -using namespace std; -using namespace Imath; - -static IndexedIO::EntryID g_transformEntry("transform"); -static IndexedIO::EntryID g_stateEntry("state"); -static IndexedIO::EntryID g_childrenEntry("children"); -const unsigned int Group::m_ioVersion = 0; - -IE_CORE_DEFINEOBJECTTYPEDESCRIPTION( Group ); - -Group::Group() - : m_transform( nullptr ), m_parent( nullptr ) -{ -} - -Group::~Group() -{ - clearChildren(); -} - -Transform *Group::getTransform() -{ - return m_transform.get(); -} - -const Transform *Group::getTransform() const -{ - return m_transform.get(); -} - -void Group::setTransform( TransformPtr transform ) -{ - m_transform = transform; -} - -Imath::M44f Group::transformMatrix( float time ) const -{ - ConstTransformPtr t = getTransform(); - if( t ) - { - return t->transform( time ); - } - return Imath::M44f(); // identity -} - -Imath::M44f Group::globalTransformMatrix( float time ) const -{ - if( m_parent ) - { - return transformMatrix( time ) * m_parent->globalTransformMatrix( time ); - } - return transformMatrix( time ); -} - -void Group::addState( StateRenderablePtr state ) -{ - if( !state ) - { - throw InvalidArgumentException( "Cannot add null state object." ); - } - if( state->isInstanceOf( Transform::staticTypeId() ) ) - { - throw Exception( "Transforms cannot be added as state." ); - } - m_state.push_back( state ); -} - -void Group::removeState( StateRenderablePtr state ) -{ - StateContainer::iterator it = find( m_state.begin(), m_state.end(), state ); - if( it==m_state.end() ) - { - throw Exception( "State not present in Group" ); - } - m_state.erase( it ); -} - -void Group::clearState() -{ - m_state.clear(); -} - -const Group::StateContainer &Group::state() const -{ - return m_state; -} - -const Data *Group::getAttribute( const std::string &name ) const -{ - StateContainer::const_reverse_iterator it = m_state.rbegin(); - for( ; it != m_state.rend(); ++it ) - { - if( ConstAttributeStatePtr attr = runTimeCast< const AttributeState >( *it ) ) - { - CompoundDataMap::const_iterator attrIt = attr->attributes().find( name ); - if( attrIt != attr->attributes().end() ) - { - return attrIt->second.get(); - } - } - } - - if( m_parent ) - { - return m_parent->getAttribute( name ); - } - - return nullptr; -} - -void Group::setAttribute( const std::string &name, ConstDataPtr value ) -{ - // find existing attribute/override it ? - StateContainer::iterator it = m_state.begin(); - AttributeStatePtr attrFound; - for( ; it != m_state.end(); ++it ) - { - if( AttributeStatePtr attr = runTimeCast< AttributeState >( *it ) ) - { - attrFound = attr; - CompoundDataMap::iterator attrIt = attr->attributes().find( name ); - if( attrIt != attr->attributes().end() ) - { - attr->attributes()[ name ] = value->copy(); - return; - } - } - } - - if( !attrFound ) - { - attrFound = new AttributeState; - addState( attrFound ); - } - - attrFound->attributes()[ name ] = value->copy(); -} - -void Group::addChild( VisibleRenderablePtr child ) -{ - if( !child ) - { - throw InvalidArgumentException( "Cannot add null child object." ); - } - - GroupPtr gChild = runTimeCast( child ); - if( gChild ) - { - GroupPtr gChildParent = gChild->parent(); - if( gChildParent ) - { - gChildParent->removeChild( gChild ); - } - gChild->m_parent = this; - } - m_children.push_back( child ); -} - -void Group::removeChild( VisibleRenderablePtr child ) -{ - ChildContainer::iterator it = find( m_children.begin(), m_children.end(), child ); - - if( it==m_children.end() ) - { - throw Exception( "Child is not a member of Group" ); - } - - GroupPtr gChild = runTimeCast( child ); - if( gChild ) - { - gChild->m_parent = nullptr; - } - - m_children.erase( it ); -} - -void Group::clearChildren() -{ - while( m_children.size() ) - { - removeChild( m_children[0] ); - } -} - -const Group::ChildContainer &Group::children() const -{ - return m_children; -} - -Group *Group::parent() -{ - return m_parent; -} - -const Group *Group::parent() const -{ - return m_parent; -} - -void Group::copyFrom( const Object *other, CopyContext *context ) -{ - VisibleRenderable::copyFrom( other, context ); - const Group *tOther = static_cast( other ); - if( tOther->m_transform ) - { - m_transform = context->copy( tOther->m_transform.get() ); - } - else - { - m_transform = nullptr; - } - clearState(); - for( StateContainer::const_iterator it=tOther->state().begin(); it!=tOther->state().end(); it++ ) - { - addState( context->copy( it->get() ) ); - } - clearChildren(); - for( ChildContainer::const_iterator it=tOther->children().begin(); it!=tOther->children().end(); it++ ) - { - addChild( context->copy( it->get() ) ); - } -} - -void Group::save( SaveContext *context ) const -{ - VisibleRenderable::save( context ); - IndexedIOPtr container = context->container( staticTypeName(), m_ioVersion ); - if( m_transform ) - { - context->save( m_transform.get(), container.get(), g_transformEntry ); - } - IndexedIOPtr stateContainer = container->subdirectory( g_stateEntry, IndexedIO::CreateIfMissing ); - int i = 0; - for( StateContainer::const_iterator it=state().begin(); it!=state().end(); it++ ) - { - string name = str( boost::format( "%d" ) % i ); - context->save( it->get(), stateContainer.get(), name ); - i++; - } - IndexedIOPtr childrenContainer = container->subdirectory( g_childrenEntry, IndexedIO::CreateIfMissing ); - i = 0; - for( ChildContainer::const_iterator it = children().begin(); it!=children().end(); it++ ) - { - string name = str( boost::format( "%d" ) % i ); - context->save( it->get(), childrenContainer.get(), name ); - i++; - } -} - -bool Group::entryListCompare( const IndexedIO::EntryID& a, const IndexedIO::EntryID& b ) -{ - int a_idx( 0 ); - int b_idx( 0 ); - - try - { - a_idx = boost::lexical_cast( a.value() ); - } - catch (...) - { - } - try - { - b_idx = boost::lexical_cast( b.value() ); - } - catch (...) - { - } - - return a_idx < b_idx; -} - -void Group::load( LoadContextPtr context ) -{ - VisibleRenderable::load( context ); - unsigned int v = m_ioVersion; - - ConstIndexedIOPtr container = context->container( staticTypeName(), v ); - m_transform = nullptr; - try - { - m_transform = context->load( container.get(), g_transformEntry ); - } - catch( ... ) - { - } - clearState(); - - ConstIndexedIOPtr stateContainer = container->subdirectory( g_stateEntry ); - IndexedIO::EntryIDList l; - stateContainer->entryIds( l ); - sort( l.begin(), l.end(), entryListCompare ); - for( IndexedIO::EntryIDList::const_iterator it=l.begin(); it!=l.end(); it++ ) - { - addState( context->load( stateContainer.get(), *it ) ); - } - clearChildren(); - ConstIndexedIOPtr childrenContainer = container->subdirectory( g_childrenEntry ); - childrenContainer->entryIds( l ); - sort( l.begin(), l.end(), entryListCompare ); - for( IndexedIO::EntryIDList::const_iterator it=l.begin(); it!=l.end(); it++ ) - { - addChild( context->load( childrenContainer.get(), *it ) ); - } -} - -bool Group::isEqualTo( const Object *other ) const -{ - if( !VisibleRenderable::isEqualTo( other ) ) - { - return false; - } - - const Group *tOther = static_cast( other ); - - // check transform - if( (bool)m_transform != (bool)tOther->m_transform ) - { - return false; - } - - if( m_transform && !tOther->m_transform->isEqualTo( m_transform.get() ) ) - { - return false; - } - - // check state - if( m_state.size()!=tOther->m_state.size() ) - { - return false; - } - for( size_t i=0; iisEqualTo( tOther->m_state[i].get() ) ) - { - return false; - } - } - - // check children - if( m_children.size()!=tOther->m_children.size() ) - { - return false; - } - for( size_t i=0; iisEqualTo( tOther->m_children[i].get() ) ) - { - return false; - } - } - - return true; -} - -void Group::memoryUsage( Object::MemoryAccumulator &a ) const -{ - VisibleRenderable::memoryUsage( a ); - if( m_transform ) - { - a.accumulate( m_transform.get() ); - } - for( StateContainer::const_iterator it=state().begin(); it!=state().end(); it++ ) - { - a.accumulate( it->get() ); - } - for( ChildContainer::const_iterator it=children().begin(); it!=children().end(); it++ ) - { - a.accumulate( it->get() ); - } -} - -void Group::hash( MurmurHash &h ) const -{ - VisibleRenderable::hash( h ); - if( m_transform ) - { - m_transform->hash( h ); - } - - for( StateContainer::const_iterator it=state().begin(); it!=state().end(); it++ ) - { - (*it)->hash( h ); - } - - for( ChildContainer::const_iterator it=children().begin(); it!=children().end(); it++ ) - { - (*it)->hash( h ); - } -} - -Imath::Box3f Group::bound() const -{ - Box3f result; - for( ChildContainer::const_iterator it=children().begin(); it!=children().end(); it++ ) - { - result.extendBy( (*it)->bound() ); - } - return transform( result, transformMatrix() ); -} diff --git a/src/IECoreScene/MatrixMotionTransform.cpp b/src/IECoreScene/MatrixMotionTransform.cpp deleted file mode 100644 index db9ed78606..0000000000 --- a/src/IECoreScene/MatrixMotionTransform.cpp +++ /dev/null @@ -1,166 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-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 Image Engine Design 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. -// -////////////////////////////////////////////////////////////////////////// - -#include "IECoreScene/MatrixMotionTransform.h" - -#include "IECore/MurmurHash.h" - -#include "Imath/ImathFun.h" - -#include "boost/format.hpp" - -using namespace IECore; -using namespace IECoreScene; -using namespace boost; -using namespace std; -using namespace Imath; - -static IndexedIO::EntryID g_snapshotsEntry("snapshots"); -static IndexedIO::EntryID g_timeEntry("time"); -static IndexedIO::EntryID g_matrixEntry("matrix"); - -const unsigned int MatrixMotionTransform::m_ioVersion = 0; -IE_CORE_DEFINEOBJECTTYPEDESCRIPTION(MatrixMotionTransform); - -MatrixMotionTransform::MatrixMotionTransform() -{ -} - -MatrixMotionTransform::~MatrixMotionTransform() -{ -} - -Imath::M44f MatrixMotionTransform::transform( float time ) const -{ - if( !m_snapshots.size() ) - { - return M44f(); - } - if( m_snapshots.size()==1 || time <= m_snapshots.begin()->first ) - { - return m_snapshots.begin()->second; - } - if( time >= m_snapshots.rbegin()->first ) - { - return m_snapshots.rbegin()->second; - } - SnapshotMap::const_iterator uIt = m_snapshots.upper_bound( time ); - SnapshotMap::const_iterator lIt = uIt; - lIt--; - - /// \todo We should probably do something to interpolate rotations better. - return lerp( lIt->second, uIt->second, lerpfactor( time, lIt->first, uIt->first ) ); -} - -const MatrixMotionTransform::SnapshotMap &MatrixMotionTransform::snapshots() const -{ - return m_snapshots; -} - -MatrixMotionTransform::SnapshotMap &MatrixMotionTransform::snapshots() -{ - return m_snapshots; -} - -void MatrixMotionTransform::copyFrom( const Object *other, CopyContext *context ) -{ - Transform::copyFrom( other, context ); - const MatrixMotionTransform *t = static_cast( other ); - m_snapshots = t->m_snapshots; -} - -void MatrixMotionTransform::save( SaveContext *context ) const -{ - Transform::save( context ); - IndexedIOPtr container = context->container( staticTypeName(), m_ioVersion ); - container = container->subdirectory( g_snapshotsEntry, IndexedIO::CreateIfMissing ); - int i = 0; - for( SnapshotMap::const_iterator it=m_snapshots.begin(); it!=m_snapshots.end(); it++ ) - { - string is = str( boost::format( "%d" ) % i ); - IndexedIOPtr snapshotContainer = container->subdirectory( is, IndexedIO::CreateIfMissing ); - snapshotContainer->write( g_timeEntry, it->first ); - snapshotContainer->write( g_matrixEntry, it->second.getValue(), 16 ); - i++; - } -} - -void MatrixMotionTransform::load( LoadContextPtr context ) -{ - Transform::load( context ); - unsigned int v = m_ioVersion; - - ConstIndexedIOPtr container = context->container( staticTypeName(), v ); - container = container->subdirectory( g_snapshotsEntry ); - m_snapshots.clear(); - IndexedIO::EntryIDList names; - container->entryIds( names, IndexedIO::Directory ); - IndexedIO::EntryIDList::const_iterator it; - for( it=names.begin(); it!=names.end(); it++ ) - { - ConstIndexedIOPtr snapshotContainer = container->subdirectory( *it ); - float t; snapshotContainer->read( g_timeEntry, t ); - M44f m; - float *f = m.getValue(); - snapshotContainer->read( g_matrixEntry, f, 16 ); - m_snapshots[t] = m; - } -} - -bool MatrixMotionTransform::isEqualTo( const Object *other ) const -{ - if( !Transform::isEqualTo( other ) ) - { - return false; - } - const MatrixMotionTransform *t = static_cast( other ); - return m_snapshots == t->m_snapshots; -} - -void MatrixMotionTransform::memoryUsage( Object::MemoryAccumulator &a ) const -{ - Transform::memoryUsage( a ); - a.accumulate( sizeof( M44f ) * m_snapshots.size() ); - a.accumulate( sizeof( float ) * m_snapshots.size() ); -} - -void MatrixMotionTransform::hash( MurmurHash &h ) const -{ - Transform::hash( h ); - for( SnapshotMap::const_iterator it=m_snapshots.begin(); it!=m_snapshots.end(); it++ ) - { - h.append( it->first ); - h.append( it->second ); - } -} diff --git a/src/IECoreScene/MatrixTransform.cpp b/src/IECoreScene/MatrixTransform.cpp deleted file mode 100644 index 1c28c7d434..0000000000 --- a/src/IECoreScene/MatrixTransform.cpp +++ /dev/null @@ -1,104 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-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 Image Engine Design 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. -// -////////////////////////////////////////////////////////////////////////// - -#include "IECoreScene/MatrixTransform.h" - -#include "IECore/MurmurHash.h" - -using namespace IECore; -using namespace IECoreScene; -using namespace boost; - -static IndexedIO::EntryID g_matrixEntry("matrix"); -const unsigned int MatrixTransform::m_ioVersion = 0; -IE_CORE_DEFINEOBJECTTYPEDESCRIPTION(MatrixTransform); - -MatrixTransform::MatrixTransform( const Imath::M44f &m ) - : matrix( m ) -{ -} - -MatrixTransform::~MatrixTransform() -{ -} - -Imath::M44f MatrixTransform::transform( float time ) const -{ - return matrix; -} - -void MatrixTransform::copyFrom( const Object *other, CopyContext *context ) -{ - Transform::copyFrom( other, context ); - const MatrixTransform *t = static_cast( other ); - matrix = t->matrix; -} - -void MatrixTransform::save( SaveContext *context ) const -{ - Transform::save( context ); - IndexedIOPtr container = context->container( staticTypeName(), m_ioVersion ); - container->write( g_matrixEntry, matrix.getValue(), 16 ); -} - -void MatrixTransform::load( LoadContextPtr context ) -{ - Transform::load( context ); - unsigned int v = m_ioVersion; - ConstIndexedIOPtr container = context->container( staticTypeName(), v ); - float *f = matrix.getValue(); - container->read( g_matrixEntry, f, 16 ); -} - -bool MatrixTransform::isEqualTo( const Object *other ) const -{ - if( !Transform::isEqualTo( other ) ) - { - return false; - } - const MatrixTransform *t = static_cast( other ); - return matrix == t->matrix; -} - -void MatrixTransform::memoryUsage( Object::MemoryAccumulator &a ) const -{ - Transform::memoryUsage( a ); - a.accumulate( sizeof( matrix ) ); -} - -void MatrixTransform::hash( MurmurHash &h ) const -{ - Transform::hash( h ); - h.append( matrix ); -} diff --git a/src/IECoreScene/Transform.cpp b/src/IECoreScene/Transform.cpp deleted file mode 100644 index fe5dd6749e..0000000000 --- a/src/IECoreScene/Transform.cpp +++ /dev/null @@ -1,83 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2011, 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 Image Engine Design 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. -// -////////////////////////////////////////////////////////////////////////// - -#include "IECoreScene/Transform.h" - -using namespace IECore; -using namespace IECoreScene; - -const unsigned int Transform::m_ioVersion = 0; -IE_CORE_DEFINEOBJECTTYPEDESCRIPTION(Transform); - -Transform::Transform() -{ -} - -Transform::~Transform() -{ -} - -void Transform::copyFrom( const Object *other, CopyContext *context ) -{ - StateRenderable::copyFrom( other, context ); -} - -void Transform::save( SaveContext *context ) const -{ - StateRenderable::save( context ); -} - -void Transform::load( LoadContextPtr context ) -{ - StateRenderable::load( context ); -} - -bool Transform::isEqualTo( const Object *other ) const -{ - if( !StateRenderable::isEqualTo( other ) ) - { - return false; - } - return true; -} - -void Transform::memoryUsage( Object::MemoryAccumulator &a ) const -{ - StateRenderable::memoryUsage( a ); -} - -void Transform::hash( MurmurHash &h ) const -{ - StateRenderable::hash( h ); -} diff --git a/src/IECoreScene/TypedObjectParameter.cpp b/src/IECoreScene/TypedObjectParameter.cpp index ea2e6c8107..97c750ca4e 100644 --- a/src/IECoreScene/TypedObjectParameter.cpp +++ b/src/IECoreScene/TypedObjectParameter.cpp @@ -34,15 +34,10 @@ #include "IECoreScene/TypedObjectParameter.h" -#include "IECoreScene/AttributeState.h" -#include "IECoreScene/Group.h" -#include "IECoreScene/MatrixMotionTransform.h" -#include "IECoreScene/MatrixTransform.h" #include "IECoreScene/Renderable.h" #include "IECoreScene/Shader.h" #include "IECoreScene/SmoothSkinningData.h" #include "IECoreScene/StateRenderable.h" -#include "IECoreScene/Transform.h" #include "IECoreScene/VisibleRenderable.h" #include "IECore/TypedObjectParameter.inl" @@ -52,24 +47,14 @@ namespace IECore IECORE_RUNTIMETYPED_DEFINETEMPLATESPECIALISATION( IECoreScene::RenderableParameter, IECoreScene::RenderableParameterTypeId ); IECORE_RUNTIMETYPED_DEFINETEMPLATESPECIALISATION( IECoreScene::StateRenderableParameter, IECoreScene::StateRenderableParameterTypeId ); -IECORE_RUNTIMETYPED_DEFINETEMPLATESPECIALISATION( IECoreScene::AttributeStateParameter, IECoreScene::AttributeStateParameterTypeId ); IECORE_RUNTIMETYPED_DEFINETEMPLATESPECIALISATION( IECoreScene::ShaderParameter, IECoreScene::ShaderParameterTypeId ); -IECORE_RUNTIMETYPED_DEFINETEMPLATESPECIALISATION( IECoreScene::TransformParameter, IECoreScene::TransformParameterTypeId ); -IECORE_RUNTIMETYPED_DEFINETEMPLATESPECIALISATION( IECoreScene::MatrixMotionTransformParameter, IECoreScene::MatrixMotionTransformParameterTypeId ); -IECORE_RUNTIMETYPED_DEFINETEMPLATESPECIALISATION( IECoreScene::MatrixTransformParameter, IECoreScene::MatrixTransformParameterTypeId ); IECORE_RUNTIMETYPED_DEFINETEMPLATESPECIALISATION( IECoreScene::VisibleRenderableParameter, IECoreScene::VisibleRenderableParameterTypeId ); -IECORE_RUNTIMETYPED_DEFINETEMPLATESPECIALISATION( IECoreScene::GroupParameter, IECoreScene::GroupParameterTypeId ); IECORE_RUNTIMETYPED_DEFINETEMPLATESPECIALISATION( IECoreScene::SmoothSkinningDataParameter, IECoreScene::SmoothSkinningDataParameterTypeId ); template class TypedObjectParameter; template class TypedObjectParameter; -template class TypedObjectParameter; template class TypedObjectParameter; -template class TypedObjectParameter; -template class TypedObjectParameter; -template class TypedObjectParameter; template class TypedObjectParameter; -template class TypedObjectParameter; template class TypedObjectParameter; } diff --git a/src/IECoreScene/bindings/AttributeStateBinding.cpp b/src/IECoreScene/bindings/AttributeStateBinding.cpp deleted file mode 100644 index 9e793a5fe8..0000000000 --- a/src/IECoreScene/bindings/AttributeStateBinding.cpp +++ /dev/null @@ -1,58 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2010, 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 Image Engine Design 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. -// -////////////////////////////////////////////////////////////////////////// - -#include "boost/python.hpp" - -#include "AttributeStateBinding.h" - -#include "IECoreScene/AttributeState.h" - -#include "IECorePython/RunTimeTypedBinding.h" - -using namespace boost::python; -using namespace IECore; -using namespace IECorePython; -using namespace IECoreScene; - -namespace IECoreSceneModule -{ - void bindAttributeState() - { - RunTimeTypedClass( "AttributeState" ) - .def( init<>() ) - .def( init() ) - .add_property( "attributes", &AttributeState::attributesData ) - ; - } -} diff --git a/src/IECoreScene/bindings/AttributeStateBinding.h b/src/IECoreScene/bindings/AttributeStateBinding.h deleted file mode 100644 index b3daf39487..0000000000 --- a/src/IECoreScene/bindings/AttributeStateBinding.h +++ /dev/null @@ -1,45 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2010, 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 Image Engine Design 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 IECORESCENEMODULE_ATTRIBUTESTATEBINDING_H -#define IECORESCENEMODULE_ATTRIBUTESTATEBINDING_H - -namespace IECoreSceneModule -{ - -void bindAttributeState(); - -} // namespace IECoreSceneModule - -#endif // IECORESCENEMODULE_ATTRIBUTESTATEBINDING_H diff --git a/src/IECoreScene/bindings/GroupBinding.cpp b/src/IECoreScene/bindings/GroupBinding.cpp deleted file mode 100644 index aa9d002688..0000000000 --- a/src/IECoreScene/bindings/GroupBinding.cpp +++ /dev/null @@ -1,113 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2010, 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 Image Engine Design 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. -// -////////////////////////////////////////////////////////////////////////// - -// This include needs to be the very first to prevent problems with warnings -// regarding redefinition of _POSIX_C_SOURCE -#include "boost/python.hpp" - -#include "GroupBinding.h" - -#include "IECoreScene/Group.h" - -#include "IECorePython/RunTimeTypedBinding.h" -#include "IECorePython/ScopedGILRelease.h" - -using namespace boost::python; -using namespace IECore; -using namespace IECorePython; -using namespace IECoreScene; - -namespace IECoreSceneModule -{ - -/// \todo: this should return a tuple rather than a list -static list children( Group &g ) -{ - list result; - for( Group::ChildContainer::const_iterator it=g.children().begin(); it!=g.children().end(); it++ ) - { - result.append( *it ); - } - return result; -} - -/// \todo: this should return a tuple rather than a list -static list state( Group &g ) -{ - list result; - for( Group::StateContainer::const_iterator it=g.state().begin(); it!=g.state().end(); it++ ) - { - result.append( *it ); - } - return result; -} - -static DataPtr getAttribute( Group &g, const std::string &name ) -{ - ConstDataPtr d = g.getAttribute( name ); - if( d ) - { - return d->copy(); - } - return nullptr; -} - - - -BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( transformMatrixOverloads, transformMatrix, 0, 1 ); -BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( globalTransformMatrixOverloads, globalTransformMatrix, 0, 1 ); - -void bindGroup() -{ - RunTimeTypedClass() - .def( init<>() ) - .def( "children", &children, "Returns all the children in a list - note that modifying the list will not add or remove children." ) - .def( "addChild", &Group::addChild ) - .def( "removeChild", &Group::removeChild ) - .def( "clearChildren", &Group::clearChildren ) - .def( "state", &state, "Returns all the state in a list - note that modifying the list will not add or remove state." ) - .def( "addState", &Group::addState ) - .def( "removeState", &Group::removeState ) - .def( "clearState", &Group::clearState ) - .def( "setAttribute", &Group::setAttribute ) - .def( "getAttribute", &getAttribute, "Returns a copy of the internal attribute data." ) - .def( "getTransform", (Transform *(Group::*)())&Group::getTransform, return_value_policy() ) - .def( "setTransform", &Group::setTransform ) - .def( "transformMatrix", &Group::transformMatrix, transformMatrixOverloads() ) - .def( "globalTransformMatrix", &Group::globalTransformMatrix, globalTransformMatrixOverloads() ) - .def( "parent", (Group *(Group::*)())&Group::parent, return_value_policy() ) - ; -} - -} diff --git a/src/IECoreScene/bindings/GroupBinding.h b/src/IECoreScene/bindings/GroupBinding.h deleted file mode 100644 index 0c025a94cb..0000000000 --- a/src/IECoreScene/bindings/GroupBinding.h +++ /dev/null @@ -1,43 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2010, 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 Image Engine Design 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 IECORESCENEMODULE_GROUPBINDING_H -#define IECORESCENEMODULE_GROUPBINDING_H - -namespace IECoreSceneModule -{ -void bindGroup(); -} - -#endif // IECORESCENEMODULE_GROUPBINDING_H diff --git a/src/IECoreScene/bindings/IECoreScene.cpp b/src/IECoreScene/bindings/IECoreScene.cpp index c86d6110a6..6b607ca2a0 100644 --- a/src/IECoreScene/bindings/IECoreScene.cpp +++ b/src/IECoreScene/bindings/IECoreScene.cpp @@ -35,7 +35,6 @@ #include "boost/python.hpp" #include "AddSmoothSkinningInfluencesOpBinding.h" -#include "AttributeStateBinding.h" #include "CameraBinding.h" #include "ClippingPlaneBinding.h" #include "CompressSmoothSkinningDataOpBinding.h" @@ -52,12 +51,9 @@ #include "ExternalProceduralBinding.h" #include "FaceVaryingPromotionOpBinding.h" #include "FontBinding.h" -#include "GroupBinding.h" #include "LightBinding.h" #include "LimitSmoothSkinningInfluencesOpBinding.h" #include "LinkedSceneBinding.h" -#include "MatrixMotionTransformBinding.h" -#include "MatrixTransformBinding.h" #include "MeshAlgoBinding.h" #include "MeshMergeOpBinding.h" #include "MeshNormalsOpBinding.h" @@ -103,7 +99,6 @@ #include "SpherePrimitiveEvaluatorBinding.h" #include "StateRenderableBinding.h" #include "TransferSmoothSkinningWeightsOpBinding.h" -#include "TransformBinding.h" #include "TransformOpBinding.h" #include "TriangulateOpBinding.h" #include "TriangulatorBinding.h" @@ -136,11 +131,6 @@ BOOST_PYTHON_MODULE(_IECoreScene) bindPrimitiveOp(); bindMeshPrimitive(); bindMotionPrimitive(); - bindTransform(); - bindMatrixTransform(); - bindMatrixMotionTransform(); - bindGroup(); - bindAttributeState(); bindPreWorldRenderable(); bindCamera(); bindNURBSPrimitive(); diff --git a/src/IECoreScene/bindings/MatrixMotionTransformBinding.cpp b/src/IECoreScene/bindings/MatrixMotionTransformBinding.cpp deleted file mode 100644 index 9254444e86..0000000000 --- a/src/IECoreScene/bindings/MatrixMotionTransformBinding.cpp +++ /dev/null @@ -1,125 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2010, 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 Image Engine Design 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. -// -////////////////////////////////////////////////////////////////////////// - -#include "boost/python.hpp" - -#include "MatrixMotionTransformBinding.h" - -#include "IECoreScene/MatrixMotionTransform.h" - -#include "IECorePython/RunTimeTypedBinding.h" - -using namespace boost::python; -using namespace Imath; -using namespace IECorePython; -using namespace IECoreScene; - -namespace IECoreSceneModule -{ - -static unsigned int len( MatrixMotionTransform &p ) -{ - return p.snapshots().size(); -} - -static M44f getItem( MatrixMotionTransform &p, float t ) -{ - MatrixMotionTransform::SnapshotMap::const_iterator it = p.snapshots().find( t ); - if( it==p.snapshots().end() ) - { - throw std::out_of_range( "Bad index" ); - } - return it->second; -} - -static void setItem( MatrixMotionTransform &p, float t, const Imath::M44f &v ) -{ - p.snapshots()[t] = v; -} - -static bool contains( MatrixMotionTransform &p, float t ) -{ - return p.snapshots().find( t )!=p.snapshots().end(); -} - -static void delItem( MatrixMotionTransform &p, float t ) -{ - MatrixMotionTransform::SnapshotMap::iterator it = p.snapshots().find( t ); - if( it==p.snapshots().end() ) - { - throw std::out_of_range( "Bad index" ); - } - p.snapshots().erase( it ); -} - -static boost::python::list keys( MatrixMotionTransform &p ) -{ - boost::python::list result; - const MatrixMotionTransform::SnapshotMap &s = p.snapshots(); - MatrixMotionTransform::SnapshotMap::const_iterator it; - for( it = s.begin(); it!=s.end(); it++ ) - { - result.append( it->first ); - } - return result; -} - -static boost::python::list values( MatrixMotionTransform &p ) -{ - boost::python::list result; - const MatrixMotionTransform::SnapshotMap &s = p.snapshots(); - MatrixMotionTransform::SnapshotMap::const_iterator it; - for( it = s.begin(); it!=s.end(); it++ ) - { - result.append( it->second ); - } - return result; -} - - -void bindMatrixMotionTransform() -{ - RunTimeTypedClass() - .def( init<>() ) - .def( "__len__", &len ) - .def( "__getitem__", &getItem ) - .def( "__setitem__", &setItem ) - .def( "__delitem__", &delItem ) - .def( "__contains__", &contains ) - .def( "keys", &keys ) - .def( "values", &values ) - ; -} - -} diff --git a/src/IECoreScene/bindings/MatrixMotionTransformBinding.h b/src/IECoreScene/bindings/MatrixMotionTransformBinding.h deleted file mode 100644 index 42c432e29f..0000000000 --- a/src/IECoreScene/bindings/MatrixMotionTransformBinding.h +++ /dev/null @@ -1,43 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2010, 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 Image Engine Design 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 IECORESCENEMODULE_MATRIXMOTIONTRANSFORMBINDING_H -#define IECORESCENEMODULE_MATRIXMOTIONTRANSFORMBINDING_H - -namespace IECoreSceneModule -{ -void bindMatrixMotionTransform(); -} - -#endif // IECORESCENEMODULE_MATRIXMOTIONTRANSFORMBINDING_H diff --git a/src/IECoreScene/bindings/MatrixTransformBinding.cpp b/src/IECoreScene/bindings/MatrixTransformBinding.cpp deleted file mode 100644 index 00293d06d9..0000000000 --- a/src/IECoreScene/bindings/MatrixTransformBinding.cpp +++ /dev/null @@ -1,60 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2010, 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 Image Engine Design 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. -// -////////////////////////////////////////////////////////////////////////// - -// This include needs to be the very first to prevent problems with warnings -// regarding redefinition of _POSIX_C_SOURCE -#include "boost/python.hpp" - -#include "MatrixTransformBinding.h" - -#include "IECoreScene/MatrixTransform.h" - -#include "IECorePython/RunTimeTypedBinding.h" - -using namespace boost::python; -using namespace IECorePython; -using namespace IECoreScene; - -namespace IECoreSceneModule -{ - -void bindMatrixTransform() -{ - RunTimeTypedClass() - .def( init() ) - .def_readwrite("matrix", &MatrixTransform::matrix) - ; -} - -} diff --git a/src/IECoreScene/bindings/MatrixTransformBinding.h b/src/IECoreScene/bindings/MatrixTransformBinding.h deleted file mode 100644 index 54a72150a0..0000000000 --- a/src/IECoreScene/bindings/MatrixTransformBinding.h +++ /dev/null @@ -1,43 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2010, 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 Image Engine Design 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 IECORESCENEMODULE_MATRIXTRANSFORMBINDING_H -#define IECORESCENEMODULE_MATRIXTRANSFORMBINDING_H - -namespace IECoreSceneModule -{ -void bindMatrixTransform(); -} - -#endif // IECORESCENEMODULE_MATRIXTRANSFORMBINDING_H diff --git a/src/IECoreScene/bindings/TransformBinding.cpp b/src/IECoreScene/bindings/TransformBinding.cpp deleted file mode 100644 index eddeae4a53..0000000000 --- a/src/IECoreScene/bindings/TransformBinding.cpp +++ /dev/null @@ -1,61 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2010, 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 Image Engine Design 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. -// -////////////////////////////////////////////////////////////////////////// - -// This include needs to be the very first to prevent problems with warnings -// regarding redefinition of _POSIX_C_SOURCE -#include "boost/python.hpp" - -#include "TransformBinding.h" - -#include "IECoreScene/Transform.h" - -#include "IECorePython/RunTimeTypedBinding.h" - -using namespace boost::python; -using namespace IECorePython; -using namespace IECoreScene; - -namespace IECoreSceneModule -{ - -BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(transformOverloads, transform, 0, 1); - -void bindTransform() -{ - RunTimeTypedClass() - .def("transform", &Transform::transform, transformOverloads() ) - ; -} - -} diff --git a/src/IECoreScene/bindings/TransformBinding.h b/src/IECoreScene/bindings/TransformBinding.h deleted file mode 100644 index 2f28595c3c..0000000000 --- a/src/IECoreScene/bindings/TransformBinding.h +++ /dev/null @@ -1,43 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2010, 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 Image Engine Design 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 IECORESCENEMODULE_TRANSFORMBINDING_H -#define IECORESCENEMODULE_TRANSFORMBINDING_H - -namespace IECoreSceneModule -{ -void bindTransform(); -} - -#endif // IECORESCENEMODULE_TRANSFORMBINDING_H diff --git a/src/IECoreScene/bindings/TypedObjectParameterBinding.cpp b/src/IECoreScene/bindings/TypedObjectParameterBinding.cpp index 49b51eb7a2..dd25d249a5 100644 --- a/src/IECoreScene/bindings/TypedObjectParameterBinding.cpp +++ b/src/IECoreScene/bindings/TypedObjectParameterBinding.cpp @@ -40,13 +40,8 @@ #include "IECoreScene/TypedPrimitiveParameter.h" #include "IECoreScene/Renderable.h" #include "IECoreScene/StateRenderable.h" -#include "IECoreScene/AttributeState.h" #include "IECoreScene/Shader.h" -#include "IECoreScene/Transform.h" -#include "IECoreScene/MatrixMotionTransform.h" -#include "IECoreScene/MatrixTransform.h" #include "IECoreScene/VisibleRenderable.h" -#include "IECoreScene/Group.h" #include "IECoreScene/SmoothSkinningData.h" #include "IECoreScene/MotionPrimitive.h" #include "IECoreScene/Primitive.h" @@ -96,13 +91,8 @@ void IECoreSceneModule::bindTypedObjectParameter() { ::bindTypedObjectParameter(); ::bindTypedObjectParameter(); - ::bindTypedObjectParameter(); ::bindTypedObjectParameter(); - ::bindTypedObjectParameter(); - ::bindTypedObjectParameter(); - ::bindTypedObjectParameter(); ::bindTypedObjectParameter(); - ::bindTypedObjectParameter(); ::bindTypedObjectParameter(); ::bindTypedObjectParameter(); diff --git a/test/IECoreScene/All.py b/test/IECoreScene/All.py index f45327a838..2d6e773c47 100644 --- a/test/IECoreScene/All.py +++ b/test/IECoreScene/All.py @@ -50,8 +50,6 @@ from RemovePrimitiveVariables import * from RenamePrimitiveVariables import * from MotionPrimitive import * -from Transform import * -from Group import * from Camera import * from NURBS import * from PrimitiveEvaluator import * @@ -66,7 +64,6 @@ from PrimitiveTest import * from MeshMergeOpTest import * from MeshVertexReorderOpTest import * -from AttributeStateTest import * from CoordinateSystemTest import * from OutputTest import OutputTest from PatchMeshPrimitiveTest import * diff --git a/test/IECoreScene/AttributeStateTest.py b/test/IECoreScene/AttributeStateTest.py deleted file mode 100644 index a314230206..0000000000 --- a/test/IECoreScene/AttributeStateTest.py +++ /dev/null @@ -1,75 +0,0 @@ -########################################################################## -# -# Copyright (c) 2008-2011, 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 Image Engine Design 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 IECoreScene - -class AttributeStateTest( unittest.TestCase ) : - - def testCopy( self ) : - - a = IECoreScene.AttributeState() - a.attributes["test"] = IECore.FloatData( 10 ) - - aa = a.copy() - self.assertEqual( a, aa ) - - def testConstructFromDict( self ) : - - a = IECoreScene.AttributeState( { - "a" : IECore.StringData( "a" ), - "b" : IECore.IntData( 10 ), - } ) - - self.assertEqual( len( a.attributes ), 2 ) - self.assertEqual( a.attributes["a"], IECore.StringData( "a" ) ) - self.assertEqual( a.attributes["b"], IECore.IntData( 10 ) ) - - def testHash( self ) : - - a1 = IECoreScene.AttributeState() - a2 = IECoreScene.AttributeState() - - self.assertEqual( a1.hash(), a2.hash() ) - - a1.attributes["a"] = IECore.StringData( "a" ) - self.assertNotEqual( a1.hash(), a2.hash() ) - - a2.attributes["a"] = IECore.StringData( "a" ) - self.assertEqual( a1.hash(), a2.hash() ) - -if __name__ == "__main__": - unittest.main() diff --git a/test/IECoreScene/Group.py b/test/IECoreScene/Group.py deleted file mode 100644 index 640f3cdb62..0000000000 --- a/test/IECoreScene/Group.py +++ /dev/null @@ -1,325 +0,0 @@ -########################################################################## -# -# Copyright (c) 2007-2010, 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 Image Engine Design 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 sys -import unittest -import imath -import IECore -import IECoreScene - -class TestGroup( unittest.TestCase ) : - - def test( self ) : - - g = IECoreScene.Group() - self.assertEqual( g.getTransform(), None ) - self.assertEqual( g.transformMatrix(), imath.M44f() ) - - g.setTransform( IECoreScene.MatrixTransform( imath.M44f().scale( imath.V3f( 2 ) ) ) ) - self.assertEqual( g.getTransform(), IECoreScene.MatrixTransform( imath.M44f().scale( imath.V3f( 2 ) ) ) ) - self.assertEqual( g.transformMatrix(), imath.M44f().scale( imath.V3f( 2 ) ) ) - - self.assertEqual( g.children(), [] ) - self.assertEqual( g.state(), [] ) - - # modifying children has no effect on the primitive - children() - # returns the internal set copied into a list - g.children().append( IECoreScene.PointsPrimitive( 1 ) ) - self.assertEqual( g.children(), [] ) - - g.addChild( IECoreScene.PointsPrimitive( 1 ) ) - self.assertEqual( g.children(), [ IECoreScene.PointsPrimitive( 1 ) ] ) - - # modifying state has no effect on the primitive - state() - # returns the internal set copied into a list - g.state().append( IECoreScene.AttributeState() ) - self.assertEqual( g.state(), [] ) - - g.addState( IECoreScene.AttributeState() ) - self.assertEqual( g.state(), [ IECoreScene.AttributeState() ] ) - - self.assertEqual( g, g ) - - gg = g.copy() - self.assertEqual( g, gg ) - self.assertTrue( not gg.children()[0].isSame( g.children()[0] ) ) - self.assertTrue( not gg.state()[0].isSame( g.state()[0] ) ) - - IECore.ObjectWriter( g, os.path.join( "test", "group.cob" ) ).write() - - ggg = IECore.ObjectReader( os.path.join( "test", "group.cob" ) ).read() - - self.assertEqual( gg, ggg ) - self.assertTrue( not gg.children()[0].isSame(ggg.children()[0] ) ) - self.assertTrue( not gg.state()[0].isSame(ggg.state()[0] ) ) - - def testStateAndChildOrder( self ) : - - # check the state/children don't get reordered when a group is written out to disk - # and read back in again: - g = IECoreScene.Group() - - for i in range( 100 ): - g.addState( IECoreScene.Shader("%d" % i,"ddyup") ) - - child = IECoreScene.Group() - child.blindData()["id"] = IECore.IntData( i ) - g.addChild( child ) - - IECore.ObjectWriter( g, os.path.join( "test", "group.cob" ) ).write() - - ggg = IECore.ObjectReader( os.path.join( "test", "group.cob" ) ).read() - - for i in range( 100 ): - - self.assertEqual( g.state()[i].name, ggg.state()[i].name ) - self.assertEqual( g.children()[i].blindData()["id"].value, ggg.children()[i].blindData()["id"].value ) - - - - def testParent( self ) : - - g = IECoreScene.Group() - g2 = IECoreScene.Group() - - self.assertTrue( g.parent() is None ) - self.assertTrue( g2.parent() is None ) - - g.addChild( g2 ) - - self.assertTrue( g.parent() is None ) - self.assertTrue( g2.parent().isSame( g ) ) - - g.removeChild( g2 ) - - self.assertTrue( g.parent() is None ) - self.assertTrue( g2.parent() is None ) - - g.addChild( g2 ) - - self.assertTrue( g.parent() is None ) - self.assertTrue( g2.parent().isSame( g ) ) - - del g - self.assertTrue( g2.parent() is None ) - - def testAttributes( self ) : - - # create a little hierarchy - g = IECoreScene.Group() - g2 = IECoreScene.Group() - g3 = IECoreScene.Group() - - g.addChild( g2 ) - g2.addChild( g3 ) - - # define an attribute at the top of the hierarchy - g.setAttribute( "toptest", IECore.BoolData( False ) ) - self.assertEqual( g.getAttribute( "toptest" ), IECore.BoolData( False ) ) - - # change our mind and set it to true: - g.setAttribute( "toptest", IECore.BoolData( True ) ) - self.assertEqual( g.getAttribute( "toptest" ), IECore.BoolData( True ) ) - - # add another attribute - g.setAttribute( "toptest2", IECore.BoolData( True ) ) - self.assertEqual( g.getAttribute( "toptest2" ), IECore.BoolData( True ) ) - - - # make sure there's only one AttributeState on the group: - self.assertEqual( len( g.state() ), 1 ) - - # define one in the middle - g2.setAttribute( "middletest", IECore.BoolData( True ) ) - - # override the one at the top - g2.setAttribute( "toptest", IECore.BoolData( False ) ) - - # define one at the bottom - g3.setAttribute( "bottomtest", IECore.BoolData( False ) ) - - self.assertEqual( g.getAttribute( "toptest" ), IECore.BoolData( True ) ) - self.assertEqual( g.getAttribute( "middletest" ), None ) - self.assertEqual( g.getAttribute( "bottomtest" ), None ) - - self.assertEqual( g2.getAttribute( "toptest" ), IECore.BoolData( False ) ) - self.assertEqual( g2.getAttribute( "middletest" ), IECore.BoolData( True ) ) - self.assertEqual( g2.getAttribute( "bottomtest" ), None ) - - self.assertEqual( g3.getAttribute( "toptest" ), IECore.BoolData( False ) ) - self.assertEqual( g3.getAttribute( "middletest" ), IECore.BoolData( True ) ) - self.assertEqual( g3.getAttribute( "bottomtest" ), IECore.BoolData( False ) ) - - - # check that the final attribute state is returned by getAttribute: - g = IECoreScene.Group() - g.addState( IECoreScene.AttributeState( {"toptest": IECore.BoolData( False ) } ) ) - g.addState( IECoreScene.AttributeState( {"toptest": IECore.BoolData( True ) } ) ) - - self.assertEqual( g.getAttribute( "toptest" ), IECore.BoolData( True ) ) - - # make sure attributes get added to existing attributeStates: - g = IECoreScene.Group() - g.addState( IECoreScene.Shader("yup","ddyup", {}) ) - g.addState( IECoreScene.AttributeState( {"toptest": IECore.BoolData( False ) } ) ) - g.addState( IECoreScene.Shader("yup","yup", {}) ) - g.setAttribute( "blahblah", IECore.BoolData( True ) ) - - self.assertEqual( len( g.state() ), 3 ) - - - - def testExceptions( self ) : - - g = IECoreScene.Group() - - self.assertRaises( Exception, g.removeChild, IECoreScene.Group() ) - self.assertRaises( Exception, g.removeState, IECoreScene.AttributeState() ) - - def testTransformsNotState( self ) : - - g = IECoreScene.Group() - self.assertRaises( Exception, g.addState, IECoreScene.MatrixTransform( imath.M44f() ) ) - - def testChildOrdering( self ) : - - g = IECoreScene.Group() - c1 = IECoreScene.PointsPrimitive( 1 ) - c2 = IECoreScene.PointsPrimitive( 2 ) - c3 = IECoreScene.PointsPrimitive( 3 ) - - g.addChild( c1 ) - g.addChild( c2 ) - g.addChild( c3 ) - - c = g.children() - self.assertEqual( len( c ), 3 ) - self.assertTrue( c[0].isSame( c1 ) ) - self.assertTrue( c[1].isSame( c2 ) ) - self.assertTrue( c[2].isSame( c3 ) ) - - def testStateOrdering( self ) : - - g = IECoreScene.Group() - a1 = IECoreScene.AttributeState() - a2 = IECoreScene.AttributeState() - a3 = IECoreScene.AttributeState() - - g.addState( a1 ) - g.addState( a2 ) - g.addState( a3 ) - - s = g.state() - self.assertEqual( len( s ), 3 ) - self.assertTrue( s[0].isSame( a1 ) ) - self.assertTrue( s[1].isSame( a2 ) ) - self.assertTrue( s[2].isSame( a3 ) ) - - def testAddNullState( self ) : - - g = IECoreScene.Group() - self.assertRaises( Exception, g.addState, None ) - - def testAddNullChild( self ) : - - g = IECoreScene.Group() - self.assertRaises( Exception, g.addChild, None ) - - def testNoneRefcount( self ) : - - # exercises a bug whereby we weren't incrementing the reference - # count for Py_None when returning it to represent a null pointer. - # this led to "Fatal Python error: deallocating None" type crashes - g = IECoreScene.Group() - for i in range( 0, sys.getrefcount( None ) + 100 ) : - p = g.parent() - - def testMemoryUsage( self ) : - - # this used to crash if the group didn't have a transform - g = IECoreScene.Group() - self.assertTrue( g.memoryUsage() > 0 ) - - def testHash( self ) : - - g = IECoreScene.Group() - h = g.hash() - - g.addChild( IECoreScene.SpherePrimitive() ) - self.assertNotEqual( g.hash(), h ) - h = g.hash() - - g.addState( IECoreScene.AttributeState() ) - self.assertNotEqual( g.hash(), h ) - h = g.hash() - - g.setTransform( IECoreScene.MatrixTransform( imath.M44f() ) ) - self.assertNotEqual( g.hash(), h ) - - def testGlobalTransform( self ) : - - g = IECoreScene.Group() - childGroup = IECoreScene.Group() - - g.addChild( childGroup ) - - parentTransform = IECore.TransformationMatrixf() - parentTransform.rotate = imath.Eulerf( 0,3.1415926/2,0 ) - - childTransform = IECore.TransformationMatrixf() - childTransform.translate = imath.V3f( 1, 0, 2 ) - - childGroup.setTransform( IECoreScene.MatrixTransform( childTransform.transform ) ) - g.setTransform( IECoreScene.MatrixTransform( parentTransform.transform ) ) - - # child group's translation should have been rotated 90 degrees about the y axis: - s = imath.V3f() - h = imath.V3f() - r = imath.V3f() - childGroupGlobalTranslation = imath.V3f() - childGroup.globalTransformMatrix().extractSHRT( s, h, r, childGroupGlobalTranslation ) - self.assertAlmostEqual( childGroupGlobalTranslation.x, 2, 4 ) - self.assertAlmostEqual( childGroupGlobalTranslation.y, 0, 4 ) - self.assertAlmostEqual( childGroupGlobalTranslation.z, -1, 4 ) - - - - def tearDown( self ) : - - if os.path.isfile(os.path.join( "test", "group.cob" )): - os.remove(os.path.join( "test", "group.cob" )) - -if __name__ == "__main__": - unittest.main() diff --git a/test/IECoreScene/Transform.py b/test/IECoreScene/Transform.py deleted file mode 100644 index e917a64320..0000000000 --- a/test/IECoreScene/Transform.py +++ /dev/null @@ -1,123 +0,0 @@ -########################################################################## -# -# Copyright (c) 2007, 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 Image Engine Design 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 imath -import IECore -import IECoreScene - -class TestTransform( unittest.TestCase ) : - - def test( self ) : - - m = IECoreScene.MatrixTransform( imath.M44f() ) - self.assertEqual( m.transform(), imath.M44f() ) - self.assertEqual( m.transform( 1 ), imath.M44f() ) - self.assertEqual( m.matrix, imath.M44f() ) - - m = IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( 1, 2, 3 ) ) ) - self.assertEqual( m.transform(), imath.M44f().translate( imath.V3f( 1, 2, 3 ) ) ) - self.assertEqual( m.transform( 1 ), imath.M44f().translate( imath.V3f( 1, 2, 3 ) ) ) - self.assertEqual( m.matrix, imath.M44f().translate( imath.V3f( 1, 2, 3 ) ) ) - - mm = m.copy() - - self.assertEqual( m, mm ) - - IECore.Writer.create( mm, os.path.join( "test", "transform.cob" ) ).write() - mmm = IECore.Reader.create( os.path.join( "test", "transform.cob" ) ).read() - - self.assertEqual( mm, mmm ) - - def testMotionTransform( self ) : - - m = IECoreScene.MatrixMotionTransform() - self.assertEqual( m.transform(), imath.M44f() ) - self.assertEqual( m.transform( 2 ), imath.M44f() ) - self.assertEqual( m.keys(), [] ) - self.assertEqual( m.values(), [] ) - self.assertEqual( len( m ), 0 ) - - t1 = imath.M44f().translate( imath.V3f( 0, 1, 0 ) ) - t2 = imath.M44f().translate( imath.V3f( 0, 5, 0 ) ) - tMid = imath.M44f().translate( imath.V3f( 0, 3, 0 ) ) - - m[0] = t1 - self.assertEqual( len( m ), 1 ) - self.assertEqual( m.keys(), [ 0 ] ) - self.assertEqual( m.values(), [ t1 ] ) - self.assertEqual( m.transform(), t1 ) - self.assertEqual( m.transform( -1 ), t1 ) - self.assertEqual( m.transform( 0 ), t1 ) - self.assertEqual( m.transform( 1 ), t1 ) - - m[1] = t2 - self.assertEqual( len( m ), 2 ) - self.assertEqual( m.keys(), [ 0, 1 ] ) - self.assertEqual( m.values(), [ t1, t2 ] ) - self.assertEqual( m.transform(), t1 ) - self.assertEqual( m.transform( -1 ), t1 ) - self.assertEqual( m.transform( 1 ), t2 ) - self.assertEqual( m.transform( 2 ), t2 ) - self.assertEqual( m.transform( 0.5 ), tMid ) - - mm = m.copy() - - self.assertEqual( m, mm ) - - IECore.Writer.create( mm, os.path.join( "test", "motionTransform.cob" ) ).write() - mmm = IECore.Reader.create( os.path.join( "test", "motionTransform.cob" ) ).read() - - self.assertEqual( mm, mmm ) - - def testHash( self ) : - - t = IECoreScene.MatrixTransform( imath.M44f() ) - self.assertEqual( t.hash(), IECoreScene.MatrixTransform( imath.M44f() ).hash() ) - - t2 = IECoreScene.MatrixTransform( imath.M44f().translate( imath.V3f( 1 ) ) ) - self.assertNotEqual( t.hash(), t2.hash() ) - - def tearDown( self ) : - - if os.path.isfile(os.path.join( "test", "motionTransform.cob" )): - os.remove(os.path.join( "test", "motionTransform.cob" )) - - if os.path.isfile(os.path.join( "test", "transform.cob" )): - os.remove(os.path.join( "test", "transform.cob" )) - -if __name__ == "__main__": - unittest.main() - From 0a60e95d2831a5b4443c0063fc0c6af29d7afca5 Mon Sep 17 00:00:00 2001 From: John Haddon Date: Tue, 8 Jul 2025 11:07:55 +0100 Subject: [PATCH 12/15] Light : Remove This has been obsolete for a long time - in Gaffer we use ShaderNetwork to represent lights. --- Changes | 2 +- include/IECoreScene/Light.h | 87 ----------- include/IECoreScene/TypeIds.h | 2 +- src/IECoreScene/Light.cpp | 167 ---------------------- src/IECoreScene/bindings/IECoreScene.cpp | 2 - src/IECoreScene/bindings/LightBinding.cpp | 68 --------- src/IECoreScene/bindings/LightBinding.h | 43 ------ test/IECoreScene/All.py | 1 - test/IECoreScene/LightTest.py | 103 ------------- 9 files changed, 2 insertions(+), 473 deletions(-) delete mode 100644 include/IECoreScene/Light.h delete mode 100644 src/IECoreScene/Light.cpp delete mode 100644 src/IECoreScene/bindings/LightBinding.cpp delete mode 100644 src/IECoreScene/bindings/LightBinding.h delete mode 100644 test/IECoreScene/LightTest.py diff --git a/Changes b/Changes index da4d1c1c05..28b09429e7 100644 --- a/Changes +++ b/Changes @@ -15,7 +15,7 @@ Breaking Changes - Renderable : Removed `render()` method. - CoordinateSystem : Removed transform. - Font : Removed `meshGroup()` method. -- Options, Group, Transform, MatrixTransform, MatrixMotionTransform, AttributeState : Removed. +- Options, Group, Transform, MatrixTransform, MatrixMotionTransform, AttributeState, Light : Removed. - CurveExtrudeOp, IDXReader : Removed. - Renderer, AttributeBlock, EditBlock, MotionBlock, TransformBlock, WorldBlock : Removed. - IECoreHoudini : Removed. diff --git a/include/IECoreScene/Light.h b/include/IECoreScene/Light.h deleted file mode 100644 index 57fe57a68e..0000000000 --- a/include/IECoreScene/Light.h +++ /dev/null @@ -1,87 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2010-2011, 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 Image Engine Design 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 IECORESCENE_LIGHT_H -#define IECORESCENE_LIGHT_H - -#include "IECoreScene/Export.h" -#include "IECoreScene/StateRenderable.h" - -namespace IECoreScene -{ - -/// A class to represent lights. -/// \ingroup renderingGroup -class IECORESCENE_API Light : public StateRenderable -{ - public: - - Light( const std::string &name="distantlight", const std::string &handle="", const IECore::CompoundDataMap ¶meters = IECore::CompoundDataMap() ); - ~Light() override; - - IE_CORE_DECLAREEXTENSIONOBJECT( Light, LightTypeId, StateRenderable ); - - const std::string &getName() const; - void setName( const std::string &name ); - - const std::string &getHandle() const; - void setHandle( const std::string &handle ); - - IECore::CompoundDataMap ¶meters(); - const IECore::CompoundDataMap ¶meters() const; - /// This is mostly of use for the binding - the parameters() - /// function gives more direct access to the contents of the CompoundData - /// (it calls readable() or writable() for you). - /// \todo: Should return raw pointer to CompoundData, and we should probably remove the - /// parameters() methods since the helper methods on ParametersData make it more useful - IECore::CompoundDataPtr parametersData(); - const IECore::CompoundDataPtr parametersData() const; - - private: - - static TypeDescription m_description; - - std::string m_name; - std::string m_handle; - IECore::CompoundDataPtr m_parameters; - - static const unsigned int m_ioVersion; -}; - -IE_CORE_DECLAREPTR( Light ); - -} // namespace IECoreScene - - -#endif // IECORESCENE_LIGHT_H diff --git a/include/IECoreScene/TypeIds.h b/include/IECoreScene/TypeIds.h index 9a308e565d..66025b9991 100644 --- a/include/IECoreScene/TypeIds.h +++ b/include/IECoreScene/TypeIds.h @@ -124,7 +124,7 @@ enum TypeId PointsPrimitiveEvaluatorTypeId = 108081, PointsMotionOpTypeId = 108082, // Obsolete, available for reuse ShaderNetworkTypeId = 108083, - LightTypeId = 108084, + LightTypeId = 108084, // Obsolete, available for reuse ContrastSmoothSkinningWeightsOpTypeId = 108085, PointDistributionOpTypeId = 108086, DiskPrimitiveTypeId = 108087, diff --git a/src/IECoreScene/Light.cpp b/src/IECoreScene/Light.cpp deleted file mode 100644 index 558478e4fc..0000000000 --- a/src/IECoreScene/Light.cpp +++ /dev/null @@ -1,167 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2010-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 Image Engine Design 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. -// -////////////////////////////////////////////////////////////////////////// - -#include "IECoreScene/Light.h" - -#include "IECore/MurmurHash.h" - -#include "boost/format.hpp" - -using namespace IECore; -using namespace IECoreScene; -using namespace boost; - -static IndexedIO::EntryID g_nameEntry("name"); -static IndexedIO::EntryID g_handleEntry("handle"); -static IndexedIO::EntryID g_parametersEntry("parameters"); - - -const unsigned int Light::m_ioVersion = 0; -Object::TypeDescription Light::m_description; - -Light::Light( const std::string &name, const std::string &handle, const CompoundDataMap ¶meters ) - : m_name( name ), m_handle( handle ), m_parameters( new CompoundData( parameters ) ) -{ - if ( m_handle.empty() ) - { - m_handle = ( boost::format( "%p" ) % this ).str(); - } -} - -Light::~Light() -{ -} - -const std::string &Light::getName() const -{ - return m_name; -} - -void Light::setName( const std::string &name ) -{ - m_name = name; -} - -const std::string &Light::getHandle() const -{ - return m_handle; -} - -void Light::setHandle( const std::string &handle ) -{ - m_handle = handle; -} - -CompoundDataMap &Light::parameters() -{ - return m_parameters->writable(); -} - -const CompoundDataMap &Light::parameters() const -{ - return m_parameters->readable(); -} - -CompoundDataPtr Light::parametersData() -{ - return m_parameters; -} - -const CompoundDataPtr Light::parametersData() const -{ - return m_parameters; -} - -bool Light::isEqualTo( const Object *other ) const -{ - if( !StateRenderable::isEqualTo( other ) ) - { - return false; - } - const Light *s = static_cast( other ); - if( m_name!=s->m_name ) - { - return false; - } - if( m_handle!=s->m_handle ) - { - return false; - } - return m_parameters->isEqualTo( s->m_parameters.get() ); -} - -void Light::memoryUsage( Object::MemoryAccumulator &a ) const -{ - StateRenderable::memoryUsage( a ); - a.accumulate( m_name.capacity() ); - a.accumulate( m_handle.capacity() ); - a.accumulate( m_parameters.get() ); -} - -void Light::copyFrom( const Object *other, CopyContext *context ) -{ - StateRenderable::copyFrom( other, context ); - const Light *s = static_cast( other ); - m_name = s->m_name; - m_handle = s->m_handle; - m_parameters = context->copy( s->m_parameters.get() ); -} - -void Light::save( SaveContext *context ) const -{ - StateRenderable::save( context ); - IndexedIOPtr container = context->container( staticTypeName(), m_ioVersion ); - container->write( g_nameEntry, m_name ); - container->write( g_handleEntry, m_handle ); - context->save( m_parameters.get(), container.get(), g_parametersEntry ); -} - -void Light::load( LoadContextPtr context ) -{ - StateRenderable::load( context ); - unsigned int v = m_ioVersion; - ConstIndexedIOPtr container = context->container( staticTypeName(), v ); - container->read( g_nameEntry, m_name ); - container->read( g_handleEntry, m_handle ); - m_parameters = context->load( container.get(), g_parametersEntry ); -} - -void Light::hash( MurmurHash &h ) const -{ - StateRenderable::hash( h ); - h.append( m_name ); - h.append( m_handle ); - m_parameters->hash( h ); -} - diff --git a/src/IECoreScene/bindings/IECoreScene.cpp b/src/IECoreScene/bindings/IECoreScene.cpp index 6b607ca2a0..959c6d0dd8 100644 --- a/src/IECoreScene/bindings/IECoreScene.cpp +++ b/src/IECoreScene/bindings/IECoreScene.cpp @@ -51,7 +51,6 @@ #include "ExternalProceduralBinding.h" #include "FaceVaryingPromotionOpBinding.h" #include "FontBinding.h" -#include "LightBinding.h" #include "LimitSmoothSkinningInfluencesOpBinding.h" #include "LinkedSceneBinding.h" #include "MeshAlgoBinding.h" @@ -178,7 +177,6 @@ BOOST_PYTHON_MODULE(_IECoreScene) bindRemoveSmoothSkinningInfluencesOp(); bindTransferSmoothSkinningWeightsOp(); bindPointsPrimitiveEvaluator(); - bindLight(); bindContrastSmoothSkinningWeightsOp(); bindDiskPrimitive(); bindSceneInterface(); diff --git a/src/IECoreScene/bindings/LightBinding.cpp b/src/IECoreScene/bindings/LightBinding.cpp deleted file mode 100644 index 0113b1a999..0000000000 --- a/src/IECoreScene/bindings/LightBinding.cpp +++ /dev/null @@ -1,68 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2010, 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 Image Engine Design 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. -// -////////////////////////////////////////////////////////////////////////// - -#include "boost/python.hpp" - -#include "LightBinding.h" - -#include "IECoreScene/Light.h" - -#include "IECorePython/RunTimeTypedBinding.h" - -using namespace boost::python; -using namespace IECore; -using namespace IECorePython; -using namespace IECoreScene; - -namespace IECoreSceneModule -{ - - static LightPtr construct( const std::string &name="distantlight", const std::string &handle="", CompoundDataPtr parameters = nullptr ) - { - return new Light( name, handle, parameters ? parameters->readable() : CompoundDataMap() ); - } - - void bindLight() - { - RunTimeTypedClass() - .def( init<>() ) - .def( init >() ) - .def( "__init__", make_constructor( &construct, default_call_policies(), ( boost::python::arg_( "name" )="distantlight", boost::python::arg_( "handle" )="", boost::python::arg_( "parameters" )=0 ) ) ) - .add_property( "name", make_function( &Light::getName, return_value_policy() ), &Light::setName ) - .add_property( "handle", make_function( &Light::getHandle, return_value_policy() ), &Light::setHandle ) - .add_property( "parameters", (CompoundDataPtr (Light::*)() )( &Light::parametersData ) ) - ; - } - -} diff --git a/src/IECoreScene/bindings/LightBinding.h b/src/IECoreScene/bindings/LightBinding.h deleted file mode 100644 index 08f45ca0b4..0000000000 --- a/src/IECoreScene/bindings/LightBinding.h +++ /dev/null @@ -1,43 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2010, 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 Image Engine Design 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 IECORESCENEMODULE_LIGHTBINDING_H -#define IECORESCENEMODULE_LIGHTBINDING_H - -namespace IECoreSceneModule -{ -void bindLight(); -} - -#endif // IECORESCENEMODULE_LIGHTBINDING_H diff --git a/test/IECoreScene/All.py b/test/IECoreScene/All.py index 2d6e773c47..898fcf896e 100644 --- a/test/IECoreScene/All.py +++ b/test/IECoreScene/All.py @@ -85,7 +85,6 @@ from PointSmoothSkinningOpTest import PointSmoothSkinningOpTest from AddAndRemoveSmoothSkinningInfluencesOpTest import AddAndRemoveSmoothSkinningInfluencesOpTest from PointsPrimitiveEvaluatorTest import PointsPrimitiveEvaluatorTest -from LightTest import LightTest from ContrastSmoothSkinningWeightsOpTest import ContrastSmoothSkinningWeightsOpTest from DiskPrimitiveTest import DiskPrimitiveTest from SWAReaderTest import SWAReaderTest diff --git a/test/IECoreScene/LightTest.py b/test/IECoreScene/LightTest.py deleted file mode 100644 index 1cfdc44869..0000000000 --- a/test/IECoreScene/LightTest.py +++ /dev/null @@ -1,103 +0,0 @@ -########################################################################## -# -# Copyright (c) 2010-2011, 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 Image Engine Design 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 IECore -import IECoreScene - -class LightTest( unittest.TestCase ) : - - def test( self ) : - - s = IECoreScene.Light() - self.assertEqual( s.name, "distantlight" ) - self.assertTrue( len(s.handle) > 0 ) - self.assertEqual( len( s.parameters ), 0 ) - self.assertEqual( s.parameters.typeName(), "CompoundData" ) - - ss = IECoreScene.Light() - self.assertNotEqual( s.handle, ss.handle ) - - s = IECoreScene.Light( "marble", "marble001" ) - self.assertEqual( s.name, "marble" ) - self.assertEqual( s.handle, "marble001" ) - - ss = s.copy() - self.assertEqual( ss.name, s.name ) - self.assertEqual( ss.handle, s.handle ) - - def testProperties( self ) : - - s = IECoreScene.Light() - s.handle = "myNewHandle" - s.name = "myNewName" - self.assertEqual( s.name, "myNewName" ) - self.assertEqual( s.handle, "myNewHandle" ) - - def testConstructWithParameters( self ) : - - s = IECoreScene.Light( "test", "test001", IECore.CompoundData( { "a" : IECore.StringData( "a" ) } ) ) - - self.assertEqual( s.name, "test" ) - self.assertEqual( s.handle, "test001" ) - self.assertEqual( len( s.parameters ), 1 ) - self.assertEqual( s.parameters.typeName(), IECore.CompoundData.staticTypeName() ) - self.assertEqual( s.parameters["a"], IECore.StringData( "a" ) ) - - def testCopy( self ) : - - s = IECoreScene.Light( "test", "surface", IECore.CompoundData( { "a" : IECore.StringData( "a" ) } ) ) - ss = s.copy() - - self.assertEqual( s, ss ) - - def testHash( self ) : - - s = IECoreScene.Light( "name", "handle" ) - h = s.hash() - - s.name = "name2" - self.assertNotEqual( s.hash(), h ) - h = s.hash() - - s.handle = "handle2" - self.assertNotEqual( s.hash(), h ) - h = s.hash() - - s.parameters["a"] = IECore.StringData( "a" ) - self.assertNotEqual( s.hash(), h ) - -if __name__ == "__main__": - unittest.main() From 73191c99950a5baa3a6a32512e81910c7e78eb0e Mon Sep 17 00:00:00 2001 From: John Haddon Date: Tue, 8 Jul 2025 11:21:12 +0100 Subject: [PATCH 13/15] Remove PreWorldRenderable Gaffer's new Renderer API doesn't have a world block, or a concept of pre/post world in the old RenderMan API sense. The whole point of modern rendering APIs is to allow anything to be edited at any time in any thread, and stateful APIs impede that. So it doesn't make sense to categorise certain renderables under a PreWorldRenderabel moniker. --- Changes | 1 + include/IECoreScene/Camera.h | 6 +- include/IECoreScene/ClippingPlane.h | 6 +- include/IECoreScene/Output.h | 6 +- include/IECoreScene/PreWorldRenderable.h | 65 -------------- include/IECoreScene/TypeIds.h | 2 +- src/IECoreScene/Camera.cpp | 12 +-- src/IECoreScene/ClippingPlane.cpp | 12 +-- src/IECoreScene/Output.cpp | 12 +-- src/IECoreScene/PreWorldRenderable.cpp | 84 ------------------- src/IECoreScene/bindings/IECoreScene.cpp | 2 - .../bindings/PreWorldRenderableBinding.cpp | 58 ------------- .../bindings/PreWorldRenderableBinding.h | 45 ---------- 13 files changed, 29 insertions(+), 282 deletions(-) delete mode 100644 include/IECoreScene/PreWorldRenderable.h delete mode 100644 src/IECoreScene/PreWorldRenderable.cpp delete mode 100644 src/IECoreScene/bindings/PreWorldRenderableBinding.cpp delete mode 100644 src/IECoreScene/bindings/PreWorldRenderableBinding.h diff --git a/Changes b/Changes index 28b09429e7..03bc44fd0a 100644 --- a/Changes +++ b/Changes @@ -17,6 +17,7 @@ Breaking Changes - Font : Removed `meshGroup()` method. - Options, Group, Transform, MatrixTransform, MatrixMotionTransform, AttributeState, Light : Removed. - CurveExtrudeOp, IDXReader : Removed. +- PreWorldRenderable : Removed. All derived classes now derive directly from Renderable. - Renderer, AttributeBlock, EditBlock, MotionBlock, TransformBlock, WorldBlock : Removed. - IECoreHoudini : Removed. - IECoreMaya : Removed. diff --git a/include/IECoreScene/Camera.h b/include/IECoreScene/Camera.h index 772b2e12b5..8c009a7136 100644 --- a/include/IECoreScene/Camera.h +++ b/include/IECoreScene/Camera.h @@ -36,12 +36,12 @@ #define IECORESCENE_CAMERA_H #include "IECoreScene/Export.h" -#include "IECoreScene/PreWorldRenderable.h" +#include "IECoreScene/Renderable.h" namespace IECoreScene { -class IECORESCENE_API Camera : public PreWorldRenderable +class IECORESCENE_API Camera : public Renderable { public: enum FilmFit @@ -56,7 +56,7 @@ class IECORESCENE_API Camera : public PreWorldRenderable Camera( IECore::CompoundDataPtr parameters = new IECore::CompoundData ); ~Camera() override; - IE_CORE_DECLAREEXTENSIONOBJECT( Camera, CameraTypeId, PreWorldRenderable ); + IE_CORE_DECLAREEXTENSIONOBJECT( Camera, CameraTypeId, Renderable ); IECore::CompoundDataMap ¶meters(); const IECore::CompoundDataMap ¶meters() const; diff --git a/include/IECoreScene/ClippingPlane.h b/include/IECoreScene/ClippingPlane.h index 4b757a2c97..168dbab625 100644 --- a/include/IECoreScene/ClippingPlane.h +++ b/include/IECoreScene/ClippingPlane.h @@ -36,19 +36,19 @@ #define IECORESCENE_CLIPPINGPLANE_H #include "IECoreScene/Export.h" -#include "IECoreScene/PreWorldRenderable.h" +#include "IECoreScene/Renderable.h" namespace IECoreScene { -class IECORESCENE_API ClippingPlane : public PreWorldRenderable +class IECORESCENE_API ClippingPlane : public Renderable { public: ClippingPlane(); ~ClippingPlane() override; - IE_CORE_DECLAREEXTENSIONOBJECT( ClippingPlane, ClippingPlaneTypeId, PreWorldRenderable ); + IE_CORE_DECLAREEXTENSIONOBJECT( ClippingPlane, ClippingPlaneTypeId, Renderable ); }; diff --git a/include/IECoreScene/Output.h b/include/IECoreScene/Output.h index b8718ed087..4d1c73a524 100644 --- a/include/IECoreScene/Output.h +++ b/include/IECoreScene/Output.h @@ -36,21 +36,21 @@ #define IECORESCENE_OUTPUT_H #include "IECoreScene/Export.h" -#include "IECoreScene/PreWorldRenderable.h" +#include "IECoreScene/Renderable.h" namespace IECoreScene { /// Describes an output image to be rendered. /// \ingroup renderingGroup -class IECORESCENE_API Output : public PreWorldRenderable +class IECORESCENE_API Output : public Renderable { public: Output( const std::string &name="default", const std::string &type="exr", const std::string &data="rgba", IECore::CompoundDataPtr parameters = new IECore::CompoundData ); ~Output() override; - IE_CORE_DECLAREEXTENSIONOBJECT( Output, OutputTypeId, PreWorldRenderable ); + IE_CORE_DECLAREEXTENSIONOBJECT( Output, OutputTypeId, Renderable ); void setName( const std::string &name ); const std::string &getName() const; diff --git a/include/IECoreScene/PreWorldRenderable.h b/include/IECoreScene/PreWorldRenderable.h deleted file mode 100644 index 03676322d7..0000000000 --- a/include/IECoreScene/PreWorldRenderable.h +++ /dev/null @@ -1,65 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007, 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 Image Engine Design 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 IECORESCENE_PREWORLDRENDERABLE_H -#define IECORESCENE_PREWORLDRENDERABLE_H - -#include "IECoreScene/Export.h" -#include "IECoreScene/Renderable.h" - -namespace IECoreScene -{ - -/// The PreWorldRenderable class is an abstract base class for all Renderables -/// which set things which are constant across a whole worldBegin()/worldEnd() -/// block, and must therefore be called before worldBegin(). -class IECORESCENE_API PreWorldRenderable : public Renderable -{ - public: - - PreWorldRenderable(); - ~PreWorldRenderable() override; - - IE_CORE_DECLAREEXTENSIONOBJECT( PreWorldRenderable, PreWorldRenderableTypeId, Renderable ); - - private: - - static const unsigned int m_ioVersion; -}; - -IE_CORE_DECLAREPTR( PreWorldRenderable ); - -} - -#endif // IECORESCENE_PREWORLDRENDERABLE_H diff --git a/include/IECoreScene/TypeIds.h b/include/IECoreScene/TypeIds.h index 66025b9991..d8230b31e6 100644 --- a/include/IECoreScene/TypeIds.h +++ b/include/IECoreScene/TypeIds.h @@ -75,7 +75,7 @@ enum TypeId PrimitiveParameterTypeId = 108032, MeshPrimitiveParameterTypeId = 108033, PointsPrimitiveParameterTypeId = 108034, - PreWorldRenderableTypeId = 108035, + PreWorldRenderableTypeId = 108035, // Obsolete, available for reuse CameraTypeId = 108036, NURBSPrimitiveTypeId = 108037, PointBoundsOpTypeId = 108038, // Obsolete, available for reuse diff --git a/src/IECoreScene/Camera.cpp b/src/IECoreScene/Camera.cpp index b70ccfef72..67ef1d0d31 100644 --- a/src/IECoreScene/Camera.cpp +++ b/src/IECoreScene/Camera.cpp @@ -94,21 +94,21 @@ Camera::~Camera() void Camera::copyFrom( const Object *other, CopyContext *context ) { - PreWorldRenderable::copyFrom( other, context ); + Renderable::copyFrom( other, context ); const Camera *tOther = static_cast( other ); m_parameters = context->copy( tOther->m_parameters.get() ); } void Camera::save( SaveContext *context ) const { - PreWorldRenderable::save( context ); + Renderable::save( context ); IndexedIOPtr container = context->container( staticTypeName(), m_ioVersion ); context->save( m_parameters.get(), container.get(), g_parametersEntry ); } void Camera::load( LoadContextPtr context ) { - PreWorldRenderable::load( context ); + Renderable::load( context ); unsigned int v = m_ioVersion; ConstIndexedIOPtr container = context->container( staticTypeName(), v ); @@ -117,7 +117,7 @@ void Camera::load( LoadContextPtr context ) bool Camera::isEqualTo( const Object *other ) const { - if( !PreWorldRenderable::isEqualTo( other ) ) + if( !Renderable::isEqualTo( other ) ) { return false; } @@ -135,13 +135,13 @@ bool Camera::isEqualTo( const Object *other ) const void Camera::memoryUsage( Object::MemoryAccumulator &a ) const { - PreWorldRenderable::memoryUsage( a ); + Renderable::memoryUsage( a ); a.accumulate( m_parameters.get() ); } void Camera::hash( MurmurHash &h ) const { - PreWorldRenderable::hash( h ); + Renderable::hash( h ); m_parameters->hash( h ); } diff --git a/src/IECoreScene/ClippingPlane.cpp b/src/IECoreScene/ClippingPlane.cpp index 37716e6227..bdc96dbf93 100644 --- a/src/IECoreScene/ClippingPlane.cpp +++ b/src/IECoreScene/ClippingPlane.cpp @@ -49,30 +49,30 @@ ClippingPlane::~ClippingPlane() void ClippingPlane::copyFrom( const Object *other, CopyContext *context ) { - PreWorldRenderable::copyFrom( other, context ); + Renderable::copyFrom( other, context ); } void ClippingPlane::save( SaveContext *context ) const { - PreWorldRenderable::save( context ); + Renderable::save( context ); } void ClippingPlane::load( LoadContextPtr context ) { - PreWorldRenderable::load( context ); + Renderable::load( context ); } bool ClippingPlane::isEqualTo( const Object *other ) const { - return PreWorldRenderable::isEqualTo( other ); + return Renderable::isEqualTo( other ); } void ClippingPlane::memoryUsage( Object::MemoryAccumulator &a ) const { - PreWorldRenderable::memoryUsage( a ); + Renderable::memoryUsage( a ); } void ClippingPlane::hash( MurmurHash &h ) const { - PreWorldRenderable::hash( h ); + Renderable::hash( h ); } diff --git a/src/IECoreScene/Output.cpp b/src/IECoreScene/Output.cpp index bc9fe38e65..437267eb94 100644 --- a/src/IECoreScene/Output.cpp +++ b/src/IECoreScene/Output.cpp @@ -60,7 +60,7 @@ Output::~Output() void Output::copyFrom( const Object *other, CopyContext *context ) { - PreWorldRenderable::copyFrom( other, context ); + Renderable::copyFrom( other, context ); const Output *tOther = static_cast( other ); m_name = tOther->m_name; m_type = tOther->m_type; @@ -70,7 +70,7 @@ void Output::copyFrom( const Object *other, CopyContext *context ) void Output::save( SaveContext *context ) const { - PreWorldRenderable::save( context ); + Renderable::save( context ); IndexedIOPtr container = context->container( staticTypeName(), m_ioVersion ); container->write( g_nameEntry, m_name ); container->write( g_typeEntry, m_type ); @@ -80,7 +80,7 @@ void Output::save( SaveContext *context ) const void Output::load( LoadContextPtr context ) { - PreWorldRenderable::load( context ); + Renderable::load( context ); unsigned int v = m_ioVersion; ConstIndexedIOPtr container = context->container( staticTypeName(), v ); container->read( g_nameEntry, m_name ); @@ -91,7 +91,7 @@ void Output::load( LoadContextPtr context ) bool Output::isEqualTo( const Object *other ) const { - if( !PreWorldRenderable::isEqualTo( other ) ) + if( !Renderable::isEqualTo( other ) ) { return false; } @@ -127,7 +127,7 @@ bool Output::isEqualTo( const Object *other ) const void Output::memoryUsage( Object::MemoryAccumulator &a ) const { - PreWorldRenderable::memoryUsage( a ); + Renderable::memoryUsage( a ); a.accumulate( m_name.capacity() ); a.accumulate( m_type.capacity() ); a.accumulate( m_data.capacity() ); @@ -136,7 +136,7 @@ void Output::memoryUsage( Object::MemoryAccumulator &a ) const void Output::hash( MurmurHash &h ) const { - PreWorldRenderable::hash( h ); + Renderable::hash( h ); h.append( m_name ); h.append( m_type ); h.append( m_data ); diff --git a/src/IECoreScene/PreWorldRenderable.cpp b/src/IECoreScene/PreWorldRenderable.cpp deleted file mode 100644 index 9952b9cce8..0000000000 --- a/src/IECoreScene/PreWorldRenderable.cpp +++ /dev/null @@ -1,84 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2011, 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 Image Engine Design 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. -// -////////////////////////////////////////////////////////////////////////// - -#include "IECoreScene/PreWorldRenderable.h" - -using namespace IECore; -using namespace IECoreScene; - -IE_CORE_DEFINEOBJECTTYPEDESCRIPTION(PreWorldRenderable); - -const unsigned int PreWorldRenderable::m_ioVersion = 0; - -PreWorldRenderable::PreWorldRenderable() -{ -} - -PreWorldRenderable::~PreWorldRenderable() -{ -} - -void PreWorldRenderable::copyFrom( const Object *other, CopyContext *context ) -{ - Renderable::copyFrom( other, context ); -} - -void PreWorldRenderable::save( SaveContext *context ) const -{ - Renderable::save( context ); -} - -void PreWorldRenderable::load( LoadContextPtr context ) -{ - Renderable::load( context ); -} - -bool PreWorldRenderable::isEqualTo( const Object *other ) const -{ - if( !Renderable::isEqualTo( other ) ) - { - return false; - } - return true; -} - -void PreWorldRenderable::memoryUsage( Object::MemoryAccumulator &a ) const -{ - Renderable::memoryUsage( a ); -} - -void PreWorldRenderable::hash( MurmurHash &h ) const -{ - Renderable::hash( h ); -} diff --git a/src/IECoreScene/bindings/IECoreScene.cpp b/src/IECoreScene/bindings/IECoreScene.cpp index 959c6d0dd8..78c7c1d17e 100644 --- a/src/IECoreScene/bindings/IECoreScene.cpp +++ b/src/IECoreScene/bindings/IECoreScene.cpp @@ -77,7 +77,6 @@ #include "PointsAlgoBinding.h" #include "PointsPrimitiveBinding.h" #include "PointsPrimitiveEvaluatorBinding.h" -#include "PreWorldRenderableBinding.h" #include "PrimitiveBinding.h" #include "PrimitiveEvaluatorBinding.h" #include "PrimitiveOpBinding.h" @@ -130,7 +129,6 @@ BOOST_PYTHON_MODULE(_IECoreScene) bindPrimitiveOp(); bindMeshPrimitive(); bindMotionPrimitive(); - bindPreWorldRenderable(); bindCamera(); bindNURBSPrimitive(); bindMeshPrimitiveBuilder(); diff --git a/src/IECoreScene/bindings/PreWorldRenderableBinding.cpp b/src/IECoreScene/bindings/PreWorldRenderableBinding.cpp deleted file mode 100644 index ee5dc6b0fb..0000000000 --- a/src/IECoreScene/bindings/PreWorldRenderableBinding.cpp +++ /dev/null @@ -1,58 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2010, 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 Image Engine Design 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. -// -////////////////////////////////////////////////////////////////////////// - -// This include needs to be the very first to prevent problems with warnings -// regarding redefinition of _POSIX_C_SOURCE -#include "boost/python.hpp" - -#include "PreWorldRenderableBinding.h" - -#include "IECoreScene/PreWorldRenderable.h" - -#include "IECorePython/RunTimeTypedBinding.h" - -using namespace boost::python; -using namespace IECorePython; -using namespace IECoreScene; - -namespace IECoreSceneModule -{ - -void bindPreWorldRenderable() -{ - RunTimeTypedClass() - ; -} - -} diff --git a/src/IECoreScene/bindings/PreWorldRenderableBinding.h b/src/IECoreScene/bindings/PreWorldRenderableBinding.h deleted file mode 100644 index fd344a8611..0000000000 --- a/src/IECoreScene/bindings/PreWorldRenderableBinding.h +++ /dev/null @@ -1,45 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2010, 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 Image Engine Design 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 IECORESCENEMODULE_PREWORLDRENDERABLEBINDING_H -#define IECORESCENEMODULE_PREWORLDRENDERABLEBINDING_H - -namespace IECoreSceneModule -{ - -void bindPreWorldRenderable(); - -} - -#endif // IECORESCENEMODULE_PREWORLDRENDERABLEBINDING_H From ea2f249e13f9de86bdcb2fced609743134b6963b Mon Sep 17 00:00:00 2001 From: John Haddon Date: Tue, 8 Jul 2025 11:23:34 +0100 Subject: [PATCH 14/15] Remove MotionPrimitive This is yet another class that doesn't play any part in Gaffer's scene representation. --- Changes | 2 +- include/IECoreScene/MotionPrimitive.h | 92 -------- include/IECoreScene/TypeIds.h | 4 +- include/IECoreScene/TypedPrimitiveParameter.h | 3 - src/IECoreScene/MotionPrimitive.cpp | 204 ------------------ src/IECoreScene/TypedPrimitiveParameter.cpp | 3 - src/IECoreScene/bindings/IECoreScene.cpp | 2 - .../bindings/MotionPrimitiveBinding.cpp | 137 ------------ .../bindings/MotionPrimitiveBinding.h | 43 ---- .../bindings/TypedObjectParameterBinding.cpp | 2 - test/IECoreScene/All.py | 1 - test/IECoreScene/MotionPrimitive.py | 115 ---------- 12 files changed, 3 insertions(+), 605 deletions(-) delete mode 100644 include/IECoreScene/MotionPrimitive.h delete mode 100644 src/IECoreScene/MotionPrimitive.cpp delete mode 100644 src/IECoreScene/bindings/MotionPrimitiveBinding.cpp delete mode 100644 src/IECoreScene/bindings/MotionPrimitiveBinding.h delete mode 100644 test/IECoreScene/MotionPrimitive.py diff --git a/Changes b/Changes index 03bc44fd0a..a1f8898aef 100644 --- a/Changes +++ b/Changes @@ -15,7 +15,7 @@ Breaking Changes - Renderable : Removed `render()` method. - CoordinateSystem : Removed transform. - Font : Removed `meshGroup()` method. -- Options, Group, Transform, MatrixTransform, MatrixMotionTransform, AttributeState, Light : Removed. +- Options, Group, Transform, MatrixTransform, MatrixMotionTransform, AttributeState, Light, MotionPrimitive : Removed. - CurveExtrudeOp, IDXReader : Removed. - PreWorldRenderable : Removed. All derived classes now derive directly from Renderable. - Renderer, AttributeBlock, EditBlock, MotionBlock, TransformBlock, WorldBlock : Removed. diff --git a/include/IECoreScene/MotionPrimitive.h b/include/IECoreScene/MotionPrimitive.h deleted file mode 100644 index c4136a92bc..0000000000 --- a/include/IECoreScene/MotionPrimitive.h +++ /dev/null @@ -1,92 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2011, 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 Image Engine Design 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 IECORESCENE_PRIMITIVEMOTION_H -#define IECORESCENE_PRIMITIVEMOTION_H - -#include "IECoreScene/Export.h" -#include "IECoreScene/Primitive.h" - -namespace IECoreScene -{ - -/// The MotionPrimitive is a simple means of constructing and rendering a -/// motionBegin/motionEnd block containing a Primitive. There's nothing to -/// stop you from calling motionBegin/motionEnd to construct motion blocks yourself -/// but this form is simple, and loadable and savable and copyable and all that. -/// \ingroup renderingGroup -class IECORESCENE_API MotionPrimitive : public VisibleRenderable -{ - public: - - /// A type to map between points in time and corresponding - /// Primitives. - typedef std::map SnapshotMap; - - MotionPrimitive(); - ~MotionPrimitive() override; - - IE_CORE_DECLAREEXTENSIONOBJECT( MotionPrimitive, MotionPrimitiveTypeId, VisibleRenderable ); - - //! @name Snapshots - //////////////////////////////////////////////////// - //@{ - /// Gives const access to the internal snapshot data. - const SnapshotMap &snapshots() const; - /// Gives access to the internal snapshot data. This can - /// be modified freely - it'll be validated in render(). - SnapshotMap &snapshots(); - /// Utility function to insert a time,primitive pair - /// into snapshots(). - void addSnapshot( float time, PrimitivePtr primitive ); - /// Utility function to remove a snapshot. - void removeSnapshot( float time ); - void removeSnapshot( PrimitivePtr primitive ); - //@} - - Imath::Box3f bound() const override; - - private: - - static const unsigned int m_ioVersion; - - SnapshotMap m_snapshots; - -}; - -IE_CORE_DECLAREPTR( MotionPrimitive ); - -} // namespace IECoreScene - -#endif // IECORESCENE_PRIMITIVEMOTION_H diff --git a/include/IECoreScene/TypeIds.h b/include/IECoreScene/TypeIds.h index d8230b31e6..50e37d15c6 100644 --- a/include/IECoreScene/TypeIds.h +++ b/include/IECoreScene/TypeIds.h @@ -51,7 +51,7 @@ enum TypeId PrimitiveOpTypeId = 108008, ParticleReaderTypeId = 108009, ParticleWriterTypeId = 108010, - MotionPrimitiveTypeId = 108011, + MotionPrimitiveTypeId = 108011, // Obsolete, available for reuse TransformTypeId = 108012, // Obsolete, available for reuse MatrixTransformTypeId = 108013, // Obsolete, available for reuse MotionTransformTypeId = 108014, // Obsolete, available for reuse @@ -71,7 +71,7 @@ enum TypeId MatrixTransformParameterTypeId = 108028, // Obsolete, available for reuse VisibleRenderableParameterTypeId = 108029, GroupParameterTypeId = 108030, // Obsolete, available for reuse - MotionPrimitiveParameterTypeId = 108031, + MotionPrimitiveParameterTypeId = 108031, // Obsolete, available for reuse PrimitiveParameterTypeId = 108032, MeshPrimitiveParameterTypeId = 108033, PointsPrimitiveParameterTypeId = 108034, diff --git a/include/IECoreScene/TypedPrimitiveParameter.h b/include/IECoreScene/TypedPrimitiveParameter.h index c2263c1869..aa32b19b8e 100644 --- a/include/IECoreScene/TypedPrimitiveParameter.h +++ b/include/IECoreScene/TypedPrimitiveParameter.h @@ -40,19 +40,16 @@ namespace IECoreScene { -IE_CORE_FORWARDDECLARE( MotionPrimitive ) IE_CORE_FORWARDDECLARE( Primitive ) IE_CORE_FORWARDDECLARE( MeshPrimitive ) IE_CORE_FORWARDDECLARE( CurvesPrimitive ) IE_CORE_FORWARDDECLARE( PointsPrimitive ) -typedef IECore::TypedObjectParameter MotionPrimitiveParameter; typedef IECore::TypedObjectParameter PrimitiveParameter; typedef IECore::TypedObjectParameter MeshPrimitiveParameter; typedef IECore::TypedObjectParameter CurvesPrimitiveParameter; typedef IECore::TypedObjectParameter PointsPrimitiveParameter; -IE_CORE_DECLAREPTR( MotionPrimitiveParameter ); IE_CORE_DECLAREPTR( PrimitiveParameter ); IE_CORE_DECLAREPTR( MeshPrimitiveParameter ); IE_CORE_DECLAREPTR( CurvesPrimitiveParameter ); diff --git a/src/IECoreScene/MotionPrimitive.cpp b/src/IECoreScene/MotionPrimitive.cpp deleted file mode 100644 index ee72208da5..0000000000 --- a/src/IECoreScene/MotionPrimitive.cpp +++ /dev/null @@ -1,204 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-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 Image Engine Design 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. -// -////////////////////////////////////////////////////////////////////////// - -#include "IECoreScene/MotionPrimitive.h" - -#include "IECore/MurmurHash.h" - -#include "boost/format.hpp" - -#include - -using namespace IECore; -using namespace IECoreScene; -using namespace std; - -static IndexedIO::EntryID g_snapshotsEntry("snapshots"); -static IndexedIO::EntryID g_primitiveEntry("primitive"); -static IndexedIO::EntryID g_timeEntry("time"); - -const unsigned int MotionPrimitive::m_ioVersion = 0; -IE_CORE_DEFINEOBJECTTYPEDESCRIPTION( MotionPrimitive ); - -MotionPrimitive::MotionPrimitive() -{ -} - -MotionPrimitive::~MotionPrimitive() -{ -} - -void MotionPrimitive::addSnapshot( float time, PrimitivePtr primitive ) -{ - m_snapshots[time] = primitive; -} - -void MotionPrimitive::removeSnapshot( float time ) -{ - m_snapshots.erase( time ); -} - -void MotionPrimitive::removeSnapshot( PrimitivePtr primitive ) -{ - SnapshotMap::iterator it=m_snapshots.begin(); - while( it!=m_snapshots.end() ) - { - SnapshotMap::iterator next = it; next++; - if( it->second==primitive ) - { - m_snapshots.erase( it ); - } - it = next; - } -} - -const MotionPrimitive::SnapshotMap &MotionPrimitive::snapshots() const -{ - return m_snapshots; -} - - -MotionPrimitive::SnapshotMap &MotionPrimitive::snapshots() -{ - return m_snapshots; -} - -Imath::Box3f MotionPrimitive::bound() const -{ - Imath::Box3f result; - for( SnapshotMap::const_iterator it=m_snapshots.begin(); it!=m_snapshots.end(); it++ ) - { - result.extendBy( it->second->bound() ); - } - return result; -} - -//////////////////////////////////////////////////////////////////////////////////////////// -// Object interface -//////////////////////////////////////////////////////////////////////////////////////////// - -void MotionPrimitive::copyFrom( const Object *other, Object::CopyContext *context ) -{ - VisibleRenderable::copyFrom( other, context ); - const MotionPrimitive *tOther = static_cast( other ); - m_snapshots.clear(); - for( SnapshotMap::const_iterator it=tOther->m_snapshots.begin(); it!=tOther->m_snapshots.end(); it++ ) - { - m_snapshots[it->first] = context->copy( it->second.get() ); - } -} - -void MotionPrimitive::save( IECore::Object::SaveContext *context ) const -{ - VisibleRenderable::save( context ); - IndexedIOPtr container = context->container( staticTypeName(), m_ioVersion ); - IndexedIOPtr snapshots = container->subdirectory( g_snapshotsEntry, IndexedIO::CreateIfMissing ); - - int i = 0; - for( SnapshotMap::const_iterator it=m_snapshots.begin(); it!=m_snapshots.end(); it++ ) - { - string is = str( boost::format( "%d" ) % i ); - IndexedIOPtr snapshot = snapshots->subdirectory( is, IndexedIO::CreateIfMissing ); - snapshot->write( g_timeEntry, it->first ); - context->save( it->second.get(), snapshot.get(), g_primitiveEntry ); - i++; - } -} - -void MotionPrimitive::load( IECore::Object::LoadContextPtr context ) -{ - VisibleRenderable::load( context ); - unsigned int v = m_ioVersion; - ConstIndexedIOPtr container = context->container( staticTypeName(), v ); - ConstIndexedIOPtr snapshots = container->subdirectory( g_snapshotsEntry ); - m_snapshots.clear(); - IndexedIO::EntryIDList names; - snapshots->entryIds( names, IndexedIO::Directory ); - IndexedIO::EntryIDList::const_iterator it; - for( it=names.begin(); it!=names.end(); it++ ) - { - ConstIndexedIOPtr snapshot = snapshots->subdirectory( *it ); - float t; - snapshot->read( g_timeEntry, t ); - m_snapshots[t] = context->load( snapshot.get(), g_primitiveEntry ); - } -} - -bool MotionPrimitive::isEqualTo( const Object *other ) const -{ - if( !VisibleRenderable::isEqualTo( other ) ) - { - return false; - } - const MotionPrimitive *tOther = static_cast( other ); - if( tOther->m_snapshots.size()!=m_snapshots.size() ) - { - return false; - } - SnapshotMap::const_iterator tIt = m_snapshots.begin(); - SnapshotMap::const_iterator oIt = tOther->m_snapshots.begin(); - while( tIt!=m_snapshots.end() ) - { - if( tIt->first!=oIt->first ) - { - return false; - } - if( !tIt->second->isEqualTo( oIt->second.get() ) ) - { - return false; - } - tIt++; - oIt++; - } - return true; -} - -void MotionPrimitive::memoryUsage( Object::MemoryAccumulator &a ) const -{ - VisibleRenderable::memoryUsage( a ); - for( SnapshotMap::const_iterator it=m_snapshots.begin(); it!=m_snapshots.end(); it++ ) - { - a.accumulate( it->second.get() ); - } -} - -void MotionPrimitive::hash( MurmurHash &h ) const -{ - VisibleRenderable::hash( h ); - for( SnapshotMap::const_iterator it=m_snapshots.begin(); it!=m_snapshots.end(); it++ ) - { - h.append( it->first ); - it->second->hash( h ); - } -} diff --git a/src/IECoreScene/TypedPrimitiveParameter.cpp b/src/IECoreScene/TypedPrimitiveParameter.cpp index f8e2ae7358..feae988ad0 100644 --- a/src/IECoreScene/TypedPrimitiveParameter.cpp +++ b/src/IECoreScene/TypedPrimitiveParameter.cpp @@ -36,7 +36,6 @@ #include "IECoreScene/CurvesPrimitive.h" #include "IECoreScene/MeshPrimitive.h" -#include "IECoreScene/MotionPrimitive.h" #include "IECoreScene/PointsPrimitive.h" #include "IECoreScene/Primitive.h" @@ -45,13 +44,11 @@ namespace IECore { -IECORE_RUNTIMETYPED_DEFINETEMPLATESPECIALISATION( IECoreScene::MotionPrimitiveParameter, IECoreScene::MotionPrimitiveParameterTypeId ); IECORE_RUNTIMETYPED_DEFINETEMPLATESPECIALISATION( IECoreScene::PrimitiveParameter, IECoreScene::PrimitiveParameterTypeId ); IECORE_RUNTIMETYPED_DEFINETEMPLATESPECIALISATION( IECoreScene::MeshPrimitiveParameter, IECoreScene::MeshPrimitiveParameterTypeId ); IECORE_RUNTIMETYPED_DEFINETEMPLATESPECIALISATION( IECoreScene::CurvesPrimitiveParameter, IECoreScene::CurvesPrimitiveParameterTypeId ); IECORE_RUNTIMETYPED_DEFINETEMPLATESPECIALISATION( IECoreScene::PointsPrimitiveParameter, IECoreScene::PointsPrimitiveParameterTypeId ); -template class TypedObjectParameter; template class TypedObjectParameter; template class TypedObjectParameter; template class TypedObjectParameter; diff --git a/src/IECoreScene/bindings/IECoreScene.cpp b/src/IECoreScene/bindings/IECoreScene.cpp index 78c7c1d17e..88aa76748b 100644 --- a/src/IECoreScene/bindings/IECoreScene.cpp +++ b/src/IECoreScene/bindings/IECoreScene.cpp @@ -62,7 +62,6 @@ #include "MeshPrimitiveShrinkWrapOpBinding.h" #include "MeshVertexReorderOpBinding.h" #include "MixSmoothSkinningWeightsOpBinding.h" -#include "MotionPrimitiveBinding.h" #include "NParticleReaderBinding.h" #include "NURBSPrimitiveBinding.h" #include "NormalizeSmoothSkinningWeightsOpBinding.h" @@ -128,7 +127,6 @@ BOOST_PYTHON_MODULE(_IECoreScene) bindShaderNetworkAlgo(); bindPrimitiveOp(); bindMeshPrimitive(); - bindMotionPrimitive(); bindCamera(); bindNURBSPrimitive(); bindMeshPrimitiveBuilder(); diff --git a/src/IECoreScene/bindings/MotionPrimitiveBinding.cpp b/src/IECoreScene/bindings/MotionPrimitiveBinding.cpp deleted file mode 100644 index eb0882c574..0000000000 --- a/src/IECoreScene/bindings/MotionPrimitiveBinding.cpp +++ /dev/null @@ -1,137 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2010, 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 Image Engine Design 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. -// -////////////////////////////////////////////////////////////////////////// - -#include "boost/python.hpp" - -#include "MotionPrimitiveBinding.h" - -#include "IECoreScene/MotionPrimitive.h" - -#include "IECorePython/RunTimeTypedBinding.h" - -using namespace boost::python; -using namespace IECore; -using namespace IECorePython; -using namespace IECoreScene; - -namespace IECoreSceneModule -{ - -static unsigned int len( MotionPrimitive &p ) -{ - return p.snapshots().size(); -} - -static PrimitivePtr getItem( MotionPrimitive &p, float t ) -{ - MotionPrimitive::SnapshotMap::const_iterator it = p.snapshots().find( t ); - if( it==p.snapshots().end() ) - { - throw std::out_of_range( "Bad index" ); - } - return it->second; -} - -static void setItem( MotionPrimitive &p, float t, const PrimitivePtr v ) -{ - p.snapshots()[t] = v; -} - -static bool contains( MotionPrimitive &p, float t ) -{ - return p.snapshots().find( t )!=p.snapshots().end(); -} - -static void delItem( MotionPrimitive &p, float t ) -{ - MotionPrimitive::SnapshotMap::iterator it = p.snapshots().find( t ); - if( it==p.snapshots().end() ) - { - throw std::out_of_range( "Bad index" ); - } - p.snapshots().erase( it ); -} - -static boost::python::list keys( MotionPrimitive &p ) -{ - boost::python::list result; - const MotionPrimitive::SnapshotMap &s = p.snapshots(); - MotionPrimitive::SnapshotMap::const_iterator it; - for( it = s.begin(); it!=s.end(); it++ ) - { - result.append( it->first ); - } - return result; -} - -static boost::python::list values( MotionPrimitive &p ) -{ - boost::python::list result; - const MotionPrimitive::SnapshotMap &s = p.snapshots(); - MotionPrimitive::SnapshotMap::const_iterator it; - for( it = s.begin(); it!=s.end(); it++ ) - { - result.append( it->second ); - } - return result; -} - -static boost::python::list items( MotionPrimitive &p ) -{ - boost::python::list result; - const MotionPrimitive::SnapshotMap &s = p.snapshots(); - MotionPrimitive::SnapshotMap::const_iterator it; - for( it = s.begin(); it!=s.end(); it++ ) - { - result.append( boost::python::make_tuple( it->first, it->second ) ); - } - return result; -} - -void bindMotionPrimitive() -{ - RunTimeTypedClass() - .def( init<>() ) - .def( "__len__", &len ) - .def( "__getitem__", &getItem ) - .def( "__setitem__", &setItem ) - .def( "__delitem__", &delItem ) - .def( "__contains__", &contains ) - .def( "keys", &keys ) - .def( "values", &values ) - .def( "items", &items ) - ; -} - -} diff --git a/src/IECoreScene/bindings/MotionPrimitiveBinding.h b/src/IECoreScene/bindings/MotionPrimitiveBinding.h deleted file mode 100644 index 8771641afa..0000000000 --- a/src/IECoreScene/bindings/MotionPrimitiveBinding.h +++ /dev/null @@ -1,43 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2010, 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 Image Engine Design 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 IECORESCENEMODULE_MOTIONPRIMITIVEBINDING_H -#define IECORESCENEMODULE_MOTIONPRIMITIVEBINDING_H - -namespace IECoreSceneModule -{ -void bindMotionPrimitive(); -} - -#endif // IECORESCENEMODULE_MOTIONPRIMITIVEBINDING_H diff --git a/src/IECoreScene/bindings/TypedObjectParameterBinding.cpp b/src/IECoreScene/bindings/TypedObjectParameterBinding.cpp index dd25d249a5..f3be31acd6 100644 --- a/src/IECoreScene/bindings/TypedObjectParameterBinding.cpp +++ b/src/IECoreScene/bindings/TypedObjectParameterBinding.cpp @@ -43,7 +43,6 @@ #include "IECoreScene/Shader.h" #include "IECoreScene/VisibleRenderable.h" #include "IECoreScene/SmoothSkinningData.h" -#include "IECoreScene/MotionPrimitive.h" #include "IECoreScene/Primitive.h" #include "IECoreScene/MeshPrimitive.h" #include "IECoreScene/CurvesPrimitive.h" @@ -95,7 +94,6 @@ void IECoreSceneModule::bindTypedObjectParameter() ::bindTypedObjectParameter(); ::bindTypedObjectParameter(); - ::bindTypedObjectParameter(); ::bindTypedObjectParameter(); ::bindTypedObjectParameter(); ::bindTypedObjectParameter(); diff --git a/test/IECoreScene/All.py b/test/IECoreScene/All.py index 898fcf896e..9a34a90410 100644 --- a/test/IECoreScene/All.py +++ b/test/IECoreScene/All.py @@ -49,7 +49,6 @@ from Shader import * from RemovePrimitiveVariables import * from RenamePrimitiveVariables import * -from MotionPrimitive import * from Camera import * from NURBS import * from PrimitiveEvaluator import * diff --git a/test/IECoreScene/MotionPrimitive.py b/test/IECoreScene/MotionPrimitive.py deleted file mode 100644 index c9748079a8..0000000000 --- a/test/IECoreScene/MotionPrimitive.py +++ /dev/null @@ -1,115 +0,0 @@ -########################################################################## -# -# Copyright (c) 2007-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 Image Engine Design 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 IECoreScene - -class TestMotionPrimitive( unittest.TestCase ) : - - def test( self ) : - - m = IECoreScene.MotionPrimitive() - self.assertTrue( m.isInstanceOf( "MotionPrimitive" ) ) - self.assertTrue( m.isInstanceOf( "VisibleRenderable" ) ) - - self.assertEqual( m.keys(), [] ) - self.assertEqual( m.values(), [] ) - self.assertEqual( len( m ), 0 ) - - self.assertRaises( Exception, m.__setitem__, "notAFloat", IECoreScene.PointsPrimitive( 1 ) ) - - m[0] = IECoreScene.PointsPrimitive( 1 ) - self.assertEqual( len( m ), 1 ) - self.assertEqual( m.keys(), [ 0 ] ) - self.assertEqual( m.values(), [ IECoreScene.PointsPrimitive( 1 ) ] ) - - m[1] = IECoreScene.PointsPrimitive( 1 ) - self.assertEqual( len( m ), 2 ) - self.assertEqual( m.keys(), [ 0, 1 ] ) - self.assertEqual( m.values(), [ IECoreScene.PointsPrimitive( 1 ), IECoreScene.PointsPrimitive( 1 ) ] ) - - iface = IECore.IndexedIO.create( os.path.join( "test", "motionPrimitive.fio" ), IECore.IndexedIO.OpenMode.Write ) - m.save( iface, "test" ) - - mm = IECore.Object.load( iface, "test" ) - self.assertEqual( m, mm ) - - mmm = m.copy() - self.assertEqual( m, mmm ) - - del m[0] - self.assertEqual( len( m ), 1 ) - self.assertEqual( m.keys(), [ 1 ] ) - self.assertEqual( m.values(), [ IECoreScene.PointsPrimitive( 1 ) ] ) - - del m[1] - self.assertEqual( m.keys(), [] ) - self.assertEqual( m.values(), [] ) - self.assertEqual( len( m ), 0 ) - - def testItems( self ) : - - m = IECoreScene.MotionPrimitive() - m[0] = IECoreScene.PointsPrimitive( 1 ) - m[1] = IECoreScene.PointsPrimitive( 2 ) - self.assertEqual( m.items(), [ ( 0, IECoreScene.PointsPrimitive( 1 ) ), ( 1, IECoreScene.PointsPrimitive( 2 ) ) ] ) - - def testHash( self ) : - - m = IECoreScene.MotionPrimitive() - m2 = IECoreScene.MotionPrimitive() - self.assertEqual( m.hash(), m2.hash() ) - - m[0] = IECoreScene.SpherePrimitive() - self.assertNotEqual( m.hash(), m2.hash() ) - - m2[0] = IECoreScene.SpherePrimitive() - self.assertEqual( m.hash(), m2.hash() ) - - m[1] = IECoreScene.SpherePrimitive() - self.assertNotEqual( m.hash(), m2.hash() ) - - m2[2] = IECoreScene.SpherePrimitive() - self.assertNotEqual( m.hash(), m2.hash() ) - - def tearDown( self ) : - - if os.path.isfile( os.path.join( "test", "motionPrimitive.fio" ) ): - os.remove( os.path.join( "test", "motionPrimitive.fio" ) ) - -if __name__ == "__main__": - unittest.main() From 13d4c8aa02f1a7624911b17f04316e7657d96369 Mon Sep 17 00:00:00 2001 From: John Haddon Date: Tue, 8 Jul 2025 11:52:25 +0100 Subject: [PATCH 15/15] Remove StateRenderable Like PreWorldRenderable, this doesn't make a distinction worth having in Gaffer's scene representation. In fact, CoordinateSystems are treated as objects in Gaffer, and only Shaders are treated as attribute state. --- Changes | 2 +- include/IECoreScene/CoordinateSystem.h | 6 +- include/IECoreScene/Shader.h | 6 +- include/IECoreScene/StateRenderable.h | 66 --------------- include/IECoreScene/TypeIds.h | 4 +- include/IECoreScene/TypedObjectParameter.h | 3 - src/IECoreScene/CoordinateSystem.cpp | 12 +-- src/IECoreScene/Shader.cpp | 12 +-- src/IECoreScene/StateRenderable.cpp | 84 ------------------- src/IECoreScene/TypedObjectParameter.cpp | 3 - src/IECoreScene/bindings/IECoreScene.cpp | 2 - .../bindings/StateRenderableBinding.cpp | 58 ------------- .../bindings/StateRenderableBinding.h | 43 ---------- .../bindings/TypedObjectParameterBinding.cpp | 2 - 14 files changed, 21 insertions(+), 282 deletions(-) delete mode 100644 include/IECoreScene/StateRenderable.h delete mode 100644 src/IECoreScene/StateRenderable.cpp delete mode 100644 src/IECoreScene/bindings/StateRenderableBinding.cpp delete mode 100644 src/IECoreScene/bindings/StateRenderableBinding.h diff --git a/Changes b/Changes index a1f8898aef..2b7dc19b6c 100644 --- a/Changes +++ b/Changes @@ -17,7 +17,7 @@ Breaking Changes - Font : Removed `meshGroup()` method. - Options, Group, Transform, MatrixTransform, MatrixMotionTransform, AttributeState, Light, MotionPrimitive : Removed. - CurveExtrudeOp, IDXReader : Removed. -- PreWorldRenderable : Removed. All derived classes now derive directly from Renderable. +- PreWorldRenderable, StateRenderable : Removed. All derived classes now derive directly from Renderable. - Renderer, AttributeBlock, EditBlock, MotionBlock, TransformBlock, WorldBlock : Removed. - IECoreHoudini : Removed. - IECoreMaya : Removed. diff --git a/include/IECoreScene/CoordinateSystem.h b/include/IECoreScene/CoordinateSystem.h index 2c1e12bdfc..fc627f4393 100644 --- a/include/IECoreScene/CoordinateSystem.h +++ b/include/IECoreScene/CoordinateSystem.h @@ -36,21 +36,21 @@ #define IECORESCENE_COORDINATESYSTEM_H #include "IECoreScene/Export.h" -#include "IECoreScene/StateRenderable.h" +#include "IECoreScene/Renderable.h" namespace IECoreScene { /// Allows the specification of coordinate systems to Renderers. /// \ingroup renderingGroup -class IECORESCENE_API CoordinateSystem : public StateRenderable +class IECORESCENE_API CoordinateSystem : public Renderable { public: CoordinateSystem( const std::string &name = "unspecified" ); ~CoordinateSystem() override; - IE_CORE_DECLAREEXTENSIONOBJECT( CoordinateSystem, CoordinateSystemTypeId, StateRenderable ); + IE_CORE_DECLAREEXTENSIONOBJECT( CoordinateSystem, CoordinateSystemTypeId, Renderable ); const std::string &getName() const; void setName( const std::string &name ); diff --git a/include/IECoreScene/Shader.h b/include/IECoreScene/Shader.h index 9abf500a08..8d8b952a39 100644 --- a/include/IECoreScene/Shader.h +++ b/include/IECoreScene/Shader.h @@ -36,14 +36,14 @@ #define IECORESCENE_SHADER_H #include "IECoreScene/Export.h" -#include "IECoreScene/StateRenderable.h" +#include "IECoreScene/Renderable.h" namespace IECoreScene { /// A class to represent shaders. /// \ingroup renderingGroup -class IECORESCENE_API Shader : public StateRenderable +class IECORESCENE_API Shader : public Renderable { public: @@ -56,7 +56,7 @@ class IECORESCENE_API Shader : public StateRenderable ~Shader() override; - IE_CORE_DECLAREEXTENSIONOBJECT( Shader, ShaderTypeId, StateRenderable ); + IE_CORE_DECLAREEXTENSIONOBJECT( Shader, ShaderTypeId, Renderable ); const std::string &getName() const; void setName( const std::string &name ); diff --git a/include/IECoreScene/StateRenderable.h b/include/IECoreScene/StateRenderable.h deleted file mode 100644 index 5816cd3aa5..0000000000 --- a/include/IECoreScene/StateRenderable.h +++ /dev/null @@ -1,66 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2011, 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 Image Engine Design 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 IECORESCENE_STATERENDERABLE_H -#define IECORESCENE_STATERENDERABLE_H - -#include "IECoreScene/Export.h" -#include "IECoreScene/Renderable.h" - -namespace IECoreScene -{ - -/// The StateRenderable class is an abstract base class for all Renderables -/// which modify RendererState (current attributes, shaders, transforms etc) -/// but do not cause any objects to be rendered. -/// \ingroup renderingGroup -class IECORESCENE_API StateRenderable : public Renderable -{ - public: - - StateRenderable(); - ~StateRenderable() override; - - IE_CORE_DECLAREEXTENSIONOBJECT( StateRenderable, StateRenderableTypeId, Renderable ); - - private: - - static const unsigned int m_ioVersion; -}; - -IE_CORE_DECLAREPTR( StateRenderable ); - -} - -#endif // IECORESCENE_STATERENDERABLE_H diff --git a/include/IECoreScene/TypeIds.h b/include/IECoreScene/TypeIds.h index 50e37d15c6..fd7fba984f 100644 --- a/include/IECoreScene/TypeIds.h +++ b/include/IECoreScene/TypeIds.h @@ -59,11 +59,11 @@ enum TypeId GroupTypeId = 108016, // Obsolete, available for reuse AttributeStateTypeId = 108017, // Obsolete, available for reuse VisibleRenderableTypeId = 108018, - StateRenderableTypeId = 108019, + StateRenderableTypeId = 108019, // Obsolete, available for reuse OBJReaderTypeId = 108020, PointNormalsOpTypeId = 108021, // Obsolete, available for reuse PointDensitiesOpTypeId = 108022, // Obsolete, available for reuse - StateRenderableParameterTypeId = 108023, + StateRenderableParameterTypeId = 108023, // Obsolete, available for reuse AttributeStateParameterTypeId = 108024, // Obsolete, available for reuse ShaderParameterTypeId = 108025, TransformParameterTypeId = 108026, // Obsolete, available for reuse diff --git a/include/IECoreScene/TypedObjectParameter.h b/include/IECoreScene/TypedObjectParameter.h index 85571bf8b9..3f2ca49831 100644 --- a/include/IECoreScene/TypedObjectParameter.h +++ b/include/IECoreScene/TypedObjectParameter.h @@ -41,19 +41,16 @@ namespace IECoreScene { IE_CORE_FORWARDDECLARE( Renderable ) -IE_CORE_FORWARDDECLARE( StateRenderable ) IE_CORE_FORWARDDECLARE( Shader ) IE_CORE_FORWARDDECLARE( VisibleRenderable ) IE_CORE_FORWARDDECLARE( SmoothSkinningData ) typedef IECore::TypedObjectParameter RenderableParameter; -typedef IECore::TypedObjectParameter StateRenderableParameter; typedef IECore::TypedObjectParameter ShaderParameter; typedef IECore::TypedObjectParameter VisibleRenderableParameter; typedef IECore::TypedObjectParameter SmoothSkinningDataParameter; IE_CORE_DECLAREPTR( RenderableParameter ); -IE_CORE_DECLAREPTR( StateRenderableParameter ); IE_CORE_DECLAREPTR( ShaderParameter ); IE_CORE_DECLAREPTR( VisibleRenderableParameter ); IE_CORE_DECLAREPTR( SmoothSkinningDataParameter ); diff --git a/src/IECoreScene/CoordinateSystem.cpp b/src/IECoreScene/CoordinateSystem.cpp index 6f05a020d2..e5e27833a6 100644 --- a/src/IECoreScene/CoordinateSystem.cpp +++ b/src/IECoreScene/CoordinateSystem.cpp @@ -66,7 +66,7 @@ void CoordinateSystem::setName( const std::string &name ) bool CoordinateSystem::isEqualTo( const Object *other ) const { - if( !StateRenderable::isEqualTo( other ) ) + if( !Renderable::isEqualTo( other ) ) { return false; } @@ -80,27 +80,27 @@ bool CoordinateSystem::isEqualTo( const Object *other ) const void CoordinateSystem::memoryUsage( Object::MemoryAccumulator &a ) const { - StateRenderable::memoryUsage( a ); + Renderable::memoryUsage( a ); a.accumulate( m_name.capacity() + sizeof( m_name ) ); } void CoordinateSystem::copyFrom( const Object *other, CopyContext *context ) { - StateRenderable::copyFrom( other, context ); + Renderable::copyFrom( other, context ); const CoordinateSystem *c = static_cast( other ); m_name = c->m_name; } void CoordinateSystem::save( SaveContext *context ) const { - StateRenderable::save( context ); + Renderable::save( context ); IndexedIOPtr container = context->container( staticTypeName(), m_ioVersion ); container->write( g_nameEntry, m_name ); } void CoordinateSystem::load( LoadContextPtr context ) { - StateRenderable::load( context ); + Renderable::load( context ); unsigned int v = m_ioVersion; ConstIndexedIOPtr container = context->container( staticTypeName(), v ); container->read( g_nameEntry, m_name ); @@ -108,6 +108,6 @@ void CoordinateSystem::load( LoadContextPtr context ) void CoordinateSystem::hash( MurmurHash &h ) const { - StateRenderable::hash( h ); + Renderable::hash( h ); h.append( m_name ); } diff --git a/src/IECoreScene/Shader.cpp b/src/IECoreScene/Shader.cpp index 2ab1474109..2c25c555a3 100644 --- a/src/IECoreScene/Shader.cpp +++ b/src/IECoreScene/Shader.cpp @@ -103,7 +103,7 @@ const CompoundData *Shader::parametersData() const bool Shader::isEqualTo( const Object *other ) const { - if( !StateRenderable::isEqualTo( other ) ) + if( !Renderable::isEqualTo( other ) ) { return false; } @@ -121,7 +121,7 @@ bool Shader::isEqualTo( const Object *other ) const void Shader::memoryUsage( Object::MemoryAccumulator &a ) const { - StateRenderable::memoryUsage( a ); + Renderable::memoryUsage( a ); a.accumulate( m_name.capacity() ); a.accumulate( m_type.capacity() ); a.accumulate( m_parameters.get() ); @@ -129,7 +129,7 @@ void Shader::memoryUsage( Object::MemoryAccumulator &a ) const void Shader::copyFrom( const Object *other, CopyContext *context ) { - StateRenderable::copyFrom( other, context ); + Renderable::copyFrom( other, context ); const Shader *s = static_cast( other ); m_name = s->m_name; m_type = s->m_type; @@ -138,7 +138,7 @@ void Shader::copyFrom( const Object *other, CopyContext *context ) void Shader::save( SaveContext *context ) const { - StateRenderable::save( context ); + Renderable::save( context ); IndexedIOPtr container = context->container( staticTypeName(), m_ioVersion ); container->write( g_nameEntry, m_name ); container->write( g_typeEntry, m_type ); @@ -147,7 +147,7 @@ void Shader::save( SaveContext *context ) const void Shader::load( LoadContextPtr context ) { - StateRenderable::load( context ); + Renderable::load( context ); unsigned int v = m_ioVersion; ConstIndexedIOPtr container = context->container( staticTypeName(), v ); container->read( g_nameEntry, m_name ); @@ -157,7 +157,7 @@ void Shader::load( LoadContextPtr context ) void Shader::hash( MurmurHash &h ) const { - StateRenderable::hash( h ); + Renderable::hash( h ); h.append( m_name ); h.append( m_type ); m_parameters->hash( h ); diff --git a/src/IECoreScene/StateRenderable.cpp b/src/IECoreScene/StateRenderable.cpp deleted file mode 100644 index 9ce41c58c1..0000000000 --- a/src/IECoreScene/StateRenderable.cpp +++ /dev/null @@ -1,84 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2011, 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 Image Engine Design 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. -// -////////////////////////////////////////////////////////////////////////// - -#include "IECoreScene/StateRenderable.h" - -using namespace IECore; -using namespace IECoreScene; - -IE_CORE_DEFINEOBJECTTYPEDESCRIPTION(StateRenderable); - -const unsigned int StateRenderable::m_ioVersion = 0; - -StateRenderable::StateRenderable() -{ -} - -StateRenderable::~StateRenderable() -{ -} - -void StateRenderable::copyFrom( const Object *other, CopyContext *context ) -{ - Renderable::copyFrom( other, context ); -} - -void StateRenderable::save( SaveContext *context ) const -{ - Renderable::save( context ); -} - -void StateRenderable::load( LoadContextPtr context ) -{ - Renderable::load( context ); -} - -bool StateRenderable::isEqualTo( const Object *other ) const -{ - if( !Renderable::isEqualTo( other ) ) - { - return false; - } - return true; -} - -void StateRenderable::memoryUsage( Object::MemoryAccumulator &a ) const -{ - Renderable::memoryUsage( a ); -} - -void StateRenderable::hash( MurmurHash &h ) const -{ - Renderable::hash( h ); -} diff --git a/src/IECoreScene/TypedObjectParameter.cpp b/src/IECoreScene/TypedObjectParameter.cpp index 97c750ca4e..aacb13edfd 100644 --- a/src/IECoreScene/TypedObjectParameter.cpp +++ b/src/IECoreScene/TypedObjectParameter.cpp @@ -37,7 +37,6 @@ #include "IECoreScene/Renderable.h" #include "IECoreScene/Shader.h" #include "IECoreScene/SmoothSkinningData.h" -#include "IECoreScene/StateRenderable.h" #include "IECoreScene/VisibleRenderable.h" #include "IECore/TypedObjectParameter.inl" @@ -46,13 +45,11 @@ namespace IECore { IECORE_RUNTIMETYPED_DEFINETEMPLATESPECIALISATION( IECoreScene::RenderableParameter, IECoreScene::RenderableParameterTypeId ); -IECORE_RUNTIMETYPED_DEFINETEMPLATESPECIALISATION( IECoreScene::StateRenderableParameter, IECoreScene::StateRenderableParameterTypeId ); IECORE_RUNTIMETYPED_DEFINETEMPLATESPECIALISATION( IECoreScene::ShaderParameter, IECoreScene::ShaderParameterTypeId ); IECORE_RUNTIMETYPED_DEFINETEMPLATESPECIALISATION( IECoreScene::VisibleRenderableParameter, IECoreScene::VisibleRenderableParameterTypeId ); IECORE_RUNTIMETYPED_DEFINETEMPLATESPECIALISATION( IECoreScene::SmoothSkinningDataParameter, IECoreScene::SmoothSkinningDataParameterTypeId ); template class TypedObjectParameter; -template class TypedObjectParameter; template class TypedObjectParameter; template class TypedObjectParameter; template class TypedObjectParameter; diff --git a/src/IECoreScene/bindings/IECoreScene.cpp b/src/IECoreScene/bindings/IECoreScene.cpp index 88aa76748b..b85d5318c9 100644 --- a/src/IECoreScene/bindings/IECoreScene.cpp +++ b/src/IECoreScene/bindings/IECoreScene.cpp @@ -94,7 +94,6 @@ #include "SmoothSmoothSkinningWeightsOpBinding.h" #include "SpherePrimitiveBinding.h" #include "SpherePrimitiveEvaluatorBinding.h" -#include "StateRenderableBinding.h" #include "TransferSmoothSkinningWeightsOpBinding.h" #include "TransformOpBinding.h" #include "TriangulateOpBinding.h" @@ -115,7 +114,6 @@ BOOST_PYTHON_MODULE(_IECoreScene) bindParticleReader(); bindPDCParticleReader(); bindRenderable(); - bindStateRenderable(); bindVisibleRenderable(); bindParticleWriter(); bindPDCParticleWriter(); diff --git a/src/IECoreScene/bindings/StateRenderableBinding.cpp b/src/IECoreScene/bindings/StateRenderableBinding.cpp deleted file mode 100644 index 8abb2d00e0..0000000000 --- a/src/IECoreScene/bindings/StateRenderableBinding.cpp +++ /dev/null @@ -1,58 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2010, 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 Image Engine Design 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. -// -////////////////////////////////////////////////////////////////////////// - -// This include needs to be the very first to prevent problems with warnings -// regarding redefinition of _POSIX_C_SOURCE -#include "boost/python.hpp" - -#include "StateRenderableBinding.h" - -#include "IECoreScene/StateRenderable.h" - -#include "IECorePython/RunTimeTypedBinding.h" - -using namespace boost::python; -using namespace IECorePython; -using namespace IECoreScene; - -namespace IECoreSceneModule -{ - -void bindStateRenderable() -{ - RunTimeTypedClass( "An abstract class to define objects which are renderable but which only modify renderer state." ) - ; -} - -} diff --git a/src/IECoreScene/bindings/StateRenderableBinding.h b/src/IECoreScene/bindings/StateRenderableBinding.h deleted file mode 100644 index d1bb0ca438..0000000000 --- a/src/IECoreScene/bindings/StateRenderableBinding.h +++ /dev/null @@ -1,43 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2007-2010, 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 Image Engine Design 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 IECORESCENEMODULE_STATERENDERABLEBINDING_H -#define IECORESCENEMODULE_STATERENDERABLEBINDING_H - -namespace IECoreSceneModule -{ -void bindStateRenderable(); -} - -#endif // IECORESCENEMODULE_STATERENDERABLEBINDING_H diff --git a/src/IECoreScene/bindings/TypedObjectParameterBinding.cpp b/src/IECoreScene/bindings/TypedObjectParameterBinding.cpp index f3be31acd6..8cb42b2d01 100644 --- a/src/IECoreScene/bindings/TypedObjectParameterBinding.cpp +++ b/src/IECoreScene/bindings/TypedObjectParameterBinding.cpp @@ -39,7 +39,6 @@ #include "IECoreScene/TypedObjectParameter.h" #include "IECoreScene/TypedPrimitiveParameter.h" #include "IECoreScene/Renderable.h" -#include "IECoreScene/StateRenderable.h" #include "IECoreScene/Shader.h" #include "IECoreScene/VisibleRenderable.h" #include "IECoreScene/SmoothSkinningData.h" @@ -89,7 +88,6 @@ void bindTypedObjectParameter() void IECoreSceneModule::bindTypedObjectParameter() { ::bindTypedObjectParameter(); - ::bindTypedObjectParameter(); ::bindTypedObjectParameter(); ::bindTypedObjectParameter(); ::bindTypedObjectParameter();