def test_export(self): filename = 'test_SSO_2incompatibleMats' xplaneFile = xplane_file.createFileFromBlenderLayerIndex(0) out = xplaneFile.write() self.assertLoggerErrors(3)
def test_export(self): filename = 'test_SSO_IllegalUsePanelTex' xplaneFile = xplane_file.createFileFromBlenderLayerIndex(0) out = xplaneFile.write() self.assertLoggerErrors(1)
def test_export(self): filename = 'test_IST_2Mats_VarSPEC' xplaneFile = xplane_file.createFileFromBlenderLayerIndex(0) out = xplaneFile.write() self.assertLoggerErrors(1)
def test_norm_met_on_two_drap_scen(self): out = xplane_file.createFileFromBlenderLayerIndex(7).write() self.assertFileOutputEqualsFixture( out, make_fixture_path(__dirname__, "test_norm_met_on_two_drap_scen", sub_dir="draped_spec_scenery"), filterLines)
def test_child_bone_matrices(self): identityMatrix = mathutils.Matrix.Identity(4) xplaneFile = xplane_file.createFileFromBlenderLayerIndex(0) cubeStatic = xplaneFile.getBoneByBlenderName('Cube_static') cubeStaticChildStatic = xplaneFile.getBoneByBlenderName('Cube_static.child_static') # FIXME: we are actually testing getBoneByBlenderName() here, should be in it's own test file self.assertIsNotNone(cubeStaticChildStatic) # no to the animated child cubeStaticChildAnimated = xplaneFile.getBoneByBlenderName('Cube_static.child_animated') preMatrix = cubeStaticChildAnimated.getPreAnimationMatrix() postMatrix = cubeStaticChildAnimated.getPostAnimationMatrix() bakeMatrix = cubeStaticChildAnimated.getBakeMatrixForMyAnimations() # pre matrix should be parents world matrix * inverted matrix relative to parent self.assertMatricesEqual(preMatrix, cubeStaticChildAnimated.blenderObject.parent.matrix_world * cubeStaticChildAnimated.blenderObject.matrix_parent_inverse) # post matrix should be world matrix self.assertMatricesEqual(postMatrix, cubeStaticChildAnimated.blenderObject.matrix_world,0.0001) # bake matrix should be inverted identity matrix * own preanimation matrix self.assertMatricesEqual(bakeMatrix, identityMatrix.inverted_safe() * preMatrix) cubeAnimated = xplaneFile.getBoneByBlenderName('Cube_animated') cubeAnimatedChildStatic = xplaneFile.getBoneByBlenderName('Cube_animated.child_static')
def test_export(self): filename = 'test_IST_2Mats_VarSPEC' xplaneFile = xplane_file.createFileFromBlenderLayerIndex(0) out = xplaneFile.write() self.assertEquals(len(logger.findErrors()), self.expected_logger_errors)
def test_scenery_glass_illegal(self): filename = 'test_scenery_glass_illegal' xplaneFile = xplane_file.createFileFromBlenderLayerIndex(7) out = xplaneFile.write() self.assertEqual(len(logger.findErrors()), 1) logger.clearMessages()
def test_export(self): filename = 'test_SSO_IllegalUsePanelTex' xplaneFile = xplane_file.createFileFromBlenderLayerIndex(0) out = xplaneFile.write() self.assertEquals(len(logger.findErrors()), self.expected_logger_errors)
def test_export(self): filename = 'test_SSO_2incompatibleDraped_Mats' xplaneFile = xplane_file.createFileFromBlenderLayerIndex(0) out = xplaneFile.write() self.assertEquals(len(logger.findErrors()), self.expected_logger_errors)
def test_autodetect_textures_export(self): def filterLines(line): return isinstance(line[0], str) and \ line[0].find('TEXTURE') == 0 xplaneFile = xplane_file.createFileFromBlenderLayerIndex(0) out = xplaneFile.write() self.assertLoggerErrors(1)
def exportLayer(self, layer, dest=None): xplaneFile = xplane_file.createFileFromBlenderLayerIndex(layer) out = xplaneFile.write() if dest: with open(os.path.join(TMP_DIR, dest + '.obj'), 'w') as tmp_file: tmp_file.write(out) return out
def exportLayer(self, layer, dest = None): xplaneFile = xplane_file.createFileFromBlenderLayerIndex(layer) out = xplaneFile.write() if dest: with open(os.path.join(TMP_DIR, dest + '.obj'), 'w') as tmp_file: tmp_file.write(out) return out
def test_create_files_from_single_layer(self): tmpDir = os.path.realpath(os.path.join(__file__, '../../tmp')) xplaneFile = xplane_file.createFileFromBlenderLayerIndex(0) # should contain 4 cubes self.assertEqual(len(xplaneFile.objects), 4) self.assertObjectsInXPlaneFile( xplaneFile, ['Cube', 'Cube.001', 'Cube.002', 'Cube.003']) self.assertXplaneFileHasBoneTree(xplaneFile, [ '0 ROOT', '1 Mesh: Cube', '2 Mesh: Cube.001', '3 Mesh: Cube.002', '4 Mesh: Cube.003' ]) xplaneFile2 = xplane_file.createFileFromBlenderLayerIndex(1) # should contain 2 cubes self.assertEqual(len(xplaneFile2.objects), 2) self.assertObjectsInXPlaneFile(xplaneFile2, ['Cube.004', 'Cube.005']) self.assertXplaneFileHasBoneTree( xplaneFile2, ['0 ROOT', '1 Mesh: Cube.005', '1 Mesh: Cube.004']) xplaneFile3 = xplane_file.createFileFromBlenderLayerIndex(2) # should contain 4 cubes self.assertEqual(len(xplaneFile3.objects), 5) self.assertObjectsInXPlaneFile( xplaneFile3, ['Cube_arm_root', 'Cube_Bone', 'Cube_Bone.child', 'Cube_Bone.001']) self.assertXplaneFileHasBoneTree(xplaneFile3, [ '0 ROOT', '1 Mesh: Cube_arm_root', '2 Armature: Armature', '3 Bone: Bone', '4 Mesh: Cube_Bone', '5 Mesh: Cube_Bone.child', '4 Bone: Bone.001', '5 Mesh: Cube_Bone.001' ])
def exportAnimationTestCase(self, name, dest): self.assertTrue(mappings[name]) for layer in mappings[name]: outFile = os.path.join(dest, os.path.basename(mappings[name][layer])) print('Exporting to "%s"' % outFile) xplaneFile = xplane_file.createFileFromBlenderLayerIndex(layer) self.assertIsNotNone(xplaneFile, 'Unable to create XPlaneFile for %s layer %d' % (name, layer)) out = xplaneFile.write() outFile = open(outFile, 'w') outFile.write(out) outFile.close()
def runAnimationTestCase(self, name, __dirname__): self.assertTrue(mappings[name]) def filterLine(line): # only keep ANIM_ lines return isinstance(line[0], str) and line[0].find('ANIM_') == 0 for layer in mappings[name]: print('Testing animations against fixture "%s"' % mappings[name][layer]) xplaneFile = xplane_file.createFileFromBlenderLayerIndex(layer) self.assertIsNotNone(xplaneFile, 'Unable to create XPlaneFile for %s layer %d' % (name, layer)) out = xplaneFile.write() fixtureFile = os.path.join(__dirname__, mappings[name][layer]) self.assertTrue(os.path.exists(fixtureFile), 'File "%s" does not exist' % fixtureFile) self.assertFileOutputEqualsFixture(out, fixtureFile, filterLine)
def exportAnimationTestCase(self, name, dest): self.assertTrue(mappings[name]) for layer in mappings[name]: outFile = os.path.join(dest, os.path.basename(mappings[name][layer])) print('Exporting to "%s"' % outFile) xplaneFile = xplane_file.createFileFromBlenderLayerIndex(layer) self.assertIsNotNone( xplaneFile, 'Unable to create XPlaneFile for %s layer %d' % (name, layer)) out = xplaneFile.write() outFile = open(outFile, 'w') outFile.write(out) outFile.close()
def test_bone_root_matrices(self): identityMatrix = mathutils.Matrix.Identity(4) xplaneFile = xplane_file.createFileFromBlenderLayerIndex(0) cubeStatic = xplaneFile.getBoneByBlenderName('Cube_static') # FIXME: we are actually testing getBoneByBlenderName() here, should be in it's own test file self.assertIsNotNone(cubeStatic) # Ben says: fix for issue 219 makes it ILLEGAL to ask for pre-and post animation or animation-bake matrices for a NON-animated bone! # preMatrix = cubeStatic.getPreAnimationMatrix() # postMatrix = cubeStatic.getPostAnimationMatrix() # bakeMatrix = cubeStatic.getBakeMatrixForMyAnimations() # self.assertFloatVectorsEqual(preMatrix.to_translation(), cubeStatic.blenderObject.location, FLOAT_TOLERANCE) # self.assertFloatVectorsEqual(preMatrix.to_scale(), cubeStatic.blenderObject.scale, FLOAT_TOLERANCE) # self.assertFloatVectorsEqual(preMatrix.to_euler('XYZ'), cubeStatic.blenderObject.rotation_euler, FLOAT_TOLERANCE) # post and pre are the same if not animated # self.assertEquals(preMatrix, postMatrix) # bake matrix should be objects world matrix as its not animated # self.assertEquals(bakeMatrix, cubeStatic.blenderObject.matrix_world) cubeAnimated = xplaneFile.getBoneByBlenderName('Cube_animated') self.assertIsNotNone(cubeAnimated) preMatrix = cubeAnimated.getPreAnimationMatrix() postMatrix = cubeAnimated.getPostAnimationMatrix() bakeMatrix = cubeAnimated.getBakeMatrixForMyAnimations() # animated object should have identity matrix as pre animation self.assertEquals(preMatrix, identityMatrix) # post matrix must be blender objects world matrix self.assertMatricesEqual(postMatrix, cubeAnimated.blenderObject.matrix_world, 0.0001) # bake matrix should be identity matrix (world origin) self.assertEquals(bakeMatrix, identityMatrix)
def runAnimationTestCase(self, name, __dirname__): self.assertTrue(mappings[name]) def filterLine(line): # only keep ANIM_ lines return isinstance(line[0], str) and line[0].find('ANIM_') == 0 for layer in mappings[name]: print('Testing animations against fixture "%s"' % mappings[name][layer]) xplaneFile = xplane_file.createFileFromBlenderLayerIndex(layer) self.assertIsNotNone( xplaneFile, 'Unable to create XPlaneFile for %s layer %d' % (name, layer)) out = xplaneFile.write() fixtureFile = os.path.join(__dirname__, mappings[name][layer]) self.assertTrue(os.path.exists(fixtureFile), 'File "%s" does not exist' % fixtureFile) self.assertFileOutputEqualsFixture(out, fixtureFile, filterLine)
def test_bone_root_matrices(self): identityMatrix = mathutils.Matrix.Identity(4) xplaneFile = xplane_file.createFileFromBlenderLayerIndex(0) cubeStatic = xplaneFile.getBoneByBlenderName('Cube_static') # FIXME: we are actually testing getBoneByBlenderName() here, should be in it's own test file self.assertIsNotNone(cubeStatic) cubeAnimated = xplaneFile.getBoneByBlenderName('Cube_animated') self.assertIsNotNone(cubeAnimated) preMatrix = cubeAnimated.getPreAnimationMatrix() postMatrix = cubeAnimated.getPostAnimationMatrix() bakeMatrix = cubeAnimated.getBakeMatrixForMyAnimations() # animated object should have identity matrix as pre animation self.assertMatricesEqual(preMatrix, identityMatrix) # post matrix must be blender objects world matrix self.assertMatricesEqual(postMatrix, cubeAnimated.blenderObject.matrix_world, 0.0001) # bake matrix should be identity matrix (world origin) self.assertMatricesEqual(bakeMatrix, identityMatrix)
def test_norm_met_off_two_drap_scen(self): expected_logger_errors = 1 #"test_norm_met_off_two_drap_scen" out = xplane_file.createFileFromBlenderLayerIndex(3).write() self.assertEqual(len(logger.findErrors()), expected_logger_errors) logger.clearMessages()
def test_autodetect_textures_export(self): xplaneFile = xplane_file.createFileFromBlenderLayerIndex(0) out = xplaneFile.write() self.assertEquals(len(logger.findErrors()),self.expected_logger_errors)
def test_glass_2_mats_conflict(self): xplaneFile = xplane_file.createFileFromBlenderLayerIndex(8) out = xplaneFile.write() self.assertEqual(len(logger.findErrors()), 1) logger.clearMessages()
def test_no_material(self): xplaneFile = xplane_file.createFileFromBlenderLayerIndex(0) out = xplaneFile.write() self.assertLoggerErrors(1)
def test_material_attributes(self): xplaneFile = xplane_file.createFileFromBlenderLayerIndex(0) green = xplaneFile.objects['green'].material red = xplaneFile.objects['red'].material blue = xplaneFile.objects['blue'].material emissive = xplaneFile.objects['emissive'].material cockpit = xplaneFile.objects['cockpit'].material cockpitPanel = xplaneFile.objects['cockpit_panel'].material invisible = xplaneFile.objects['invisible'].material surface = xplaneFile.objects['surface'].material conditions = xplaneFile.objects['conditions'].material specular = xplaneFile.objects['specular'].material defaultAttrs = { 'ATTR_shiny_rat': 1, 'ATTR_hard': None, 'ATTR_hard_deck': None, 'ATTR_no_hard': True, 'ATTR_blend': True, 'ATTR_shadow_blend': None, 'ATTR_no_blend': None, 'ATTR_draw_enable': True, 'ATTR_draw_disable': None, 'ATTR_solid_camera': None, 'ATTR_no_solid_camera': True, 'ATTR_light_level': None, 'ATTR_poly_os': None, 'ATTR_draped': None, 'ATTR_no_draped': True } defaultCockpitAttrs = { 'ATTR_cockpit': None, 'ATTR_no_cockpit': True, 'ATTR_cockpit_region': None } redAttrs = defaultAttrs.copy() greenAttrs = defaultAttrs.copy() blueAttrs = defaultAttrs.copy() emissiveAttrs = defaultAttrs.copy() cockpitAttrs = defaultAttrs.copy() cockpitAttrs['ATTR_shiny_rat'] = 1.0 cockpitAttrs['ATTR_blend'] = True cockpitAttrs['ATTR_draw_enable'] = True cockpitAttrs['ATTR_solid_camera'] = True cockpitAttrs['ATTR_no_solid_camera'] = False cockpitAttrs['ATTR_light_level'] = [1.0, 2.0, 'light-level-test'] cockpitCockpitAttrs = defaultCockpitAttrs.copy() cockpitCockpitAttrs['ATTR_cockpit'] = None cockpitCockpitAttrs['ATTR_no_cockpit'] = True cockpitCockpitAttrs['ATTR_cockpit_region'] = None cockpitPanelAttrs = defaultAttrs.copy() cockpitPanelAttrs['ATTR_shiny_rat'] = None cockpitPanelAttrs['ATTR_blend'] = None cockpitPanelAttrs['ATTR_draw_enable'] = True cockpitPanelAttrs['ATTR_solid_camera'] = True cockpitPanelAttrs['ATTR_no_solid_camera'] = False cockpitPanelCockpitAttrs = defaultCockpitAttrs.copy() cockpitPanelCockpitAttrs['ATTR_cockpit'] = True cockpitPanelCockpitAttrs['ATTR_no_cockpit'] = None cockpitPanelCockpitAttrs['ATTR_cockpit_region'] = 0 invisibleAttrs = defaultAttrs.copy() invisibleAttrs['ATTR_shiny_rat'] = None invisibleAttrs['ATTR_blend'] = None invisibleAttrs['ATTR_draw_enable'] = None invisibleAttrs['ATTR_draw_disable'] = True surfaceAttrs = defaultAttrs.copy() surfaceAttrs['ATTR_no_hard'] = None surfaceAttrs['ATTR_hard_deck'] = 'asphalt' surfaceAttrs['ATTR_poly_os'] = 2 conditionsAttrs = defaultAttrs.copy() conditionsAttrs['custom_prop'] = '10' specularAttrs = defaultAttrs.copy() specularAttrs['ATTR_shiny_rat'] = 0.75 self.assertAttributesEqualDict(red.attributes, redAttrs) self.assertAttributesEqualDict(red.cockpitAttributes, defaultCockpitAttrs) self.assertAttributesEqualDict(blue.attributes, blueAttrs) self.assertAttributesEqualDict(blue.cockpitAttributes, defaultCockpitAttrs) self.assertAttributesEqualDict(green.attributes, greenAttrs) self.assertAttributesEqualDict(green.cockpitAttributes, defaultCockpitAttrs) self.assertAttributesEqualDict(emissive.attributes, emissiveAttrs) self.assertAttributesEqualDict(emissive.cockpitAttributes, defaultCockpitAttrs) self.assertAttributesEqualDict(cockpit.attributes, cockpitAttrs) self.assertAttributesEqualDict(cockpit.cockpitAttributes, cockpitCockpitAttrs) self.assertAttributesEqualDict(cockpitPanel.attributes, cockpitPanelAttrs) self.assertAttributesEqualDict(cockpitPanel.cockpitAttributes, cockpitPanelCockpitAttrs) self.assertAttributesEqualDict(invisible.attributes, invisibleAttrs) self.assertAttributesEqualDict(invisible.cockpitAttributes, defaultCockpitAttrs) self.assertAttributesEqualDict(surface.attributes, surfaceAttrs) self.assertAttributesEqualDict(surface.cockpitAttributes, defaultCockpitAttrs) self.assertAttributesEqualDict(conditions.attributes, conditionsAttrs) self.assertAttributesEqualDict(conditions.cockpitAttributes, defaultCockpitAttrs) self.assertAttributesEqualDict(specular.attributes, specularAttrs) self.assertAttributesEqualDict(specular.cockpitAttributes, defaultCockpitAttrs)
def test_no_material(self): xplaneFile = xplane_file.createFileFromBlenderLayerIndex(0) out = xplaneFile.write() self.assertEquals(len(logger.findErrors()), self.expected_logger_errors)
def test_bone_animations(self): xplaneFile = xplane_file.createFileFromBlenderLayerIndex(0) self.assertXplaneFileHasBoneTree( xplaneFile, [ '0 ROOT', '1 Armature: Armature', '2 Bone: Bone', '3 Mesh: Cube.001', '1 Mesh: Cube', ]) armature = xplaneFile.rootBone.children[0] cube = xplaneFile.rootBone.children[1] bone = armature.children[0] boneCube = bone.children[0] # Root bone is not animated self.assertEquals(xplaneFile.rootBone.isAnimated(), False) # Armature is not animated self.assertEquals(armature.isAnimated(), False) # Bone is animated self.assertEquals(bone.isAnimated(), True) # Cube is animated self.assertEquals(cube.isAnimated(), True) # bone.cube is not animated self.assertEquals(boneCube.isAnimated(), False) # should have only one dataref and animation self.assertEquals(len(cube.datarefs), 1) self.assertEquals(len(cube.animations), 1) # cube should have one 'example' dataref and corresponding animation self.assertIn('example', cube.datarefs) self.assertIn('example', cube.animations) # should have 2 keyframes self.assertEquals(len(cube.animations['example']), 2) cubeKeyframes = cube.animations['example'] # check for correct location and rotation self.assertEquals(cubeKeyframes[0].location, mathutils.Vector((0, 0, 0))) self.assertEquals(cubeKeyframes[0].rotation, mathutils.Euler((0, 0, 0), 'XYZ')) self.assertEquals(cubeKeyframes[0].rotationMode, 'XYZ') self.assertEquals(cubeKeyframes[1].location, mathutils.Vector((0, 2, 0))) self.assertFloatsEqual(cubeKeyframes[1].rotation[0], math.radians( 0),0.00001) self.assertFloatsEqual(cubeKeyframes[1].rotation[1], math.radians(90),0.00001) self.assertFloatsEqual(cubeKeyframes[1].rotation[2], math.radians( 0),0.00001) self.assertEquals(cubeKeyframes[1].rotationMode, 'XYZ') # should have only one dataref and animation self.assertEquals(len(bone.datarefs), 1) self.assertEquals(len(bone.animations), 1) # bone should have 'bone_example' dataref self.assertIn('bone_example', bone.datarefs) self.assertIn('bone_example', bone.animations) # should have 2 keyframes self.assertEquals(len(bone.animations['bone_example']), 2) boneKeyframes = bone.animations['bone_example'] # check for correct location and rotation self.assertEquals(boneKeyframes[0].location, mathutils.Vector((0, 0, 0))) self.assertFloatsEqual(boneKeyframes[0].rotation[0], 0.0) self.assertFloatVectorsEqual(boneKeyframes[0].rotation[1], mathutils.Vector((1, 0, 0))) self.assertEquals(boneKeyframes[0].rotationMode, 'AXIS_ANGLE') self.assertEquals(boneKeyframes[1].location, mathutils.Vector((0, 0, 0))) self.assertFloatsEqual(boneKeyframes[1].rotation[0], 1.5707961320877075) self.assertFloatVectorsEqual(boneKeyframes[1].rotation[1], mathutils.Vector((-1.0, 0.0, 0.0))) self.assertEquals(boneKeyframes[1].rotationMode, 'AXIS_ANGLE')
def test_autodetect_textures_export(self): xplaneFile = xplane_file.createFileFromBlenderLayerIndex(0) out = xplaneFile.write() self.assertLoggerErrors(1)
def test_manipulator_attributes(self): xplaneFile = xplane_file.createFileFromBlenderLayerIndex(0) drag_xy = xplaneFile.objects['drag_xy'] self.assertAttributesEqualDict(drag_xy.cockpitAttributes, { 'ATTR_manip_drag_xy': ( 'hand', 1, 2, 3, 4, 5, 6, 'dataref1', 'dataref2', 'this should be the tooltip' ), 'ATTR_manip_wheel': (1) }) drag_axis = xplaneFile.objects['drag_axis'] self.assertAttributesEqualDict(drag_axis.cockpitAttributes, { 'ATTR_manip_drag_axis': ( 'four_arrows', 1, 2, 3, 4, 5, 'dataref', 'this should be the tooltip' ) }) command = xplaneFile.objects['command'] self.assertAttributesEqualDict(command.cockpitAttributes, { 'ATTR_manip_command': ( 'button', 'the_command', 'this should be the tooltip' ) }) command_axis = xplaneFile.objects['command_axis'] self.assertAttributesEqualDict(command_axis.cockpitAttributes, { 'ATTR_manip_command_axis': ( 'rotate_small', 1, 2, 3, 'pos_command', 'neg_command', 'this should be the tooltip' ) }) push = xplaneFile.objects['push'] self.assertAttributesEqualDict(push.cockpitAttributes, { 'ATTR_manip_push': ( 'rotate_small_left', 1, 2, 'dataref', 'this should be the tooltip' ), 'ATTR_manip_wheel': (1) }) radio = xplaneFile.objects['radio'] self.assertAttributesEqualDict(radio.cockpitAttributes, { 'ATTR_manip_radio': ( 'rotate_small_right', 1, 'dataref', 'this should be the tooltip' ), 'ATTR_manip_wheel': (1) }) delta = xplaneFile.objects['delta'] self.assertAttributesEqualDict(delta.cockpitAttributes, { 'ATTR_manip_delta': ( 'rotate_medium', 1, 2, 3, 4, 'dataref', 'this should be the tooltip' ), 'ATTR_manip_wheel': (1) }) wrap = xplaneFile.objects['wrap'] self.assertAttributesEqualDict(wrap.cockpitAttributes, { 'ATTR_manip_wrap': ( 'rotate_medium_left', 1, 2, 3, 4, 'dataref', 'this should be the tooltip' ), 'ATTR_manip_wheel': (1) }) toggle = xplaneFile.objects['toggle'] self.assertAttributesEqualDict(toggle.cockpitAttributes, { 'ATTR_manip_toggle': ( 'rotate_medium_right', 1, 2, 'dataref', 'this should be the tooltip' ), 'ATTR_manip_wheel': (1) }) noop = xplaneFile.objects['noop'] self.assertAttributesEqualDict(noop.cockpitAttributes, { 'ATTR_manip_noop': ( 'dataref', 'this should be the tooltip' ) }) drag_axis_pix = xplaneFile.objects['drag_axis_pix'] self.assertAttributesEqualDict(drag_axis_pix.cockpitAttributes, { 'ATTR_manip_drag_axis_pix': ( 'rotate_large_left', 1, 2, 3, 4, 5, 'dataref', 'this should be the tooltip' ), 'ATTR_manip_wheel': (1) }) command_knob = xplaneFile.objects['command_knob'] self.assertAttributesEqualDict(command_knob.cockpitAttributes, { 'ATTR_manip_command_knob': ( 'rotate_large_left', 'pos_command', 'neg_command', 'this should be the tooltip' ) }) command_switch_up_down = xplaneFile.objects['command_switch_up_down'] self.assertAttributesEqualDict(command_switch_up_down.cockpitAttributes, { 'ATTR_manip_command_switch_up_down': ( 'rotate_large_left', 'pos_command', 'neg_command', 'this should be the tooltip' ) }) command_switch_left_right = xplaneFile.objects['command_switch_left_right'] self.assertAttributesEqualDict(command_switch_left_right.cockpitAttributes, { 'ATTR_manip_command_switch_left_right': ( 'rotate_large_left', 'pos_command', 'neg_command', 'this should be the tooltip' ) }) axis_switch_up_down = xplaneFile.objects['axis_switch_up_down'] self.assertAttributesEqualDict(axis_switch_up_down.cockpitAttributes, { 'ATTR_manip_axis_switch_up_down': ( 'rotate_large_left', 4, 5, 1, 0.5, 'dataref', 'this should be the tooltip' ) }) axis_switch_left_right = xplaneFile.objects['axis_switch_left_right'] self.assertAttributesEqualDict(axis_switch_left_right.cockpitAttributes, { 'ATTR_manip_axis_switch_left_right': ( 'rotate_large_left', 4, 5, 1, 0.5, 'dataref', 'this should be the tooltip' ) })
def test_norm_met_on_two_drap_scen(self): out = xplane_file.createFileFromBlenderLayerIndex(7).write() self.assertFileOutputEqualsFixture(out,make_fixture_path(__dirname__, "test_norm_met_on_two_drap_scen",sub_dir="draped_spec_scenery"),filterLines)
def test_export(self): xplaneFile = xplane_file.createFileFromBlenderLayerIndex(0) out = xplaneFile.write() self.assertEquals(len(logger.findErrors()), 1)
def test_bone_animations(self): xplaneFile = xplane_file.createFileFromBlenderLayerIndex(0) self.assertXplaneFileHasBoneTree(xplaneFile, [ '0 ROOT', '1 Object: Armature', '2 Bone: Bone', '3 Object: Cube.001', '1 Object: Cube', ]) armature = xplaneFile.rootBone.children[0] cube = xplaneFile.rootBone.children[1] bone = armature.children[0] boneCube = bone.children[0] # Root bone is not animated self.assertEquals(xplaneFile.rootBone.isAnimated(), False) # Armature is not animated self.assertEquals(armature.isAnimated(), False) # Bone is animated self.assertEquals(bone.isAnimated(), True) # Cube is animated self.assertEquals(cube.isAnimated(), True) # bone.cube is not animated self.assertEquals(boneCube.isAnimated(), False) # should have only one dataref and animation self.assertEquals(len(cube.datarefs), 1) self.assertEquals(len(cube.animations), 1) # cube should have one 'example' dataref and corresponding animation self.assertIn('example', cube.datarefs) self.assertIn('example', cube.animations) # should have 2 keyframes self.assertEquals(len(cube.animations['example']), 2) cubeKeyframes = cube.animations['example'] # check for correct location and rotation self.assertEquals(cubeKeyframes[0].location, mathutils.Vector( (0, 0, 0))) self.assertEquals(cubeKeyframes[0].rotation, mathutils.Euler((0, 0, 0), 'XYZ')) self.assertEquals(cubeKeyframes[0].rotationMode, 'XYZ') self.assertEquals(cubeKeyframes[1].location, mathutils.Vector( (0, 2, 0))) self.assertFloatsEqual(cubeKeyframes[1].rotation[0], math.radians(0), 0.00001) self.assertFloatsEqual(cubeKeyframes[1].rotation[1], math.radians(90), 0.00001) self.assertFloatsEqual(cubeKeyframes[1].rotation[2], math.radians(0), 0.00001) self.assertEquals(cubeKeyframes[1].rotationMode, 'XYZ') # should have only one dataref and animation self.assertEquals(len(bone.datarefs), 1) self.assertEquals(len(bone.animations), 1) # bone should have 'bone_example' dataref self.assertIn('bone_example', bone.datarefs) self.assertIn('bone_example', bone.animations) # should have 2 keyframes self.assertEquals(len(bone.animations['bone_example']), 2) boneKeyframes = bone.animations['bone_example'] # check for correct location and rotation self.assertEquals(boneKeyframes[0].location, mathutils.Vector( (0, 0, 0))) self.assertEquals(boneKeyframes[0].rotation, mathutils.Quaternion((1, 0, 0, 0))) self.assertEquals(boneKeyframes[0].rotationMode, 'QUATERNION') self.assertEquals(boneKeyframes[1].location, mathutils.Vector( (0, 0, 0))) self.assertEquals(boneKeyframes[1].rotation, mathutils.Quaternion((1, 0, 0), math.radians(-90))) self.assertEquals(boneKeyframes[1].rotationMode, 'QUATERNION')
def test_export(self): xplaneFile = xplane_file.createFileFromBlenderLayerIndex(0) out = xplaneFile.write() self.assertLoggerErrors(1)
def test_create_files_from_single_layer(self): tmpDir = os.path.realpath(os.path.join(__file__, '../../tmp')) xplaneFile = xplane_file.createFileFromBlenderLayerIndex(0) # should contain 4 cubes self.assertEqual(len(xplaneFile.objects), 4) self.assertObjectsInXPlaneFile( xplaneFile, [ 'Cube', 'Cube.001', 'Cube.002', 'Cube.003' ]) self.assertXplaneFileHasBoneTree( xplaneFile, [ '0 ROOT', '1 Mesh: Cube', '2 Mesh: Cube.001', '3 Mesh: Cube.002', '4 Mesh: Cube.003' ]) xplaneFile2 = xplane_file.createFileFromBlenderLayerIndex(1) # should contain 2 cubes self.assertEqual(len(xplaneFile2.objects), 2) self.assertObjectsInXPlaneFile( xplaneFile2, [ 'Cube.004', 'Cube.005' ]) self.assertXplaneFileHasBoneTree( xplaneFile2, [ '0 ROOT', '1 Mesh: Cube.005', '1 Mesh: Cube.004' ]) xplaneFile3 = xplane_file.createFileFromBlenderLayerIndex(2) # should contain 4 cubes self.assertEqual(len(xplaneFile3.objects), 5) self.assertObjectsInXPlaneFile( xplaneFile3, [ 'Cube_arm_root', 'Cube_Bone', 'Cube_Bone.child', 'Cube_Bone.001' ]) self.assertXplaneFileHasBoneTree( xplaneFile3, [ '0 ROOT', '1 Mesh: Cube_arm_root', '2 Armature: Armature', '3 Bone: Bone', '4 Mesh: Cube_Bone', '5 Mesh: Cube_Bone.child', '4 Bone: Bone.001', '5 Mesh: Cube_Bone.001' ])