/// <summary> /// Exports models, animations, and textures in a model group to a directory /// </summary> /// <param name="model_group"></param> /// <param name="out_directory"></param> public static void Export(this RenderBase.OModelGroup model_group, string out_directory) { model_group.ExportModels(out_directory); // TODO: support selecting the model to apply animations to if (model_group.model.Count != 0) { model_group.ExportSkeletalAnimations(0, out_directory); } else if (model_group.skeletalAnimation.Count != 0) { Console.Error.WriteLine("Warning: File contains animations but no models. Animations will not be exported."); } model_group.ExportTextures(out_directory); }
public override int Execute() { if (this.InDirectory == null || this.OutDirectory == null) { Console.WriteLine(this.GetUsage()); return(Parser.DefaultExitCodeFail); } try { Directory.CreateDirectory(this.OutDirectory); } catch (IOException ex) { Console.Error.WriteLine("Could not create output directory: " + ex.Message); return(1); } string[] files; try { files = Directory.GetFiles(this.InDirectory, "*.bin").Select(filename => Path.GetFileName(filename)).OrderBy(v => v).ToArray(); } catch (IOException ex) { Console.Error.WriteLine("Could not access input directory: " + ex.Message); return(1); } Console.WriteLine("Reading from " + this.InDirectory + ", exporting to " + this.OutDirectory); string current_name = null; string current_folder_name = null; RenderBase.OModelGroup current_group = null; foreach (var filename in files) { Console.WriteLine("Reading file " + filename); FileIO.file import_file; try { import_file = FileIO.load(Path.Combine(this.InDirectory, filename)); } catch (IOException ex) { Console.Error.WriteLine("Could not open file: " + ex.Message); return(1); } RenderBase.OModelGroup this_group = import_file.data as RenderBase.OModelGroup; if (this_group == null) { Console.Error.WriteLine("Unrecognized file type for file " + Path.Combine(this.InDirectory, filename) + "; skipping"); continue; } if (this_group.model.Count != 0) { // Starting new model, export the old one if (current_name != null) { try { current_group.ExportModels(current_folder_name); current_group.ExportSkeletalAnimations(0, current_folder_name); } catch (IOException ex) { Console.Error.WriteLine("Could not export " + current_name + ": " + ex.Message); return(1); } } // Move to next one current_name = filename; current_folder_name = Path.Combine(this.OutDirectory, filename + "_exported"); current_group = this_group; Console.WriteLine("Model found: " + current_name); try { Directory.CreateDirectory(current_folder_name); } catch (IOException ex) { Console.Error.WriteLine("Could not create " + current_folder_name + ": " + ex.Message); return(1); } } else if (this_group.skeletalAnimation.Count != 0) { // Append animations to model if (current_name == null) { Console.Error.WriteLine(filename + " contains animations not corresponding to any model, skipping."); continue; } current_group.skeletalAnimation.AddRange(this_group.skeletalAnimation); } if (this_group.texture.Count != 0) { // Export textures if (current_name == null) { Console.Error.WriteLine(filename + " contains texture not corresponding to any model, skipping."); continue; } string texture_folder_name = Path.Combine(current_folder_name, filename); try { Directory.CreateDirectory(texture_folder_name); } catch (IOException ex) { Console.Error.WriteLine("Could not create " + current_folder_name + ": " + ex.Message); return(1); } this_group.ExportTextures(texture_folder_name); } } // Export last model if (current_name != null) { try { current_group.ExportModels(current_folder_name); current_group.ExportSkeletalAnimations(0, current_folder_name); } catch (IOException ex) { Console.Error.WriteLine("Could not export " + current_name + ": " + ex.Message); return(1); } } else { Console.Error.WriteLine("No files found in " + this.InDirectory); return(1); } return(0); }