def test_only_mesh_chunk_is_written_if_mode_M(self): export_settings = {'mode': 'M', 'compression': 'U'} data_context = DataContext(container_name='containerName', meshes=[get_mesh()]) self.filepath = self.outpath() + 'output_skn' self.assertEqual({'FINISHED'}, save(self, export_settings, data_context)) self.filepath += '.w3d' self.assertTrue(os.path.exists(self.filepath)) file = open(self.filepath, 'rb') filesize = os.path.getsize(self.filepath) found_meshes = 0 while file.tell() < filesize: (chunk_type, chunk_size, chunk_end) = read_chunk_head(file) self.assertEqual(W3D_CHUNK_MESH, chunk_type) found_meshes += 1 file.seek(chunk_end, 1) file.close() self.assertEqual(1, found_meshes)
def test_hierarchy_name_is_container_name_for_hlod_and_animation_if_export_mode_HAM( self): export_settings = { 'mode': 'HAM', 'compression': 'U', 'use_existing_skeleton': False } hierarchy_name = 'TestHiera_SKL' data_context = DataContext(container_name='containerName', meshes=[ get_mesh(name='sword', skin=True), get_mesh(name='soldier', skin=True), get_mesh(name='TRUNK') ], hierarchy=get_hierarchy(hierarchy_name), hlod=get_hlod('TestModelName', hierarchy_name), animation=get_animation(hierarchy_name)) self.filepath = self.outpath() + 'output_skn' self.assertEqual({'FINISHED'}, save(self, export_settings, data_context)) self.assertEqual('containerName', data_context.hierarchy.header.name) self.assertEqual('containerName', data_context.hlod.header.hierarchy_name) self.assertEqual('containerName', data_context.animation.header.hierarchy_name)
def test_no_file_created_if_MODE_is_HAM_and_no_meshes(self): export_settings = {} export_settings['w3d_mode'] = "HAM" file_path = self.outpath() + "output_skn.w3d" context = ImportWrapper(file_path) self.assertEqual({'CANCELLED'}, save(context, export_settings)) self.assertFalse(os.path.exists(file_path))
def test_roundtrip_HAM(self): hierarchy_name = "TestName" hierarchy = get_hierarchy(hierarchy_name) meshes = [ get_mesh(name="sword", skin=True), get_mesh(name="soldier", skin=True), get_mesh(name="TRUNK")] hlod = get_hlod(hierarchy_name, hierarchy_name) box = get_box() animation = get_animation(hierarchy_name) comp_animation = get_compressed_animation(hierarchy_name) # write to file output = open(self.outpath() + "base.w3d", "wb") hierarchy.write(output) for mesh in meshes: mesh.write(output) hlod.write(output) box.write(output) animation.write(output) comp_animation.write(output) output.close() # import model = ImportWrapper(self.outpath() + "base.w3d") load(model, import_settings={}) # check created objects self.assertTrue("TestName" in bpy.data.armatures) amt = bpy.data.armatures["TestName"] self.assertEqual(6, len(amt.bones)) self.assertTrue("sword" in bpy.data.objects) self.assertTrue("soldier" in bpy.data.objects) self.assertTrue("TRUNK" in bpy.data.objects) # export export_settings = {} export_settings['w3d_mode'] = "HAM" export_settings['w3d_compression'] = "U" context = ImportWrapper(self.outpath() + "output.w3d") save(context, export_settings)
def test_no_file_created_if_MODE_is_A_and_TC_no_animation_channels(self): export_settings = {} export_settings['w3d_mode'] = "A" export_settings['w3d_compression'] = "TC" file_path = self.outpath() + "output_ani.w3d" context = ImportWrapper(file_path) self.assertEqual({'CANCELLED'}, save(context, export_settings)) self.assertFalse(os.path.exists(file_path))
def test_roundtrip_prelit(self): hierarchy_name = "TestHiera_SKL" hierarchy = get_hierarchy(hierarchy_name) meshes = [get_mesh(name="sword", skin=True, prelit=True), get_mesh(name="soldier", skin=True), get_mesh(name="TRUNK", prelit=True)] hlod = get_hlod("TestModelName", hierarchy_name) copyfile(up(up(self.relpath())) + "/testfiles/texture.dds", self.outpath() + "texture.dds") # write to file skn = open(self.outpath() + "base_skn.w3d", "wb") for mesh in meshes: mesh.write(skn) hlod.write(skn) skn.close() skl = open(self.outpath() + hierarchy_name + ".w3d", "wb") hierarchy.write(skl) skl.close() # import model = ImportWrapper(self.outpath() + "base_skn.w3d") load(model, import_settings={}) # check created objects self.assertTrue("TestHiera_SKL" in bpy.data.objects) self.assertTrue("TestHiera_SKL" in bpy.data.armatures) amt = bpy.data.armatures["TestHiera_SKL"] self.assertEqual(6, len(amt.bones)) self.assertTrue("sword" in bpy.data.objects) self.assertTrue("soldier" in bpy.data.objects) self.assertTrue("TRUNK" in bpy.data.objects) # export context = ImportWrapper(self.outpath() + "output_skn.w3d") export_settings = {} export_settings['w3d_mode'] = "M" save(context, export_settings)
def test_does_not_apply_extension_if_already_there(self): export_settings = {'mode': 'M', 'compression': 'U'} data_context = DataContext(container_name='containerName', meshes=[get_mesh()]) self.filepath = self.outpath() + 'output_skn.w3d' self.assertEqual({'FINISHED'}, save(self, export_settings, data_context)) self.assertTrue(os.path.exists(self.filepath)) self.assertFalse(os.path.exists(self.filepath + '.w3d'))
def test_error_is_shown_if_unsupported_export_mode(self): export_settings = {'mode': 'UNSUPPORTED', 'compression': 'U'} data_context = DataContext(container_name='containerName', meshes=[get_mesh(), get_mesh()]) self.filepath = self.outpath() + 'output_skn' with (patch.object(self, 'error')) as error_func: self.assertEqual({'CANCELLED'}, save(self, export_settings, data_context)) error_func.assert_called_with( 'unsupported export mode: UNSUPPORTED, aborting export!')
def test_warning_is_shown_if_M_and_multiple_meshes(self): export_settings = {'mode': 'M', 'compression': 'U'} data_context = DataContext(container_name='containerName', meshes=[get_mesh(), get_mesh()]) self.filepath = self.outpath() + 'output_skn' with (patch.object(self, 'warning')) as warning_func: self.assertEqual({'FINISHED'}, save(self, export_settings, data_context)) warning_func.assert_called_with( 'Scene does contain multiple meshes, exporting only the first with export mode M!' )
def test_hierarchy_is_written_if_mode_HM_and_not_use_existing_skeleton( self): export_settings = { 'mode': 'HM', 'compression': 'U', 'use_existing_skeleton': False } hierarchy_name = 'TestHiera_SKL' data_context = DataContext(container_name='containerName', meshes=[ get_mesh(name='sword', skin=True), get_mesh(name='soldier', skin=True), get_mesh(name='TRUNK') ], hierarchy=get_hierarchy(hierarchy_name), hlod=get_hlod('TestModelName', hierarchy_name)) self.filepath = self.outpath() + 'output_skn' self.assertEqual({'FINISHED'}, save(self, export_settings, data_context)) self.filepath += '.w3d' self.assertTrue(os.path.exists(self.filepath)) file = open(self.filepath, 'rb') filesize = os.path.getsize(self.filepath) hierarchy_found = False while file.tell() < filesize: (chunk_type, chunk_size, chunk_end) = read_chunk_head(file) if chunk_type == W3D_CHUNK_HIERARCHY: hierarchy_found = True skip_unknown_chunk(self, file, chunk_type, chunk_size) file.close() self.assertTrue(hierarchy_found)
def test_no_hlod_is_written_if_HAM_and_less_than_2_sub_objects(self): export_settings = {} export_settings['w3d_mode'] = "HAM" export_settings['w3d_compression'] = "U" meshes = [get_mesh()] create_data(self, meshes) file_path = self.outpath() + "output_skn.w3d" context = ImportWrapper(file_path) self.assertEqual({'FINISHED'}, save(context, export_settings)) file = open(file_path, "rb") filesize = os.path.getsize(file_path) while file.tell() < filesize: (chunk_type, chunk_size, chunk_end) = read_chunk_head(file) self.assertNotEqual(W3D_CHUNK_HLOD, chunk_type) skip_unknown_chunk(self, file, chunk_type, chunk_size) file.close()
def test_unsupported_export_mode(self): export_settings = {} export_settings['w3d_mode'] = "NON_EXISTING" self.assertEqual({'CANCELLED'}, save(self, export_settings))