@ -30,8 +30,8 @@ from magnum import *
from magnum import scenetools , trade
import magnum
class FlattenTransformation Hierarchy( unittest . TestCase ) :
def test_2d ( self ) :
class Hierarchy ( unittest . TestCase ) :
def test_absolute_field_transformations 2d ( self ) :
# Static builds with non-static plugins cause assertions with non-owned
# array deleters used by PrimitiveImporter, skip in that case
if magnum . BUILD_STATIC :
@ -44,30 +44,14 @@ class FlattenTransformationHierarchy(unittest.TestCase):
scene = importer . scene ( 0 )
self . assertTrue ( scene . is_2d )
transformations = scenetools . flatten_transformation_hierarchy2d ( scene , trade . SceneField . MESH )
self . assertEqual ( len ( transformations ) , scene . field_size ( trade . SceneField . MESH ) )
self . assertEqual ( transformations [ 0 ] , Matrix3 . translation ( ( - 4.5 , - 3.0 ) ) )
transformations1 = scenetools . absolute_field_transformations2d ( scene , trade . SceneField . MESH )
transformations2 = scenetools . absolute_field_transformations2d ( scene , scene . field_id ( trade . SceneField . MESH ) )
self . assertEqual ( len ( transformations1 ) , scene . field_size ( trade . SceneField . MESH ) )
self . assertEqual ( len ( transformations2 ) , scene . field_size ( trade . SceneField . MESH ) )
self . assertEqual ( transformations1 [ 0 ] , Matrix3 . translation ( ( - 4.5 , - 3.0 ) ) )
self . assertEqual ( transformations2 [ 0 ] , Matrix3 . translation ( ( - 4.5 , - 3.0 ) ) )
def test_2d_field_id ( self ) :
# Static builds with non-static plugins cause assertions with non-owned
# array deleters used by PrimitiveImporter, skip in that case
if magnum . BUILD_STATIC :
self . skipTest ( " dynamic PrimitiveImporter doesn ' t work with a static build " )
# The only way to get a 2D scene is via PrimitiveImporter
importer = trade . ImporterManager ( ) . load_and_instantiate ( ' PrimitiveImporter ' )
importer . open_data ( containers . ArrayView ( ) )
scene = importer . scene ( 0 )
self . assertTrue ( scene . is_2d )
mesh_field = scene . field_id ( trade . SceneField . MESH )
transformations = scenetools . flatten_transformation_hierarchy2d ( scene , mesh_field )
self . assertEqual ( len ( transformations ) , scene . field_size ( mesh_field ) )
self . assertEqual ( transformations [ 0 ] , Matrix3 . translation ( ( - 4.5 , - 3.0 ) ) )
def test_3d ( self ) :
def test_absolute_field_transformations3d ( self ) :
# Static builds with non-static plugins cause assertions with non-owned
# array deleters used by PrimitiveImporter, skip in that case
if magnum . BUILD_STATIC :
@ -79,29 +63,14 @@ class FlattenTransformationHierarchy(unittest.TestCase):
scene = importer . scene ( 1 )
self . assertTrue ( scene . is_3d )
transformations = scenetools . flatten_transformation_hierarchy3d ( scene , trade . SceneField . MESH )
self . assertEqual ( len ( transformations ) , scene . field_size ( trade . SceneField . MESH ) )
self . assertEqual ( transformations [ 0 ] , Matrix4 . translation ( ( - 4.5 , - 3.0 , 0.0 ) ) )
def test_3d_field_id ( self ) :
# Static builds with non-static plugins cause assertions with non-owned
# array deleters used by PrimitiveImporter, skip in that case
if magnum . BUILD_STATIC :
self . skipTest ( " dynamic PrimitiveImporter doesn ' t work with a static build " )
importer = trade . ImporterManager ( ) . load_and_instantiate ( ' PrimitiveImporter ' )
importer . open_data ( containers . ArrayView ( ) )
scene = importer . scene ( 1 )
self . assertTrue ( scene . is_3d )
mesh_field = scene . field_id ( trade . SceneField . MESH )
transformations = scenetools . flatten_transformation_hierarchy3d ( scene , mesh_field )
self . assertEqual ( len ( transformations ) , scene . field_size ( mesh_field ) )
self . assertEqual ( transformations [ 0 ] , Matrix4 . translation ( ( - 4.5 , - 3.0 , 0.0 ) ) )
transformations1 = scenetools . absolute_field_transformations3d ( scene , trade . SceneField . MESH )
transformations2 = scenetools . absolute_field_transformations3d ( scene , scene . field_id ( trade . SceneField . MESH ) )
self . assertEqual ( len ( transformations1 ) , scene . field_size ( trade . SceneField . MESH ) )
self . assertEqual ( len ( transformations2 ) , scene . field_size ( trade . SceneField . MESH ) )
self . assertEqual ( transformations1 [ 0 ] , Matrix4 . translation ( ( - 4.5 , - 3.0 , 0.0 ) ) )
self . assertEqual ( transformations2 [ 0 ] , Matrix4 . translation ( ( - 4.5 , - 3.0 , 0.0 ) ) )
def test_field_not_found ( self ) :
def test_absolute_field_transformations_not_found ( self ) :
# Static builds with non-static plugins cause assertions with non-owned
# array deleters used by PrimitiveImporter, skip in that case
if magnum . BUILD_STATIC :
@ -113,15 +82,15 @@ class FlattenTransformationHierarchy(unittest.TestCase):
scene = importer . scene ( 0 )
with self . assertRaises ( KeyError ) :
scenetools . flatten_transformation_hierarchy 2d( scene , trade . SceneField . LIGHT )
scenetools . absolute_field_transformations 2d( scene , trade . SceneField . LIGHT )
with self . assertRaises ( KeyError ) :
scenetools . flatten_transformation_hierarchy 3d( scene , trade . SceneField . LIGHT )
scenetools . absolute_field_transformations 3d( scene , trade . SceneField . LIGHT )
with self . assertRaises ( IndexError ) :
scenetools . flatten_transformation_hierarchy 2d( scene , scene . field_count )
scenetools . absolute_field_transformations 2d( scene , scene . field_count )
with self . assertRaises ( IndexError ) :
scenetools . flatten_transformation_hierarchy 3d( scene , scene . field_count )
scenetools . absolute_field_transformations 3d( scene , scene . field_count )
def test_not_2d_not_3d ( self ) :
def test_absolute_field_transformations_ not_2d_not_3d ( self ) :
# Static builds with non-static plugins cause assertions with non-owned
# array deleters used by PrimitiveImporter, skip in that case
if magnum . BUILD_STATIC :
@ -136,15 +105,15 @@ class FlattenTransformationHierarchy(unittest.TestCase):
self . assertFalse ( scene3d . is_2d )
with self . assertRaisesRegex ( AssertionError , " the scene is not 2D " ) :
scenetools . flatten_transformation_hierarchy 2d( scene3d , trade . SceneField . MESH )
scenetools . absolute_field_transformations 2d( scene3d , trade . SceneField . MESH )
with self . assertRaisesRegex ( AssertionError , " the scene is not 2D " ) :
scenetools . flatten_transformation_hierarchy 2d( scene3d , scene2d . field_id ( trade . SceneField . MESH ) )
scenetools . absolute_field_transformations 2d( scene3d , scene2d . field_id ( trade . SceneField . MESH ) )
with self . assertRaisesRegex ( AssertionError , " the scene is not 3D " ) :
scenetools . flatten_transformation_hierarchy 3d( scene2d , trade . SceneField . MESH )
scenetools . absolute_field_transformations 3d( scene2d , trade . SceneField . MESH )
with self . assertRaisesRegex ( AssertionError , " the scene is not 3D " ) :
scenetools . flatten_transformation_hierarchy 3d( scene2d , scene3d . field_id ( trade . SceneField . MESH ) )
scenetools . absolute_field_transformations 3d( scene2d , scene3d . field_id ( trade . SceneField . MESH ) )
def test_no_hierarchy ( self ) :
def test_absolute_field_transformations_ no_hierarchy ( self ) :
# TODO implement once it's possible to create / import a scene without
# the parent field
pass